diff --git a/ComponentApi/src/main/java/com/xiaojinzi/component/anno/FragmentAnno.java b/ComponentApi/src/main/java/com/xiaojinzi/component/anno/FragmentAnno.java index 17f7c60f..a15747e2 100644 --- a/ComponentApi/src/main/java/com/xiaojinzi/component/anno/FragmentAnno.java +++ b/ComponentApi/src/main/java/com/xiaojinzi/component/anno/FragmentAnno.java @@ -1,6 +1,6 @@ package com.xiaojinzi.component.anno; -import com.xiaojinzi.component.anno.support.MainThreadCreateAnno; +import com.xiaojinzi.component.anno.support.UiThreadCreateAnno; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -10,7 +10,7 @@ /** * 标记一个 Fragment, 方便路由到此注解标记的 Fragment */ -@MainThreadCreateAnno +@UiThreadCreateAnno @Target({ElementType.TYPE, ElementType.METHOD}) @Retention(RetentionPolicy.CLASS) public @interface FragmentAnno { diff --git a/ComponentApi/src/main/java/com/xiaojinzi/component/anno/InterceptorAnno.java b/ComponentApi/src/main/java/com/xiaojinzi/component/anno/InterceptorAnno.java index 5fe10cf5..b9098624 100644 --- a/ComponentApi/src/main/java/com/xiaojinzi/component/anno/InterceptorAnno.java +++ b/ComponentApi/src/main/java/com/xiaojinzi/component/anno/InterceptorAnno.java @@ -1,6 +1,6 @@ package com.xiaojinzi.component.anno; -import com.xiaojinzi.component.anno.support.MainThreadCreateAnno; +import com.xiaojinzi.component.anno.support.UiThreadCreateAnno; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -10,7 +10,7 @@ /** * 拦截器的注解,用这个注解标记的不是全局的拦截器,但是你可以使用特定的字符串访问到这个拦截器 */ -@MainThreadCreateAnno +@UiThreadCreateAnno @Target({ElementType.TYPE}) @Retention(RetentionPolicy.CLASS) public @interface InterceptorAnno { diff --git a/ComponentApi/src/main/java/com/xiaojinzi/component/anno/ServiceAnno.java b/ComponentApi/src/main/java/com/xiaojinzi/component/anno/ServiceAnno.java index 2c87c551..949f1f61 100644 --- a/ComponentApi/src/main/java/com/xiaojinzi/component/anno/ServiceAnno.java +++ b/ComponentApi/src/main/java/com/xiaojinzi/component/anno/ServiceAnno.java @@ -1,6 +1,6 @@ package com.xiaojinzi.component.anno; -import com.xiaojinzi.component.anno.support.MainThreadCreateAnno; +import com.xiaojinzi.component.anno.support.UiThreadCreateAnno; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -10,7 +10,7 @@ /** * 标记一个接口 */ -@MainThreadCreateAnno +@UiThreadCreateAnno @Target({ElementType.TYPE, ElementType.METHOD}) @Retention(RetentionPolicy.CLASS) public @interface ServiceAnno { diff --git a/ComponentApi/src/main/java/com/xiaojinzi/component/anno/ServiceMethodAnno.java b/ComponentApi/src/main/java/com/xiaojinzi/component/anno/ServiceMethodAnno.java index d89fd350..4af107e9 100644 --- a/ComponentApi/src/main/java/com/xiaojinzi/component/anno/ServiceMethodAnno.java +++ b/ComponentApi/src/main/java/com/xiaojinzi/component/anno/ServiceMethodAnno.java @@ -1,6 +1,6 @@ package com.xiaojinzi.component.anno; -import com.xiaojinzi.component.anno.support.MainThreadCreateAnno; +import com.xiaojinzi.component.anno.support.UiThreadCreateAnno; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -10,7 +10,7 @@ /** * 标记一个 Service 服务接口的方法是暴露的 */ -@MainThreadCreateAnno +@UiThreadCreateAnno @Target({ElementType.TYPE, ElementType.METHOD}) @Retention(RetentionPolicy.CLASS) public @interface ServiceMethodAnno { diff --git a/ComponentApi/src/main/java/com/xiaojinzi/component/anno/ServiceParameterAnno.java b/ComponentApi/src/main/java/com/xiaojinzi/component/anno/ServiceParameterAnno.java index ebe81429..b074eb2d 100644 --- a/ComponentApi/src/main/java/com/xiaojinzi/component/anno/ServiceParameterAnno.java +++ b/ComponentApi/src/main/java/com/xiaojinzi/component/anno/ServiceParameterAnno.java @@ -1,6 +1,6 @@ package com.xiaojinzi.component.anno; -import com.xiaojinzi.component.anno.support.MainThreadCreateAnno; +import com.xiaojinzi.component.anno.support.UiThreadCreateAnno; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -10,7 +10,7 @@ /** * 标记一个 Service 服务接口的方法的参数是暴露的 */ -@MainThreadCreateAnno +@UiThreadCreateAnno @Target({ElementType.TYPE, ElementType.PARAMETER}) @Retention(RetentionPolicy.CLASS) public @interface ServiceParameterAnno { diff --git a/ComponentApi/src/main/java/com/xiaojinzi/component/anno/support/MainThreadCreateAnno.java b/ComponentApi/src/main/java/com/xiaojinzi/component/anno/support/UiThreadCreateAnno.java similarity index 92% rename from ComponentApi/src/main/java/com/xiaojinzi/component/anno/support/MainThreadCreateAnno.java rename to ComponentApi/src/main/java/com/xiaojinzi/component/anno/support/UiThreadCreateAnno.java index b443b14e..851f3643 100644 --- a/ComponentApi/src/main/java/com/xiaojinzi/component/anno/support/MainThreadCreateAnno.java +++ b/ComponentApi/src/main/java/com/xiaojinzi/component/anno/support/UiThreadCreateAnno.java @@ -11,5 +11,5 @@ */ @Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.SOURCE) -public @interface MainThreadCreateAnno { +public @interface UiThreadCreateAnno { } diff --git a/ComponentCompiler/src/main/java/com/xiaojinzi/component/RouterProcessor.java b/ComponentCompiler/src/main/java/com/xiaojinzi/component/RouterProcessor.java index 4b95392a..862e40c5 100644 --- a/ComponentCompiler/src/main/java/com/xiaojinzi/component/RouterProcessor.java +++ b/ComponentCompiler/src/main/java/com/xiaojinzi/component/RouterProcessor.java @@ -336,9 +336,9 @@ public void accept(String key, RouterAnnoBean routerBean) { // 声明一个拦截器的集合. String interceptorListName = "interceptorList" + atomicInteger.incrementAndGet(); - initMapMethodSpecBuilder.addStatement("$N<$T> $N = new $T($L)", + initMapMethodSpecBuilder.addStatement("$N<$T> $N = new $N<$T>($L)", ComponentConstants.JAVA_LIST, pageInterceptorBeanTypeElement, interceptorListName, - ArrayList.class, routerBean.getTotalInterceptorSize()); + ComponentConstants.JAVA_ARRAYLIST, pageInterceptorBeanTypeElement, routerBean.getTotalInterceptorSize()); initMapMethodSpecBuilder.addStatement("$N.setPageInterceptors($N)", routerBeanName, interceptorListName); // 拦截器的代码的生成 diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/Component.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/Component.java index 32a9b1ac..702b590d 100644 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/Component.java +++ b/ComponentImpl/src/main/java/com/xiaojinzi/component/Component.java @@ -7,6 +7,7 @@ import android.support.annotation.MainThread; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.annotation.UiThread; import com.xiaojinzi.component.impl.application.ModuleManager; import com.xiaojinzi.component.support.Inject; @@ -22,6 +23,11 @@ */ public class Component { + public static final String GITHUB_URL = "https://github.com/xiaojinzi123/Component"; + public static final String DOC_URL = "https://github.com/xiaojinzi123/Component/wiki"; + public static final String COMMON_ERROR_ISSUE = "https://github.com/xiaojinzi123/Component/issues/21"; + public static final String ROUTER_UES_NOTE = "https://github.com/xiaojinzi123/Component/wiki/%E4%B8%BB%E9%A1%B5#%E7%89%B9%E5%88%AB%E6%B3%A8%E6%84%8F"; + /** * 是否初始化过了 */ @@ -45,28 +51,25 @@ private Component() { * * @see Config 初始化的配置对象 */ - @MainThread + @UiThread public static void init(boolean isDebug, @NonNull Config config) { - // 做必要的检查 if (isInit) { throw new RuntimeException("you have init Component already!"); } Utils.checkMainThread(); Utils.checkNullPointer(config, "config"); - Component.isDebug = isDebug; mConfig = config; + if (isDebug) { + printComponent(); + } // 注册 mConfig.getApplication().registerActivityLifecycleCallbacks(new ComponentLifecycleCallback()); if (mConfig.isOptimizeInit() && mConfig.isAutoRegisterModule()) { ModuleManager.getInstance().autoRegister(); } isInit = true; - if (isDebug) { - printComponent(); - } - } /** @@ -92,8 +95,9 @@ private static void printComponent() { sb.append(" *********\n"); sb.append("感谢您选择 Component 组件化框架. \n有任何问题欢迎提 issue 或者扫描 github 上的二维码进入群聊@群主\n") - .append("Github 地址:https://github.com/xiaojinzi123/Component") - .append("\n文档地址:https://github.com/xiaojinzi123/Component/wiki") + .append("Github 地址:" + GITHUB_URL) + .append("\n文档地址:" + DOC_URL) + .append("\n错误排查指南:" + COMMON_ERROR_ISSUE) .append("\n "); LogUtil.logw(sb.toString()); @@ -132,22 +136,22 @@ private static void checkInit() { } } - @MainThread + @UiThread public static void inject(@NonNull Object target) { inject(target, null, true, true); } - @MainThread + @UiThread public static void injectAttrValueFromIntent(@NonNull Object target, @Nullable Intent intent) { injectAttrValueFromBundle(target, intent == null ? null : intent.getExtras()); } - @MainThread + @UiThread public static void injectAttrValueFromBundle(@NonNull Object target, @Nullable Bundle bundle) { inject(target, bundle, true, false); } - @MainThread + @UiThread public static void injectService(@NonNull Object target) { inject(target, null, false, true); } @@ -160,7 +164,7 @@ public static void injectService(@NonNull Object target) { * @param isAutoWireAttrValue 是否注入属性值 * @param isAutoWireService 是否注入 Service */ - @MainThread + @UiThread private static void inject(@NonNull Object target, @Nullable Bundle bundle, boolean isAutoWireAttrValue, boolean isAutoWireService) { diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/ComponentActivityStack.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/ComponentActivityStack.java index 3bb21889..8c17ac03 100644 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/ComponentActivityStack.java +++ b/ComponentImpl/src/main/java/com/xiaojinzi/component/ComponentActivityStack.java @@ -1,9 +1,9 @@ package com.xiaojinzi.component; import android.app.Activity; -import android.support.annotation.MainThread; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.annotation.UiThread; import com.xiaojinzi.component.support.Utils; @@ -28,7 +28,7 @@ private static class Holder { private static ComponentActivityStack INSTANCE = new ComponentActivityStack(); } - @MainThread + @UiThread public static ComponentActivityStack getInstance() { return Holder.INSTANCE; } diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/application/IApplicationLifecycle.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/application/IApplicationLifecycle.java index 5efaafd8..b5a44d80 100644 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/application/IApplicationLifecycle.java +++ b/ComponentImpl/src/main/java/com/xiaojinzi/component/application/IApplicationLifecycle.java @@ -1,8 +1,7 @@ package com.xiaojinzi.component.application; -import android.support.annotation.MainThread; +import android.support.annotation.UiThread; -import com.xiaojinzi.component.ComponentConstants; import com.xiaojinzi.component.anno.ModuleAppAnno; import com.xiaojinzi.component.anno.support.CheckClassNameAnno; import com.xiaojinzi.component.support.IBaseLifecycle; @@ -14,7 +13,7 @@ * 你可以实现此接口或者{@link IComponentApplication} 接口, 但是建议实现此接口. * 老接口 {@link IComponentApplication} 会在将来某个版本删除 */ -@MainThread +@UiThread @CheckClassNameAnno public interface IApplicationLifecycle extends IBaseLifecycle { } diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/application/IComponentApplication.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/application/IComponentApplication.java index 811cae93..b2e187e7 100644 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/application/IComponentApplication.java +++ b/ComponentImpl/src/main/java/com/xiaojinzi/component/application/IComponentApplication.java @@ -1,15 +1,13 @@ package com.xiaojinzi.component.application; -import android.support.annotation.MainThread; +import android.support.annotation.UiThread; -import com.xiaojinzi.component.ComponentConstants; import com.xiaojinzi.component.anno.support.CheckClassNameAnno; -import com.xiaojinzi.component.support.IBaseLifecycle; /** * @see IApplicationLifecycle */ -@MainThread +@UiThread @CheckClassNameAnno public interface IComponentApplication extends IApplicationLifecycle { } diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/fragment/IComponentHostFragment.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/fragment/IComponentHostFragment.java index 08f36c59..055374c7 100644 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/fragment/IComponentHostFragment.java +++ b/ComponentImpl/src/main/java/com/xiaojinzi/component/fragment/IComponentHostFragment.java @@ -1,7 +1,7 @@ package com.xiaojinzi.component.fragment; -import android.support.annotation.MainThread; import android.support.annotation.NonNull; +import android.support.annotation.UiThread; import com.xiaojinzi.component.support.IBaseLifecycle; import com.xiaojinzi.component.support.IHost; @@ -20,7 +20,7 @@ public interface IComponentHostFragment extends IBaseLifecycle, IHost { * 第二:在注解驱动器中, 做了避免重复的操作 */ @NonNull - @MainThread + @UiThread Set getFragmentNameSet(); } diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/BiCallback.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/BiCallback.java index 64448941..b32a65ee 100644 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/BiCallback.java +++ b/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/BiCallback.java @@ -1,8 +1,8 @@ package com.xiaojinzi.component.impl; -import android.support.annotation.MainThread; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.annotation.UiThread; import com.xiaojinzi.component.anno.support.CheckClassNameAnno; import com.xiaojinzi.component.support.Function; @@ -26,7 +26,7 @@ public interface BiCallback extends OnRouterCancel, OnRouterError { * @param result 路由成功的对象 * @param t 返回的对象 */ - @MainThread + @UiThread void onSuccess(@NonNull RouterResult result, @NonNull T t); /** diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/Callback.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/Callback.java index e939213f..a068b43a 100644 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/Callback.java +++ b/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/Callback.java @@ -1,8 +1,8 @@ package com.xiaojinzi.component.impl; -import android.support.annotation.MainThread; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.annotation.UiThread; import com.xiaojinzi.component.anno.support.CheckClassNameAnno; import com.xiaojinzi.component.support.OnRouterCancel; @@ -31,7 +31,7 @@ public interface Callback extends OnRouterError, OnRouterCancel { * @see Navigator#navigate(Callback) * @see Navigator#navigateForResultCodeMatch(Callback, int) */ - @MainThread + @UiThread void onSuccess(@NonNull RouterResult result); /** @@ -40,7 +40,7 @@ public interface Callback extends OnRouterError, OnRouterCancel { * @param successResult 路由成功时候的返回对象,成功的对象 * @param errorResult 发生的错误对象 */ - @MainThread + @UiThread void onEvent(@Nullable RouterResult successResult, @Nullable RouterErrorResult errorResult); } diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/Navigator.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/Navigator.java index 5d1bd00b..63cd4b1d 100644 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/Navigator.java +++ b/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/Navigator.java @@ -12,6 +12,7 @@ import android.support.annotation.MainThread; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.annotation.UiThread; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; @@ -194,7 +195,7 @@ public Navigator proxyBundle(@NonNull Bundle bundle) { } @Override - public Navigator intentConsumer(@Nullable @MainThread Consumer intentConsumer) { + public Navigator intentConsumer(@Nullable @UiThread Consumer intentConsumer) { super.intentConsumer(intentConsumer); return this; } @@ -212,7 +213,7 @@ public Navigator addIntentCategories(@Nullable String... categories) { } @Override - public Navigator beforAction(@Nullable @MainThread Action action) { + public Navigator beforAction(@Nullable @UiThread Action action) { super.beforAction(action); return this; } @@ -230,19 +231,19 @@ public Navigator afterStartAction(@Nullable Action action) { } @Override - public Navigator afterAction(@Nullable @MainThread Action action) { + public Navigator afterAction(@Nullable @UiThread Action action) { super.afterAction(action); return this; } @Override - public Navigator afterErrorAction(@Nullable @MainThread Action action) { + public Navigator afterErrorAction(@Nullable @UiThread Action action) { super.afterErrorAction(action); return this; } @Override - public Navigator afterEventAction(@Nullable @MainThread Action action) { + public Navigator afterEventAction(@Nullable @UiThread Action action) { super.afterEventAction(action); return this; } @@ -518,6 +519,7 @@ public Navigator query(@NonNull String queryName, double queryValue) { } @Override + @NonNull public RouterRequest build() { RouterRequest routerRequest = super.build(); // 如果是随机的 requestCode, 则生成 @@ -589,7 +591,7 @@ private void onCheckForResult() throws Exception { * @param callback 回调方法 */ @AnyThread - public void forwardForResultCode(@NonNull @MainThread final BiCallback callback) { + public void forwardForResultCode(@NonNull @UiThread final BiCallback callback) { navigateForResultCode(callback); } @@ -601,7 +603,7 @@ public void forwardForResultCode(@NonNull @MainThread final BiCallback @NonNull @AnyThread @CheckResult - public NavigationDisposable navigateForResultCode(@NonNull @MainThread final BiCallback callback) { + public NavigationDisposable navigateForResultCode(@NonNull @UiThread final BiCallback callback) { return navigateForResult(new BiCallback.Map(callback) { @NonNull @Override @@ -618,7 +620,7 @@ public Integer apply(@NonNull ActivityResult activityResult) throws Exception { */ @AnyThread public void forwardForResultCodeMatch( - @NonNull @MainThread final Callback callback, final int expectedResultCode) { + @NonNull @UiThread final Callback callback, final int expectedResultCode) { navigateForResultCodeMatch(callback, expectedResultCode); } @@ -631,7 +633,7 @@ public void forwardForResultCodeMatch( @AnyThread @CheckResult public NavigationDisposable navigateForResultCodeMatch( - @NonNull @MainThread final Callback callback, final int expectedResultCode) { + @NonNull @UiThread final Callback callback, final int expectedResultCode) { return navigateForResult(new BiCallback() { @Override public void onSuccess(@NonNull RouterResult result, @NonNull ActivityResult activityResult) { @@ -661,7 +663,7 @@ public void onCancel(@NonNull RouterRequest originalRequest) { */ @AnyThread public void forwardForIntentAndResultCodeMatch( - @NonNull @MainThread final BiCallback callback, final int expectedResultCode) { + @NonNull @UiThread final BiCallback callback, final int expectedResultCode) { navigateForIntentAndResultCodeMatch(callback, expectedResultCode); } @@ -674,7 +676,7 @@ public void forwardForIntentAndResultCodeMatch( @AnyThread @CheckResult public NavigationDisposable navigateForIntentAndResultCodeMatch( - @NonNull @MainThread final BiCallback callback, + @NonNull @UiThread final BiCallback callback, final int expectedResultCode) { return navigateForResult(new BiCallback.Map(callback) { @NonNull @@ -691,7 +693,7 @@ public Intent apply(@NonNull ActivityResult activityResult) throws Exception { * @param callback 回调方法 */ @AnyThread - public void forwardForIntent(@NonNull @MainThread final BiCallback callback) { + public void forwardForIntent(@NonNull @UiThread final BiCallback callback) { navigateForIntent(callback); } @@ -703,7 +705,7 @@ public void forwardForIntent(@NonNull @MainThread final BiCallback callb @NonNull @AnyThread @CheckResult - public NavigationDisposable navigateForIntent(@NonNull @MainThread final BiCallback callback) { + public NavigationDisposable navigateForIntent(@NonNull @UiThread final BiCallback callback) { return navigateForResult(new BiCallback.Map(callback) { @NonNull @Override @@ -719,7 +721,7 @@ public Intent apply(@NonNull ActivityResult activityResult) throws Exception { * @param callback 这里是为了拿返回的东西是不可以为空的 */ @AnyThread - public void forwardForResult(@NonNull @MainThread final BiCallback callback) { + public void forwardForResult(@NonNull @UiThread final BiCallback callback) { navigateForResult(callback); } @@ -733,7 +735,7 @@ public void forwardForResult(@NonNull @MainThread final BiCallback callback) { + @NonNull @UiThread final BiCallback callback) { Utils.checkNullPointer(callback, "callback"); return realNavigateForResult(callback); } @@ -762,7 +764,7 @@ public NavigationDisposable navigate() { * @param callback 路由的回调 */ @AnyThread - public void forward(@Nullable @MainThread final Callback callback) { + public void forward(@Nullable @UiThread final Callback callback) { navigate(callback); } @@ -770,7 +772,7 @@ public void forward(@Nullable @MainThread final Callback callback) { @AnyThread @CheckResult public synchronized NavigationDisposable navigate( - @Nullable @MainThread final Callback callback) { + @Nullable @UiThread final Callback callback) { // 构建请求对象 RouterRequest originalRequest = null; // 可取消对象 @@ -868,7 +870,7 @@ public void run() { * 但是没有那个必要去做这件事情了,等到有必要的时候再说,基本不会出现并且出现了也不是什么问题 */ @NonNull - @MainThread + @UiThread private NavigationDisposable doNavigateForResult(@NonNull final BiCallback biCallback) { // 直接 gg Utils.checkNullPointer(biCallback, "biCallback"); @@ -903,7 +905,7 @@ private NavigationDisposable doNavigateForResult(@NonNull final BiCallback getCustomInterceptors(@NonNull RouterRequest originalRequest, @Nullable List customInterceptors) throws InterceptorNotFoundException { if (customInterceptors == null || customInterceptors.isEmpty()) { @@ -1097,6 +1099,7 @@ public InterceptorCallback(@NonNull RouterRequest originalRequest, @Override public void onSuccess(@NonNull RouterResult result) { + Utils.checkNullPointer(result); synchronized (this) { if (isEnd()) { return; @@ -1108,6 +1111,7 @@ public void onSuccess(@NonNull RouterResult result) { @Override public void onError(@NonNull Throwable error) { + Utils.checkNullPointer(error); synchronized (this) { if (isEnd()) { return; @@ -1160,7 +1164,7 @@ public void cancel() { * 最后确认 {@link Uri} 的目标没被改变的时候 * 就可以加载 {@link DoActivityStartInterceptor} 执行跳转了. */ - @MainThread + @UiThread private static class PageInterceptor implements RouterInterceptor { @NonNull @@ -1201,7 +1205,7 @@ public void intercept(@NonNull Chain chain) throws Exception { * 最后确认 {@link Uri} 的目标没被改变的时候 * 就可以加载 {@link DoActivityStartInterceptor} 执行跳转了. */ - @MainThread + @UiThread private static class PageInterceptorUriCheckInterceptor implements RouterInterceptor { @NonNull @@ -1282,7 +1286,7 @@ public void intercept(@NonNull Chain chain) throws Exception { * 1.如果跳转的时候没有发生异常, 说明可以跳转过去 * 如果失败了进行降级处理 */ - @MainThread + @UiThread private static class DoActivityStartInterceptor implements RouterInterceptor { @NonNull @@ -1297,7 +1301,7 @@ public DoActivityStartInterceptor(@NonNull RouterRequest originalRequest) { * @throws Exception */ @Override - @MainThread + @UiThread public void intercept(final Chain chain) throws Exception { // 这个 request 对象已经不是最原始的了,但是可能是最原始的,就看拦截器是否更改了这个对象了 RouterRequest finalRequest = chain.request(); @@ -1404,9 +1408,9 @@ private static class InterceptorChain implements RouterInterceptor.Chain { /** * @param interceptors 拦截器的即可 - * @param index 要执行的拦截器的下标 + * @param index 要执行的拦截器的下标 * @param request 第一次这个对象是不需要的 - * @param callback 用户的 {@link Callback} + * @param callback 用户的 {@link Callback} */ public InterceptorChain(@NonNull List interceptors, int index, @NonNull RouterRequest request, @NonNull RouterInterceptor.Callback callback) { diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/Router.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/Router.java index dddd8c9b..c08ee573 100644 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/Router.java +++ b/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/Router.java @@ -4,9 +4,9 @@ import android.content.Context; import android.os.Bundle; import android.support.annotation.AnyThread; -import android.support.annotation.MainThread; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.annotation.UiThread; import android.support.v4.app.Fragment; import com.xiaojinzi.component.Component; @@ -178,7 +178,7 @@ public static boolean isProxyIntentExist(@Nullable Bundle bundle) { * * @param act 要取消的 {@link Activity} */ - @MainThread + @UiThread public static void cancel(@NonNull Activity act) { Utils.checkMainThread(); synchronized (mNavigationDisposableList) { @@ -197,7 +197,7 @@ public static void cancel(@NonNull Activity act) { * * @param fragment {@link Fragment} */ - @MainThread + @UiThread public static void cancel(@NonNull Fragment fragment) { Utils.checkMainThread(); synchronized (mNavigationDisposableList) { diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/RouterCenter.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/RouterCenter.java index 57e026ca..b15db757 100644 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/RouterCenter.java +++ b/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/RouterCenter.java @@ -5,9 +5,9 @@ import android.content.Context; import android.content.Intent; import android.net.Uri; -import android.support.annotation.MainThread; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.annotation.UiThread; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; @@ -96,7 +96,7 @@ public boolean isSameTarget(@NonNull Uri uri1, @NonNull Uri uri2) { } @Override - @MainThread + @UiThread public void openUri(@NonNull final RouterRequest routerRequest) throws Exception { doOpenUri(routerRequest); } @@ -105,7 +105,7 @@ public void openUri(@NonNull final RouterRequest routerRequest) throws Exception * @param request 路由请求对象 * @param routerDegradeIntent 一个降级的 Intent */ - @MainThread + @UiThread public void routerDegrade(@NonNull RouterRequest request, @NonNull Intent routerDegradeIntent) throws Exception { String uriString = request.uri.toString(); if (routerDegradeIntent == null) { @@ -119,7 +119,7 @@ public void routerDegrade(@NonNull RouterRequest request, @NonNull Intent router * * @param request 路由请求对象 */ - @MainThread + @UiThread private void doOpenUri(@NonNull final RouterRequest request) throws Exception { if (!Utils.isMainThread()) { throw new NavigationFailException("Router must run on main thread"); @@ -142,7 +142,8 @@ private void doOpenUri(@NonNull final RouterRequest request) throws Exception { Context rawContext = request.getRawContext(); // 如果 Context 和 Fragment 中的 Context 都是 null if (rawContext == null) { - throw new NavigationFailException("is your fragment or Activity is Destoried?"); + throw new NavigationFailException("is your fragment or Activity is Destoried?\n" + + "see " + Component.ROUTER_UES_NOTE); } Intent intent = null; if (target.getTargetClass() != null) { @@ -162,7 +163,7 @@ private void doOpenUri(@NonNull final RouterRequest request) throws Exception { * @param request 请求对象 * @param intent Intent */ - @MainThread + @UiThread private void doStartIntent(@NonNull RouterRequest request, Intent intent) throws Exception { // 前置工作 diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/RouterInterceptor.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/RouterInterceptor.java index e8b92092..cfe86242 100644 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/RouterInterceptor.java +++ b/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/RouterInterceptor.java @@ -1,8 +1,8 @@ package com.xiaojinzi.component.impl; import android.support.annotation.AnyThread; -import android.support.annotation.MainThread; import android.support.annotation.NonNull; +import android.support.annotation.UiThread; import com.xiaojinzi.component.anno.support.CheckClassNameAnno; import com.xiaojinzi.component.support.RouterInterceptorCache; @@ -31,7 +31,7 @@ public interface RouterInterceptor { * * @param chain 拦截器执行连接器 */ - @MainThread + @UiThread void intercept(@NonNull Chain chain) throws Exception; /** diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/RouterListener.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/RouterListener.java index 427d1042..87dea433 100644 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/RouterListener.java +++ b/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/RouterListener.java @@ -1,7 +1,8 @@ package com.xiaojinzi.component.impl; -import android.support.annotation.MainThread; + import android.support.annotation.NonNull; +import android.support.annotation.UiThread; /** * 路由监听器,目前就只有三种情况,其实还有 RxJava 支持的 RxRouter 成功的和失败的 @@ -9,7 +10,7 @@ * * @author xiaojinzi */ -@MainThread +@UiThread public interface RouterListener { /** @@ -17,7 +18,7 @@ public interface RouterListener { * * @param successResult 成功的对象 */ - @MainThread + @UiThread void onSuccess(@NonNull RouterResult successResult) throws Exception; /** @@ -25,7 +26,7 @@ public interface RouterListener { * * @param errorResult 失败的对象 */ - @MainThread + @UiThread void onError(RouterErrorResult errorResult) throws Exception; /** @@ -33,7 +34,7 @@ public interface RouterListener { * * @param originalRequest 最原始的请求对象 */ - @MainThread + @UiThread void onCancel(@NonNull RouterRequest originalRequest) throws Exception; } \ No newline at end of file diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/RouterRequest.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/RouterRequest.java index f29a713a..0f2ed0d9 100644 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/RouterRequest.java +++ b/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/RouterRequest.java @@ -6,9 +6,9 @@ import android.net.Uri; import android.os.Bundle; import android.os.Parcelable; -import android.support.annotation.MainThread; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.annotation.UiThread; import android.support.v4.app.Fragment; import android.text.TextUtils; import android.util.SparseArray; @@ -81,13 +81,13 @@ public class RouterRequest { public final Bundle options; /** - * Intent 的 flag + * Intent 的 flag, 集合不可更改 */ @NonNull public final List intentFlags; /** - * Intent 的 类别 + * Intent 的 类别, 集合不可更改 */ @NonNull public final List intentCategories; @@ -158,9 +158,7 @@ private RouterRequest(@NonNull Builder builder) { // 这两个集合是不可以更改的 intentCategories = Collections.unmodifiableList(builder.intentCategories); intentFlags = Collections.unmodifiableList(builder.intentFlags); - if (builder.bundle != null) { - this.bundle.putAll(builder.bundle); - } + this.bundle.putAll(builder.bundle); intentConsumer = builder.intentConsumer; beforAction = builder.beforAction; beforStartAction = builder.beforStartAction; @@ -280,9 +278,8 @@ public final Activity getRawOrTopActivity() { /** * 这里转化的对象会比 {@link Builder} 对象中的参数少一个 {@link Builder#url} * 因为 uri 转化为了 scheme,host,path,queryMap 那么这时候就不需要 url 了 - * - * @return */ + @NonNull public Builder toBuilder() { Builder builder = new Builder(); @@ -301,7 +298,10 @@ public Builder toBuilder() { } } - builder.bundle = bundle; + if (builder.bundle == null) { + builder.bundle = new Bundle(); + } + builder.bundle.putAll(bundle); builder.requestCode = requestCode; builder.isForResult = isForResult; builder.options = options; @@ -410,32 +410,32 @@ public Builder fragment(@Nullable Fragment fragment) { return this; } - public Builder beforAction(@Nullable @MainThread Action action) { + public Builder beforAction(@Nullable @UiThread Action action) { this.beforAction = action; return this; } - public Builder beforStartAction(@Nullable @MainThread Action action) { + public Builder beforStartAction(@Nullable @UiThread Action action) { this.beforStartAction = action; return this; } - public Builder afterStartAction(@Nullable @MainThread Action action) { + public Builder afterStartAction(@Nullable @UiThread Action action) { this.afterStartAction = action; return this; } - public Builder afterAction(@Nullable @MainThread Action action) { + public Builder afterAction(@Nullable @UiThread Action action) { this.afterAction = action; return this; } - public Builder afterErrorAction(@Nullable @MainThread Action action) { + public Builder afterErrorAction(@Nullable @UiThread Action action) { this.afterErrorAction = action; return this; } - public Builder afterEventAction(@Nullable @MainThread Action action) { + public Builder afterEventAction(@Nullable @UiThread Action action) { this.afterEventAction = action; return this; } @@ -456,7 +456,7 @@ public Builder requestCode(@Nullable Integer requestCode) { * 更改的机会,最好别更改内部的参数等的信息,这里提供出来其实主要是可以让你调用Intent * 的 {@link Intent#addFlags(int)} 等方法,并不是给你修改内部的 bundle 的 */ - public Builder intentConsumer(@Nullable @MainThread Consumer intentConsumer) { + public Builder intentConsumer(@Nullable @UiThread Consumer intentConsumer) { this.intentConsumer = intentConsumer; return this; } @@ -717,6 +717,7 @@ public Builder query(@NonNull String queryName, double queryValue) { * * @return 可能会抛出一个运行时异常, 由于您的参数在构建 uri 的时候出现的异常 */ + @NonNull public RouterRequest build() { return new RouterRequest(this); } diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/RouterResult.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/RouterResult.java index c0b8f100..48d805c2 100644 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/RouterResult.java +++ b/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/RouterResult.java @@ -2,6 +2,8 @@ import android.support.annotation.NonNull; +import com.xiaojinzi.component.support.Utils; + /** * 这个类表示一次成功路由的返回结果对象 * time : 2018/11/10 @@ -28,6 +30,8 @@ public class RouterResult { * @param finalRequest 可能修改过的请求,也可能是和原始请求一样 */ public RouterResult(@NonNull RouterRequest originalRequest, @NonNull RouterRequest finalRequest) { + Utils.checkNullPointer(originalRequest); + Utils.checkNullPointer(finalRequest); this.mOriginalRequest = originalRequest; this.mFinalRequest = finalRequest; } @@ -44,8 +48,6 @@ public RouterRequest getOriginalRequest() { /** * 获取可能由拦截器修改过的 request 对象,大部分没有被修改的其实就是最原始的 request 对象 - * - * @return */ @NonNull public RouterRequest getFinalRequest() { diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/RouterUtil.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/RouterUtil.java index 97155d73..9d1c93dd 100644 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/RouterUtil.java +++ b/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/RouterUtil.java @@ -7,6 +7,7 @@ import android.support.annotation.MainThread; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.annotation.UiThread; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; @@ -45,7 +46,7 @@ public void run() { } - @MainThread + @UiThread private static void cancelCallbackOnMainThread(@Nullable RouterRequest request, @Nullable final OnRouterCancel callback) { if (request == null) { @@ -72,7 +73,7 @@ public void run() { deliveryListener(null, errorResult, null); } - @MainThread + @UiThread private static void errorCallbackOnMainThread(@Nullable final Callback callback, @Nullable final BiCallback biCallback, @NonNull final RouterErrorResult errorResult) { @@ -115,7 +116,7 @@ public void run() { deliveryListener(successResult, null, null); } - @MainThread + @UiThread private static void successCallbackOnMainThread(@Nullable final Callback callback, @NonNull final RouterResult result) { Utils.checkNullPointer(result, "result"); @@ -126,7 +127,7 @@ private static void successCallbackOnMainThread(@Nullable final Callback callbac } // 执行 Request 中 的 afterCallback try { - RouterRequestHelp.executeAfterAction(result.getOriginalRequest()); + RouterRequestHelp.executeAfterAction(result.getFinalRequest()); } catch (Exception e) { throw new RouterRuntimeException("afterJumpCallback or afterEventCallback can't throw any exception!", e); } @@ -148,7 +149,7 @@ public void run() { }); } - @MainThread + @UiThread public static void deliveryListenerOnMainThread(@Nullable final RouterResult successResult, @Nullable final RouterErrorResult errorResult, @Nullable final RouterRequest cancelRequest) { diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/application/ModuleManager.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/application/ModuleManager.java index 54d5a204..1db57573 100644 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/application/ModuleManager.java +++ b/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/application/ModuleManager.java @@ -28,6 +28,8 @@ */ public class ModuleManager implements IComponentCenterApplication { + public static final String ISSUE = "https://github.com/xiaojinzi123/Component/issues/21"; + /** * 单例对象 */ @@ -104,7 +106,7 @@ public void registerArr(@Nullable String... hosts) { for (String host : hosts) { IComponentHostApplication moduleApplication = findModuleApplication(host); if (moduleApplication == null) { - LogUtil.log("模块 '" + host + "' 加载失败"); + LogUtil.log("模块 '" + host + "' 加载失败, 请根据链接中的内容自行排查! \n " + Component.COMMON_ERROR_ISSUE); } else { register(moduleApplication); } diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/interceptor/InterceptorCenter.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/interceptor/InterceptorCenter.java index ddb0bfdd..b7b4532f 100644 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/interceptor/InterceptorCenter.java +++ b/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/interceptor/InterceptorCenter.java @@ -1,8 +1,8 @@ package com.xiaojinzi.component.impl.interceptor; -import android.support.annotation.MainThread; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.annotation.UiThread; import com.xiaojinzi.component.Component; import com.xiaojinzi.component.ComponentUtil; @@ -81,7 +81,7 @@ public static InterceptorCenter getInstance() { /** * 获取全局拦截器 */ - @MainThread + @UiThread public List getGlobalInterceptorList() { if (isInterceptorListHaveChange) { loadAllGlobalInterceptor(); @@ -135,7 +135,7 @@ public void unregister(@NonNull String host) { /** * 按顺序弄好所有全局拦截器 */ - @MainThread + @UiThread private void loadAllGlobalInterceptor() { mGlobalInterceptorList.clear(); List totalList = new ArrayList<>(); @@ -163,7 +163,7 @@ public int compare(InterceptorBean o1, InterceptorBean o2) { } @Nullable - @MainThread + @UiThread public IComponentHostInterceptor findModuleInterceptor(String host) { Utils.checkMainThread(); try { @@ -183,7 +183,7 @@ public IComponentHostInterceptor findModuleInterceptor(String host) { @Nullable @Override - @MainThread + @UiThread public RouterInterceptor getByName(@Nullable String interceptorName) { if (interceptorName == null) { return null; @@ -203,7 +203,7 @@ public RouterInterceptor getByName(@Nullable String interceptorName) { /** * 做拦截器的名称是否重复的工作 */ - @MainThread + @UiThread public void check() { Utils.checkMainThread(); Set set = new HashSet<>(); diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/interceptor/ModuleInterceptorImpl.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/interceptor/ModuleInterceptorImpl.java index 1bf17954..9cac20b6 100644 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/interceptor/ModuleInterceptorImpl.java +++ b/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/interceptor/ModuleInterceptorImpl.java @@ -2,9 +2,9 @@ import android.app.Application; import android.support.annotation.CallSuper; -import android.support.annotation.MainThread; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.annotation.UiThread; import com.xiaojinzi.component.impl.RouterInterceptor; import com.xiaojinzi.component.interceptor.IComponentHostInterceptor; @@ -48,7 +48,7 @@ public void onDestroy() { @Override @NonNull - @MainThread + @UiThread public List globalInterceptorList() { return Collections.emptyList(); } @@ -57,7 +57,7 @@ public List globalInterceptorList() { * 初始化拦截器的集合 */ @CallSuper - @MainThread + @UiThread protected void initInterceptorMap() { isInitMap = true; } @@ -82,7 +82,7 @@ public Map> getInterceptorMap() { @Override @Nullable - @MainThread + @UiThread public RouterInterceptor getByName(@Nullable String name) { if (name == null) { return null; diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/service/ServiceManager.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/service/ServiceManager.java index 00c2dcba..e06325e9 100644 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/service/ServiceManager.java +++ b/ComponentImpl/src/main/java/com/xiaojinzi/component/impl/service/ServiceManager.java @@ -6,7 +6,6 @@ import com.xiaojinzi.component.Component; import com.xiaojinzi.component.anno.support.CheckClassNameAnno; -import com.xiaojinzi.component.service.IServiceLifecycle; import com.xiaojinzi.component.support.Action; import com.xiaojinzi.component.support.CallNullable; import com.xiaojinzi.component.support.Callable; @@ -44,35 +43,24 @@ private ServiceManager() { public static void register(@NonNull Class tClass, @NonNull Callable callable) { Utils.checkNullPointer(tClass, "tClass"); Utils.checkNullPointer(callable, "callable"); - // 先卸载, 因为覆盖的话, 生命周期的销毁就走不了 unregister(tClass); serviceMap.put(tClass, callable); } @Nullable @AnyThread - public static T unregister(@NonNull Class tClass) { + public static void unregister(@NonNull Class tClass) { Utils.checkNullPointer(tClass, "tClass"); // 需要判断到是否已经初始化了, 如果还没初始化就返回 null Callable callable = serviceMap.remove(tClass); if (callable == null) { - return null; + return; } if (callable instanceof SingletonCallable) { if (((SingletonCallable) callable).isInit()) { - final T t = (T) callable.get(); - if (t instanceof IServiceLifecycle) { - Utils.mainThreadAction(new Action() { - @Override - public void run() { - ((IServiceLifecycle) t).onDestroy(); - } - }); - } - return t; + ((SingletonCallable) callable).destroy(); } } - return null; } /** @@ -93,18 +81,8 @@ public T get() { if (callable == null) { return null; } else { - T t = null; - boolean isNeedCallOnCreateMethod = true; - if (callable instanceof SingletonCallable) { // 如果是单利的 - if (((SingletonCallable) callable).isInit()) { - isNeedCallOnCreateMethod = false; - } - } // 如果没创建, 这时候会创建了目标 service 对象 - t = (T) Utils.checkNullPointer(callable.get()); - if (isNeedCallOnCreateMethod && t instanceof IServiceLifecycle) { - ((IServiceLifecycle) t).onCreate(Component.getApplication()); - } + T t = (T) Utils.checkNullPointer(callable.get()); return t; } } diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/interceptor/IComponentCenterInterceptor.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/interceptor/IComponentCenterInterceptor.java index 49fa9658..58b4b1fc 100644 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/interceptor/IComponentCenterInterceptor.java +++ b/ComponentImpl/src/main/java/com/xiaojinzi/component/interceptor/IComponentCenterInterceptor.java @@ -1,10 +1,10 @@ package com.xiaojinzi.component.interceptor; -import android.support.annotation.MainThread; import android.support.annotation.NonNull; +import android.support.annotation.UiThread; -import com.xiaojinzi.component.support.IComponentCenter; import com.xiaojinzi.component.impl.RouterInterceptor; +import com.xiaojinzi.component.support.IComponentCenter; import java.util.List; @@ -22,7 +22,7 @@ public interface IComponentCenterInterceptor extends IComponentInterceptor, ICom * @return 全局的拦截器列表 */ @NonNull - @MainThread + @UiThread List getGlobalInterceptorList(); } diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/interceptor/IComponentHostInterceptor.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/interceptor/IComponentHostInterceptor.java index 2b9927ca..d0d9e768 100644 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/interceptor/IComponentHostInterceptor.java +++ b/ComponentImpl/src/main/java/com/xiaojinzi/component/interceptor/IComponentHostInterceptor.java @@ -1,7 +1,7 @@ package com.xiaojinzi.component.interceptor; -import android.support.annotation.MainThread; import android.support.annotation.NonNull; +import android.support.annotation.UiThread; import com.xiaojinzi.component.impl.RouterInterceptor; import com.xiaojinzi.component.impl.interceptor.InterceptorBean; @@ -26,7 +26,7 @@ public interface IComponentHostInterceptor * 让外面使用的地方去初始化也可以 */ @NonNull - @MainThread + @UiThread List globalInterceptorList(); /** @@ -35,14 +35,14 @@ public interface IComponentHostInterceptor * 拦截器做检查 */ @NonNull - @MainThread + @UiThread Set getInterceptorNames(); /** * 获取拦截器集合 */ @NonNull - @MainThread + @UiThread Map> getInterceptorMap(); } diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/interceptor/IComponentInterceptor.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/interceptor/IComponentInterceptor.java index 847faa7c..fad3e1c6 100644 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/interceptor/IComponentInterceptor.java +++ b/ComponentImpl/src/main/java/com/xiaojinzi/component/interceptor/IComponentInterceptor.java @@ -1,7 +1,7 @@ package com.xiaojinzi.component.interceptor; -import android.support.annotation.MainThread; import android.support.annotation.Nullable; +import android.support.annotation.UiThread; import com.xiaojinzi.component.impl.RouterInterceptor; @@ -19,7 +19,7 @@ public interface IComponentInterceptor { * @param name if name is null,return null */ @Nullable - @MainThread + @UiThread RouterInterceptor getByName(@Nullable String name); } diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/router/IComponentRouter.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/router/IComponentRouter.java index dc60e603..3dec8483 100644 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/router/IComponentRouter.java +++ b/ComponentImpl/src/main/java/com/xiaojinzi/component/router/IComponentRouter.java @@ -1,8 +1,8 @@ package com.xiaojinzi.component.router; import android.net.Uri; -import android.support.annotation.MainThread; import android.support.annotation.NonNull; +import android.support.annotation.UiThread; import com.xiaojinzi.component.impl.RouterInterceptor; import com.xiaojinzi.component.impl.RouterRequest; @@ -24,7 +24,7 @@ public interface IComponentRouter { * * @throws android.content.ActivityNotFoundException */ - @MainThread + @UiThread void openUri(@NonNull RouterRequest routerRequest) throws Exception; /** @@ -64,7 +64,7 @@ public interface IComponentRouter { * @throws Exception */ @NonNull - @MainThread + @UiThread List listPageInterceptors(@NonNull Uri uri) throws Exception; /** @@ -72,7 +72,7 @@ public interface IComponentRouter { * 获取该 URI 对应的降级需要执行的拦截器 */ @NonNull - @MainThread + @UiThread List listDegradeInterceptors(@NonNull Uri uri) throws Exception; } diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/service/IServiceLifecycle.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/service/IServiceLifecycle.java deleted file mode 100644 index dacb5a85..00000000 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/service/IServiceLifecycle.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.xiaojinzi.component.service; - -import com.xiaojinzi.component.support.IBaseLifecycle; - -/** - * 如果一个自定义的 Service 想有基本的生命周期的回调, 请实现此接口 - */ -public interface IServiceLifecycle extends IBaseLifecycle { -} diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/support/CallbackAdapter.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/support/CallbackAdapter.java index eb3202f8..79b37d7c 100644 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/support/CallbackAdapter.java +++ b/ComponentImpl/src/main/java/com/xiaojinzi/component/support/CallbackAdapter.java @@ -1,8 +1,8 @@ package com.xiaojinzi.component.support; -import android.support.annotation.MainThread; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.annotation.UiThread; import com.xiaojinzi.component.impl.Callback; import com.xiaojinzi.component.impl.RouterErrorResult; @@ -15,25 +15,25 @@ public class CallbackAdapter implements Callback { @Override - @MainThread + @UiThread public void onSuccess(@NonNull RouterResult result) { // empty } @Override - @MainThread + @UiThread public void onError(RouterErrorResult errorResult) { // empty } @Override - @MainThread + @UiThread public void onEvent(@Nullable RouterResult successResult, @Nullable RouterErrorResult errorResult) { // empty } @Override - @MainThread + @UiThread public void onCancel(@NonNull RouterRequest originalRequest) { // empty } diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/support/ConditionCache.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/support/ConditionCache.java index 8e841afc..ad830219 100644 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/support/ConditionCache.java +++ b/ComponentImpl/src/main/java/com/xiaojinzi/component/support/ConditionCache.java @@ -34,7 +34,7 @@ public static synchronized Condition getByClass(@NonNull Class { * * @param t 注册的目标 */ - @MainThread + @UiThread void register(T t); /** @@ -21,7 +21,7 @@ public interface IComponentCenter { * * @param host 需要注册的 host */ - @MainThread + @UiThread void register(@NonNull String host); /** @@ -29,7 +29,7 @@ public interface IComponentCenter { * * @param t 反注册的目标 */ - @MainThread + @UiThread void unregister(T t); /** @@ -37,7 +37,7 @@ public interface IComponentCenter { * * @param host 反注册的 host */ - @MainThread + @UiThread void unregister(@NonNull String host); } diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/support/IHost.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/support/IHost.java index 4b0bdf0d..c4cced1c 100644 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/support/IHost.java +++ b/ComponentImpl/src/main/java/com/xiaojinzi/component/support/IHost.java @@ -1,7 +1,7 @@ package com.xiaojinzi.component.support; -import android.support.annotation.MainThread; import android.support.annotation.NonNull; +import android.support.annotation.UiThread; /** * 获取 Host 的接口 @@ -12,7 +12,7 @@ public interface IHost { * 获取模块的 host */ @NonNull - @MainThread + @UiThread String getHost(); } diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/support/Inject.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/support/Inject.java index 99a113d7..bce49133 100644 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/support/Inject.java +++ b/ComponentImpl/src/main/java/com/xiaojinzi/component/support/Inject.java @@ -4,6 +4,7 @@ import android.os.Bundle; import android.support.annotation.MainThread; import android.support.annotation.NonNull; +import android.support.annotation.UiThread; import android.support.v4.app.Fragment; import com.xiaojinzi.component.anno.support.CheckClassNameAnno; @@ -19,7 +20,7 @@ public interface Inject { * * @param target 目标 */ - @MainThread + @UiThread void injectAttrValue(@NonNull T target); /** @@ -28,7 +29,7 @@ public interface Inject { * @param target 目标 * @param bundle 数据源的 bundle */ - @MainThread + @UiThread void injectAttrValue(@NonNull T target, @NonNull Bundle bundle); /** @@ -36,7 +37,7 @@ public interface Inject { * * @param target 目标 */ - @MainThread + @UiThread void injectService(@NonNull T target); } diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/support/OnRouterCancel.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/support/OnRouterCancel.java index 936673ce..08f31b7e 100644 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/support/OnRouterCancel.java +++ b/ComponentImpl/src/main/java/com/xiaojinzi/component/support/OnRouterCancel.java @@ -1,11 +1,9 @@ package com.xiaojinzi.component.support; -import android.support.annotation.MainThread; -import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.annotation.UiThread; import com.xiaojinzi.component.impl.RouterRequest; -import com.xiaojinzi.component.support.NavigationDisposable; /** * 被取消了回调接口 @@ -20,7 +18,7 @@ public interface OnRouterCancel { * 的时候不会调用这个方法,因为这时候是不可以取消的,因为压根就没开始,当 request 构建出来了 * 这时候就可以取消了,所以在真正取消的时候,一定会有这个参数的 */ - @MainThread + @UiThread void onCancel(@Nullable RouterRequest originalRequest); } diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/support/OnRouterError.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/support/OnRouterError.java index 6d2b6ff4..1a00db31 100644 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/support/OnRouterError.java +++ b/ComponentImpl/src/main/java/com/xiaojinzi/component/support/OnRouterError.java @@ -1,11 +1,9 @@ package com.xiaojinzi.component.support; -import android.support.annotation.MainThread; import android.support.annotation.NonNull; -import android.support.annotation.Nullable; +import android.support.annotation.UiThread; import com.xiaojinzi.component.impl.RouterErrorResult; -import com.xiaojinzi.component.support.NavigationDisposable; /** * 被取消了回调接口 @@ -17,7 +15,7 @@ public interface OnRouterError { * * @param errorResult 路由失败的对象 */ - @MainThread + @UiThread void onError(@NonNull RouterErrorResult errorResult); } diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/support/RouterInterceptorCache.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/support/RouterInterceptorCache.java index 3c4d62ef..d66ec835 100644 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/support/RouterInterceptorCache.java +++ b/ComponentImpl/src/main/java/com/xiaojinzi/component/support/RouterInterceptorCache.java @@ -2,9 +2,9 @@ import android.app.Application; import android.content.Context; -import android.support.annotation.MainThread; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.annotation.UiThread; import com.xiaojinzi.component.Component; import com.xiaojinzi.component.anno.RouterAnno; @@ -38,7 +38,7 @@ private RouterInterceptorCache() { * 内部做了缓存,如果缓存中没有就会反射创建拦截器对象 */ @Nullable - @MainThread + @UiThread public static synchronized RouterInterceptor getInterceptorByClass(@NonNull Class tClass) { RouterInterceptor t = ClassCache.get(tClass); if (t != null) { diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/support/RouterRequestHelp.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/support/RouterRequestHelp.java index e8902f44..e29efd8b 100644 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/support/RouterRequestHelp.java +++ b/ComponentImpl/src/main/java/com/xiaojinzi/component/support/RouterRequestHelp.java @@ -1,7 +1,7 @@ package com.xiaojinzi.component.support; -import android.support.annotation.MainThread; import android.support.annotation.NonNull; +import android.support.annotation.UiThread; import com.xiaojinzi.component.impl.RouterRequest; @@ -10,7 +10,7 @@ */ public class RouterRequestHelp { - @MainThread + @UiThread public static void executeBeforAction(@NonNull RouterRequest request) throws Exception { Utils.checkNullPointer(request, "request"); if (request.beforAction != null) { @@ -18,7 +18,7 @@ public static void executeBeforAction(@NonNull RouterRequest request) throws Exc } } - @MainThread + @UiThread public static void executeAfterAction(@NonNull RouterRequest request) throws Exception { Utils.checkNullPointer(request, "request"); if (request.afterAction != null) { @@ -27,7 +27,7 @@ public static void executeAfterAction(@NonNull RouterRequest request) throws Exc executeAfterEventAction(request); } - @MainThread + @UiThread public static void executeAfterErrorAction(@NonNull RouterRequest request) throws Exception { Utils.checkNullPointer(request, "request"); if (request.afterErrorAction != null) { @@ -36,7 +36,7 @@ public static void executeAfterErrorAction(@NonNull RouterRequest request) throw executeAfterEventAction(request); } - @MainThread + @UiThread public static void executeAfterEventAction(@NonNull RouterRequest request) throws Exception { Utils.checkNullPointer(request, "request"); if (request.afterEventAction != null) { diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/support/SingletonCallable.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/support/SingletonCallable.java index 05a4e0c3..faf997d8 100644 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/support/SingletonCallable.java +++ b/ComponentImpl/src/main/java/com/xiaojinzi/component/support/SingletonCallable.java @@ -31,6 +31,10 @@ public final T get() { return instance; } + public synchronized final void destroy() { + instance = null; + } + /** * 获取真正的对象 */ diff --git a/ComponentImpl/src/main/java/com/xiaojinzi/component/support/Utils.java b/ComponentImpl/src/main/java/com/xiaojinzi/component/support/Utils.java index 797c683c..868f81b1 100644 --- a/ComponentImpl/src/main/java/com/xiaojinzi/component/support/Utils.java +++ b/ComponentImpl/src/main/java/com/xiaojinzi/component/support/Utils.java @@ -9,9 +9,9 @@ import android.os.Handler; import android.os.Looper; import android.support.annotation.AnyThread; -import android.support.annotation.MainThread; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.annotation.UiThread; import com.xiaojinzi.component.Component; import com.xiaojinzi.component.error.RouterRuntimeException; @@ -271,7 +271,7 @@ public void run() { @AnyThread @SuppressLint("WrongThread") - public static void mainThreadAction(@NonNull @MainThread final Action action) { + public static void mainThreadAction(@NonNull @UiThread final Action action) { if (isMainThread()) { action.run(); } else { diff --git a/ComponentPlugin/src/main/java/com/xiaojinzi/component/plugin/ComponentPlugin.java b/ComponentPlugin/src/main/java/com/xiaojinzi/component/plugin/ComponentPlugin.java index ded21202..feff3fe0 100644 --- a/ComponentPlugin/src/main/java/com/xiaojinzi/component/plugin/ComponentPlugin.java +++ b/ComponentPlugin/src/main/java/com/xiaojinzi/component/plugin/ComponentPlugin.java @@ -25,18 +25,26 @@ public class ComponentPlugin implements Plugin { public static final String ROUTER_FOLDER = "component_router_doc_folder"; - public static final String ROUTER_ENABLE = "componnet_router_doc_enable"; + public static final String ROUTER_ENABLE = "component_router_doc_enable"; @Override public void apply(final Project project) { BaseAppModuleExtension appModuleExtension = (BaseAppModuleExtension) project.getProperties().get("android"); + Object asmDisable = project.findProperty("component_asm_disable"); Object asmUtilOutputPath = project.findProperty("component_asm_util_class_output_path"); + boolean asmDisableBool = false; + if (asmDisable instanceof Boolean) { + asmDisableBool = (boolean) asmDisable; + } // may be null String asmUtilOutputPathStr = null; if (asmUtilOutputPath instanceof String) { asmUtilOutputPathStr = (String) asmUtilOutputPath; } - appModuleExtension.registerTransform(new ModifyASMUtilTransform(asmUtilOutputPathStr)); + // 不禁用的话, 才注册 + if (!asmDisableBool) { + appModuleExtension.registerTransform(new ModifyASMUtilTransform(asmUtilOutputPathStr)); + } // 生成文档功能的 routerDocTask(project); cleanTask(project); diff --git a/ComponentPlugin/src/main/java/com/xiaojinzi/component/plugin/ModifyASMUtilTransform.java b/ComponentPlugin/src/main/java/com/xiaojinzi/component/plugin/ModifyASMUtilTransform.java index ee7203f6..d86cff65 100644 --- a/ComponentPlugin/src/main/java/com/xiaojinzi/component/plugin/ModifyASMUtilTransform.java +++ b/ComponentPlugin/src/main/java/com/xiaojinzi/component/plugin/ModifyASMUtilTransform.java @@ -117,6 +117,7 @@ public void transform(TransformInvocation transformInvocation) throws TransformE routerDegradeMap, serviceMap, fragmentMap ); try { + // 生成到桌面用来测试 if (mAsmUtilOutputPathStr != null && !"".equals(mAsmUtilOutputPathStr)) { File file = new File(mAsmUtilOutputPathStr); file.delete(); @@ -130,7 +131,6 @@ public void transform(TransformInvocation transformInvocation) throws TransformE } catch (Exception ignore) { // ignore } - // 生成到桌面用来测试 ZipEntry asmUtiZipEntry = new ZipEntry(jarEntry.getName()); asmUtiZipEntry.setSize(bytes.length); CRC32 crc = new CRC32(); diff --git a/ComponentRxImpl/src/main/java/com/xiaojinzi/component/impl/RxRouter.java b/ComponentRxImpl/src/main/java/com/xiaojinzi/component/impl/RxRouter.java index 6d79bf9b..c500c2dc 100644 --- a/ComponentRxImpl/src/main/java/com/xiaojinzi/component/impl/RxRouter.java +++ b/ComponentRxImpl/src/main/java/com/xiaojinzi/component/impl/RxRouter.java @@ -5,9 +5,9 @@ import android.os.Bundle; import android.os.Parcelable; import android.support.annotation.CheckResult; -import android.support.annotation.MainThread; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.annotation.UiThread; import android.support.v4.app.Fragment; import android.util.SparseArray; @@ -89,44 +89,44 @@ private RxNavigator(@NonNull Fragment fragment) { } @Override - public RxNavigator beforAction(@NonNull @MainThread Action action) { + public RxNavigator beforAction(@NonNull @UiThread Action action) { super.beforAction(action); return this; } @Override - public RxNavigator beforStartAction(@NonNull @MainThread Action action) { + public RxNavigator beforStartAction(@NonNull @UiThread Action action) { super.beforStartAction(action); return this; } @Override - public RxNavigator afterStartAction(@NonNull @MainThread Action action) { + public RxNavigator afterStartAction(@NonNull @UiThread Action action) { super.afterStartAction(action); return this; } @Override - public RxNavigator afterAction(@NonNull @MainThread Action action) { + public RxNavigator afterAction(@NonNull @UiThread Action action) { super.afterAction(action); return this; } @Override - public RxNavigator afterErrorAction(@Nullable @MainThread Action action) { + public RxNavigator afterErrorAction(@Nullable @UiThread Action action) { super.afterErrorAction(action); return this; } @Override - public RxNavigator afterEventAction(@Nullable @MainThread Action action) { + public RxNavigator afterEventAction(@Nullable @UiThread Action action) { super.afterEventAction(action); return this; } @Override public RxNavigator intentConsumer( - @NonNull @MainThread com.xiaojinzi.component.support.Consumer intentConsumer) { + @NonNull @UiThread com.xiaojinzi.component.support.Consumer intentConsumer) { super.intentConsumer(intentConsumer); return this; } @@ -589,7 +589,7 @@ public void subscribe(final CompletableEmitter emitter) throws Exception { // 可能是一个 空实现,这些个回调都是回调在主线程的 final NavigationDisposable navigationDisposable = navigate(new CallbackAdapter() { @Override - @MainThread + @UiThread public void onSuccess(@NonNull RouterResult routerResult) { super.onSuccess(routerResult); if (emitter != null && !emitter.isDisposed()) { @@ -598,7 +598,7 @@ public void onSuccess(@NonNull RouterResult routerResult) { } @Override - @MainThread + @UiThread public void onError(@NonNull RouterErrorResult errorResult) { super.onError(errorResult); RxHelp.onErrorSolve(emitter, errorResult.getError()); @@ -660,7 +660,7 @@ private static void onErrorSolve(@NonNull CompletableEmitter emitter, @NonNull T * 发射错误,目前这些个发射错误都是为了 {@link RxRouter} 写的,发射的错误和正确的 item 被发射都应该 * 最终发射在主线程 */ - private static void onErrorEmitter(@MainThread final SingleEmitter emitter, + private static void onErrorEmitter(@UiThread final SingleEmitter emitter, @NonNull final Throwable e) { if (emitter == null || emitter.isDisposed()) { return; @@ -684,7 +684,7 @@ public void run() { * @param emitter {@link Completable} 的发射器 * @param e 跑出的异常 */ - private static void onErrorEmitter(@MainThread final CompletableEmitter emitter, + private static void onErrorEmitter(@UiThread final CompletableEmitter emitter, @NonNull final Throwable e) { if (emitter == null || emitter.isDisposed()) { return; diff --git a/Module1/build.gradle b/Module1/build.gradle index 456aafd9..24393325 100644 --- a/Module1/build.gradle +++ b/Module1/build.gradle @@ -14,7 +14,7 @@ android { arguments = [ "HOST" : "component1", "RouterDocFolder": project.property("component_router_doc_folder"), - "RouterDocEnable": String.valueOf(project.property("componnet_router_doc_enable")) + "RouterDocEnable": String.valueOf(project.property("component_router_doc_enable")) ] } } diff --git a/Module1/gradle.properties b/Module1/gradle.properties index 22413b6b..e69de29b 100644 --- a/Module1/gradle.properties +++ b/Module1/gradle.properties @@ -1,4 +0,0 @@ -canRunAlone=true -isLibraryActual=true -//debugComponents=UserComponent -//releaseComponents=UserComponent \ No newline at end of file diff --git a/Module1/src/main/java/com/xiaojinzi/component1/service/Component1ServiceImpl.java b/Module1/src/main/java/com/xiaojinzi/component1/service/Component1ServiceImpl.java index 6b669582..7d6f7103 100644 --- a/Module1/src/main/java/com/xiaojinzi/component1/service/Component1ServiceImpl.java +++ b/Module1/src/main/java/com/xiaojinzi/component1/service/Component1ServiceImpl.java @@ -7,7 +7,6 @@ import com.xiaojinzi.base.service.inter.component1.Component1Service; import com.xiaojinzi.component.anno.ServiceAnno; -import com.xiaojinzi.component.service.IServiceLifecycle; import java.util.Random; import java.util.concurrent.TimeUnit; @@ -15,7 +14,7 @@ import io.reactivex.Single; @ServiceAnno(Component1Service.class) -public class Component1ServiceImpl implements Component1Service, IServiceLifecycle { +public class Component1ServiceImpl implements Component1Service { private Random r = new Random(); private Context context; @@ -42,14 +41,4 @@ public Single testError() throws Exception { } } - @Override - public void onCreate(@NonNull Application app) { - System.out.println(""); - } - - @Override - public void onDestroy() { - System.out.println(""); - } - } diff --git a/Module2/build.gradle b/Module2/build.gradle index 808d45e8..9f840d39 100644 --- a/Module2/build.gradle +++ b/Module2/build.gradle @@ -19,7 +19,7 @@ android { arguments = [ "HOST" : "component2", "RouterDocFolder": project.property("component_router_doc_folder"), - "RouterDocEnable": String.valueOf(project.property("componnet_router_doc_enable")) + "RouterDocEnable": String.valueOf(project.property("component_router_doc_enable")) ] } } diff --git a/Module2/src/main/java/com/xiaojinzi/component2/service/TestInterfaceImpl.kt b/Module2/src/main/java/com/xiaojinzi/component2/service/TestInterfaceImpl.kt index 08b1a281..b0229289 100644 --- a/Module2/src/main/java/com/xiaojinzi/component2/service/TestInterfaceImpl.kt +++ b/Module2/src/main/java/com/xiaojinzi/component2/service/TestInterfaceImpl.kt @@ -1,8 +1,6 @@ package com.xiaojinzi.component2.service -import android.app.Application import com.xiaojinzi.component.anno.ServiceAnno -import com.xiaojinzi.component.service.IServiceLifecycle /** * time : 2018/12/06 @@ -10,16 +8,10 @@ import com.xiaojinzi.component.service.IServiceLifecycle * @author : xiaojinzi */ @ServiceAnno(value = [TestInterface::class], singleTon = false) -class TestInterfaceImpl : TestInterface, IServiceLifecycle { +class TestInterfaceImpl : TestInterface { override fun doSomeThing() { TODO("Not yet implemented") } - override fun onCreate(app: Application) { - } - - override fun onDestroy() { - } - } diff --git a/Module2/src/main/java/com/xiaojinzi/component2/view/TestInterceptorAct.java b/Module2/src/main/java/com/xiaojinzi/component2/view/TestInterceptorAct.java index 07ccfa27..06a935c0 100644 --- a/Module2/src/main/java/com/xiaojinzi/component2/view/TestInterceptorAct.java +++ b/Module2/src/main/java/com/xiaojinzi/component2/view/TestInterceptorAct.java @@ -1,11 +1,13 @@ package com.xiaojinzi.component2.view; +import com.xiaojinzi.base.interceptor.TimeConsumingInterceptor; import com.xiaojinzi.base.view.BaseAct; import com.xiaojinzi.component.anno.RouterAnno; @RouterAnno( path = "testInterceptor", - interceptorNames = "testInterceptor" + interceptorNames = "testInterceptor", + interceptors = TimeConsumingInterceptor.class ) public class TestInterceptorAct extends BaseAct { } diff --git a/ModuleBase/build.gradle b/ModuleBase/build.gradle index 6442a4a7..b59e7cf1 100644 --- a/ModuleBase/build.gradle +++ b/ModuleBase/build.gradle @@ -13,7 +13,7 @@ android { arguments = [ "HOST" : "base", "RouterDocFolder": project.property("component_router_doc_folder"), - "RouterDocEnable": String.valueOf(project.property("componnet_router_doc_enable")) + "RouterDocEnable": String.valueOf(project.property("component_router_doc_enable")) ] } } diff --git a/ModuleBase/src/main/java/com/xiaojinzi/base/interceptor/DialogShowInterceptor.java b/ModuleBase/src/main/java/com/xiaojinzi/base/interceptor/DialogShowInterceptor.java index 37680ade..bfaf25bb 100644 --- a/ModuleBase/src/main/java/com/xiaojinzi/base/interceptor/DialogShowInterceptor.java +++ b/ModuleBase/src/main/java/com/xiaojinzi/base/interceptor/DialogShowInterceptor.java @@ -10,8 +10,11 @@ import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; +import io.reactivex.Completable; import io.reactivex.Single; import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.disposables.Disposable; +import io.reactivex.functions.Action; import io.reactivex.functions.BiConsumer; import io.reactivex.functions.Consumer; import io.reactivex.schedulers.Schedulers; @@ -35,25 +38,19 @@ public void intercept(final Chain chain) throws Exception { } final ProgressDialog dialog = ProgressDialog.show(rawContext, "温馨提示", "耗时操作进行中,2秒后结束", true, false); dialog.show(); - Single - .fromCallable(new Callable() { - @Override - public String call() throws Exception { - return "test"; - } - }) + Disposable disposable = Completable.complete() .delay(2, TimeUnit.SECONDS) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) - .doOnEvent(new BiConsumer() { + .doOnEvent(new Consumer() { @Override - public void accept(String s, Throwable throwable) throws Exception { + public void accept(Throwable throwable) throws Exception { dialog.dismiss(); } }) - .subscribe(new Consumer() { + .subscribe(new Action() { @Override - public void accept(String s) throws Exception { + public void run() throws Exception { chain.proceed(chain.request()); } }, new Consumer() { diff --git a/ModuleBase/src/main/java/com/xiaojinzi/base/service/inter/component1/Component1Service.java b/ModuleBase/src/main/java/com/xiaojinzi/base/service/inter/component1/Component1Service.java index 297d46f2..99ba8aab 100644 --- a/ModuleBase/src/main/java/com/xiaojinzi/base/service/inter/component1/Component1Service.java +++ b/ModuleBase/src/main/java/com/xiaojinzi/base/service/inter/component1/Component1Service.java @@ -1,10 +1,10 @@ package com.xiaojinzi.base.service.inter.component1; -import android.support.annotation.MainThread; +import android.support.annotation.UiThread; import io.reactivex.Single; -@MainThread +@UiThread public interface Component1Service { void doSomeThing(); diff --git a/ModuleBase/src/main/java/com/xiaojinzi/base/service/inter/component2/Component2Service.java b/ModuleBase/src/main/java/com/xiaojinzi/base/service/inter/component2/Component2Service.java index f57edf34..69b0cbce 100644 --- a/ModuleBase/src/main/java/com/xiaojinzi/base/service/inter/component2/Component2Service.java +++ b/ModuleBase/src/main/java/com/xiaojinzi/base/service/inter/component2/Component2Service.java @@ -1,13 +1,13 @@ package com.xiaojinzi.base.service.inter.component2; -import android.support.annotation.MainThread; +import android.support.annotation.UiThread; /** * time : 2018/11/27 * * @author : xiaojinzi */ -@MainThread +@UiThread public interface Component2Service { void doSomeThing(); diff --git a/ModuleHelp/build.gradle b/ModuleHelp/build.gradle index 6fe115e3..c74cf17b 100644 --- a/ModuleHelp/build.gradle +++ b/ModuleHelp/build.gradle @@ -16,7 +16,7 @@ android { arguments = [ "HOST" : "help", "RouterDocFolder": project.property("component_router_doc_folder"), - "RouterDocEnable": String.valueOf(project.property("componnet_router_doc_enable")) + "RouterDocEnable": String.valueOf(project.property("component_router_doc_enable")) ] } } diff --git a/ModuleUser/build.gradle b/ModuleUser/build.gradle index f94a17ec..a93c418c 100644 --- a/ModuleUser/build.gradle +++ b/ModuleUser/build.gradle @@ -17,7 +17,7 @@ android { arguments = [ "HOST" : "user", "RouterDocFolder": project.property("component_router_doc_folder"), - "RouterDocEnable": String.valueOf(project.property("componnet_router_doc_enable")) + "RouterDocEnable": String.valueOf(project.property("component_router_doc_enable")) ] } } diff --git a/ModuleUser/gradle.properties b/ModuleUser/gradle.properties index c34c326c..e69de29b 100644 --- a/ModuleUser/gradle.properties +++ b/ModuleUser/gradle.properties @@ -1,2 +0,0 @@ -canRunAlone=true -isLibraryActual=true \ No newline at end of file diff --git a/README.md b/README.md index a06d5d76..28a0650e 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,7 @@ - [x] `H5` 发起路由不需要关心目标界面需要做的先决条件(框架的[页面拦截器](https://github.com/xiaojinzi123/Component/wiki/%E5%90%8D%E8%AF%8D%E8%A7%A3%E9%87%8A#%E9%A1%B5%E9%9D%A2%E6%8B%A6%E6%88%AA%E5%99%A8)已经帮您做完) - [x] 支持原生的[跳转动画](https://github.com/xiaojinzi123/Component/wiki/%E8%B7%B3%E8%BD%AC-%E5%8A%A8%E7%94%BB) - [x] 支持跳转 `Fragment`(也就是跨组件获取`Fragment`) + - [x] 支持[单 Activity 多 Fragment 架构](https://github.com/xiaojinzi123/Component/wiki/%E5%8D%95-Activity-%E5%A4%9A-Fragment) - [x] 路由拦截器执行线程设计是主线程, 整体是异步的(这点很多人不理解, 没有关系. 先用起来之后在慢慢理解) - 在路由拦截器的执行线程的设计上,考虑到用户平时书写的 `90%` 代码都是在主线程的,
所以路由拦截器的执行线程也设计为主线程执行,可以让您放心的操作 `UI`、弹框等操作.
同时提供 `Callback` 机制可以在拦截器中做任何耗时的任务
这点绝对是压倒性的优势,不仅整体是 `异步` 的,而且拦截器中能像平常一样写实现的代码 - [x] 路由的取消,基本上没有路由框架支持路由的取消,这也是一个很大的优势! diff --git a/RepoComponent/com/xiaojinzi/component/component-plugin/1.8.3.3/component-plugin-1.8.3.3.jar b/RepoComponent/com/xiaojinzi/component/component-plugin/1.8.3.3/component-plugin-1.8.3.3.jar new file mode 100644 index 00000000..865d4fee Binary files /dev/null and b/RepoComponent/com/xiaojinzi/component/component-plugin/1.8.3.3/component-plugin-1.8.3.3.jar differ diff --git a/RepoComponent/com/xiaojinzi/component/component-plugin/1.8.3.3/component-plugin-1.8.3.3.jar.md5 b/RepoComponent/com/xiaojinzi/component/component-plugin/1.8.3.3/component-plugin-1.8.3.3.jar.md5 new file mode 100644 index 00000000..6d1656d5 --- /dev/null +++ b/RepoComponent/com/xiaojinzi/component/component-plugin/1.8.3.3/component-plugin-1.8.3.3.jar.md5 @@ -0,0 +1 @@ +53e7f77768a5218f4ec329ab54d623c3 \ No newline at end of file diff --git a/RepoComponent/com/xiaojinzi/component/component-plugin/1.8.3.3/component-plugin-1.8.3.3.jar.sha1 b/RepoComponent/com/xiaojinzi/component/component-plugin/1.8.3.3/component-plugin-1.8.3.3.jar.sha1 new file mode 100644 index 00000000..bc698a67 --- /dev/null +++ b/RepoComponent/com/xiaojinzi/component/component-plugin/1.8.3.3/component-plugin-1.8.3.3.jar.sha1 @@ -0,0 +1 @@ +a0604c81efd6405143aa687cd218dd5ca928f31e \ No newline at end of file diff --git a/RepoComponent/com/xiaojinzi/component/component-plugin/1.8.3.3/component-plugin-1.8.3.3.pom b/RepoComponent/com/xiaojinzi/component/component-plugin/1.8.3.3/component-plugin-1.8.3.3.pom new file mode 100644 index 00000000..637e4e91 --- /dev/null +++ b/RepoComponent/com/xiaojinzi/component/component-plugin/1.8.3.3/component-plugin-1.8.3.3.pom @@ -0,0 +1,28 @@ + + + 4.0.0 + com.xiaojinzi.component + component-plugin + 1.8.3.3 + + + org.ow2.asm + asm-all + 5.2 + runtime + + + com.android.tools.build + gradle + 3.3.0 + runtime + + + com.google.code.gson + gson + 2.8.6 + runtime + + + diff --git a/RepoComponent/com/xiaojinzi/component/component-plugin/1.8.3.3/component-plugin-1.8.3.3.pom.md5 b/RepoComponent/com/xiaojinzi/component/component-plugin/1.8.3.3/component-plugin-1.8.3.3.pom.md5 new file mode 100644 index 00000000..2f6453dc --- /dev/null +++ b/RepoComponent/com/xiaojinzi/component/component-plugin/1.8.3.3/component-plugin-1.8.3.3.pom.md5 @@ -0,0 +1 @@ +0613aed020c1d9fe0aa601b24aef8882 \ No newline at end of file diff --git a/RepoComponent/com/xiaojinzi/component/component-plugin/1.8.3.3/component-plugin-1.8.3.3.pom.sha1 b/RepoComponent/com/xiaojinzi/component/component-plugin/1.8.3.3/component-plugin-1.8.3.3.pom.sha1 new file mode 100644 index 00000000..4b6c5b90 --- /dev/null +++ b/RepoComponent/com/xiaojinzi/component/component-plugin/1.8.3.3/component-plugin-1.8.3.3.pom.sha1 @@ -0,0 +1 @@ +c9db56cc1072bc4345a1df01e2774b3ef46dcf54 \ No newline at end of file diff --git a/RepoComponent/com/xiaojinzi/component/component-plugin/maven-metadata.xml b/RepoComponent/com/xiaojinzi/component/component-plugin/maven-metadata.xml index 085632d7..6374d5e7 100644 --- a/RepoComponent/com/xiaojinzi/component/component-plugin/maven-metadata.xml +++ b/RepoComponent/com/xiaojinzi/component/component-plugin/maven-metadata.xml @@ -3,7 +3,7 @@ com.xiaojinzi.component component-plugin - 1.8.3.2 + 1.8.3.3 1.7.7.3 1.7.8 @@ -19,7 +19,8 @@ 1.8.3 1.8.3.1 1.8.3.2 + 1.8.3.3 - 20200805142303 + 20200915125221 diff --git a/RepoComponent/com/xiaojinzi/component/component-plugin/maven-metadata.xml.md5 b/RepoComponent/com/xiaojinzi/component/component-plugin/maven-metadata.xml.md5 index cda8aa59..e2407794 100644 --- a/RepoComponent/com/xiaojinzi/component/component-plugin/maven-metadata.xml.md5 +++ b/RepoComponent/com/xiaojinzi/component/component-plugin/maven-metadata.xml.md5 @@ -1 +1 @@ -a4cf46c1ec57b65a0939bc37600e555d \ No newline at end of file +15087436f9aa56605774b1111a2cfb86 \ No newline at end of file diff --git a/RepoComponent/com/xiaojinzi/component/component-plugin/maven-metadata.xml.sha1 b/RepoComponent/com/xiaojinzi/component/component-plugin/maven-metadata.xml.sha1 index a680c083..c8443a1f 100644 --- a/RepoComponent/com/xiaojinzi/component/component-plugin/maven-metadata.xml.sha1 +++ b/RepoComponent/com/xiaojinzi/component/component-plugin/maven-metadata.xml.sha1 @@ -1 +1 @@ -375ae8e06c10e7bb354345fbc1b135636ffb6cf9 \ No newline at end of file +6fc795bf30b34f791466870e5edf2dfa4bab65e4 \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 3a4bc5cb..57d9621b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -20,7 +20,7 @@ android { arguments = [ "HOST" : "app", "RouterDocFolder": project.property("component_router_doc_folder"), - "RouterDocEnable": String.valueOf(project.property("componnet_router_doc_enable")) + "RouterDocEnable": String.valueOf(project.property("component_router_doc_enable")) ] } } @@ -73,4 +73,7 @@ dependencies { } // 内存检测的 // debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.0-beta-3' + + implementation "org.java-websocket:Java-WebSocket:1.5.1" + } diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 765ff01d..c4955d3a 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -37,6 +37,5 @@ -keep class * implements com.xiaojinzi.component.impl.RouterInterceptor{*;} -keep class * implements com.xiaojinzi.component.support.IBaseLifecycle{*;} -keep class * implements com.xiaojinzi.component.application.IApplicationLifecycle{*;} --keep class * implements com.xiaojinzi.component.service.IServiceLifecycle{*;} -keep class * implements com.xiaojinzi.component.application.IComponentApplication{*;} -keep class * implements com.xiaojinzi.component.support.Inject{*;} \ No newline at end of file diff --git a/app/src/main/java/com/xiaojinzi/componentdemo/CustomerRouterImpl.java b/app/src/main/java/com/xiaojinzi/componentdemo/CustomerRouterImpl.java index bda965e7..1c1d5a18 100644 --- a/app/src/main/java/com/xiaojinzi/componentdemo/CustomerRouterImpl.java +++ b/app/src/main/java/com/xiaojinzi/componentdemo/CustomerRouterImpl.java @@ -27,7 +27,6 @@ public class CustomerRouterImpl { /** * 自定义实现跳转到打电话的界面,并且自动完成打电话权限的申请 */ - @Nullable @RouterAnno( host = ModuleConfig.System.NAME, path = ModuleConfig.System.CALL_PHONE, @@ -49,7 +48,6 @@ public static Intent callPhoneIntent(@NonNull RouterRequest request, @NonNull Ro * @param request * @return */ - @Nullable @RouterAnno( host = ModuleConfig.System.NAME, path = ModuleConfig.System.TAKE_PHONE, diff --git a/app/src/main/java/com/xiaojinzi/componentdemo/Test.java b/app/src/main/java/com/xiaojinzi/componentdemo/Test.java deleted file mode 100644 index d5b8b44b..00000000 --- a/app/src/main/java/com/xiaojinzi/componentdemo/Test.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.xiaojinzi.componentdemo; - -public class Test { - public static void main(String[] args) { - - } -} diff --git a/app/src/main/java/com/xiaojinzi/componentdemo/view/MainAct.java b/app/src/main/java/com/xiaojinzi/componentdemo/view/MainAct.java index 1d156992..1a2b6f7b 100644 --- a/app/src/main/java/com/xiaojinzi/componentdemo/view/MainAct.java +++ b/app/src/main/java/com/xiaojinzi/componentdemo/view/MainAct.java @@ -7,7 +7,6 @@ import android.content.Intent; import android.os.Build; import android.os.Bundle; -import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.support.v4.app.NotificationCompat; @@ -18,11 +17,7 @@ import com.xiaojinzi.base.ModuleConfig; import com.xiaojinzi.base.router.AppApi; import com.xiaojinzi.component.anno.RouterAnno; -import com.xiaojinzi.component.impl.Callback; import com.xiaojinzi.component.impl.Router; -import com.xiaojinzi.component.impl.RouterErrorResult; -import com.xiaojinzi.component.impl.RouterRequest; -import com.xiaojinzi.component.impl.RouterResult; import com.xiaojinzi.component.impl.application.ModuleManager; import com.xiaojinzi.componentdemo.R; @@ -133,7 +128,7 @@ public void testWebRouter(View view) { .forward(); } - public void testQuality(View view) { + public void testQuality(View view) throws Exception { Router.withApi(AppApi.class) .goToTestQuality() .subscribe(); diff --git a/build.gradle b/build.gradle index 0307eff5..1562bcec 100644 --- a/build.gradle +++ b/build.gradle @@ -4,13 +4,14 @@ buildscript { apply from: "dependencies.gradle" - ext.kotlin_version = '1.3.72' + ext.kotlin_version = '1.4.10' ext.component_group_id = "com.xiaojinzi" ext.isDependMavenOnline = false // ext.component_asm_util_class_output_path = "./Temp/ASMUtil.class" + ext.component_asm_disable = false // 注解生成器生成的文件 json 信息都在这里面 ext.component_router_doc_folder = "./Doc" - ext.componnet_router_doc_enable = false + ext.component_router_doc_enable = false repositories { google() diff --git a/changelog.md b/changelog.md index 9224db42..bf025fd8 100644 --- a/changelog.md +++ b/changelog.md @@ -1,11 +1,24 @@ +#### [v1.8.3.3](https://github.com/xiaojinzi123/Component/releases/tag/v1.8.3.3) +- 删除 1.8.3.1 增加的 Service 生命周期的功能. 实践得知, 这功能并不正确 +- ServiceManager 的反注册方法改为没有返回值. +- @MainThread 注解全都改为 @UiThread +- afterAction 的执行用的 request 修复为 finalRequest, 而不是 originRequest +- 增加一些方法的 @NonNull 注解 +- 修复 RouterRequest的bundle变为RouterRequest.Builder.Bundle 地址传递的问题, 应该为值传递 +- 增加模块加载失败时候的 url 链接, 可以帮助排查错误 +- 调整 Logo 输出的位置 +- 修复生成的路由表的 ArrayList 的泛型警告问题 +- 修改 componnet 拼写错误的问题. +- 增加 component_asm_disable 配置, 可以让 Gradle 插件禁用 ASM 的功能. 因为有些人就只用 RouterDoc 的功能 + #### [v1.8.3.2](https://github.com/xiaojinzi123/Component/releases/tag/v1.8.3.2) - 修复 void method(Context context, Callback callback); 这中 Api 接口方法生成代码失败的问题 #### [v1.8.3.1](https://github.com/xiaojinzi123/Component/releases/tag/v1.8.3.1) - 增加 java8 的发布维度 - 支持属性注入多个属性. 主要用于兼容如果想变动 key 的问题. -- 支持 @ServiceAnno 标记的服务实现类, 可以可选的实现 IServiceLifecycle 接口来接受模块的生命周期的回调 +- ~~支持 @ServiceAnno 标记的服务实现类, 可以可选的实现 IServiceLifecycle 接口来接受模块的生命周期的回调~~ 此功能将被删除. - 用户自定义的模块生命周期类, 需要实现 IApplicationLifecycle 接口, 而不是老的 IComponentApplication 接口, 虽说老的目前也支持, 但是若干版本之后会删除 - 内部优化类结构. 需要更新新的[混淆配置](https://github.com/xiaojinzi123/Component/wiki/%E4%BE%9D%E8%B5%96%E5%92%8C%E9%85%8D%E7%BD%AE-AndroidX#%E6%B7%B7%E6%B7%86%E9%85%8D%E7%BD%AE) @@ -19,10 +32,10 @@ #### [v1.8.2.1](https://github.com/xiaojinzi123/Component/releases/tag/v1.8.2.1) - 修复之前修改 `impl` 模块的包名引起的 `ProxtActivity` 失效的问题 -- `router` 文档增加控制是否生成文档的 `boolean` 的开关. `componnet_router_doc_enable` - - 配置方式和 `componnet_router_doc_folder` 一致. 比如 ext.componnet_router_doc_enable = true +- `router` 文档增加控制是否生成文档的 `boolean` 的开关. `component_router_doc_enable` + - 配置方式和 `componnet_router_doc_folder` 一致. 比如 ext.component_router_doc_enable = true - 同时注解驱动器的 `RouterDoc` 属性配置改为 `RouterDocFolder` -- 注解驱动器也增加一个文档是否生成的开关 `RouterDocEable`, 一般 `RouterDocEable` 这个值随着 `componnet_router_doc_enable` 变化即可 +- 注解驱动器也增加一个文档是否生成的开关 `RouterDocEable`, 一般 `RouterDocEable` 这个值随着 `component_router_doc_enable` 变化即可 #### [v1.8.2](https://github.com/xiaojinzi123/Component/releases/tag/v1.8.2) diff --git a/dependencies.gradle b/dependencies.gradle index 2682497d..515a7513 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -7,11 +7,11 @@ ext.versions = [ version_name : "1.0", support_lib : "28.0.0", // 第三方控件的版本号 - constraintLayout : '2.0.0-rc1', + constraintLayout : '2.0.1', rxjava : '2.2.19', rxandroid : "2.1.1", - component_version : "1.8.3.2", - component_plugin_upload_version: "1.8.3.2" + component_version : "1.8.3.3", + component_plugin_upload_version: "1.8.3.3" ] ext.libs = [