新增登录
This commit is contained in:
34
app/src/main/java/com/aiosman/riderpro/store.kt
Normal file
34
app/src/main/java/com/aiosman/riderpro/store.kt
Normal file
@@ -0,0 +1,34 @@
|
||||
package com.aiosman.riderpro
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
|
||||
/**
|
||||
* 持久化本地数据
|
||||
*/
|
||||
object AppStore {
|
||||
private const val STORE_VERSION = 1
|
||||
private const val PREFS_NAME = "app_prefs_$STORE_VERSION"
|
||||
var token: String? = null
|
||||
var rememberMe: Boolean = false
|
||||
private lateinit var sharedPreferences: SharedPreferences
|
||||
|
||||
fun init(context: Context) {
|
||||
sharedPreferences = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
||||
this.loadData()
|
||||
}
|
||||
|
||||
suspend fun saveData() {
|
||||
// shared preferences
|
||||
sharedPreferences.edit().apply {
|
||||
putString("token", token)
|
||||
putBoolean("rememberMe", rememberMe)
|
||||
}.apply()
|
||||
}
|
||||
|
||||
fun loadData() {
|
||||
// shared preferences
|
||||
token = sharedPreferences.getString("token", null)
|
||||
rememberMe = sharedPreferences.getBoolean("rememberMe", false)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user