-
- All Implemented Interfaces:
-
com.airbnb.epoxy.BaseEpoxyTouchCallback,com.airbnb.epoxy.EpoxyDragCallback,com.airbnb.epoxy.EpoxySwipeCallback
public abstract class EpoxyModelTouchCallback<T extends EpoxyModel> extends EpoxyTouchHelperCallback implements EpoxyDragCallback<T>, EpoxySwipeCallback<T>
A wrapper around androidx.recyclerview.widget.ItemTouchHelper.Callback to enable easier touch support when working with Epoxy models.
For simplicity you can use EpoxyTouchHelper to set up touch handling via this class for you instead of using this class directly. However, you may choose to use this class directly with your own ItemTouchHelper if you need extra flexibility or customization.
-
-
Constructor Summary
Constructors Constructor Description EpoxyModelTouchCallback(EpoxyController controller, Class<T> targetModelClass)
-
Method Summary
Modifier and Type Method Description voidonModelMoved(int fromPosition, int toPosition, T modelBeingMoved, View itemView)Called after onDragStarted when the dragged view is dropped toa new position. voidonSwipeCompleted(T model, View itemView, int position, int direction)Called after onSwipeReleased if the swipe surpassed the threshold tobe considered a full swipe. voidonSwipeStarted(T model, View itemView, int adapterPosition)Called when the view switches from an idle state to a swiped state, as the user begins a swipeinteraction with it. voidonSwipeReleased(T model, View itemView)Called when the user has released their touch on the view. voidonDragStarted(T model, View itemView, int adapterPosition)Called when the view switches from an idle state to a dragged state, as the user begins a draginteraction with it. voidonDragReleased(T model, View itemView)Called after onDragStarted when the view being dragged isreleased. voidclearView(T model, View itemView)Called when the user interaction with a view is over and the view hascompleted its animation. voidonSwipeProgressChanged(T model, View itemView, float swipeProgress, Canvas canvas)Once a view has begun swiping with onSwipeStarted it willreceive this callback as the swipe distance changes. -
Methods inherited from class com.airbnb.epoxy.EpoxyTouchHelperCallback
canDropOver, chooseDropTarget, clearView, getMoveThreshold, getMovementFlags, getSwipeThreshold, onChildDraw, onChildDrawOver, onMove, onMoved, onSelectedChanged, onSwiped -
Methods inherited from class androidx.recyclerview.widget.ItemTouchHelper.Callback
canDropOver, chooseDropTarget, clearView, convertToAbsoluteDirection, convertToRelativeDirection, getAnimationDuration, getBoundingBoxMargin, getDefaultUIUtil, getMoveThreshold, getMovementFlags, getSwipeEscapeVelocity, getSwipeThreshold, getSwipeVelocityThreshold, interpolateOutOfBoundsScroll, isItemViewSwipeEnabled, isLongPressDragEnabled, makeFlag, makeMovementFlags, onChildDraw, onChildDrawOver, onMove, onMoved, onSelectedChanged, onSwiped -
Methods inherited from class com.airbnb.epoxy.BaseEpoxyTouchCallback
getMovementFlagsForModel -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
EpoxyModelTouchCallback
EpoxyModelTouchCallback(EpoxyController controller, Class<T> targetModelClass)
-
-
Method Detail
-
onModelMoved
void onModelMoved(int fromPosition, int toPosition, T modelBeingMoved, View itemView)
Called after onDragStarted when the dragged view is dropped toa new position. The EpoxyController will be updated automatically for you to reposition themodels and notify the RecyclerView of the change.
You MUST use this callback to modify your data backing the models to reflect the change.
The next callback in the drag lifecycle will be onDragStarted
- Parameters:
fromPosition- The adapter position that the model came fromtoPosition- The new adapter position of the modelmodelBeingMoved- The model representing the view that was moveditemView- The view that was moved
-
onSwipeCompleted
void onSwipeCompleted(T model, View itemView, int position, int direction)
Called after onSwipeReleased if the swipe surpassed the threshold tobe considered a full swipe. The view will now be animated off screen.
You MUST use this callback to remove this item from your backing data and request a modelupdate.
clearView will be called after this.
- Parameters:
model- The model representing the view that was being swipeditemView- The view that was being swipedposition- The adapter position of the modeldirection- The direction that the view was swiped.
-
onSwipeStarted
void onSwipeStarted(T model, View itemView, int adapterPosition)
Called when the view switches from an idle state to a swiped state, as the user begins a swipeinteraction with it. You can use this callback to modify the view to indicate it is beingswiped.
This is the first callback made in the lifecycle of a swipe event.
- Parameters:
model- The model representing the view that is being swipeditemView- The view that is being swipedadapterPosition- The adapter position of the model
-
onSwipeReleased
void onSwipeReleased(T model, View itemView)
Called when the user has released their touch on the view. If the displacement passed the swipethreshold then onSwipeCompleted will be called after thisand the view will be animated off screen. Otherwise the view will animate back to its originalposition.
- Parameters:
model- The model representing the view that was being swipeditemView- The view that was being swiped
-
onDragStarted
void onDragStarted(T model, View itemView, int adapterPosition)
Called when the view switches from an idle state to a dragged state, as the user begins a draginteraction with it. You can use this callback to modify the view to indicate it is beingdragged.
This is the first callback in the lifecycle of a drag event.
- Parameters:
model- The model representing the view that is being draggeditemView- The view that is being draggedadapterPosition- The adapter position of the model
-
onDragReleased
void onDragReleased(T model, View itemView)
Called after onDragStarted when the view being dragged isreleased. If the view was dragged to a new, valid location then onModelMoved will be called before this and the view will settle to the new location.Otherwise the view will animate back to its original position.
You can use this callback to modify the view as it animates back into position.
clearView will be called after this, when theview has finished animating. Final cleanup of the view should be done there.
- Parameters:
model- The model representing the view that is being releaseditemView- The view that was being dragged
-
clearView
void clearView(T model, View itemView)
Called when the user interaction with a view is over and the view hascompleted its animation. This is a good place to clear all changes on the view that were donein other previous touch callbacks (such as on touch start, change, release, etc).
This is the last callback in the lifecycle of a touch event.
- Parameters:
model- The model whose view is being cleared.itemView- The view being cleared.
-
onSwipeProgressChanged
void onSwipeProgressChanged(T model, View itemView, float swipeProgress, Canvas canvas)
Once a view has begun swiping with onSwipeStarted it willreceive this callback as the swipe distance changes. This can be called multiple times as theswipe interaction progresses.
- Parameters:
model- The model representing the view that is being swipeditemView- The view that is being swipedswipeProgress- A float from -1 to 1 representing the percentage that the view has beenswiped relative to its width.canvas- The canvas on which RecyclerView is drawing its children.
-
-
-
-