Skip to content

Commit 3eada5d

Browse files
author
mrzhang
committed
Merge branch 'anno' of https://github.com/luojilab/DDComponentForAndroid into anno
2 parents 9ce01ba + b53f245 commit 3eada5d

File tree

65 files changed

+2208
-100
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+2208
-100
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ demo解读请参考文章[Android彻底组件化demo发布](http://www.jianshu.c
66
### 实现功能:
77
- 组件可以单独调试
88
- 组件之间通过接口+实现的方式进行数据传输
9-
- 使用schme和host路由的方式进行activity之间的跳转
9+
- 使用scheme和host路由的方式进行activity之间的跳转
1010
- 任意组件可以充当host,集成其他组件进行集成调试
1111
- 可以动态对已集成的组件进行加载和卸载
1212
- 杜绝组件之前相互耦合,代码完全隔离,彻底解耦

URI设计.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# URI设计
2+
By Leobert
3+
4+
## 为什么要有这一篇
5+
DDComponent设计的初衷应当是注重于实现组件化,得到的几位大牛也提供了非常优秀的解决方案。但是组件化的代码边界带来了一个问题:UI跳转的时候没那么方便了,以往常见的做法:
6+
7+
* 耦合非常高的直接构造Intent并启动
8+
* 将所需的参数、参数组装等都在目标Activity中进行方法封装,暴露静态方法供调用
9+
* 实现Factory进行Intent的构造、实现启动器
10+
11+
都不行了。所以DDComponent中有了Router部分,使用路由进行UI跳转(通过路由寻找组件的内容本篇略过)。而DDComponent中的UIRouter部分是比较轻量级的,本人也有幸和得到的大牛进行了一定的讨论,对router部分略尽了绵薄之力。但是当前的Router部分使用还是没那么轻松的,而本人也对这些问题进行了思考,幸有所得。鉴于接下来一段时间我都比较忙,现将设计思路记录于此,倘若有同行有兴趣提供一臂自力也是非常感激的。
12+
13+
PS:格竹子君给我开了一个anno分支,本身我命这个名字是Feature/anno 使用注解实现路由定义的功能分支。
14+
15+
## URI的基础格式
16+
> 协议://域名:port/目录a/目录b/文件c?key1=value1&key2=v2#author
17+
18+
除了这些还有query部分,author部分(URL中也有人称hash部分)
19+
而‘目录a/目录b/文件c’这段也有人称为path。
20+
21+
**在当前的实现中,参数传递暂使用Bundle,不支持使用queryString**
22+
23+
我们可以看到demo中有这样一段:
24+
25+
```
26+
UIRouter.getInstance().openUri(getActivity(), "componentdemo://share", bundle);
27+
```
28+
29+
这里使用的URI尚未经过精心设计,而且直接使用hardcode形式也是不利于维护的(当然这里只是demo,当我们将框架完善后这些问题就解决了)
30+
31+
## 设计构想
32+
### 协议部分
33+
有一些朋友提过issue:runalone时的传值问题。参考一些服务端的同事在一些非敏感接口同时兼容了query传值和表单传值的做法,我觉得Router部分兼容query传值和Intent的bundle传值是可取的。考虑到可能控制不住的场面。通过协议部分区分两种形式。
34+
35+
* dunq: DDUiNavigation-QueryString 使用queryString传值
36+
* dunb: DDUiNavigation-Bundle 使用Bundle传值
37+
38+
### host部分
39+
我们可以将Component认为是不同的主机,给定不同的域名
40+
41+
### port部分
42+
我有在项目中提过一个issue,intent的FLAG问题,当前是没有支持的,可以使用port来做一些手脚,也可以直接在Router中将方法原型扩展一下。*我还要再细想想哪种好*
43+
44+
### path部分
45+
当前的anno分支实现中,在对path提出了group的概念,可以针对group分一下Router,但是除了看起来有点噱头其实没啥大用,因为路由表都是按照注解自动生成的,最多就是路由器命名的时候贴切一些。
46+
47+
但潜意识告诉我这个group迟早会有用 233333
48+
49+
计划中会按照注解的path生成一些常量,减少hardcode。这个时候group可能会有用哦。
50+
51+
### query部分
52+
计划中需要支持使用query进行传值
53+
54+

app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ android {
2626

2727
dependencies {
2828
compile project(':componentservice')
29+
// annotationProcessor project(':router-anno-compiler')
2930
}
3031

3132
combuild {

app/gradle.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ org.gradle.jvmargs=-Xmx1536m
1212
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
1313
# org.gradle.parallel=true
1414
isRunAlone=true
15-
debugComponent=readercomponent,com.mrzhang.share:sharecomponent
15+
debugComponent=readercomponent,sharecomponent
16+
#debugComponent=readercomponent,com.mrzhang.share:sharecomponent
1617
compileComponent=readercomponent,sharecomponent
1718

1819

app/src/main/java/com/mrzhang/component/MainActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ protected void onCreate(Bundle savedInstanceState) {
3030
showFragment();
3131
}
3232

33+
3334
private void showFragment() {
3435
if (fragment != null) {
3536
ft = getSupportFragmentManager().beginTransaction();

app/src/main/java/com/mrzhang/component/application/AppApplication.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ public void onCreate() {
1515
//如果isRegisterCompoAuto为false,则需要通过反射加载组件
1616
// Router.registerComponent("com.mrzhang.reader.applike.ReaderAppLike");
1717
// Router.registerComponent("com.mrzhang.share.applike.ShareApplike");
18-
1918
}
2019

2120

basicres/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,8 @@ android {
2525

2626
dependencies {
2727
compile project(':basiclib')
28+
testCompile 'junit:junit:4.12'
29+
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
30+
exclude group: 'com.android.support', module: 'support-annotations'
31+
})
2832
}

build-gradle/src/main/groovy/com.dd.buildgradle/exten/ComExtension.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class ComExtension {
99
boolean isRegisterCompoAuto = false;
1010

1111
/**
12-
* 当前组件的applicatonName,用于字节码插入。
12+
* 当前组件的applicationName,用于字节码插入。
1313
* 当isRegisterCompoAuto==true的时候是必须的
1414
*/
1515
String applicationName

componentlib/build.gradle

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,13 @@ android {
2525
}
2626

2727
dependencies {
28-
compile fileTree(dir: 'libs', include: ['*.jar'])
28+
compile fileTree(include: ['*.jar'], dir: 'libs')
2929
compile 'com.android.support:appcompat-v7:26.+'
30+
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
31+
exclude group: 'com.android.support', module: 'support-annotations'
32+
})
33+
testCompile 'junit:junit:4.12'
34+
compile project(':router-annotation')
3035
}
3136

3237

componentlib/src/main/java/com/mrzhang/component/componentlib/router/Router.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
import java.util.HashMap;
99

1010
/**
11+
* Center router, works for component-dynamic-load/remove and services add/remove/get
1112
* Created by mrzhang on 2017/6/15.
1213
*/
13-
1414
public class Router {
1515

1616
private HashMap<String, Object> services = new HashMap<>();
@@ -33,6 +33,7 @@ public static Router getInstance() {
3333
return instance;
3434
}
3535

36+
3637
public synchronized void addService(String serviceName, Object serviceImpl) {
3738
if (serviceName == null || serviceImpl == null) {
3839
return;

0 commit comments

Comments
 (0)