From 2847dd1705a1800c89fdcc0d5044a666a6d15859 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 26 Mar 2021 09:12:23 +0100 Subject: [PATCH] Sort answer groups --- .../java/eu/faircode/email/FragmentCompose.java | 15 +++++++++++++-- .../java/eu/faircode/email/FragmentMessages.java | 16 +++++++++++++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 4ecf8210a9..646f0e6d30 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -1619,16 +1619,27 @@ public class FragmentCompose extends FragmentBase { PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(getContext(), getViewLifecycleOwner(), vwAnchorMenu); Menu main = popupMenu.getMenu(); + List groups = new ArrayList<>(); + for (EntityAnswer answer : answers) + if (answer.group != null && !groups.contains(answer.group)) + groups.add(answer.group); + + Collator collator = Collator.getInstance(Locale.getDefault()); + collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc + Collections.sort(groups, collator); + int order = 0; + Map map = new HashMap<>(); + for (String group : groups) + map.put(group, main.addSubMenu(Menu.NONE, order, order++, group)); + for (EntityAnswer answer : answers) { order++; if (answer.group == null) main.add(Menu.NONE, order, order++, answer.toString()) .setIntent(new Intent().putExtra("id", answer.id)); else { - if (!map.containsKey(answer.group)) - map.put(answer.group, main.addSubMenu(Menu.NONE, order, order++, answer.group)); SubMenu smenu = map.get(answer.group); smenu.add(Menu.NONE, smenu.size(), smenu.size() + 1, answer.toString()) .setIntent(new Intent().putExtra("id", answer.id)); diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index d09d0722a0..f5308bf058 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -2569,17 +2569,27 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(getContext(), getViewLifecycleOwner(), fabReply); Menu main = popupMenu.getMenu(); - Map map = new HashMap<>(); + List groups = new ArrayList<>(); + for (EntityAnswer answer : answers) + if (answer.group != null && !groups.contains(answer.group)) + groups.add(answer.group); + + Collator collator = Collator.getInstance(Locale.getDefault()); + collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc + Collections.sort(groups, collator); int order = 0; + + Map map = new HashMap<>(); + for (String group : groups) + map.put(group, main.addSubMenu(Menu.NONE, order, order++, group)); + for (EntityAnswer answer : answers) { order++; if (answer.group == null) main.add(Menu.NONE, order, order++, answer.toString()) .setIntent(new Intent().putExtra("id", answer.id)); else { - if (!map.containsKey(answer.group)) - map.put(answer.group, main.addSubMenu(Menu.NONE, order, order++, answer.group)); SubMenu smenu = map.get(answer.group); smenu.add(Menu.NONE, smenu.size(), smenu.size() + 1, answer.toString()) .setIntent(new Intent().putExtra("id", answer.id));