Kaynağa Gözat

simplify menu item filtering code

AndyScherzinger 7 yıl önce
ebeveyn
işleme
ce66e125e2

+ 18 - 72
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);
-        if (item != null) {
-            item.setVisible(false);
-            item.setEnabled(false);
-        }
+        // 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));
 
-        // additional restriction for this fragment
-        item = menu.findItem(R.id.action_select_all);
-        if (item != null) {
-            item.setVisible(false);
-            item.setEnabled(false);
+        // 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));
         }
 
-        // 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);
+        // share restrictions
+        if (getFile().isSharedWithMe() && !getFile().canReshare()) {
+            hideMenuItem(menu.findItem(R.id.action_send_share_file));
         }
+    }
 
-        // additional restriction for this fragment
-        item = menu.findItem(R.id.action_search);
+    private void hideMenuItem(MenuItem item) {
         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) {