android/source/src/java/org/libreoffice/ToolbarController.java | 22 ++-------- 1 file changed, 5 insertions(+), 17 deletions(-)
New commits: commit 8d015346d0ac21da7a4908ea35d2f736e9a0cc97 Author: Michael Weghorn <[email protected]> AuthorDate: Tue Nov 25 23:06:02 2025 +0100 Commit: Michael Weghorn <[email protected]> CommitDate: Wed Nov 26 06:27:04 2025 +0100 android: Have a single method for menu item (de)activation Instead of having one method that enables/disables a menu item and one that shows/hides it, let ToolbarController.setItemVisible take care of both. Use that method also where ToolbarController.enableMenuItem was used before and drop that now unused method. The way that hiding/disabling menu items was and is used is to do that when they are not applicable, in which case it seems reasonable to consistently both hide and disable them at the same time. Quoting from the MenuItem.setVisible doc [1]: > Sets the visibility of the menu item. Even if a menu item is not > visible, it may still be invoked via its shortcut (to completely disable > an item, set it to invisible and disabled). [1] https://developer.android.com/reference/android/view/MenuItem#setVisible(boolean) Change-Id: I5d05f5324a1fb5c69e38302b59b2ad56a45342ff Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194533 Tested-by: Jenkins Code-Style: Michael Weghorn <[email protected]> Reviewed-by: Michael Weghorn <[email protected]> diff --git a/android/source/src/java/org/libreoffice/ToolbarController.java b/android/source/src/java/org/libreoffice/ToolbarController.java index 6e88d90aa7ca..466de485489e 100644 --- a/android/source/src/java/org/libreoffice/ToolbarController.java +++ b/android/source/src/java/org/libreoffice/ToolbarController.java @@ -46,19 +46,6 @@ public class ToolbarController implements Toolbar.OnMenuItemClickListener { clipboardManager = (ClipboardManager)mContext.getSystemService(Context.CLIPBOARD_SERVICE); } - private void enableMenuItem(final int menuItemId, final boolean enabled) { - LOKitShell.getMainHandler().post(new Runnable() { - public void run() { - MenuItem menuItem = mMainMenu.findItem(menuItemId); - if (menuItem != null) { - menuItem.setEnabled(enabled); - } else { - Log.e(LOGTAG, "MenuItem not found."); - } - } - }); - } - public void setEditModeOn(boolean enabled) { isEditModeOn = enabled; } @@ -240,7 +227,7 @@ public class ToolbarController implements Toolbar.OnMenuItemClickListener { void setupToolbars() { if (LibreOfficeMainActivity.isExperimentalMode()) { boolean enableSaveEntry = !LibreOfficeMainActivity.isReadOnlyMode() && mContext.hasLocationForSave(); - enableMenuItem(R.id.action_save, enableSaveEntry); + setItemVisible(R.id.action_save, enableSaveEntry); if (LibreOfficeMainActivity.isReadOnlyMode()) { // show message in case experimental mode is enabled (i.e. editing is supported in general), // but current document is readonly @@ -252,15 +239,16 @@ public class ToolbarController implements Toolbar.OnMenuItemClickListener { setItemVisible(R.id.action_parts, mContext.isDrawerEnabled()); final boolean enablePrint = mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_PRINTING); - enableMenuItem(R.id.action_print, enablePrint); setItemVisible(R.id.action_print, enablePrint); } - public void setItemVisible(final int item, boolean visible){ + public void setItemVisible(final int item, boolean visible) { LOKitShell.getMainHandler().post(new Runnable() { @Override public void run() { - mMainMenu.findItem(item).setVisible(visible); + final MenuItem menuItem = mMainMenu.findItem(item); + menuItem.setEnabled(visible); + menuItem.setVisible(visible); } }); }
