From 40ca8c9aceab51513f6447859e55132f540672a7 Mon Sep 17 00:00:00 2001 From: codokie <@> Date: Mon, 1 Apr 2024 21:36:53 +0300 Subject: [PATCH] fix duplicated pinned clips --- .../keyboard/latin/ClipboardHistoryManager.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/latin/ClipboardHistoryManager.kt b/app/src/main/java/helium314/keyboard/latin/ClipboardHistoryManager.kt index 5c61a606d..93488f152 100644 --- a/app/src/main/java/helium314/keyboard/latin/ClipboardHistoryManager.kt +++ b/app/src/main/java/helium314/keyboard/latin/ClipboardHistoryManager.kt @@ -45,8 +45,14 @@ class ClipboardHistoryManager( } fun onPinnedClipsAvailable(pinnedClips: List) { - historyEntries.addAll(pinnedClips) - sortHistoryEntries() + val added = historyEntries.addAll(pinnedClips.filterNot { pinnedClip -> + historyEntries.any { historyEntry -> + historyEntry.content == pinnedClip.content + } + }) + if (added) { + sortHistoryEntries() + } if (onHistoryChangeListener != null) { pinnedClips.forEach { onHistoryChangeListener?.onClipboardHistoryEntryAdded(historyEntries.indexOf(it))