Search in sources :

Example 1 with ItemCollectLinkBinding

use of com.example.jingbin.cloudreader.databinding.ItemCollectLinkBinding 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)

Aggregations

Activity (android.app.Activity)1 View (android.view.View)1 AlertDialog (androidx.appcompat.app.AlertDialog)1 R (com.example.jingbin.cloudreader.R)1 CollectUrlBean (com.example.jingbin.cloudreader.bean.CollectUrlBean)1 CollectModel (com.example.jingbin.cloudreader.data.model.CollectModel)1 ItemCollectLinkBinding (com.example.jingbin.cloudreader.databinding.ItemCollectLinkBinding)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 BaseBindingAdapter (me.jingbin.bymvvm.adapter.BaseBindingAdapter)1 BaseBindingHolder (me.jingbin.bymvvm.adapter.BaseBindingHolder)1