Skip to content

Commit

Permalink
Merge branch 'master' into master-androidx
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaojinzi123 committed Mar 17, 2020
2 parents 4f17370 + 7c0b660 commit e918a7d
Show file tree
Hide file tree
Showing 27 changed files with 122 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,11 @@

/**
* 定义host
*
* @return
*/
String host() default "";

/**
* 路径
*
* @return
*/
String path() default "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,34 @@

/**
* 标记一个方法的跳转类型. 默认可省略
* 返回值支持以下的类型:
* 1. void
* 2. {@link com.xiaojinzi.component.ComponentConstants#NAVIGATOR_CLASS_NAME}
* 3. {@link com.xiaojinzi.component.ComponentConstants#RXJAVA_COMPLETABLE}
* 4. {@link com.xiaojinzi.component.ComponentConstants#RXJAVA_SINGLE}
* 此注解省略和 @NavigateAnno 是一样的
*/
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.CLASS)
public @interface NavigateAnno {

/**
* 为了拿 ActivityResult
*
* @return
*/
boolean forResult() default false;

/**
* 为了拿 Intent
*
* @return
*/
boolean forIntent() default false;

/**
* 为了那 resultCode
*
* @return
*/
boolean forResultCode() default false;

/**
* 当你使用了 {@link #forIntent()}的时候,你可以使用这个属性匹配 ResultCode
*
* @return
*/
int resultCodeMatch() default Integer.MIN_VALUE;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1169,9 +1169,10 @@ public void cancel() {
}

/**
* 实现拦截器列表中的最后一环,内部去执行了跳转的代码
* 这是拦截器的最后一个拦截器了
* 实现拦截器列表中的最后一环, 内部去执行了跳转的代码
* 1.如果跳转的时候没有发生异常, 说明可以跳转过去
* 如果失败需要继续链接下一个拦截器
* 如果失败了进行降级处理
*/
private static class DoActivityStartInterceptor implements RouterInterceptor {

Expand Down Expand Up @@ -1214,7 +1215,10 @@ public void intercept(final Chain chain) throws Exception {
throw new NavigationFailException("degrade route fail, it's url is " + mOriginalRequest.uri.toString());
}
// 降级跳转
RouterCenter.getInstance().routerDegrade(finalRequest, routerDegrade.onDegrade(finalRequest));
RouterCenter.getInstance().routerDegrade(
finalRequest,
routerDegrade.onDegrade(finalRequest)
);
// 成功的回调
chain.callback().onSuccess(new RouterResult(mOriginalRequest, finalRequest));
} catch (Exception ignore) {
Expand Down Expand Up @@ -1346,6 +1350,8 @@ public void run() {
request, callback);
// current Interceptor
RouterInterceptor interceptor = mInterceptors.get(mIndex);
// 提前同步 Query 到 Bundle
next.request().syncUriToBundle();
// 用户自定义的部分,必须在主线程
interceptor.intercept(next);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.xiaojinzi.component.router.IComponentHostRouter;
import com.xiaojinzi.component.support.ASMUtil;
import com.xiaojinzi.component.support.LogUtil;
import com.xiaojinzi.component.support.ParameterSupport;
import com.xiaojinzi.component.support.RouterInterceptorCache;
import com.xiaojinzi.component.support.Utils;

Expand Down Expand Up @@ -157,16 +156,10 @@ private void doOpenUri(@NonNull final RouterRequest request) throws Exception {
* @param intent Intent
*/
@MainThread
private void doStartIntent(@NonNull RouterRequest request, Intent intent) throws Exception {
private void doStartIntent(@NonNull RouterRequest request,
Intent intent) throws Exception {
// 前置工作

// 转化 query 到 bundle,这句话不能随便放
// 因为这句话之前是因为拦截器可以修改 routerRequest 对象中的参数或者整个对象
// 所以直接当所有拦截器都执行完毕的时候,在确定要跳转了
// 这个 query 参数可以往 bundle 里面存了
ParameterSupport.putQueryBundleToBundle(request.bundle, request.uri);
ParameterSupport.putUriStringToBundle(request.bundle, request.uri);
// 然后把 Uri 塞进一个特殊的 key 中
intent.putExtras(request.bundle);
// 把用户的 flags 和 categories 都设置进来
for (String intentCategory : request.intentCategories) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.xiaojinzi.component.bean.ActivityResult;
import com.xiaojinzi.component.support.Action;
import com.xiaojinzi.component.support.Consumer;
import com.xiaojinzi.component.support.ParameterSupport;
import com.xiaojinzi.component.support.Utils;

import java.io.Serializable;
Expand All @@ -44,6 +45,8 @@
@CheckClassNameAnno
public class RouterRequest {

public static final String KEY_SYNC_URI = "_componentSyncUri";

@Nullable
public final Context context;

Expand Down Expand Up @@ -146,6 +149,41 @@ public class RouterRequest {
@Nullable
public final Action afterEventAction;

private RouterRequest(@NonNull Builder builder) {
this.uri = builder.buildURI();
context = builder.context;
fragment = builder.fragment;
requestCode = builder.requestCode;
isForResult = builder.isForResult;
options = builder.options;
// 这两个集合是不可以更改的
intentCategories = Collections.unmodifiableList(builder.intentCategories);
intentFlags = Collections.unmodifiableList(builder.intentFlags);
if (builder.bundle != null) {
this.bundle.putAll(builder.bundle);
}
intentConsumer = builder.intentConsumer;
beforAction = builder.beforAction;
beforStartAction = builder.beforStartAction;
afterStartAction = builder.afterStartAction;
afterAction = builder.afterAction;
afterErrorAction = builder.afterErrorAction;
afterEventAction = builder.afterEventAction;
}

/**
* 同步 Query 到 Bundle 中
*/
public void syncUriToBundle() {
// 如果 URI 没有变化就不同步了
if (bundle.getInt(KEY_SYNC_URI) == uri.hashCode()) {
return;
}
ParameterSupport.syncUriToBundle(uri, bundle);
// 更新新的 hashCode
bundle.putInt(KEY_SYNC_URI, uri.hashCode());
}

/**
* 从 {@link Fragment} 和 {@link Context} 中获取上下文
* <p>
Expand Down Expand Up @@ -296,28 +334,6 @@ public Builder toBuilder() {
return builder;
}

private RouterRequest(@NonNull Builder builder) {
this.uri = builder.buildURI();
context = builder.context;
fragment = builder.fragment;
requestCode = builder.requestCode;
isForResult = builder.isForResult;
options = builder.options;
// 这两个集合是不可以更改的
intentCategories = Collections.unmodifiableList(builder.intentCategories);
intentFlags = Collections.unmodifiableList(builder.intentFlags);
if (builder.bundle != null) {
this.bundle.putAll(builder.bundle);
}
intentConsumer = builder.intentConsumer;
beforAction = builder.beforAction;
beforStartAction = builder.beforStartAction;
afterStartAction = builder.afterStartAction;
afterAction = builder.afterAction;
afterErrorAction = builder.afterErrorAction;
afterEventAction = builder.afterEventAction;
}

/**
* 构建一个路由请求对象 {@link RouterRequest} 对象的 Builder
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;

Expand Down Expand Up @@ -66,7 +65,7 @@ private ParameterSupport() {
public static final String KEY_URI_QUERY_BUNDLE = "_componentQueryBundle";
public static final String KEY_URI = "_componentRouterUri";

public static void putQueryBundleToBundle(@NonNull Bundle bundle, @NonNull Uri uri) {
public static void syncUriToBundle(@NonNull Uri uri, @NonNull Bundle bundle) {
Bundle routerParameterBundle = new Bundle();
Set<String> queryParameterNames = uri.getQueryParameterNames();
if (queryParameterNames != null) {
Expand All @@ -76,9 +75,6 @@ public static void putQueryBundleToBundle(@NonNull Bundle bundle, @NonNull Uri u
}
}
bundle.putBundle(KEY_URI_QUERY_BUNDLE, routerParameterBundle);
}

public static void putUriStringToBundle(@NonNull Bundle bundle, @NonNull Uri uri) {
bundle.putString(KEY_URI, uri.toString());
}

Expand Down Expand Up @@ -1460,26 +1456,26 @@ public static <T extends Parcelable> T getParcelable(@Nullable Bundle bundle,
}

@Nullable
public static <T extends Serializable> T getSerializable(@NonNull Intent intent,
@NonNull String key) {
public static <T extends Serializable> T getSerializable(@NonNull Intent intent,
@NonNull String key) {
return getSerializable(intent, key, null);
}

@Nullable
public static <T extends Serializable> T getSerializable(@NonNull Intent intent,
@NonNull String key,
@Nullable T defaultValue) {
public static <T extends Serializable> T getSerializable(@NonNull Intent intent,
@NonNull String key,
@Nullable T defaultValue) {
return getSerializable(intent.getExtras(), key, defaultValue);
}

@Nullable
public static <T extends Serializable> T getSerializable(@Nullable Bundle bundle,
@NonNull String key) {
public static <T extends Serializable> T getSerializable(@Nullable Bundle bundle,
@NonNull String key) {
return getSerializable(bundle, key, null);
}

@Nullable
public static <T extends Serializable> T getSerializable(@Nullable Bundle bundle,
public static <T extends Serializable> T getSerializable(@Nullable Bundle bundle,
@NonNull String key,
@Nullable T defaultValue) {
if (bundle == null) {
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
668aab85967fe559fe1ca5befc57b852
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
686ffdd5bf685881ab5fbf153ce4d4c6bb62ec87
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.xiaojinzi.component</groupId>
<artifactId>component-plugin</artifactId>
<version>1.8.1</version>
<version>1.8.1.1</version>
<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e6d1f0cd41fb56f8c80f8ae667c09417
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
515efe5ba0c1a4d733657a65a0d7396ac26cfcef

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<groupId>com.xiaojinzi.component</groupId>
<artifactId>component-plugin</artifactId>
<versioning>
<release>1.8.1</release>
<release>1.8.1.1</release>
<versions>
<version>1.7.7.3</version>
<version>1.7.8</version>
Expand All @@ -12,7 +12,8 @@
<version>1.8.0.1</version>
<version>1.8.0.2</version>
<version>1.8.1</version>
<version>1.8.1.1</version>
</versions>
<lastUpdated>20200313060550</lastUpdated>
<lastUpdated>20200317113531</lastUpdated>
</versioning>
</metadata>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d43378f68bfc295c8b78c015f8347aff
fba0561559f0b8312c89940a79fc3699
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2d4bfc15ade2e4d7f29fb533b31c82ac5cfe4a9f
4341db6390cfb91dbb4edeffa0bce8bd0903bafd
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ public class CustomerRouterImpl {

/**
* 自定义实现跳转到打电话的界面,并且自动完成打电话权限的申请
*
* @param request
* @return
*/
@Nullable
@RouterAnno(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

import com.xiaojinzi.component.anno.ConditionalAnno;
import com.xiaojinzi.component.anno.GlobalInterceptorAnno;
import com.xiaojinzi.component.support.Condition;
import com.xiaojinzi.component.impl.RouterInterceptor;
import com.xiaojinzi.component.impl.RouterRequest;
import com.xiaojinzi.component.support.Condition;

/**
* 全局的一个监测的拦截器
Expand All @@ -20,9 +21,15 @@ public class MonitorInterceptor implements RouterInterceptor {

@Override
public void intercept(Chain chain) throws Exception {
String uriStr = chain.request().uri.toString();
RouterRequest request = chain.request();
/*if (request.uri.getQueryParameter("tel") != null) {
request = request.toBuilder()
.query("tel", "15857913622")
.build();
}*/
String uriStr = request.uri.toString();
Log.d("全局监控的拦截器", "uri = " + uriStr);
chain.proceed(chain.request());
chain.proceed(request);
}

public static class OnCondition implements Condition {
Expand Down
Loading

0 comments on commit e918a7d

Please sign in to comment.