From ce66e125e2dc677ff3b79b7e2f0dcddd20ecd203 Mon Sep 17 00:00:00 2001 From: AndyScherzinger Date: Fri, 4 May 2018 09:20:20 +0200 Subject: [PATCH] simplify menu item filtering code --- .../ui/fragment/FileDetailFragment.java | 100 ++++-------------- 1 file changed, 23 insertions(+), 77 deletions(-) diff --git a/src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java b/src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java index ca5ac90f07..14838214d6 100644 --- a/src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java +++ b/src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java @@ -259,87 +259,33 @@ public class FileDetailFragment extends FileFragment implements OnClickListener mf.filter(menu, true); } - // additional restriction for this fragment - MenuItem item = menu.findItem(R.id.action_see_details); + // restriction for this fragment + hideMenuItem(menu.findItem(R.id.action_see_details)); + hideMenuItem(menu.findItem(R.id.action_select_all)); + hideMenuItem(menu.findItem(R.id.action_move)); + hideMenuItem(menu.findItem(R.id.action_copy)); + hideMenuItem(menu.findItem(R.id.action_favorite)); + hideMenuItem(menu.findItem(R.id.action_unset_favorite)); + hideMenuItem(menu.findItem(R.id.action_search)); + + // dual pane restrictions + if (!getResources().getBoolean(R.bool.large_land_layout)){ + hideMenuItem(menu.findItem(R.id.action_switch_view)); + hideMenuItem(menu.findItem(R.id.action_sync_account)); + hideMenuItem(menu.findItem(R.id.action_sort)); + } + + // share restrictions + if (getFile().isSharedWithMe() && !getFile().canReshare()) { + hideMenuItem(menu.findItem(R.id.action_send_share_file)); + } + } + + private void hideMenuItem(MenuItem item) { if (item != null) { item.setVisible(false); item.setEnabled(false); } - - // additional restriction for this fragment - item = menu.findItem(R.id.action_select_all); - if (item != null) { - item.setVisible(false); - item.setEnabled(false); - } - - // additional restriction for this fragment - item = menu.findItem(R.id.action_move); - if (item != null) { - item.setVisible(false); - item.setEnabled(false); - } - - // additional restriction for this fragment - item = menu.findItem(R.id.action_copy); - if (item != null) { - item.setVisible(false); - item.setEnabled(false); - } - - // additional restriction for this fragment - item = menu.findItem(R.id.action_favorite); - if (item != null) { - item.setVisible(false); - item.setEnabled(false); - } - - // additional restriction for this fragment - item = menu.findItem(R.id.action_unset_favorite); - if (item != null) { - item.setVisible(false); - item.setEnabled(false); - } - - // additional restriction for this fragment - item = menu.findItem(R.id.action_search); - if (item != null) { - item.setVisible(false); - item.setEnabled(false); - } - - - Boolean dualPane = getResources().getBoolean(R.bool.large_land_layout); - - item = menu.findItem(R.id.action_switch_view); - if (item != null && !dualPane){ - item.setVisible(false); - item.setEnabled(false); - } - - item = menu.findItem(R.id.action_sync_account); - if (item != null && !dualPane) { - item.setVisible(false); - item.setEnabled(false); - } - - item = menu.findItem(R.id.action_sort); - if (item != null && !dualPane) { - item.setVisible(false); - item.setEnabled(false); - } - - item = menu.findItem(R.id.action_send_share_file); - if (item != null) { - ThemeUtils.tintDrawable(item.getIcon(), ThemeUtils.fontColor(getContext())); - item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); - if (getFile().isSharedWithMe() && !getFile().canReshare()) { - // additional restriction for this fragment - - item.setVisible(false); - item.setEnabled(false); - } - } } public boolean optionsItemSelected(MenuItem item) {