Search in sources :

Example 1 with ByBannerViewHolder

use of me.jingbin.banner.holder.ByBannerViewHolder in project CloudReader by youlookwhat.

the class EverydayFragment method onObserveViewModel.

private void onObserveViewModel() {
    viewModel.getShowLoading().observe(this, new Observer<Boolean>() {

        @Override
        public void onChanged(@Nullable Boolean aBoolean) {
            showRotaLoading(aBoolean);
        }
    });
    viewModel.getBannerData().observe(this, new Observer<EverydayViewModel.BannerDataBean>() {

        @Override
        public void onChanged(@Nullable EverydayViewModel.BannerDataBean bean) {
            if (bean != null && bean.getImageUrls() != null && bean.getImageUrls().size() > 0) {
                mHeaderBinding.banner.setAutoPlay(true).setOffscreenPageLimit(bean.getImageUrls().size()).setPages(bean.getImageUrls(), new HolderCreator<ByBannerViewHolder>() {

                    @Override
                    public ByBannerViewHolder createViewHolder() {
                        return new ByBannerViewHolder<String>() {

                            private ImageView imageView;

                            @Override
                            public View createView(Context context) {
                                View view = LayoutInflater.from(context).inflate(R.layout.item_banner_wanandroid, null);
                                imageView = (ImageView) view.findViewById(R.id.iv_banner);
                                return view;
                            }

                            @Override
                            public void onBind(Context context, int position, String data) {
                                DensityUtil.setWidthHeight(imageView, DensityUtil.getDisplayWidth(), 2.5f);
                                GlideUtil.displayEspImage(data, imageView, 3);
                            }
                        };
                    }
                }).start();
                mHeaderBinding.banner.setOnBannerClickListener(new OnBannerClickListener() {

                    @Override
                    public void onBannerClick(int position) {
                        if (bean.getList() != null && bean.getList().size() > 0 && !TextUtils.isEmpty(bean.getList().get(position).getCode()) && bean.getList().get(position).getCode().startsWith("http")) {
                            WebViewActivity.loadUrl(getContext(), bean.getList().get(position).getCode(), "加载中...");
                        }
                    }
                });
                isLoadBanner = true;
            }
        }
    });
    viewModel.getContentData().observe(this, new Observer<ArrayList<ArrayList<AndroidBean>>>() {

        @Override
        public void onChanged(@Nullable ArrayList<ArrayList<AndroidBean>> lists) {
            if (lists != null && lists.size() > 0) {
                mEverydayAdapter.setNewData(lists);
            } else {
                showError();
            }
        }
    });
}
Also used : Context(android.content.Context) OnBannerClickListener(me.jingbin.banner.config.OnBannerClickListener) ByBannerViewHolder(me.jingbin.banner.holder.ByBannerViewHolder) ArrayList(java.util.ArrayList) ImageView(android.widget.ImageView) View(android.view.View) EverydayViewModel(com.example.jingbin.cloudreader.viewmodel.gank.EverydayViewModel) ImageView(android.widget.ImageView) AndroidBean(com.example.jingbin.cloudreader.bean.AndroidBean)

Example 2 with ByBannerViewHolder

use of me.jingbin.banner.holder.ByBannerViewHolder in project CloudReader by youlookwhat.

the class GankHomeFragment method onObserveViewModel.

private void onObserveViewModel() {
    viewModel.getShowLoading().observe(getViewLifecycleOwner(), new Observer<Boolean>() {

        @Override
        public void onChanged(@Nullable Boolean aBoolean) {
            showRotaLoading(aBoolean);
        }
    });
    viewModel.getBannerData().observe(getViewLifecycleOwner(), new Observer<GankIoDataBean>() {

        @Override
        public void onChanged(@Nullable GankIoDataBean bean) {
            if (bean != null && bean.getResults() != null && bean.getResults().size() > 0) {
                mHeaderBinding.banner.setDelayTime(4000).setAutoPlay(true).setOffscreenPageLimit(bean.getResults().size()).setPages(bean.getResults(), new HolderCreator<ByBannerViewHolder>() {

                    @Override
                    public ByBannerViewHolder createViewHolder() {
                        return new ByBannerViewHolder<GankIoDataBean.ResultBean>() {

                            private ImageView imageView;

                            @Override
                            public View createView(Context context) {
                                View view = LayoutInflater.from(context).inflate(R.layout.item_banner_wanandroid, null);
                                imageView = (ImageView) view.findViewById(R.id.iv_banner);
                                return view;
                            }

                            @Override
                            public void onBind(Context context, int position, GankIoDataBean.ResultBean data) {
                                DensityUtil.setWidthHeight(imageView, DensityUtil.getDisplayWidth(), 2.2f);
                                GlideUtil.displayEspImage(data.getImage(), imageView, 3);
                                imageView.setOnClickListener(new View.OnClickListener() {

                                    @Override
                                    public void onClick(View v) {
                                        if (!TextUtils.isEmpty(bean.getResults().get(position).getUrl()) && bean.getResults().get(position).getUrl().startsWith("http")) {
                                            WebViewActivity.loadUrl(getContext(), bean.getResults().get(position).getUrl(), "干货集中营");
                                        }
                                    }
                                });
                                imageView.setOnLongClickListener(new View.OnLongClickListener() {

                                    @Override
                                    public boolean onLongClick(View v) {
                                        ViewBigImageActivity.start(v.getContext(), data.getImage(), data.getTitle());
                                        return true;
                                    }
                                });
                            }
                        };
                    }
                }).start();
                isLoadBanner = true;
            }
        }
    });
    viewModel.getContentData().observe(getViewLifecycleOwner(), new Observer<GankIoDataBean>() {

        @Override
        public void onChanged(@Nullable GankIoDataBean bean) {
            bindingView.ivLoading.postDelayed(new Runnable() {

                @Override
                public void run() {
                    if (bean != null && bean.getResults() != null && bean.getResults().size() > 0) {
                        skeletonScreen.hide();
                        mAdapter.setNewData(bean.getResults());
                        bindingView.recyclerView.loadMoreEnd();
                    } else {
                        showError();
                    }
                }
            }, 1000);
        }
    });
}
Also used : Context(android.content.Context) ByBannerViewHolder(me.jingbin.banner.holder.ByBannerViewHolder) ImageView(android.widget.ImageView) View(android.view.View) GankIoDataBean(com.example.jingbin.cloudreader.bean.GankIoDataBean) ImageView(android.widget.ImageView)

Aggregations

Context (android.content.Context)2 View (android.view.View)2 ImageView (android.widget.ImageView)2 ByBannerViewHolder (me.jingbin.banner.holder.ByBannerViewHolder)2 AndroidBean (com.example.jingbin.cloudreader.bean.AndroidBean)1 GankIoDataBean (com.example.jingbin.cloudreader.bean.GankIoDataBean)1 EverydayViewModel (com.example.jingbin.cloudreader.viewmodel.gank.EverydayViewModel)1 ArrayList (java.util.ArrayList)1 OnBannerClickListener (me.jingbin.banner.config.OnBannerClickListener)1