show Hide and Unhide menu items only when appropriate

This commit is contained in:
tibbi 2016-10-09 16:06:32 +02:00
parent ceb6b14250
commit c0a430c839

View file

@ -569,8 +569,25 @@ public class MainActivity extends SimpleActivity
@Override @Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) { public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
final MenuItem menuItem = menu.findItem(R.id.cab_edit); menu.findItem(R.id.cab_edit).setVisible(mSelectedItemsCnt == 1);
menuItem.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; return true;
} }
@ -586,9 +603,11 @@ public class MainActivity extends SimpleActivity
return true; return true;
case R.id.cab_hide: case R.id.cab_hide:
hideFolders(); hideFolders();
mode.finish();
return true; return true;
case R.id.cab_unhide: case R.id.cab_unhide:
unhideFolders(); unhideFolders();
mode.finish();
return true; return true;
default: default:
return false; return false;
@ -610,11 +629,11 @@ public class MainActivity extends SimpleActivity
} }
private void hideFolders() { private void hideFolders() {
initializeGallery();
} }
private void unhideFolders() { private void unhideFolders() {
initializeGallery();
} }
private void scanCompleted(final String path) { private void scanCompleted(final String path) {