That fuck shit the fascists are using
at master 177 lines 7.3 kB view raw
1package org.tm.archive.wallpaper; 2 3import android.content.Context; 4import android.content.Intent; 5import android.graphics.drawable.Drawable; 6import android.os.Bundle; 7import android.view.View; 8import android.widget.TextView; 9 10import androidx.annotation.NonNull; 11import androidx.annotation.Nullable; 12import androidx.appcompat.widget.Toolbar; 13import androidx.viewpager2.widget.ViewPager2; 14 15import com.annimon.stream.Stream; 16 17import org.tm.archive.PassphraseRequiredActivity; 18import org.tm.archive.R; 19import org.tm.archive.conversation.colors.ChatColors; 20import org.tm.archive.conversation.colors.ColorizerView; 21import org.tm.archive.keyvalue.SignalStore; 22import org.tm.archive.recipients.Recipient; 23import org.tm.archive.recipients.RecipientId; 24import org.tm.archive.util.DynamicNoActionBarTheme; 25import org.tm.archive.util.DynamicTheme; 26import org.tm.archive.util.FullscreenHelper; 27import org.tm.archive.util.Projection; 28import org.tm.archive.util.ViewUtil; 29import org.tm.archive.util.WindowUtil; 30import org.tm.archive.util.adapter.mapping.MappingModel; 31 32import java.util.Collections; 33 34public class ChatWallpaperPreviewActivity extends PassphraseRequiredActivity { 35 36 public static final String EXTRA_CHAT_WALLPAPER = "extra.chat.wallpaper"; 37 private static final String EXTRA_DIM_IN_DARK_MODE = "extra.dim.in.dark.mode"; 38 private static final String EXTRA_RECIPIENT_ID = "extra.recipient.id"; 39 40 private final DynamicTheme dynamicTheme = new DynamicNoActionBarTheme(); 41 42 private ChatWallpaperPreviewAdapter adapter; 43 private ColorizerView colorizerView; 44 private View bubble2; 45 private OnPageChanged onPageChanged; 46 private ViewPager2 viewPager; 47 48 public static @NonNull Intent create(@NonNull Context context, @NonNull ChatWallpaper selection, @NonNull RecipientId recipientId, boolean dimInDarkMode) { 49 Intent intent = new Intent(context, ChatWallpaperPreviewActivity.class); 50 51 intent.putExtra(EXTRA_CHAT_WALLPAPER, selection); 52 intent.putExtra(EXTRA_DIM_IN_DARK_MODE, dimInDarkMode); 53 intent.putExtra(EXTRA_RECIPIENT_ID, recipientId); 54 55 return intent; 56 } 57 58 @Override 59 protected void onCreate(Bundle savedInstanceState, boolean ready) { 60 dynamicTheme.onCreate(this); 61 62 setContentView(R.layout.chat_wallpaper_preview_activity); 63 64 adapter = new ChatWallpaperPreviewAdapter(); 65 colorizerView = findViewById(R.id.colorizer); 66 bubble2 = findViewById(R.id.preview_bubble_2); 67 viewPager = findViewById(R.id.preview_pager); 68 69 View submit = findViewById(R.id.preview_set_wallpaper); 70 ChatWallpaperRepository repository = new ChatWallpaperRepository(); 71 ChatWallpaper selected = getIntent().getParcelableExtra(EXTRA_CHAT_WALLPAPER); 72 boolean dim = getIntent().getBooleanExtra(EXTRA_DIM_IN_DARK_MODE, false); 73 Toolbar toolbar = findViewById(R.id.toolbar); 74 TextView bubble2Text = findViewById(R.id.preview_bubble_2_text); 75 76 toolbar.setNavigationOnClickListener(unused -> { 77 finish(); 78 }); 79 80 viewPager.setAdapter(adapter); 81 82 adapter.submitList(Collections.singletonList(new ChatWallpaperSelectionMappingModel(selected))); 83 repository.getAllWallpaper(wallpapers -> adapter.submitList(Stream.of(wallpapers) 84 .map(wallpaper -> ChatWallpaperFactory.updateWithDimming(wallpaper, dim ? ChatWallpaper.FIXED_DIM_LEVEL_FOR_DARK_THEME : 0f)) 85 .<MappingModel<?>>map(ChatWallpaperSelectionMappingModel::new) 86 .toList())); 87 88 submit.setOnClickListener(unused -> { 89 ChatWallpaperSelectionMappingModel model = (ChatWallpaperSelectionMappingModel) adapter.getCurrentList().get(viewPager.getCurrentItem()); 90 91 setResult(RESULT_OK, new Intent().putExtra(EXTRA_CHAT_WALLPAPER, model.getWallpaper())); 92 finish(); 93 }); 94 95 RecipientId recipientId = getIntent().getParcelableExtra(EXTRA_RECIPIENT_ID); 96 97 if (recipientId != null) { 98 Recipient.live(recipientId) 99 .getLiveDataResolved() 100 .observe(this, recipient -> { 101 bubble2Text.setText(getString(R.string.ChatWallpaperPreviewActivity__set_wallpaper_for_s, 102 recipient.isSelf() ? getString(R.string.note_to_self) 103 : recipient.getDisplayName(this))); 104 addUpdateBubbleColorListeners(recipient.getChatColors(), selected.getAutoChatColors()); 105 }); 106 } else { 107 addUpdateBubbleColorListeners(SignalStore.chatColorsValues().getChatColors(), selected.getAutoChatColors()); 108 } 109 110 new FullscreenHelper(this).showSystemUI(); 111 WindowUtil.setLightStatusBarFromTheme(this); 112 WindowUtil.setLightNavigationBarFromTheme(this); 113 } 114 115 @Override 116 protected void onDestroy() { 117 if (onPageChanged != null) { 118 viewPager.unregisterOnPageChangeCallback(onPageChanged); 119 } 120 121 super.onDestroy(); 122 } 123 124 private void addUpdateBubbleColorListeners(@Nullable ChatColors chatColors, @NonNull ChatColors selectedWallpaperAutoColors) { 125 if (chatColors == null || chatColors.getId().equals(ChatColors.Id.Auto.INSTANCE)) { 126 onPageChanged = new OnPageChanged(); 127 viewPager.registerOnPageChangeCallback(onPageChanged); 128 bubble2.addOnLayoutChangeListener(new UpdateChatColorsOnNextLayoutChange(selectedWallpaperAutoColors)); 129 } else { 130 bubble2.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> { 131 updateChatColors(chatColors); 132 }); 133 } 134 } 135 136 private class OnPageChanged extends ViewPager2.OnPageChangeCallback { 137 @Override 138 public void onPageSelected(int position) { 139 ChatWallpaperSelectionMappingModel model = (ChatWallpaperSelectionMappingModel) adapter.getCurrentList().get(position); 140 141 updateChatColors(model.getWallpaper().getAutoChatColors()); 142 } 143 } 144 145 private void updateChatColors(@NonNull ChatColors chatColors) { 146 Drawable mask = chatColors.getChatBubbleMask(); 147 148 colorizerView.setBackground(mask); 149 150 colorizerView.setProjections( 151 Collections.singletonList(Projection.relativeToViewWithCommonRoot(bubble2, colorizerView, new Projection.Corners(ViewUtil.dpToPx(18)))) 152 ); 153 154 bubble2.getBackground().setColorFilter(chatColors.getChatBubbleColorFilter()); 155 } 156 157 private class UpdateChatColorsOnNextLayoutChange implements View.OnLayoutChangeListener { 158 159 private final ChatColors chatColors; 160 161 private UpdateChatColorsOnNextLayoutChange(@NonNull ChatColors chatColors) { 162 this.chatColors = chatColors; 163 } 164 165 @Override 166 public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { 167 v.removeOnLayoutChangeListener(this); 168 updateChatColors(chatColors); 169 } 170 } 171 172 @Override 173 protected void onResume() { 174 super.onResume(); 175 dynamicTheme.onResume(this); 176 } 177}