Search in sources :

Example 1 with BaseBindingHolder

use of me.jingbin.bymvvm.adapter.BaseBindingHolder in project CloudReader by youlookwhat.

the class CollectUrlAdapter method bindView.

@Override
protected void bindView(BaseBindingHolder holder, CollectUrlBean.DataBean bean, ItemCollectLinkBinding binding, int position) {
    if (bean != null) {
        binding.setBean(bean);
        binding.setAdapter(CollectUrlAdapter.this);
        binding.rlItemLink.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {
                String[] items = { "编辑", "删除" };
                AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext());
                builder.setItems(items, (dialog, which) -> {
                    switch(which) {
                        case 0:
                            DialogBuild.show(v, bean.getName(), bean.getLink(), (DialogBuild.OnEditClickListener) (name, link) -> {
                                if (model == null) {
                                    model = new CollectModel();
                                }
                                model.updateUrl(bean.getId(), name, link, new WanNavigator.OnCollectNavigator() {

                                    @Override
                                    public void onSuccess() {
                                        bean.setName(name);
                                        bean.setLink(link);
                                        refreshNotifyItemChanged(position);
                                    }

                                    @Override
                                    public void onFailure() {
                                        ToastUtil.showToastLong("编辑失败");
                                    }
                                });
                            });
                            break;
                        case 1:
                            if (model == null) {
                                model = new CollectModel();
                            }
                            model.unCollectUrl(bean.getId(), new WanNavigator.OnCollectNavigator() {

                                @Override
                                public void onSuccess() {
                                    int indexOf = getData().indexOf(bean);
                                    // 移除数据增加删除动画
                                    getData().remove(indexOf);
                                    refreshNotifyItemRemoved(indexOf);
                                }

                                @Override
                                public void onFailure() {
                                    ToastUtil.showToastLong("删除失败");
                                }
                            });
                            break;
                        default:
                            break;
                    }
                });
                builder.show();
                return true;
            }
        });
    }
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) AlertDialog(androidx.appcompat.app.AlertDialog) BaseBindingAdapter(me.jingbin.bymvvm.adapter.BaseBindingAdapter) ToastUtil(com.example.jingbin.cloudreader.utils.ToastUtil) BaseBindingHolder(me.jingbin.bymvvm.adapter.BaseBindingHolder) CollectModel(com.example.jingbin.cloudreader.data.model.CollectModel) CollectUrlBean(com.example.jingbin.cloudreader.bean.CollectUrlBean) R(com.example.jingbin.cloudreader.R) WebViewActivity(com.example.jingbin.cloudreader.ui.WebViewActivity) ItemCollectLinkBinding(com.example.jingbin.cloudreader.databinding.ItemCollectLinkBinding) WanNavigator(com.example.jingbin.cloudreader.viewmodel.wan.WanNavigator) View(android.view.View) DialogBuild(com.example.jingbin.cloudreader.utils.DialogBuild) Activity(android.app.Activity) View(android.view.View) WanNavigator(com.example.jingbin.cloudreader.viewmodel.wan.WanNavigator) CollectModel(com.example.jingbin.cloudreader.data.model.CollectModel)

Example 2 with BaseBindingHolder

use of me.jingbin.bymvvm.adapter.BaseBindingHolder in project CloudReader by youlookwhat.

the class WelfareFragment method initRecycleView.

private void initRecycleView() {
    int width = (DensityUtil.getDisplayWidth() - 36) / 2;
    mWelfareAdapter = new BaseBindingAdapter<GankIoDataBean.ResultBean, ItemWelfareBinding>(R.layout.item_welfare) {

        @Override
        protected void bindView(BaseBindingHolder holder, GankIoDataBean.ResultBean bean, ItemWelfareBinding binding, int position) {
            DensityUtil.setWidthHeight(binding.ivWelfare, width, 852 / 1280f);
            DensityUtil.setWidthHeight(binding.viewMask, width, 852 / 1280f);
            binding.setBean(bean);
        }
    };
    RefreshHelper.initStaggeredGrid(bindingView.xrvWelfare, 2, 12);
    bindingView.xrvWelfare.setAdapter(mWelfareAdapter);
    bindingView.xrvWelfare.setOnLoadMoreListener(new ByRecyclerView.OnLoadMoreListener() {

        @Override
        public void onLoadMore() {
            int page = viewModel.getPage();
            page++;
            viewModel.setPage(page);
            loadWelfareData();
        }
    }, 300);
    bindingView.xrvWelfare.setOnItemClickListener(new OnItemFilterClickListener() {

        @Override
        public void onSingleClick(View v, int position) {
            ViewBigImageActivity.startImageList(getContext(), position, imgList, imgTitleList);
        }
    });
    viewModel.getImageAndTitle().observe(getViewLifecycleOwner(), new Observer<ArrayList<ArrayList<String>>>() {

        @Override
        public void onChanged(@Nullable ArrayList<ArrayList<String>> arrayLists) {
            if (arrayLists != null && arrayLists.size() == 2) {
                imgList.addAll(arrayLists.get(0));
                imgTitleList.addAll(arrayLists.get(1));
            }
        }
    });
}
Also used : ByRecyclerView(me.jingbin.library.ByRecyclerView) OnItemFilterClickListener(me.jingbin.library.view.OnItemFilterClickListener) ArrayList(java.util.ArrayList) ByRecyclerView(me.jingbin.library.ByRecyclerView) View(android.view.View) GankIoDataBean(com.example.jingbin.cloudreader.bean.GankIoDataBean) ItemWelfareBinding(com.example.jingbin.cloudreader.databinding.ItemWelfareBinding) BaseBindingHolder(me.jingbin.bymvvm.adapter.BaseBindingHolder)

Aggregations

View (android.view.View)2 BaseBindingHolder (me.jingbin.bymvvm.adapter.BaseBindingHolder)2 Activity (android.app.Activity)1 AlertDialog (androidx.appcompat.app.AlertDialog)1 R (com.example.jingbin.cloudreader.R)1 CollectUrlBean (com.example.jingbin.cloudreader.bean.CollectUrlBean)1 GankIoDataBean (com.example.jingbin.cloudreader.bean.GankIoDataBean)1 CollectModel (com.example.jingbin.cloudreader.data.model.CollectModel)1 ItemCollectLinkBinding (com.example.jingbin.cloudreader.databinding.ItemCollectLinkBinding)1 ItemWelfareBinding (com.example.jingbin.cloudreader.databinding.ItemWelfareBinding)1 WebViewActivity (com.example.jingbin.cloudreader.ui.WebViewActivity)1 DialogBuild (com.example.jingbin.cloudreader.utils.DialogBuild)1 ToastUtil (com.example.jingbin.cloudreader.utils.ToastUtil)1 WanNavigator (com.example.jingbin.cloudreader.viewmodel.wan.WanNavigator)1 ArrayList (java.util.ArrayList)1 BaseBindingAdapter (me.jingbin.bymvvm.adapter.BaseBindingAdapter)1 ByRecyclerView (me.jingbin.library.ByRecyclerView)1 OnItemFilterClickListener (me.jingbin.library.view.OnItemFilterClickListener)1