CreateQuery query no error, Rxjava doAfterTerminate method no callback. But there is a callback when there is error
tpnet opened this issue · 2 comments
tpnet commented
CreateQuery query no error, Rxjava doAfterTerminate method no callback. But there is a callback when there is error
tpnet commented
just like this:
Presenter:
mModel.getHots(JsoupRegular.HOT_MOVIE)
.compose(RxUtils.<List<Hot>>bindToLifecycle(mRootView))
.observeOn(AndroidSchedulers.mainThread())
.doAfterTerminate(new Action0() {
@Override
public void call() {
Timber.e("hot doAfterTerminate");
showLoad();
}
})
.doOnNext(new Action1<List<Hot>>() {
@Override
public void call(List<Hot> hots) {
showLoad();
}
})
.subscribe(new ErrorHandleSubscriber<List<Hot>>(mErrorHandler) {
@Override
public void onNext(List<Hot> hots) {
mRootView.setHotAdapter(new HotAdapter(hots));
}
});
model:
@Override
public Observable<List<Hot>> getHots(@JsoupRegular.HOTCATEGORY String hotCategory) {
return DBUtil.getInstance().getHotByType(hotCategory)
.flatMap(new Func1<List<Hot>, Observable<List<Hot>>>() {
@Override
public Observable<List<Hot>> call(List<Hot> hots) {
if(hots.size() <=0 || SystemTool.isTimeOld(hots.get(0).createTime(),1)){
try {
hots = JsoupRegular.getHotList(Jsoup.connect(Constant.HOME).timeout(Constant.TIME_OUT).get(),hotCategory);
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}
}
return Observable.just(hots);
}
});
}
DBUtil:
public Observable<List<Hot>> getHotByType(String hotCategory) {
SqlDelightStatement sqlDelightStatement = Hot.FACTORY.selectHotByType(hotCategory);
return db.createQuery(Hot.TABLE_NAME,sqlDelightStatement.statement,sqlDelightStatement.args)
.mapToList(new Func1<Cursor, Hot>() {
@Override
public Hot call(Cursor cursor) {
return Hot.ROW_HOT_BYTYPE_MAPPER.map(cursor);
}
});
}
in Presenter, doAfterTerminate method no callback when query is normal。
artem-zinnatullin commented
Because Observable does not complete, it listens to changes to be able to emit you new query results.