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

Loading…
Cancel
Save