use of app.main.wangliwei.enablehands.http.WeixinService in project EnableHands by LeviWGG.
the class PicturePresenterImp method getWeixinNews.
@Override
public void getWeixinNews() {
Retrofit retrofit = new ServiceFactory().create(BASE_URL);
WeixinService weixinService = retrofit.create(WeixinService.class);
Observable<Weixin> observable = weixinService.getWeixinNews(page, 10, "json", KEY);
observable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).flatMap(new Function<Weixin, ObservableSource<List<Weixin.ResultBean.ListBean>>>() {
@Override
public ObservableSource<List<Weixin.ResultBean.ListBean>> apply(Weixin weixin) throws Exception {
return Observable.just(weixin.getResult().getList());
}
}).filter(new Predicate<List<Weixin.ResultBean.ListBean>>() {
@Override
public boolean test(List<Weixin.ResultBean.ListBean> listBeans) throws Exception {
if (listBeans.isEmpty()) {
return false;
}
return true;
}
}).subscribe(new Consumer<List<Weixin.ResultBean.ListBean>>() {
@Override
public void accept(List<Weixin.ResultBean.ListBean> listBeans) throws Exception {
if (page == 1) {
mView.setWeixinNews(listBeans);
} else {
mView.loadMore(listBeans);
}
page++;
}
});
}
Aggregations