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;
}
});
}
}
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));
}
}
});
}
Aggregations