-
- All Implemented Interfaces:
-
eu.davidea.fastscroller.FastScroller.AdapterInterface,eu.davidea.fastscroller.FastScroller.BubbleTextCreator,eu.davidea.fastscroller.FastScroller.OnScrollStateChangeListener,eu.davidea.flexibleadapter.helpers.ItemTouchHelperCallback.AdapterCallback
public class FlexibleAdapter<T extends IFlexible> extends AnimatorAdapter implements ItemTouchHelperCallback.AdapterCallback
This Adapter is backed by an ArrayList of arbitrary objects of class T, where Tis your adapter object containing the data of a single item. This Adapter simplifies the development by providing a set of standard methods to handle changes on the data set such as: selecting, filtering, adding, removing, moving and animating an item.
With version 5.0.0, T item must implement IFlexible item interface as base item for all view types and new methods have been added in order to:
- handle Headers/Sections with IHeader and ISectionable items;
- expand and collapse IExpandable items;
- drag&drop and swipe any items.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfaceFlexibleAdapter.OnUpdateListenerpublic interfaceFlexibleAdapter.OnFilterListenerpublic interfaceFlexibleAdapter.OnDeleteCompleteListenerpublic interfaceFlexibleAdapter.OnItemClickListenerpublic interfaceFlexibleAdapter.OnItemLongClickListenerpublic interfaceFlexibleAdapter.OnActionStateListenerpublic interfaceFlexibleAdapter.OnItemMoveListenerpublic interfaceFlexibleAdapter.OnItemSwipeListenerpublic interfaceFlexibleAdapter.OnStickyHeaderChangeListenerpublic interfaceFlexibleAdapter.EndlessScrollListenerpublic classFlexibleAdapter.HandlerCallbackHandler callback for delayed actions.
You can use and override this Callback, current values used by the Adapter:
1 = async call for updateDataSet.2 = async call for filterItems, optionally delayed.8 = hide the progress item from the list, optionally delayed.Note: numbers 0-9 are reserved for the Adapter, use others.
public classFlexibleAdapter.DiffUtilCallbackUse setItems to set the old and new lists, that are available as:
-
{@code protected ListoldItems;}-{@code protected ListnewItems;}
-
Field Summary
Fields Modifier and Type Field Description private longtimeprivate FlexibleAdapter.DiffUtilCallbackdiffUtilCallbackprivate booleanpermanentDeleteprivate booleanheadersShownprivate booleannotifyChangeOfUnfilteredItemsprivate booleannotifyMoveOfFilteredItemspublic FlexibleAdapter.OnItemClickListenermItemClickListenerpublic FlexibleAdapter.OnItemLongClickListenermItemLongClickListener
-
Constructor Summary
Constructors Constructor Description FlexibleAdapter(List<T> items)Simple Constructor with NO listeners! FlexibleAdapter(List<T> items, Object listeners)Main Constructor with all managed listeners for ViewHolder and the Adapter itself. FlexibleAdapter(List<T> items, Object listeners, boolean stableIds)Same as ( with possibility to set stableIds.
-
Method Summary
Modifier and Type Method Description longgetTime()FlexibleAdapter<T>setDiffUtilCallback(FlexibleAdapter.DiffUtilCallback diffUtilCallback)Sets a custom implementation of DiffUtilCallback for the DiffUtil. FlexibleAdapter<T>setPermanentDelete(boolean permanentDelete)Sets if the deleted items should be deleted immediately or if Adapter should cache them torestore them when requested by the user. FlexibleAdapter<T>setHeadersShown(boolean headersShown)Manually change the flag to indicate that headers are inserted(or not) in the main list by the userand the Adapter doesn't(does) have to automatically insert them. final FlexibleAdapter<T>setNotifyChangeOfUnfilteredItems(boolean notifyChange)With this setting, we can skip the check of the implemented method shouldNotifyChange. final FlexibleAdapter<T>setNotifyMoveOfFilteredItems(boolean notifyMove)This method performs a further step to nicely animate the moved items. FlexibleAdapter<T>addListener(Object listener)Initializes the listener(s) of this Adapter. FlexibleAdapter<T>removeListener(Object listener)Removes one listener from this Adapter. voidonAttachedToRecyclerView(@NonNull() RecyclerView recyclerView)Attaches the FastScrollerDelegate} to the RecyclerView if necessary. voidonDetachedFromRecyclerView(@NonNull() RecyclerView recyclerView)Detaches the FastScrollerDelegate} from the RecyclerView if necessary. FlexibleAdapter<T>expandItemsAtStartUp()Maps and expands items that are initially configured to be shown as expanded. booleanisItemEnabled(int position)Checks if the current item has the property {@code enabled = true}.booleanisSelectable(int position)Checks if the current item has the property selectable = true}. voidtoggleSelection(int position)Toggles the selection status of the item at a given position. voidselectAll(Array<Integer> viewTypes)Helper to automatically select all the items of the viewType equal to the viewType ofthe first selected item. voidclearSelection()Clears the selection status for all items one by one and it doesn't stop animations in the items. booleanisAnyParentSelected()booleanisAnyChildSelected()voidupdateDataSet(@Nullable() List<T> items)Convenience method of updateDataSet (You should read the commentsof this method). voidupdateDataSet(@Nullable() List<T> items, boolean animate)This method will refresh the entire data set content. TgetItem(int position)Returns the object of the generic type T. <S extends T> SgetItem(int position, Class<S> clazz)Returns the object of specific type S. longgetItemId(int position)This method is mostly used by the adapter if items have stableIds. intgetItemCount()Returns the total number of items in the data set held by the adapter (headers and footersINCLUDED). final intgetMainItemCount()Returns the total number of items in the data set held by the adapter. final intgetItemCountOfTypes(Array<Integer> viewTypes)Provides the number of items currently displayed of one or more certain types. final List<T>getCurrentItems()Gets an unmodifiable view of the internal list of items. booleanisEmpty()You can override this method to define your own concept of "Empty". final intgetGlobalPositionOf(IFlexible item)Retrieves the global position of the item in the Adapter list.If no scrollable Headers are added, the global position coincides with the cardinal position. final intgetCardinalPositionOf(@NonNull() IFlexible item)Retrieves the position of the Main item in the Adapter list excluding the scrollable Headers.If no scrollable Headers are added, the cardinal position coincides with the global position. final intgetSameTypePositionOf(@NonNull() IFlexible item)Retrieves the position of any item in the Adapter counting only the items of thesame view type of the provided item and excluding all the others view types. booleancontains(@Nullable() T item)This method is never called internally. intcalculatePositionFor(@NonNull() Object item, @Nullable() Comparator<IFlexible> comparator)New method to extract the new position where the item should lay. final List<T>getScrollableHeaders()final List<T>getScrollableFooters()final booleanisScrollableHeaderOrFooter(int position)Checks if at the provided position, the item is a Header or Footer. final booleanisScrollableHeaderOrFooter(T item)Checks if at the provided item is a Header or Footer. final booleanaddScrollableHeader(@NonNull() T headerItem)Adds a Scrollable Header. final booleanaddScrollableFooter(@NonNull() T footerItem)Adds a Scrollable Footer. final voidremoveScrollableHeader(@NonNull() T headerItem)Removes the provided Scrollable Header. final voidremoveScrollableFooter(@NonNull() T footerItem)Removes the provided Scrollable Footer. final voidremoveAllScrollableHeaders()Removes all Scrollable Headers at once. final voidremoveAllScrollableFooters()Removes all Scrollable Footers at once. final voidaddScrollableHeaderWithDelay(@NonNull() T headerItem, long delay, boolean scrollToPosition)Same as addScrollableHeader but with a delay and the possibility toscroll to it. final voidaddScrollableFooterWithDelay(@NonNull() T footerItem, long delay, boolean scrollToPosition)Same as addScrollableFooter but with a delay and the possibility toscroll to it. final voidremoveScrollableHeaderWithDelay(@NonNull() T headerItem, long delay)Same as removeScrollableHeader but with a delay. final voidremoveScrollableFooterWithDelay(@NonNull() T footerItem, long delay)Same as removeScrollableFooter but with a delay. FlexibleAdapter<T>setUnlinkAllItemsOnRemoveHeaders(boolean unlinkOnRemoveHeader)Setting to automatically unlink the deleted header from items having that header linked. List<IHeader>getHeaderItems()Retrieves all the header items. booleanisHeader(T item)booleanhasHeader(T item)Helper method to check if an item holds a header. booleanhasSameHeader(T item, IHeader header)Checks if the item has a header and that header is the same of the provided one. IHeadergetHeaderOf(T item)Retrieves the header of the provided {@code ISectionable}item.IHeadergetSectionHeader(int position)Retrieves the IHeader item of any specified position. List<ISectionable>getSectionItems(@NonNull() IHeader header)Provides all the items that belongs to the section represented by the provided header. List<Integer>getSectionItemPositions(@NonNull() IHeader header)Provides all the item positions that belongs to the section represented by the providedheader. booleanareHeadersShown()Evaluates if Adapter has headers shown. booleanareHeadersSticky()Evaluates if Adapter can actually display sticky headers on the top. final intgetStickyPosition()Returns the current position of the sticky header. final voidensureHeaderParent()Ensures the current sticky header view is correctly displayed in the sticky layout. FlexibleAdapter<T>setStickyHeaders(boolean sticky)Enables/Disables the sticky header feature with default sticky layout container. FlexibleAdapter<T>setStickyHeaders(boolean sticky, @Nullable() ViewGroup stickyContainer)Enables/Disables the sticky header feature with a custom sticky layout container. intgetStickyHeaderElevation()Gets the layout in dpi elevation for sticky header. FlexibleAdapter<T>setStickyHeaderElevation(int stickyElevation)Sets the elevation in dpi for the sticky header layout. FlexibleAdapter<T>setDisplayHeadersAtStartUp(boolean displayHeaders)Sets if all headers should be shown at startup by the Adapter automatically. FlexibleAdapter<T>showAllHeaders()Shows all headers in the RecyclerView at their linked position. voidhideAllHeaders()Hides all headers from the RecyclerView. intgetItemViewType(int position)You CANNOT override this method: {@code FlexibleAdapter}delegates the ViewTypedefinition via{@code IFlexible.getLayoutRes()}so ViewTypes are automatically mapped(AutoMap).RecyclerView.ViewHolderonCreateViewHolder(@NonNull() ViewGroup parent, int viewType)You CANNOT override this method to create the ViewHolder, {@code FlexibleAdapter}delegates the creation via{@code IFlexible.createViewHolder()}.voidonBindViewHolder(@NonNull() RecyclerView.ViewHolder holder, int position)You CANNOT override this method to bind the items. voidonBindViewHolder(@NonNull() RecyclerView.ViewHolder holder, int position, @NonNull() List payloads)Same concept of {@code #onBindViewHolder()}but with Payload.voidonViewAttachedToWindow(@NonNull() RecyclerView.ViewHolder holder)voidonViewDetachedFromWindow(@NonNull() RecyclerView.ViewHolder holder)voidonViewRecycled(@NonNull() RecyclerView.ViewHolder holder)booleanisTopEndless()voidsetTopEndless(boolean topEndless)Sets endless scrolling from the top. booleanisEndlessScrollEnabled()Evaluates if the Adapter is in Endless Scroll mode. intgetEndlessCurrentPage()Provides the current endless page if the page size limit is set, if not set the returnedvalue is always 0. intgetEndlessPageSize()The current setting for the endless page size limit. FlexibleAdapter<T>setEndlessPageSize(int endlessPageSize)Sets the limit to automatically disable the endless feature when coming items size is lessthan the page size. intgetEndlessTargetCount()The current setting for the endless target item count limit. FlexibleAdapter<T>setEndlessTargetCount(int endlessTargetCount)Sets the limit to automatically disable the endless feature when the total items count inthe Adapter is equals or bigger than the target count. FlexibleAdapter<T>setLoadingMoreAtStartUp(boolean enable)Sets if Endless / Loading More should be triggered at start-up, especially when thelist is empty. FlexibleAdapter<T>setEndlessProgressItem(@Nullable() T progressItem)Sets the progressItem to be displayed at the end of the list and activate the Loading Morefeature. FlexibleAdapter<T>setEndlessScrollListener(@Nullable() FlexibleAdapter.EndlessScrollListener endlessScrollListener, @NonNull() T progressItem)Sets the progressItem to be displayed at the end of the list and Sets the callback toautomatically load more items asynchronously(your duty) (no further user action is neededbut the scroll). FlexibleAdapter<T>setEndlessScrollThreshold(int thresholdItems)Sets the minimum number of items still to bind to start the automatic loading. voidonLoadMoreComplete(@Nullable() List<T> newItems)To call when more items are successfully loaded. voidonLoadMoreComplete(@Nullable() List<T> newItems, long delay)Call this method to complete the action of the Loading more items. booleanisAutoCollapseOnExpand()FlexibleAdapter<T>setAutoCollapseOnExpand(boolean collapseOnExpand)Automatically collapse all previous expanded parents before expand the new clicked parent. booleanisRecursiveCollapse()FlexibleAdapter<T>setRecursiveCollapse(boolean collapseSubLevels)Automatically collapse all inner sub expandable when higher parent is collapsed. booleanisAutoScrollOnExpand()FlexibleAdapter<T>setAutoScrollOnExpand(boolean scrollOnExpand)Automatically scroll the clicked expandable item to the first visible position. booleanisExpanded(int position)booleanisExpanded(@Nullable() T item)Checks if the provided item is an IExpandable instance and is expanded. booleanisExpandable(@Nullable() T item)Checks if the provided item is an IExpandable instance. intgetMinCollapsibleLevel()FlexibleAdapter<T>setMinCollapsibleLevel(int minCollapsibleLevel)Sets the minimum level which all sub expandable items will be collapsed too. booleanhasSubItems(IExpandable expandable)Utility method to check if the expandable item has sub items. IExpandablegetExpandableOf(int position)Retrieves the parent of a child for the provided position. IExpandablegetExpandableOf(T child)Retrieves the parent of a child. intgetExpandablePositionOf(@NonNull() T child)Retrieves the parent position of a child. intgetSubPositionOf(@NonNull() T child)Retrieves the sub position of any sub item in the section where it lays. List<T>getSiblingsOf(@NonNull() T child)Provides the full sub list where the child currently lays. List<T>getExpandedItems()Provides a list of all expandable items that are currently expanded. List<Integer>getExpandedPositions()Provides a list of all expandable positions that are currently expanded. intexpand(int position)Expands an item that is {@code IExpandable}type, not yet expanded and if has subItems.intexpand(int position, boolean notifyParent)Expands an item that is {@code IExpandable}type, not yet expanded and if has subItems.intexpand(T item)Convenience method to expand a single item. intexpand(T item, boolean init)Convenience method to initially expand a single item. intexpandAll()Expands all {@code IExpandable}items with minimum of level mMinCollapsibleLevel.intexpandAll(int level)Expands all {@code IExpandable}items with at least the specified level.intcollapse(int position)Collapses an {@code IExpandable}item that is already expanded and if no subItemis selected.intcollapse(int position, boolean notifyParent)Same behaviors as collapse with possibility to notify/update the parent. intcollapseAll()Collapses all expandable items with the minimum level of mMinCollapsibleLevel. intcollapseAll(int level)Collapses all expandable items with the level equals-higher than the specified level. voidupdateItem(@NonNull() T item)Updates/Rebounds the itemView corresponding to the current position of theprovided item with the new content. voidupdateItem(@NonNull() T item, @Nullable() Object payload)Updates/Rebounds the itemView corresponding to the current position of theprovided item with the new content. voidupdateItem(int position, @NonNull() T item, @Nullable() Object payload)Updates/Rebounds the itemView corresponding to the current position of theprovided item with the new content. voidaddItemWithDelay(int position, @NonNull() T item, long delay, boolean scrollToPosition)Inserts the given item at desired position or Add item at last position with a delayand auto-scroll to the position. booleanaddItem(@NonNull() T item)Simply append the provided item to the end of the list. booleanaddItem(int position, @NonNull() T item)Inserts the given item at the specified position or Adds the item to the end of the list(no matters if the new position is out of bounds!). booleanaddItems(int position, @NonNull() List<T> items)Inserts a set of items at specified position or Adds the items to the end of the list(no matters if the new position is out of bounds!). booleanaddSubItem(int parentPosition, int subPosition, @NonNull() T item)Convenience method of addSubItem. booleanaddSubItem(int parentPosition, int subPosition, @NonNull() T item, boolean expandParent, @Nullable() Object payload)Convenience method of addSubItems. booleanaddSubItems(int parentPosition, int subPosition, @NonNull() List<T> items)Convenience method of addSubItems. booleanaddSubItems(int parentPosition, int subPosition, @NonNull() List<T> items, boolean expandParent, @Nullable() Object payload)Convenience method of addSubItems. intaddSection(@NonNull() IHeader header)Adds and shows an empty section to the top (position = 0). intaddSection(@NonNull() IHeader header, @Nullable() Comparator<IFlexible> comparator)Adds and shows an empty section. intaddItemToSection(@NonNull() ISectionable sectionable, @Nullable() IHeader header, @Nullable() Comparator<IFlexible> comparator)Adds a new item in a section when the relative position is unknown. intaddItemToSection(@NonNull() ISectionable sectionable, @Nullable() IHeader header, int index)Adds a new item in a section when the relative position is known. voidclear()This method clears everything: main items, Scrollable Headers and Footers andeverything else is displayed. voidclearAllBut(Array<Integer> viewTypes)Clears the Adapter list retaining Scrollable Headers and Footers and all items of thetype provided as parameter. voidremoveItemWithDelay(@NonNull() T item, long delay, boolean permanent)Removes the given item after the given delay. voidremoveSection(IHeader header)Removes all items of a section, header included. voidremoveItem(int position)Convenience method of removeItem providing CHANGE as payload for the parent item. voidremoveItem(int position, @Nullable() Object payload)Removes an item from the internal list and notify the change. voidremoveItems(@NonNull() List<Integer> selectedPositions)Convenience method of removeItems providing the default CHANGE for the parent items. voidremoveItems(@Nullable() List<Integer> selectedPositions, @Nullable() Object payload)Removes items by ranges, auto-collapse expanded items and notify the change. voidremoveItemsOfType(Array<Integer> viewTypes)Selectively removes all items of the type provided as parameter. voidremoveRange(int positionStart, int itemCount)Same as removeRange, but in this case the parent will not benotified about the change, if children are removed. voidremoveRange(int positionStart, int itemCount, @Nullable() Object payload)Removes a list of consecutive items and notify the change. voidremoveAllSelectedItems()Convenience method to remove all items that are currently selected. voidremoveAllSelectedItems(@Nullable() Object payload)Convenience method to remove all items that are currently selected. booleanisPermanentDelete()Returns if items will be deleted immediately when deletion is requested. booleanisRestoreWithSelection()Returns the current configuration to restore selections on Undo. FlexibleAdapter<T>setRestoreSelectionOnUndo(boolean restoreSelection)Gives the possibility to restore the selection on Undo, when restoreDeletedItems is called. voidrestoreDeletedItems()Restore items just removed. voidconfirmDeletion()Performs removal confirmation and cleans memory by synchronizing the internal list from deletion. synchronized voidemptyBin()Cleans memory from items just removed. final synchronized booleanisRestoreInTime()List<T>getDeletedItems()List<Integer>getUndoPositions()voidsaveUndoPositions(@NonNull() List<Integer> undoPositions)final IExpandablegetExpandableOfDeletedChild(@NonNull() T child)Retrieves the expandable of the deleted child. final List<T>getDeletedChildren(IExpandable expandable)Retrieves only the deleted children of the specified parent. final List<T>getCurrentChildren(@Nullable() IExpandable expandable)Retrieves all the original children of the specified parent, filtering out all thedeleted children if any. booleanhasFilter()booleanhasNewFilter(Serializable constraint)Checks if the filter is changed. voidsetFilter(@Nullable() Serializable filter)Sets the new filter entity. <F extends Serializable> FgetFilter(Class<F> clazz)Gets the current filter. voidfilterItems()Filters the current list with the filter previously set with setFilter. voidfilterItems(long delay)Same as filterItems but with a delay in the execution, useful to grabmore characters from user before starting the search. voidfilterItems(@NonNull() List<T> unfilteredItems, long delay)WATCH OUT! voidfilterItems(@NonNull() List<T> unfilteredItems)WATCH OUT! booleanisFiltering()FlexibleAdapter<T>setAnimateToLimit(int limit)Tunes the limit after the which the synchronization animations, occurred duringupdateDataSet and filter operations, are skipped and notifyDataSetChanged will be called instead. booleanisAnimateChangesWithDiffUtil()FlexibleAdapter<T>setAnimateChangesWithDiffUtil(boolean useDiffUtil)Whether use DiffUtil to calculate the changes between 2 lists after Update orFilter operations. final ItemTouchHelpergetItemTouchHelper()Used by onTouch to start Drag or Swipe when HandleView is touched. final ItemTouchHelperCallbackgetItemTouchHelperCallback()Returns the customization of the ItemTouchHelperCallback or the default if it wasn't setbefore. final FlexibleAdapter<T>setItemTouchHelperCallback(ItemTouchHelperCallback itemTouchHelperCallback)Sets a custom callback implementation for item touch. final booleanisLongPressDragEnabled()Returns whether ItemTouchHelper should start a drag and drop operation if an item islong pressed. final FlexibleAdapter<T>setLongPressDragEnabled(boolean longPressDragEnabled)Enables / Disables the drag of the item when long-press the entire itemView. final booleanisHandleDragEnabled()Returns whether ItemTouchHelper should start a drag and drop operation by touching itshandle. final FlexibleAdapter<T>setHandleDragEnabled(boolean handleDragEnabled)Enables / Disables the drag of the item with a handle view.Requires the Adapter being attached to the RecyclerView. final booleanisSwipeEnabled()Returns whether ItemTouchHelper should start a swipe operation if a pointer is swipedover the View. final FlexibleAdapter<T>setSwipeEnabled(boolean swipeEnabled)Enables full the swipe of the items. voidmoveItem(int fromPosition, int toPosition)Moves the item placed at position {@code fromPosition}to the position{@code toPosition}.voidmoveItem(int fromPosition, int toPosition, @Nullable() Object payload)Moves the item placed at position {@code fromPosition}to the position{@code toPosition}.voidswapItems(List<T> list, int fromPosition, int toPosition)Swaps the elements of list at indices fromPosition and toPosition and notify the change. voidonActionStateChanged(RecyclerView.ViewHolder viewHolder, int actionState)Called when the first registers an item as being moved or swipedor when has been released. booleanshouldMove(int fromPosition, int toPosition)Evaluate if positions are compatible for swapping. booleanonItemMove(int fromPosition, int toPosition)Called when an item has been dragged far enough to trigger a move. voidonItemSwiped(int position, int direction)Called when an item has been dismissed by a swipe. voidsmoothScrollToPosition(int position)Performs safe smooth scroll with a delay of {@value #AUTO_SCROLL_DELAY} ms. final voidinvalidateItemDecorations(long delay)Helper method to post invalidate the item decorations after the provided delay. voidonSaveInstanceState(Bundle outState)Save the state of the current expanded items. voidonRestoreInstanceState(Bundle savedInstanceState)Restore the previous state of the expanded items. -
Methods inherited from class eu.davidea.flexibleadapter.AnimatorAdapter
isAnimationOnForwardScrollingEnabled, isAnimationOnReverseScrollingEnabled, isOnlyEntryAnimation, setAnimationDelay, setAnimationDuration, setAnimationEntryStep, setAnimationInitialDelay, setAnimationInterpolator, setAnimationOnForwardScrolling, setAnimationOnReverseScrolling, setOnlyEntryAnimation -
Methods inherited from class eu.davidea.flexibleadapter.SelectableAdapter
addSelection, enableLogs, getAllBoundViewHolders, getFastScroller, getFlexibleLayoutManager, getMode, getRecyclerView, getSelectedItemCount, getSelectedPositions, getSelectedPositionsAsSet, isFastScrollerEnabled, isLastItemInActionMode, isSelectAll, isSelected, onBindViewHolder, onCreateBubbleText, onFastScrollerStateChange, removeSelection, setFastScroller, setFlexibleLayoutManager, setMode, toggleFastScroller, toggleSelection, useTag -
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
-
-
Constructor Detail
-
FlexibleAdapter
FlexibleAdapter(List<T> items)
Simple Constructor with NO listeners!- Parameters:
items- items to display.
-
FlexibleAdapter
FlexibleAdapter(List<T> items, Object listeners)
Main Constructor with all managed listeners for ViewHolder and the Adapter itself.- Parameters:
items- items to displaylisteners- can be an instance of:
-
-
Method Detail
-
getTime
long getTime()
-
setDiffUtilCallback
FlexibleAdapter<T> setDiffUtilCallback(FlexibleAdapter.DiffUtilCallback diffUtilCallback)
Sets a custom implementation of DiffUtilCallback for the DiffUtil.
- Parameters:
diffUtilCallback- the custom callback that DiffUtil will call
-
setPermanentDelete
FlexibleAdapter<T> setPermanentDelete(boolean permanentDelete)
Sets if the deleted items should be deleted immediately or if Adapter should cache them torestore them when requested by the user.
Default value is
{@code true}(Undo mechanism is disabled).- Parameters:
permanentDelete- true to delete items forever, false to use the cache for Undo feature
-
setHeadersShown
FlexibleAdapter<T> setHeadersShown(boolean headersShown)
Manually change the flag to indicate that headers are inserted(or not) in the main list by the userand the Adapter doesn't(does) have to automatically insert them.
Default value is
{@code false}(headers are not shown at startup).- Parameters:
headersShown- true, if headers are already shown
-
setNotifyChangeOfUnfilteredItems
final FlexibleAdapter<T> setNotifyChangeOfUnfilteredItems(boolean notifyChange)
With this setting, we can skip the check of the implemented method shouldNotifyChange.
By setting false all items will be skipped by an update.
Default value is{@code true}(items will always be notified of a change).- Parameters:
notifyChange- true to trigger notifyItemChanged,false to not update the items' content.
-
setNotifyMoveOfFilteredItems
final FlexibleAdapter<T> setNotifyMoveOfFilteredItems(boolean notifyMove)
This method performs a further step to nicely animate the moved items. When false, theitems are not moved but removed, to be added at the correct position.
The process is very slow on big list of the order of ~3-5000 items and higher,due to the calculation of the correct position for each item to be shifted.Use with caution!
The slowness is higher when the filter is cleared out.Default value is
{@code false}.- Parameters:
notifyMove- true to animate move changes after filtering or update data set,false otherwise
-
addListener
@CallSuper() FlexibleAdapter<T> addListener(Object listener)
Initializes the listener(s) of this Adapter.
This method is automatically called from the Constructor.
- Parameters:
listener- the object(s) instance(s) of any listener
-
removeListener
@CallSuper() FlexibleAdapter<T> removeListener(Object listener)
Removes one listener from this Adapter.
Warning:
- In case of Click and LongClick events, it will remove also the callbackfrom all bound ViewHolders too. To restore these 2 events on the current bound ViewHolders,call addListener providing the instance of the desired listener.
- To remove a specific listener you have to provide the either the instance or the Classtype of the listener, example:
removeListener(mUpdateListener); removeListener(FlexibleAdapter.OnItemLongClickListener.class);
- Parameters:
listener- the listener instance or Class type to remove from this Adapter and/or from all bound ViewHolders
-
onAttachedToRecyclerView
@CallSuper() void onAttachedToRecyclerView(@NonNull() RecyclerView recyclerView)
Attaches the FastScrollerDelegate} to the RecyclerView if necessary.
Attaches the
{@code StickyHeaderHelper}to the RecyclerView if necessary.
-
onDetachedFromRecyclerView
@CallSuper() void onDetachedFromRecyclerView(@NonNull() RecyclerView recyclerView)
Detaches the FastScrollerDelegate} from the RecyclerView if necessary.
Detaches the
{@code StickyHeaderHelper}from the RecyclerView if necessary.
-
expandItemsAtStartUp
FlexibleAdapter<T> expandItemsAtStartUp()
Maps and expands items that are initially configured to be shown as expanded.
This method should be called during the creation of the Activity/Fragment, useful alsoafter a screen rotation.
-
isItemEnabled
boolean isItemEnabled(int position)
Checks if the current item has the property
{@code enabled = true}.When an item is disabled, user cannot interact with it.
- Parameters:
position- the current position of the item to check
-
isSelectable
boolean isSelectable(int position)
Checks if the current item has the property selectable = true}.
-
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(int).
The Activated State of the ItemView is automatically set in FlexibleViewHolder#toggleActivation() called in 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 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.
-
selectAll
void selectAll(Array<Integer> viewTypes)
Helper to automatically select all the items of the viewType equal to the viewType ofthe first selected item.
Examples:
- if user initially selects an expandable of type A, then only expandable items oftype A can be selected.
- if user initially selects a non-expandable of type B, then only items of type Bcan be selected.
- The developer can override this behaviour by passing a list of viewTypes for whichhe wants to force the selection.
- Parameters:
viewTypes- All the desired viewTypes to be selected, providing no view types, willautomatically select all the viewTypes of the first item user has selected
-
clearSelection
@CallSuper() 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 java.util.Iterator} on synchronized collection toavoid java.util.ConcurrentModificationException}.
-
isAnyParentSelected
boolean isAnyParentSelected()
-
isAnyChildSelected
boolean isAnyChildSelected()
-
updateDataSet
@CallSuper() void updateDataSet(@Nullable() List<T> items)
Convenience method of updateDataSet (You should read the commentsof this method).
In this call, changes will NOT be animated: Warning!notifyDataSetChanged will be invoked.
- Parameters:
items- the new data set
-
updateDataSet
@CallSuper() void updateDataSet(@Nullable() List<T> items, boolean animate)
This method will refresh the entire data set content. Optionally, all changes can beanimated, limited by the value previously set with setAnimateToLimit to improve performance on very big list. Should provide
{@code animate=false}todirectly invoke notifyDataSetChanged without any animations, if{@code stableIds}is not set!Note:
- Scrollable Headers and Footers (if existent) will be restored in this call.
- I strongly recommend to implement hashCode to all adapter itemsalong with equals: This Adapter is making use of HashSet toimprove performance.
- expandItemsAtStartUp
- showAllHeaders if headers are shown
- onPostUpdate
- onUpdateEmptyView if the listener is set
- Parameters:
items- the new data setanimate- true to animate the changes, false for an instant refresh
-
getItem
@Nullable() T getItem(int position)
Returns the object of the generic type T.
This method cannot be overridden since the entire library relies on it.
- Parameters:
position- the position of the item in the list
-
getItem
@Nullable() <S extends T> S getItem(int position, Class<S> clazz)
Returns the object of specific type S.
- Parameters:
position- the position of the item in the listclazz- the class type expected
-
getItemId
long getItemId(int position)
This method is mostly used by the adapter if items have stableIds.
- Parameters:
position- the position of the current item
-
getItemCount
int getItemCount()
Returns the total number of items in the data set held by the adapter (headers and footersINCLUDED). Use getMainItemCount with
{@code false}as parameter to retrieveonly real items excluding headers and footers.Note: This method cannot be overridden since the selection and the internalmethods rely on it.
-
getMainItemCount
final int getMainItemCount()
Returns the total number of items in the data set held by the adapter.
- Provide
{@code true}(default behavior) to count all items, same result of getItemCount. - Provide
{@code false}to count only main items (headers and footers are EXCLUDED).
- Provide
-
getItemCountOfTypes
final int getItemCountOfTypes(Array<Integer> viewTypes)
Provides the number of items currently displayed of one or more certain types.
- Parameters:
viewTypes- the viewTypes to count
-
getCurrentItems
@NonNull() final List<T> getCurrentItems()
Gets an unmodifiable view of the internal list of items.
-
isEmpty
boolean isEmpty()
You can override this method to define your own concept of "Empty". This method is nevercalled internally.
-
getGlobalPositionOf
final int getGlobalPositionOf(IFlexible item)
Retrieves the global position of the item in the Adapter list.If no scrollable Headers are added, the global position coincides with the cardinal position.
This method cannot be overridden since the entire library relies on it.
- Parameters:
item- the item for which the position needs to be found
-
getCardinalPositionOf
final int getCardinalPositionOf(@NonNull() IFlexible item)
Retrieves the position of the Main item in the Adapter list excluding the scrollable Headers.If no scrollable Headers are added, the cardinal position coincides with the global position.
Note:- This method is NOT suitable to call when managing items: ALL insert, remove, move andswap operations, should done with global position getGlobalPositionOf.- This method cannot be overridden.
- Parameters:
item- the item for which the position needs to be found
-
getSameTypePositionOf
final int getSameTypePositionOf(@NonNull() IFlexible item)
Retrieves the position of any item in the Adapter counting only the items of thesame view type of the provided item and excluding all the others view types.
Tip: You can identify the number of the section (you need to add +1) of anyheaders OR to retrieve the position of an item as it were the only view type visible inthe Adapter.
- Parameters:
item- the item for which the position needs to be found
-
contains
boolean contains(@Nullable() T item)
This method is never called internally.
- Parameters:
item- the item to find
-
calculatePositionFor
int calculatePositionFor(@NonNull() Object item, @Nullable() Comparator<IFlexible> comparator)
New method to extract the new position where the item should lay.
Note: The
If the{@code Comparator}object should be customized to support alltypes of items this Adapter is managing or a{@code ClassCastException}will be raised.{@code Comparator}is{@code null}the returned position is 0 (first position).- Parameters:
item- the item to evaluate the insertioncomparator- the Comparator object with the logic to sort the list
-
getScrollableHeaders
@NonNull() final List<T> getScrollableHeaders()
-
getScrollableFooters
@NonNull() final List<T> getScrollableFooters()
-
isScrollableHeaderOrFooter
final boolean isScrollableHeaderOrFooter(int position)
Checks if at the provided position, the item is a Header or Footer.
-
isScrollableHeaderOrFooter
final boolean isScrollableHeaderOrFooter(T item)
Checks if at the provided item is a Header or Footer.
- Parameters:
item- the item to check
-
addScrollableHeader
final boolean addScrollableHeader(@NonNull() T headerItem)
Adds a Scrollable Header.
Scrollable Headers have the following characteristic:
- lay always before any main item.
- cannot be selectable nor draggable.
- cannot be inserted twice, but many can be inserted.
- any new header will be inserted before the existent.
- can be of any type so they can be bound at runtime with any data inside.
- won't be filtered because they won't be part of the main list, but added separatelyat the initialization phase
- can be added and removed with certain delay.
- Parameters:
headerItem- the header item to be added
-
addScrollableFooter
final boolean addScrollableFooter(@NonNull() T footerItem)
Adds a Scrollable Footer.
Scrollable Footers have the following characteristic:
- lay always after any main item.
- cannot be selectable nor draggable.
- cannot be inserted twice, but many can be inserted.
- cannot scroll animate, when inserted for the first time.
- any new footer will be inserted after the existent.
- can be of any type so they can be bound at runtime with any data inside.
- won't be filtered because they won't be part of the main list, but added separatelyat the initialization phase
- can be added and removed with certain delay.
- endless
{@code progressItem}is handled as a Scrollable Footer, but it will be alwaysdisplayed between the main items and the others footers.
- Parameters:
footerItem- the footer item to be added
-
removeScrollableHeader
final void removeScrollableHeader(@NonNull() T headerItem)
Removes the provided Scrollable Header.
- Parameters:
headerItem- the header to remove
-
removeScrollableFooter
final void removeScrollableFooter(@NonNull() T footerItem)
Removes the provided Scrollable Footer.
- Parameters:
footerItem- the footer to remove
-
removeAllScrollableHeaders
final void removeAllScrollableHeaders()
Removes all Scrollable Headers at once.
-
removeAllScrollableFooters
final void removeAllScrollableFooters()
Removes all Scrollable Footers at once.
-
addScrollableHeaderWithDelay
final void addScrollableHeaderWithDelay(@NonNull() T headerItem, long delay, boolean scrollToPosition)
Same as addScrollableHeader but with a delay and the possibility toscroll to it.
- Parameters:
headerItem- the header item to be addeddelay- the delay in msscrollToPosition- true to scroll to the header item position once it has been added
-
addScrollableFooterWithDelay
final void addScrollableFooterWithDelay(@NonNull() T footerItem, long delay, boolean scrollToPosition)
Same as addScrollableFooter but with a delay and the possibility toscroll to it.
- Parameters:
footerItem- the footer item to be addeddelay- the delay in msscrollToPosition- true to scroll to the footer item position once it has been added
-
removeScrollableHeaderWithDelay
final void removeScrollableHeaderWithDelay(@NonNull() T headerItem, long delay)
Same as removeScrollableHeader but with a delay.
- Parameters:
headerItem- the header item to be removeddelay- the delay in ms
-
removeScrollableFooterWithDelay
final void removeScrollableFooterWithDelay(@NonNull() T footerItem, long delay)
Same as removeScrollableFooter but with a delay.
- Parameters:
footerItem- the footer item to be removeddelay- the delay in ms
-
setUnlinkAllItemsOnRemoveHeaders
FlexibleAdapter<T> setUnlinkAllItemsOnRemoveHeaders(boolean unlinkOnRemoveHeader)
Setting to automatically unlink the deleted header from items having that header linked.
Default value is
{@code false}.- Parameters:
unlinkOnRemoveHeader- true to unlink the deleted header from items having that headerlinked, false otherwise
-
getHeaderItems
@NonNull() List<IHeader> getHeaderItems()
Retrieves all the header items.
-
hasHeader
boolean hasHeader(T item)
Helper method to check if an item holds a header.
- Parameters:
item- the identified item
-
hasSameHeader
boolean hasSameHeader(T item, IHeader header)
Checks if the item has a header and that header is the same of the provided one.
- Parameters:
item- the item supposing having the headerheader- the header to compare
-
getHeaderOf
@Nullable() IHeader getHeaderOf(T item)
Retrieves the header of the provided
{@code ISectionable}item.- Parameters:
item- the ISectionable item holding a header
-
getSectionHeader
IHeader getSectionHeader(int position)
Retrieves the IHeader item of any specified position.
- Parameters:
position- the item position
-
getSectionItems
@NonNull() List<ISectionable> getSectionItems(@NonNull() IHeader header)
Provides all the items that belongs to the section represented by the provided header.
- Parameters:
header- the{@code IHeader}item that represents the section
-
getSectionItemPositions
@NonNull() List<Integer> getSectionItemPositions(@NonNull() IHeader header)
Provides all the item positions that belongs to the section represented by the providedheader.
- Parameters:
header- the{@code IHeader}item that represents the section
-
areHeadersShown
boolean areHeadersShown()
Evaluates if Adapter has headers shown.
-
areHeadersSticky
boolean areHeadersSticky()
Evaluates if Adapter can actually display sticky headers on the top.
-
getStickyPosition
final int getStickyPosition()
Returns the current position of the sticky header.
-
ensureHeaderParent
final void ensureHeaderParent()
Ensures the current sticky header view is correctly displayed in the sticky layout.
-
setStickyHeaders
FlexibleAdapter<T> setStickyHeaders(boolean sticky)
Enables/Disables the sticky header feature with default sticky layout container.
Note:
- You should consider to display headers with setDisplayHeadersAtStartUp:Feature can enabled/disabled freely, but if headers are hidden nothing will happen.
- Only in case of "Sticky Header" items you must provide
{@code true}to theconstructor: FlexibleViewHolder. - Optionally, you can set a custom sticky layout container that must be alreadyinflated.Check setStickyHeaders.
- Optionally, you can set a layout elevation: Header item elevation is used first,if not set, default elevation of
{@code 21f}pixel is used. - Sticky headers are clickable as any views, but cannot be dragged nor swiped.
- Content and linkage are automatically updated.
- Sticky layout container is fade-in and fade-out animated when featureis respectively enabled and disabled.
- Sticky container can be elevated only if the header item layout has elevation (Do notexaggerate with elevation).
{@code FrameLayout}as following:<FrameLayout android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v7.widget.RecyclerView android:id="@+id/recycler_view" android:layout_width="match_parent" android:layout_height="match_parent"/> </FrameLayout>- Parameters:
sticky- true to initialize sticky headers with default container, false to disable them
-
setStickyHeaders
FlexibleAdapter<T> setStickyHeaders(boolean sticky, @Nullable() ViewGroup stickyContainer)
Enables/Disables the sticky header feature with a custom sticky layout container.
Important: Read the javaDoc of the overloaded method setStickyHeaders.
- Parameters:
sticky- true to initialize sticky headers, false to disable themstickyContainer- user defined and already inflated sticky layout that willhold the sticky header itemViews
-
getStickyHeaderElevation
int getStickyHeaderElevation()
Gets the layout in dpi elevation for sticky header.
Note: This setting is ignored if the header item has already an elevation. Theheader elevation overrides this setting.
-
setStickyHeaderElevation
FlexibleAdapter<T> setStickyHeaderElevation(int stickyElevation)
Sets the elevation in dpi for the sticky header layout.
Note: This setting is ignored if the header item has already an elevation. Theheader elevation overrides this setting.
Default value is 0 dpi.- Parameters:
stickyElevation- the elevation in dpi
-
setDisplayHeadersAtStartUp
FlexibleAdapter<T> setDisplayHeadersAtStartUp(boolean displayHeaders)
Sets if all headers should be shown at startup by the Adapter automatically.
If called, this method won't trigger
Note: Headers can only be shown or hidden all together.{@code notifyItemInserted()}and scrollinganimations are instead performed if the header item was configured with animation:Headers will be loaded/bound along with others items.Default value is
{@code false}(headers are not shown at startup).- Parameters:
displayHeaders- true to display headers, false to keep them hidden
-
showAllHeaders
FlexibleAdapter<T> showAllHeaders()
Shows all headers in the RecyclerView at their linked position.
If called at startup, this method will trigger
Note: Headers can only be shown or hidden all together.{@code notifyItemInserted}for adifferent loading effect: Headers will be inserted after the items!
-
hideAllHeaders
void hideAllHeaders()
Hides all headers from the RecyclerView.
Headers can be shown or hidden all together.
-
getItemViewType
int getItemViewType(int position)
You CANNOT override this method:
{@code FlexibleAdapter}delegates the ViewTypedefinition via{@code IFlexible.getLayoutRes()}so ViewTypes are automatically mapped(AutoMap).- Parameters:
position- position for which ViewType is requested
-
onCreateViewHolder
@NonNull() RecyclerView.ViewHolder onCreateViewHolder(@NonNull() ViewGroup parent, int viewType)
You CANNOT override this method to create the ViewHolder,
{@code FlexibleAdapter}delegates the creation via{@code IFlexible.createViewHolder()}.HELP: To know how to implement AutoMap for ViewTypes please refer to theFlexibleAdapter Wiki Pageon GitHub.
-
onBindViewHolder
void onBindViewHolder(@NonNull() RecyclerView.ViewHolder holder, int position)
You CANNOT override this method to bind the items.
{@code FlexibleAdapter}delegatesthe binding to the corresponding item via{@code IFlexible.bindViewHolder()}.HELP: To know how to implement AutoMap for ViewTypes please refer to theFlexibleAdapter Wiki Pageon GitHub.
-
onBindViewHolder
void onBindViewHolder(@NonNull() RecyclerView.ViewHolder holder, int position, @NonNull() List payloads)
Same concept of
{@code #onBindViewHolder()}but with Payload.
-
onViewAttachedToWindow
@CallSuper() void onViewAttachedToWindow(@NonNull() RecyclerView.ViewHolder holder)
-
onViewDetachedFromWindow
@CallSuper() void onViewDetachedFromWindow(@NonNull() RecyclerView.ViewHolder holder)
-
onViewRecycled
@CallSuper() void onViewRecycled(@NonNull() RecyclerView.ViewHolder holder)
-
isTopEndless
boolean isTopEndless()
-
setTopEndless
void setTopEndless(boolean topEndless)
Sets endless scrolling from the top. All item will be added to the top of the list.Default value is
{@code false}(bottom endless scrolling).- Parameters:
topEndless- true to enable endless scrolling from the top, false from the bottom
-
isEndlessScrollEnabled
boolean isEndlessScrollEnabled()
Evaluates if the Adapter is in Endless Scroll mode. When no more load, this method willreturn
{@code false}. To enable again the progress item you MUST be set again.
-
getEndlessCurrentPage
int getEndlessCurrentPage()
Provides the current endless page if the page size limit is set, if not set the returnedvalue is always 0.
-
getEndlessPageSize
int getEndlessPageSize()
The current setting for the endless page size limit.
Tip: This limit is ignored if value is 0.
-
setEndlessPageSize
FlexibleAdapter<T> setEndlessPageSize(int endlessPageSize)
Sets the limit to automatically disable the endless feature when coming items size is lessthan the page size.
When endless feature is disabled a notifyItemChanged with payload NO_MORE_LOAD will be triggered on the progressItem, so you can display amessage or change the views in this item.
Default value is 0 (limit is ignored).- Parameters:
endlessPageSize- the size limit for each page
-
getEndlessTargetCount
int getEndlessTargetCount()
The current setting for the endless target item count limit.
Tip: This limit is ignored if value is 0.
-
setEndlessTargetCount
FlexibleAdapter<T> setEndlessTargetCount(int endlessTargetCount)
Sets the limit to automatically disable the endless feature when the total items count inthe Adapter is equals or bigger than the target count.
When endless feature is disabled a notifyItemChanged with payload NO_MORE_LOAD will be triggered on the progressItem, so you can display amessage or change the views in this item.
Default value is 0 (limit is ignored).- Parameters:
endlessTargetCount- the total items count limit
-
setLoadingMoreAtStartUp
FlexibleAdapter<T> setLoadingMoreAtStartUp(boolean enable)
Sets if Endless / Loading More should be triggered at start-up, especially when thelist is empty.
Default value is
{@code false}.- Parameters:
enable- true to trigger a loading at start up, false to trigger loading with binding
-
setEndlessProgressItem
FlexibleAdapter<T> setEndlessProgressItem(@Nullable() T progressItem)
Sets the progressItem to be displayed at the end of the list and activate the Loading Morefeature.
Using this method, the EndlessScrollListener won't be called so that you canhandle a click event to load more items upon a user request.
To correctly implement "Load more upon a user request" check the Wiki page of this library.- Parameters:
progressItem- the item representing the progress bar
-
setEndlessScrollListener
FlexibleAdapter<T> setEndlessScrollListener(@Nullable() FlexibleAdapter.EndlessScrollListener endlessScrollListener, @NonNull() T progressItem)
Sets the progressItem to be displayed at the end of the list and Sets the callback toautomatically load more items asynchronously(your duty) (no further user action is neededbut the scroll).
- Parameters:
endlessScrollListener- the callback to invoke the asynchronous loadingprogressItem- the item representing the progress bar
-
setEndlessScrollThreshold
FlexibleAdapter<T> setEndlessScrollThreshold(int thresholdItems)
Sets the minimum number of items still to bind to start the automatic loading.
Default value is 1.
- Parameters:
thresholdItems- minimum number of unbound items to start loading more items
-
onLoadMoreComplete
void onLoadMoreComplete(@Nullable() List<T> newItems)
To call when more items are successfully loaded.
When noMoreLoad OR onError OR onCancel, pass empty list or null to hide theprogressItem.
In this case the ProgressItem is removed immediately.- Parameters:
newItems- the list of the new items, can be empty or null
-
onLoadMoreComplete
void onLoadMoreComplete(@Nullable() List<T> newItems, long delay)
Call this method to complete the action of the Loading more items.
When noMoreLoad OR onError OR onCancel, pass empty list or null to hide theprogressItem. When limits are set, endless feature will be disabled. To enableagain call setEndlessProgressItem.
Optionally you can pass a delay time to still display the item with the latest informationinside. The message has to be handled inside the{@code bindViewHolder}of the item.A notifyItemChanged with payload NO_MORE_LOAD will be triggered on the progressItem, so you can display a message or change the views inthis item.
- Parameters:
newItems- the list of the new items, can be empty or nulldelay- the delay used to remove the progress item or -1 to disable theloading forever and to keep the progress item visible.
-
isAutoCollapseOnExpand
boolean isAutoCollapseOnExpand()
-
setAutoCollapseOnExpand
FlexibleAdapter<T> setAutoCollapseOnExpand(boolean collapseOnExpand)
Automatically collapse all previous expanded parents before expand the new clicked parent.
Default value is
Tip: This parameter works in collaboration with setMinCollapsibleLevel.{@code false}(disabled).- Parameters:
collapseOnExpand- true to collapse others items, false to just expand the current
-
isRecursiveCollapse
boolean isRecursiveCollapse()
-
setRecursiveCollapse
FlexibleAdapter<T> setRecursiveCollapse(boolean collapseSubLevels)
Automatically collapse all inner sub expandable when higher parent is collapsed.By keeping this parameter
{@code false}, their expanded status remains{@code expanded=true}so when the higher parent is expanded again, the sub expandables will appear again expanded.Default value is
Tip: This parameter works in collaboration with setMinCollapsibleLevel.{@code false}(keep expanded status).- Parameters:
collapseSubLevels- true to allow inner sub expandable to collapse, false to keep the expanded status
-
isAutoScrollOnExpand
boolean isAutoScrollOnExpand()
-
setAutoScrollOnExpand
FlexibleAdapter<T> setAutoScrollOnExpand(boolean scrollOnExpand)
Automatically scroll the clicked expandable item to the first visible position.
Default value is
Note: This works ONLY in combination with{@code false}(disabled).{@code SmoothScrollLinearLayoutManager}or with{@code SmoothScrollGridLayoutManager}available in UI extension.- Parameters:
scrollOnExpand- true to enable automatic scroll, false to disable
-
isExpanded
boolean isExpanded(int position)
- Parameters:
position- the position of the item to check
-
isExpanded
boolean isExpanded(@Nullable() T item)
Checks if the provided item is an IExpandable instance and is expanded.
- Parameters:
item- the item to check
-
isExpandable
boolean isExpandable(@Nullable() T item)
Checks if the provided item is an IExpandable instance.
- Parameters:
item- the item to check
-
getMinCollapsibleLevel
int getMinCollapsibleLevel()
-
setMinCollapsibleLevel
FlexibleAdapter<T> setMinCollapsibleLevel(int minCollapsibleLevel)
Sets the minimum level which all sub expandable items will be collapsed too.
Default value is mMinCollapsibleLevel (All levels including 0).
Tip: This parameter works in collaboration with setRecursiveCollapse.- Parameters:
minCollapsibleLevel- the minimum level to auto-collapse sub expandable items
-
hasSubItems
boolean hasSubItems(IExpandable expandable)
Utility method to check if the expandable item has sub items.
- Parameters:
expandable- the IExpandable object
-
getExpandableOf
@Nullable() IExpandable getExpandableOf(int position)
Retrieves the parent of a child for the provided position.
Only for a real child of an expanded parent.
- Parameters:
position- the position of the child item
-
getExpandableOf
@Nullable() IExpandable getExpandableOf(T child)
Retrieves the parent of a child.
Only for a real child of an expanded parent.
- Parameters:
child- the child item
-
getExpandablePositionOf
int getExpandablePositionOf(@NonNull() T child)
Retrieves the parent position of a child.
Only for a real child of an expanded parent.
- Parameters:
child- the child item
-
getSubPositionOf
int getSubPositionOf(@NonNull() T child)
Retrieves the sub position of any sub item in the section where it lays. First positioncorresponds to
{@code 0}.Works for items under header and under expandable too.
- Parameters:
child- any sub item of any section
-
getSiblingsOf
@NonNull() List<T> getSiblingsOf(@NonNull() T child)
Provides the full sub list where the child currently lays.
- Parameters:
child- the child item
-
getExpandedItems
@NonNull() List<T> getExpandedItems()
Provides a list of all expandable items that are currently expanded.
-
getExpandedPositions
@NonNull() List<Integer> getExpandedPositions()
Provides a list of all expandable positions that are currently expanded.
-
expand
int expand(int position)
Expands an item that is
{@code IExpandable}type, not yet expanded and if has subItems.If configured, automatic smooth scroll will be performed when necessary.
Parent won't be notified.- Parameters:
position- the position of the item to expand
-
expand
int expand(int position, boolean notifyParent)
Expands an item that is
{@code IExpandable}type, not yet expanded and if has subItems.If configured, automatic smooth scroll will be performed when necessary.
- Parameters:
position- the position of the item to expandnotifyParent- true to notify the parent with EXPANDED
-
expand
int expand(T item)
Convenience method to expand a single item. Parent will be notified.
Expands an item that is Expandable, not yet expanded, that has subItems andno child is selected.
If configured, automatic smooth scroll will be performed.- Parameters:
item- the item to expand, must be an Expandable and present in the list
-
expand
int expand(T item, boolean init)
Convenience method to initially expand a single item. Parent won't be notified.
Note: Must be used in combination when adding new items, those require to beinitially expanded.
WARNING!Expanded status is ignored if{@code init = true}: it will always attempt to expandthe item: If subItems are already visible and the new item has status expanded, thesubItems will appear duplicated(!) and the automatic smooth scroll will be skipped!- Parameters:
item- the item to expand, must be an Expandable and present in the listinit- true to initially expand item
-
expandAll
int expandAll()
Expands all
{@code IExpandable}items with minimum of level mMinCollapsibleLevel.
-
expandAll
int expandAll(int level)
Expands all
{@code IExpandable}items with at least the specified level.Parents will be notified.
- Parameters:
level- the minimum level to expand the sub expandable items
-
collapse
int collapse(int position)
Collapses an
{@code IExpandable}item that is already expanded and if no subItemis selected.Multilevel option behaviours:
{@code IExpandable}subItems, that are expanded, can be recursively collapsed,see setRecursiveCollapse.- You can set the minimum level to auto-collapse siblings,see setMinCollapsibleLevel.
- Parameters:
position- the position of the item to collapse
-
collapse
int collapse(int position, boolean notifyParent)
Same behaviors as collapse with possibility to notify/update the parent.
- Parameters:
position- the position of the item to collapsenotifyParent- notify the parent with COLLAPSED
-
collapseAll
int collapseAll()
Collapses all expandable items with the minimum level of mMinCollapsibleLevel.
-
collapseAll
int collapseAll(int level)
Collapses all expandable items with the level equals-higher than the specified level.
Parents will be notified.
- Parameters:
level- the level to start collapse sub expandable items
-
updateItem
void updateItem(@NonNull() T item)
Updates/Rebounds the itemView corresponding to the current position of theprovided item with the new content.
- Parameters:
item- the item with the new content
-
updateItem
void updateItem(@NonNull() T item, @Nullable() Object payload)
Updates/Rebounds the itemView corresponding to the current position of theprovided item with the new content.
- Parameters:
item- the item with the new contentpayload- any non-null user object to notify the current item (the payload will betherefore passed to the bind method of the item ViewHolder to optimize thecontent to update); pass null to rebind all fields of this item.
-
updateItem
void updateItem(int position, @NonNull() T item, @Nullable() Object payload)
Updates/Rebounds the itemView corresponding to the current position of theprovided item with the new content. Use updateItem if thenew content should be bound on the same position.
- Parameters:
position- the position where the new content should be updated and rebounditem- the item with the new contentpayload- any non-null user object to notify the current item (the payload will betherefore passed to the bind method of the item ViewHolder to optimize thecontent to update); pass null to rebind all fields of this item.
-
addItemWithDelay
void addItemWithDelay(int position, @NonNull() T item, long delay, boolean scrollToPosition)
Inserts the given item at desired position or Add item at last position with a delayand auto-scroll to the position.
Scrolling animation is automatically preserved, meaning that, notification for animationis ignored.
Useful at startup, when there's an item to add after Adapter Animations is completed.- Parameters:
position- position of the item to additem- the item to adddelay- a non-negative delayscrollToPosition- true if RecyclerView should scroll after item has been added,false otherwise
-
addItem
boolean addItem(@NonNull() T item)
Simply append the provided item to the end of the list.
Convenience method of addItem with
{@code position = getMainItemCount()}.- Parameters:
item- the item to add
-
addItem
boolean addItem(int position, @NonNull() T item)
Inserts the given item at the specified position or Adds the item to the end of the list(no matters if the new position is out of bounds!).
- Parameters:
position- position inside the list, if negative, items will be added to the enditem- the item to add
-
addItems
boolean addItems(int position, @NonNull() List<T> items)
Inserts a set of items at specified position or Adds the items to the end of the list(no matters if the new position is out of bounds!).
Note:- When all headers are shown, if exists, the header of this item will be shown as well,unless it's already shown, so it won't be shown twice.- Items will be always added between any scrollable header and footers.
- Parameters:
position- position inside the list, if negative, items will be added to the enditems- the set of items to add
-
addSubItem
boolean addSubItem(int parentPosition, int subPosition, @NonNull() T item)
Convenience method of addSubItem.In this case parent item will never be expanded if it is collapsed.
-
addSubItem
boolean addSubItem(int parentPosition, int subPosition, @NonNull() T item, boolean expandParent, @Nullable() Object payload)
Convenience method of addSubItems.Optionally you can pass any payload to notify the parent about the change and optimizethe view binding.
- Parameters:
parentPosition- position of the expandable item that shall contain the subItemsubPosition- the position of the subItem in the expandable listitem- the subItem to add in the expandable listexpandParent- true to initially expand the parent (if needed) and after to addthe subItem, false to simply add the subItem to the parentpayload- 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
-
addSubItems
boolean addSubItems(int parentPosition, int subPosition, @NonNull() List<T> items)
Convenience method of addSubItems.In this case parent item will never be expanded if it is collapsed.
-
addSubItems
boolean addSubItems(int parentPosition, int subPosition, @NonNull() List<T> items, boolean expandParent, @Nullable() Object payload)
Convenience method of addSubItems.Optionally you can pass any payload to notify the parent about the change and optimizethe view binding.
- Parameters:
parentPosition- position of the expandable item that shall contain the subItemssubPosition- the start position in the parent where the new items shall be inserteditems- the list of the subItems to addexpandParent- true to initially expand the parent (if needed) and after to addthe subItems, false to simply add the subItems to the parentpayload- 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
-
addSection
int addSection(@NonNull() IHeader header)
Adds and shows an empty section to the top (position = 0).
-
addSection
int addSection(@NonNull() IHeader header, @Nullable() Comparator<IFlexible> comparator)
Adds and shows an empty section. The new section is a IHeader item and theposition is calculated after sorting the data set.
- To add Sections to the top, set null the Comparator object or simply call addSection;- To add Sections to the bottom or in the middle, implement a Comparatorobject able to support all the item types this Adapter is displaying or aClassCastException will be raised.
- Parameters:
header- the section header item to addcomparator- the criteria to sort the Data Set used to extract the correct positionof the new header
-
addItemToSection
int addItemToSection(@NonNull() ISectionable sectionable, @Nullable() IHeader header, @Nullable() Comparator<IFlexible> comparator)
Adds a new item in a section when the relative position is unknown.
The header can be a
The Comparator object must support all the item types this Adapter is displaying ora ClassCastException will be raised.{@code IExpandable}type or{@code IHeader}type.- Parameters:
sectionable- the item to addheader- the section receiving the new itemcomparator- the criteria to sort the sectionItems used to extract the correct positionof the new item in the section
-
addItemToSection
int addItemToSection(@NonNull() ISectionable sectionable, @Nullable() IHeader header, int index)
Adds a new item in a section when the relative position is known.
The header can be a
{@code IExpandable}type or{@code IHeader}type.- Parameters:
sectionable- the item to addheader- the section receiving the new itemindex- the known relative position where to add the new item into the section
-
clear
void clear()
This method clears everything: main items, Scrollable Headers and Footers andeverything else is displayed.
-
clearAllBut
void clearAllBut(Array<Integer> viewTypes)
Clears the Adapter list retaining Scrollable Headers and Footers and all items of thetype provided as parameter.
Tip:- This method is opposite of removeItemsOfType.
- Parameters:
viewTypes- the viewTypes to retain
-
removeItemWithDelay
void removeItemWithDelay(@NonNull() T item, long delay, boolean permanent)
Removes the given item after the given delay.
Scrolling animation is automatically preserved, meaning that notification for animationis ignored.
- Parameters:
item- the item to adddelay- a non-negative delaypermanent- true to permanently delete the item (no undo), false otherwise
-
removeSection
void removeSection(IHeader header)
Removes all items of a section, header included.
For header that is also expandable, it's equivalent to remove a single item.
- Parameters:
header- the head of the section
-
removeItem
void removeItem(int position)
Convenience method of removeItem providing CHANGE as payload for the parent item.
- Parameters:
position- the position of item to remove
-
removeItem
void removeItem(int position, @Nullable() Object payload)
Removes an item from the internal list and notify the change.
The item is retained for an eventual Undo.
This method delegates the removal to removeRange.- Parameters:
position- The position of item to removepayload- 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
-
removeItems
void removeItems(@NonNull() List<Integer> selectedPositions)
Convenience method of removeItems providing the default CHANGE for the parent items.
-
removeItems
void removeItems(@Nullable() List<Integer> selectedPositions, @Nullable() Object payload)
Removes items by ranges, auto-collapse expanded items and notify the change.
Every item is retained for an eventual Undo.
Optionally you can pass any payload to notify the parent items about the change tooptimize the view binding.This method delegates the removal to removeRange.
- Parameters:
selectedPositions- list with item positions to removepayload- 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
-
removeItemsOfType
void removeItemsOfType(Array<Integer> viewTypes)
Selectively removes all items of the type provided as parameter.
Tips:- This method is opposite of clearAllBut.- View types of Scrollable Headers and Footers are ignored!
- Parameters:
viewTypes- the viewTypes to remove
-
removeRange
void removeRange(int positionStart, int itemCount)
Same as removeRange, but in this case the parent will not benotified about the change, if children are removed.
-
removeRange
void removeRange(int positionStart, int itemCount, @Nullable() Object payload)
Removes a list of consecutive items and notify the change.
If the item, resulting from the provided position:
- is not expandable with no parent, it is removed as usual.- is not expandable with a parent, it is removed only if the parent is expanded.- is expandable implementing IExpandable, it is removed as usual, butit will be collapsed if expanded.- has a IHeader item, the header will be automatically linked to the first itemafter the range or can remain orphan.Optionally you can pass any payload to notify the parent or the headerabout the change and optimize the view binding.
- Parameters:
positionStart- the start position of the first itemitemCount- how many items should be removedpayload- 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
-
removeAllSelectedItems
void removeAllSelectedItems()
Convenience method to remove all items that are currently selected.
Parent will not be notified about the change if a child is removed.
-
removeAllSelectedItems
void removeAllSelectedItems(@Nullable() Object payload)
Convenience method to remove all items that are currently selected.
Optionally, the parent item can be notified about the change if a child is removed,by providing any non-null payload.
- 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
-
isPermanentDelete
boolean isPermanentDelete()
Returns if items will be deleted immediately when deletion is requested.
Default value is
{@code true}(Undo mechanism is disabled).
-
isRestoreWithSelection
boolean isRestoreWithSelection()
Returns the current configuration to restore selections on Undo.
Default value is
{@code false}(selection is NOT restored).
-
setRestoreSelectionOnUndo
FlexibleAdapter<T> setRestoreSelectionOnUndo(boolean restoreSelection)
Gives the possibility to restore the selection on Undo, when restoreDeletedItems is called.
To use in combination with
Default value is{@code ActionMode}in order to not disable it.{@code false}(selection is NOT restored).- Parameters:
restoreSelection- true to have restored items still selected, false to empty selections
-
restoreDeletedItems
void restoreDeletedItems()
Restore items just removed.
Tip: If filter is active, only items that match that filter will be shown(restored).
-
confirmDeletion
void confirmDeletion()
Performs removal confirmation and cleans memory by synchronizing the internal list from deletion.
Note: This method is automatically called after timer is over in UndoHelper.
-
emptyBin
synchronized void emptyBin()
Cleans memory from items just removed.
Note: This method is automatically called after timer is over in UndoHelperand after a restoration.
-
isRestoreInTime
final synchronized boolean isRestoreInTime()
-
getDeletedItems
@NonNull() List<T> getDeletedItems()
-
getUndoPositions
@NonNull() List<Integer> getUndoPositions()
-
saveUndoPositions
void saveUndoPositions(@NonNull() List<Integer> undoPositions)
- Parameters:
undoPositions- the positions to Undo with UndoHelper when{@code Action.UPDATE}.
-
getExpandableOfDeletedChild
final IExpandable getExpandableOfDeletedChild(@NonNull() T child)
Retrieves the expandable of the deleted child.
- Parameters:
child- the deleted child
-
getDeletedChildren
@NonNull() final List<T> getDeletedChildren(IExpandable expandable)
Retrieves only the deleted children of the specified parent.
- Parameters:
expandable- the parent item
-
getCurrentChildren
@NonNull() final List<T> getCurrentChildren(@Nullable() IExpandable expandable)
Retrieves all the original children of the specified parent, filtering out all thedeleted children if any.
- Parameters:
expandable- the parent item
-
hasFilter
boolean hasFilter()
-
hasNewFilter
boolean hasNewFilter(Serializable constraint)
Checks if the filter is changed.
- Parameters:
constraint- the new filter entity
-
setFilter
void setFilter(@Nullable() Serializable filter)
Sets the new filter entity.
Note:
- Filter object must implement Serializable (
{@code String}does). - In case of free text (
{@code String}), filter is automatically trimmedand lowercase.
Tip: You can highlight filtered Text or Words using
{@code FlexibleUtils}from UI extension:{@code FlexibleUtils#highlightText(TextView, String, String)}{@code FlexibleUtils#highlightWords(TextView, String, String)}
- Parameters:
filter- the new filter entity for the items
- Filter object must implement Serializable (
-
getFilter
@Nullable() <F extends Serializable> F getFilter(Class<F> clazz)
Gets the current filter.
- Parameters:
clazz- The class type of filter to return (eg.
-
filterItems
void filterItems()
Filters the current list with the filter previously set with setFilter.
-
filterItems
void filterItems(long delay)
Same as filterItems but with a delay in the execution, useful to grabmore characters from user before starting the search.
- Parameters:
delay- any non-negative delay
-
filterItems
void filterItems(@NonNull() List<T> unfilteredItems, long delay)
WATCH OUT! ADAPTER ALREADY CREATES A COPY OF THE PROVIDED LIST: due to internalmechanism, items are removed and/or added in order to animate items in the final list.
Same as filterItems, but with a delay in the execution, useful to grabmore characters from user before starting the search.
- Parameters:
unfilteredItems- the list to filterdelay- any non-negative delay
-
filterItems
void filterItems(@NonNull() List<T> unfilteredItems)
WATCH OUT! ADAPTER ALREADY CREATES A COPY OF THE PROVIDED LIST: due to internalmechanism, items are removed and/or added in order to animate items in the final list.
This method filters the provided list with the filter previously set with setFilter. Filter object can be of any type.
Important notes:- The Filter is always executed in background, asynchronously.The method onPostFilter is called after the filter task is completed.
- This method calls filterObject for each filterable item.
- Any pending deleted items are always deleted before filter is performed: onDeleteConfirmed (implemented in
{@code UndoHelper})is therefore invoked. - Expandable items are picked up and displayed if at least a child is collected bythe current filter.
- Filter is skipped while endless feature is active (loading).
- If filter is
{@code null}, the provided list is the new list plus anyScrollable Headers and Footers if existent. - Items are animated thanks to animateTo BUT a limit of {@value #ANIMATE_TO_LIMIT} (default) items is set. Tip: Above this limit, notifyDataSetChanged will be called to improve performance. You can changethis limit by calling setAnimateToLimit.
- Parameters:
unfilteredItems- the list to filter
-
isFiltering
boolean isFiltering()
-
setAnimateToLimit
FlexibleAdapter<T> setAnimateToLimit(int limit)
Tunes the limit after the which the synchronization animations, occurred duringupdateDataSet and filter operations, are skipped and notifyDataSetChanged will be called instead.
Default value is {@value #ANIMATE_TO_LIMIT} items, number new items.
- Parameters:
limit- the number of new items that, when reached, will skip synchronization animations
-
isAnimateChangesWithDiffUtil
boolean isAnimateChangesWithDiffUtil()
-
setAnimateChangesWithDiffUtil
FlexibleAdapter<T> setAnimateChangesWithDiffUtil(boolean useDiffUtil)
Whether use DiffUtil to calculate the changes between 2 lists after Update orFilter operations. If disabled, the advanced default calculation will be used instead.
A time, to compare the 2 different approaches, is calculated and displayed in the log.To see the logs call enableLogs before creating the Adapter instance!
Default value is{@code false}(default calculation is used).- Parameters:
useDiffUtil- true to switch the calculation and use DiffUtil, false to use the defaultcalculation.
-
getItemTouchHelper
final ItemTouchHelper getItemTouchHelper()
Used by onTouch to start Drag or Swipe when HandleView is touched.
-
getItemTouchHelperCallback
final ItemTouchHelperCallback getItemTouchHelperCallback()
Returns the customization of the ItemTouchHelperCallback or the default if it wasn't setbefore.
-
setItemTouchHelperCallback
final FlexibleAdapter<T> setItemTouchHelperCallback(ItemTouchHelperCallback itemTouchHelperCallback)
Sets a custom callback implementation for item touch.
If called, Helper will be reinitialized.
If not called, the default Helper will be used.- Parameters:
itemTouchHelperCallback- the custom callback implementation for item touch
-
isLongPressDragEnabled
final boolean isLongPressDragEnabled()
Returns whether ItemTouchHelper should start a drag and drop operation if an item islong pressed.
Default value is
{@code false}.
-
setLongPressDragEnabled
final FlexibleAdapter<T> setLongPressDragEnabled(boolean longPressDragEnabled)
Enables / Disables the drag of the item when long-press the entire itemView.
Note: This will skip LongClick on the view in order to handle the LongPress,however the LongClick listener will be called if necessary in the new onActionStateChanged.
Requires the Adapter being attached to the RecyclerView.Default value is{@code false}.- Parameters:
longPressDragEnabled- true to activate, false otherwise
-
isHandleDragEnabled
final boolean isHandleDragEnabled()
Returns whether ItemTouchHelper should start a drag and drop operation by touching itshandle.
Default value is
To use, it is sufficient to set the HandleView by calling setDragHandleView.{@code false}.
-
setHandleDragEnabled
final FlexibleAdapter<T> setHandleDragEnabled(boolean handleDragEnabled)
Enables / Disables the drag of the item with a handle view.Requires the Adapter being attached to the RecyclerView.
Default value is
{@code false}.- Parameters:
handleDragEnabled- true to activate, false otherwise
-
isSwipeEnabled
final boolean isSwipeEnabled()
Returns whether ItemTouchHelper should start a swipe operation if a pointer is swipedover the View.
Default value is
{@code false}.
-
setSwipeEnabled
final FlexibleAdapter<T> setSwipeEnabled(boolean swipeEnabled)
Enables full the swipe of the items.
Note:
- Requires the Adapter being attached to the RecyclerView.
- Must override
{@code getFrontView}and at least a rear View:{@code getRearLeftView}and/or{@code getRearRightView}in the{@code FlexibleViewHolder}.
{@code false}.- Parameters:
swipeEnabled- true to activate, false otherwise
-
moveItem
void moveItem(int fromPosition, int toPosition)
Moves the item placed at position
{@code fromPosition}to the position{@code toPosition}.- Selection of moved element is preserved.- If item is an expandable, it is collapsed and then expanded at the new position.- Parameters:
fromPosition- previous position of the itemtoPosition- new position of the item
-
moveItem
void moveItem(int fromPosition, int toPosition, @Nullable() Object payload)
Moves the item placed at position
{@code fromPosition}to the position{@code toPosition}.- Selection of moved element is preserved.- If item is an expandable, it is collapsed and then expanded at the new position.- Parameters:
fromPosition- previous position of the itemtoPosition- new position of the itempayload- allows to update the content of the item just moved
-
swapItems
void swapItems(List<T> list, int fromPosition, int toPosition)
Swaps the elements of list at indices fromPosition and toPosition and notify the change.
Selection of swiped elements is automatically updated.
- Parameters:
fromPosition- previous position of the item.toPosition- new position of the item.
-
onActionStateChanged
void onActionStateChanged(RecyclerView.ViewHolder viewHolder, int actionState)
Called when the first registers an item as being moved or swipedor when has been released.
Override this method to receive touch events with its state.
-
shouldMove
boolean shouldMove(int fromPosition, int toPosition)
Evaluate if positions are compatible for swapping.
-
onItemMove
@CallSuper() boolean onItemMove(int fromPosition, int toPosition)
Called when an item has been dragged far enough to trigger a move. This is calledevery time an item is shifted, and not at the end of a "drop" event.
Implementations should call Adapter#notifyItemMoved(int, int)after adjusting the underlying data to reflect this move.
-
onItemSwiped
@CallSuper() void onItemSwiped(int position, int direction)
Called when an item has been dismissed by a swipe.
Implementations should decide to call or not Adapter#notifyItemRemoved(int)after adjusting the underlying data to reflect this removal.
-
smoothScrollToPosition
void smoothScrollToPosition(int position)
Performs safe smooth scroll with a delay of {@value #AUTO_SCROLL_DELAY} ms.
- Parameters:
position- the position to scroll to.
-
invalidateItemDecorations
final void invalidateItemDecorations(long delay)
Helper method to post invalidate the item decorations after the provided delay.
The delay will give time to the LayoutManagers to complete the layout of the child views.
Tip: A delay of{@code 100ms}should be enough, anyway it can be customized.- Parameters:
delay- delay to invalidate the decorations
-
onSaveInstanceState
void onSaveInstanceState(Bundle outState)
Save the state of the current expanded items.
- Parameters:
outState- Current state
-
onRestoreInstanceState
void onRestoreInstanceState(Bundle savedInstanceState)
Restore the previous state of the expanded items.
- Parameters:
savedInstanceState- Previous state
-
-
-
-