Skip to content

Commit

Permalink
Merge pull request #61 from chenenyu/dev
Browse files Browse the repository at this point in the history
1.3.2
  • Loading branch information
Half Stack committed Nov 29, 2017
2 parents 2a1738f + a8dc9f9 commit aa653e9
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 7 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 2017.11.29

`router: 1.3.2`:

1. 兼容低版本的v4包. [issue59](https://github.com/chenenyu/Router/issues/59)

`compiler:1.3.2`:

1. 编译时检查是否存在重复的注解. [issue60](https://github.com/chenenyu/Router/issues/60)

## 2017.11.09

`router: 1.3.0`:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Router.initialize(new Configuration.Builder()
// 这里添加了path和拦截器
@Route(value = "test", interceptors = "SampleInterceptor")
public class TestActivity extends AppCompatActivity {
...
...
}
```

Expand Down
4 changes: 2 additions & 2 deletions VERSION.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# router library version
ROUTER_VERSION=1.3.1
ROUTER_VERSION=1.3.2
# compiler library version
COMPILER_VERSION=1.3.0
COMPILER_VERSION=1.3.2
# annotation library version
ANNOTATION_VERSION=0.3.0
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.squareup.javapoet.WildcardTypeName;

import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -103,11 +104,18 @@ private void generateInterceptors(String moduleName, Set<TypeElement> elements)
.addAnnotation(Override.class)
.addModifiers(Modifier.PUBLIC)
.addParameter(mapParameterSpec);

Map<String, String> interceptorRecorder = new HashMap<>();
for (TypeElement element : elements) {
mLogger.info(String.format("Found interceptor: %s", element.getQualifiedName()));
Interceptor interceptor = element.getAnnotation(Interceptor.class);
String name = interceptor.value();
if (interceptorRecorder.containsKey(name)) {
throw new RuntimeException(String.format("Duplicate interceptor name: %s[%s, %s]",
name, element.getQualifiedName(), interceptorRecorder.get(name)));
}
handleInterceptors.addStatement("map.put($S, $T.class)", name, ClassName.get(element));
interceptorRecorder.put(name, element.getQualifiedName().toString());
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.squareup.javapoet.WildcardTypeName;

import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -122,12 +123,21 @@ private void generateRouteTable(String moduleName, Set<TypeElement> elements) {
.addAnnotation(Override.class)
.addModifiers(Modifier.PUBLIC)
.addParameter(mapParameterSpec);

// 记录path->element,防止重复的route path
Map<String, String> pathRecorder = new HashMap<>();

for (TypeElement element : elements) {
mLogger.info(String.format("Found routed target: %s", element.getQualifiedName()));
Route route = element.getAnnotation(Route.class);
String[] paths = route.value();
for (String path : paths) {
if (pathRecorder.containsKey(path)) {
throw new RuntimeException(String.format("Duplicate route path: %s[%s, %s]",
path, element.getQualifiedName(), pathRecorder.get(path)));
}
methodHandle.addStatement("map.put($S, $T.class)", path, ClassName.get(element));
pathRecorder.put(path, element.getQualifiedName().toString());
}
}

Expand Down
4 changes: 2 additions & 2 deletions router/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ android {
buildToolsVersion rootProject.ext.buildToolsVersion

defaultConfig {
minSdkVersion 11
minSdkVersion 14
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
Expand Down Expand Up @@ -36,7 +36,7 @@ def annoVersion = version.getProperty("ANNOTATION_VERSION")
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
testImplementation 'junit:junit:4.12'
compileOnly "com.android.support:support-v4:${rootProject.ext.supportVersion}"
compileOnly "com.android.support:support-v4:24.2.0"
// api project(':annotation')
// 这里不能使用implementation,因为pom依赖不识别
compile "com.chenenyu.router:annotation:${annoVersion}"
Expand Down
9 changes: 7 additions & 2 deletions router/src/main/java/com/chenenyu/router/RealRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.content.ContextCompat;

import com.chenenyu.router.matcher.AbsImplicitMatcher;
import com.chenenyu.router.matcher.AbsMatcher;
Expand Down Expand Up @@ -353,7 +352,13 @@ public void go(Context context) {
}
} else {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ContextCompat.startActivity(context, intent, options);
// The below api added in v4:25.1.0
// ContextCompat.startActivity(context, intent, options);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
context.startActivity(intent, options);
} else {
context.startActivity(intent);
}
}

callback(RouteResult.SUCCEED, null);
Expand Down

0 comments on commit aa653e9

Please sign in to comment.