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)