|
|
@@ -2,6 +2,9 @@ package com.atmob.keyboard_android.component.base
|
|
|
|
|
|
import android.content.Context
|
|
|
import android.util.AttributeSet
|
|
|
+import com.atmob.keyboard_android.component.base.interceptor.InterceptorCallback
|
|
|
+import com.atmob.keyboard_android.component.base.interceptor.RouteCallback
|
|
|
+import com.atmob.keyboard_android.component.base.interceptor.RouteInterceptorManager
|
|
|
|
|
|
/**
|
|
|
* 带路由功能的组件
|
|
|
@@ -16,7 +19,8 @@ class RouteComponent @JvmOverloads constructor(
|
|
|
*/
|
|
|
fun <T : IUIComponent> routeChildComponent(
|
|
|
targetComponentClass: Class<T>,
|
|
|
- mutex: Boolean = false
|
|
|
+ mutex: Boolean = false,
|
|
|
+ routeCallback: RouteCallback? = null
|
|
|
) {
|
|
|
// 获取所有直接子组件
|
|
|
val directChildComponentList = getDirectChildComponentList()
|
|
|
@@ -27,7 +31,7 @@ class RouteComponent @JvmOverloads constructor(
|
|
|
targetComponentClass.isInstance(it)
|
|
|
}
|
|
|
|
|
|
- if (targetComponent != null) {
|
|
|
+ val routeAction = {
|
|
|
// 找到兄弟组件
|
|
|
if (mutex) {
|
|
|
val siblingComponentList = directChildComponentList.filter {
|
|
|
@@ -39,9 +43,27 @@ class RouteComponent @JvmOverloads constructor(
|
|
|
}
|
|
|
}
|
|
|
// 将自己的层级,移动到父View的最顶层,从而覆盖住兄弟组件
|
|
|
- targetComponent.asView().parent.bringChildToFront(targetComponent.asView())
|
|
|
+ targetComponent?.asView()?.parent?.bringChildToFront(targetComponent.asView())
|
|
|
// 再显示自己
|
|
|
- targetComponent.show()
|
|
|
+ targetComponent?.show()
|
|
|
+ }
|
|
|
+
|
|
|
+ // 找不到目标组件,路由失败
|
|
|
+ if (targetComponent == null) {
|
|
|
+ routeCallback?.onLost()
|
|
|
+ } else {
|
|
|
+ // 找到目标组件,路由前,执行路由拦截器
|
|
|
+ RouteInterceptorManager.executeInterceptors(object : InterceptorCallback {
|
|
|
+ override fun onContinue() {
|
|
|
+ // 拦截器放行,继续路由
|
|
|
+ routeAction.invoke()
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onInterrupt(error: Throwable) {
|
|
|
+ // 路由被拦截器拦截了,回调外部
|
|
|
+ routeCallback?.onInterrupt()
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
}
|
|
|
}
|