Skip to content

Commit 81dbbe5

Browse files
committed
1:修改组件化架构,将APP组件改成一个没有界面的壳工程,提取了一个新组件main,负责启动APP和主界面管理。
1 parent f4010db commit 81dbbe5

20 files changed

Lines changed: 201 additions & 54 deletions

File tree

‎app/build.gradle‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ dependencies {
5353
compile fileTree(dir: 'libs', include: ['*.jar'])
5454

5555
if (!isModule.toBoolean()) {
56+
compile project(':main')
5657
compile project(':girls')
5758
compile project(':news')
5859
} else {

‎app/src/main/AndroidManifest.xml‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
android:label="@string/app_name"
1010
android:supportsRtl="true"
1111
android:theme="@style/AppTheme">
12+
13+
<!--声明整个应用程序的路由协议-->
1214
<activity
1315
android:name="com.github.mzule.activityrouter.router.RouterActivity"
1416
android:theme="@android:style/Theme.NoDisplay">
@@ -22,13 +24,6 @@
2224
</intent-filter>
2325
</activity>
2426

25-
<activity android:name=".MainActivity">
26-
<intent-filter>
27-
<action android:name="android.intent.action.MAIN" />
28-
29-
<category android:name="android.intent.category.LAUNCHER" />
30-
</intent-filter>
31-
</activity>
3227
</application>
3328

3429
</manifest>

app/src/main/java/com/guiying/androidmodulepattern/AppModule.java renamed to app/src/main/java/com/guiying/androidmodulepattern/App.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
import com.github.mzule.activityrouter.annotation.Module;
44

55
/**
6-
* <p>类说明</p>
6+
* <p>这就是个壳工程,没有任何界面,只负责管理组件</p>
77
*
88
* @author 张华洋 2017/2/15 20:42
99
* @version V1.2.0
1010
* @name AppModule
1111
*/
1212

1313
@Module("app")
14-
public class AppModule {
14+
public class App {
1515
}

‎app/src/main/java/com/guiying/androidmodulepattern/MyApplication.java‎

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,21 @@
22

33
import com.github.mzule.activityrouter.annotation.Modules;
44
import com.guiying.common.base.BaseApplication;
5-
import com.guiying.common.http.HttpClient;
6-
import com.guiying.common.http.OnResultListener;
7-
import com.orhanobut.logger.Logger;
85

96
/**
10-
* <p>类说明</p>
7+
* <p>应用程序的Application只负责管理组件</p>
118
*
129
* @author 张华洋 2017/2/15 20:14
1310
* @version V1.2.0
1411
* @name MyApplication
1512
*/
16-
@Modules({"app", "girls", "news"})
13+
@Modules({"app", "main", "girls", "news"})
1714
public class MyApplication extends BaseApplication {
1815

1916

2017
@Override
2118
public void onCreate() {
2219
super.onCreate();
23-
login();
2420
}
2521

26-
/**
27-
* 在这里模拟登陆,然后拿到sessionId或者Token
28-
* 这样就能够在组件请求接口了
29-
*/
30-
private void login() {
31-
HttpClient client = new HttpClient.Builder()
32-
.baseUrl("http://gank.io/api/data/")
33-
.url("福利/10/1")
34-
.build();
35-
client.get(new OnResultListener<String>() {
36-
37-
@Override
38-
public void onSuccess(String result) {
39-
Logger.e(result);
40-
}
41-
42-
@Override
43-
public void onError(int code, String message) {
44-
Logger.e(message);
45-
}
46-
47-
@Override
48-
public void onFailure(String message) {
49-
Logger.e(message);
50-
}
51-
});
52-
}
5322
}

‎app/src/main/res/values/colors.xml‎

Lines changed: 0 additions & 4 deletions
This file was deleted.

‎app/src/main/res/values/strings.xml‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,4 @@
33

44
<string name="global_scheme">module</string>
55

6-
<string name="app_exit_hint">再按一次退出程序哦~</string>
7-
86
</resources>

‎build.gradle‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ ext {
4343
javaVersion = JavaVersion.VERSION_1_8
4444

4545
// App dependencies version
46-
supportLibraryVersion = "25.2.0"
46+
supportLibraryVersion = "25.3.0"
4747
retrofitVersion = "2.1.0"
4848
glideVersion = "3.7.0"
4949
loggerVersion = "1.15"

‎common/src/main/java/com/guiying/common/base/BaseApplication.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
/**
1616
* 要想使用BaseApplication,必须在组件中实现自己的Application,并且继承BaseApplication;
17-
* 组件中实现的Application必须在AndroidManifest.xml中注册,否则无法使用;
17+
* 组件中实现的Application必须在debug包中的AndroidManifest.xml中注册,否则无法使用;
1818
* 组件的Application需置于java/debug文件夹中,不得放于主代码;
1919
* 组件中获取Context的方法必须为:Utils.getContext(),不允许其他写法;
2020
* BaseApplication主要用来管理全局Activity;

‎main/.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

‎main/build.gradle‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
if (isModule.toBoolean()) {
2+
apply plugin: 'com.android.application'
3+
} else {
4+
apply plugin: 'com.android.library'
5+
}
6+
7+
apply plugin: 'com.neenbedankt.android-apt'
8+
9+
android {
10+
compileSdkVersion rootProject.ext.compileSdkVersion
11+
buildToolsVersion rootProject.ext.buildToolsVersion
12+
13+
defaultConfig {
14+
minSdkVersion rootProject.ext.minSdkVersion
15+
targetSdkVersion rootProject.ext.targetSdkVersion
16+
versionCode rootProject.ext.versionCode
17+
versionName rootProject.ext.versionName
18+
}
19+
20+
buildTypes {
21+
release {
22+
minifyEnabled false
23+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
24+
}
25+
}
26+
27+
sourceSets {
28+
main {
29+
if (isModule.toBoolean()) {
30+
manifest.srcFile 'src/main/debug/AndroidManifest.xml'
31+
} else {
32+
manifest.srcFile 'src/main/release/AndroidManifest.xml'
33+
//release模式下排除debug文件夹中的所有Java文件
34+
java {
35+
exclude 'debug/**'
36+
}
37+
}
38+
}
39+
}
40+
//设置了resourcePrefix值后,所有的资源名必须以指定的字符串做前缀,否则会报错。
41+
//但是resourcePrefix这个值只能限定xml里面的资源,并不能限定图片资源,所有图片资源仍然需要手动去修改资源名。
42+
//resourcePrefix "girls_"
43+
}
44+
45+
dependencies {
46+
compile fileTree(dir: 'libs', include: ['*.jar'])
47+
compile project(':common')
48+
//router
49+
apt "com.github.mzule.activityrouter:compiler:$rootProject.aptCompilerVersion"
50+
}

0 commit comments

Comments
 (0)