首先,说放弃 MVP,肯定是夸大其词了。MVP 很好,只是个人不习惯那么多的回调,更喜欢 Flux 这种单向数据流模式。希望大家能多多点赞,多多拍砖!
Step 1.添加到根目录中的 build.gradle中
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
Step 2. 添加依赖到 build.gradle
dependencies {
//RxFlux2
implementation 'com.github.coolfire2015:RxFlux2:1.0.1'
//Dagger2
implementation "com.google.dagger:dagger:${DAGGER}"
annotationProcessor "com.google.dagger:dagger-compiler:${DAGGER}"
//网络Retrofit
implementation "com.squareup.retrofit2:retrofit:${RETROFIT}"
implementation "com.squareup.retrofit2:converter-gson:${RETROFIT}"
implementation "com.squareup.retrofit2:adapter-rxjava2:${RETROFIT}"
//网络OkHttp,OkIo
implementation "com.squareup.okio:okio:${OKIO}"
implementation "com.squareup.okhttp3:okhttp:${OKHTTP}"
//RxLifecycle
implementation "com.trello.rxlifecycle2:rxlifecycle:${RX_LIFE_CYCLE_2}"
implementation "com.trello.rxlifecycle2:rxlifecycle-android:${RX_LIFE_CYCLE_2}"
implementation "com.trello.rxlifecycle2:rxlifecycle-components:${RX_LIFE_CYCLE_2}"
}
Step 3. 复制com.huyingbao.rxflux2包到项目中
包Step 4. 复制代码模板
复制代码模板 templates 到 android studio 安装目录中 android-studio\plugins\android\lib\templates目录下
包
Step 5. 创建RxActivity、RxFragment
创建RxFluxActivity创建RxFluxFragment
模板选项
全部添加之后的文件
手动在Dagger2 module中添加实例Store方法
代码修改
总结
- 可以只依赖包'com.github.coolfire2015:RxFlux2:1.0.2',不使用 dagger2,自己实现 Flux 模式。
- 第三步 copy 的代码主要是封装的view基类、dagger2类等框架基础类。若是用不到的代码可以删掉。
- 使用代码模块,可以一键创建标准 RxFlux2 模块代码,包含activity、fragment 、store、布局文件(只有fragment 对应的布局文件),并在 manifest 文件注册,也可只创建 fragment 。
- 代码模版创建界面选项丰富,随心创建。
网友评论