Skip to content

Commit afbaea5

Browse files
committed
完善route
1 parent 0279805 commit afbaea5

File tree

5 files changed

+29
-4
lines changed

5 files changed

+29
-4
lines changed

app/src/main/java/com/flyjingfish/modulecommunication/MainActivity.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import android.util.Log
77
import androidx.activity.ComponentActivity
88
import com.flyjingfish.login.LoginActivity
99
import com.flyjingfish.module_communication_intercept.RouterInterceptManager
10+
import com.flyjingfish.module_communication_intercept.intercept.Proceed
1011
import com.flyjingfish.module_communication_intercept.intercept.RouterIntercept
1112
import com.flyjingfish.modulecommunication.databinding.ActivityMainBinding
1213
import com.flyjingfish.user.UserActivity
@@ -27,6 +28,17 @@ class MainActivity : ComponentActivity() {
2728
}
2829

2930
binding.btnGoUri.setOnClickListener {
31+
RouterInterceptManager.addIntercept(object :RouterIntercept{
32+
override fun onIntercept(proceed: Proceed) {
33+
Log.e("onIntercept","--MainActivity--${proceed.path},params = ${proceed.paramsMap},byPath = ${proceed.byPath}")
34+
proceed.proceed()
35+
}
36+
37+
override fun order(): Int {
38+
return 4
39+
}
40+
41+
})
3042
startActivity(Intent(this,SchemeFilterActivity::class.java))
3143
// startActivity(Intent(this,WebActivity::class.java))
3244
}

module-communication-intercept/src/main/java/com/flyjingfish/module_communication_intercept/RouterInterceptManager.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,32 @@ import com.flyjingfish.module_communication_intercept.intercept.RouterIntercept
66
object RouterInterceptManager {
77
private val intercepts = mutableSetOf<RouterIntercept>()
88

9+
/**
10+
* 添加单个拦截器
11+
*/
912
fun addIntercept(intercept: RouterIntercept) {
1013
intercepts.add(intercept)
1114
val newIntercept = intercepts.sortedBy { it.order() }
1215
intercepts.clear()
1316
intercepts.addAll(newIntercept)
1417
}
1518

19+
/**
20+
* 删除单个拦截器
21+
*/
22+
fun removeIntercept(intercept: RouterIntercept) {
23+
intercepts.remove(intercept)
24+
}
25+
26+
/**
27+
* 添加多个拦截器
28+
*/
1629
fun addAllIntercept(intercepts: MutableSet<RouterIntercept>) {
1730
RouterInterceptManager.intercepts.clear()
1831
RouterInterceptManager.intercepts.addAll(intercepts.sortedBy { it.order() })
1932
}
2033

21-
fun notifyIntercept(proceed : Proceed) {
34+
internal fun notifyIntercept(proceed : Proceed) {
2235
if (intercepts.isEmpty()) {
2336
proceed.proceed()
2437
return

module-communication-route/src/main/java/com/flyjingfish/module_communication_route/ModuleRoute.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ object ModuleRoute {
1818
private val allClazz = mutableMapOf<String, ClassInfo?>()
1919
private var application : Application ?= null
2020

21-
private fun addRouteClass(moduleName: String, routeClazz: BaseRouterClass) {
21+
fun addRouteClass(moduleName: String, routeClazz: BaseRouterClass) {
2222
allRouteClass[moduleName] = routeClazz
2323
}
2424

module-communication-route/src/main/java/com/flyjingfish/module_communication_route/bean/ClassInfo.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ package com.flyjingfish.module_communication_route.bean
33
import com.flyjingfish.module_communication_annotation.bean.PathInfo
44
import com.flyjingfish.module_communication_annotation.interfaces.BaseRouterClass
55

6-
class ClassInfo(val pathInfo: PathInfo,val goRouterClazz: BaseRouterClass)
6+
internal class ClassInfo(val pathInfo: PathInfo,val goRouterClazz: BaseRouterClass)

module-communication-route/src/main/java/com/flyjingfish/module_communication_route/utils/IntentUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import android.os.Bundle
55
import android.os.Parcelable
66
import java.io.Serializable
77

8-
fun <T> Intent.putValue(paramName: String, paramsValue: T) {
8+
internal fun <T> Intent.putValue(paramName: String, paramsValue: T) {
99
val intent: Intent = this
1010
when (paramsValue) {
1111
is Char -> {

0 commit comments

Comments
 (0)