Hush lite wallet for Android
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.

33 lines
1.0 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 LongDefaultValue(
override val key: String,
internal val defaultValue: Long
) : DefaultValue<Long> {
init {
require(key.isNotEmpty())
}
}
fun LongDefaultValue.get(context: Context) = get(
SharedPreferenceFactory.getSharedPreferences(context)
)
internal fun LongDefaultValue.get(sharedPreferences: SharedPreferences) =
sharedPreferences.getLong(key, defaultValue)
fun LongDefaultValue.put(context: Context, newValue: Long) = put(
SharedPreferenceFactory.getSharedPreferences(context),
newValue
)
internal fun LongDefaultValue.put(sharedPreferences: SharedPreferences, newValue: Long) =
sharedPreferences.edit().putLong(key, newValue).apply()