Settings

interface Settings

A Wrapper for saving simple key-value data. Currently it only supports saving of primitive data types. TODO later we can add coroutines support or settings listeners since our implementation can support it. TODO later we can support wrapped using a property delegate.

Inheritors

Types

Link copied to clipboard
object Companion
Link copied to clipboard
interface Listener

Properties

Link copied to clipboard
abstract val keys: Set<String>

Returns a Set containing all the keys present in this Settings.

Link copied to clipboard
Link copied to clipboard
abstract val size: Int

Returns the number of key-value pairs present in this Settings.

Functions

Link copied to clipboard

In case you need to stop removing expired keys

Link copied to clipboard
abstract fun clear()

Clears all values stored in this Settings instance.

Link copied to clipboard
inline operator fun Settings.contains(key: String): Boolean

Equivalent to Settings.hasKey

Link copied to clipboard
inline operator fun <T : Any> Settings.get(key: String): T?

Get the typed value stored at key if present, or return null if not. Throws IllegalArgumentException if T is not one of Int, Long, String, Float, Double, or Boolean.

inline operator fun Settings.get(key: String, defaultValue: Boolean): Boolean

Equivalent to Settings.getBoolean

inline operator fun Settings.get(key: String, defaultValue: Double): Double

Equivalent to Settings.getDouble

inline operator fun Settings.get(key: String, defaultValue: Float): Float

Equivalent to Settings.getFloat

inline operator fun Settings.get(key: String, defaultValue: Int): Int

Equivalent to Settings.getInt

inline operator fun Settings.get(key: String, defaultValue: Long): Long

Equivalent to Settings.getLong

inline operator fun Settings.get(key: String, defaultValue: String): String

Equivalent to Settings.getString

Link copied to clipboard
abstract fun getBoolean(key: String, defaultValue: Boolean): Boolean

Returns the Boolean value stored at key, or defaultValue if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

Link copied to clipboard
abstract fun getBooleanFlow(key: String): Flow<Boolean?>

Returns a Flow Boolean value stored at key, or null if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

abstract fun getBooleanFlow(key: String, defaultValue: Boolean): Flow<Boolean>

Returns a Flow Boolean value stored at key, or defaultValue if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

Link copied to clipboard
abstract fun getBooleanOrNull(key: String): Boolean?

Returns the Boolean value stored at key, or null if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

Link copied to clipboard
abstract fun getDouble(key: String, defaultValue: Double): Double

Returns the Double value stored at key, or defaultValue if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

Link copied to clipboard
abstract fun getDoubleFlow(key: String): Flow<Double?>

Returns a Flow Double value stored at key, or null if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

abstract fun getDoubleFlow(key: String, defaultValue: Double): Flow<Double>

Returns a Flow Double value stored at key, or defaultValue if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

Link copied to clipboard
abstract fun getDoubleOrNull(key: String): Double?

Returns the Double value stored at key, or null if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

Link copied to clipboard
abstract fun getExpirableString(key: String): String?
abstract fun getExpirableString(key: String, default: String?): String?
Link copied to clipboard
abstract fun getFloat(key: String, defaultValue: Float): Float

Returns the Float value stored at key, or defaultValue if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

Link copied to clipboard
abstract fun getFloatFlow(key: String): Flow<Float?>

Returns a Flow Float value stored at key, or null if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

abstract fun getFloatFlow(key: String, defaultValue: Float): Flow<Float>

Returns a Flow Float value stored at key, or defaultValue if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

Link copied to clipboard
abstract fun getFloatOrNull(key: String): Float?

Returns the Float value stored at key, or null if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

Link copied to clipboard
abstract fun getInt(key: String, defaultValue: Int): Int

Returns the Int value stored at key, or defaultValue if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

Link copied to clipboard
abstract fun getIntFlow(key: String): Flow<Int?>

Returns a Flow Int value stored at key, or null if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

abstract fun getIntFlow(key: String, defaultValue: Int): Flow<Int>

Returns a Flow Int value stored at key, or defaultValue if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

Link copied to clipboard
abstract fun getIntOrNull(key: String): Int?

Returns the Int value stored at key, or null if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

Link copied to clipboard
abstract fun getLong(key: String, defaultValue: Long): Long

Returns the Long value stored at key, or defaultValue if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

Link copied to clipboard
abstract fun getLongFlow(key: String): Flow<Long?>

Returns a Flow Long value stored at key, or null if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

abstract fun getLongFlow(key: String, defaultValue: Long): Flow<Long>

Returns a Flow Long value stored at key, or defaultValue if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

Link copied to clipboard
abstract fun getLongOrNull(key: String): Long?

Returns the Long value stored at key, or null if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

Link copied to clipboard
abstract fun getString(key: String, defaultValue: String): String

Returns the String value stored at key, or defaultValue if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

Link copied to clipboard
abstract fun getStringFlow(key: String): Flow<String?>

Returns a Flow String value stored at key, or null if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

abstract fun getStringFlow(key: String, defaultValue: String): Flow<String>

Returns a Flow String value stored at key, or defaultValue if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

Link copied to clipboard
abstract fun getStringOrNull(key: String): String?

Returns the String value stored at key, or null if no value was stored. If a value of a different type was stored at key, the behavior is not defined.

Link copied to clipboard
abstract fun hasKey(key: String): Boolean

Returns true if there is a value stored at key, or false otherwise.

Link copied to clipboard
inline operator fun Settings.minusAssign(key: String)

Equivalent to Settings.remove

Link copied to clipboard
abstract fun putBoolean(key: String, value: Boolean)

Stores the Boolean value at key.

Link copied to clipboard
abstract fun putDouble(key: String, value: Double)

Stores the Double value at key.

Link copied to clipboard
abstract fun putExpirableString(key: String, value: String, exp: Long)
open fun putExpirableString(key: String, value: String, exp: Duration)
Link copied to clipboard
abstract fun putFloat(key: String, value: Float)

Stores the Float value at key.

Link copied to clipboard
abstract fun putInt(key: String, value: Int)

Stores the Int value at key.

Link copied to clipboard
abstract fun putLong(key: String, value: Long)

Stores the Long value at key.

Link copied to clipboard
abstract fun putString(key: String, value: String)

Stores the String value at key.

Link copied to clipboard
abstract fun remove(key: String)

Removes the value stored at key.

Link copied to clipboard
abstract fun removeExpiredKeys()

Will loop all keys and remove the expired ones

Link copied to clipboard
inline operator fun <T : Any> Settings.set(key: String, value: T?)

Stores a typed value at key, or remove what's there if value is null. Throws IllegalArgumentException if T is not one of Int, Long, String, Float, Double, or Boolean.

inline operator fun Settings.set(key: String, value: Boolean)

Equivalent to Settings.putBoolean

inline operator fun Settings.set(key: String, value: Double)

Equivalent to Settings.putDouble

inline operator fun Settings.set(key: String, value: Float)

Equivalent to Settings.putFloat

inline operator fun Settings.set(key: String, value: Int)

Equivalent to Settings.putInt

inline operator fun Settings.set(key: String, value: Long)

Equivalent to Settings.putLong

inline operator fun Settings.set(key: String, value: Nothing?)

Equivalent to Settings.remove

inline operator fun Settings.set(key: String, value: String)

Equivalent to Settings.putString