首先胧洒,說放棄 MVP卫漫,肯定是夸大其詞了列赎。MVP 很好,只是個(gè)人不習(xí)慣那么多的回調(diào)源葫,更喜歡 Flux 這種單向數(shù)據(jù)流模式息堂。希望大家能多多點(diǎn)贊,多多拍磚芭届!
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}"
//網(wǎng)絡(luò)Retrofit
implementation "com.squareup.retrofit2:retrofit:${RETROFIT}"
implementation "com.squareup.retrofit2:converter-gson:${RETROFIT}"
implementation "com.squareup.retrofit2:adapter-rxjava2:${RETROFIT}"
//網(wǎng)絡(luò)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. 復(fù)制com.huyingbao.rxflux2包到項(xiàng)目中
包
Step 4. 復(fù)制代碼模板
復(fù)制代碼模板 templates 到 android studio 安裝目錄中 android-studio\plugins\android\lib\templates目錄下
包
Step 5. 創(chuàng)建RxActivity储矩、RxFragment
創(chuàng)建RxFluxActivity
創(chuàng)建RxFluxFragment
模板選項(xiàng)
全部添加之后的文件
手動(dòng)在Dagger2 module中添加實(shí)例Store方法
代碼修改
總結(jié)
- 可以只依賴包'com.github.coolfire2015:RxFlux2:1.0.2'感耙,不使用 dagger2褂乍,自己實(shí)現(xiàn) Flux 模式。
- 第三步 copy 的代碼主要是封裝的view基類即硼、dagger2類等框架基礎(chǔ)類逃片。若是用不到的代碼可以刪掉。
- 使用代碼模塊只酥,可以一鍵創(chuàng)建標(biāo)準(zhǔn) RxFlux2 模塊代碼褥实,包含activity损离、fragment 、store窟勃、布局文件(只有fragment 對應(yīng)的布局文件),并在 manifest 文件注冊汁咏,也可只創(chuàng)建 fragment 掂骏。
- 代碼模版創(chuàng)建界面選項(xiàng)豐富级解,隨心創(chuàng)建抡爹。