|
@@ -1,6 +1,9 @@
|
|
|
package com.fastest.pass.helpers
|
|
|
|
|
|
import android.content.Context
|
|
|
+import com.fastest.pass.login.data.model.UserInfo
|
|
|
+import com.google.gson.Gson
|
|
|
+import com.google.gson.reflect.TypeToken
|
|
|
|
|
|
class BasePreferenceHelper(private val context: Context) : PreferencesHelper() {
|
|
|
|
|
@@ -9,14 +12,14 @@ class BasePreferenceHelper(private val context: Context) : PreferencesHelper() {
|
|
|
removePreference(context, KEY_FILENAME, KEY_BEARER_TOKEN)
|
|
|
}
|
|
|
|
|
|
- fun getLoggedInState(): Boolean {
|
|
|
- return getBooleanPreference(context, KEY_FILENAME, KEY_ISLOGGEDIN)
|
|
|
- }
|
|
|
-
|
|
|
fun setLoggedInState(state: Boolean) {
|
|
|
putBooleanPreference(context, KEY_FILENAME, KEY_ISLOGGEDIN, state)
|
|
|
}
|
|
|
|
|
|
+ fun getLoggedInState(): Boolean {
|
|
|
+ return getBooleanPreference(context, KEY_FILENAME, KEY_ISLOGGEDIN)
|
|
|
+ }
|
|
|
+
|
|
|
fun saveToken(token: String) {
|
|
|
putStringPreference(context, KEY_FILENAME, KEY_BEARER_TOKEN, token)
|
|
|
}
|
|
@@ -25,9 +28,23 @@ class BasePreferenceHelper(private val context: Context) : PreferencesHelper() {
|
|
|
return getStringPreference(context, KEY_FILENAME, KEY_BEARER_TOKEN)
|
|
|
}
|
|
|
|
|
|
+ fun saveUserInfo(userInfo: UserInfo?) {
|
|
|
+ putStringPreference(context, KEY_FILENAME, KEY_USERINFO, Gson().toJson(userInfo))
|
|
|
+ }
|
|
|
+
|
|
|
+ fun getUserInfo() : UserInfo? {
|
|
|
+ val type = object : TypeToken<UserInfo?>() {}.type
|
|
|
+ return Gson().fromJson<UserInfo?>(
|
|
|
+ getStringPreference(
|
|
|
+ context, KEY_FILENAME, KEY_USERINFO
|
|
|
+ ), type
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
companion object {
|
|
|
private const val KEY_FILENAME = "file_fastestpass"
|
|
|
private const val KEY_ISLOGGEDIN = "key_isloggedin"
|
|
|
private const val KEY_BEARER_TOKEN = "key_bearer_token"
|
|
|
+ private const val KEY_USERINFO = "key_userinfo"
|
|
|
}
|
|
|
}
|