forked from melod1n/fast-messenger
New cache system
Refactoring Separation into libraries
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package com.meloda.fast
|
||||
|
||||
import android.text.TextUtils
|
||||
import com.meloda.fast.common.AppGlobal
|
||||
|
||||
object UserConfig {
|
||||
|
||||
private const val TOKEN = "token"
|
||||
private const val USER_ID = "user_id"
|
||||
|
||||
const val API_ID = "6964679"
|
||||
|
||||
var token = ""
|
||||
var userId = 0
|
||||
|
||||
fun save() {
|
||||
AppGlobal.preferences.edit()
|
||||
.putString(TOKEN, token)
|
||||
.putInt(USER_ID, userId)
|
||||
.apply()
|
||||
}
|
||||
|
||||
fun restore() {
|
||||
token = AppGlobal.preferences.getString(TOKEN, "") ?: ""
|
||||
userId = AppGlobal.preferences.getInt(USER_ID, -1)
|
||||
}
|
||||
|
||||
fun clear() {
|
||||
token = ""
|
||||
userId = -1
|
||||
|
||||
AppGlobal.preferences.edit()
|
||||
.remove(TOKEN)
|
||||
.remove(USER_ID)
|
||||
.apply()
|
||||
}
|
||||
|
||||
fun isLoggedIn(): Boolean {
|
||||
return userId > 0 && !TextUtils.isEmpty(token)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user