That fuck shit the fascists are using
1package org.tm.archive.components;
2
3import android.content.Context;
4import android.graphics.drawable.Drawable;
5import android.text.SpannableStringBuilder;
6import android.util.AttributeSet;
7
8import androidx.annotation.DrawableRes;
9import androidx.annotation.Nullable;
10import androidx.core.content.ContextCompat;
11
12import org.tm.archive.R;
13import org.tm.archive.components.emoji.SimpleEmojiTextView;
14import org.tm.archive.recipients.Recipient;
15import org.tm.archive.util.ContextUtil;
16import org.tm.archive.util.DrawableUtil;
17import org.tm.archive.util.SpanUtil;
18import org.tm.archive.util.ViewUtil;
19
20public class FromTextView extends SimpleEmojiTextView {
21
22 public FromTextView(Context context) {
23 super(context);
24 }
25
26 public FromTextView(Context context, AttributeSet attrs) {
27 super(context, attrs);
28 }
29
30 public void setText(Recipient recipient) {
31 setText(recipient, null);
32 }
33
34 public void setText(Recipient recipient, @Nullable CharSequence suffix) {
35 setText(recipient, recipient.getDisplayName(getContext()), suffix);
36 }
37
38 public void setText(Recipient recipient, @Nullable CharSequence fromString, @Nullable CharSequence suffix) {
39 setText(recipient, fromString, suffix, true);
40 }
41
42 public void setText(Recipient recipient, @Nullable CharSequence fromString, @Nullable CharSequence suffix, boolean asThread) {
43 SpannableStringBuilder builder = new SpannableStringBuilder();
44
45 if (asThread && recipient.isSelf()) {
46 builder.append(getContext().getString(R.string.note_to_self));
47 } else {
48 builder.append(fromString);
49 }
50
51 if (suffix != null) {
52 builder.append(suffix);
53 }
54
55 if (asThread && recipient.showVerified()) {
56 Drawable official = ContextUtil.requireDrawable(getContext(), R.drawable.ic_official_20);
57 official.setBounds(0, 0, ViewUtil.dpToPx(20), ViewUtil.dpToPx(20));
58
59 builder.append(" ")
60 .append(SpanUtil.buildCenteredImageSpan(official));
61 }
62
63 setText(builder);
64
65 if (recipient.isBlocked()) setCompoundDrawablesRelativeWithIntrinsicBounds(getBlocked(), null, null, null);
66 else if (recipient.isMuted()) setCompoundDrawablesRelativeWithIntrinsicBounds(getMuted(), null, null, null);
67 else setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, 0, 0);
68 }
69
70 private Drawable getBlocked() {
71 return getDrawable(R.drawable.symbol_block_16);
72 }
73
74 private Drawable getMuted() {
75 return getDrawable(R.drawable.ic_bell_disabled_16);
76 }
77
78 private Drawable getDrawable(@DrawableRes int drawable) {
79 Drawable mutedDrawable = ContextUtil.requireDrawable(getContext(), drawable);
80 mutedDrawable.setBounds(0, 0, ViewUtil.dpToPx(18), ViewUtil.dpToPx(18));
81 DrawableUtil.tint(mutedDrawable, ContextCompat.getColor(getContext(), R.color.signal_icon_tint_secondary));
82 return mutedDrawable;
83 }
84}