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) {
2323 }
2424 }
2525
26- inline fun <reified T > get (key : Key ): T {
26+ inline fun <reified T > get (key : Key , default : T ? = null ): T {
2727 return when (T ::class ) {
2828 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
3030 a
3131 }
3232 Boolean ::class -> {
33- pref.getBoolean(key.value, false ) as T
33+ pref.getBoolean(key.value, default?. let { it as Boolean } ? : false ) as T
3434 }
3535 Int ::class -> {
36- pref.getInt(key.value, - 1 ) as T
36+ pref.getInt(key.value, default?. let { it as Int } ? : - 1 ) as T
3737 }
3838 User ::class -> {
39- val st = pref.getString(key.value, " " )!!
39+ val st = pref.getString(key.value, default?. let { it as String } ? : " " )!!
4040 User .fromString(st) as T
4141 }
4242 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) {
3636
3737 fun getUser () = get<User >(Key .USER )
3838
39- fun isFirstLaunch () = get< Boolean > (Key .LAUNCHSTATE )
39+ fun isFirstLaunch () = get(Key .LAUNCHSTATE , true )
4040
4141 private fun updateLaunchState () = put(Key .LAUNCHSTATE , false )
4242
You can’t perform that action at this time.
0 commit comments