Is it possible to have just some Items Swipeable?
I have many different types of items on my adapter, but someone them should not be swipeable. Is there a way to achieve that? Like the IDraggable?
@hsdmiranda you will have to extend the SimpleDragCallback and overwrite the getDragDirs method. https://github.com/mikepenz/FastAdapter/blob/develop/library-extensions/src/main/java/com/mikepenz/fastadapter_extensions/drag/SimpleDragCallback.java#L84
There you will not only check for IDraggable but you will also check if this item is really dragable, if not you will return 0.
@hsdmiranda Just wanted to ask, if you got it working.
@Rainer-Lang I did, but it wasn't so simple like was described.
@hsdmiranda I'm glad you did it. Could I ask for the solution? It's also nice to have here the solution if someone else is searching for the same. Thanks.
Sorry for the delay. This is what i did.
This class also contains something for drag and drop. I created a callback to notify when the item is actually dropped.
`
public class ImprovedSwipeDragCallback extends SimpleSwipeDragCallback {
private Integer mFrom = null;
private Integer mTo = null;
private ImprovedItemTouchCallback callback;
public ImprovedSwipeDragCallback(ImprovedItemTouchCallback itemTouchCallback, SimpleSwipeCallback.ItemSwipeCallback itemSwipeCallback, Drawable leaveBehindDrawable, int swipeDirs, @ColorInt int bgColor) {
super(itemTouchCallback, itemSwipeCallback, leaveBehindDrawable, swipeDirs, bgColor);
this.callback = itemTouchCallback;
}
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
if (target.itemView.getTag() instanceof IDraggable) {
if (((IDraggable) target.itemView.getTag()).isDraggable()) {
if (mFrom == null) {
mFrom = viewHolder.getAdapterPosition();
}
mTo = target.getAdapterPosition();
return super.onMove(recyclerView, viewHolder, target);
}
}
return false;
}
@Override
public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
if (recyclerView==null || viewHolder == null)
return super.getSwipeDirs(recyclerView,viewHolder);
if (viewHolder.itemView.getTag() instanceof IDraggable) {
if (((IDraggable) viewHolder.itemView.getTag()).isDraggable()) {
return super.getSwipeDirs(recyclerView,viewHolder);
} else {
return 0;
}
} else {
return 0;
}
}
@Override
public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
super.clearView(recyclerView, viewHolder);
if (mFrom != null && mTo != null) {
callback.onDrop(mFrom, mTo);
}
// clear saved positions
mFrom = mTo = null;
}
} `
@hsdmiranda Thanks. If you have a bit time, may I ask you to contribute to this great lib and make a sample?