From 1683a241e6d703f0e0bac9145cf447185b3df7f8 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 13 Jan 2021 19:44:59 +0100 Subject: [PATCH] Use hash to determine duplicates --- .../eu/faircode/email/FragmentMessages.java | 45 ++++--------------- 1 file changed, 9 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 5421b5efab..5d261a2915 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -192,7 +192,6 @@ import java.util.Arrays; import java.util.Calendar; import java.util.Collection; import java.util.Collections; -import java.util.Comparator; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -361,18 +360,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. "time", "unread", "starred", "priority" )); - private static final List DUPLICATE_ORDER = Collections.unmodifiableList(Arrays.asList( - EntityFolder.INBOX, - EntityFolder.OUTBOX, - EntityFolder.DRAFTS, - EntityFolder.SENT, - EntityFolder.TRASH, - EntityFolder.JUNK, - EntityFolder.SYSTEM, - EntityFolder.USER, - EntityFolder.ARCHIVE - )); - @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -4717,30 +4704,16 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. // Mark duplicates Map> duplicates = new HashMap<>(); for (TupleMessageEx message : messages) - if (message != null && !TextUtils.isEmpty(message.msgid)) { - if (!duplicates.containsKey(message.msgid)) - duplicates.put(message.msgid, new ArrayList()); - duplicates.get(message.msgid).add(message); - } - for (String msgid : duplicates.keySet()) { - List dups = duplicates.get(msgid); - if (dups.size() > 1) { - Collections.sort(dups, new Comparator() { - @Override - public int compare(TupleMessageEx d1, TupleMessageEx d2) { - Integer o1 = DUPLICATE_ORDER.indexOf(d1.folderType); - Integer o2 = DUPLICATE_ORDER.indexOf(d2.folderType); - return o1.compareTo(o2); - } - }); - - TupleMessageEx first = dups.get(0); - for (int i = 1; i < dups.size(); i++) { - TupleMessageEx dup = dups.get(i); - if (!Objects.equals(first.folderType, dup.folderType)) - dup.duplicate = true; - } + if (message != null && + !TextUtils.isEmpty(message.hash)) { + if (!duplicates.containsKey(message.hash)) + duplicates.put(message.hash, new ArrayList<>()); + duplicates.get(message.hash).add(message); } + for (String hash : duplicates.keySet()) { + List dups = duplicates.get(hash); + for (int i = 1; i < dups.size(); i++) + dups.get(i).duplicate = true; } if (autoExpanded) {