Skip to content

Commit 5c1e47f

Browse files
author
wangshuwen15222
committed
feat:修改拦截器逻辑
1 parent 2d2cf8e commit 5c1e47f

File tree

11 files changed

+39
-24
lines changed

11 files changed

+39
-24
lines changed

app/src/main/java/cn/cheney/app/MainActivity.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ public void onError(int code, String message) {
4646

4747
}
4848

49+
@Override
50+
public void hasIntercept() {
51+
52+
}
53+
4954
@Override
5055
public void notFound() {
5156
}

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ android.useAndroidX=true
1818
# Automatically convert third-party libraries to use AndroidX
1919
android.enableJetifier=true
2020

21-
debug = true
21+
debug = false
2222
pluginVersion = 1.0.8
2323
annotationVersion = 1.0.8
2424
compilerVersion = 1.0.8
25-
coreVersion = 1.0.8
25+
coreVersion = 1.0.9

publish-mavencentral.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ publishing {
4444
version PUBLISH_VERSION
4545

4646
if (isAar) {
47-
artifact("$buildDir/outputs/aar/${project.getName()}.aar")
47+
artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
4848
artifact androidSourcesJar
4949
} else {
5050
artifact("$buildDir/libs/${project.getName()}.jar")

xrouter_annotation/src/main/java/cn/cheney/xrouter/annotation/XInterceptor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@
1313

1414
String[] modules() default {};
1515

16+
/**
17+
* 优先级 值越大 越先触发
18+
*/
1619
int priority() default 0;
1720
}

xrouter_core/src/main/java/cn/cheney/xrouter/core/XRouter.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,14 @@ public Object proceed(BaseCall<?> call, RouteCallback callback) {
158158
if (null != callback) {
159159
callback.notFound();
160160
}
161-
} else {
161+
} else if (e.getCode() == RouterException.HAS_INTERCEPT) {
162162
if (null != callback) {
163-
callback.onError(e.getCode(), e.getMessage());
163+
callback.hasIntercept();
164164
}
165165
}
166+
if (null != callback) {
167+
callback.onError(e.getCode(), e.getMessage());
168+
}
166169
}
167170
return value;
168171
}

xrouter_core/src/main/java/cn/cheney/xrouter/core/callback/RouteCallback.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ public void onResult(Map<String, Object> result){}
88

99
public void notFound(){}
1010

11+
public void hasIntercept(){}
12+
1113
public void onError(int code, String message){}
1214

1315
}

xrouter_core/src/main/java/cn/cheney/xrouter/core/exception/RouterException.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ public RouterException(int code,String message) {
1313

1414
public static final int NOT_INIT = -100;
1515
public static final int NOT_FOUND = -1000;
16-
public static final int INVOKE_ERROR = -1002;
1716
public static final int UN_KNOWN = -1001;
18-
public static final int UN_SUPPORT_EXTRA_TYPE = -1001;
17+
public static final int INVOKE_ERROR = -1002;
18+
public static final int UN_SUPPORT_EXTRA_TYPE = -1003;
19+
public static final int HAS_INTERCEPT = -1004;
1920

2021

2122
private int code;

xrouter_core/src/main/java/cn/cheney/xrouter/core/interceptor/Chain.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ public interface Chain {
1111
* @return value
1212
*/
1313
Object proceed();
14+
15+
void stop();
1416
}

xrouter_core/src/main/java/cn/cheney/xrouter/core/interceptor/InterceptorManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ public List<RouterInterceptor> getInterceptorList(String module, String path) {
7171
interceptorList.add(interceptor);
7272
}
7373
interceptorCacheMap.put(clazz, interceptor);
74+
}else {
75+
interceptorList.add(interceptor);
7476
}
7577
} catch (Exception e) {
7678
e.printStackTrace();

xrouter_core/src/main/java/cn/cheney/xrouter/core/interceptor/RealChain.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.List;
44

55
import cn.cheney.xrouter.core.call.BaseCall;
6+
import cn.cheney.xrouter.core.exception.RouterException;
67
import cn.cheney.xrouter.core.util.Logger;
78

89
public class RealChain implements Chain {
@@ -13,6 +14,8 @@ public class RealChain implements Chain {
1314

1415
private int index = -1;
1516

17+
private boolean stop = false;
18+
1619
public RealChain(BaseCall<?> call, List<RouterInterceptor> interceptorList) {
1720
this.call = call;
1821
this.interceptorList = interceptorList;
@@ -25,6 +28,11 @@ public BaseCall<?> call() {
2528

2629
@Override
2730
public Object proceed() {
31+
if (stop) {
32+
//可以再次做拦截记录
33+
Logger.d("uri=" + call.getUri().toString() + " has been intercept");
34+
throw new RouterException(RouterException.HAS_INTERCEPT);
35+
}
2836
index++;
2937
RouterInterceptor routerInterceptor = null;
3038
if (index <= interceptorList.size() - 1) {
@@ -37,4 +45,10 @@ public Object proceed() {
3745
return null;
3846
}
3947

48+
@Override
49+
public void stop() {
50+
stop = true;
51+
proceed();
52+
}
53+
4054
}

xrouter_core/src/test/java/cn/cheney/xrouter/ExampleUnitTest.java

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)