Search in sources :

Example 1 with ZhuangbiImage

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);
}
Also used : ZhuangbiImage(com.rengwuxian.rxjavasamples.model.ZhuangbiImage)

Example 2 with ZhuangbiImage

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();
        }
    });
}
Also used : Item(com.rengwuxian.rxjavasamples.model.Item) Consumer(io.reactivex.functions.Consumer) NonNull(io.reactivex.annotations.NonNull) ArrayList(java.util.ArrayList) List(java.util.List) ZhuangbiImage(com.rengwuxian.rxjavasamples.model.ZhuangbiImage) OnClick(butterknife.OnClick)

Aggregations

ZhuangbiImage (com.rengwuxian.rxjavasamples.model.ZhuangbiImage)2 OnClick (butterknife.OnClick)1 Item (com.rengwuxian.rxjavasamples.model.Item)1 NonNull (io.reactivex.annotations.NonNull)1 Consumer (io.reactivex.functions.Consumer)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1