Laurent 6 years ago
parent f5bac646b8
commit bc78db7f0d
  1. 37
      app/src/main/java/net/pokeranalytics/android/util/Preferences.kt

@ -14,22 +14,13 @@ import java.util.*
class Preferences { class Preferences {
interface PreferenceKey { interface PreferenceKey {
var identifier: String val identifier: String
}
enum class DBPatch(var key: String) : PreferenceKey {
LONE_COMPUTABLE_RESULTS("loneComputableResult");
override var identifier: String = ""
get() {
return "dbpatch." + this.key
}
} }
enum class Keys(override var identifier: String) : PreferenceKey { enum class Keys(override var identifier: String) : PreferenceKey {
CURRENCY_CODE("CurrencyCode"), CURRENCY_CODE("CurrencyCode"),
LOCALE_CODE("LocaleCode"), LOCALE_CODE("LocaleCode"),
FIRST_LAUNCH("firstLaunch"), // FIRST_LAUNCH("firstLaunch"),
STOP_SHOWING_DISCLAIMER("stopShowingDisclaimer"), STOP_SHOWING_DISCLAIMER("stopShowingDisclaimer"),
STOP_SHOWING_DUPLICATE("stopShowingDuplicate"), STOP_SHOWING_DUPLICATE("stopShowingDuplicate"),
STOP_SHOWING_DISCORD("stopShowingDiscord"), STOP_SHOWING_DISCORD("stopShowingDiscord"),
@ -99,26 +90,26 @@ class Preferences {
editor.apply() editor.apply()
} }
private fun removeKey(key: Keys, context: Context) { // private fun removeKey(key: Keys, context: Context) {
val preferences = PreferenceManager.getDefaultSharedPreferences(context) // val preferences = PreferenceManager.getDefaultSharedPreferences(context)
val editor = preferences.edit() // val editor = preferences.edit()
editor.remove(key.identifier) // editor.remove(key.identifier)
editor.apply() // editor.apply()
} // }
fun getString(key: Keys, context: Context): String? { fun getString(key: Keys, context: Context): String? {
val preferences = PreferenceManager.getDefaultSharedPreferences(context) val preferences = PreferenceManager.getDefaultSharedPreferences(context)
return preferences.getString(key.identifier, null) return preferences.getString(key.identifier, null)
} }
fun setBoolean(key: PreferenceKey, value: Boolean, context: Context) { private fun setBoolean(key: PreferenceKey, value: Boolean, context: Context) {
val preferences = PreferenceManager.getDefaultSharedPreferences(context) val preferences = PreferenceManager.getDefaultSharedPreferences(context)
val editor = preferences.edit() val editor = preferences.edit()
editor.putBoolean(key.identifier, value) editor.putBoolean(key.identifier, value)
editor.apply() editor.apply()
} }
fun getBoolean( private fun getBoolean(
key: PreferenceKey, key: PreferenceKey,
context: Context, context: Context,
defaultValue: Boolean? = false defaultValue: Boolean? = false
@ -140,15 +131,15 @@ class Preferences {
return getString(Keys.ACTIVE_FILTER_ID, context) return getString(Keys.ACTIVE_FILTER_ID, context)
} }
fun removeActiveFilterId(context: Context) { // fun removeActiveFilterId(context: Context) {
removeKey(Keys.ACTIVE_FILTER_ID, context) // removeKey(Keys.ACTIVE_FILTER_ID, context)
} // }
private fun getCurrencyCode(context: Context): String? { private fun getCurrencyCode(context: Context): String? {
return getString(Keys.CURRENCY_CODE, context) return getString(Keys.CURRENCY_CODE, context)
} }
fun getCurrencyLocale(context: Context): Locale? { private fun getCurrencyLocale(context: Context): Locale? {
getCurrencyCode(context)?.let { currencyCode -> getCurrencyCode(context)?.let { currencyCode ->
UserDefaults.availableCurrencyLocales.filter { UserDefaults.availableCurrencyLocales.filter {
Currency.getInstance(it).currencyCode == currencyCode Currency.getInstance(it).currencyCode == currencyCode

Loading…
Cancel
Save