当我第一次关闭互联网并滑动刷新时,一切正常(刷新禁用和显示NetworkErrorView
),但是当我第二次滑动刷新时,刷新状态冻结,据我所知,SingleObserver
两者都没有调用onSuccess
(因为互联网关闭, 好吧), nor onError
, 应该打电话因为互联网关闭, 结果doAfterTerminate
也没有打电话。
顺便一提,
dataManager.getCitiesFromDb()
返回Observable(City)
和
dataManager.getCityConditionsResponse()
返回Single(List(City))
MainActivity (onCreate)
presenter.setRefreshObservable(RxSwipeRefreshLayout.refreshes(swipeRefreshLayout));
主持人
@Override
public void setRefreshObservable(Observable<Object> observable) {
observable
.flatMapSingle(l -> getCitiesListObservable()
.flatMap(list -> Single.fromObservable(Observable.fromIterable(list)))
.map(city -> city))
.toList()
.subscribe(new SingleObserver<List<City>>() {
@Override
public void onSubscribe(Disposable d) {
disposables.add(d);
}
@Override
public void onSuccess(List<City> list) {
view.showCitiesList(list);
}
@Override
public void onError(Throwable e) {
view.showNetworkErrorView();
}
});
}
private Single<List<City>> getCitiesListObservable() {
return dataManager.getCitiesFromDb()
.flatMapSingle(city ->
dataManager.getCityConditionsResponse(city.getQuery())
.map(response -> {
city.setTemp(response.getTemp());
city.setIcon(response.getIcon());
return city;
})
)
.toList()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doAfterTerminate(() -> view.hideRefreshingStatus());
}