-
- All Implemented Interfaces:
-
eu.davidea.fastscroller.FastScroller.AdapterInterface,eu.davidea.fastscroller.FastScroller.BubbleTextCreator,eu.davidea.fastscroller.FastScroller.OnScrollStateChangeListener
public abstract class SelectableAdapter extends RecyclerView.Adapter implements FastScroller.BubbleTextCreator, FastScroller.OnScrollStateChangeListener, FastScroller.AdapterInterface
This class provides a set of standard methods to handle the selection on the items of an Adapter.
Also it manages the FastScroller.
This class is extended by AnimatorAdapter.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public @interfaceSelectableAdapter.ModeAnnotation interface for selection modes: IDLE, SINGLE, MULTI
-
Constructor Summary
Constructors Constructor Description SelectableAdapter()
-
Method Summary
Modifier and Type Method Description static voidenableLogs(int level)Call this once, to enable or disable internal logs with custom level. static voiduseTag(String tag)voidonAttachedToRecyclerView(@NonNull() RecyclerView recyclerView)Attaches the {@code FastScrollerDelegate}to the RecyclerView if necessary.voidonDetachedFromRecyclerView(@NonNull() RecyclerView recyclerView)Detaches the {@code FastScrollerDelegate}from the RecyclerView if necessary.RecyclerViewgetRecyclerView()IFlexibleLayoutManagergetFlexibleLayoutManager()Current instance of the wrapper class for LayoutManager suitable for FlexibleAdapter.LayoutManager must be already initialized in the RecyclerView. voidsetFlexibleLayoutManager(IFlexibleLayoutManager flexibleLayoutManager)Allow to use a custom LayoutManager. intgetMode()The current selection mode of the Adapter. voidsetMode(int mode)Sets the mode of the selection: booleanisSelectAll()booleanisLastItemInActionMode()booleanisSelected(int position)Indicates if the item, at the provided position, is selected. abstract booleanisSelectable(int position)Checks if the current item has the property {@code selectable = true}.voidtoggleSelection(int position)Toggles the selection status of the item at a given position. final booleanaddSelection(int position)Adds the selection status for the given position without notifying the change. final booleanremoveSelection(int position)Removes the selection status for the given position without notifying the change. voidselectAll(Array<Integer> viewTypes)Sets the selection status for all items which the ViewTypes are included in the specified array. voidclearSelection()Clears the selection status for all items one by one and it doesn't stop animations in the items. voidonBindViewHolder(@NonNull() RecyclerView.ViewHolder holder, int position, @NonNull() List payloads)voidonViewRecycled(@NonNull() RecyclerView.ViewHolder holder)Set<FlexibleViewHolder>getAllBoundViewHolders()Usually {@code RecyclerView}binds 3 items more than the visible items.intgetSelectedItemCount()Counts the selected items. List<Integer>getSelectedPositions()Retrieves the list of selected items. Set<Integer>getSelectedPositionsAsSet()Retrieves the set of selected items. voidonSaveInstanceState(Bundle outState)Saves the state of the current selection on the items. voidonRestoreInstanceState(Bundle savedInstanceState)Restores the previous state of the selection on the items. voidtoggleFastScroller()Displays or Hides the FastScroller if previously configured. booleanisFastScrollerEnabled()FastScrollergetFastScroller()voidsetFastScroller(@Nullable() FastScroller fastScroller)Sets up the FastScroller with automatic fetch of accent color. StringonCreateBubbleText(int position)voidonFastScrollerStateChange(boolean scrolling)Triggered when FastScroller State is changed. -
Methods inherited from class androidx.recyclerview.widget.RecyclerView.Adapter
bindViewHolder, createViewHolder, findRelativeAdapterPositionIn, getItemCount, getItemId, getItemViewType, getStateRestorationPolicy, hasObservers, hasStableIds, notifyDataSetChanged, notifyItemChanged, notifyItemInserted, notifyItemMoved, notifyItemRangeChanged, notifyItemRangeInserted, notifyItemRangeRemoved, notifyItemRemoved, onAttachedToRecyclerView, onBindViewHolder, onCreateViewHolder, onDetachedFromRecyclerView, onFailedToRecycleView, onViewAttachedToWindow, onViewDetachedFromWindow, onViewRecycled, registerAdapterDataObserver, setHasStableIds, setStateRestorationPolicy, unregisterAdapterDataObserver -
Methods inherited from class eu.davidea.fastscroller.FastScroller.AdapterInterface
setFastScroller -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Method Detail
-
enableLogs
static void enableLogs(int level)
Call this once, to enable or disable internal logs with custom level.Logs are disabled by default.
- Parameters:
level- One of Level value
-
onAttachedToRecyclerView
void onAttachedToRecyclerView(@NonNull() RecyclerView recyclerView)
Attaches the
{@code FastScrollerDelegate}to the RecyclerView if necessary.
-
onDetachedFromRecyclerView
void onDetachedFromRecyclerView(@NonNull() RecyclerView recyclerView)
Detaches the
{@code FastScrollerDelegate}from the RecyclerView if necessary.
-
getRecyclerView
RecyclerView getRecyclerView()
-
getFlexibleLayoutManager
IFlexibleLayoutManager getFlexibleLayoutManager()
Current instance of the wrapper class for LayoutManager suitable for FlexibleAdapter.LayoutManager must be already initialized in the RecyclerView.
return wrapper class for any non-conventional LayoutManagers or
{@code null}if not initialized.
-
setFlexibleLayoutManager
void setFlexibleLayoutManager(IFlexibleLayoutManager flexibleLayoutManager)
Allow to use a custom LayoutManager.
- Parameters:
flexibleLayoutManager- the custom LayoutManager suitable for FlexibleAdapter
-
getMode
int getMode()
The current selection mode of the Adapter.
-
setMode
void setMode(int mode)
Sets the mode of the selection:
-
isSelectAll
boolean isSelectAll()
-
isLastItemInActionMode
boolean isLastItemInActionMode()
-
isSelected
boolean isSelected(int position)
Indicates if the item, at the provided position, is selected.
- Parameters:
position- Position of the item to check.
-
isSelectable
abstract boolean isSelectable(int position)
Checks if the current item has the property
{@code selectable = true}.- Parameters:
position- the current position of the item to check
-
toggleSelection
void toggleSelection(int position)
Toggles the selection status of the item at a given position.
The behaviour depends on the selection mode previously set with setMode.
The Activated State of the ItemView is automatically set in toggleActivation called in{@code onClick}eventUsage:
- If you don't want any item to be selected/activated at all, just don't call this method.
- To have actually the item visually selected you need to add a custom Selector Drawableto the background of the View, via
{@code DrawableUtils}or via layout's item:android:background="?attr/selectableItemBackground", pointing to a custom Drawablein the style.xml (note: prefix ?android:attrdoesn't work).
- Parameters:
position- Position of the item to toggle the selection status for.
-
addSelection
final boolean addSelection(int position)
Adds the selection status for the given position without notifying the change.
- Parameters:
position- Position of the item to add the selection status for.
-
removeSelection
final boolean removeSelection(int position)
Removes the selection status for the given position without notifying the change.
- Parameters:
position- Position of the item to remove the selection status for.
-
selectAll
void selectAll(Array<Integer> viewTypes)
Sets the selection status for all items which the ViewTypes are included in the specified array.
- Parameters:
viewTypes- The ViewTypes for which we want the selection, pass nothing to select all
-
clearSelection
void clearSelection()
Clears the selection status for all items one by one and it doesn't stop animations in the items.
Note 1: Items are not rebound, so an eventual animation is not stopped!Note 2: This method use
{@code java.util.Iterator}on synchronized collection toavoid{@code java.util.ConcurrentModificationException}.
-
onBindViewHolder
void onBindViewHolder(@NonNull() RecyclerView.ViewHolder holder, int position, @NonNull() List payloads)
-
onViewRecycled
void onViewRecycled(@NonNull() RecyclerView.ViewHolder holder)
-
getAllBoundViewHolders
Set<FlexibleViewHolder> getAllBoundViewHolders()
Usually
{@code RecyclerView}binds 3 items more than the visible items.
-
getSelectedItemCount
int getSelectedItemCount()
Counts the selected items.
-
getSelectedPositions
List<Integer> getSelectedPositions()
Retrieves the list of selected items.
The list is a copy and it's sorted.
-
getSelectedPositionsAsSet
Set<Integer> getSelectedPositionsAsSet()
Retrieves the set of selected items.
The set is sorted.
-
onSaveInstanceState
void onSaveInstanceState(Bundle outState)
Saves the state of the current selection on the items.
- Parameters:
outState- Current state
-
onRestoreInstanceState
void onRestoreInstanceState(Bundle savedInstanceState)
Restores the previous state of the selection on the items.
- Parameters:
savedInstanceState- Previous state
-
toggleFastScroller
void toggleFastScroller()
Displays or Hides the FastScroller if previously configured.The action is animated.
-
isFastScrollerEnabled
boolean isFastScrollerEnabled()
-
getFastScroller
@Nullable() FastScroller getFastScroller()
-
setFastScroller
void setFastScroller(@Nullable() FastScroller fastScroller)
Sets up the FastScroller with automatic fetch of accent color.
IMPORTANT: Call this method after the adapter is added to the RecyclerView.
NOTE: If the device has at least Lollipop, the Accent color is fetched, otherwisefor previous version, the default value is used.- Parameters:
fastScroller- instance of FastScroller
-
onCreateBubbleText
String onCreateBubbleText(int position)
- Parameters:
position- the position of the handle
-
onFastScrollerStateChange
void onFastScrollerStateChange(boolean scrolling)
Triggered when FastScroller State is changed.
- Parameters:
scrolling- true if the user is actively scrolling, false when idle
-
-
-
-