From 18bad5106a689374fd7e57415d0a82e22784def5 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 17 Nov 2016 14:14:19 +0100 Subject: [PATCH] properly store hidden folders --- .../com/simplemobiletools/gallery/Config.kt | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/Config.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/Config.kt index 6266074a5..d3f1309ef 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/Config.kt @@ -40,35 +40,34 @@ class Config private constructor(context: Context) { set(showHiddenFolders) = mPrefs.edit().putBoolean(SHOW_HIDDEN_FOLDERS, showHiddenFolders).apply() fun addHiddenDirectory(path: String) { - val hiddenFolders = hiddenFolders - hiddenFolders.add(path) - mPrefs.edit().putStringSet(HIDDEN_FOLDERS, hiddenFolders).apply() + val currHiddenFolders = HashSet(hiddenFolders) + currHiddenFolders.add(path) + hiddenFolders = currHiddenFolders } fun addHiddenDirectories(paths: Set) { - val hiddenFolders = hiddenFolders - hiddenFolders.addAll(paths) - mPrefs.edit().putStringSet(HIDDEN_FOLDERS, hiddenFolders).apply() + val currHiddenFolders = HashSet(hiddenFolders) + currHiddenFolders.addAll(paths) + hiddenFolders = currHiddenFolders } fun removeHiddenDirectory(path: String) { - val hiddenFolders = hiddenFolders - hiddenFolders.remove(path) - mPrefs.edit().putStringSet(HIDDEN_FOLDERS, hiddenFolders).apply() + val currHiddenFolders = HashSet(hiddenFolders) + currHiddenFolders.remove(path) + hiddenFolders = currHiddenFolders } fun removeHiddenDirectories(paths: Set) { - val hiddenFolders = hiddenFolders - hiddenFolders.removeAll(paths) - mPrefs.edit().putStringSet(HIDDEN_FOLDERS, hiddenFolders).apply() + val currHiddenFolders = HashSet(hiddenFolders) + currHiddenFolders.removeAll(paths) + hiddenFolders = currHiddenFolders } - val hiddenFolders: MutableSet + fun getIsFolderHidden(path: String) = hiddenFolders.contains(path) + + var hiddenFolders: MutableSet get() = mPrefs.getStringSet(HIDDEN_FOLDERS, HashSet()) - - fun getIsFolderHidden(path: String): Boolean { - return hiddenFolders.contains(path) - } + set(hiddenFolders) = mPrefs.edit().remove(HIDDEN_FOLDERS).putStringSet(HIDDEN_FOLDERS, hiddenFolders).apply() var autoplayVideos: Boolean get() = mPrefs.getBoolean(AUTOPLAY_VIDEOS, false)