use of com.example.jingbin.cloudreader.data.model.CollectModel 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;
}
});
}
}
Aggregations