From c0a430c8396efa210712997f98cee9a29011a3c7 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 9 Oct 2016 16:06:32 +0200 Subject: [PATCH] show Hide and Unhide menu items only when appropriate --- .../gallery/activities/MainActivity.java | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java index 1443b0fb3..f65295fc6 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java @@ -569,8 +569,25 @@ public class MainActivity extends SimpleActivity @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { - final MenuItem menuItem = menu.findItem(R.id.cab_edit); - menuItem.setVisible(mSelectedItemsCnt == 1); + menu.findItem(R.id.cab_edit).setVisible(mSelectedItemsCnt == 1); + + int hiddenCnt = 0; + int unhiddenCnt = 0; + final SparseBooleanArray items = mGridView.getCheckedItemPositions(); + final int cnt = items.size(); + for (int i = 0; i < cnt; i++) { + if (items.valueAt(i)) { + final int id = items.keyAt(i); + if (mConfig.getIsFolderHidden(mDirs.get(id).getPath())) + hiddenCnt++; + else + unhiddenCnt++; + } + } + + menu.findItem(R.id.cab_hide).setVisible(unhiddenCnt > 0); + menu.findItem(R.id.cab_unhide).setVisible(hiddenCnt > 0); + return true; } @@ -586,9 +603,11 @@ public class MainActivity extends SimpleActivity return true; case R.id.cab_hide: hideFolders(); + mode.finish(); return true; case R.id.cab_unhide: unhideFolders(); + mode.finish(); return true; default: return false; @@ -610,11 +629,11 @@ public class MainActivity extends SimpleActivity } private void hideFolders() { - + initializeGallery(); } private void unhideFolders() { - + initializeGallery(); } private void scanCompleted(final String path) {