Skip to content

Commit

Permalink
Merge pull request #77 from chenenyu/dev
Browse files Browse the repository at this point in the history
1.4.0
  • Loading branch information
Half Stack committed Apr 3, 2018
2 parents 47124d8 + 5a1cad1 commit 83e0025
Show file tree
Hide file tree
Showing 33 changed files with 275 additions and 487 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
## 2018.04.03

`router:1.4.0`:

1. [issue76](https://github.com/chenenyu/Router/issues/76)
2. Refactor `RouteInterceptor`
3. Remove Method-Callable support

## 2018.02.06

`router:1.4.0-beta1` `compiler:1.4.0-beta1` `annotation:0.4.0`:

1. fix: https://github.com/chenenyu/Router/pull/71
2. Router can annotate methods now!
2. ~~Router can annotate methods now!~~ (Removed in 1.4.0)

## 2018.01.30

Expand Down
40 changes: 11 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,6 @@ public class TestActivity extends AppCompatActivity {
public class TestFragment extends Fragment {
...
}

// 给方法添加注解(类必须实现MethodCallable接口)
public class Foo implements MethodCallable {
private Context mContext;

public CallToast(Context context) {
mContext = context;
}

@Route("showToast") // 注解到方法上,方法若有参数,则每个参数必须
public void toast(@InjectParam(key = "param") String msg) {
Toast.makeText(mContext, msg, Toast.LENGTH_SHORT).show();
}

@Route({"showLog"})
public static void log() {
Log.i("Foo", "a log shows how to call native static method.");
}
}
```

4. 跳转
Expand All @@ -119,16 +100,9 @@ Router.build("test").go(this, new RouteCallback() {
}
});
// 获取路由对应的intent
Router.build("test").getIntent(content);
Router.build("test").getIntent();
// 获取注解的Fragment
Router.build("test").getFragment(context);

// 通过对象调用方法
Foo foo = new Foo(context);
Router.build("showToast").with("param", "Hello, Router!").go(context, foo); // 调用非静态方法
Router.build("showLog").go(context, foo); // 调用静态方法
// 通过类调用方法(只能调用静态方法)
Router.build("showLog").go(context, MethodCallable.class);
Router.build("test").getFragment();
```

## 进阶用法
Expand All @@ -137,12 +111,20 @@ Please refer to the [wiki](https://github.com/chenenyu/Router/wiki) for more inf

## ProGuard

See [wiki](https://github.com/chenenyu/Router/wiki).
```
# Router
-keep class com.chenenyu.router.** {*;}
-keep class * implements com.chenenyu.router.template.ParamInjector {*;}
```

## 讨论

QQ group: 271849001

## Donate

![donate_wechat](static/donate_wechat.png)

## License

[Apache 2.0](https://github.com/chenenyu/Router/blob/master/LICENSE)
2 changes: 1 addition & 1 deletion Sample/app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@

# Router
-keep class com.chenenyu.router.** {*;}
-keep class * implements com.chenenyu.router.ParamInjector {*;}
-keep class * implements com.chenenyu.router.template.ParamInjector {*;}

5 changes: 0 additions & 5 deletions Sample/app/src/main/assets/scheme.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,5 @@
<a href="router://empty">router://empty</a>
</li>
</ul>
<button onclick="location.href='router://toast1';return false;">Toast</button>
<button onclick="location.href='router://toast2?param=Hello, Router!';return false;">Hello,
Router!
</button>
<button onclick="location.href='router://log';return false;">Log</button>
</body>
</html>
17 changes: 0 additions & 17 deletions Sample/app/src/main/java/com/chenenyu/router/app/CallLog.java

This file was deleted.

33 changes: 0 additions & 33 deletions Sample/app/src/main/java/com/chenenyu/router/app/CallToast.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.chenenyu.router.app;

import android.content.Context;
import android.util.Log;

import com.chenenyu.router.RouteInterceptor;
Expand All @@ -13,7 +12,7 @@
*/
public class GlobalInterceptor implements RouteInterceptor {
@Override
public boolean intercept(Context context, RouteRequest routeRequest) {
public boolean intercept(Object source, RouteRequest routeRequest) {
Log.d("GlobalInterceptor", String.format("{uri: %s, interceptor: %s}",
routeRequest.getUri().toString(), GlobalInterceptor.class.getName()));
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

import com.chenenyu.router.RouteCallback;
import com.chenenyu.router.RouteResult;
import com.chenenyu.router.RouteTable;
import com.chenenyu.router.Router;
import com.chenenyu.router.template.RouteTable;

import java.util.Map;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
@Interceptor("SampleInterceptor")
public class SampleInterceptor implements RouteInterceptor {
@Override
public boolean intercept(Context context, RouteRequest routeRequest) {
Toast.makeText(context, String.format("Intercepted: {uri: %s, interceptor: %s}",
public boolean intercept(Object source, RouteRequest routeRequest) {
Toast.makeText((Context) source, String.format("Intercepted: {uri: %s, interceptor: %s}",
routeRequest.getUri().toString(), SampleInterceptor.class.getName()),
Toast.LENGTH_LONG).show();
return true;
Expand Down
23 changes: 0 additions & 23 deletions Sample/app/src/main/java/com/chenenyu/router/app/WebActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,17 @@
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.chenenyu.router.Router;

public class WebActivity extends AppCompatActivity {
WebView mWebView;
CallToast mCallToast;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

mCallToast = new CallToast(this);
mWebView = new WebView(this);
mWebView.getSettings().setJavaScriptEnabled(true);
setContentView(mWebView);
mWebView.loadUrl("file:///android_asset/scheme.html");
mWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// 通过对象调用
if (Router.build(url).go(getApplicationContext(), mCallToast)) {
return true;
}
// 通过类调用(优点是不需要实例化对象, 缺点是只能调用静态方法)
if (Router.build(url).go(getApplicationContext(), CallLog.class)) {
return true;
}

// 页面跳转
Router.build(url).go(getApplicationContext());
return true;
}
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
package com.chenenyu.router.module;


import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.chenenyu.router.RouteCallback;
import com.chenenyu.router.RouteResult;
import com.chenenyu.router.Router;
import com.chenenyu.router.annotation.InjectParam;
import com.chenenyu.router.annotation.Route;
Expand Down Expand Up @@ -45,12 +41,7 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
getView().findViewById(R.id.btn_go).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Router.build("module1").go(getContext(), new RouteCallback() {
@Override
public void callback(RouteResult state, Uri uri, String message) {
Toast.makeText(getContext(), state.name() + ", " + uri, Toast.LENGTH_SHORT).show();
}
});
Router.build("module1").go(Module1Fragment.this);
getActivity().finish();
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package com.chenenyu.router.module;


import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.chenenyu.router.RouteCallback;
import com.chenenyu.router.RouteResult;
import com.chenenyu.router.Router;
import com.chenenyu.router.annotation.Route;
import com.chenenyu.router.module2.R;
Expand All @@ -38,12 +34,7 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
getView().findViewById(R.id.btn_go).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Router.build("module2").go(getContext(), new RouteCallback() {
@Override
public void callback(RouteResult state, Uri uri, String message) {
Toast.makeText(getContext(), state.name() + ", " + uri, Toast.LENGTH_SHORT).show();
}
});
Router.build("module2").go(Module2Fragment.this);
getActivity().finish();
}
});
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.4.0-beta1
ROUTER_VERSION=1.4.0
# compiler library version
COMPILER_VERSION=1.4.0-beta1
COMPILER_VERSION=1.4.0
# annotation library version
ANNOTATION_VERSION=0.4.0
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ ext {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7

compileSdkVersion = 27
buildToolsVersion = "27.0.3"
compileSdkVersion = 27
minSdkVersion = 14
targetSdkVersion = 27

supportVersion = "27.0.2"
supportVersion = "27.1.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
import static com.chenenyu.router.compiler.util.Consts.CLASS_JAVA_DOC;
import static com.chenenyu.router.compiler.util.Consts.FRAGMENT_FULL_NAME;
import static com.chenenyu.router.compiler.util.Consts.FRAGMENT_V4_FULL_NAME;
import static com.chenenyu.router.compiler.util.Consts.INNER_CLASS_NAME;
import static com.chenenyu.router.compiler.util.Consts.METHOD_INJECT;
import static com.chenenyu.router.compiler.util.Consts.OPTION_MODULE_NAME;
import static com.chenenyu.router.compiler.util.Consts.PACKAGE_NAME;
import static com.chenenyu.router.compiler.util.Consts.PARAM_ANNOTATION_TYPE;
import static com.chenenyu.router.compiler.util.Consts.PARAM_CLASS_SUFFIX;
import static com.chenenyu.router.compiler.util.Consts.PARAM_INJECTOR_FULL_NAME;

/**
* {@link InjectParam} annotation processor.
Expand Down Expand Up @@ -112,7 +112,7 @@ private void generate() throws IllegalAccessException, IOException {
String qualifiedName = parent.getQualifiedName().toString();
String simpleName = parent.getSimpleName().toString();
String packageName = qualifiedName.substring(0, qualifiedName.lastIndexOf("."));
String fileName = simpleName + INNER_CLASS_NAME;
String fileName = simpleName + PARAM_CLASS_SUFFIX;

// validate
boolean isActivity;
Expand Down Expand Up @@ -203,11 +203,12 @@ private void generate() throws IllegalAccessException, IOException {
}
}

TypeElement interfaceType = processingEnv.getElementUtils().getTypeElement(PARAM_INJECTOR_FULL_NAME);
TypeSpec typeSpec = TypeSpec.classBuilder(fileName)
.addJavadoc(CLASS_JAVA_DOC)
.addSuperinterface(ClassName.get(PACKAGE_NAME, "ParamInjector"))
.addSuperinterface(ClassName.get(interfaceType))
.addModifiers(Modifier.PUBLIC)
.addMethod(injectMethodBuilder.build())
.addJavadoc(CLASS_JAVA_DOC)
.build();

JavaFile.builder(packageName, typeSpec).build().writeTo(processingEnv.getFiler());
Expand Down

0 comments on commit 83e0025

Please sign in to comment.