当我关闭互联网并在第一次下拉刷新时,一切正常(禁用刷新,并显示“NetworkErrorView”),但是当我在第二次下拉刷新时,刷新状态会冻结。我理解在SingleObserver中既不调用onSuccess(因为没有网络,没问题),也不调用onError,因为互联网关闭,结果doAfterTerminate也不被调用。
顺便说一下,dataManager.getCitiesFromDb()返回Observable(City),而dataManager.getCityConditionsResponse()返回Single(List(City))。
MainActivity(onCreate)
顺便说一下,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());
}