fix bug of when user clear cache
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
package com.mogo.module.authorize.authprovider.biz
|
||||
|
||||
import com.google.gson.Gson
|
||||
import com.mogo.module.authorize.authprovider.invoke.IMogoAuthorizeContentListener
|
||||
import com.mogo.module.authorize.model.BaseResponse
|
||||
import com.mogo.module.authorize.model.IMogoAuthorizeModel
|
||||
import com.mogo.module.authorize.model.bean.Agreement
|
||||
import com.mogo.module.authorize.model.bean.AgreementData
|
||||
import com.mogo.module.authorize.model.bean.*
|
||||
import com.mogo.module.authorize.net.request
|
||||
import com.mogo.module.authorize.util.DateUtil.parseDateToTime
|
||||
import com.mogo.module.authorize.util.SharedPreferenceUtil.getAuthorizeVersion
|
||||
@@ -31,7 +31,7 @@ open class IMogoAuthorizeController {
|
||||
}
|
||||
}, { msg: String ->
|
||||
onError.invoke(msg)
|
||||
})
|
||||
}, true)
|
||||
}
|
||||
|
||||
fun invokeAuthorizeContent(tag: String, agreementType: Int) {
|
||||
@@ -62,12 +62,12 @@ open class IMogoAuthorizeController {
|
||||
})
|
||||
}
|
||||
|
||||
private fun realInvokeAuthorizeContent(agreementType: Int, onStart: (() -> Unit), onSuccess: ((BaseResponse<AgreementData>) -> Unit), onError: ((String) -> Unit)) {
|
||||
private fun realInvokeAuthorizeContent(agreementType: Int, onStart: (() -> Unit), onSuccess: ((BaseResponse<AgreementData>) -> Unit), onError: ((String) -> Unit), needContent: Boolean = false) {
|
||||
onStart.invoke()
|
||||
try {
|
||||
request<BaseResponse<AgreementData>> {
|
||||
loader {
|
||||
authorizeModel.invokeAuthorizeContent(agreementType)
|
||||
authorizeModel.invokeAuthorizeContent(agreementType, needContent)
|
||||
}
|
||||
onSuccess {
|
||||
onSuccess.invoke(it)
|
||||
@@ -116,4 +116,25 @@ open class IMogoAuthorizeController {
|
||||
val oldVersion = getAuthorizeVersion()
|
||||
return currentTime > oldVersion
|
||||
}
|
||||
|
||||
fun checkIfNeedAuthorize(agreementType: Int) {
|
||||
request<BaseResponse<AgreementStatus>> {
|
||||
loader {
|
||||
authorizeModel.invokeIfNeedAuthorize(agreementType)
|
||||
}
|
||||
onSuccess {
|
||||
Logger.d(TAG,"result : ${it.result}")
|
||||
val result = it.result
|
||||
when (result.agreementStatus) {
|
||||
AGREEMENT_EFFECT -> setAuthorizeStatus(agreementType, true)
|
||||
AGREEMENT_NOT_EFFECT -> setAuthorizeStatus(agreementType, false)
|
||||
else -> Logger.d(TAG, "agreementStatus is not match any case")
|
||||
}
|
||||
}
|
||||
onError {
|
||||
Logger.d(TAG, it.message ?: "checkIfNeedAuthorize onError, message is null")
|
||||
setAuthorizeStatus(agreementType, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import com.mogo.module.authorize.authprovider.module.IMogoAcquireAuthorizeListen
|
||||
import com.mogo.module.authorize.model.proxy.AuthorizeProxy
|
||||
import com.mogo.module.authorize.model.proxy.toAuthorizeType
|
||||
import com.mogo.module.authorize.util.SharedPreferenceUtil.needAuthorization
|
||||
import com.mogo.module.authorize.util.SharedPreferenceUtil.setAuthorizeStatus
|
||||
import com.mogo.module.authorize.util.isDeviceOfD
|
||||
import com.mogo.utils.logger.Logger
|
||||
|
||||
@@ -19,14 +20,18 @@ open abstract class MogoAuthorizeManagerImpl : IMogoAuthorizeInvoke {
|
||||
|
||||
override fun needAuthorize(tag: String): Boolean {
|
||||
return if (isDeviceOfD()) {
|
||||
Logger.d(TAG, "needAuthorize update agreement in background")
|
||||
baseController.updateAgreementVersion(tag.toAuthorizeType())
|
||||
Logger.d(TAG, "===== needAuthorize update agreement in background")
|
||||
baseController.checkIfNeedAuthorize(tag.toAuthorizeType())
|
||||
needAuthorization(tag.toAuthorizeType())
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
override fun updateAuthorizeStatus(tag: String) {
|
||||
baseController.checkIfNeedAuthorize(tag.toAuthorizeType())
|
||||
}
|
||||
|
||||
override fun invokeAuthorizeContent(tag: String) {
|
||||
//todo 后面动态代理统一处理校验问题
|
||||
Logger.d(TAG, "tag:$tag")
|
||||
|
||||
@@ -67,6 +67,8 @@ class MogoAuthorizeProvider : IMogoModuleProvider {
|
||||
if (isDeviceOfD() && hasGuide() && mogoAuthShow.needAuthorize(AUTHORIZE_TYPE_LAUNCHER_MAIN)) {
|
||||
mogoAuthShow.invokeAuthorizeForShow()
|
||||
} else {
|
||||
//首次进入Launcher同步一下授权状态,防止由于用户清除数据造成首次加载还会出现授权状态不同步问题
|
||||
mogoAuthShow.updateAuthorizeStatus(AUTHORIZE_TYPE_LAUNCHER_MAIN)
|
||||
Logger.d(TAG, "not do match self startUp condition ,wait for someone invoke")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,4 +15,12 @@ interface IMogoAuthorizeInvoke : IMogoAuthorizeRegister {
|
||||
* tag:模块ID
|
||||
*/
|
||||
fun invokeAuthorizeContent(tag: String)
|
||||
|
||||
/**
|
||||
* 更新授权状态
|
||||
* tag:模块ID
|
||||
*/
|
||||
fun updateAuthorizeStatus(tag:String){
|
||||
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,9 @@ package com.mogo.module.authorize.model
|
||||
|
||||
import com.google.gson.Gson
|
||||
import com.mogo.commons.network.Utils.getSn
|
||||
import com.mogo.module.authorize.model.bean.RequestUserAgreement
|
||||
import com.mogo.module.authorize.model.bean.Agreement
|
||||
import com.mogo.module.authorize.model.bean.AgreementData
|
||||
import com.mogo.module.authorize.model.bean.AgreementStatus
|
||||
import com.mogo.module.authorize.model.bean.RequestUserAgreement
|
||||
|
||||
open class IMogoAuthorizeModel : BaseRepository() {
|
||||
|
||||
@@ -12,9 +12,15 @@ open class IMogoAuthorizeModel : BaseRepository() {
|
||||
const val TAG = "IMogoAuthorizeModel"
|
||||
}
|
||||
|
||||
suspend fun invokeAuthorizeContent(agreementType: Int): BaseResponse<AgreementData> {
|
||||
val requestUserAgreement = Gson().toJson(RequestUserAgreement(agreementType))
|
||||
suspend fun invokeAuthorizeContent(agreementType: Int, needContent: Boolean = false): BaseResponse<AgreementData> {
|
||||
val requestUserAgreement = Gson().toJson(RequestUserAgreement(agreementType, needContent))
|
||||
val map = mapOf("sn" to getSn(), "data" to requestUserAgreement)
|
||||
return apiCall { getNetWorkApi().getAuthorizeContent(map) }
|
||||
}
|
||||
|
||||
suspend fun invokeIfNeedAuthorize(agreementType: Int): BaseResponse<AgreementStatus> {
|
||||
val requestUserAgreement = Gson().toJson(RequestUserAgreement(agreementType))
|
||||
val map = mapOf("sn" to getSn(), "data" to requestUserAgreement)
|
||||
return apiCall { getNetWorkApi().checkIfNeedAuthorize(map) }
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,21 @@ package com.mogo.module.authorize.model.bean
|
||||
const val AGREEMENT_EFFECT = 1 //用户协议生效
|
||||
const val AGREEMENT_NOT_EFFECT = 2 //用户协议不生效
|
||||
|
||||
class RequestUserAgreement(val agreementType: Int)
|
||||
class RequestUserAgreement{
|
||||
var agreementType:Int
|
||||
var want:Boolean = false
|
||||
|
||||
constructor(agreementType:Int){
|
||||
this.agreementType = agreementType
|
||||
}
|
||||
|
||||
constructor(agreementType: Int, want: Boolean) {
|
||||
this.agreementType = agreementType
|
||||
this.want = want
|
||||
}
|
||||
}
|
||||
|
||||
data class AgreementStatus(val agreementStatus:Int)
|
||||
|
||||
data class AgreementData(val agreement: Agreement)
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.mogo.module.authorize.net
|
||||
|
||||
import com.mogo.module.authorize.model.BaseResponse
|
||||
import com.mogo.module.authorize.model.bean.Agreement
|
||||
import com.mogo.module.authorize.model.bean.AgreementData
|
||||
import com.mogo.module.authorize.model.bean.AgreementStatus
|
||||
import retrofit2.http.FieldMap
|
||||
import retrofit2.http.FormUrlEncoded
|
||||
import retrofit2.http.POST
|
||||
@@ -19,4 +19,9 @@ interface AuthorizeApi {
|
||||
@POST("yycp-channelManager/agreement/updateStatus")
|
||||
suspend fun updateAuthorize(@FieldMap updateStatus: Map<String, String>): BaseResponse<Any>
|
||||
|
||||
//查询是否要授权
|
||||
@FormUrlEncoded
|
||||
@POST("yycp-channelManager/agreement/queryUserAuthorizeStatusByType")
|
||||
suspend fun checkIfNeedAuthorize(@FieldMap needAuthorize: Map<String, String>): BaseResponse<AgreementStatus>
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user