use the inherited prefs variable for shared preferences

This commit is contained in:
tibbi 2016-12-26 21:54:00 +01:00
parent b33d0d54e6
commit 60739762b0

View file

@ -1,45 +1,38 @@
package com.simplemobiletools.gallery.helpers package com.simplemobiletools.gallery.helpers
import android.content.Context import android.content.Context
import android.content.SharedPreferences
import com.simplemobiletools.commons.helpers.BaseConfig import com.simplemobiletools.commons.helpers.BaseConfig
import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.R
import java.util.* import java.util.*
class Config(context: Context) : BaseConfig(context) { class Config(context: Context) : BaseConfig(context) {
private val mPrefs: SharedPreferences
companion object { companion object {
fun newInstance(context: Context) = Config(context) fun newInstance(context: Context) = Config(context)
} }
init {
mPrefs = context.getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE)
}
var isSameSorting: Boolean var isSameSorting: Boolean
get() = mPrefs.getBoolean(IS_SAME_SORTING, true) get() = prefs.getBoolean(IS_SAME_SORTING, true)
set(isSameSorting) = mPrefs.edit().putBoolean(IS_SAME_SORTING, isSameSorting).apply() set(isSameSorting) = prefs.edit().putBoolean(IS_SAME_SORTING, isSameSorting).apply()
var fileSorting: Int var fileSorting: Int
get() = if (isSameSorting) directorySorting else mPrefs.getInt(SORT_ORDER, SORT_BY_DATE_MODIFIED or SORT_DESCENDING) get() = if (isSameSorting) directorySorting else prefs.getInt(SORT_ORDER, SORT_BY_DATE_MODIFIED or SORT_DESCENDING)
set(order) = if (isSameSorting) directorySorting = order else mPrefs.edit().putInt(SORT_ORDER, order).apply() set(order) = if (isSameSorting) directorySorting = order else prefs.edit().putInt(SORT_ORDER, order).apply()
var directorySorting: Int var directorySorting: Int
get() = mPrefs.getInt(DIRECTORY_SORT_ORDER, SORT_BY_DATE_MODIFIED or SORT_DESCENDING) get() = prefs.getInt(DIRECTORY_SORT_ORDER, SORT_BY_DATE_MODIFIED or SORT_DESCENDING)
set(order) = mPrefs.edit().putInt(DIRECTORY_SORT_ORDER, order).apply() set(order) = prefs.edit().putInt(DIRECTORY_SORT_ORDER, order).apply()
var showHiddenFolders: Boolean var showHiddenFolders: Boolean
get() = mPrefs.getBoolean(SHOW_HIDDEN_FOLDERS, false) get() = prefs.getBoolean(SHOW_HIDDEN_FOLDERS, false)
set(showHiddenFolders) = mPrefs.edit().putBoolean(SHOW_HIDDEN_FOLDERS, showHiddenFolders).apply() set(showHiddenFolders) = prefs.edit().putBoolean(SHOW_HIDDEN_FOLDERS, showHiddenFolders).apply()
var pinnedFolders: Set<String> var pinnedFolders: Set<String>
get() = mPrefs.getStringSet(PINNED_FOLDERS, HashSet<String>()) get() = prefs.getStringSet(PINNED_FOLDERS, HashSet<String>())
set(pinnedFolders) = mPrefs.edit().putStringSet(PINNED_FOLDERS, pinnedFolders).apply() set(pinnedFolders) = prefs.edit().putStringSet(PINNED_FOLDERS, pinnedFolders).apply()
var showAll: Boolean var showAll: Boolean
get() = mPrefs.getBoolean(SHOW_ALL, false) get() = prefs.getBoolean(SHOW_ALL, false)
set(showAll) = mPrefs.edit().putBoolean(SHOW_ALL, showAll).apply() set(showAll) = prefs.edit().putBoolean(SHOW_ALL, showAll).apply()
fun addPinnedFolders(paths: Set<String>) { fun addPinnedFolders(paths: Set<String>) {
val currPinnedFolders = HashSet<String>(pinnedFolders) val currPinnedFolders = HashSet<String>(pinnedFolders)
@ -76,26 +69,26 @@ class Config(context: Context) : BaseConfig(context) {
fun getIsFolderHidden(path: String) = hiddenFolders.contains(path) fun getIsFolderHidden(path: String) = hiddenFolders.contains(path)
var hiddenFolders: MutableSet<String> var hiddenFolders: MutableSet<String>
get() = mPrefs.getStringSet(HIDDEN_FOLDERS, HashSet<String>()) get() = prefs.getStringSet(HIDDEN_FOLDERS, HashSet<String>())
set(hiddenFolders) = mPrefs.edit().remove(HIDDEN_FOLDERS).putStringSet(HIDDEN_FOLDERS, hiddenFolders).apply() set(hiddenFolders) = prefs.edit().remove(HIDDEN_FOLDERS).putStringSet(HIDDEN_FOLDERS, hiddenFolders).apply()
var autoplayVideos: Boolean var autoplayVideos: Boolean
get() = mPrefs.getBoolean(AUTOPLAY_VIDEOS, false) get() = prefs.getBoolean(AUTOPLAY_VIDEOS, false)
set(autoplay) = mPrefs.edit().putBoolean(AUTOPLAY_VIDEOS, autoplay).apply() set(autoplay) = prefs.edit().putBoolean(AUTOPLAY_VIDEOS, autoplay).apply()
var displayFileNames: Boolean var displayFileNames: Boolean
get() = mPrefs.getBoolean(DISPLAY_FILE_NAMES, false) get() = prefs.getBoolean(DISPLAY_FILE_NAMES, false)
set(display) = mPrefs.edit().putBoolean(DISPLAY_FILE_NAMES, display).apply() set(display) = prefs.edit().putBoolean(DISPLAY_FILE_NAMES, display).apply()
var showMedia: Int var showMedia: Int
get() = mPrefs.getInt(SHOW_MEDIA, IMAGES_AND_VIDEOS) get() = prefs.getInt(SHOW_MEDIA, IMAGES_AND_VIDEOS)
set(showMedia) = mPrefs.edit().putInt(SHOW_MEDIA, showMedia).apply() set(showMedia) = prefs.edit().putInt(SHOW_MEDIA, showMedia).apply()
var dirColumnCnt: Int var dirColumnCnt: Int
get() = mPrefs.getInt(DIR_COLUMN_CNT, context.resources.getInteger(R.integer.directory_columns)) get() = prefs.getInt(DIR_COLUMN_CNT, context.resources.getInteger(R.integer.directory_columns))
set(dirColumnCnt) = mPrefs.edit().putInt(DIR_COLUMN_CNT, dirColumnCnt).apply() set(dirColumnCnt) = prefs.edit().putInt(DIR_COLUMN_CNT, dirColumnCnt).apply()
var mediaColumnCnt: Int var mediaColumnCnt: Int
get() = mPrefs.getInt(MEDIA_COLUMN_CNT, context.resources.getInteger(R.integer.media_columns)) get() = prefs.getInt(MEDIA_COLUMN_CNT, context.resources.getInteger(R.integer.media_columns))
set(mediaColumnCnt) = mPrefs.edit().putInt(MEDIA_COLUMN_CNT, mediaColumnCnt).apply() set(mediaColumnCnt) = prefs.edit().putInt(MEDIA_COLUMN_CNT, mediaColumnCnt).apply()
} }