use of com.codeest.geeknews.widget.DefaultItemTouchHelpCallback in project GeekNews by codeestX.
the class LikeFragment method initEventAndData.
@Override
protected void initEventAndData() {
mList = new ArrayList<>();
mAdapter = new LikeAdapter(mContext, mList);
rvLikeList.setLayoutManager(new LinearLayoutManager(mContext));
rvLikeList.setAdapter(mAdapter);
mCallback = new DefaultItemTouchHelpCallback(new DefaultItemTouchHelpCallback.OnItemTouchCallbackListener() {
@Override
public void onSwiped(int adapterPosition) {
// 滑动删除的时候,从数据库、数据源移除,并刷新UI
if (mList != null) {
mPresenter.deleteLikeData(mList.get(adapterPosition).getId());
mList.remove(adapterPosition);
mAdapter.notifyItemRemoved(adapterPosition);
}
}
@Override
public boolean onMove(int srcPosition, int targetPosition) {
if (mList != null) {
// 更换数据库中的数据Item的位置
boolean isPlus = srcPosition < targetPosition;
mPresenter.changeLikeTime(mList.get(srcPosition).getId(), mList.get(targetPosition).getTime(), isPlus);
// 更换数据源中的数据Item的位置
Collections.swap(mList, srcPosition, targetPosition);
// 更新UI中的Item的位置,主要是给用户看到交互效果
mAdapter.notifyItemMoved(srcPosition, targetPosition);
return true;
}
return false;
}
});
mCallback.setDragEnable(true);
mCallback.setSwipeEnable(true);
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(mCallback);
itemTouchHelper.attachToRecyclerView(rvLikeList);
mPresenter.getLikeData();
}
use of com.codeest.geeknews.widget.DefaultItemTouchHelpCallback in project GeekNews by codeestX.
the class GoldManagerActivity method initEventAndData.
@Override
protected void initEventAndData() {
setToolBar(toolBar, "首页特别展示");
mList = ((GoldManagerBean) getIntent().getParcelableExtra(Constants.IT_GOLD_MANAGER)).getManagerList();
mAdapter = new GoldManagerAdapter(mContext, mList);
rvGoldManagerList.setLayoutManager(new LinearLayoutManager(mContext));
rvGoldManagerList.setAdapter(mAdapter);
mCallback = new DefaultItemTouchHelpCallback(new DefaultItemTouchHelpCallback.OnItemTouchCallbackListener() {
@Override
public void onSwiped(int adapterPosition) {
}
@Override
public boolean onMove(int srcPosition, int targetPosition) {
if (mList != null) {
Collections.swap(mList, srcPosition, targetPosition);
mAdapter.notifyItemMoved(srcPosition, targetPosition);
return true;
}
return false;
}
});
mCallback.setDragEnable(true);
mCallback.setSwipeEnable(false);
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(mCallback);
itemTouchHelper.attachToRecyclerView(rvGoldManagerList);
}
Aggregations