That fuck shit the fascists are using
at master 94 lines 3.0 kB view raw
1package org.tm.archive.components; 2 3import android.content.Context; 4import android.content.res.TypedArray; 5import android.util.AttributeSet; 6import android.view.View; 7import android.view.animation.Animation; 8import android.view.animation.AnimationUtils; 9import android.widget.FrameLayout; 10import android.widget.ImageView; 11import android.widget.TextView; 12 13import androidx.annotation.ColorInt; 14import androidx.annotation.NonNull; 15import androidx.annotation.Nullable; 16 17import com.airbnb.lottie.SimpleColorFilter; 18 19import org.tm.archive.R; 20import org.tm.archive.util.ViewUtil; 21 22public final class ConversationScrollToView extends FrameLayout { 23 24 private final TextView unreadCount; 25 private final ImageView scrollButton; 26 private final Animation inAnimation; 27 private final Animation outAnimation; 28 29 public ConversationScrollToView(@NonNull Context context) { 30 this(context, null); 31 } 32 33 public ConversationScrollToView(@NonNull Context context, @Nullable AttributeSet attrs) { 34 this(context, attrs, 0); 35 } 36 37 public ConversationScrollToView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 38 super(context, attrs, defStyleAttr); 39 40 inflate(context, R.layout.conversation_scroll_to, this); 41 42 unreadCount = findViewById(R.id.conversation_scroll_to_count); 43 scrollButton = findViewById(R.id.conversation_scroll_to_button); 44 45 if (attrs != null && !isInEditMode()) { 46 TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.ConversationScrollToView); 47 int srcId = array.getResourceId(R.styleable.ConversationScrollToView_cstv_scroll_button_src, 0); 48 49 scrollButton.setImageResource(srcId); 50 51 array.recycle(); 52 } 53 54 inAnimation = AnimationUtils.loadAnimation(context, R.anim.fade_scale_in); 55 outAnimation = AnimationUtils.loadAnimation(context, R.anim.fade_scale_out); 56 57 inAnimation.setDuration(100); 58 outAnimation.setDuration(50); 59 } 60 61 public void setShown(boolean isShown) { 62 if (isShown) { 63 ViewUtil.animateIn(this, inAnimation); 64 } else { 65 ViewUtil.animateOut(this, outAnimation, View.INVISIBLE); 66 } 67 } 68 69 public void setWallpaperEnabled(boolean hasWallpaper) { 70 if (hasWallpaper) { 71 scrollButton.setBackgroundResource(R.drawable.scroll_to_bottom_background_wallpaper); 72 } else { 73 scrollButton.setBackgroundResource(R.drawable.scroll_to_bottom_background_normal); 74 } 75 } 76 77 public void setUnreadCountBackgroundTint(@ColorInt int tint) { 78 unreadCount.getBackground().setColorFilter(new SimpleColorFilter(tint)); 79 } 80 81 @Override 82 public void setOnClickListener(@Nullable OnClickListener l) { 83 scrollButton.setOnClickListener(l); 84 } 85 86 public void setUnreadCount(int unreadCount) { 87 this.unreadCount.setText(formatUnreadCount(unreadCount)); 88 this.unreadCount.setVisibility(unreadCount > 0 ? VISIBLE : GONE); 89 } 90 91 private @NonNull CharSequence formatUnreadCount(int unreadCount) { 92 return unreadCount > 999 ? "999+" : String.valueOf(unreadCount); 93 } 94}