Package 

Class UndoHelper

  • All Implemented Interfaces:
    eu.davidea.flexibleadapter.FlexibleAdapter.OnDeleteCompleteListener

    
    public class UndoHelper
    extends Snackbar.Callback implements FlexibleAdapter.OnDeleteCompleteListener
                        

    Helper Class to simplify the Undo operation with FlexibleAdapter.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      public final static int UNDO_TIMEOUT
    • Method Summary

      Modifier and Type Method Description
      UndoHelper withPayload(Object payload) Sets the payload to inform other linked items about the change in action.
      UndoHelper withAction(int action) By default REMOVE is performed.
      UndoHelper withActionTextColor(@ColorInt() int color) Sets the text color of the action.
      UndoHelper withConsecutive(boolean consecutive) Allows to commit previous action before next consecutive Undo request.
      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.
      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.
      void onDeleteConfirmed(int event) Note: This method is also invoked by filterItems before applying the filter.
      void onDismissed(Snackbar snackbar, int event)
      void onShown(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
      • 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, 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 update
        mainView - the view to find a parent from
        message - the text to show.
        actionText - the action text to display
        duration - 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)