From 3cf23474e328aafda2b0a87823a2fdc32784821f Mon Sep 17 00:00:00 2001 From: sk Date: Sun, 22 Oct 2023 22:10:25 +0200 Subject: [PATCH] fix issue with too-wide context menu icons closes sk22#893 --- .../displayitems/HeaderStatusDisplayItem.java | 3 ++- .../android/ui/utils/UiUtils.java | 23 +++++++++++++------ .../ic_fluent_prohibited_24_regular.xml | 3 --- 3 files changed, 18 insertions(+), 11 deletions(-) delete mode 100644 mastodon/src/main/res/drawable/ic_fluent_prohibited_24_regular.xml diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/HeaderStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/HeaderStatusDisplayItem.java index 408a610813..6f1b95c2af 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/HeaderStatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/HeaderStatusDisplayItem.java @@ -546,7 +546,8 @@ private void updateOptionsMenu(){ follow.setIcon(following ? R.drawable.ic_fluent_person_delete_24_regular : R.drawable.ic_fluent_person_add_24_regular); manageUserLists.setVisible(relationship != null && relationship.following); manageUserLists.setTitle(item.parentFragment.getString(R.string.sk_lists_with_user, username)); - UiUtils.insetPopupMenuIcon(item.parentFragment.getContext(), follow); + // ic_fluent_person_add_24_regular actually has a width of 25dp -.- + UiUtils.insetPopupMenuIcon(item.parentFragment.getContext(), follow, following ? 0 : V.dp(-1)); } workaroundChangingMenuItemWidths(menu, username); diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java b/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java index 325618145c..f139d756e0 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java @@ -906,17 +906,26 @@ public static Bitmap getBitmapFromDrawable(Drawable d) { } public static void insetPopupMenuIcon(Context context, MenuItem item) { + insetPopupMenuIcon(context, item, 0); + } + + public static void insetPopupMenuIcon(Context context, MenuItem item, int addWidth) { ColorStateList iconTint = ColorStateList.valueOf(UiUtils.getThemeColor(context, android.R.attr.textColorSecondary)); - insetPopupMenuIcon(item, iconTint); + insetPopupMenuIcon(item, iconTint, addWidth); } - public static void insetPopupMenuIcon(MenuItem item, ColorStateList iconTint) { - Drawable icon = item.getIcon().mutate(); - if (Build.VERSION.SDK_INT >= 26) item.setIconTintList(iconTint); + /** + * @param addWidth set if icon is too wide/narrow. if icon is 25dp in width, set to -1dp + */ + public static void insetPopupMenuIcon(MenuItem item, ColorStateList iconTint, int addWidth) { + Drawable icon=item.getIcon().mutate(); + if(Build.VERSION.SDK_INT>=26) item.setIconTintList(iconTint); else icon.setTintList(iconTint); - icon = new InsetDrawable(icon, V.dp(8), 0, V.dp(8), 0); + int pad=V.dp(8); + boolean rtl=icon.getLayoutDirection()==View.LAYOUT_DIRECTION_RTL; + icon=new InsetDrawable(icon, rtl ? pad+addWidth : pad, 0, rtl ? pad : addWidth+pad, 0); item.setIcon(icon); - SpannableStringBuilder ssb = new SpannableStringBuilder(item.getTitle()); + SpannableStringBuilder ssb = new SpannableStringBuilder(item.getTitle()); item.setTitle(ssb); } @@ -950,7 +959,7 @@ public static void enableMenuIcons(Context context, Menu m, @IdRes int... exclud if (subMenu != null) enableMenuIcons(context, subMenu, exclude); if (item.getIcon() == null || Arrays.stream(exclude).anyMatch(id -> id == item.getItemId())) continue; - insetPopupMenuIcon(item, iconTint); + insetPopupMenuIcon(item, iconTint, 0); } } diff --git a/mastodon/src/main/res/drawable/ic_fluent_prohibited_24_regular.xml b/mastodon/src/main/res/drawable/ic_fluent_prohibited_24_regular.xml deleted file mode 100644 index e971bcf5db..0000000000 --- a/mastodon/src/main/res/drawable/ic_fluent_prohibited_24_regular.xml +++ /dev/null @@ -1,3 +0,0 @@ - - -