Package 

Class ActionModeHelper

  • All Implemented Interfaces:
    androidx.appcompat.view.ActionMode.Callback

    
    public class ActionModeHelper
     implements ActionMode.Callback
                        

    Helper Class to coordinate the MULTI selection with FlexibleAdapter.

    • Constructor Detail

      • ActionModeHelper

        ActionModeHelper(FlexibleAdapter adapter, int cabMenu)
        Default constructor with internal callback.
        Parameters:
        adapter - the FlexibleAdapter instance
        cabMenu - the Contextual Action Bar menu resourceId
      • ActionModeHelper

        ActionModeHelper(FlexibleAdapter adapter, int cabMenu, ActionMode.Callback callback)
        Constructor with internal callback + custom callback.
        Parameters:
        adapter - the FlexibleAdapter instance
        cabMenu - the Contextual Action Bar menu resourceId
        callback - the custom androidx.appcompat.view.ActionMode.Callback
    • Method Detail

      • withDefaultMode

         final ActionModeHelper withDefaultMode(int defaultMode)

        Changes the default mode to apply when the ActionMode is destroyed and normal selection isagain active.

        Default value is IDLE.

        Parameters:
        defaultMode - the new default mode when ActionMode is off, accepted values:{@code IDLE, SINGLE}
      • disableDragOnActionMode

         final ActionModeHelper disableDragOnActionMode(boolean disableDrag)

        Automatically disables LongPress drag and Handle drag capability when ActionMode isactivated and enable it again when ActionMode is destroyed.

        Parameters:
        disableDrag - true to disable the drag, false to maintain the drag during ActionMode
      • disableSwipeOnActionMode

         final ActionModeHelper disableSwipeOnActionMode(boolean disableSwipe)

        Automatically disables Swipe capability when ActionMode is activated and enable it againwhen ActionMode is destroyed.

        Parameters:
        disableSwipe - true to disable the swipe, false to maintain the swipe during ActionMode
      • getActivatedPosition

         int getActivatedPosition()

        Gets the activated position only when mode is {@code SINGLE}.

      • onClick

         boolean onClick(int position)

        Implements the basic behavior of a CAB and multi select behavior.

        Parameters:
        position - the current item position
      • onLongClick

        @NonNull() ActionMode onLongClick(AppCompatActivity activity, int position)

        Implements the basic behavior of a CAB and multi select behavior onLongClick.

        Parameters:
        activity - the current Activity
        position - the position of the clicked item
      • toggleSelection

         void toggleSelection(int position)

        Toggle the selection state of an item.

        If the item was the last one in the selection and is unselected, the selection is stopped.Note that the selection must already be started (actionMode must not be null).

        Parameters:
        position - position of the item to toggle the selection state
      • updateContextTitle

         void updateContextTitle(int count)

        Updates the title of the Context Menu.

        Override to customize the title and subtitle.

        Parameters:
        count - the current number of selected items
      • restoreSelection

         void restoreSelection(AppCompatActivity activity)

        Helper method to restart the action mode after a restoration of deleted items and afterscreen rotation. The ActionMode will be activated only if getSelectedItemCount has selections.

        To be called in the {@code onUndo} method after the restoration is done or at the endof {@code onRestoreInstanceState}.

        Parameters:
        activity - the current Activity
      • destroyActionModeIfCan

         boolean destroyActionModeIfCan()

        Utility method to be called from Activity in many occasions such as: onBackPressed,onRefresh for SwipeRefreshLayout, after deleting all selected items.