Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
Initial commit
  • Loading branch information
goldze committed Nov 16, 2018
1 parent 334ea8f commit 3d82731
Show file tree
Hide file tree
Showing 123 changed files with 1,142 additions and 446 deletions.
7 changes: 5 additions & 2 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
<a target="_blank" href="//shang.qq.com/wpa/qunwpa?idkey=a8db5d8f95bc432606fd79c3d6e494e8a97401671c27de4a8fe975382a441a3e"><img border="0" src="http://pub.idqqimg.com/wpa/images/group.png" alt="MVVMHabit-Family" title="MVVMHabit-Family"></a>
##
[戳我去MVVMHabit](https://github.com/goldze/MVVMHabit)
## 方案架构图
## 整体架构
![](./img/ComponentProgrammeImage.png)
25 changes: 19 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ android {
versionCode rootProject.ext.android.versionCode
versionName rootProject.ext.android.versionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
//阿里路由框架配置
javaCompileOptions {
annotationProcessorOptions {
arguments = [AROUTER_MODULE_NAME: project.getName()]
}
}
}
buildTypes {
release {
Expand All @@ -26,18 +32,25 @@ android {

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation rootProject.ext.support["appcompat-v7"]
testImplementation rootProject.ext.support["junit"]
//宿主项目中判断组件是否需要独立运行
if (isBuildModule.toBoolean()) {
//组件独立运行时,宿主项目直接依赖基础库,避免编译错误
implementation project(':base')
implementation project(':library-base')
} else {
//登录验证模块
//身份验证模块
implementation project(':module-sign')
//主业务模块
implementation project(':module-main')
//应用模块
implementation project(':module-home')
//工作模块
implementation project(':module-work')
//消息模块
implementation project(':module-msg')
//用户模块
implementation project(':module-user')
}
testImplementation rootProject.ext.support["junit"]
//第三方底部Tabbar
implementation 'me.majiajie:pager-bottom-tab-strip:2.2.2'
//组件中依赖阿里路由编译框架
annotationProcessor rootProject.ext.dependencies["arouter-compiler"]
}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ui.MainActivity"></activity>
</application>

</manifest>
93 changes: 93 additions & 0 deletions app/src/main/java/com/goldze/component/ui/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package com.goldze.component.ui;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.content.ContextCompat;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.goldze.base.router.RouterActivityPath;
import com.goldze.base.router.RouterFragmentPath;
import com.goldze.component.R;
import com.goldze.component.BR;
import com.goldze.component.databinding.ActivityMainBinding;

import java.util.ArrayList;
import java.util.List;

import me.goldze.mvvmhabit.base.BaseActivity;
import me.goldze.mvvmhabit.base.BaseViewModel;
import me.majiajie.pagerbottomtabstrip.NavigationController;
import me.majiajie.pagerbottomtabstrip.listener.OnTabItemSelectedListener;

/**
* Created by goldze on 2018/6/21
*/
@Route(path = RouterActivityPath.App.APP_MAIN)
public class MainActivity extends BaseActivity<ActivityMainBinding, BaseViewModel> {
private List<Fragment> mFragments;

@Override
public int initContentView(Bundle savedInstanceState) {
return R.layout.activity_main;
}

@Override
public int initVariableId() {
return BR.viewModel;
}

@Override
public void initData() {
//初始化Fragment
initFragment();
//初始化底部Button
initBottomTab();
}

private void initFragment() {
//ARouter拿到多Fragment(这里需要通过ARouter获取,不能直接new,因为在组件独立运行时,宿主app是没有依赖其他组件,所以new不到其他组件的Fragment)
Fragment homeFragment = (Fragment) ARouter.getInstance().build(RouterFragmentPath.Home.HOME_HOME).navigation();
Fragment workFragment = (Fragment) ARouter.getInstance().build(RouterFragmentPath.Work.WORK_WORK).navigation();
Fragment msgFragment = (Fragment) ARouter.getInstance().build(RouterFragmentPath.Msg.MSG_MSG).navigation();
Fragment meFragment = (Fragment) ARouter.getInstance().build(RouterFragmentPath.User.USER_ME).navigation();
mFragments = new ArrayList<>();
mFragments.add(homeFragment);
mFragments.add(workFragment);
mFragments.add(msgFragment);
mFragments.add(meFragment);
if (homeFragment != null) {
//默认选中第一个
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.add(R.id.frameLayout, homeFragment);
transaction.commitAllowingStateLoss();
}
}

private void initBottomTab() {
NavigationController navigationController = binding.pagerBottomTab.material()
.addItem(R.mipmap.yingyong, "首页")
.addItem(R.mipmap.huanzhe, "工作")
.addItem(R.mipmap.xiaoxi_select, "消息")
.addItem(R.mipmap.wode_select, "我的")
.setDefaultColor(ContextCompat.getColor(this, R.color.textColorVice))
.build();
//底部按钮的点击事件监听
navigationController.addTabItemSelectedListener(new OnTabItemSelectedListener() {
@Override
public void onSelected(int index, int old) {
Fragment currentFragment = mFragments.get(index);
if (currentFragment != null) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.frameLayout, currentFragment);
transaction.commitAllowingStateLoss();
}
}

@Override
public void onRepeat(int index) {
}
});
}
}
5 changes: 3 additions & 2 deletions app/src/main/java/com/goldze/component/ui/SplashActivity.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.goldze.component.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;

import com.alibaba.android.arouter.launcher.ARouter;
import com.goldze.base.router.RouterActivityPath;

import me.goldze.mvvmhabit.utils.ToastUtils;

Expand All @@ -30,8 +32,7 @@ public void run() {
* 跳转登录界面
*/
private void inSign() {
//使用路由框架,跳转到Sign组件的登录页
ARouter.getInstance().build("/sign/Login").navigation();
startActivity(new Intent(this, MainActivity.class));
finish();
}
}
File renamed without changes.
File renamed without changes
3 changes: 0 additions & 3 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>
8 changes: 0 additions & 8 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<!--StartActivity Style 冷启动效果-->
<style name="AppTheme.Start">
<item name="android:windowBackground">@drawable/activity_start</item>
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ org.gradle.jvmargs=-Xmx1536m
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
#isBuildModule 为 true 时可以使每个组件独立运行, false 则可以将所有组件集成到宿主 App 中
isBuildModule=true
isBuildModule=false
File renamed without changes.
3 changes: 3 additions & 0 deletions base/build.gradle → library-base/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ dependencies {
api fileTree(include: ['*.jar'], dir: 'libs')
//公用的support相关库在base中依赖
api rootProject.ext.support["design"]
api rootProject.ext.support["appcompat-v7"]
//公用资源在base中依赖
api project(':library-res')
//核心基础库(由于这是例子, 所以这里采用远程依赖的方式, 可根据实际情况自行换成源码依赖,源码地址:https://github.com/goldze/MVVMHabit)
api rootProject.ext.dependencies.MVVMHabit
//阿里路由框架
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@

/**
* Created by goldze on 2018/6/21 0021.
* 组件生命周期反射类名管理,在这里注册需要初始化的组件
* 组件生命周期反射类名管理,在这里注册需要初始化的组件,通过反射动态调用各个组件的初始化方法
* 注意:以下模块中初始化的Module类不能被混淆
*/

public class ModuleLifecycleReflexs {
private static final String BaseInit = "com.goldze.base.base.BaseModuleInit";
//登录验证模块
private static final String SignInit = "com.goldze.sign.SignModuleInit";
//主业务模块
private static final String MainInit = "com.goldze.main.MainModuleInit";
//应用业务模块
private static final String HomeInit = "com.goldze.main.HomeModuleInit";
//工作业务模块
private static final String WorkInit = "com.goldze.work.WorkModuleInit";
//用户业务模块
private static final String UserInit = "com.goldze.user.UserModuleInit";

public static String[] initModuleNames = {BaseInit, SignInit, MainInit, UserInit};
public static String[] initModuleNames = {BaseInit, SignInit, HomeInit, WorkInit, UserInit};
}
18 changes: 18 additions & 0 deletions library-base/src/main/java/com/goldze/base/contract/_Login.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.goldze.base.contract;

/**
* 登录完成后,组件间通信的契约类
* Created by goldze on 2018/6/21.
*/

public class _Login {
private String userName;

public String getUserName() {
return userName;
}

public void setUserName(String userName) {
this.userName = userName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import me.goldze.mvvmhabit.base.BaseApplication;

/**
* Created by xg-goldze on 2018/6/25 0025.
* Created by goldze on 2018/6/25 0025.
* debug包下的代码不参与编译,仅作为独立模块运行时初始化数据
*/

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.goldze.base.global;

/**
* 全局SharedPreferences Key 统一存放在这里,单个组件中的key可以另外在组件中定义
* Created by goldze on 2018/6/21 0021.
*/
public class SPKeyGlobal {
public static final String USER_INFO = "user_info";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.goldze.base.router;

/**
* 用于组件开发中,ARouter单Activity跳转的统一路径注册
* 在这里注册添加路由路径,需要清楚的写好注释,标明功能界面
* Created by goldze on 2018/6/21
*/

public class RouterActivityPath {
/**
* 宿主组件
*/
public static class App {
/*主界面*/
public static final String APP_MAIN = "/app/Main";
}

/**
* 身份验证组件
*/
public static class Sign {
/*登录界面*/
public static final String SIGN_LOGIN = "/sign/Login";
}

/**
* 用户组件
*/
public static class User {
/*用户详情*/
public static final String USER_USERDETAIL = "/user/UserDetail";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.goldze.base.router;

/**
* 用于组件开发中,ARouter多Fragment跳转的统一路径注册
* 在这里注册添加路由路径,需要清楚的写好注释,标明功能界面
* Created by goldze on 2018/6/21
*/

public class RouterFragmentPath {
/**
* 首页组件
*/
public static class Home {
/*首页*/
public static final String HOME_HOME = "/home/Home";
}

/**
* 工作组件
*/
public static class Work {
/*工作*/
public static final String WORK_WORK = "/work/Work";
}
/**
* 消息组件
*/
public static class Msg {
/*消息*/
public static final String MSG_MSG = "/msg/Msg";
}
/**
* 用户组件
*/
public static class User {
/*我的*/
public static final String USER_ME = "/user/Me";
}
}
File renamed without changes
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 3d82731

Please sign in to comment.