google 官方的mvp例子:
https://github.com/googlesamples/android-architecture/tree/todo-mvp-dagger/
国内集成了很多目前热门框架的项目:
http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2016/1125/6803.html
android进阶篇 MVP+Retrofit+RxJava框架结合:
http://m.2cto.com/kf/201608/538697.html
响应式编程:RxJava/RxAndroid 使用实例实践:
http://www.jianshu.com/p/031745744bfa
rxjava使用场景:
http://blog.csdn.net/lzyzsd/article/details/50120801
http://blog.csdn.net/aiynmimi/article/details/53382567
Rxjava 官方github
https://github.com/ReactiveX/RxJava/
【腾讯大神】一步一步实现Android的MVP框架
http://dev.qq.com/topic/5799d7844bef22a823b3ad44
http://blog.csdn.net/jdsjlzx/article/details/52415615
给 Android 开发者的 RxJava 详解
http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/1012/3572.html#toc_17
retrofit2和rxjava2应用:
compile 'com.google.code.gson:gson:2.7'compile( 'com.squareup.retrofit2:retrofit:2.2.0'){ exclude group: 'com.squareup.okhttp3'}compile ('com.squareup.retrofit2:converter-gson:2.2.0'){ exclude group : 'com.google.code.gson' exclude group: 'com.squareup.okhttp3'}compile ('com.squareup.retrofit2:adapter-rxjava2:2.2.0'){ exclude group: 'io.reactivex' exclude group: 'com.squareup.okhttp3' }compile 'io.reactivex.rxjava2:rxjava:2.0.8'compile 'io.reactivex.rxjava2:rxandroid:2.0.1'compile 'com.squareup.okhttp3:logging-interceptor:latest.release'compile 'com.squareup.okhttp3:okhttp:latest.release'compile 'com.squareup.okio:okio:latest.release'
遇到一个问题,不知道flatmap和doOnNext怎么配合使用,问题见注释:
@Override public void start(final String agentId, String typeId) { mRootView.showProgress(); LogUtils.e("main Thread:"+Thread.currentThread().getId()); Disposable o = mModel.getSecondaryGoodsTypes(agentId, typeId) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doOnNext(new Consumer
>>() { @Override public void accept(@NonNull BaseResponse
> listBaseResponse) throws Exception { LogUtils.e("doOnNext current Thread:"+Thread.currentThread().getId()); List goodsTypes = listBaseResponse.getData(); mRootView.updateTypeList(goodsTypes); } }).doOnError(new Consumer () { @Override public void accept(@NonNull Throwable throwable) throws Exception { LogUtils.e("doOnError current Thread:"+Thread.currentThread().getId()); mRootView.hideProgress(); mRootView.showCommonErrorPage(); } }) .observeOn(Schedulers.newThread()) .flatMap(new Function
>, Observable >>() { @Override public Observable > apply(@NonNull BaseResponse
> listBaseResponse) throws Exception { LogUtils.e("flatMap apply current Thread:"+Thread.currentThread().getId()); //先通过一级分类id拿商品二级分类,再默认拿第一个分类下的商品列表 if (listBaseResponse != null) { List list = listBaseResponse.getData(); if (list != null && list.size() > 0) { int secondTypeId = list.get(0).getId(); return mModel.getGoodsByType(agentId, String.valueOf(secondTypeId), 20, 0); } } return Observable.just(null); } }) //.observeOn(AndroidSchedulers.mainThread())//加上这行就没有回调了,不加的话就是在子线程而不是在主线程 .subscribeWith(new DisposableObserver >() { @Override public void onNext(BaseResponse goodsListBaseResponse) { LogUtils.e("subscribeWith onNext current Thread:"+Thread.currentThread().getId()); } @Override public void onError(Throwable e) { LogUtils.e("subscribeWith onError current Thread:"+Thread.currentThread().getId()); mRootView.hideProgress(); } @Override public void onComplete() { mRootView.hideProgress(); } });