1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2025-01-19 05:38:31 +00:00

Sort answer groups

This commit is contained in:
M66B 2021-03-26 09:12:23 +01:00
parent bdb5d4d8a5
commit 2847dd1705
2 changed files with 26 additions and 5 deletions

View file

@ -1619,16 +1619,27 @@ public class FragmentCompose extends FragmentBase {
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(getContext(), getViewLifecycleOwner(), vwAnchorMenu);
Menu main = popupMenu.getMenu();
List<String> 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<String, SubMenu> 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));

View file

@ -2569,17 +2569,27 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(getContext(), getViewLifecycleOwner(), fabReply);
Menu main = popupMenu.getMenu();
Map<String, SubMenu> map = new HashMap<>();
List<String> 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<String, SubMenu> 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));