allow toggling the visibility of multiple folders at once

This commit is contained in:
tibbi 2016-10-09 16:12:40 +02:00
parent c0a430c839
commit e51ff13da7
2 changed files with 28 additions and 0 deletions

View file

@ -77,12 +77,24 @@ public class Config {
mPrefs.edit().putStringSet(Constants.HIDDEN_FOLDERS, hiddenFolders).apply(); mPrefs.edit().putStringSet(Constants.HIDDEN_FOLDERS, hiddenFolders).apply();
} }
public void addHiddenDirectories(Set<String> paths) {
final Set<String> hiddenFolders = getHiddenFolders();
hiddenFolders.addAll(paths);
mPrefs.edit().putStringSet(Constants.HIDDEN_FOLDERS, hiddenFolders).apply();
}
public void removeHiddenDirectory(String path) { public void removeHiddenDirectory(String path) {
final Set<String> hiddenFolders = getHiddenFolders(); final Set<String> hiddenFolders = getHiddenFolders();
hiddenFolders.remove(path); hiddenFolders.remove(path);
mPrefs.edit().putStringSet(Constants.HIDDEN_FOLDERS, hiddenFolders).apply(); mPrefs.edit().putStringSet(Constants.HIDDEN_FOLDERS, hiddenFolders).apply();
} }
public void removeHiddenDirectories(Set<String> paths) {
final Set<String> hiddenFolders = getHiddenFolders();
hiddenFolders.removeAll(paths);
mPrefs.edit().putStringSet(Constants.HIDDEN_FOLDERS, hiddenFolders).apply();
}
public Set<String> getHiddenFolders() { public Set<String> getHiddenFolders() {
return mPrefs.getStringSet(Constants.HIDDEN_FOLDERS, new HashSet<String>()); return mPrefs.getStringSet(Constants.HIDDEN_FOLDERS, new HashSet<String>());
} }

View file

@ -40,6 +40,7 @@ import java.io.File;
import java.io.FilenameFilter; import java.io.FilenameFilter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -629,13 +630,28 @@ public class MainActivity extends SimpleActivity
} }
private void hideFolders() { private void hideFolders() {
mConfig.addHiddenDirectories(getSelectedPaths());
initializeGallery(); initializeGallery();
} }
private void unhideFolders() { private void unhideFolders() {
mConfig.removeHiddenDirectories(getSelectedPaths());
initializeGallery(); initializeGallery();
} }
private Set<String> getSelectedPaths() {
final SparseBooleanArray items = mGridView.getCheckedItemPositions();
final Set<String> selectedPaths = new HashSet<>();
final int cnt = items.size();
for (int i = 0; i < cnt; i++) {
if (items.valueAt(i)) {
final int id = items.keyAt(i);
selectedPaths.add(mDirs.get(id).getPath());
}
}
return selectedPaths;
}
private void scanCompleted(final String path) { private void scanCompleted(final String path) {
final File dir = new File(path); final File dir = new File(path);
if (dir.isDirectory()) { if (dir.isDirectory()) {