RxGreenDao: Reactive Extensions for GreenDao
使GreenDao支持Rxjava的补丁包
#Download
compile 'io.github.llp:RxGreenDao:0.1'
注意:
- 使用DaoGenerator生成出来的XXXDao要把继承关系从AbstractDao修改为RxAbstractDao
- RxGreenDao提供的方法以rx开头,例如:xxxDao.rxCount(),xxxDao.rxInsert()...
- 提供xxxDao.rxQueryBuilder()
#TODO
- 扩展DaoGenerator,使其自动生成继承RxAbstractDao的xxxDao
- 添加测试类
#Sample Note note = new Note(); note.setText("hello world!"); noteDao.rxInsert(note) .doOnNext(new Action1() { @Override public void call(Long aLong) { Log.e(TAG, "#-----doOnNext---->>>" + aLong); } }) .flatMap(new Func1<Long, Observable<List>>() { @Override public Observable<List> call(Long aLong) { return noteDao.rxQueryBuilder().list(); } }) .flatMap(new Func1<List, Observable>() { @Override public Observable call(List notes) { return Observable.from(notes); } }) .flatMap(new Func1<Note, Observable>() { @Override public Observable call(Note note) { return Observable.just(note.getText()); } }) .subscribe(new Subscriber() { @Override public void onCompleted() { Log.e(TAG, "#-----onCompleted---->>>"); }
@Override
public void onError(Throwable e) {
Log.e(TAG, "#-----onError---->>>");
}
@Override
public void onNext(String s) {
Log.e(TAG, "#------onNext--->>>" + s);
}
});