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

85 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) {
val hiddenFolders = hiddenFolders
hiddenFolders.add(path)
2016-11-13 23:13:41 +01:00
mPrefs.edit().putStringSet(HIDDEN_FOLDERS, hiddenFolders).apply()
2016-11-13 10:58:10 +01:00
}
fun addHiddenDirectories(paths: Set<String>) {
val hiddenFolders = hiddenFolders
hiddenFolders.addAll(paths)
2016-11-13 23:13:41 +01:00
mPrefs.edit().putStringSet(HIDDEN_FOLDERS, hiddenFolders).apply()
2016-11-13 10:58:10 +01:00
}
fun removeHiddenDirectory(path: String) {
val hiddenFolders = hiddenFolders
hiddenFolders.remove(path)
2016-11-13 23:13:41 +01:00
mPrefs.edit().putStringSet(HIDDEN_FOLDERS, hiddenFolders).apply()
2016-11-13 10:58:10 +01:00
}
fun removeHiddenDirectories(paths: Set<String>) {
val hiddenFolders = hiddenFolders
hiddenFolders.removeAll(paths)
2016-11-13 23:13:41 +01:00
mPrefs.edit().putStringSet(HIDDEN_FOLDERS, hiddenFolders).apply()
2016-11-13 10:58:10 +01:00
}
val hiddenFolders: MutableSet<String>
2016-11-13 23:13:41 +01:00
get() = mPrefs.getStringSet(HIDDEN_FOLDERS, HashSet<String>())
2016-11-13 10:58:10 +01:00
fun getIsFolderHidden(path: String): Boolean {
return hiddenFolders.contains(path)
}
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
}