That fuck shit the fascists are using
at master 152 lines 5.0 kB view raw
1package org.tm.archive.conversation; 2 3import android.content.Context; 4import android.util.AttributeSet; 5import android.view.View; 6import android.view.ViewGroup; 7import android.widget.FrameLayout; 8 9import androidx.annotation.NonNull; 10import androidx.annotation.Nullable; 11import androidx.recyclerview.widget.GridLayoutManager; 12import androidx.recyclerview.widget.LinearLayoutManager; 13import androidx.recyclerview.widget.RecyclerView; 14 15import com.bumptech.glide.Glide; 16 17import org.tm.archive.R; 18import org.tm.archive.components.InputAwareLayout; 19import org.tm.archive.mediasend.Media; 20import org.tm.archive.util.StorageUtil; 21 22import java.util.Arrays; 23import java.util.List; 24import java.util.function.Predicate; 25import java.util.stream.Collectors; 26 27public class AttachmentKeyboard extends FrameLayout implements InputAwareLayout.InputView { 28 29 private static final List<AttachmentKeyboardButton> DEFAULT_BUTTONS = Arrays.asList( 30 AttachmentKeyboardButton.GALLERY, 31 AttachmentKeyboardButton.FILE, 32 AttachmentKeyboardButton.CONTACT, 33 AttachmentKeyboardButton.LOCATION, 34 AttachmentKeyboardButton.PAYMENT 35 ); 36 37 private View container; 38 private AttachmentKeyboardMediaAdapter mediaAdapter; 39 private AttachmentKeyboardButtonAdapter buttonAdapter; 40 private Callback callback; 41 42 private RecyclerView mediaList; 43 private View permissionText; 44 private View permissionButton; 45 46 public AttachmentKeyboard(@NonNull Context context) { 47 super(context); 48 init(context); 49 } 50 51 public AttachmentKeyboard(@NonNull Context context, @Nullable AttributeSet attrs) { 52 super(context, attrs); 53 init(context); 54 } 55 56 private void init(@NonNull Context context) { 57 inflate(context, R.layout.attachment_keyboard, this); 58 59 this.container = findViewById(R.id.attachment_keyboard_container); 60 this.mediaList = findViewById(R.id.attachment_keyboard_media_list); 61 this.permissionText = findViewById(R.id.attachment_keyboard_permission_text); 62 this.permissionButton = findViewById(R.id.attachment_keyboard_permission_button); 63 64 RecyclerView buttonList = findViewById(R.id.attachment_keyboard_button_list); 65 buttonList.setItemAnimator(null); 66 67 mediaAdapter = new AttachmentKeyboardMediaAdapter(Glide.with(this), media -> { 68 if (callback != null) { 69 callback.onAttachmentMediaClicked(media); 70 } 71 }); 72 73 buttonAdapter = new AttachmentKeyboardButtonAdapter(button -> { 74 if (callback != null) { 75 callback.onAttachmentSelectorClicked(button); 76 } 77 }); 78 79 mediaList.setAdapter(mediaAdapter); 80 buttonList.setAdapter(buttonAdapter); 81 82 buttonAdapter.registerAdapterDataObserver(new AttachmentButtonCenterHelper(buttonList)); 83 84 mediaList.setLayoutManager(new GridLayoutManager(context, 1, GridLayoutManager.HORIZONTAL, false)); 85 buttonList.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)); 86 87 buttonAdapter.setButtons(DEFAULT_BUTTONS); 88 } 89 90 public void setCallback(@NonNull Callback callback) { 91 this.callback = callback; 92 } 93 94 public void filterAttachmentKeyboardButtons(@Nullable Predicate<AttachmentKeyboardButton> buttonPredicate) { 95 if (buttonPredicate == null) { 96 buttonAdapter.setButtons(DEFAULT_BUTTONS); 97 } else { 98 buttonAdapter.setButtons(DEFAULT_BUTTONS.stream().filter(buttonPredicate).collect(Collectors.toList())); 99 } 100 } 101 102 public void onMediaChanged(@NonNull List<Media> media) { 103 if (StorageUtil.canReadFromMediaStore()) { 104 mediaAdapter.setMedia(media); 105 permissionButton.setVisibility(GONE); 106 permissionText.setVisibility(GONE); 107 } else { 108 permissionButton.setVisibility(VISIBLE); 109 permissionText.setVisibility(VISIBLE); 110 111 permissionButton.setOnClickListener(v -> { 112 if (callback != null) { 113 callback.onAttachmentPermissionsRequested(); 114 } 115 }); 116 } 117 } 118 119 public void setWallpaperEnabled(boolean wallpaperEnabled) { 120 if (wallpaperEnabled) { 121 container.setBackgroundColor(getContext().getResources().getColor(R.color.wallpaper_compose_background)); 122 } else { 123 container.setBackgroundColor(getContext().getResources().getColor(R.color.signal_background_primary)); 124 } 125 buttonAdapter.setWallpaperEnabled(wallpaperEnabled); 126 } 127 128 @Override 129 public void show(int height, boolean immediate) { 130 ViewGroup.LayoutParams params = getLayoutParams(); 131 params.height = height; 132 setLayoutParams(params); 133 134 setVisibility(VISIBLE); 135 } 136 137 @Override 138 public void hide(boolean immediate) { 139 setVisibility(GONE); 140 } 141 142 @Override 143 public boolean isShowing() { 144 return getVisibility() == VISIBLE; 145 } 146 147 public interface Callback { 148 void onAttachmentMediaClicked(@NonNull Media media); 149 void onAttachmentSelectorClicked(@NonNull AttachmentKeyboardButton button); 150 void onAttachmentPermissionsRequested(); 151 } 152}