-
- All Implemented Interfaces:
-
eu.davidea.flexibleadapter.FlexibleAdapter.OnDeleteCompleteListener
public class UndoHelper extends Snackbar.Callback implements FlexibleAdapter.OnDeleteCompleteListenerHelper Class to simplify the Undo operation with FlexibleAdapter.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public @interfaceUndoHelper.ActionAnnotation interface for Undo actions.
public interfaceUndoHelper.OnActionListener
-
Field Summary
Fields Modifier and Type Field Description public final static intUNDO_TIMEOUT
-
Constructor Summary
Constructors Constructor Description UndoHelper(FlexibleAdapter adapter, UndoHelper.OnActionListener undoListener)Default constructor.
-
Method Summary
Modifier and Type Method Description UndoHelperwithPayload(Object payload)Sets the payload to inform other linked items about the change in action. UndoHelperwithAction(int action)By default REMOVE is performed. UndoHelperwithActionTextColor(@ColorInt() int color)Sets the text color of the action. UndoHelperwithConsecutive(boolean consecutive)Allows to commit previous action before next consecutive Undo request. Snackbarstart(List<Integer> positions, @NonNull() View mainView, @StringRes() int messageStringResId, @StringRes() int actionStringResId, @IntRange(from = -1) int duration)As start but with Stringresources instead of CharSequence. Snackbarstart(List<Integer> positions, @NonNull() View mainView, CharSequence message, CharSequence actionText, @IntRange(from = -1) int duration)Performs the action on the specified positions and displays a SnackBar to Undothe operation. voidonDeleteConfirmed(int event)Note: This method is also invoked by filterItems before applying the filter. voidonDismissed(Snackbar snackbar, int event)voidonShown(Snackbar snackbar)-
Methods inherited from class com.google.android.material.snackbar.Snackbar.Callback
onDismissed, onShown -
Methods inherited from class eu.davidea.flexibleadapter.FlexibleAdapter.OnDeleteCompleteListener
onDeleteConfirmed -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
UndoHelper
UndoHelper(FlexibleAdapter adapter, UndoHelper.OnActionListener undoListener)
Default constructor.- Parameters:
adapter- the instance of{@code FlexibleAdapter}undoListener- the callback for the Undo and Delete confirmation
-
-
Method Detail
-
withPayload
UndoHelper withPayload(Object payload)
Sets the payload to inform other linked items about the change in action.
- Parameters:
payload- any non-null user object to notify the parent (the payload will betherefore passed to the bind method of the parent ViewHolder),pass null to not notify the parent
-
withAction
UndoHelper withAction(int action)
By default REMOVE is performed.
-
withActionTextColor
UndoHelper withActionTextColor(@ColorInt() int color)
Sets the text color of the action.
- Parameters:
color- the color for the action button
-
withConsecutive
UndoHelper withConsecutive(boolean consecutive)
Allows to commit previous action before next consecutive Undo request.
Default value is
{@code false}(accumulate items).- Parameters:
consecutive- true to commit deletion at each Undo request to undo last action,false to accumulate the deleted items and Undo all in one shot.
-
start
Snackbar start(List<Integer> positions, @NonNull() View mainView, @StringRes() int messageStringResId, @StringRes() int actionStringResId, @IntRange(from = -1) int duration)
As start but with Stringresources instead of CharSequence.
-
start
Snackbar start(List<Integer> positions, @NonNull() View mainView, CharSequence message, CharSequence actionText, @IntRange(from = -1) int duration)
Performs the action on the specified positions and displays a SnackBar to Undothe operation. To customize the UPDATE event, please set a custom listener with withAction method.
By default the DELETE action will be performed.
- Parameters:
positions- the position to delete or updatemainView- the view to find a parent frommessage- the text to show.actionText- the action text to displayduration- How long to display the message.
-
onDeleteConfirmed
void onDeleteConfirmed(int event)
Note: This method is also invoked by filterItems before applying the filter.
-
onDismissed
void onDismissed(Snackbar snackbar, int event)
-
onShown
void onShown(Snackbar snackbar)
-
-
-
-