use of com.xinshang.audient.model.entities.ToplistDataBean in project Audient by komamj.
the class TopListPresenter method loadTopList.
@Override
public void loadTopList() {
mDisposables.clear();
if (mView.isActive()) {
mView.setLoadingIndictor(true);
}
Disposable disposable = mRepository.getToplists().map(new Function<ApiResponse<List<ToplistDataBean>>, List<ToplistDataBean>>() {
@Override
public List<ToplistDataBean> apply(ApiResponse<List<ToplistDataBean>> listApiResponse) throws Exception {
return listApiResponse.data;
}
}).map(new Function<List<ToplistDataBean>, List<Toplist>>() {
@Override
public List<Toplist> apply(List<ToplistDataBean> toplistDataBeans) throws Exception {
List<Toplist> topLists = new ArrayList<>();
for (ToplistDataBean toplistDataBean : toplistDataBeans) {
for (Toplist topList : toplistDataBean.topLists) {
if (isLegal(topList)) {
topLists.add(topList);
}
}
}
return topLists;
}
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new DisposableSubscriber<List<Toplist>>() {
@Override
public void onNext(List<Toplist> topLists) {
if (mView.isActive()) {
mView.showTopLists(topLists);
}
}
@Override
public void onError(Throwable t) {
if (t instanceof ConnectException) {
LogUtils.e(TAG, "loadTopList connect error :");
}
LogUtils.e(TAG, "loadTopList error :" + t.toString());
if (mView.isActive()) {
mView.setLoadingIndictor(false);
mView.showLoadingError();
}
}
@Override
public void onComplete() {
if (mView.isActive()) {
mView.setLoadingIndictor(false);
mView.showSuccessfulMessage();
}
}
});
mDisposables.add(disposable);
}
Aggregations