teapod/app/src/main/java/org/mosad/teapod/preferences/Preferences.kt

40 lines
1010 B
Kotlin
Raw Normal View History

2020-10-08 22:20:20 +02:00
package org.mosad.teapod.preferences
import android.content.Context
import org.mosad.teapod.R
2020-10-08 22:20:20 +02:00
object Preferences {
var preferSecondary = false
2020-10-08 22:20:20 +02:00
internal set
fun savePreferSecondary(context: Context, preferSecondary: Boolean) {
val sharedPref = context.getSharedPreferences(
context.getString(R.string.preference_file_key),
Context.MODE_PRIVATE
)
2020-10-08 22:20:20 +02:00
with(sharedPref.edit()) {
putBoolean(context.getString(R.string.save_key_prefer_secondary), preferSecondary)
apply()
}
2020-10-08 22:20:20 +02:00
this.preferSecondary = preferSecondary
2020-10-08 22:20:20 +02:00
}
/**
* initially load the stored values
*/
fun load(context: Context) {
val sharedPref = context.getSharedPreferences(
context.getString(R.string.preference_file_key),
Context.MODE_PRIVATE
)
2020-10-08 22:20:20 +02:00
preferSecondary = sharedPref.getBoolean(
context.getString(R.string.save_key_prefer_secondary), false
)
2020-10-08 22:20:20 +02:00
}
2020-10-08 22:20:20 +02:00
}