Slide 42
Slide 42 text
app
krate
interface Krate {
val sharedPreferences: SharedPreferences
}
class IntDelegate(
private val sharedPreferences: SharedPreferences,
private val key: String
) {
operator fun getValue(thisRef: Any?, property: KProperty<*>): Int {
return sharedPreferences.getInt(key, 0)
}
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: Int) {
sharedPreferences.edit().putInt(key, value).apply()
}
}
class MyKrate(context: Context) : SimpleKrate(context) {
var score: Int by IntDelegate(sharedPreferences, "score")
}
fun Krate.intPref(key: String): IntDelegate {
return IntDelegate(sharedPreferences, key)
}