1、处理存储和解析过程的崩溃问题
This commit is contained in:
shenzuqiang 2026-03-09 11:39:28 +08:00
parent f186c45c49
commit 79c1e4c066
4 changed files with 21 additions and 17 deletions

View File

@ -70,7 +70,6 @@ import com.img.rabbit.config.Constants.agreementUrl
import com.img.rabbit.config.Constants.privacyUrl
import com.img.rabbit.pages.NetworkDisconnectedPage
import com.img.rabbit.pages.toolbar.TitleBar
import com.img.rabbit.provider.storage.GlobalStateManager
import com.img.rabbit.utils.AgreementTextHelper
import com.img.rabbit.utils.AppEventBus
import com.img.rabbit.utils.LoginBindEvent

View File

@ -5,12 +5,8 @@ import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.booleanPreferencesKey
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.intPreferencesKey
import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.datastore.preferences.preferencesDataStore
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.map
private val Context.storeData: DataStore<Preferences> by preferencesDataStore(name = "global_state")

View File

@ -1,8 +1,6 @@
package com.img.rabbit.provider.storage
import android.text.TextUtils
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.img.rabbit.bean.response.UserConfigEntity
@ -125,18 +123,31 @@ object PreferenceUtil {
}
fun getLoginInfos(): MutableList<LoginInfoEntity>? {
return try {
/**
*[{"user_id":"25","name":"手机用户0253","avater":"https://cdn.batiao8.com/jietutu/logo.png","token":"45731e27-d101-4ec3-975c-e665cf86a579"},{"user_id":"25","name":"手机用户0253","avater":"https://cdn.batiao8.com/jietutu/logo.png","token":"45731e27-d101-4ec3-975c-e665cf86a579"}]
*/
return gson.fromJson(mmkv.decodeString(KEY_LOGIN_INFO, "[]"), Array<LoginInfoEntity>::class.java)?.toMutableList()
gson.fromJson(mmkv.decodeString(KEY_LOGIN_INFO, "[]"), Array<LoginInfoEntity>::class.java)?.toMutableList()
}catch (e: Exception){
null
}
}
fun saveUserInfo(userInfoEntity: UserInfoEntity) {
fun saveUserInfo(userInfoEntity: UserInfoEntity?) {
if(userInfoEntity == null){
mmkv.encode(KEY_USER_INFO, gson.toJson("{}"))
}else{
mmkv.encode(KEY_USER_INFO, gson.toJson(userInfoEntity))
}
}
fun getUserInfo(): UserInfoEntity? {
return gson.fromJson(mmkv.decodeString(KEY_USER_INFO, "{}"), UserInfoEntity::class.java)
return try {
gson.fromJson(mmkv.decodeString(KEY_USER_INFO, "{}"), UserInfoEntity::class.java)
}catch (e: Exception){
null
}
}

View File

@ -34,9 +34,6 @@ import com.tencent.mm.opensdk.modelmsg.SendAuth
import com.tencent.mm.opensdk.openapi.IWXAPI
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlinx.serialization.json.Json
import okhttp3.RequestBody.Companion.toRequestBody
@ -429,6 +426,7 @@ class LoginViewModel : BaseViewModel() {
}
fun requestUserInfo(){
PreferenceUtil.saveUserInfo(null)
mLaunch {
val response = ApiManager.serviceVo.userInfo()
if(response.status){