|
@@ -1,6 +1,5 @@
|
|
|
package cn.yyxx.eyuangame.core.utils
|
|
|
|
|
|
-import android.content.Context
|
|
|
import android.text.TextUtils
|
|
|
import cn.yyxx.eyuangame.base.utils.Logger
|
|
|
import cn.yyxx.eyuangame.core.entity.LoginType
|
|
@@ -19,8 +18,8 @@ import org.json.JSONObject
|
|
|
class SessionUtils private constructor() {
|
|
|
|
|
|
@Synchronized
|
|
|
- fun saveSession(context: Context, currentSession: Session) {
|
|
|
- val userList = getLocalSession(context)
|
|
|
+ fun saveSession(currentSession: Session) {
|
|
|
+ val userList = getLocalSession()
|
|
|
userList.apply {
|
|
|
if (size > 0) {
|
|
|
var isSessionExist = false
|
|
@@ -46,7 +45,6 @@ class SessionUtils private constructor() {
|
|
|
for (item in userList) {
|
|
|
jsonArray.put(item.toJSONObject())
|
|
|
}
|
|
|
-// val filePath = FileUtils.getUserInfoFilePath(context)
|
|
|
try {
|
|
|
jsonObject.put("info", jsonArray)
|
|
|
} catch (e: JSONException) {
|
|
@@ -58,12 +56,11 @@ class SessionUtils private constructor() {
|
|
|
else -> "online"
|
|
|
}
|
|
|
MMKVUtils.instance.userKV.encode(keyName, jsonObject.toString())
|
|
|
-// FileUtils.writeFile(jsonObject.toString(), filePath)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- fun getLocalLastSession(context: Context): Session? {
|
|
|
- val list = getLocalSession(context)
|
|
|
+ fun getLocalLastSession(): Session? {
|
|
|
+ val list = getLocalSession()
|
|
|
if (list.size == 0) {
|
|
|
return null
|
|
|
}
|
|
@@ -72,8 +69,8 @@ class SessionUtils private constructor() {
|
|
|
return session
|
|
|
}
|
|
|
|
|
|
- fun getLocalSessionLimit3(context: Context): MutableList<Session> {
|
|
|
- val list = getLocalSession(context)
|
|
|
+ fun getLocalSessionLimit3(): MutableList<Session> {
|
|
|
+ val list = getLocalSession()
|
|
|
list.let {
|
|
|
if (it.size == 0) {
|
|
|
return mutableListOf()
|
|
@@ -96,14 +93,13 @@ class SessionUtils private constructor() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private fun getLocalSession(context: Context): MutableList<Session> {
|
|
|
+ private fun getLocalSession(): MutableList<Session> {
|
|
|
val keyName = when (Host.IP_MODEL) {
|
|
|
HostModelUtils.ENV_ONLINE -> "online"
|
|
|
HostModelUtils.ENV_TEST -> "test"
|
|
|
else -> "online"
|
|
|
}
|
|
|
val json = MMKVUtils.instance.userKV.decodeString(keyName)
|
|
|
-// val json = FileUtils.readFile(FileUtils.getUserInfoFilePath(context))
|
|
|
return if (TextUtils.isEmpty(json)) {
|
|
|
mutableListOf()
|
|
|
} else {
|
|
@@ -112,8 +108,8 @@ class SessionUtils private constructor() {
|
|
|
}
|
|
|
|
|
|
@Synchronized
|
|
|
- fun deleteUserInfo(context: Context, userId: String) {
|
|
|
- val userList = getLocalSession(context)
|
|
|
+ fun deleteUserInfo(userId: String) {
|
|
|
+ val userList = getLocalSession()
|
|
|
if (userList.size == 0) {
|
|
|
return
|
|
|
}
|
|
@@ -137,8 +133,6 @@ class SessionUtils private constructor() {
|
|
|
jsonArray.put(item.toJSONObject())
|
|
|
}
|
|
|
|
|
|
-// val filePath = FileUtils.getUserInfoFilePath(context)
|
|
|
-
|
|
|
try {
|
|
|
jsonObject.put("info", jsonArray)
|
|
|
} catch (e: JSONException) {
|
|
@@ -152,7 +146,6 @@ class SessionUtils private constructor() {
|
|
|
else -> "online"
|
|
|
}
|
|
|
MMKVUtils.instance.userKV.encode(keyName, jsonObject.toString())
|
|
|
-// FileUtils.writeFile(jsonObject.toString(), filePath)
|
|
|
}
|
|
|
|
|
|
private fun toList(json: String): MutableList<Session> {
|
|
@@ -192,7 +185,6 @@ class SessionUtils private constructor() {
|
|
|
}
|
|
|
|
|
|
companion object {
|
|
|
-
|
|
|
val instance: SessionUtils by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
|
|
|
SessionUtils()
|
|
|
}
|