Skip to content

Commit

Permalink
Merge pull request #683 from alibaba/develop
Browse files Browse the repository at this point in the history
Add pretreatment service
  • Loading branch information
zhi1ong authored May 9, 2019
2 parents 1a06912 + 7503053 commit 790d091
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 12 deletions.
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ version|[![Download](https://api.bintray.com/packages/zhi1ong/maven/arouter-api/
@Override
public String sayHello(String name) {
return "hello, " + name;
return "hello, " + name;
}
@Override
Expand All @@ -304,7 +304,7 @@ version|[![Download](https://api.bintray.com/packages/zhi1ong/maven/arouter-api/
HelloService helloService4;
public Test() {
ARouter.getInstance().inject(this);
ARouter.getInstance().inject(this);
}
public void testService() {
Expand All @@ -320,6 +320,22 @@ version|[![Download](https://api.bintray.com/packages/zhi1ong/maven/arouter-api/
}
}
```
8. Pretreatment Service
``` java
@Route(path = "/xxx/xxx")
public class PretreatmentServiceImpl implements PretreatmentService {
@Override
public boolean onPretreatment(Context context, Postcard postcard) {
// Do something before the navigation, if you need to handle the navigation yourself, the method returns false
}
@Override
public void init(Context context) {
}
}
```
#### V. More features
Expand Down
17 changes: 17 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,23 @@
}
```
9. 预处理服务
``` java
// 实现 PretreatmentService 接口,并加上一个Path内容任意的注解即可
@Route(path = "/xxx/xxx")
public class PretreatmentServiceImpl implements PretreatmentService {
@Override
public boolean onPretreatment(Context context, Postcard postcard) {
// 跳转前预处理,如果需要自行处理跳转,该方法返回 false 即可
}
@Override
public void init(Context context) {
}
}
```
#### 五、更多功能
1. 初始化中的其他设置
Expand Down
2 changes: 1 addition & 1 deletion arouter-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ android {

dependencies {
annotationProcessor 'com.alibaba:arouter-compiler:1.2.0'
implementation 'com.alibaba:arouter-annotation:1.0.6'
api 'com.alibaba:arouter-annotation:1.0.6'
implementation "com.android.support:support-v4:${SUPPORT_LIB_VERSION}"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface InterceptorCallback {
void onContinue(Postcard postcard);

/**
* Interrupt process, pipeline will be destory when this method called.
* Interrupt process, pipeline will be destroy when this method called.
*
* @param exception Reson of interrupt.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.alibaba.android.arouter.facade.service;

import android.content.Context;
import com.alibaba.android.arouter.facade.Postcard;
import com.alibaba.android.arouter.facade.template.IProvider;

/**
* Pretreatment service used for check if need navigation.
*
* @author zhilong [Contact me.](mailto:[email protected])
* @version 1.0
* @since 2019-05-08 11:53
*/
public interface PretreatmentService extends IProvider {
/**
* Do something before navigation.
*
* @param context context
* @param postcard meta
* @return if need navigation.
*/
boolean onPretreatment(Context context, Postcard postcard);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
import com.alibaba.android.arouter.facade.Postcard;
import com.alibaba.android.arouter.facade.callback.InterceptorCallback;
import com.alibaba.android.arouter.facade.callback.NavigationCallback;
import com.alibaba.android.arouter.facade.service.AutowiredService;
import com.alibaba.android.arouter.facade.service.DegradeService;
import com.alibaba.android.arouter.facade.service.InterceptorService;
import com.alibaba.android.arouter.facade.service.PathReplaceService;
import com.alibaba.android.arouter.facade.service.*;
import com.alibaba.android.arouter.facade.template.ILogger;
import com.alibaba.android.arouter.thread.DefaultPoolExecutor;
import com.alibaba.android.arouter.utils.Consts;
Expand Down Expand Up @@ -276,6 +273,12 @@ protected <T> T navigation(Class<? extends T> service) {
* @param callback cb
*/
protected Object navigation(final Context context, final Postcard postcard, final int requestCode, final NavigationCallback callback) {
PretreatmentService pretreatmentService = ARouter.getInstance().navigation(PretreatmentService.class);
if (null != pretreatmentService && !pretreatmentService.onPretreatment(context, postcard)) {
// Pretreatment failed, navigation canceled.
return null;
}

try {
LogisticsCenter.completion(postcard);
} catch (NoRouteFoundException ex) {
Expand All @@ -295,7 +298,8 @@ public void run() {

if (null != callback) {
callback.onLost(postcard);
} else { // No callback for this invoke, then we use the global degrade service.
} else {
// No callback for this invoke, then we use the global degrade service.
DegradeService degradeService = ARouter.getInstance().navigation(DegradeService.class);
if (null != degradeService) {
degradeService.onLost(context, postcard);
Expand Down Expand Up @@ -416,6 +420,7 @@ private void runInMainThread(Runnable runnable) {

/**
* Start activity
*
* @see ActivityCompat
*/
private void startActivity(int requestCode, Context currentContext, Intent intent, Postcard postcard, NavigationCallback callback) {
Expand Down
2 changes: 1 addition & 1 deletion bintray.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ task javadocJar(type: Jar, dependsOn: javadoc) {
}

artifacts {
archives javadocJar
// archives javadocJar
archives sourcesJar
}

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ buildscript {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.alibaba:arouter-register:$arouter_register_version"
}
Expand Down
2 changes: 1 addition & 1 deletion install.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

apply plugin: 'com.github.dcendents.android-maven'

group = publishedGroupId // Maven Group ID for the artifact
group = publishedGroupId

install {
repositories.mavenInstaller {
Expand Down

0 comments on commit 790d091

Please sign in to comment.