Files
fast-messenger/app/src/main/java/com/meloda/fast/UserConfig.kt
T
melod1n 84d812a6d6 New cache system
Refactoring
Separation into libraries
2021-03-17 19:47:53 +03:00

41 lines
851 B
Kotlin

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)
}
}