That fuck shit the fascists are using
1package org.tm.archive.conversation;
2
3import android.content.Context;
4import android.graphics.Canvas;
5import android.graphics.drawable.Drawable;
6import android.util.AttributeSet;
7import android.widget.LinearLayout;
8
9import androidx.annotation.NonNull;
10import androidx.annotation.Nullable;
11
12import com.annimon.stream.Collectors;
13import com.annimon.stream.Stream;
14
15import org.tm.archive.components.Outliner;
16import org.tm.archive.util.Projection;
17import org.tm.archive.util.Util;
18
19import java.util.Collections;
20import java.util.List;
21import java.util.Objects;
22import java.util.Set;
23
24public class ConversationItemBodyBubble extends LinearLayout {
25
26 @Nullable private List<Outliner> outliners = Collections.emptyList();
27 @Nullable private OnSizeChangedListener sizeChangedListener;
28
29 private ClipProjectionDrawable clipProjectionDrawable;
30 private Projection quoteViewProjection;
31 private Projection videoPlayerProjection;
32
33 private final BodyBubbleLayoutTransition bodyBubbleLayoutTransition = new BodyBubbleLayoutTransition();
34
35 public ConversationItemBodyBubble(Context context) {
36 super(context);
37 init();
38 }
39
40 public ConversationItemBodyBubble(Context context, @Nullable AttributeSet attrs) {
41 super(context, attrs);
42 init();
43 }
44
45 public ConversationItemBodyBubble(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
46 super(context, attrs, defStyleAttr);
47 init();
48 }
49
50 private void init() {
51 setLayoutTransition(bodyBubbleLayoutTransition);
52 }
53
54 public void setParentScrolling(boolean isParentScrolling) {
55 if (isParentScrolling) {
56 setLayoutTransition(null);
57 } else {
58 setLayoutTransition(bodyBubbleLayoutTransition);
59 }
60 }
61
62 public void setOutliners(@NonNull List<Outliner> outliners) {
63 this.outliners = outliners;
64 }
65
66 public void setOnSizeChangedListener(@Nullable OnSizeChangedListener listener) {
67 this.sizeChangedListener = listener;
68 }
69
70 @Override
71 public void setBackground(Drawable background) {
72 clipProjectionDrawable = new ClipProjectionDrawable(background);
73
74 clipProjectionDrawable.setProjections(getProjections());
75 super.setBackground(clipProjectionDrawable);
76 }
77
78 public void setQuoteViewProjection(@Nullable Projection quoteViewProjection) {
79 if (this.quoteViewProjection != null) {
80 this.quoteViewProjection.release();
81 }
82
83 this.quoteViewProjection = quoteViewProjection;
84 clipProjectionDrawable.setProjections(getProjections());
85 }
86
87 public void setVideoPlayerProjection(@Nullable Projection videoPlayerProjection) {
88 if (this.videoPlayerProjection != null) {
89 this.videoPlayerProjection.release();
90 }
91
92 this.videoPlayerProjection = videoPlayerProjection;
93 clipProjectionDrawable.setProjections(getProjections());
94 }
95
96 public @Nullable Projection getVideoPlayerProjection() {
97 return videoPlayerProjection;
98 }
99
100 public @NonNull Set<Projection> getProjections() {
101 return Stream.of(quoteViewProjection, videoPlayerProjection)
102 .filterNot(Objects::isNull)
103 .collect(Collectors.toSet());
104 }
105
106 @Override
107 public void onDrawForeground(Canvas canvas) {
108 super.onDrawForeground(canvas);
109
110 if (Util.isEmpty(outliners)) return;
111
112 for (Outliner outliner : outliners) {
113 outliner.draw(canvas, 0, getMeasuredWidth(), getMeasuredHeight(), 0);
114 }
115 }
116
117 @Override
118 protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) {
119 if (sizeChangedListener != null) {
120 post(() -> {
121 if (sizeChangedListener != null) {
122 sizeChangedListener.onSizeChanged(width, height);
123 }
124 });
125 }
126 }
127
128 public interface OnSizeChangedListener {
129 void onSizeChanged(int width, int height);
130 }
131}
132