use of com.rengwuxian.rxjavasamples.model.ZhuangbiImage in project RxJavaSamples by rengwuxian.
the class ZhuangbiListAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
DebounceViewHolder debounceViewHolder = (DebounceViewHolder) holder;
ZhuangbiImage image = images.get(position);
Glide.with(holder.itemView.getContext()).load(image.image_url).into(debounceViewHolder.imageIv);
debounceViewHolder.descriptionTv.setText(image.description);
}
use of com.rengwuxian.rxjavasamples.model.ZhuangbiImage in project RxJavaSamples by rengwuxian.
the class ZipFragment method load.
@OnClick(R.id.zipLoadBt)
void load() {
swipeRefreshLayout.setRefreshing(true);
unsubscribe();
disposable = Observable.zip(Network.getGankApi().getBeauties(200, 1).map(GankBeautyResultToItemsMapper.getInstance()), Network.getZhuangbiApi().search("装逼"), new BiFunction<List<Item>, List<ZhuangbiImage>, List<Item>>() {
@Override
public List<Item> apply(List<Item> gankItems, List<ZhuangbiImage> zhuangbiImages) {
List<Item> items = new ArrayList<Item>();
for (int i = 0; i < gankItems.size() / 2 && i < zhuangbiImages.size(); i++) {
items.add(gankItems.get(i * 2));
items.add(gankItems.get(i * 2 + 1));
Item zhuangbiItem = new Item();
ZhuangbiImage zhuangbiImage = zhuangbiImages.get(i);
zhuangbiItem.description = zhuangbiImage.description;
zhuangbiItem.imageUrl = zhuangbiImage.image_url;
items.add(zhuangbiItem);
}
return items;
}
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<List<Item>>() {
@Override
public void accept(@NonNull List<Item> items) throws Exception {
swipeRefreshLayout.setRefreshing(false);
adapter.setItems(items);
}
}, new Consumer<Throwable>() {
@Override
public void accept(@NonNull Throwable throwable) throws Exception {
swipeRefreshLayout.setRefreshing(false);
Toast.makeText(getActivity(), R.string.loading_failed, Toast.LENGTH_SHORT).show();
}
});
}
Aggregations