From aa849d6e56d0e66293ae14c8a76245c5c536102d Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 11 Nov 2021 10:41:08 +0100 Subject: [PATCH] Fixed submenu icons (2) --- .../java/eu/faircode/email/FragmentCompose.java | 8 +++----- .../java/eu/faircode/email/FragmentMessages.java | 14 +++++--------- .../java/eu/faircode/email/PopupMenuLifecycle.java | 13 +++++++------ 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 66979eb2f5..35ff475884 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -1537,7 +1537,7 @@ public class FragmentCompose extends FragmentBase { inflater.inflate(R.menu.menu_compose, menu); final Context context = getContext(); - PopupMenuLifecycle.insertIcons(context, menu); + PopupMenuLifecycle.insertIcons(context, menu, false); LayoutInflater infl = LayoutInflater.from(context); @@ -1618,10 +1618,8 @@ public class FragmentCompose extends FragmentBase { ssbZoom.append(' '); for (int i = 0; i <= zoom; i++) ssbZoom.append('+'); - menu.findItem(R.id.menu_zoom) - .setTitle(ssbZoom) - .setIcon(R.drawable.twotone_format_size_24); - PopupMenuLifecycle.insertIcon(context, menu.findItem(R.id.menu_zoom)); + menu.findItem(R.id.menu_zoom).setTitle(ssbZoom); + PopupMenuLifecycle.insertIcon(context, menu.findItem(R.id.menu_zoom), false); int colorEncrypt = Helper.resolveColor(context, R.attr.colorEncrypt); int colorActionForeground = Helper.resolveColor(context, R.attr.colorActionForeground); diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 1d333b9c5d..6503e95ba7 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -4385,7 +4385,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. inflater.inflate(R.menu.menu_messages, menu); final Context context = getContext(); - PopupMenuLifecycle.insertIcons(context, menu); + PopupMenuLifecycle.insertIcons(context, menu, false); LayoutInflater infl = LayoutInflater.from(context); ImageButton ib = (ImageButton) infl.inflate(R.layout.action_button, null); @@ -4537,16 +4537,12 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. menu.findItem(R.id.menu_compact).setChecked(compact); - menu.findItem(R.id.menu_zoom) - .setTitle(ssbZoom) - .setIcon(R.drawable.twotone_format_size_24); - PopupMenuLifecycle.insertIcon(context, menu.findItem(R.id.menu_zoom)); + menu.findItem(R.id.menu_zoom).setTitle(ssbZoom); + PopupMenuLifecycle.insertIcon(context, menu.findItem(R.id.menu_zoom), false); - menu.findItem(R.id.menu_padding) - .setTitle(ssbPadding) - .setIcon(R.drawable.twotone_fullscreen_24); + menu.findItem(R.id.menu_padding).setTitle(ssbPadding); menu.findItem(R.id.menu_padding).setVisible(cards); - PopupMenuLifecycle.insertIcon(context, menu.findItem(R.id.menu_padding)); + PopupMenuLifecycle.insertIcon(context, menu.findItem(R.id.menu_padding), false); menu.findItem(R.id.menu_theme).setVisible(viewType == AdapterMessage.ViewType.UNIFIED); diff --git a/app/src/main/java/eu/faircode/email/PopupMenuLifecycle.java b/app/src/main/java/eu/faircode/email/PopupMenuLifecycle.java index e7026facaf..5ce98ed3c3 100644 --- a/app/src/main/java/eu/faircode/email/PopupMenuLifecycle.java +++ b/app/src/main/java/eu/faircode/email/PopupMenuLifecycle.java @@ -59,7 +59,7 @@ public class PopupMenuLifecycle extends PopupMenu { } public void insertIcons(Context context) { - insertIcons(new ContextThemeWrapper(context, R.style.popupMenuStyle), getMenu()); + insertIcons(new ContextThemeWrapper(context, R.style.popupMenuStyle), getMenu(), false); } @Override @@ -95,18 +95,18 @@ public class PopupMenuLifecycle extends PopupMenu { }); } - static void insertIcons(Context context, Menu menu) { + static void insertIcons(Context context, Menu menu, boolean submenu) { for (int i = 0; i < menu.size(); i++) { MenuItem item = menu.getItem(i); CharSequence title = item.getTitle(); - insertIcon(context, item); + insertIcon(context, item, submenu); if (item.hasSubMenu()) { SubMenu sub = item.getSubMenu(); boolean has = false; for (int j = 0; j < sub.size(); j++) if (sub.getItem(j).getIcon() != null) { has = true; - insertIcons(context, sub); + insertIcons(context, sub, true); break; } if (has) @@ -115,7 +115,7 @@ public class PopupMenuLifecycle extends PopupMenu { } } - static void insertIcon(Context context, MenuItem menuItem) { + static void insertIcon(Context context, MenuItem menuItem, boolean submenu) { Drawable icon = menuItem.getIcon(); if (icon == null) @@ -136,7 +136,8 @@ public class PopupMenuLifecycle extends PopupMenu { ssb.insert(0, "\uFFFC\u2002"); // object replacement character, en space ssb.setSpan(imageSpan, 0, 1, 0); menuItem.setTitle(ssb); - menuItem.setIcon(null); + if (submenu) + menuItem.setIcon(null); menuItem.setTitleCondensed(""); } }