Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Grid Mode):keep the data in adapter synchronized with the view when moving items in grid mode #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package co.paulburke.android.itemtouchhelperdemo;

import android.content.Context;

import co.paulburke.android.itemtouchhelperdemo.helper.OnStartDragListener;

/**
* Date: 2016-03-17
* Time: 21:08
* Author: cf
* -----------------------------
*/
public class RecyclerGridAdapter extends RecyclerListAdapter {

public RecyclerGridAdapter(Context context, OnStartDragListener dragStartListener) {
super(context, dragStartListener);
}

@Override
public boolean onItemMove(int fromPosition, int toPosition) {
String str = mItems.get(fromPosition);
mItems.remove(fromPosition);
mItems.add(toPosition, str);

notifyItemMoved(fromPosition, toPosition);
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

final RecyclerListAdapter adapter = new RecyclerListAdapter(getActivity(), this);
final RecyclerGridAdapter adapter = new RecyclerGridAdapter(getActivity(), this);

RecyclerView recyclerView = (RecyclerView) view;
recyclerView.setHasFixedSize(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
public class RecyclerListAdapter extends RecyclerView.Adapter<RecyclerListAdapter.ItemViewHolder>
implements ItemTouchHelperAdapter {

private final List<String> mItems = new ArrayList<>();
protected final List<String> mItems = new ArrayList<>();

private final OnStartDragListener mDragStartListener;

Expand Down