Fixed submenu icons (2)

pull/194/merge
M66B 3 years ago
parent bc2af68449
commit aa849d6e56

@ -1537,7 +1537,7 @@ public class FragmentCompose extends FragmentBase {
inflater.inflate(R.menu.menu_compose, menu); inflater.inflate(R.menu.menu_compose, menu);
final Context context = getContext(); final Context context = getContext();
PopupMenuLifecycle.insertIcons(context, menu); PopupMenuLifecycle.insertIcons(context, menu, false);
LayoutInflater infl = LayoutInflater.from(context); LayoutInflater infl = LayoutInflater.from(context);
@ -1618,10 +1618,8 @@ public class FragmentCompose extends FragmentBase {
ssbZoom.append(' '); ssbZoom.append(' ');
for (int i = 0; i <= zoom; i++) for (int i = 0; i <= zoom; i++)
ssbZoom.append('+'); ssbZoom.append('+');
menu.findItem(R.id.menu_zoom) menu.findItem(R.id.menu_zoom).setTitle(ssbZoom);
.setTitle(ssbZoom) PopupMenuLifecycle.insertIcon(context, menu.findItem(R.id.menu_zoom), false);
.setIcon(R.drawable.twotone_format_size_24);
PopupMenuLifecycle.insertIcon(context, menu.findItem(R.id.menu_zoom));
int colorEncrypt = Helper.resolveColor(context, R.attr.colorEncrypt); int colorEncrypt = Helper.resolveColor(context, R.attr.colorEncrypt);
int colorActionForeground = Helper.resolveColor(context, R.attr.colorActionForeground); int colorActionForeground = Helper.resolveColor(context, R.attr.colorActionForeground);

@ -4385,7 +4385,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
inflater.inflate(R.menu.menu_messages, menu); inflater.inflate(R.menu.menu_messages, menu);
final Context context = getContext(); final Context context = getContext();
PopupMenuLifecycle.insertIcons(context, menu); PopupMenuLifecycle.insertIcons(context, menu, false);
LayoutInflater infl = LayoutInflater.from(context); LayoutInflater infl = LayoutInflater.from(context);
ImageButton ib = (ImageButton) infl.inflate(R.layout.action_button, null); 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_compact).setChecked(compact);
menu.findItem(R.id.menu_zoom) menu.findItem(R.id.menu_zoom).setTitle(ssbZoom);
.setTitle(ssbZoom) PopupMenuLifecycle.insertIcon(context, menu.findItem(R.id.menu_zoom), false);
.setIcon(R.drawable.twotone_format_size_24);
PopupMenuLifecycle.insertIcon(context, menu.findItem(R.id.menu_zoom));
menu.findItem(R.id.menu_padding) menu.findItem(R.id.menu_padding).setTitle(ssbPadding);
.setTitle(ssbPadding)
.setIcon(R.drawable.twotone_fullscreen_24);
menu.findItem(R.id.menu_padding).setVisible(cards); 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); menu.findItem(R.id.menu_theme).setVisible(viewType == AdapterMessage.ViewType.UNIFIED);

@ -59,7 +59,7 @@ public class PopupMenuLifecycle extends PopupMenu {
} }
public void insertIcons(Context context) { public void insertIcons(Context context) {
insertIcons(new ContextThemeWrapper(context, R.style.popupMenuStyle), getMenu()); insertIcons(new ContextThemeWrapper(context, R.style.popupMenuStyle), getMenu(), false);
} }
@Override @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++) { for (int i = 0; i < menu.size(); i++) {
MenuItem item = menu.getItem(i); MenuItem item = menu.getItem(i);
CharSequence title = item.getTitle(); CharSequence title = item.getTitle();
insertIcon(context, item); insertIcon(context, item, submenu);
if (item.hasSubMenu()) { if (item.hasSubMenu()) {
SubMenu sub = item.getSubMenu(); SubMenu sub = item.getSubMenu();
boolean has = false; boolean has = false;
for (int j = 0; j < sub.size(); j++) for (int j = 0; j < sub.size(); j++)
if (sub.getItem(j).getIcon() != null) { if (sub.getItem(j).getIcon() != null) {
has = true; has = true;
insertIcons(context, sub); insertIcons(context, sub, true);
break; break;
} }
if (has) 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(); Drawable icon = menuItem.getIcon();
if (icon == null) if (icon == null)
@ -136,7 +136,8 @@ public class PopupMenuLifecycle extends PopupMenu {
ssb.insert(0, "\uFFFC\u2002"); // object replacement character, en space ssb.insert(0, "\uFFFC\u2002"); // object replacement character, en space
ssb.setSpan(imageSpan, 0, 1, 0); ssb.setSpan(imageSpan, 0, 1, 0);
menuItem.setTitle(ssb); menuItem.setTitle(ssb);
menuItem.setIcon(null); if (submenu)
menuItem.setIcon(null);
menuItem.setTitleCondensed(""); menuItem.setTitleCondensed("");
} }
} }

Loading…
Cancel
Save