From ff09645b7c933cc1abf60651061c64be9c8474c6 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 1 May 2019 13:08:15 +0200 Subject: [PATCH] Sort folders on display name --- .../java/eu/faircode/email/AdapterFolder.java | 9 +-------- .../java/eu/faircode/email/AdapterOrder.java | 10 +++++++--- .../java/eu/faircode/email/EntityAccount.java | 7 ++++++- .../java/eu/faircode/email/EntityFolder.java | 9 +++++++-- .../java/eu/faircode/email/EntityOrder.java | 4 +++- .../eu/faircode/email/TupleFolderSort.java | 4 ++-- app/src/main/res/layout/item_order.xml | 19 +++++++++++++++++-- 7 files changed, 43 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterFolder.java b/app/src/main/java/eu/faircode/email/AdapterFolder.java index debd9c4f60..e54c38e61b 100644 --- a/app/src/main/java/eu/faircode/email/AdapterFolder.java +++ b/app/src/main/java/eu/faircode/email/AdapterFolder.java @@ -647,14 +647,7 @@ public class AdapterFolder extends RecyclerView.Adapter public class ViewHolder extends RecyclerView.ViewHolder { private TextView tvTitle; + private TextView tvSubTitle; ViewHolder(View itemView) { super(itemView); tvTitle = itemView.findViewById(R.id.tvTitle); + tvSubTitle = itemView.findViewById(R.id.tvSubTitle); } private void bindTo(EntityOrder item) { - tvTitle.setText(item.getSortTitle(context)); + String[] text = item.getSortTitle(context); + tvTitle.setText(text[0]); + tvSubTitle.setText(text[1]); } } @@ -82,8 +86,8 @@ public class AdapterOrder extends RecyclerView.Adapter if (o != 0) return o; - String name1 = s1.getSortTitle(context); - String name2 = s2.getSortTitle(context); + String name1 = s1.getSortKey(context); + String name2 = s2.getSortKey(context); return collator.compare(name1, name2); } }); diff --git a/app/src/main/java/eu/faircode/email/EntityAccount.java b/app/src/main/java/eu/faircode/email/EntityAccount.java index b0191c182d..1a6f1aaa54 100644 --- a/app/src/main/java/eu/faircode/email/EntityAccount.java +++ b/app/src/main/java/eu/faircode/email/EntityAccount.java @@ -124,10 +124,15 @@ public class EntityAccount extends EntityOrder implements Serializable { } @Override - String getSortTitle(Context context) { + String getSortKey(Context context) { return name; } + @Override + String[] getSortTitle(Context context) { + return new String[]{name, null}; + } + public JSONObject toJSON() throws JSONException { JSONObject json = new JSONObject(); json.put("id", id); diff --git a/app/src/main/java/eu/faircode/email/EntityFolder.java b/app/src/main/java/eu/faircode/email/EntityFolder.java index 3cf27dd270..cd63605e67 100644 --- a/app/src/main/java/eu/faircode/email/EntityFolder.java +++ b/app/src/main/java/eu/faircode/email/EntityFolder.java @@ -235,8 +235,13 @@ public class EntityFolder extends EntityOrder implements Serializable { } @Override - String getSortTitle(Context context) { - return Helper.localizeFolderName(context, name); + String getSortKey(Context context) { + return getDisplayName(context); + } + + @Override + String[] getSortTitle(Context context) { + return new String[]{getDisplayName(context), null}; } boolean isOutgoing() { diff --git a/app/src/main/java/eu/faircode/email/EntityOrder.java b/app/src/main/java/eu/faircode/email/EntityOrder.java index b932a7b9fb..91f4958377 100644 --- a/app/src/main/java/eu/faircode/email/EntityOrder.java +++ b/app/src/main/java/eu/faircode/email/EntityOrder.java @@ -26,5 +26,7 @@ public abstract class EntityOrder { abstract Long getSortId(); - abstract String getSortTitle(Context context); + abstract String getSortKey(Context context); + + abstract String[] getSortTitle(Context context); } diff --git a/app/src/main/java/eu/faircode/email/TupleFolderSort.java b/app/src/main/java/eu/faircode/email/TupleFolderSort.java index ecf69e63ac..fc71f383bb 100644 --- a/app/src/main/java/eu/faircode/email/TupleFolderSort.java +++ b/app/src/main/java/eu/faircode/email/TupleFolderSort.java @@ -25,7 +25,7 @@ public class TupleFolderSort extends EntityFolder { public String accountName; @Override - String getSortTitle(Context context) { - return accountName + "/" + super.getSortTitle(context); + String[] getSortTitle(Context context) { + return new String[]{getDisplayName(context), accountName}; } } diff --git a/app/src/main/res/layout/item_order.xml b/app/src/main/res/layout/item_order.xml index 799a7f8069..539ee0950b 100644 --- a/app/src/main/res/layout/item_order.xml +++ b/app/src/main/res/layout/item_order.xml @@ -14,12 +14,27 @@ + + \ No newline at end of file