From 8f564433baa545c6200f2f7210114c4587d45f1e Mon Sep 17 00:00:00 2001 From: chenenyu Date: Fri, 18 May 2018 15:05:45 +0800 Subject: [PATCH 1/3] Ordered interceptor set. --- router/src/main/java/com/chenenyu/router/AptHub.java | 5 +++-- router/src/main/java/com/chenenyu/router/RealRouter.java | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/router/src/main/java/com/chenenyu/router/AptHub.java b/router/src/main/java/com/chenenyu/router/AptHub.java index 2c46d47..1ef4398 100644 --- a/router/src/main/java/com/chenenyu/router/AptHub.java +++ b/router/src/main/java/com/chenenyu/router/AptHub.java @@ -8,6 +8,7 @@ import java.lang.reflect.Constructor; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; /** @@ -26,7 +27,7 @@ class AptHub { // Uri -> Activity/Fragment static Map> routeTable = new HashMap<>(); // Activity/Fragment -> interceptorTable' name - static Map, String[]> targetInterceptors = new HashMap<>(); + static Map, String[]> targetInterceptors = new LinkedHashMap<>(); // interceptor's name -> interceptor static Map> interceptorTable = new HashMap<>(); static Map interceptorInstances = new HashMap<>(); @@ -34,7 +35,7 @@ class AptHub { static Map> injectors = new HashMap<>(); /** - * This method offers an ability to register extra modules for developers. + * This method offers an ability to register modules for developers. * * @param modules extra modules' name */ diff --git a/router/src/main/java/com/chenenyu/router/RealRouter.java b/router/src/main/java/com/chenenyu/router/RealRouter.java index c4fb418..937b592 100644 --- a/router/src/main/java/com/chenenyu/router/RealRouter.java +++ b/router/src/main/java/com/chenenyu/router/RealRouter.java @@ -18,7 +18,7 @@ import java.lang.reflect.Constructor; import java.util.Collections; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -278,7 +278,7 @@ private Set assembleClassInterceptors(@Nullable Class target) { return null; } // Assemble final interceptors - Set finalInterceptors = new HashSet<>(); + Set finalInterceptors = new LinkedHashSet<>(); if (target != null) { // 1. Add original interceptors in Map String[] baseInterceptors = AptHub.targetInterceptors.get(target); From 846569232d5eedfac25bf21cfe1b55def2a2df42 Mon Sep 17 00:00:00 2001 From: chenenyu Date: Fri, 18 May 2018 15:18:35 +0800 Subject: [PATCH 2/3] Update demo and version. --- Sample/app/build.gradle | 1 - ...mpleInterceptor.java => AInterceptor.java} | 6 ++--- .../com/chenenyu/router/app/BInterceptor.java | 23 +++++++++++++++++++ .../router/app/InterceptedActivity.java | 3 ++- .../com/chenenyu/router/app/MainActivity.java | 4 ++-- build.gradle | 6 ++--- gradle/wrapper/gradle-wrapper.properties | 4 ++-- 7 files changed, 35 insertions(+), 12 deletions(-) rename Sample/app/src/main/java/com/chenenyu/router/app/{SampleInterceptor.java => AInterceptor.java} (77%) create mode 100644 Sample/app/src/main/java/com/chenenyu/router/app/BInterceptor.java diff --git a/Sample/app/build.gradle b/Sample/app/build.gradle index ea8f401..a175cf5 100644 --- a/Sample/app/build.gradle +++ b/Sample/app/build.gradle @@ -42,7 +42,6 @@ dependencies { implementation project(':module1') implementation project(':module2') testImplementation 'junit:junit:4.12' - implementation 'com.android.support.constraint:constraint-layout:1.0.2' implementation project(':router') annotationProcessor project(':compiler') } diff --git a/Sample/app/src/main/java/com/chenenyu/router/app/SampleInterceptor.java b/Sample/app/src/main/java/com/chenenyu/router/app/AInterceptor.java similarity index 77% rename from Sample/app/src/main/java/com/chenenyu/router/app/SampleInterceptor.java rename to Sample/app/src/main/java/com/chenenyu/router/app/AInterceptor.java index d3dc9e5..08d7a34 100644 --- a/Sample/app/src/main/java/com/chenenyu/router/app/SampleInterceptor.java +++ b/Sample/app/src/main/java/com/chenenyu/router/app/AInterceptor.java @@ -12,12 +12,12 @@ *

* Created by Cheney on 2017/3/6. */ -@Interceptor("SampleInterceptor") -public class SampleInterceptor implements RouteInterceptor { +@Interceptor("AInterceptor") +public class AInterceptor implements RouteInterceptor { @Override public boolean intercept(Object source, RouteRequest routeRequest) { Toast.makeText((Context) source, String.format("Intercepted: {uri: %s, interceptor: %s}", - routeRequest.getUri().toString(), SampleInterceptor.class.getName()), + routeRequest.getUri().toString(), AInterceptor.class.getName()), Toast.LENGTH_LONG).show(); return true; } diff --git a/Sample/app/src/main/java/com/chenenyu/router/app/BInterceptor.java b/Sample/app/src/main/java/com/chenenyu/router/app/BInterceptor.java new file mode 100644 index 0000000..da019f6 --- /dev/null +++ b/Sample/app/src/main/java/com/chenenyu/router/app/BInterceptor.java @@ -0,0 +1,23 @@ +package com.chenenyu.router.app; + +import android.content.Context; +import android.widget.Toast; + +import com.chenenyu.router.RouteInterceptor; +import com.chenenyu.router.RouteRequest; +import com.chenenyu.router.annotation.Interceptor; + + +/** + * Created by chenenyu on 2018/5/18. + */ +@Interceptor("BInterceptor") +public class BInterceptor implements RouteInterceptor { + @Override + public boolean intercept(Object source, RouteRequest routeRequest) { + Toast.makeText((Context) source, String.format("Intercepted: {uri: %s, interceptor: %s}", + routeRequest.getUri().toString(), BInterceptor.class.getName()), + Toast.LENGTH_LONG).show(); + return true; + } +} diff --git a/Sample/app/src/main/java/com/chenenyu/router/app/InterceptedActivity.java b/Sample/app/src/main/java/com/chenenyu/router/app/InterceptedActivity.java index add89ba..be9f2a3 100644 --- a/Sample/app/src/main/java/com/chenenyu/router/app/InterceptedActivity.java +++ b/Sample/app/src/main/java/com/chenenyu/router/app/InterceptedActivity.java @@ -5,7 +5,8 @@ import com.chenenyu.router.annotation.Route; -@Route(value = "intercepted", interceptors = "SampleInterceptor") +@Route(value = "intercepted", interceptors = {"AInterceptor", "BInterceptor"}) +//@Route(value = "intercepted", interceptors = {"BInterceptor", "AInterceptor"}) public class InterceptedActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { diff --git a/Sample/app/src/main/java/com/chenenyu/router/app/MainActivity.java b/Sample/app/src/main/java/com/chenenyu/router/app/MainActivity.java index 6b22be3..08b9304 100644 --- a/Sample/app/src/main/java/com/chenenyu/router/app/MainActivity.java +++ b/Sample/app/src/main/java/com/chenenyu/router/app/MainActivity.java @@ -115,9 +115,9 @@ public void callback(RouteResult state, Uri uri, String message) { } else if (v == btn9) { Router.build("intercepted").go(this); } else if (v == btn10) { - Router.build("intercepted").skipInterceptors("SampleInterceptor").go(this); + Router.build("intercepted").skipInterceptors("AInterceptor").go(this); } else if (v == btn11) { - Router.build("test").addInterceptors("SampleInterceptor").go(this); + Router.build("test").addInterceptors("AInterceptor").go(this); } } diff --git a/build.gradle b/build.gradle index e8eee61..2e6bae4 100644 --- a/build.gradle +++ b/build.gradle @@ -1,11 +1,11 @@ buildscript { - ext.kotlin_version = '1.2.10' + ext.kotlin_version = '1.2.30' repositories { google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.0.0' + classpath 'com.android.tools.build:gradle:3.1.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.0' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' @@ -32,5 +32,5 @@ ext { minSdkVersion = 14 targetSdkVersion = 27 - supportVersion = "27.1.0" + supportVersion = "27.1.1" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 8eeb8b1..2567de2 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Sep 04 12:31:05 CST 2017 +#Fri May 18 12:39:21 CST 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip From 274dbde436fb531ac5e4333da8cc9b86ce5ba5f0 Mon Sep 17 00:00:00 2001 From: chenenyu Date: Fri, 18 May 2018 15:37:53 +0800 Subject: [PATCH 3/3] release 1.4.2 --- CHANGELOG.md | 6 ++++++ README.md | 9 +++++---- VERSION.properties | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 274da64..8dbc889 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 2018.05.18 + +`router:1.4.2`: + +1. Ordered interceptors. + ## 2018.04.03 `router:1.4.1`: diff --git a/README.md b/README.md index a24c832..085b198 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://travis-ci.org/chenenyu/Router.svg?branch=master)](https://travis-ci.org/chenenyu/Router) ![license](https://img.shields.io/badge/license-Apache%202-yellow.svg) ![PullRequest](https://img.shields.io/badge/PRs-welcome-brightgreen.svg) +![Build Status](https://travis-ci.org/chenenyu/Router.svg?branch=master) ![license](https://img.shields.io/badge/license-Apache%202-yellow.svg) ![PullRequest](https://img.shields.io/badge/PRs-welcome-brightgreen.svg) # Router @@ -24,6 +24,7 @@ android { dependencies { implementation 'com.chenenyu.router:router:版本号' + // 每个使用了@Router注解的module都要添加该注解处理器 annotationProcessor 'com.chenenyu.router:compiler:版本号' } ``` @@ -107,7 +108,7 @@ Router.build("test").getFragment(); ## 进阶用法 -Please refer to the [wiki](https://github.com/chenenyu/Router/wiki) for more informations. +Please refer to the [wiki](https://github.com/chenenyu/Router/wiki) for more information. ## ProGuard @@ -121,9 +122,9 @@ Please refer to the [wiki](https://github.com/chenenyu/Router/wiki) for more inf QQ group: 271849001 -## Donate +## Donate ❤️ -![donate_wechat](static/donate_wechat.png) +[Click here](https://github.com/chenenyu/Router/wiki/Donate). ## License diff --git a/VERSION.properties b/VERSION.properties index 4cc269f..dc38cf2 100644 --- a/VERSION.properties +++ b/VERSION.properties @@ -1,5 +1,5 @@ # router library version -ROUTER_VERSION=1.4.1 +ROUTER_VERSION=1.4.2 # compiler library version COMPILER_VERSION=1.4.0 # annotation library version