You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.6 KiB
53 lines
1.6 KiB
package net.pokeranalytics.android.util
|
|
|
|
import android.content.Context
|
|
import android.preference.PreferenceManager
|
|
import java.util.*
|
|
|
|
class Preferences {
|
|
|
|
enum class Keys(var identifier: String) {
|
|
CURRENCY_LANGUAGE("CurrencyLanguage")
|
|
}
|
|
|
|
companion object {
|
|
|
|
fun setString(key: Keys, value: String, context: Context) {
|
|
var preferences = PreferenceManager.getDefaultSharedPreferences(context)
|
|
var editor = preferences.edit()
|
|
editor.putString(key.identifier, value)
|
|
editor.commit()
|
|
}
|
|
|
|
fun getString(key: Keys, context: Context) : String? {
|
|
var preferences = PreferenceManager.getDefaultSharedPreferences(context)
|
|
return preferences.getString(key.identifier, null)
|
|
}
|
|
|
|
fun setCurrencyLanguage(language: String, context: Context) {
|
|
Preferences.setString(Keys.CURRENCY_LANGUAGE, language, context)
|
|
}
|
|
|
|
fun getCurrencyLocale(context : Context) : Locale {
|
|
|
|
/*
|
|
|
|
java.util.Currency usd = java.util.Currency.getInstance("USD");
|
|
java.text.NumberFormat format = java.text.NumberFormat.getCurrencyInstance(
|
|
java.util.Locale.JAPAN);
|
|
format.setCurrency(usd);
|
|
System.out.println(format.format(23.23));
|
|
format.setMaximumFractionDigits(usd.getDefaultFractionDigits());
|
|
System.out.println(format.format(23.23));
|
|
|
|
*/
|
|
val currencyLanguage = Preferences.getString(Keys.CURRENCY_LANGUAGE, context)
|
|
if (currencyLanguage != null) {
|
|
return Locale(currencyLanguage)
|
|
}
|
|
return Locale.getDefault()
|
|
}
|
|
|
|
}
|
|
|
|
} |