添加时间戳校验,优化账户管理用户信息显示, 2.6.0/260
This commit is contained in:
parent
b358bdb889
commit
d8ac807fdb
|
|
@ -20,8 +20,8 @@ android {
|
|||
applicationId "com.cheng.BoLe"
|
||||
minSdk 26
|
||||
targetSdk 34
|
||||
versionCode 240
|
||||
versionName "2.4.0"
|
||||
versionCode 260
|
||||
versionName "2.6.0"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
vectorDrawables {
|
||||
|
|
|
|||
|
|
@ -7,5 +7,6 @@ class UserConfigEntity : Serializable{
|
|||
var temp = false
|
||||
var name = ""
|
||||
var user_id = ""
|
||||
var config: com.cheng.blzb.bean.ConfigEntity? = null
|
||||
var nowtime = ""
|
||||
var config: ConfigEntity? = null
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,9 @@ import androidx.lifecycle.MutableLiveData
|
|||
import com.cheng.blzb.bean.AreaEntity
|
||||
import com.cheng.blzb.bean.BidTypeEntity
|
||||
import com.cheng.blzb.bean.HotWordEntity
|
||||
import com.cheng.blzb.bean.UserConfigEntity
|
||||
import com.cheng.blzb.bean.UserEntity
|
||||
import com.cheng.blzb.bean.WxShareEntity
|
||||
import com.cheng.blzb.net.ApiFactory
|
||||
import com.example.base.extensions.toast
|
||||
import com.example.base.utils.MMKVUtils
|
||||
|
|
@ -22,17 +25,40 @@ import kotlinx.coroutines.withContext
|
|||
import org.json.JSONObject
|
||||
|
||||
object UserConfigManager {
|
||||
val _userConfigLiveData = MutableLiveData<com.cheng.blzb.bean.UserConfigEntity?>()
|
||||
val _userConfigLiveData = MutableLiveData<UserConfigEntity?>()
|
||||
|
||||
val userConfig: com.cheng.blzb.bean.UserConfigEntity? get() = _userConfigLiveData.value
|
||||
val userConfig: UserConfigEntity? get() = _userConfigLiveData.value
|
||||
|
||||
val userInfoLiveData = MutableLiveData<com.cheng.blzb.bean.UserEntity?>()
|
||||
val userInfoLiveData = MutableLiveData<UserEntity?>()
|
||||
|
||||
val userInfo: com.cheng.blzb.bean.UserEntity? get() = userInfoLiveData.value
|
||||
val userInfo: UserEntity? get() = userInfoLiveData.value
|
||||
|
||||
//服务器时间和本地时间的偏移量
|
||||
private var timeDiff = 0L
|
||||
|
||||
//真实的服务器时间
|
||||
fun serverTimeMillis(): Long {
|
||||
return System.currentTimeMillis() + timeDiff * 1000
|
||||
}
|
||||
|
||||
fun getServerTime(clickFun: () -> Unit?) {
|
||||
GlobalScope.launch {
|
||||
try {
|
||||
val response = ApiFactory.apiService.getServerTime()
|
||||
if (response.status) {
|
||||
timeDiff = response.data.toLong() - System.currentTimeMillis() / 1000
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
} finally {
|
||||
getUserConfig { clickFun.invoke() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getUserConfig(clickFun: () -> Unit?) {
|
||||
if (!TextUtils.isEmpty(MMKVUtils.getString("userConfig"))) {
|
||||
val data = Gson().fromJson(MMKVUtils.getString("userConfig"), com.cheng.blzb.bean.UserConfigEntity::class.java)
|
||||
val data = Gson().fromJson(MMKVUtils.getString("userConfig"), UserConfigEntity::class.java)
|
||||
_userConfigLiveData.postValue(data)
|
||||
|
||||
getOaId()
|
||||
|
|
@ -51,6 +77,8 @@ object UserConfigManager {
|
|||
val oaid = MMKVUtils.getString("oaid") ?: ""
|
||||
val response = ApiFactory.apiService.getUserConfig(oaid, Build.VERSION.SDK_INT, "", DeviceIdentifier.getAndroidID(Utils.getApp()), getGTCid())
|
||||
if (response.status) {
|
||||
timeDiff = response.data.nowtime.toLong() - System.currentTimeMillis() / 1000
|
||||
|
||||
_userConfigLiveData.postValue(response.data)
|
||||
MMKVUtils.put("userConfig", Gson().toJson(response.data))
|
||||
|
||||
|
|
@ -70,7 +98,7 @@ object UserConfigManager {
|
|||
}
|
||||
}
|
||||
|
||||
private fun saveUserConfig(data: com.cheng.blzb.bean.UserConfigEntity) {
|
||||
private fun saveUserConfig(data: UserConfigEntity) {
|
||||
try {
|
||||
LoginManager.saveToken(data.token)
|
||||
saveIsTemp(data.temp)
|
||||
|
|
@ -92,14 +120,14 @@ object UserConfigManager {
|
|||
}
|
||||
}
|
||||
|
||||
fun saveLastUserinfo(userinfo: com.cheng.blzb.bean.UserEntity?) {
|
||||
fun saveLastUserinfo(userinfo: UserEntity?) {
|
||||
MMKVUtils.put("last_userinfo", Gson().toJson(userinfo))
|
||||
}
|
||||
|
||||
fun getLastUserinfo(): com.cheng.blzb.bean.UserEntity? {
|
||||
fun getLastUserinfo(): UserEntity? {
|
||||
val str = MMKVUtils.getString("last_userinfo")
|
||||
if (!TextUtils.isEmpty(str)) {
|
||||
return Gson().fromJson(str, com.cheng.blzb.bean.UserEntity::class.java)
|
||||
return Gson().fromJson(str, UserEntity::class.java)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
|
@ -175,14 +203,14 @@ object UserConfigManager {
|
|||
return emptyList()
|
||||
}
|
||||
|
||||
private fun saveShareEntity(entity: com.cheng.blzb.bean.WxShareEntity?) {
|
||||
private fun saveShareEntity(entity: WxShareEntity?) {
|
||||
MMKVUtils.put("weixin_share", Gson().toJson(entity))
|
||||
}
|
||||
|
||||
fun getShareEntity(): com.cheng.blzb.bean.WxShareEntity? {
|
||||
fun getShareEntity(): WxShareEntity? {
|
||||
val s = MMKVUtils.getString("weixin_share")
|
||||
if (!TextUtils.isEmpty(s)) {
|
||||
return Gson().fromJson(s, com.cheng.blzb.bean.WxShareEntity::class.java)
|
||||
return Gson().fromJson(s, WxShareEntity::class.java)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.cheng.blzb.net
|
|||
|
||||
import android.text.TextUtils
|
||||
import com.cheng.blzb.common.Constants
|
||||
import com.cheng.blzb.manager.UserConfigManager
|
||||
import com.cheng.blzb.utils.StringUtils
|
||||
import com.example.base.utils.L
|
||||
import okhttp3.Interceptor
|
||||
|
|
@ -33,9 +34,9 @@ class RequestInterceptor : Interceptor {
|
|||
}
|
||||
var queryString = url.encodedQuery
|
||||
queryString = if (!TextUtils.isEmpty(queryString)) {
|
||||
(queryString + "&nonce=" + StringUtils.createUUID()) + "×tamp=" + System.currentTimeMillis() / 1000
|
||||
(queryString + "&nonce=" + StringUtils.createUUID()) + "×tamp=" + UserConfigManager.serverTimeMillis() / 1000
|
||||
} else {
|
||||
("nonce=" + StringUtils.createUUID()) + "×tamp=" + System.currentTimeMillis() / 1000
|
||||
("nonce=" + StringUtils.createUUID()) + "×tamp=" + UserConfigManager.serverTimeMillis() / 1000
|
||||
}
|
||||
val sortQueryString = Arrays.stream(queryString.split("&".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray())
|
||||
.sorted { obj: String, anotherString: String? -> obj.compareTo(anotherString!!) }
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ class LauncherActivity : BaseActivity() {
|
|||
if (UserConfigManager.isAgree()) {
|
||||
loadingDialog.show()
|
||||
UserConfigManager.saveBDVID()
|
||||
UserConfigManager.getUserConfig {
|
||||
UserConfigManager.getServerTime {
|
||||
EventReportManager.eventReport(EventConstants.APP_LAUNCH, "", "")
|
||||
loadingDialog.dismiss()
|
||||
initUM()
|
||||
|
|
@ -76,7 +76,7 @@ class LauncherActivity : BaseActivity() {
|
|||
loadingDialog.show()
|
||||
UserConfigManager.saveAgree()
|
||||
UserConfigManager.saveBDVID()
|
||||
UserConfigManager.getUserConfig {
|
||||
UserConfigManager.getServerTime {
|
||||
EventReportManager.eventReport(EventConstants.APP_LAUNCH, "", "")
|
||||
loadingDialog.dismiss()
|
||||
initUM()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.cheng.blzb.ui.fragment.mine.account
|
||||
|
||||
import android.graphics.Color
|
||||
import android.text.TextUtils
|
||||
import com.cheng.blzb.bean.AccountEntity
|
||||
import com.cheng.blzb.common.EventConstants
|
||||
import com.cheng.blzb.databinding.FragmentAccountManageBinding
|
||||
|
|
@ -66,6 +67,28 @@ class AccountManageFragment : BaseFragment<FragmentAccountManageBinding, Account
|
|||
mAdapter.setList(list)
|
||||
if (mAccount != null) {
|
||||
mAdapter.addData(0, mAccount!!)
|
||||
} else if (UserConfigManager.userInfo != null) {
|
||||
val userinfo = UserConfigManager.userInfo
|
||||
val bind = mutableListOf<String>()
|
||||
if (!TextUtils.isEmpty(userinfo!!.unionid)) {
|
||||
bind.add("weixin")
|
||||
}
|
||||
if (!TextUtils.isEmpty(userinfo.phone)) {
|
||||
bind.add("phone")
|
||||
}
|
||||
val account = AccountEntity(
|
||||
userinfo.avater,
|
||||
bind,
|
||||
"",
|
||||
userinfo.name,
|
||||
userinfo.phone,
|
||||
userinfo.role.toInt(),
|
||||
userinfo.temp,
|
||||
userinfo.user_id,
|
||||
userinfo.vip_name,
|
||||
userinfo.vip
|
||||
)
|
||||
mAdapter.addData(0, account)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue