parent
f186c45c49
commit
79c1e4c066
|
|
@ -70,7 +70,6 @@ import com.img.rabbit.config.Constants.agreementUrl
|
||||||
import com.img.rabbit.config.Constants.privacyUrl
|
import com.img.rabbit.config.Constants.privacyUrl
|
||||||
import com.img.rabbit.pages.NetworkDisconnectedPage
|
import com.img.rabbit.pages.NetworkDisconnectedPage
|
||||||
import com.img.rabbit.pages.toolbar.TitleBar
|
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.AgreementTextHelper
|
||||||
import com.img.rabbit.utils.AppEventBus
|
import com.img.rabbit.utils.AppEventBus
|
||||||
import com.img.rabbit.utils.LoginBindEvent
|
import com.img.rabbit.utils.LoginBindEvent
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,8 @@ import androidx.datastore.core.DataStore
|
||||||
import androidx.datastore.preferences.core.Preferences
|
import androidx.datastore.preferences.core.Preferences
|
||||||
import androidx.datastore.preferences.core.booleanPreferencesKey
|
import androidx.datastore.preferences.core.booleanPreferencesKey
|
||||||
import androidx.datastore.preferences.core.edit
|
import androidx.datastore.preferences.core.edit
|
||||||
import androidx.datastore.preferences.core.intPreferencesKey
|
|
||||||
import androidx.datastore.preferences.core.stringPreferencesKey
|
|
||||||
import androidx.datastore.preferences.preferencesDataStore
|
import androidx.datastore.preferences.preferencesDataStore
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
|
|
||||||
private val Context.storeData: DataStore<Preferences> by preferencesDataStore(name = "global_state")
|
private val Context.storeData: DataStore<Preferences> by preferencesDataStore(name = "global_state")
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
package com.img.rabbit.provider.storage
|
package com.img.rabbit.provider.storage
|
||||||
|
|
||||||
import android.text.TextUtils
|
import android.text.TextUtils
|
||||||
import androidx.lifecycle.LiveData
|
|
||||||
import androidx.lifecycle.MutableLiveData
|
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import com.google.gson.GsonBuilder
|
import com.google.gson.GsonBuilder
|
||||||
import com.img.rabbit.bean.response.UserConfigEntity
|
import com.img.rabbit.bean.response.UserConfigEntity
|
||||||
|
|
@ -125,18 +123,31 @@ object PreferenceUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getLoginInfos(): MutableList<LoginInfoEntity>? {
|
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"}]
|
*[{"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))
|
mmkv.encode(KEY_USER_INFO, gson.toJson(userInfoEntity))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun getUserInfo(): 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
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,9 +34,6 @@ import com.tencent.mm.opensdk.modelmsg.SendAuth
|
||||||
import com.tencent.mm.opensdk.openapi.IWXAPI
|
import com.tencent.mm.opensdk.openapi.IWXAPI
|
||||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.GlobalScope
|
|
||||||
import kotlinx.coroutines.delay
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import okhttp3.RequestBody.Companion.toRequestBody
|
import okhttp3.RequestBody.Companion.toRequestBody
|
||||||
|
|
@ -429,6 +426,7 @@ class LoginViewModel : BaseViewModel() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun requestUserInfo(){
|
fun requestUserInfo(){
|
||||||
|
PreferenceUtil.saveUserInfo(null)
|
||||||
mLaunch {
|
mLaunch {
|
||||||
val response = ApiManager.serviceVo.userInfo()
|
val response = ApiManager.serviceVo.userInfo()
|
||||||
if(response.status){
|
if(response.status){
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue