From dd56ad86d73f97deb39b4146420bafc4d21b7b55 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 17 Aug 2021 19:32:54 +0200 Subject: [PATCH] Added favorite answers menu separator --- .../main/java/eu/faircode/email/FragmentCompose.java | 11 +++++++---- .../java/eu/faircode/email/FragmentMessages.java | 12 ++++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index db5a8ae603..cf204031aa 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -1803,6 +1803,7 @@ public class FragmentCompose extends FragmentBase { return; } + boolean grouped = BuildConfig.DEBUG; PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(getContext(), getViewLifecycleOwner(), vwAnchorMenu); Menu main = popupMenu.getMenu(); @@ -1821,7 +1822,7 @@ public class FragmentCompose extends FragmentBase { Collections.sort(answers, new Comparator() { @Override public int compare(EntityAnswer a1, EntityAnswer a2) { - if (!BuildConfig.DEBUG || a1.applied.equals(a2.applied)) + if (!grouped || a1.applied.equals(a2.applied)) return collator.compare(a1.name, a2.name); else return -a1.applied.compareTo(a2.applied); @@ -1847,15 +1848,14 @@ public class FragmentCompose extends FragmentBase { order++; String name = answer.name; - if (BuildConfig.DEBUG && answer.applied > 0) - name += " ★"; MenuItem item; if (answer.group == null) item = main.add(Menu.NONE, order, order++, name); else { SubMenu smenu = map.get(answer.group); - item = smenu.add(Menu.NONE, smenu.size(), smenu.size() + 1, name); + item = smenu.add(answer.applied > 0 ? Menu.FIRST : Menu.NONE, + smenu.size(), smenu.size() + 1, name); } item.setIntent(new Intent().putExtra("id", answer.id)); } @@ -1922,6 +1922,9 @@ public class FragmentCompose extends FragmentBase { } } + if (grouped) + MenuCompat.setGroupDividerEnabled(popupMenu.getMenu(), true); + popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem target) { diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 80b77cf195..715733c6e6 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -122,6 +122,7 @@ import androidx.appcompat.app.AlertDialog; import androidx.appcompat.widget.PopupMenu; import androidx.constraintlayout.widget.Group; import androidx.core.graphics.ColorUtils; +import androidx.core.view.MenuCompat; import androidx.core.view.MenuItemCompat; import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; @@ -2744,6 +2745,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. }); snackbar.show(); } else { + boolean grouped = BuildConfig.DEBUG; PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(getContext(), getViewLifecycleOwner(), fabReply); Menu main = popupMenu.getMenu(); @@ -2759,7 +2761,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. Collections.sort(answers, new Comparator() { @Override public int compare(EntityAnswer a1, EntityAnswer a2) { - if (!BuildConfig.DEBUG || a1.applied.equals(a2.applied)) + if (!grouped || a1.applied.equals(a2.applied)) return collator.compare(a1.name, a2.name); else return -a1.applied.compareTo(a2.applied); @@ -2776,19 +2778,21 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. order++; String name = answer.name; - if (BuildConfig.DEBUG && answer.applied > 0) - name += " ★"; MenuItem item; if (answer.group == null) item = main.add(Menu.NONE, order, order++, name); else { SubMenu smenu = map.get(answer.group); - item = smenu.add(Menu.NONE, smenu.size(), smenu.size() + 1, name); + item = smenu.add(answer.applied > 0 ? Menu.FIRST : Menu.NONE, + smenu.size(), smenu.size() + 1, name); } item.setIntent(new Intent().putExtra("id", answer.id)); } + if (grouped) + MenuCompat.setGroupDividerEnabled(popupMenu.getMenu(), true); + popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem target) {