-
Notifications
You must be signed in to change notification settings - Fork 1
/
Prefs.kt
32 lines (32 loc) · 856 Bytes
/
Prefs.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
* Put one of few prmitive types of values to SharedPreferences. Always using to reduce repeating code
* Returns false if your value is not one of supported primtves
*
* @property key
* @property value
*/
fun SharedPreferences.putPrimitiveValue(key: String, value: Any): Boolean {
return when (value) {
is Boolean -> {
this.edit().putBoolean(key, value).apply()
true
}
is String -> {
this.edit().putString(key, value).apply()
true
}
is Int -> {
this.edit().putInt(key, value).apply()
true
}
is Float -> {
this.edit().putFloat(key, value).apply()
true
}
is Long -> {
this.edit().putLong(key, value).apply()
true
}
else -> false
}
}