diff --git a/app/src/main/java/eu/faircode/email/EntityAnswer.java b/app/src/main/java/eu/faircode/email/EntityAnswer.java index 21b2bc259b..51a6c7479f 100644 --- a/app/src/main/java/eu/faircode/email/EntityAnswer.java +++ b/app/src/main/java/eu/faircode/email/EntityAnswer.java @@ -167,18 +167,35 @@ public class EntityAnswer implements Serializable { boolean grouped = BuildConfig.DEBUG; int iconSize = context.getResources().getDimensionPixelSize(R.dimen.menu_item_icon_size); + NumberFormat NF = NumberFormat.getNumberInstance(); List favorites = new ArrayList<>(); - List groups = new ArrayList<>(); + Map groupApplied = new HashMap<>(); for (EntityAnswer answer : answers) if (compose && answer.favorite) favorites.add(answer); - else if (answer.group != null && !groups.contains(answer.group)) - groups.add(answer.group); + else if (answer.group != null) { + Integer total = groupApplied.get(answer.group); + if (total == null) + total = 0; + groupApplied.put(answer.group, total + answer.applied); + } Collator collator = Collator.getInstance(Locale.getDefault()); collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc - Collections.sort(groups, collator); + + List groups = new ArrayList<>(groupApplied.keySet()); + Collections.sort(groups, new Comparator() { + @Override + public int compare(String g1, String g2) { + Integer a1 = groupApplied.get(g1); + Integer a2 = groupApplied.get(g2); + if (!grouped || a1.equals(a2)) + return collator.compare(g1, g2); + else + return -a1.compareTo(a2); + } + }); Collections.sort(answers, new Comparator() { @Override @@ -200,10 +217,20 @@ public class EntityAnswer implements Serializable { int order = 0; Map map = new HashMap<>(); - for (String group : groups) - map.put(group, main.addSubMenu(Menu.NONE, order, order++, group)); + for (String group : groups) { + SpannableStringBuilder ssb = new SpannableStringBuilderEx(group); + + int total = groupApplied.get(group); + if (grouped && total > 0) { + int start = ssb.length(); + ssb.append(" (").append(NF.format(total)).append(")"); + ssb.setSpan(new RelativeSizeSpan(HtmlHelper.FONT_SMALL), + start, ssb.length(), 0); + } + + map.put(group, main.addSubMenu(Menu.NONE, order, order++, ssb)); + } - NumberFormat NF = NumberFormat.getNumberInstance(); for (EntityAnswer answer : answers) { if (compose && answer.favorite) continue;