public class FastAdapter<Item extends IItem>
extends android.support.v7.widget.RecyclerView.Adapter<android.support.v7.widget.RecyclerView.ViewHolder>
| Modifier and Type | Class and Description |
|---|---|
static interface |
FastAdapter.OnBindViewHolderListener |
class |
FastAdapter.OnBindViewHolderListenerImpl |
static interface |
FastAdapter.OnClickListener<Item extends IItem> |
static interface |
FastAdapter.OnCreateViewHolderListener |
class |
FastAdapter.OnCreateViewHolderListenerImpl
default implementation of the OnCreateViewHolderListener
|
static interface |
FastAdapter.OnLongClickListener<Item extends IItem> |
static interface |
FastAdapter.OnTouchListener<Item extends IItem> |
static class |
FastAdapter.RelativeInfo<Item extends IItem>
an internal class to return the IItem and relativePosition and its adapter at once.
|
| Modifier and Type | Field and Description |
|---|---|
protected static java.lang.String |
BUNDLE_EXPANDED |
protected static java.lang.String |
BUNDLE_SELECTIONS |
| Constructor and Description |
|---|
FastAdapter()
default CTOR
|
| Modifier and Type | Method and Description |
|---|---|
void |
clearTypeInstance()
clears the internal mapper - be sure, to remap everything before going on
|
void |
collapse()
collapses all expanded items
|
void |
collapse(boolean notifyItemChanged)
collapses all expanded items
|
void |
collapse(int position)
collapses (closes) the given collapsible item at the given position
|
void |
collapse(int position,
boolean notifyItemChanged)
collapses (closes) the given collapsible item at the given position
|
java.util.List<Item> |
deleteAllSelectedItems()
deletes all current selected items
|
void |
deselect()
deselects all selections
|
void |
deselect(int position)
deselects an item and removes its position in the selections list
|
void |
deselect(java.lang.Iterable<java.lang.Integer> positions)
deselects all items at the positions in the iteratable
|
FastAdapter<Item> |
enableVerboseLog()
enables the verbose log for the adapter
|
void |
expand()
expands all expandable items
|
void |
expand(boolean notifyItemChanged)
expands all expandable items
|
void |
expand(int position)
opens the expandable item at the given position
|
void |
expand(int position,
boolean notifyItemChanged)
opens the expandable item at the given position
|
IAdapter<Item> |
getAdapter(int position)
Gets the adapter for the given position
|
android.util.SparseIntArray |
getExpanded()
returns the expanded items this contains position and the count of items
which are expanded by this position
|
int[] |
getExpandedItems() |
int |
getExpandedItemsCount(int from,
int position)
calculates the count of expandable items before a given position
|
int |
getHolderAdapterPosition(android.support.v7.widget.RecyclerView.ViewHolder holder)
helper method to get the position from a holder
overwrite this if you have an adapter adding additional items inbetwean
|
Item |
getItem(int position)
gets the IItem by a position, from all registered adapters
|
int |
getItemCount()
calculates the total ItemCount over all registered adapters
|
long |
getItemId(int position)
finds the int ItemId from the IItem which exists at the given position
|
int |
getItemViewType(int position)
finds the int ItemViewType from the IItem which exists at the given position
|
int |
getPosition(Item item)
Searches for the given item and calculates its global position
|
int |
getPosition(long identifier)
Searches for the given item and calculates its global position
|
int |
getPreItemCount(int position)
calculates the item count up to a given (excluding this) adapter (defined by the global position of the item)
|
int |
getPreItemCountByOrder(int order)
calculates the item count up to a given (excluding this) order number
|
FastAdapter.RelativeInfo<Item> |
getRelativeInfo(int position)
Internal method to get the Item as ItemHolder which comes with the relative position within its adapter
Finds the responsible adapter for the given position
|
java.util.Set<Item> |
getSelectedItems() |
java.util.Set<java.lang.Integer> |
getSelections() |
Item |
getTypeInstance(int type)
gets the TypeInstance remembered within the FastAdapter for an item
|
boolean |
isOnlyOneExpandedItem() |
boolean |
isPositionBasedStateManagement() |
boolean |
isSelectable() |
void |
notifyAdapterDataSetChanged()
wraps notifyDataSetChanged
|
void |
notifyAdapterItemChanged(int position)
wraps notifyItemChanged
|
void |
notifyAdapterItemChanged(int position,
java.lang.Object payload)
wraps notifyItemChanged
|
void |
notifyAdapterItemInserted(int position)
wraps notifyItemInserted
|
void |
notifyAdapterItemMoved(int fromPosition,
int toPosition)
wraps notifyItemMoved
|
void |
notifyAdapterItemRangeChanged(int position,
int itemCount)
wraps notifyItemRangeChanged
|
void |
notifyAdapterItemRangeChanged(int position,
int itemCount,
java.lang.Object payload)
wraps notifyItemRangeChanged
|
void |
notifyAdapterItemRangeInserted(int position,
int itemCount)
wraps notifyItemRangeInserted
|
void |
notifyAdapterItemRangeRemoved(int position,
int itemCount)
wraps notifyItemRangeRemoved
|
void |
notifyAdapterItemRemoved(int position)
wraps notifyItemRemoved
|
void |
notifyAdapterSubItemsChanged(int position)
notifies the fastAdapter about new / removed items within a sub hierarchy
NOTE this currently only works for sub items with only 1 level
|
int |
notifyAdapterSubItemsChanged(int position,
int previousCount)
notifies the fastAdapter about new / removed items within a sub hierarchy
NOTE this currently only works for sub items with only 1 level
|
void |
onAttachedToRecyclerView(android.support.v7.widget.RecyclerView recyclerView) |
void |
onBindViewHolder(android.support.v7.widget.RecyclerView.ViewHolder holder,
int position)
Binds the data to the created ViewHolder and sets the listeners to the holder.itemView
Note that you should use the `onBindViewHolder(RecyclerView.ViewHolder holder, int position, List payloads`
as it allows you to implement a more efficient adapter implementation
|
void |
onBindViewHolder(android.support.v7.widget.RecyclerView.ViewHolder holder,
int position,
java.util.List<java.lang.Object> payloads)
Binds the data to the created ViewHolder and sets the listeners to the holder.itemView
|
android.support.v7.widget.RecyclerView.ViewHolder |
onCreateViewHolder(android.view.ViewGroup parent,
int viewType)
Creates the ViewHolder by the viewType
|
void |
onDetachedFromRecyclerView(android.support.v7.widget.RecyclerView recyclerView) |
boolean |
onFailedToRecycleView(android.support.v7.widget.RecyclerView.ViewHolder holder)
is called when the ViewHolder is in a transient state.
|
void |
onViewAttachedToWindow(android.support.v7.widget.RecyclerView.ViewHolder holder)
is called in onViewAttachedToWindow when the view is detached from the window
|
void |
onViewDetachedFromWindow(android.support.v7.widget.RecyclerView.ViewHolder holder)
is called in onViewDetachedFromWindow when the view is detached from the window
|
void |
onViewRecycled(android.support.v7.widget.RecyclerView.ViewHolder holder)
Unbinds the data to the already existing ViewHolder and removes the listeners from the holder.itemView
|
<A extends AbstractAdapter<Item>> |
registerAdapter(A adapter)
registers an AbstractAdapter which will be hooked into the adapter chain
|
void |
registerTypeInstance(Item item)
register a new type into the TypeInstances to be able to efficiently create thew ViewHolders
|
android.os.Bundle |
saveInstanceState(android.os.Bundle savedInstanceState)
add the values to the bundle for saveInstanceState
|
android.os.Bundle |
saveInstanceState(android.os.Bundle savedInstanceState,
java.lang.String prefix)
add the values to the bundle for saveInstanceState
|
void |
select()
select all items
|
void |
select(boolean considerSelectableFlag)
select all items
|
void |
select(int position)
selects an item and remembers its position in the selections list
|
void |
select(int position,
boolean fireEvent)
selects an item and remembers its position in the selections list
|
void |
select(int position,
boolean fireEvent,
boolean considerSelectableFlag)
selects an item and remembers its position in the selections list
|
void |
select(java.lang.Iterable<java.lang.Integer> positions)
selects all items at the positions in the iteratable
|
void |
toggleExpandable(int position)
toggles the expanded state of the given expandable item at the given position
|
void |
toggleSelection(int position)
toggles the selection of the item at the given position
|
FastAdapter<Item> |
withAllowDeselection(boolean allowDeselection)
If false, a user can't deselect an item via click (you can still do this programmatically)
|
FastAdapter<Item> |
withEventHook(EventHook<Item> eventHook)
adds a new event hook for an item
NOTE: this has to be called before adding the first items, as this won't be called anymore after the ViewHolders were created
|
FastAdapter<Item> |
withEventHooks(java.util.Collection<? extends EventHook<Item>> eventHooks)
adds new event hooks for an item
NOTE: this has to be called before adding the first items, as this won't be called anymore after the ViewHolders were created
|
FastAdapter<Item> |
withItemEvent(EventHook<Item> eventHook)
Deprecated.
please use `withEventHook`
|
FastAdapter<Item> |
withLegacyBindViewMode(boolean legacyBindViewMode)
set to true if you want the FastAdapter to forward all calls from onBindViewHolder(final RecyclerView.ViewHolder holder, int position) to onBindViewHolder(final RecyclerView.ViewHolder holder, int position, List payloads)
|
FastAdapter<Item> |
withMultiSelect(boolean multiSelect)
Enable this if you want multiSelection possible in the list
|
FastAdapter<Item> |
withOnBindViewHolderListener(FastAdapter.OnBindViewHolderListener onBindViewHolderListener)
allows you to set an custom OnBindViewHolderListener which is used to bind the view.
|
FastAdapter<Item> |
withOnClickListener(FastAdapter.OnClickListener<Item> onClickListener)
Define the OnClickListener which will be used for a single item
|
FastAdapter<Item> |
withOnCreateViewHolderListener(FastAdapter.OnCreateViewHolderListener onCreateViewHolderListener)
allows you to set a custom OnCreateViewHolderListener which will be used before and after the ViewHolder is created
You may check the OnCreateViewHolderListenerImpl for the default behavior
|
FastAdapter<Item> |
withOnLongClickListener(FastAdapter.OnLongClickListener<Item> onLongClickListener)
Define the OnLongClickListener which will be used for a single item
|
FastAdapter<Item> |
withOnlyOneExpandedItem(boolean mOnlyOneExpandedItem)
set if there should only be one opened expandable item
DEFAULT: false
|
FastAdapter<Item> |
withOnPreClickListener(FastAdapter.OnClickListener<Item> onPreClickListener)
Define the OnPreClickListener which will be used for a single item and is called after all internal methods are done
|
FastAdapter<Item> |
withOnPreLongClickListener(FastAdapter.OnLongClickListener<Item> onPreLongClickListener)
Define the OnLongClickListener which will be used for a single item and is called after all internal methods are done
|
FastAdapter<Item> |
withOnTouchListener(FastAdapter.OnTouchListener<Item> onTouchListener)
Define the TouchListener which will be used for a single item
|
FastAdapter<Item> |
withPositionBasedStateManagement(boolean mPositionBasedStateManagement)
set if we want to use the positionBasedStateManagement (high performant for lists up to Integer.MAX_INT)
set to false if you want to use the new stateManagement which will come with more flexibility (but worse performance on long lists)
|
FastAdapter<Item> |
withSavedInstanceState(android.os.Bundle savedInstanceState)
re-selects all elements stored in the savedInstanceState
IMPORTANT! Call this method only after all items where added to the adapters again.
|
FastAdapter<Item> |
withSavedInstanceState(android.os.Bundle savedInstanceState,
java.lang.String prefix)
re-selects all elements stored in the savedInstanceState
IMPORTANT! Call this method only after all items where added to the adapters again.
|
FastAdapter<Item> |
withSelectable(boolean selectable)
set if no item is selectable
|
FastAdapter<Item> |
withSelectionListener(ISelectionListener<Item> selectionListener)
set a listener that get's notified whenever an item is selected or deselected
|
FastAdapter<Item> |
withSelectOnLongClick(boolean selectOnLongClick)
Disable this if you want the selection on a single tap
|
FastAdapter<Item> |
withSelectWithItemUpdate(boolean selectWithItemUpdate)
select between the different selection behaviors.
|
bindViewHolder, createViewHolder, hasObservers, hasStableIds, notifyDataSetChanged, notifyItemChanged, notifyItemChanged, notifyItemInserted, notifyItemMoved, notifyItemRangeChanged, notifyItemRangeChanged, notifyItemRangeInserted, notifyItemRangeRemoved, notifyItemRemoved, registerAdapterDataObserver, setHasStableIds, unregisterAdapterDataObserverprotected static final java.lang.String BUNDLE_SELECTIONS
protected static final java.lang.String BUNDLE_EXPANDED
public FastAdapter<Item> enableVerboseLog()
@Deprecated public FastAdapter<Item> withItemEvent(EventHook<Item> eventHook)
eventHook - the event hook to be added for an itempublic FastAdapter<Item> withEventHook(EventHook<Item> eventHook)
eventHook - the event hook to be added for an itempublic FastAdapter<Item> withEventHooks(@Nullable java.util.Collection<? extends EventHook<Item>> eventHooks)
eventHooks - the event hooks to be added for an itempublic FastAdapter<Item> withOnClickListener(FastAdapter.OnClickListener<Item> onClickListener)
onClickListener - the OnClickListener which will be used for a single itempublic FastAdapter<Item> withOnPreClickListener(FastAdapter.OnClickListener<Item> onPreClickListener)
onPreClickListener - the OnPreClickListener which will be called after a single item was clicked and all internal methods are donepublic FastAdapter<Item> withOnLongClickListener(FastAdapter.OnLongClickListener<Item> onLongClickListener)
onLongClickListener - the OnLongClickListener which will be used for a single itempublic FastAdapter<Item> withOnPreLongClickListener(FastAdapter.OnLongClickListener<Item> onPreLongClickListener)
onPreLongClickListener - the OnLongClickListener which will be called after a single item was clicked and all internal methods are donepublic FastAdapter<Item> withOnTouchListener(FastAdapter.OnTouchListener<Item> onTouchListener)
onTouchListener - the TouchListener which will be used for a single itempublic FastAdapter<Item> withOnCreateViewHolderListener(FastAdapter.OnCreateViewHolderListener onCreateViewHolderListener)
onCreateViewHolderListener - the OnCreateViewHolderListener (you may use the OnCreateViewHolderListenerImpl)public FastAdapter<Item> withOnBindViewHolderListener(FastAdapter.OnBindViewHolderListener onBindViewHolderListener)
onBindViewHolderListener - the OnBindViewHolderListenerpublic FastAdapter<Item> withSelectWithItemUpdate(boolean selectWithItemUpdate)
selectWithItemUpdate - true if notifyItemChanged should be called upon selectpublic FastAdapter<Item> withMultiSelect(boolean multiSelect)
multiSelect - true to enable multiSelectpublic FastAdapter<Item> withSelectOnLongClick(boolean selectOnLongClick)
selectOnLongClick - false to do select via single clickpublic FastAdapter<Item> withAllowDeselection(boolean allowDeselection)
allowDeselection - true if a user can deselect an already selected item via clickpublic FastAdapter<Item> withSelectable(boolean selectable)
selectable - true if items are selectablepublic FastAdapter<Item> withPositionBasedStateManagement(boolean mPositionBasedStateManagement)
mPositionBasedStateManagement - false to enable the alternative "stateLess" stateManagementpublic FastAdapter<Item> withLegacyBindViewMode(boolean legacyBindViewMode)
legacyBindViewMode - true if you want to activate it (default = false)public FastAdapter<Item> withSelectionListener(ISelectionListener<Item> selectionListener)
selectionListener - the listener that will be notified about selection changespublic boolean isSelectable()
public boolean isPositionBasedStateManagement()
public FastAdapter<Item> withOnlyOneExpandedItem(boolean mOnlyOneExpandedItem)
mOnlyOneExpandedItem - true if there should be only one expanded, expandable item in the listpublic boolean isOnlyOneExpandedItem()
public FastAdapter<Item> withSavedInstanceState(android.os.Bundle savedInstanceState)
savedInstanceState - If the activity is being re-initialized after
previously being shut down then this Bundle contains the data it most
recently supplied in Note: Otherwise it is null.public FastAdapter<Item> withSavedInstanceState(android.os.Bundle savedInstanceState, java.lang.String prefix)
savedInstanceState - If the activity is being re-initialized after
previously being shut down then this Bundle contains the data it most
recently supplied in Note: Otherwise it is null.prefix - a prefix added to the savedInstance key so we can store multiple statespublic <A extends AbstractAdapter<Item>> void registerAdapter(A adapter)
adapter - an adapter which extends the AbstractAdapterpublic void registerTypeInstance(Item item)
item - an IItem which will be shown in the listpublic Item getTypeInstance(int type)
type - the int type of the itempublic void clearTypeInstance()
public int getHolderAdapterPosition(android.support.v7.widget.RecyclerView.ViewHolder holder)
holder - the viewHolder of the itempublic android.support.v7.widget.RecyclerView.ViewHolder onCreateViewHolder(android.view.ViewGroup parent,
int viewType)
onCreateViewHolder in class android.support.v7.widget.RecyclerView.Adapter<android.support.v7.widget.RecyclerView.ViewHolder>parent - the parent view (the RecyclerView)viewType - the current viewType which is boundpublic void onBindViewHolder(android.support.v7.widget.RecyclerView.ViewHolder holder,
int position)
onBindViewHolder in class android.support.v7.widget.RecyclerView.Adapter<android.support.v7.widget.RecyclerView.ViewHolder>holder - the viewHolder we bind the data onposition - the global positionpublic void onBindViewHolder(android.support.v7.widget.RecyclerView.ViewHolder holder,
int position,
java.util.List<java.lang.Object> payloads)
onBindViewHolder in class android.support.v7.widget.RecyclerView.Adapter<android.support.v7.widget.RecyclerView.ViewHolder>holder - the viewHolder we bind the data onposition - the global positionpayloads - the payloads for the bindViewHolder event containing data which allows to improve view animatingpublic void onViewRecycled(android.support.v7.widget.RecyclerView.ViewHolder holder)
onViewRecycled in class android.support.v7.widget.RecyclerView.Adapter<android.support.v7.widget.RecyclerView.ViewHolder>holder - the viewHolder we unbind the data frompublic void onViewDetachedFromWindow(android.support.v7.widget.RecyclerView.ViewHolder holder)
onViewDetachedFromWindow in class android.support.v7.widget.RecyclerView.Adapter<android.support.v7.widget.RecyclerView.ViewHolder>holder - the viewHolder for the view which got detachedpublic void onViewAttachedToWindow(android.support.v7.widget.RecyclerView.ViewHolder holder)
onViewAttachedToWindow in class android.support.v7.widget.RecyclerView.Adapter<android.support.v7.widget.RecyclerView.ViewHolder>holder - the viewHolder for the view which got detachedpublic boolean onFailedToRecycleView(android.support.v7.widget.RecyclerView.ViewHolder holder)
onFailedToRecycleView in class android.support.v7.widget.RecyclerView.Adapter<android.support.v7.widget.RecyclerView.ViewHolder>holder - the viewHolder for the view which failed to recyclepublic void onAttachedToRecyclerView(android.support.v7.widget.RecyclerView recyclerView)
onAttachedToRecyclerView in class android.support.v7.widget.RecyclerView.Adapter<android.support.v7.widget.RecyclerView.ViewHolder>public void onDetachedFromRecyclerView(android.support.v7.widget.RecyclerView recyclerView)
onDetachedFromRecyclerView in class android.support.v7.widget.RecyclerView.Adapter<android.support.v7.widget.RecyclerView.ViewHolder>public int getPosition(Item item)
item - the item which is searched forpublic int getPosition(long identifier)
identifier - the identifier of an item which is searched forpublic Item getItem(int position)
position - the global positionpublic FastAdapter.RelativeInfo<Item> getRelativeInfo(int position)
position - the global position@Nullable public IAdapter<Item> getAdapter(int position)
position - the global positionpublic int getItemViewType(int position)
getItemViewType in class android.support.v7.widget.RecyclerView.Adapter<android.support.v7.widget.RecyclerView.ViewHolder>position - the global positionpublic long getItemId(int position)
getItemId in class android.support.v7.widget.RecyclerView.Adapter<android.support.v7.widget.RecyclerView.ViewHolder>position - the global positionpublic int getItemCount()
getItemCount in class android.support.v7.widget.RecyclerView.Adapter<android.support.v7.widget.RecyclerView.ViewHolder>public int getPreItemCountByOrder(int order)
order - the number up to which the items are countedpublic int getPreItemCount(int position)
position - the global position of an adapter itempublic int getExpandedItemsCount(int from,
int position)
from - the global start position you should pass here the count of items of the previous adapters (or 0 if you want to start from the beginning)position - the global positionpublic android.os.Bundle saveInstanceState(android.os.Bundle savedInstanceState)
savedInstanceState - If the activity is being re-initialized after
previously being shut down then this Bundle contains the data it most
recently supplied in Note: Otherwise it is null.public android.os.Bundle saveInstanceState(android.os.Bundle savedInstanceState,
java.lang.String prefix)
savedInstanceState - If the activity is being re-initialized after
previously being shut down then this Bundle contains the data it most
recently supplied in Note: Otherwise it is null.prefix - a prefix added to the savedInstance key so we can store multiple statespublic java.util.Set<java.lang.Integer> getSelections()
public java.util.Set<Item> getSelectedItems()
public void toggleSelection(int position)
position - the global positionpublic void select(java.lang.Iterable<java.lang.Integer> positions)
positions - the global positions to selectpublic void select(int position)
position - the global positionpublic void select(int position,
boolean fireEvent)
position - the global positionfireEvent - true if the onClick listener should be calledpublic void select(int position,
boolean fireEvent,
boolean considerSelectableFlag)
position - the global positionfireEvent - true if the onClick listener should be calledconsiderSelectableFlag - true if the select method should not select an item if its not selectablepublic void deselect()
public void select()
public void select(boolean considerSelectableFlag)
considerSelectableFlag - true if the select method should not select an item if its not selectablepublic void deselect(java.lang.Iterable<java.lang.Integer> positions)
positions - the global positions to deselectpublic void deselect(int position)
position - the global positionpublic java.util.List<Item> deleteAllSelectedItems()
public android.util.SparseIntArray getExpanded()
public int[] getExpandedItems()
public void toggleExpandable(int position)
position - the global positionpublic void collapse()
public void collapse(boolean notifyItemChanged)
notifyItemChanged - true if we need to call notifyItemChanged. DEFAULT: falsepublic void collapse(int position)
position - the global positionpublic void collapse(int position,
boolean notifyItemChanged)
position - the global positionnotifyItemChanged - true if we need to call notifyItemChanged. DEFAULT: falsepublic void expand()
public void expand(boolean notifyItemChanged)
notifyItemChanged - true if we need to call notifyItemChanged. DEFAULT: falsepublic void expand(int position)
position - the global positionpublic void expand(int position,
boolean notifyItemChanged)
position - the global positionnotifyItemChanged - true if we need to call notifyItemChanged. DEFAULT: falsepublic void notifyAdapterDataSetChanged()
public void notifyAdapterItemInserted(int position)
position - the global positionpublic void notifyAdapterItemRangeInserted(int position,
int itemCount)
position - the global positionitemCount - the count of items insertedpublic void notifyAdapterItemRemoved(int position)
position - the global positionpublic void notifyAdapterItemRangeRemoved(int position,
int itemCount)
position - the global positionitemCount - the count of items removedpublic void notifyAdapterItemMoved(int fromPosition,
int toPosition)
fromPosition - the global fromPositiontoPosition - the global toPositionpublic void notifyAdapterItemChanged(int position)
position - the global positionpublic void notifyAdapterItemChanged(int position,
java.lang.Object payload)
position - the global positionpayload - additional payloadpublic void notifyAdapterItemRangeChanged(int position,
int itemCount)
position - the global positionitemCount - the count of items changedpublic void notifyAdapterItemRangeChanged(int position,
int itemCount,
java.lang.Object payload)
position - the global positionitemCount - the count of items changedpayload - an additional payloadpublic void notifyAdapterSubItemsChanged(int position)
position - the global position of the parent itempublic int notifyAdapterSubItemsChanged(int position,
int previousCount)
position - the global position of the parent itempreviousCount - the previous count of sub items