FossifyGallery/app/src/main/kotlin/com/simplemobiletools/gallery/Config.kt

84 lines
3.1 KiB
Kotlin
Raw Normal View History

2016-11-13 10:58:10 +01:00
package com.simplemobiletools.gallery
import android.content.Context
import android.content.SharedPreferences
import java.util.*
class Config private constructor(context: Context) {
private val mPrefs: SharedPreferences
companion object {
2016-11-14 18:55:48 +01:00
fun newInstance(context: Context) = Config(context)
2016-11-13 10:58:10 +01:00
}
init {
2016-11-13 23:13:41 +01:00
mPrefs = context.getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE)
2016-11-13 10:58:10 +01:00
}
var isFirstRun: Boolean
2016-11-13 23:13:41 +01:00
get() = mPrefs.getBoolean(IS_FIRST_RUN, true)
set(isFirstRun) = mPrefs.edit().putBoolean(IS_FIRST_RUN, isFirstRun).apply()
2016-11-13 10:58:10 +01:00
var isDarkTheme: Boolean
2016-11-13 23:13:41 +01:00
get() = mPrefs.getBoolean(IS_DARK_THEME, true)
set(isDarkTheme) = mPrefs.edit().putBoolean(IS_DARK_THEME, isDarkTheme).apply()
2016-11-13 10:58:10 +01:00
var isSameSorting: Boolean
2016-11-13 23:13:41 +01:00
get() = mPrefs.getBoolean(IS_SAME_SORTING, true)
set(isSameSorting) = mPrefs.edit().putBoolean(IS_SAME_SORTING, isSameSorting).apply()
2016-11-13 10:58:10 +01:00
var sorting: Int
2016-11-13 23:13:41 +01:00
get() = if (isSameSorting) directorySorting else mPrefs.getInt(SORT_ORDER, SORT_BY_DATE or SORT_DESCENDING)
set(order) = if (isSameSorting) directorySorting = order else mPrefs.edit().putInt(SORT_ORDER, order).apply()
2016-11-13 10:58:10 +01:00
var directorySorting: Int
2016-11-13 23:13:41 +01:00
get() = mPrefs.getInt(DIRECTORY_SORT_ORDER, SORT_BY_DATE or SORT_DESCENDING)
set(order) = mPrefs.edit().putInt(DIRECTORY_SORT_ORDER, order).apply()
2016-11-13 10:58:10 +01:00
var showHiddenFolders: Boolean
2016-11-13 23:13:41 +01:00
get() = mPrefs.getBoolean(SHOW_HIDDEN_FOLDERS, false)
set(showHiddenFolders) = mPrefs.edit().putBoolean(SHOW_HIDDEN_FOLDERS, showHiddenFolders).apply()
2016-11-13 10:58:10 +01:00
fun addHiddenDirectory(path: String) {
2016-11-17 14:14:19 +01:00
val currHiddenFolders = HashSet<String>(hiddenFolders)
currHiddenFolders.add(path)
hiddenFolders = currHiddenFolders
2016-11-13 10:58:10 +01:00
}
fun addHiddenDirectories(paths: Set<String>) {
2016-11-17 14:14:19 +01:00
val currHiddenFolders = HashSet<String>(hiddenFolders)
currHiddenFolders.addAll(paths)
hiddenFolders = currHiddenFolders
2016-11-13 10:58:10 +01:00
}
fun removeHiddenDirectory(path: String) {
2016-11-17 14:14:19 +01:00
val currHiddenFolders = HashSet<String>(hiddenFolders)
currHiddenFolders.remove(path)
hiddenFolders = currHiddenFolders
2016-11-13 10:58:10 +01:00
}
fun removeHiddenDirectories(paths: Set<String>) {
2016-11-17 14:14:19 +01:00
val currHiddenFolders = HashSet<String>(hiddenFolders)
currHiddenFolders.removeAll(paths)
hiddenFolders = currHiddenFolders
2016-11-13 10:58:10 +01:00
}
2016-11-17 14:14:19 +01:00
fun getIsFolderHidden(path: String) = hiddenFolders.contains(path)
2016-11-13 10:58:10 +01:00
2016-11-17 14:14:19 +01:00
var hiddenFolders: MutableSet<String>
get() = mPrefs.getStringSet(HIDDEN_FOLDERS, HashSet<String>())
set(hiddenFolders) = mPrefs.edit().remove(HIDDEN_FOLDERS).putStringSet(HIDDEN_FOLDERS, hiddenFolders).apply()
2016-11-13 10:58:10 +01:00
var autoplayVideos: Boolean
2016-11-13 23:13:41 +01:00
get() = mPrefs.getBoolean(AUTOPLAY_VIDEOS, false)
set(autoplay) = mPrefs.edit().putBoolean(AUTOPLAY_VIDEOS, autoplay).apply()
2016-11-13 10:58:10 +01:00
var treeUri: String
2016-11-13 23:13:41 +01:00
get() = mPrefs.getString(TREE_URI, "")
set(uri) = mPrefs.edit().putString(TREE_URI, uri).apply()
2016-11-13 10:58:10 +01:00
var displayFileNames: Boolean
2016-11-13 23:13:41 +01:00
get() = mPrefs.getBoolean(DISPLAY_FILE_NAMES, false)
set(display) = mPrefs.edit().putBoolean(DISPLAY_FILE_NAMES, display).apply()
2016-11-13 10:58:10 +01:00
}