From cf735128978be68de93cb2db310abf5b37f8d15d Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 3 Aug 2018 16:54:54 +0000 Subject: [PATCH] Better folder sort --- .../java/eu/faircode/email/AdapterFolder.java | 18 ++++++++++-------- .../java/eu/faircode/email/EntityFolder.java | 4 ++++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterFolder.java b/app/src/main/java/eu/faircode/email/AdapterFolder.java index 74e91437..8d2adfa6 100644 --- a/app/src/main/java/eu/faircode/email/AdapterFolder.java +++ b/app/src/main/java/eu/faircode/email/AdapterFolder.java @@ -119,15 +119,17 @@ public class AdapterFolder extends RecyclerView.Adapter() { @Override public int compare(TupleFolderEx f1, TupleFolderEx f2) { - if (f1.accountName == null) - if (f2.accountName == null) - return 0; + int s = EntityFolder.isUser(f1.type).compareTo(EntityFolder.isUser(f2.type)); + if (s == 0) { + int a = collator.compare( + f1.accountName == null ? "" : f1.accountName, + f2.accountName == null ? "" : f2.accountName); + if (a == 0) + return collator.compare(f1.name, f2.name); else - return -1; - else if (f2.accountName == null) - return 1; - else - return collator.compare(f1.accountName, f2.accountName); + return a; + } else + return s; } }); diff --git a/app/src/main/java/eu/faircode/email/EntityFolder.java b/app/src/main/java/eu/faircode/email/EntityFolder.java index d5e709cd..7f70b745 100644 --- a/app/src/main/java/eu/faircode/email/EntityFolder.java +++ b/app/src/main/java/eu/faircode/email/EntityFolder.java @@ -73,6 +73,10 @@ public class EntityFolder { return (TYPE_OUTBOX.equals(type) || TYPE_DRAFTS.equals(type) || TYPE_SENT.equals(type)); } + static Boolean isUser(String type) { + return TYPE_USER.equals(type); + } + @PrimaryKey(autoGenerate = true) public Long id; public Long account; // Outbox = null