[fix]
[有选择的使用缓存]
This commit is contained in:
yangyakun
2024-10-23 15:14:52 +08:00
parent 63dc124902
commit 820d87d101
10 changed files with 31 additions and 20 deletions

View File

@@ -99,9 +99,9 @@ class LoginProvider : LoginService {
}
}
override fun queryLoginStatusByNet() {
override fun queryLoginStatusByNet(readCatche:Boolean) {
CallerLogger.d(tag, "queryLoginStatusByNet")
LoginModel.queryCarStatus()
LoginModel.queryCarStatus(readCatche)
}
override fun loginOut() {

View File

@@ -48,7 +48,7 @@ import java.util.concurrent.TimeUnit
@SuppressLint("StaticFieldLeak")
object LoginModel {
private const val TAG = "TaxiLoginModel"
private const val TAG = "LoginModel"
private var mContext: Context? = null
var iTaxiLoginCallback: ITaxiLoginCallback? = null
private var subscribe: Disposable? = null
@@ -59,6 +59,7 @@ object LoginModel {
d(TAG, "onIntentReceived = %s", intentStr)
if (ConnectivityManager.CONNECTIVITY_ACTION == intentStr) {
if (NetworkUtils.isConnected(mContext)) {
// 网络链接成功可以先读取本地再获取服务器
queryCarStatus()
}
}
@@ -135,7 +136,8 @@ object LoginModel {
if (null != data && 0 == data.code) {
// 获取验证码成功
ToastCharterUtils.showToastShort(mContext?.getString(R.string.module_och_taxi_login_login_success))
queryCarStatus()
// 登录成功需要新的值
queryCarStatus(false)
} else {
if (data != null) {
ToastCharterUtils.showToastShort(data.code.toString())
@@ -169,20 +171,22 @@ object LoginModel {
* 7、网络状态变更后查询
* 8、登录页面关闭后查下状态
*/
fun queryCarStatus() {
fun queryCarStatus(readCatche:Boolean = true) {
mContext?.let {
if(readCatche){
val logingInfoJson = OchSPManager.getString(loginInfoKey)
val timeText = DateTimeUtils.getTimeText(DateTimeUtils.yyyy_MM_dd)
logingInfoJson?.let {logininfo->
if(logininfo.startsWith(timeText)){
val json = logingInfoJson.replace(timeText,"" )
val oldLoginInfo = GsonUtils.fromJson(json, DriverStatusQueryRespBean::class.java)
go2LoginInfo(oldLoginInfo)
go2LoginInfo(oldLoginInfo,"缓存获取")
}
}
}
OchCommonServiceManager.queryDriverServiceStatus(it, object : OchCommonServiceCallback<DriverStatusQueryRespBean> {
override fun onSuccess(data: DriverStatusQueryRespBean?) {
go2LoginInfo(data)
go2LoginInfo(data,"接口获取")
}
override fun onError() {
@@ -192,15 +196,17 @@ object LoginModel {
ToastCharterUtils.showToastShort(mContext!!.getString(R.string.request_error_tip))
}
LoginStatusManager.setLoginError(-10012,"网络错误")
// 依赖参数
subscribe = Observable.timer(5, TimeUnit.SECONDS)
.subscribe { _: Long? -> queryCarStatus() }
.subscribe { _: Long? -> queryCarStatus(readCatche) }
}
override fun onFail(code: Int, msg: String) {
LoginStatusManager.setLoginError(code,"msg:${msg}")
ToastUtilsOch.showWithCodeMessage(code, msg)
// 依赖参数
subscribe = Observable.timer(3, TimeUnit.SECONDS)
.subscribe { _: Long? -> queryCarStatus() }
.subscribe { _: Long? -> queryCarStatus(readCatche) }
// if (code == OchCommonConst.WAIT_TAKEN) {
//
// } else {
@@ -211,7 +217,9 @@ object LoginModel {
}
}
private fun go2LoginInfo(data: DriverStatusQueryRespBean?) {
@Synchronized
private fun go2LoginInfo(data: DriverStatusQueryRespBean?, source: String) {
CallerLogger.d(TAG,"设置源:${source}")
data?.let {
LoginStatusManager.setLoginInfo(data.data)
}
@@ -258,7 +266,8 @@ object LoginModel {
if (null != data && 0 == data.code) {
loginFail(false)
OchSPManager.remove(loginInfoKey)
queryCarStatus()
// 退出登录成功需要查询新的
queryCarStatus(false)
}
}

View File

@@ -112,7 +112,8 @@ class LoginPresenter(view: LoginFragment?) : Presenter<LoginFragment?>(view), IT
gotoOfflineMode()
return
}
LoginModel.queryCarStatus()
// 需要实时查询新的
LoginModel.queryCarStatus(false)
mView?.closeSoftInput()
this.phone = phone
this.code = code

View File

@@ -20,7 +20,7 @@ interface LoginService :CommonService {
fun getBusinessType():BusinessEnum
fun queryLoginStatusByNet()
fun queryLoginStatusByNet(readCatche:Boolean=false)
/**
* 登出

View File

@@ -43,8 +43,8 @@ object LoginStatusManager : CallerBase<ILoginCallback>() {
}
@JvmStatic
fun queryLoginStatusByNet() {
loginService?.queryLoginStatusByNet()
fun queryLoginStatusByNet(readCatche:Boolean=false) {
loginService?.queryLoginStatusByNet(readCatche)
}
@JvmStatic
fun getPurpose(): RoleEnum {

View File

@@ -34,7 +34,8 @@ class FacadeDriverProvider : FacadeProvider() {
sweeperFacadeProvider.init(context)
}else {
super.init(context)
LoginStatusManager.queryLoginStatusByNet()
// 初始化先读取客户端 让客户尽快进入
LoginStatusManager.queryLoginStatusByNet(true)
LanSocketManager.load()
LoginLanDriverSocket.load()
CheckVinManager.load()

View File

@@ -37,7 +37,7 @@ object BusServiceManager {
SharedPrefsMgr.getInstance().token,
BusQueryLineStationsRequest()
) .transformTry()
.flatMap(OchCommonNet("queryBusRoutes",false))
.flatMap(OchCommonNet("mogo/dali bus queryBusRoutes",false))
.flatMap {
Observable.just(it.data?: BusRoutesResult())
}

View File

@@ -37,7 +37,7 @@ object BusShuttleServiceManager {
SharedPrefsMgr.getInstance().token,
SharedPrefsMgr.getInstance().getSn(),
) .transformTry()
.flatMap(OchCommonNet("queryBusRoutes",false))
.flatMap(OchCommonNet("saas bus queryBusRoutes",false))
.flatMap {
Observable.just(it.data?: BusRoutesResult())
}

View File

@@ -43,7 +43,7 @@ object ShuttleServiceManager {
SharedPrefsMgr.getInstance().token,
BusQueryLineStationsRequest()
) .transformTry()
.flatMap(OchCommonNet("queryBusRoutes",false))
.flatMap(OchCommonNet("mogo/dali shuttle queryBusRoutes",false))
.flatMap {
Observable.just(it.data?: BusRoutesResult())
}

View File

@@ -41,7 +41,7 @@ object ShuttleSaasServiceManager {
SharedPrefsMgr.getInstance().token,
BusQueryLineStationsRequest()
) .transformIoTry()
.flatMap(OchCommonNet("queryBusRoutes",false))
.flatMap(OchCommonNet("saas shuttle queryBusRoutes",false))
.flatMap {
Observable.just(it.data?:BusRoutesResult())
}