From a23bec0618ba92e761fc01db465cf24ed947da41 Mon Sep 17 00:00:00 2001 From: likeazir Date: Sun, 27 Oct 2024 17:41:38 +0100 Subject: [PATCH 1/2] Delay loading of emojis until emoji picker is opened --- .../android/ui/CustomEmojiPopupKeyboard.java | 22 ++++++++++++++----- .../EmojiReactionsStatusDisplayItem.java | 2 +- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/CustomEmojiPopupKeyboard.java b/mastodon/src/main/java/org/joinmastodon/android/ui/CustomEmojiPopupKeyboard.java index 16a1ae52e1..31a4709c63 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/CustomEmojiPopupKeyboard.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/CustomEmojiPopupKeyboard.java @@ -111,12 +111,13 @@ public int getSpanSize(int position){ list.setPadding(V.dp(16), 0, V.dp(16), 0); imgLoader=new ListImageLoaderWrapper(activity, list, new RecyclerViewDelegate(list), null); - List recentEmoji=new ArrayList<>(lp.recentCustomEmoji); - if(!recentEmoji.isEmpty()) - adapter.addAdapter(new SingleCategoryAdapter(recentEmojiCategory=new EmojiCategory(activity.getString(R.string.mo_emoji_recent), recentEmoji))); - - for(EmojiCategory category:emojis) - adapter.addAdapter(new SingleCategoryAdapter(category)); + if (!forReaction){ + List recentEmoji=new ArrayList<>(lp.recentCustomEmoji); + if(!recentEmoji.isEmpty()) + adapter.addAdapter(new SingleCategoryAdapter(recentEmojiCategory=new EmojiCategory(activity.getString(R.string.mo_emoji_recent), recentEmoji))); + for(EmojiCategory category : emojis) + adapter.addAdapter(new SingleCategoryAdapter(category)); + } list.setAdapter(adapter); list.addItemDecoration(new RecyclerView.ItemDecoration(){ @Override @@ -229,6 +230,15 @@ public void onEmojiUpdated(EmojiUpdatedEvent ev){ } } + public void customToggleKeyboardPopup(){ + List recentEmoji=new ArrayList<>(lp.recentCustomEmoji); + if(!recentEmoji.isEmpty()) + adapter.addAdapter(new SingleCategoryAdapter(recentEmojiCategory=new EmojiCategory(activity.getString(R.string.mo_emoji_recent), recentEmoji))); + for(EmojiCategory category : emojis) + adapter.addAdapter(new SingleCategoryAdapter(category)); + super.toggleKeyboardPopup(null); + } + private class SingleCategoryAdapter extends UsableRecyclerView.Adapter implements ImageLoaderRecyclerAdapter, Filterable{ private EmojiCategory category; diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/EmojiReactionsStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/EmojiReactionsStatusDisplayItem.java index 3eece84482..8838fd4a81 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/EmojiReactionsStatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/EmojiReactionsStatusDisplayItem.java @@ -265,7 +265,7 @@ private void addEmojiReaction(String emoji, Emoji info) { public void onBackspace() {} private void onReactClick(View v){ - emojiKeyboard.toggleKeyboardPopup(null); + emojiKeyboard.customToggleKeyboardPopup(); v.setSelected(emojiKeyboard.isVisible()); space.setVisibility(emojiKeyboard.isVisible() ? View.VISIBLE : View.GONE); DisplayMetrics displayMetrics = new DisplayMetrics(); From 540dcd86033de26a72292b2c5410027b173ca969 Mon Sep 17 00:00:00 2001 From: likeazir Date: Mon, 28 Oct 2024 13:14:34 +0100 Subject: [PATCH 2/2] don't load adapters if they already exist --- .../android/ui/CustomEmojiPopupKeyboard.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/CustomEmojiPopupKeyboard.java b/mastodon/src/main/java/org/joinmastodon/android/ui/CustomEmojiPopupKeyboard.java index 31a4709c63..e976a3d1c2 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/CustomEmojiPopupKeyboard.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/CustomEmojiPopupKeyboard.java @@ -231,11 +231,13 @@ public void onEmojiUpdated(EmojiUpdatedEvent ev){ } public void customToggleKeyboardPopup(){ - List recentEmoji=new ArrayList<>(lp.recentCustomEmoji); - if(!recentEmoji.isEmpty()) - adapter.addAdapter(new SingleCategoryAdapter(recentEmojiCategory=new EmojiCategory(activity.getString(R.string.mo_emoji_recent), recentEmoji))); - for(EmojiCategory category : emojis) - adapter.addAdapter(new SingleCategoryAdapter(category)); + if (adapter.getAdapterCount() == 0){ + List recentEmoji=new ArrayList<>(lp.recentCustomEmoji); + if(!recentEmoji.isEmpty()) + adapter.addAdapter(new SingleCategoryAdapter(recentEmojiCategory=new EmojiCategory(activity.getString(R.string.mo_emoji_recent), recentEmoji))); + for(EmojiCategory category : emojis) + adapter.addAdapter(new SingleCategoryAdapter(category)); + } super.toggleKeyboardPopup(null); }