public interface

DraggableItemAdapter

com.h6ah4i.android.widget.advrecyclerview.draggable.DraggableItemAdapter<T extends androidx.recyclerview.widget.RecyclerView.ViewHolder>

Summary

Public Methods
abstract boolean onCheckCanDrop(int draggingPosition, int dropPosition)
Called while dragging in order to check whether the dragging item can be dropped to the specified position.
abstract boolean onCheckCanStartDrag(T holder, int position, int x, int y)
Called when user is attempt to drag the item.
abstract ItemDraggableRange onGetItemDraggableRange(T holder, int position)
abstract void onItemDragFinished(int fromPosition, int toPosition, boolean result)
Callback method to be invoked when finished dragging an item.
abstract void onItemDragStarted(int position)
Callback method to be invoked when started dragging an item.
abstract void onMoveItem(int fromPosition, int toPosition)
Called when item is moved.

Public Methods

public abstract boolean onCheckCanDrop (int draggingPosition, int dropPosition)

Called while dragging in order to check whether the dragging item can be dropped to the specified position. NOTE: This method will be called when the checkCanDrop option is enabled by setCheckCanDropEnabled(boolean).

Parameters
draggingPosition The position of the currently dragging item.
dropPosition The position to check whether the dragging item can be dropped or not.
Returns
  • Whether can be dropped to the specified position.

public abstract boolean onCheckCanStartDrag (T holder, int position, int x, int y)

Called when user is attempt to drag the item.

Parameters
holder The ViewHolder which is associated to item user is attempt to start dragging.
position The position of the item within the adapter's data set.
x Touched X position. Relative from the itemView's top-left.
y Touched Y position. Relative from the itemView's top-left.
Returns
  • Whether can start dragging.

public abstract ItemDraggableRange onGetItemDraggableRange (T holder, int position)

Parameters
holder The ViewHolder which is associated to item user is attempt to start dragging.
position The position of the item within the adapter's data set.
Returns
  • null: no constraints (= new ItemDraggableRange(0, getItemCount() - 1)), otherwise: the range specified item can be drag-sortable.

public abstract void onItemDragFinished (int fromPosition, int toPosition, boolean result)

Callback method to be invoked when finished dragging an item. Call the notifyDataSetChanged() method in this callback to get the same behavior with v0.10.x or before.

Parameters
fromPosition Previous position of the item.
toPosition New position of the item.
result Indicates whether the dragging operation was succeeded.

public abstract void onItemDragStarted (int position)

Callback method to be invoked when started dragging an item. Call the notifyDataSetChanged() method in this callback to get the same behavior with v0.10.x or before.

Parameters
position The position of the item.

public abstract void onMoveItem (int fromPosition, int toPosition)

Called when item is moved. Should apply the move operation result to data set.

Parameters
fromPosition Previous position of the item.
toPosition New position of the item.