forked from hush/SilentDragonAndroid
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.
35 lines
1.1 KiB
35 lines
1.1 KiB
package cash.z.ecc.android.preference.model
|
|
|
|
import android.content.Context
|
|
import android.content.SharedPreferences
|
|
import cash.z.ecc.android.preference.SharedPreferenceFactory
|
|
|
|
/**
|
|
* A default value represents a preference key, along with its default value. It does not, by itself,
|
|
* know how to read or write values from the preference repository.
|
|
*/
|
|
data class BooleanDefaultValue(override val key: String, internal val defaultValue: Boolean) :
|
|
DefaultValue<Boolean> {
|
|
init {
|
|
require(key.isNotEmpty())
|
|
}
|
|
}
|
|
|
|
fun BooleanDefaultValue.get(context: Context) = get(
|
|
SharedPreferenceFactory.getSharedPreferences(
|
|
context
|
|
)
|
|
)
|
|
|
|
internal fun BooleanDefaultValue.get(sharedPreferences: SharedPreferences) =
|
|
sharedPreferences.getBoolean(key, defaultValue)
|
|
|
|
fun BooleanDefaultValue.put(context: Context, newValue: Boolean) = put(
|
|
SharedPreferenceFactory.getSharedPreferences(
|
|
context
|
|
),
|
|
newValue
|
|
)
|
|
|
|
internal fun BooleanDefaultValue.put(sharedPreferences: SharedPreferences, newValue: Boolean) =
|
|
sharedPreferences.edit().putBoolean(key, newValue).apply()
|
|
|