diff --git a/app/src/main/java/helium314/keyboard/keyboard/emoji/DynamicGridKeyboard.java b/app/src/main/java/helium314/keyboard/keyboard/emoji/DynamicGridKeyboard.java index 48cf39b8ea..bebeec257e 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/emoji/DynamicGridKeyboard.java +++ b/app/src/main/java/helium314/keyboard/keyboard/emoji/DynamicGridKeyboard.java @@ -180,6 +180,9 @@ public void addKeyLast(final Key usedKey) { public void removeAllKeys() { synchronized (mLock) { mGridKeys.clear(); + // also drop keys typed while viewing the recents tab that haven't been flushed yet, + // otherwise they get re-added on the next flushPendingRecentKeys() after a clear-all + mPendingKeys.clear(); mCachedGridKeys = null; } } diff --git a/app/src/main/java/helium314/keyboard/keyboard/emoji/EmojiPalettesView.java b/app/src/main/java/helium314/keyboard/keyboard/emoji/EmojiPalettesView.java index 42fb1e1a50..f7ace162ee 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/emoji/EmojiPalettesView.java +++ b/app/src/main/java/helium314/keyboard/keyboard/emoji/EmojiPalettesView.java @@ -167,6 +167,16 @@ private static RecyclerView getRecyclerView(View view) { return view.findViewById(R.id.emoji_keyboard_list); } + /** Rebuild the recents page while it is the currently visible page. notifyItemChanged does not + * rebind the current ViewPager2 page, so refresh its inner adapter directly (same as the + * tab-change path in onViewDetachedFromWindow). No-op if recents is not currently bound. */ + void refreshVisibleRecents() { + final RecyclerView recyclerView = mViews.get(mEmojiCategory.getRecentTabId()); + if (recyclerView != null && recyclerView.getAdapter() != null) { + recyclerView.getAdapter().notifyDataSetChanged(); + } + } + private void updateState(@NonNull RecyclerView recyclerView, long categoryId) { if (categoryId != mEmojiCategory.getCurrentCategory().ordinal()) { return; @@ -333,6 +343,10 @@ public void onRemoveRecentsKey(Key key) private void clearRecentKeys() { RecentEmojis.clear(); getRecentsKeyboard().removeAllKeys(); + // clearing happens while the recents tab is visible (its icon is long-pressed), where a plain + // notifyItemChanged does not rebind the current page - refresh the visible recents grid directly + if (initialized && mPager.getAdapter() instanceof PagerAdapter adapter) + adapter.refreshVisibleRecents(); } @Override