use of com.example.jingbin.cloudreader.adapter.JokeAdapter in project CloudReader by youlookwhat.
the class JokeFragment method initRefreshView.
private void initRefreshView() {
RefreshHelper.initLinear(bindingView.xrvWan, true).setItemAnimator(new DefaultItemAnimator());
RefreshHelper.setSwipeRefreshView(bindingView.srlWan);
mAdapter = new JokeAdapter();
bindingView.xrvWan.setAdapter(mAdapter);
bindingView.srlWan.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
bindingView.srlWan.postDelayed(() -> {
viewModel.setRefreshBK(true);
viewModel.setPage(new Random().nextInt(100));
viewModel.showQSBKList();
}, 100);
}
});
bindingView.xrvWan.setOnLoadMoreListener(new ByRecyclerView.OnLoadMoreListener() {
@Override
public void onLoadMore() {
int page = viewModel.getPage();
viewModel.setPage(++page);
viewModel.setRefreshBK(false);
viewModel.showQSBKList();
}
});
bindingView.xrvWan.setOnItemLongClickListener(new ByRecyclerView.OnItemLongClickListener() {
@Override
public boolean onLongClick(View v, int position) {
DialogBuild.showItems(v, mAdapter.getItemData(position).getContent());
return false;
}
});
viewModel.getData().observe(this, new Observer<List<DuanZiBean>>() {
@Override
public void onChanged(@Nullable List<DuanZiBean> duanZiBeans) {
showContentView();
if (bindingView.srlWan.isRefreshing()) {
bindingView.srlWan.setRefreshing(false);
}
if (duanZiBeans != null && duanZiBeans.size() > 0) {
if (viewModel.isRefreshBK()) {
mAdapter.setNewData(duanZiBeans);
} else {
mAdapter.addData(duanZiBeans);
bindingView.xrvWan.loadMoreComplete();
}
} else {
if (!viewModel.isRefreshBK()) {
showError();
} else {
bindingView.xrvWan.loadMoreComplete();
}
}
}
});
}
Aggregations