Grid size preference
parent
ad201d2bcd
commit
5c3242c511
@ -0,0 +1,20 @@
|
|||||||
|
package org.koitharu.kotatsu.utils.delegates.prefs
|
||||||
|
|
||||||
|
import android.content.SharedPreferences
|
||||||
|
import androidx.core.content.edit
|
||||||
|
import kotlin.properties.ReadWriteProperty
|
||||||
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
|
class IntPreferenceDelegate(private val key: String, private val defValue: Int) :
|
||||||
|
ReadWriteProperty<SharedPreferences, Int> {
|
||||||
|
|
||||||
|
override fun getValue(thisRef: SharedPreferences, property: KProperty<*>): Int {
|
||||||
|
return thisRef.getInt(key, defValue) ?: defValue
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setValue(thisRef: SharedPreferences, property: KProperty<*>, value: Int) {
|
||||||
|
thisRef.edit {
|
||||||
|
putInt(key, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue