update some functions related to pinning and hiding folders

This commit is contained in:
tibbi 2016-12-05 20:36:43 +01:00
parent b5b4e15990
commit 0857391189
3 changed files with 30 additions and 22 deletions

View file

@ -116,11 +116,11 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
true true
} }
R.id.hide_folder -> { R.id.hide_folder -> {
hideDirectory() hideFolder()
true true
} }
R.id.unhide_folder -> { R.id.unhide_folder -> {
unhideDirectory() unhideFolder()
true true
} }
else -> super.onOptionsItemSelected(item) else -> super.onOptionsItemSelected(item)
@ -138,8 +138,8 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
} }
} }
private fun hideDirectory() { private fun hideFolder() {
mConfig.addHiddenDirectory(mPath) mConfig.addHiddenFolder(mPath)
if (!mConfig.showHiddenFolders) if (!mConfig.showHiddenFolders)
finish() finish()
@ -147,8 +147,8 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
invalidateOptionsMenu() invalidateOptionsMenu()
} }
private fun unhideDirectory() { private fun unhideFolder() {
mConfig.removeHiddenDirectory(mPath) mConfig.removeHiddenFolder(mPath)
invalidateOptionsMenu() invalidateOptionsMenu()
} }

View file

@ -78,12 +78,12 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
true true
} }
R.id.cab_hide -> { R.id.cab_hide -> {
hideDirs() hideFolders()
mode.finish() mode.finish()
true true
} }
R.id.cab_unhide -> { R.id.cab_unhide -> {
unhideDir() unhideFolders()
mode.finish() mode.finish()
true true
} }
@ -163,13 +163,13 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
} }
} }
private fun hideDirs() { private fun hideFolders() {
config.addHiddenDirectories(getSelectedPaths()) config.addHiddenFolders(getSelectedPaths())
listener?.refreshItems() listener?.refreshItems()
} }
private fun unhideDir() { private fun unhideFolders() {
config.removeHiddenDirectories(getSelectedPaths()) config.removeHiddenFolders(getSelectedPaths())
listener?.refreshItems() listener?.refreshItems()
} }

View file

@ -43,25 +43,33 @@ class Config private constructor(context: Context) {
get() = mPrefs.getStringSet(PINNED_FOLDERS, HashSet<String>()) get() = mPrefs.getStringSet(PINNED_FOLDERS, HashSet<String>())
set(pinnedFolders) = mPrefs.edit().putStringSet(PINNED_FOLDERS, pinnedFolders).apply() set(pinnedFolders) = mPrefs.edit().putStringSet(PINNED_FOLDERS, pinnedFolders).apply()
fun addHiddenDirectory(path: String) { fun addPinnedFolders(paths: Set<String>) {
val currHiddenFolders = HashSet<String>(hiddenFolders) val currPinnedFolders = HashSet<String>(pinnedFolders)
currHiddenFolders.add(path) currPinnedFolders.addAll(paths)
hiddenFolders = currHiddenFolders pinnedFolders = currPinnedFolders
} }
fun addHiddenDirectories(paths: Set<String>) { fun removePinnedFolders(paths: Set<String>) {
val currPinnedFolders = HashSet<String>(pinnedFolders)
currPinnedFolders.removeAll(paths)
pinnedFolders = currPinnedFolders
}
fun addHiddenFolder(path: String) {
addHiddenFolders(HashSet<String>(Arrays.asList(path)))
}
fun addHiddenFolders(paths: Set<String>) {
val currHiddenFolders = HashSet<String>(hiddenFolders) val currHiddenFolders = HashSet<String>(hiddenFolders)
currHiddenFolders.addAll(paths) currHiddenFolders.addAll(paths)
hiddenFolders = currHiddenFolders hiddenFolders = currHiddenFolders
} }
fun removeHiddenDirectory(path: String) { fun removeHiddenFolder(path: String) {
val currHiddenFolders = HashSet<String>(hiddenFolders) removeHiddenFolders(HashSet<String>(Arrays.asList(path)))
currHiddenFolders.remove(path)
hiddenFolders = currHiddenFolders
} }
fun removeHiddenDirectories(paths: Set<String>) { fun removeHiddenFolders(paths: Set<String>) {
val currHiddenFolders = HashSet<String>(hiddenFolders) val currHiddenFolders = HashSet<String>(hiddenFolders)
currHiddenFolders.removeAll(paths) currHiddenFolders.removeAll(paths)
hiddenFolders = currHiddenFolders hiddenFolders = currHiddenFolders