fix bug
This commit is contained in:
@@ -4,14 +4,15 @@ import com.mogo.module.authorize.authprovider.invoke.IMogoAuthorizeContentListen
|
||||
import com.mogo.module.authorize.authprovider.invoke.IMogoAuthorizeInvoke
|
||||
import com.mogo.module.authorize.authprovider.module.IMogoAcquireAuthorizeListener
|
||||
import com.mogo.module.authorize.model.proxy.AuthorizeProxy
|
||||
import com.mogo.module.authorize.util.SharedPreferenceUtil.hasAuth
|
||||
import com.mogo.module.authorize.util.SharedPreferenceUtil.needAuthorization
|
||||
import com.mogo.utils.logger.Logger
|
||||
|
||||
open abstract class MogoAuthorizeManagerImpl : IMogoAuthorizeInvoke {
|
||||
|
||||
private val baseController: IMogoAuthorizeController by lazy { IMogoAuthorizeController() }
|
||||
|
||||
override fun needAuthorize(): Boolean {
|
||||
return hasAuth()
|
||||
return needAuthorization()
|
||||
}
|
||||
|
||||
override fun invokeAuthorizeContent(tag: String) {
|
||||
@@ -29,6 +30,7 @@ open abstract class MogoAuthorizeManagerImpl : IMogoAuthorizeInvoke {
|
||||
}
|
||||
|
||||
override fun registerAuthorizeListener(tag: String, listener: IMogoAcquireAuthorizeListener) {
|
||||
Logger.d("AuthorizeManager", "registerAuthorize tag : $tag listener:$listener")
|
||||
MogoAuthorizeRegisterHandler.registerAuthorizeListener(tag, listener)
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.mogo.module.authorize.authprovider.biz
|
||||
import com.mogo.module.authorize.authprovider.invoke.IMogoAuthorizeContentListener
|
||||
import com.mogo.module.authorize.authprovider.invoke.IMogoAuthorizeRegister
|
||||
import com.mogo.module.authorize.authprovider.module.IMogoAcquireAuthorizeListener
|
||||
import com.mogo.utils.logger.Logger
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
object MogoAuthorizeRegisterHandler : IMogoAuthorizeRegister {
|
||||
@@ -11,6 +12,7 @@ object MogoAuthorizeRegisterHandler : IMogoAuthorizeRegister {
|
||||
private val authContentMap: ConcurrentHashMap<String, IMogoAuthorizeContentListener> = ConcurrentHashMap()
|
||||
|
||||
override fun registerAuthorizeListener(tag: String, listener: IMogoAcquireAuthorizeListener) {
|
||||
Logger.d("RegisterHandler", "tag : $tag listener:$listener")
|
||||
authMap[tag] = listener
|
||||
}
|
||||
|
||||
|
||||
@@ -9,33 +9,25 @@ interface IMogoAuthorizeRegister {
|
||||
* tag:module tag
|
||||
* @see IMogoAcquireAuthorizeListener
|
||||
*/
|
||||
fun registerAuthorizeListener(tag: String, listener: IMogoAcquireAuthorizeListener) {
|
||||
|
||||
}
|
||||
fun registerAuthorizeListener(tag: String, listener: IMogoAcquireAuthorizeListener)
|
||||
|
||||
/**
|
||||
* 反注册授权回调
|
||||
* tag:module tag
|
||||
*/
|
||||
fun unregisterAuthorizeListener(tag: String) {
|
||||
|
||||
}
|
||||
fun unregisterAuthorizeListener(tag: String)
|
||||
|
||||
/**
|
||||
* 注册授权信息内容回调
|
||||
* tag:module tag
|
||||
* @see IMogoAuthorizeContentListener
|
||||
*/
|
||||
fun registerInvokeAuthorizeContentListener(tag: String, listener: IMogoAuthorizeContentListener) {
|
||||
|
||||
}
|
||||
fun registerInvokeAuthorizeContentListener(tag: String, listener: IMogoAuthorizeContentListener)
|
||||
|
||||
/**
|
||||
* 反注册授权信息内容回调
|
||||
* tag:module tag
|
||||
*/
|
||||
fun unregisterInvokeAuthorizeContentListener(tag: String) {
|
||||
|
||||
}
|
||||
fun unregisterInvokeAuthorizeContentListener(tag: String)
|
||||
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import com.alibaba.android.arouter.facade.annotation.Route
|
||||
import com.mogo.module.authorize.authprovider.invoke.AuthorizeConstant
|
||||
import com.mogo.module.authorize.authprovider.invoke.IMogoAuthorizeContentListener
|
||||
import com.mogo.module.authorize.authprovider.launcher.MogoMainAuthorize.Companion.mogoAuthShow
|
||||
import com.mogo.module.authorize.authprovider.module.IMogoAcquireAuthorizeListener
|
||||
|
||||
@Route(path = AuthorizeConstant.PROVIDER_LAUNCHER)
|
||||
class IMogoAuthorizeMainManager : IMogoAuthorizeMainProvider {
|
||||
@@ -23,4 +24,20 @@ class IMogoAuthorizeMainManager : IMogoAuthorizeMainProvider {
|
||||
override fun disAgreeAuthorize(tag: String, agrId: Long) {
|
||||
mogoAuthShow.disAgreeAuthorize(tag, agrId)
|
||||
}
|
||||
|
||||
override fun registerAuthorizeListener(tag: String, listener: IMogoAcquireAuthorizeListener) {
|
||||
mogoAuthShow.registerAuthorizeListener(tag, listener)
|
||||
}
|
||||
|
||||
override fun unregisterAuthorizeListener(tag: String) {
|
||||
mogoAuthShow.unregisterAuthorizeListener(tag)
|
||||
}
|
||||
|
||||
override fun registerInvokeAuthorizeContentListener(tag: String, listener: IMogoAuthorizeContentListener) {
|
||||
mogoAuthShow.registerInvokeAuthorizeContentListener(tag, listener)
|
||||
}
|
||||
|
||||
override fun unregisterInvokeAuthorizeContentListener(tag: String) {
|
||||
mogoAuthShow.unregisterInvokeAuthorizeContentListener(tag)
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,12 @@ import com.alibaba.android.arouter.launcher.ARouter
|
||||
import com.mogo.module.authorize.authprovider.biz.MogoAuthorizeManagerImpl
|
||||
import com.mogo.module.authorize.authprovider.biz.MogoAuthorizeRegisterHandler
|
||||
import com.mogo.module.authorize.fragment.AuthorizeFragment
|
||||
import com.mogo.module.authorize.util.ServiceUtil.getFragmentManagerApi
|
||||
import com.mogo.module.authorize.util.SharedPreferenceUtil.hasAuth
|
||||
import com.mogo.service.IMogoServiceApis
|
||||
import com.mogo.service.MogoServicePaths
|
||||
import com.mogo.service.fragmentmanager.FragmentDescriptor
|
||||
import com.mogo.utils.logger.Logger
|
||||
|
||||
class MogoMainAuthorize private constructor() : MogoAuthorizeManagerImpl(), IMogoAuthorizeMainProvider {
|
||||
|
||||
@@ -21,7 +23,8 @@ class MogoMainAuthorize private constructor() : MogoAuthorizeManagerImpl(), IMog
|
||||
}
|
||||
}
|
||||
|
||||
private var serviceApi: IMogoServiceApis? = null
|
||||
@Volatile
|
||||
private var showAuthorizeView: Boolean = false
|
||||
|
||||
override fun agreeAuthorize(tag: String, agrId: Long) {
|
||||
MogoAuthorizeMainController.agreeAuthorize(tag, agrId)
|
||||
@@ -31,27 +34,61 @@ class MogoMainAuthorize private constructor() : MogoAuthorizeManagerImpl(), IMog
|
||||
MogoAuthorizeMainController.disAgreeAuthorize(tag, agrId)
|
||||
}
|
||||
|
||||
fun invokeAuthorizeForShow() {
|
||||
if (showAuthorizeView) {
|
||||
Logger.d(TAG, "User is operation authorization, do not repeat invoke")
|
||||
return
|
||||
}
|
||||
pushFragmentToMainView {
|
||||
showAuthorizeView = true
|
||||
}
|
||||
}
|
||||
|
||||
fun showAuthorizeView(tag: String, forbiddenVoice: (() -> Unit), onError: ((String) -> Unit)) {
|
||||
val listener = MogoAuthorizeRegisterHandler.getAuthorizeListener(tag)
|
||||
if (listener == null) {
|
||||
onError.invoke("launcher authorizeShowListener is null,must register in MainActivity")
|
||||
return
|
||||
}
|
||||
forbiddenVoice()
|
||||
|
||||
if (Thread.currentThread() != Looper.getMainLooper().thread) {
|
||||
onError.invoke("invoke should be in main thread")
|
||||
}
|
||||
val mogoService = ARouter.getInstance().build(MogoServicePaths.PATH_SERVICE_APIS).navigation()
|
||||
if (mogoService is IMogoServiceApis) {
|
||||
serviceApi = mogoService
|
||||
return
|
||||
}
|
||||
if (hasAuth()) {
|
||||
onError.invoke("already authorize,do not repeat operation")
|
||||
return
|
||||
}
|
||||
serviceApi?.let {
|
||||
val builderWrapper = FragmentDescriptor.Builder().fragment(AuthorizeFragment()).build()
|
||||
it.fragmentManagerApi.push(builderWrapper)
|
||||
if (showAuthorizeView) {
|
||||
onError.invoke("User is operation authorization, do not repeat invoke")
|
||||
return
|
||||
}
|
||||
Logger.d(TAG, "ready to forbidden voice")
|
||||
forbiddenVoice.invoke()
|
||||
Logger.d(TAG, "ready to push fragment")
|
||||
pushFragmentToMainView {
|
||||
showAuthorizeView = true
|
||||
}
|
||||
}
|
||||
|
||||
fun hideAuthorizeView() {
|
||||
popFragmentFromMainView {
|
||||
showAuthorizeView = false
|
||||
}
|
||||
}
|
||||
|
||||
private inline fun pushFragmentToMainView(push: (() -> Unit)) {
|
||||
val builderWrapper = FragmentDescriptor.Builder().fragment(AuthorizeFragment()).build()
|
||||
Logger.d(TAG,"pushFragmentToMainView")
|
||||
val mogoService = ARouter.getInstance().build(MogoServicePaths.PATH_SERVICE_APIS).navigation()
|
||||
if (mogoService is IMogoServiceApis) {
|
||||
mogoService.fragmentManagerApi.push(builderWrapper)
|
||||
}
|
||||
push.invoke()
|
||||
}
|
||||
|
||||
private inline fun popFragmentFromMainView(pop: (() -> Unit)) {
|
||||
getFragmentManagerApi().pop()
|
||||
pop.invoke()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,6 +12,10 @@ class IMogoAuthorizeModuleManager : IMogoAuthorizeModuleProvider {
|
||||
return mogoAuth.needAuthorize()
|
||||
}
|
||||
|
||||
override fun invokeAuthorizeForShow() {
|
||||
mogoAuth.invokeAuthorizeForShow()
|
||||
}
|
||||
|
||||
override fun invokeAuthorization(tag: String) {
|
||||
mogoAuth.invokeAuthorization(tag)
|
||||
}
|
||||
@@ -20,4 +24,20 @@ class IMogoAuthorizeModuleManager : IMogoAuthorizeModuleProvider {
|
||||
mogoAuth.invokeAuthorizeContent(tag)
|
||||
}
|
||||
|
||||
override fun registerAuthorizeListener(tag: String, listener: IMogoAcquireAuthorizeListener) {
|
||||
mogoAuth.registerAuthorizeListener(tag, listener)
|
||||
}
|
||||
|
||||
override fun unregisterAuthorizeListener(tag: String) {
|
||||
mogoAuth.unregisterAuthorizeListener(tag)
|
||||
}
|
||||
|
||||
override fun registerInvokeAuthorizeContentListener(tag: String, listener: IMogoAuthorizeContentListener) {
|
||||
mogoAuth.registerInvokeAuthorizeContentListener(tag, listener)
|
||||
}
|
||||
|
||||
override fun unregisterInvokeAuthorizeContentListener(tag: String) {
|
||||
mogoAuth.unregisterInvokeAuthorizeContentListener(tag)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,6 +11,11 @@ interface IMogoAuthorizeModuleProvider : IProvider, IMogoAuthorizeInvoke {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 用于没有回调且直接调用授权页面展示 仅Launcher主界面业务使用
|
||||
*/
|
||||
fun invokeAuthorizeForShow()
|
||||
|
||||
/**
|
||||
* 调用授权页面
|
||||
*/
|
||||
|
||||
@@ -12,6 +12,10 @@ class MogoModuleAuthorize private constructor() : MogoAuthorizeManagerImpl(), IM
|
||||
}
|
||||
}
|
||||
|
||||
override fun invokeAuthorizeForShow() {
|
||||
mogoAuthShow.invokeAuthorizeForShow()
|
||||
}
|
||||
|
||||
override fun invokeAuthorization(tag: String) {
|
||||
mogoAuthShow.showAuthorizeView(tag, {
|
||||
//todo SP存储状态
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.mogo.module.authorize.util
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter
|
||||
import com.mogo.commons.AbsMogoApplication
|
||||
import com.mogo.module.authorize.constant.HttpConstant.Companion.getNetHost
|
||||
import com.mogo.module.authorize.net.AuthorizeApi
|
||||
import com.mogo.service.IMogoServiceApis
|
||||
import com.mogo.service.MogoServicePaths
|
||||
import com.mogo.service.fragmentmanager.IMogoFragmentManager
|
||||
|
||||
object ServiceUtil {
|
||||
|
||||
@@ -24,7 +26,19 @@ object ServiceUtil {
|
||||
}
|
||||
|
||||
fun getNetWorkApi(): AuthorizeApi {
|
||||
checkInit()
|
||||
return serviceApi.networkApi.create(AuthorizeApi::class.java, getNetHost())
|
||||
}
|
||||
|
||||
fun getFragmentManagerApi(): IMogoFragmentManager {
|
||||
checkInit()
|
||||
return serviceApi.fragmentManagerApi
|
||||
}
|
||||
|
||||
private fun checkInit() {
|
||||
if (serviceApi == null) {
|
||||
initMogoService()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,7 +5,11 @@ import com.mogo.utils.storage.SharedPrefsMgr
|
||||
|
||||
object SharedPreferenceUtil {
|
||||
|
||||
const val HAS_AUTH = "HAS_AUTH"
|
||||
private const val HAS_AUTH = "HAS_AUTH"
|
||||
|
||||
fun needAuthorization():Boolean{
|
||||
return !hasAuth()
|
||||
}
|
||||
|
||||
fun hasAuth(): Boolean {
|
||||
return SharedPrefsMgr.getInstance(AbsMogoApplication.getApp()).getBoolean(HAS_AUTH, false)
|
||||
|
||||
Reference in New Issue
Block a user