Android开发经验谈Android开发Android技术知识

放弃MVP-Android Flux 框架 RxFlux2 (二

2017-11-08  本文已影响226人  coolfireApy

首先,说放弃 MVP,肯定是夸大其词了。MVP 很好,只是个人不习惯那么多的回调,更喜欢 Flux 这种单向数据流模式。希望大家能多多点赞,多多拍砖!

demo源码RxFlux2

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方法
代码修改

总结

下一篇 放弃MVP-Android Flux 框架 RxFlux2 (三)使用

上一篇 下一篇

猜你喜欢

热点阅读