File tree Expand file tree Collapse file tree 2 files changed +6
-6
lines changed
app/src/main/java/com/github/code/gambit/utility/sharedpreference Expand file tree Collapse file tree 2 files changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -23,20 +23,20 @@ abstract class PreferenceManager(var context: Context) {
23
23
}
24
24
}
25
25
26
- inline fun <reified T > get (key : Key ): T {
26
+ inline fun <reified T > get (key : Key , default : T ? = null ): T {
27
27
return when (T ::class ) {
28
28
String ::class -> {
29
- val a = pref.getString(key.value, " " ) as T
29
+ val a = pref.getString(key.value, default?. let { it as String } ? : " " ) as T
30
30
a
31
31
}
32
32
Boolean ::class -> {
33
- pref.getBoolean(key.value, false ) as T
33
+ pref.getBoolean(key.value, default?. let { it as Boolean } ? : false ) as T
34
34
}
35
35
Int ::class -> {
36
- pref.getInt(key.value, - 1 ) as T
36
+ pref.getInt(key.value, default?. let { it as Int } ? : - 1 ) as T
37
37
}
38
38
User ::class -> {
39
- val st = pref.getString(key.value, " " )!!
39
+ val st = pref.getString(key.value, default?. let { it as String } ? : " " )!!
40
40
User .fromString(st) as T
41
41
}
42
42
else -> throw IllegalStateException (" Only supports String, Boolean and Int" )
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ constructor(@ApplicationContext context: Context) : PreferenceManager(context) {
36
36
37
37
fun getUser () = get<User >(Key .USER )
38
38
39
- fun isFirstLaunch () = get< Boolean > (Key .LAUNCHSTATE )
39
+ fun isFirstLaunch () = get(Key .LAUNCHSTATE , true )
40
40
41
41
private fun updateLaunchState () = put(Key .LAUNCHSTATE , false )
42
42
You can’t perform that action at this time.
0 commit comments