That fuck shit the fascists are using
1package org.tm.archive.wallpaper;
2
3import android.util.DisplayMetrics;
4import android.view.View;
5import android.widget.ImageView;
6
7import androidx.annotation.LayoutRes;
8import androidx.annotation.NonNull;
9import androidx.annotation.Nullable;
10import androidx.annotation.OptIn;
11import androidx.media3.common.util.UnstableApi;
12import androidx.media3.ui.AspectRatioFrameLayout;
13import androidx.recyclerview.widget.RecyclerView;
14
15
16import org.tm.archive.R;
17import org.tm.archive.util.DisplayMetricsUtil;
18import org.tm.archive.util.adapter.mapping.Factory;
19import org.tm.archive.util.adapter.mapping.LayoutFactory;
20import org.tm.archive.util.adapter.mapping.MappingViewHolder;
21
22@OptIn(markerClass = UnstableApi.class)
23class ChatWallpaperViewHolder extends MappingViewHolder<ChatWallpaperSelectionMappingModel> {
24
25 private final AspectRatioFrameLayout frame;
26 private final ImageView preview;
27 private final EventListener eventListener;
28
29 public ChatWallpaperViewHolder(@NonNull View itemView, @Nullable EventListener eventListener, @Nullable DisplayMetrics windowDisplayMetrics) {
30 super(itemView);
31 this.frame = itemView.findViewById(R.id.chat_wallpaper_preview_frame);
32 this.preview = itemView.findViewById(R.id.chat_wallpaper_preview);
33 this.eventListener = eventListener;
34
35 if (windowDisplayMetrics != null) {
36 DisplayMetricsUtil.forceAspectRatioToScreenByAdjustingHeight(windowDisplayMetrics, itemView);
37 } else if (frame != null) {
38 frame.setAspectRatio(1.0f);
39 }
40 }
41
42 @Override
43 public void bind(@NonNull ChatWallpaperSelectionMappingModel model) {
44 model.loadInto(preview);
45
46 preview.setColorFilter(ChatWallpaperDimLevelUtil.getDimColorFilterForNightMode(context, model.getWallpaper()));
47
48 if (eventListener != null) {
49 preview.setOnClickListener(unused -> {
50 if (getAdapterPosition() != RecyclerView.NO_POSITION) {
51 eventListener.onModelClick(model);
52 }
53 });
54 }
55 }
56
57 public static @NonNull Factory<ChatWallpaperSelectionMappingModel> createFactory(@LayoutRes int layout, @Nullable EventListener listener, @Nullable DisplayMetrics windowDisplayMetrics) {
58 return new LayoutFactory<>(view -> new ChatWallpaperViewHolder(view, listener, windowDisplayMetrics), layout);
59 }
60
61 public interface EventListener {
62 default void onModelClick(@NonNull ChatWallpaperSelectionMappingModel model) {
63 onClick(model.getWallpaper());
64 }
65
66 void onClick(@NonNull ChatWallpaper chatWallpaper);
67 }
68}