public class FlexibleAdapter<T extends IFlexible> extends AnimatorAdapter implements ItemTouchHelperCallback.AdapterCallback
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:
IHeader and ISectionable items;IExpandable items;AnimatorAdapter that extends SelectableAdapter
AnimatorAdapter,
SelectableAdapter,
IFlexible,
FlexibleViewHolder,
ExpandableViewHolder| Modifier and Type | Class and Description |
|---|---|
static class |
FlexibleAdapter.DiffUtilCallback<T extends IFlexible>
Use
FlexibleAdapter.DiffUtilCallback.setItems(List, List) to set the old and new lists, that are available as:
- protected List<T> oldItems;
- protected List<T> newItems; |
static interface |
FlexibleAdapter.EndlessScrollListener |
class |
FlexibleAdapter.HandlerCallback
Handler callback for delayed actions.
|
static interface |
FlexibleAdapter.OnActionStateListener |
static interface |
FlexibleAdapter.OnDeleteCompleteListener |
static interface |
FlexibleAdapter.OnFilterListener |
static interface |
FlexibleAdapter.OnItemClickListener |
static interface |
FlexibleAdapter.OnItemLongClickListener |
static interface |
FlexibleAdapter.OnItemMoveListener |
static interface |
FlexibleAdapter.OnItemSwipeListener |
static interface |
FlexibleAdapter.OnStickyHeaderChangeListener |
static interface |
FlexibleAdapter.OnUpdateListener |
SelectableAdapter.Mode| Modifier and Type | Field and Description |
|---|---|
protected int |
FILTER |
protected int |
LOAD_MORE_COMPLETE |
protected FlexibleAdapter.OnDeleteCompleteListener |
mDeleteCompleteListener |
protected FlexibleAdapter.EndlessScrollListener |
mEndlessScrollListener |
protected FlexibleAdapter.OnFilterListener |
mFilterListener |
protected android.os.Handler |
mHandler |
protected android.view.LayoutInflater |
mInflater |
FlexibleAdapter.OnItemClickListener |
mItemClickListener |
FlexibleAdapter.OnItemLongClickListener |
mItemLongClickListener |
protected FlexibleAdapter.OnItemMoveListener |
mItemMoveListener |
protected FlexibleAdapter.OnItemSwipeListener |
mItemSwipeListener |
protected FlexibleAdapter.OnStickyHeaderChangeListener |
mStickyHeaderChangeListener |
protected FlexibleAdapter.OnUpdateListener |
mUpdateListener |
protected int |
UPDATE |
isFastScroll, mFastScrollerDelegate, mLastItemInActionMode, mRecyclerView, mSelectAll| Constructor and Description |
|---|
FlexibleAdapter(java.util.List<T> items)
Simple Constructor with NO listeners!
|
FlexibleAdapter(java.util.List<T> items,
java.lang.Object listeners)
Main Constructor with all managed listeners for ViewHolder and the Adapter itself.
|
FlexibleAdapter(java.util.List<T> items,
java.lang.Object listeners,
boolean stableIds)
Same as
FlexibleAdapter(List, Object) with possibility to set stableIds. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
addItem(int position,
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!).
|
boolean |
addItem(T item)
Simply append the provided item to the end of the list.
|
boolean |
addItems(int position,
java.util.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!).
|
int |
addItemToSection(ISectionable sectionable,
IHeader header,
java.util.Comparator<IFlexible> comparator)
Adds a new item in a section when the relative position is unknown.
|
int |
addItemToSection(ISectionable sectionable,
IHeader header,
int index)
Adds a new item in a section when the relative position is known.
|
void |
addItemWithDelay(int position,
T item,
long delay,
boolean scrollToPosition)
Inserts the given item at desired position or Add item at last position with a delay
and auto-scroll to the position.
|
FlexibleAdapter<T> |
addListener(java.lang.Object listener)
Initializes the listener(s) of this Adapter.
|
boolean |
addScrollableFooter(T footerItem)
Adds a Scrollable Footer.
|
void |
addScrollableFooterWithDelay(T footerItem,
long delay,
boolean scrollToPosition)
Same as
addScrollableFooter(IFlexible) but with a delay and the possibility to
scroll to it. |
boolean |
addScrollableHeader(T headerItem)
Adds a Scrollable Header.
|
void |
addScrollableHeaderWithDelay(T headerItem,
long delay,
boolean scrollToPosition)
Same as
addScrollableHeader(IFlexible) but with a delay and the possibility to
scroll to it. |
int |
addSection(IHeader header)
Adds and shows an empty section to the top (position = 0).
|
int |
addSection(IHeader header,
java.util.Comparator<IFlexible> comparator)
Adds and shows an empty section.
|
boolean |
addSubItem(int parentPosition,
int subPosition,
T item)
Convenience method of
addSubItem(int, int, IFlexible, boolean, Object). |
boolean |
addSubItem(int parentPosition,
int subPosition,
T item,
boolean expandParent,
java.lang.Object payload)
Convenience method of
addSubItems(int, int, IExpandable, List, boolean, Object). |
boolean |
addSubItems(int parentPosition,
int subPosition,
java.util.List<T> items)
Convenience method of
addSubItems(int, int, List, boolean, Object). |
boolean |
addSubItems(int parentPosition,
int subPosition,
java.util.List<T> items,
boolean expandParent,
java.lang.Object payload)
Convenience method of
addSubItems(int, int, IExpandable, List, boolean, Object). |
boolean |
areHeadersShown()
Evaluates if Adapter has headers shown.
|
boolean |
areHeadersSticky()
Evaluates if Adapter can actually display sticky headers on the top.
|
int |
calculatePositionFor(java.lang.Object item,
java.util.Comparator<IFlexible> comparator)
New method to extract the new position where the item should lay.
|
void |
clear()
This method clears everything: main items, Scrollable Headers and Footers and
everything else is displayed.
|
void |
clearAllBut(java.lang.Integer... viewTypes)
Clears the Adapter list retaining Scrollable Headers and Footers and all items of the
type provided as parameter.
|
void |
clearSelection()
Clears the selection status for all items one by one and it doesn't stop animations in the items.
|
int |
collapse(int position)
Collapses an
IExpandable item that is already expanded and if no subItem
is selected. |
int |
collapse(int position,
boolean notifyParent)
Same behaviors as
collapse(int) with possibility to notify/update the parent. |
int |
collapseAll()
Collapses all expandable items with the minimum level of
mMinCollapsibleLevel. |
int |
collapseAll(int level)
Collapses all expandable items with the level equals-higher than the specified level.
|
void |
confirmDeletion()
Performs removal confirmation and cleans memory by synchronizing the internal list from deletion.
|
boolean |
contains(T item)
This method is never called internally.
|
void |
emptyBin()
Cleans memory from items just removed.
|
void |
ensureHeaderParent()
Ensures the current sticky header view is correctly displayed in the sticky layout.
|
int |
expand(int position)
Expands an item that is
IExpandable type, not yet expanded and if has subItems. |
int |
expand(int position,
boolean notifyParent)
Expands an item that is
IExpandable type, not yet expanded and if has subItems. |
int |
expand(T item)
Convenience method to expand a single item.
|
int |
expand(T item,
boolean init)
Convenience method to initially expand a single item.
|
int |
expandAll()
Expands all
IExpandable items with minimum of level mMinCollapsibleLevel. |
int |
expandAll(int level)
Expands all
IExpandable items with at least the specified level. |
FlexibleAdapter<T> |
expandItemsAtStartUp()
Maps and expands items that are initially configured to be shown as expanded.
|
void |
filterItems()
Filters the current list with the filter previously set with
setFilter(Serializable). |
void |
filterItems(java.util.List<T> unfilteredItems)
WATCH OUT!
|
void |
filterItems(java.util.List<T> unfilteredItems,
long delay)
WATCH OUT!
|
void |
filterItems(long delay)
Same as
filterItems() but with a delay in the execution, useful to grab
more characters from user before starting the search. |
protected boolean |
filterObject(T item,
java.io.Serializable constraint)
This method checks if the provided object is a type of
IFilterable interface,
if yes, performs the filter on the implemented method IFilterable.filter(Serializable). |
int |
getCardinalPositionOf(IFlexible item)
Retrieves the position of the Main item in the Adapter list excluding the scrollable Headers.
|
java.util.List<T> |
getCurrentChildren(IExpandable expandable)
Retrieves all the original children of the specified parent, filtering out all the
deleted children if any.
|
java.util.List<T> |
getCurrentItems()
Gets an unmodifiable view of the internal list of items.
|
java.util.List<T> |
getDeletedChildren(IExpandable expandable)
Retrieves only the deleted children of the specified parent.
|
java.util.List<T> |
getDeletedItems() |
int |
getEndlessCurrentPage()
Provides the current endless page if the page size limit is set, if not set the returned
value is always 0.
|
int |
getEndlessPageSize()
The current setting for the endless page size limit.
|
int |
getEndlessTargetCount()
The current setting for the endless target item count limit.
|
IExpandable |
getExpandableOf(int position)
Retrieves the parent of a child for the provided position.
|
IExpandable |
getExpandableOf(T child)
Retrieves the parent of a child.
|
IExpandable |
getExpandableOfDeletedChild(T child)
Retrieves the expandable of the deleted child.
|
int |
getExpandablePositionOf(T child)
Retrieves the parent position of a child.
|
java.util.List<T> |
getExpandedItems()
Provides a list of all expandable items that are currently expanded.
|
java.util.List<java.lang.Integer> |
getExpandedPositions()
Provides a list of all expandable positions that are currently expanded.
|
<F extends java.io.Serializable> |
getFilter(java.lang.Class<F> clazz)
Gets the current filter.
|
int |
getGlobalPositionOf(IFlexible item)
Retrieves the global position of the item in the Adapter list.
|
java.util.List<IHeader> |
getHeaderItems()
Retrieves all the header items.
|
IHeader |
getHeaderOf(T item)
Retrieves the header of the provided
ISectionable item. |
T |
getItem(int position)
Returns the object of the generic type T.
|
<S extends T> |
getItem(int position,
java.lang.Class<S> clazz)
Returns the object of specific type S.
|
int |
getItemCount()
Returns the total number of items in the data set held by the adapter (headers and footers
INCLUDED).
|
int |
getItemCountOfTypes(java.lang.Integer... viewTypes)
Provides the number of items currently displayed of one or more certain types.
|
long |
getItemId(int position)
This method is mostly used by the adapter if items have stableIds.
|
ItemTouchHelper |
getItemTouchHelper()
Used by
FlexibleViewHolder.onTouch(View, MotionEvent)
to start Drag or Swipe when HandleView is touched. |
ItemTouchHelperCallback |
getItemTouchHelperCallback()
Returns the customization of the ItemTouchHelperCallback or the default if it wasn't set
before.
|
int |
getItemViewType(int position)
You CANNOT override this method:
FlexibleAdapter delegates the ViewType
definition via IFlexible.getLayoutRes() so ViewTypes are automatically mapped
(AutoMap). |
int |
getMainItemCount()
Returns the total number of items in the data set held by the adapter.
|
int |
getMinCollapsibleLevel() |
int |
getSameTypePositionOf(IFlexible item)
Retrieves the position of any item in the Adapter counting only the items of the
same view type of the provided item and excluding all the others view types.
|
java.util.List<T> |
getScrollableFooters() |
java.util.List<T> |
getScrollableHeaders() |
IHeader |
getSectionHeader(int position)
Retrieves the
IHeader item of any specified position. |
java.util.List<java.lang.Integer> |
getSectionItemPositions(IHeader header)
Provides all the item positions that belongs to the section represented by the provided
header.
|
java.util.List<ISectionable> |
getSectionItems(IHeader header)
Provides all the items that belongs to the section represented by the provided header.
|
java.util.List<T> |
getSiblingsOf(T child)
Provides the full sub list where the child currently lays.
|
int |
getStickyHeaderElevation()
Gets the layout in dpi elevation for sticky header.
|
int |
getStickyPosition()
Returns the current position of the sticky header.
|
int |
getSubPositionOf(T child)
Retrieves the sub position of any sub item in the section where it lays.
|
long |
getTime() |
java.util.List<java.lang.Integer> |
getUndoPositions() |
boolean |
hasFilter() |
boolean |
hasHeader(T item)
Helper method to check if an item holds a header.
|
boolean |
hasNewFilter(java.io.Serializable constraint)
Checks if the filter is changed.
|
boolean |
hasSameHeader(T item,
IHeader header)
Checks if the item has a header and that header is the same of the provided one.
|
boolean |
hasSubItems(IExpandable expandable)
Utility method to check if the expandable item has sub items.
|
void |
hideAllHeaders()
Hides all headers from the RecyclerView.
|
void |
invalidateItemDecorations(long delay)
Helper method to post invalidate the item decorations after the provided delay.
|
boolean |
isAnimateChangesWithDiffUtil() |
boolean |
isAnyChildSelected() |
boolean |
isAnyParentSelected() |
boolean |
isAutoCollapseOnExpand() |
boolean |
isAutoScrollOnExpand() |
boolean |
isEmpty()
You can override this method to define your own concept of "Empty".
|
boolean |
isEnabled(int position)
Deprecated.
Use
isItemEnabled(int). |
boolean |
isEndlessScrollEnabled()
Evaluates if the Adapter is in Endless Scroll mode.
|
boolean |
isExpandable(T item)
Checks if the provided item is an
IExpandable instance. |
boolean |
isExpanded(int position) |
boolean |
isExpanded(T item)
Checks if the provided item is an
IExpandable instance and is expanded. |
boolean |
isFiltering() |
boolean |
isHandleDragEnabled()
Returns whether ItemTouchHelper should start a drag and drop operation by touching its
handle.
|
boolean |
isHeader(T item) |
boolean |
isItemEnabled(int position)
Checks if the current item has the property
enabled = true. |
boolean |
isLongPressDragEnabled()
Returns whether ItemTouchHelper should start a drag and drop operation if an item is
long pressed.
|
boolean |
isPermanentDelete()
Returns if items will be deleted immediately when deletion is requested.
|
boolean |
isRecursiveCollapse() |
boolean |
isRestoreInTime() |
boolean |
isRestoreWithSelection()
Returns the current configuration to restore selections on Undo.
|
boolean |
isScrollableHeaderOrFooter(int position)
Checks if at the provided position, the item is a Header or Footer.
|
boolean |
isScrollableHeaderOrFooter(T item)
Checks if at the provided item is a Header or Footer.
|
boolean |
isSelectable(int position)
Checks if the current item has the property
selectable = true. |
boolean |
isSwipeEnabled()
Returns whether ItemTouchHelper should start a swipe operation if a pointer is swiped
over the View.
|
boolean |
isTopEndless() |
void |
moveItem(int fromPosition,
int toPosition)
Moves the item placed at position
fromPosition to the position
toPosition. |
void |
moveItem(int fromPosition,
int toPosition,
java.lang.Object payload)
Moves the item placed at position
fromPosition to the position
toPosition. |
void |
onActionStateChanged(RecyclerView.ViewHolder viewHolder,
int actionState)
Called when the
ItemTouchHelper first registers an item as being moved or swiped
or when has been released. |
void |
onAttachedToRecyclerView(RecyclerView recyclerView)
Attaches the
FastScrollerDelegate to the RecyclerView if necessary. |
void |
onBindViewHolder(RecyclerView.ViewHolder holder,
int position)
You CANNOT override this method to bind the items.
|
void |
onBindViewHolder(RecyclerView.ViewHolder holder,
int position,
java.util.List payloads)
Same concept of
#onBindViewHolder() but with Payload. |
RecyclerView.ViewHolder |
onCreateViewHolder(android.view.ViewGroup parent,
int viewType)
You CANNOT override this method to create the ViewHolder,
FlexibleAdapter
delegates the creation via IFlexible.createViewHolder(). |
void |
onDetachedFromRecyclerView(RecyclerView recyclerView)
Detaches the
FastScrollerDelegate from the RecyclerView if necessary. |
boolean |
onItemMove(int fromPosition,
int toPosition)
Called when an item has been dragged far enough to trigger a move.
|
void |
onItemSwiped(int position,
int direction)
Called when an item has been dismissed by a swipe.
|
protected void |
onLoadMore(int position)
This method is called automatically when an item is bound.
|
void |
onLoadMoreComplete(java.util.List<T> newItems)
To call when more items are successfully loaded.
|
void |
onLoadMoreComplete(java.util.List<T> newItems,
long delay)
Call this method to complete the action of the Loading more items.
|
protected void |
onPostFilter()
This method is called after the execution of Async Filter, it calls the
implementation of the
FlexibleAdapter.OnFilterListener for the filterView. |
protected void |
onPostUpdate()
This method is called only in case of granular notifications (not when notifyDataSetChanged) and after the
execution of Async Update, it calls the implementation of the
FlexibleAdapter.OnUpdateListener for the emptyView. |
void |
onRestoreInstanceState(android.os.Bundle savedInstanceState)
Restore the previous state of the expanded items.
|
void |
onSaveInstanceState(android.os.Bundle outState)
Save the state of the current expanded items.
|
void |
onViewAttachedToWindow(RecyclerView.ViewHolder holder) |
void |
onViewDetachedFromWindow(RecyclerView.ViewHolder holder) |
void |
onViewRecycled(RecyclerView.ViewHolder holder) |
void |
removeAllScrollableFooters()
Removes all Scrollable Footers at once.
|
void |
removeAllScrollableHeaders()
Removes all Scrollable Headers at once.
|
void |
removeAllSelectedItems()
Convenience method to remove all items that are currently selected.
|
void |
removeAllSelectedItems(java.lang.Object payload)
Convenience method to remove all items that are currently selected.
|
void |
removeItem(int position)
Convenience method of
removeItem(int, Object) providing Payload.CHANGE
as payload for the parent item. |
void |
removeItem(int position,
java.lang.Object payload)
Removes an item from the internal list and notify the change.
|
void |
removeItems(java.util.List<java.lang.Integer> selectedPositions)
Convenience method of
removeItems(List, Object) providing the default
Payload.CHANGE for the parent items. |
void |
removeItems(java.util.List<java.lang.Integer> selectedPositions,
java.lang.Object payload)
Removes items by ranges, auto-collapse expanded items and notify the change.
|
void |
removeItemsOfType(java.lang.Integer... viewTypes)
Selectively removes all items of the type provided as parameter.
|
void |
removeItemWithDelay(T item,
long delay,
boolean permanent)
Removes the given item after the given delay.
|
FlexibleAdapter<T> |
removeListener(java.lang.Object listener)
Removes one listener from this Adapter.
|
void |
removeRange(int positionStart,
int itemCount)
Same as
removeRange(int, int, Object), but in this case the parent will not be
notified about the change, if children are removed. |
void |
removeRange(int positionStart,
int itemCount,
java.lang.Object payload)
Removes a list of consecutive items and notify the change.
|
void |
removeScrollableFooter(T footerItem)
Removes the provided Scrollable Footer.
|
void |
removeScrollableFooterWithDelay(T footerItem,
long delay)
Same as
removeScrollableFooter(IFlexible) but with a delay. |
void |
removeScrollableHeader(T headerItem)
Removes the provided Scrollable Header.
|
void |
removeScrollableHeaderWithDelay(T headerItem,
long delay)
Same as
removeScrollableHeader(IFlexible) but with a delay. |
void |
removeSection(IHeader header)
Removes all items of a section, header included.
|
void |
restoreDeletedItems()
Restore items just removed.
|
void |
saveUndoPositions(java.util.List<java.lang.Integer> undoPositions) |
void |
selectAll(java.lang.Integer... viewTypes)
Helper to automatically select all the items of the viewType equal to the viewType of
the first selected item.
|
FlexibleAdapter<T> |
setAnimateChangesWithDiffUtil(boolean useDiffUtil)
Whether use
DiffUtil to calculate the changes between 2 lists after Update or
Filter operations. |
FlexibleAdapter<T> |
setAnimateToLimit(int limit)
Tunes the limit after the which the synchronization animations, occurred during
updateDataSet and filter operations, are skipped and
#notifyDataSetChanged()
will be called instead. |
FlexibleAdapter<T> |
setAutoCollapseOnExpand(boolean collapseOnExpand)
Automatically collapse all previous expanded parents before expand the new clicked parent.
|
FlexibleAdapter<T> |
setAutoScrollOnExpand(boolean scrollOnExpand)
Automatically scroll the clicked expandable item to the first visible position.
|
FlexibleAdapter<T> |
setDiffUtilCallback(FlexibleAdapter.DiffUtilCallback diffUtilCallback)
Sets a custom implementation of
FlexibleAdapter.DiffUtilCallback for the DiffUtil. |
FlexibleAdapter<T> |
setDisplayHeadersAtStartUp(boolean displayHeaders)
Sets if all headers should be shown at startup by the Adapter automatically.
|
FlexibleAdapter<T> |
setEndlessPageSize(int endlessPageSize)
Sets the limit to automatically disable the endless feature when coming items size is less
than the page size.
|
FlexibleAdapter<T> |
setEndlessProgressItem(T progressItem)
Sets the progressItem to be displayed at the end of the list and activate the Loading More
feature.
|
FlexibleAdapter<T> |
setEndlessScrollListener(FlexibleAdapter.EndlessScrollListener endlessScrollListener,
T progressItem)
Sets the progressItem to be displayed at the end of the list and Sets the callback to
automatically load more items asynchronously(your duty) (no further user action is needed
but the scroll).
|
FlexibleAdapter<T> |
setEndlessScrollThreshold(int thresholdItems)
Sets the minimum number of items still to bind to start the automatic loading.
|
FlexibleAdapter<T> |
setEndlessTargetCount(int endlessTargetCount)
Sets the limit to automatically disable the endless feature when the total items count in
the Adapter is equals or bigger than the target count.
|
void |
setFilter(java.io.Serializable filter)
Sets the new filter entity.
|
FlexibleAdapter<T> |
setHandleDragEnabled(boolean handleDragEnabled)
Enables / Disables the drag of the item with a handle view.
|
FlexibleAdapter<T> |
setHeadersShown(boolean headersShown)
Manually change the flag to indicate that headers are inserted(or not) in the main list by the user
and the Adapter doesn't(does) have to automatically insert them.
|
FlexibleAdapter<T> |
setItemTouchHelperCallback(ItemTouchHelperCallback itemTouchHelperCallback)
Sets a custom callback implementation for item touch.
|
FlexibleAdapter<T> |
setLoadingMoreAtStartUp(boolean enable)
Sets if Endless / Loading More should be triggered at start-up, especially when the
list is empty.
|
FlexibleAdapter<T> |
setLongPressDragEnabled(boolean longPressDragEnabled)
Enables / Disables the drag of the item when long-press the entire itemView.
|
FlexibleAdapter<T> |
setMinCollapsibleLevel(int minCollapsibleLevel)
Sets the minimum level which all sub expandable items will be collapsed too.
|
FlexibleAdapter<T> |
setNotifyChangeOfUnfilteredItems(boolean notifyChange)
With this setting, we can skip the check of the implemented method
IFlexible.shouldNotifyChange(IFlexible). |
FlexibleAdapter<T> |
setNotifyMoveOfFilteredItems(boolean notifyMove)
This method performs a further step to nicely animate the moved items.
|
FlexibleAdapter<T> |
setPermanentDelete(boolean permanentDelete)
Sets if the deleted items should be deleted immediately or if Adapter should cache them to
restore them when requested by the user.
|
FlexibleAdapter<T> |
setRecursiveCollapse(boolean collapseSubLevels)
Automatically collapse all inner sub expandable when higher parent is collapsed.
|
FlexibleAdapter<T> |
setRestoreSelectionOnUndo(boolean restoreSelection)
Gives the possibility to restore the selection on Undo, when
restoreDeletedItems()
is called. |
FlexibleAdapter<T> |
setStickyHeaderElevation(int stickyElevation)
Sets the elevation in dpi for the sticky header layout.
|
FlexibleAdapter<T> |
setStickyHeaders(boolean sticky)
Enables/Disables the sticky header feature with default sticky layout container.
|
FlexibleAdapter<T> |
setStickyHeaders(boolean sticky,
android.view.ViewGroup stickyContainer)
Enables/Disables the sticky header feature with a custom sticky layout container.
|
FlexibleAdapter<T> |
setSwipeEnabled(boolean swipeEnabled)
Enables full the swipe of the items.
|
void |
setTopEndless(boolean topEndless)
Sets endless scrolling from the top.
|
FlexibleAdapter<T> |
setUnlinkAllItemsOnRemoveHeaders(boolean unlinkOnRemoveHeader)
Setting to automatically unlink the deleted header from items having that header linked.
|
boolean |
shouldMove(int fromPosition,
int toPosition)
Evaluate if positions are compatible for swapping.
|
FlexibleAdapter<T> |
showAllHeaders()
Shows all headers in the RecyclerView at their linked position.
|
void |
smoothScrollToPosition(int position)
Performs safe smooth scroll with a delay of ms.
|
void |
swapItems(java.util.List<T> list,
int fromPosition,
int toPosition)
Swaps the elements of list at indices fromPosition and toPosition and notify the change.
|
void |
toggleSelection(int position)
Toggles the selection status of the item at a given position.
|
void |
updateDataSet(java.util.List<T> items)
Convenience method of
updateDataSet(List, boolean) (You should read the comments
of this method). |
void |
updateDataSet(java.util.List<T> items,
boolean animate)
This method will refresh the entire data set content.
|
void |
updateItem(int position,
T item,
java.lang.Object payload)
Updates/Rebounds the itemView corresponding to the current position of the
provided item with the new content.
|
void |
updateItem(T item)
Updates/Rebounds the itemView corresponding to the current position of the
provided item with the new content.
|
void |
updateItem(T item,
java.lang.Object payload)
Updates/Rebounds the itemView corresponding to the current position of the
provided item with the new content.
|
animateView, isAnimationOnForwardScrollingEnabled, isAnimationOnReverseScrollingEnabled, isOnlyEntryAnimation, setAnimationDelay, setAnimationDuration, setAnimationEntryStep, setAnimationInitialDelay, setAnimationInterpolator, setAnimationOnForwardScrolling, setAnimationOnReverseScrolling, setOnlyEntryAnimationaddSelection, enableLogs, getAllBoundViewHolders, getFastScroller, getFlexibleLayoutManager, getMode, getRecyclerView, getSelectedItemCount, getSelectedPositions, getSelectedPositionsAsSet, isFastScrollerEnabled, isLastItemInActionMode, isSelectAll, isSelected, onCreateBubbleText, onFastScrollerStateChange, removeSelection, setFastScroller, setFlexibleLayoutManager, setMode, swapSelection, toggleFastScroller, useTagprotected final int UPDATE
protected final int FILTER
protected final int LOAD_MORE_COMPLETE
protected android.os.Handler mHandler
protected android.view.LayoutInflater mInflater
public FlexibleAdapter.OnItemClickListener mItemClickListener
public FlexibleAdapter.OnItemLongClickListener mItemLongClickListener
protected FlexibleAdapter.OnUpdateListener mUpdateListener
protected FlexibleAdapter.OnFilterListener mFilterListener
protected FlexibleAdapter.OnItemMoveListener mItemMoveListener
protected FlexibleAdapter.OnItemSwipeListener mItemSwipeListener
protected FlexibleAdapter.EndlessScrollListener mEndlessScrollListener
protected FlexibleAdapter.OnDeleteCompleteListener mDeleteCompleteListener
protected FlexibleAdapter.OnStickyHeaderChangeListener mStickyHeaderChangeListener
public FlexibleAdapter(java.util.List<T> items)
items - items to display.FlexibleAdapter(List, Object),
FlexibleAdapter(List, Object, boolean)public FlexibleAdapter(java.util.List<T> items, java.lang.Object listeners)
The listener must be a single instance of a class, usually Activity or Fragment, where you can implement how to handle the different events.
THE ADAPTER WORKS WITH A COPY OF THE ORIGINAL LIST:
new ArrayList<T>(originalList);
items - items to displaylisteners - can be an instance of:
FlexibleAdapter(List),
FlexibleAdapter(List, Object, boolean),
addListener(Object)public FlexibleAdapter(java.util.List<T> items, java.lang.Object listeners, boolean stableIds)
FlexibleAdapter(List, Object) with possibility to set stableIds.
Tip: Setting true allows the RecyclerView to rebind only items really
changed after a refresh with #notifyDataSetChanged() or after swapping Adapter.
This increases performance.
Set true only if items implement Object.hashCode() and have unique ids.
The method #setHasStableIds(boolean) will be called.
stableIds - set true if item implements hashcode() and have unique ids.FlexibleAdapter(List),
FlexibleAdapter(List, Object),
addListener(Object)public FlexibleAdapter<T> addListener(java.lang.Object listener)
This method is automatically called from the Constructor.
listener - the object(s) instance(s) of any listenerremoveListener(Object)public FlexibleAdapter<T> removeListener(java.lang.Object listener)
Warning:
addListener(Object) providing the instance of the desired listener.
removeListener(mUpdateListener);
removeListener(FlexibleAdapter.OnItemLongClickListener.class);listener - the listener instance or Class type to remove from this Adapter and/or from all bound ViewHoldersaddListener(Object)public void onAttachedToRecyclerView(RecyclerView recyclerView)
Attaches the FastScrollerDelegate to the RecyclerView if necessary.
Attaches the StickyHeaderHelper to the RecyclerView if necessary.
onAttachedToRecyclerView in class SelectableAdapterpublic void onDetachedFromRecyclerView(RecyclerView recyclerView)
Detaches the FastScrollerDelegate from the RecyclerView if necessary.
Detaches the StickyHeaderHelper from the RecyclerView if necessary.
onDetachedFromRecyclerView in class SelectableAdapterpublic FlexibleAdapter<T> expandItemsAtStartUp()
This method should be called during the creation of the Activity/Fragment, useful also after a screen rotation.
@Deprecated public boolean isEnabled(int position)
isItemEnabled(int).public boolean isItemEnabled(int position)
enabled = true.
When an item is disabled, user cannot interact with it.
position - the current position of the item to checkpublic boolean isSelectable(int position)
selectable = true.isSelectable in class SelectableAdapterposition - the current position of the item to checkpublic void toggleSelection(int position)
The behaviour depends on the selection mode previously set with SelectableAdapter.setMode(int).
FlexibleViewHolder.toggleActivation() called in onClick event
Usage:
DrawableUtils or via layout's item:
android:background="?attr/selectableItemBackground", pointing to a custom Drawable
in the style.xml (note: prefix ?android:attr doesn't work).toggleSelection in class SelectableAdapterposition - position of the item to toggle the selection status for.public void selectAll(java.lang.Integer... viewTypes)
Examples:
selectAll in class SelectableAdapterviewTypes - All the desired viewTypes to be selected, providing no view types, will
automatically select all the viewTypes of the first item user has selectedpublic void clearSelection()
Note 1: Items are not rebound, so an eventual animation is not stopped!
Note 2: This method use java.util.Iterator on synchronized collection to
avoid java.util.ConcurrentModificationException.
clearSelection in class SelectableAdapterpublic boolean isAnyParentSelected()
public boolean isAnyChildSelected()
public void updateDataSet(java.util.List<T> items)
updateDataSet(List, boolean) (You should read the comments
of this method).
In this call, changes will NOT be animated: Warning!
#notifyDataSetChanged() will be invoked.
items - the new data setupdateDataSet(List, boolean)public void updateDataSet(java.util.List<T> items, boolean animate)
setAnimateToLimit(int)
to improve performance on very big list. Should provide animate=false to
directly invoke #notifyDataSetChanged() without any animations, if stableIds
is not set!
Note:
Object.hashCode() to all adapter items
along with Object.equals(Object): This Adapter is making use of HashSet to
improve performance.expandItemsAtStartUp()showAllHeaders() if headers are shownonPostUpdate()FlexibleAdapter.OnUpdateListener.onUpdateEmptyView(int) if the listener is setitems - the new data setanimate - true to animate the changes, false for an instant refreshupdateDataSet(List),
setAnimateToLimit(int),
onPostUpdate()public T getItem(int position)
This method cannot be overridden since the entire library relies on it.
position - the position of the item in the listpublic <S extends T> S getItem(int position, java.lang.Class<S> clazz)
position - the position of the item in the listclazz - the class type expectedjava.lang.ClassCastException - if the class type doesn't match with the item type requestedpublic long getItemId(int position)
position - the position of the current itempublic int getItemCount()
getMainItemCount() with false as parameter to retrieve
only real items excluding headers and footers.
Note: This method cannot be overridden since the selection and the internal methods rely on it.
getMainItemCount(),
getItemCountOfTypes(Integer...),
isEmpty()public final int getMainItemCount()
true (default behavior) to count all items, same result of getItemCount().false to count only main items (headers and footers are EXCLUDED).getItemCount(),
getItemCountOfTypes(Integer...)public final int getItemCountOfTypes(java.lang.Integer... viewTypes)
viewTypes - the viewTypes to countgetItemCount(),
getMainItemCount(),
isEmpty()public final java.util.List<T> getCurrentItems()
public boolean isEmpty()
getItemCount(),
getItemCountOfTypes(Integer...)public final int getGlobalPositionOf(IFlexible item)
This method cannot be overridden since the entire library relies on it.
item - the item for which the position needs to be foundgetSameTypePositionOf(IFlexible)public final int getCardinalPositionOf(IFlexible item)
Note:
- This method is NOT suitable to call when managing items: ALL insert, remove, move and
swap operations, should done with global position getGlobalPositionOf(IFlexible).
- This method cannot be overridden.
item - the item for which the position needs to be foundgetSameTypePositionOf(IFlexible)public final int getSameTypePositionOf(IFlexible item)
Tip: You can identify the number of the section (you need to add +1) of any headers OR to retrieve the position of an item as it were the only view type visible in the Adapter.
item - the item for which the position needs to be foundgetSubPositionOf(IFlexible)public boolean contains(T item)
item - the item to findpublic int calculatePositionFor(java.lang.Object item,
java.util.Comparator<IFlexible> comparator)
Note: The Comparator object should be customized to support all
types of items this Adapter is managing or a ClassCastException will be raised.
Comparator is null the returned position is 0 (first position).item - the item to evaluate the insertioncomparator - the Comparator object with the logic to sort the listpublic final java.util.List<T> getScrollableHeaders()
addScrollableHeader(IFlexible),
addScrollableHeaderWithDelay(IFlexible, long, boolean)public final java.util.List<T> getScrollableFooters()
addScrollableFooter(IFlexible),
addScrollableFooterWithDelay(IFlexible, long, boolean)public final boolean isScrollableHeaderOrFooter(int position)
isScrollableHeaderOrFooter in class AnimatorAdapterposition - the position to checkpublic final boolean isScrollableHeaderOrFooter(T item)
item - the item to checkpublic final boolean addScrollableHeader(T headerItem)
Scrollable Headers have the following characteristic:
headerItem - the header item to be addedgetScrollableHeaders(),
addScrollableHeaderWithDelay(IFlexible, long, boolean)public final boolean addScrollableFooter(T footerItem)
Scrollable Footers have the following characteristic:
progressItem is handled as a Scrollable Footer, but it will be always
displayed between the main items and the others footers.footerItem - the footer item to be addedgetScrollableFooters(),
addScrollableFooterWithDelay(IFlexible, long, boolean)public final void removeScrollableHeader(T headerItem)
headerItem - the header to removeremoveScrollableHeaderWithDelay(IFlexible, long),
removeAllScrollableHeaders()public final void removeScrollableFooter(T footerItem)
footerItem - the footer to removeremoveScrollableFooterWithDelay(IFlexible, long),
removeAllScrollableFooters()public final void removeAllScrollableHeaders()
removeScrollableHeader(IFlexible),
removeScrollableHeaderWithDelay(IFlexible, long)public final void removeAllScrollableFooters()
removeScrollableFooter(IFlexible),
removeScrollableFooterWithDelay(IFlexible, long)public final void addScrollableHeaderWithDelay(T headerItem, long delay, boolean scrollToPosition)
addScrollableHeader(IFlexible) but with a delay and the possibility to
scroll to it.headerItem - the header item to be addeddelay - the delay in msscrollToPosition - true to scroll to the header item position once it has been addedaddScrollableHeader(IFlexible)public final void addScrollableFooterWithDelay(T footerItem, long delay, boolean scrollToPosition)
addScrollableFooter(IFlexible) but with a delay and the possibility to
scroll to it.footerItem - the footer item to be addeddelay - the delay in msscrollToPosition - true to scroll to the footer item position once it has been addedaddScrollableFooter(IFlexible)public final void removeScrollableHeaderWithDelay(T headerItem, long delay)
removeScrollableHeader(IFlexible) but with a delay.headerItem - the header item to be removeddelay - the delay in msremoveScrollableHeader(IFlexible),
removeAllScrollableHeaders()public final void removeScrollableFooterWithDelay(T footerItem, long delay)
removeScrollableFooter(IFlexible) but with a delay.footerItem - the footer item to be removeddelay - the delay in msremoveScrollableFooter(IFlexible),
removeAllScrollableFooters()public FlexibleAdapter<T> setUnlinkAllItemsOnRemoveHeaders(boolean unlinkOnRemoveHeader)
Default value is false.
unlinkOnRemoveHeader - true to unlink the deleted header from items having that header
linked, false otherwisepublic java.util.List<IHeader> getHeaderItems()
public boolean isHeader(T item)
item - the item to checkIHeader interface, false otherwisepublic boolean hasHeader(T item)
item - the identified itempublic boolean hasSameHeader(T item, IHeader header)
item - the item supposing having the headerheader - the header to comparepublic IHeader getHeaderOf(T item)
ISectionable item.item - the ISectionable item holding a headerpublic IHeader getSectionHeader(int position)
IHeader item of any specified position.position - the item positionpublic java.util.List<ISectionable> getSectionItems(IHeader header)
header - the IHeader item that represents the sectionpublic java.util.List<java.lang.Integer> getSectionItemPositions(IHeader header)
header - the IHeader item that represents the sectionpublic boolean areHeadersShown()
public boolean areHeadersSticky()
public final int getStickyPosition()
public final void ensureHeaderParent()
public FlexibleAdapter<T> setStickyHeaders(boolean sticky)
Note:
setDisplayHeadersAtStartUp(boolean):
Feature can enabled/disabled freely, but if headers are hidden nothing will happen.true to the
constructor: FlexibleViewHolder.FlexibleViewHolder(View, FlexibleAdapter, boolean).setStickyHeaders(boolean, ViewGroup).21f pixel is used.
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>
sticky - true to initialize sticky headers with default container, false to disable themjava.lang.IllegalStateException - if this Adapter was not attached to the RecyclerViewsetStickyHeaders(boolean, ViewGroup),
setDisplayHeadersAtStartUp(boolean),
setStickyHeaderElevation(int)public FlexibleAdapter<T> setStickyHeaders(boolean sticky, android.view.ViewGroup stickyContainer)
Important: Read the javaDoc of the overloaded method setStickyHeaders(boolean).
sticky - true to initialize sticky headers, false to disable themstickyContainer - user defined and already inflated sticky layout that will
hold the sticky header itemViewsjava.lang.IllegalStateException - if this Adapter was not attached to the RecyclerViewsetStickyHeaders(boolean),
setDisplayHeadersAtStartUp(boolean),
setStickyHeaderElevation(int)public int getStickyHeaderElevation()
Note: This setting is ignored if the header item has already an elevation. The header elevation overrides this setting.
setStickyHeaderElevation(int)public FlexibleAdapter<T> setStickyHeaderElevation(int stickyElevation)
Note: This setting is ignored if the header item has already an elevation. The header elevation overrides this setting.
Default value is 0 dpi.stickyElevation - the elevation in dpigetStickyHeaderElevation()public FlexibleAdapter<T> setDisplayHeadersAtStartUp(boolean displayHeaders)
If called, this method won't trigger notifyItemInserted() and scrolling
animations are instead performed if the header item was configured with animation:
Headers will be loaded/bound along with others items.
Default value is false (headers are not shown at startup).
displayHeaders - true to display headers, false to keep them hiddenshowAllHeaders(),
AnimatorAdapter.setAnimationOnForwardScrolling(boolean)public FlexibleAdapter<T> setHeadersShown(boolean headersShown)
Default value is false (headers are not shown at startup).
headersShown - true, if headers are already shownpublic FlexibleAdapter<T> showAllHeaders()
If called at startup, this method will trigger notifyItemInserted for a
different loading effect: Headers will be inserted after the items!
hideAllHeaders(),
setDisplayHeadersAtStartUp(boolean)public void hideAllHeaders()
Headers can be shown or hidden all together.
showAllHeaders(),
setDisplayHeadersAtStartUp(boolean)public int getItemViewType(int position)
You CANNOT override this method: FlexibleAdapter delegates the ViewType
definition via IFlexible.getLayoutRes() so ViewTypes are automatically mapped
(AutoMap).
position - position for which ViewType is requestedIFlexible#getLayoutRes()IFlexible.getItemViewType()public RecyclerView.ViewHolder onCreateViewHolder(android.view.ViewGroup parent,
int viewType)
FlexibleAdapter
delegates the creation via IFlexible.createViewHolder().
HELP: To know how to implement AutoMap for ViewTypes please refer to the FlexibleAdapter Wiki Page on GitHub.
IFlexible.createViewHolder(View, FlexibleAdapter)public void onBindViewHolder(RecyclerView.ViewHolder holder,
int position)
FlexibleAdapter delegates
the binding to the corresponding item via IFlexible.bindViewHolder().
HELP: To know how to implement AutoMap for ViewTypes please refer to the FlexibleAdapter Wiki Page on GitHub.
IFlexible.bindViewHolder(FlexibleAdapter, RecyclerView.ViewHolder, int, List)public void onBindViewHolder(RecyclerView.ViewHolder holder,
int position,
java.util.List payloads)
#onBindViewHolder() but with Payload.
onBindViewHolder in class SelectableAdapterIFlexible.bindViewHolder(FlexibleAdapter, RecyclerView.ViewHolder, int, List),
onBindViewHolder(RecyclerView.ViewHolder, int)public void onViewAttachedToWindow(RecyclerView.ViewHolder holder)
public void onViewDetachedFromWindow(RecyclerView.ViewHolder holder)
public void onViewRecycled(RecyclerView.ViewHolder holder)
onViewRecycled in class SelectableAdapterpublic boolean isTopEndless()
public void setTopEndless(boolean topEndless)
false (bottom endless scrolling).topEndless - true to enable endless scrolling from the top, false from the bottompublic boolean isEndlessScrollEnabled()
false. To enable again the progress item you MUST be set again.setEndlessProgressItem(IFlexible)public int getEndlessCurrentPage()
getEndlessPageSize(),
setEndlessPageSize(int)public int getEndlessPageSize()
Tip: This limit is ignored if value is 0.
getEndlessCurrentPage(),
setEndlessPageSize(int)public FlexibleAdapter<T> setEndlessPageSize(int endlessPageSize)
When endless feature is disabled a #notifyItemChanged(int, Object) with payload
Payload.NO_MORE_LOAD will be triggered on the progressItem, so you can display a
message or change the views in this item.
endlessPageSize - the size limit for each pagepublic int getEndlessTargetCount()
Tip: This limit is ignored if value is 0.
setEndlessTargetCount(int)public FlexibleAdapter<T> setEndlessTargetCount(int endlessTargetCount)
When endless feature is disabled a #notifyItemChanged(int, Object) with payload
Payload.NO_MORE_LOAD will be triggered on the progressItem, so you can display a
message or change the views in this item.
endlessTargetCount - the total items count limitgetEndlessTargetCount()public FlexibleAdapter<T> setLoadingMoreAtStartUp(boolean enable)
Default value is false.
enable - true to trigger a loading at start up, false to trigger loading with bindingpublic FlexibleAdapter<T> setEndlessProgressItem(T progressItem)
Using this method, the FlexibleAdapter.EndlessScrollListener won't be called so that you can
handle a click event to load more items upon a user request.
progressItem - the item representing the progress barisEndlessScrollEnabled(),
setEndlessScrollListener(EndlessScrollListener, IFlexible)public FlexibleAdapter<T> setEndlessScrollListener(FlexibleAdapter.EndlessScrollListener endlessScrollListener, T progressItem)
endlessScrollListener - the callback to invoke the asynchronous loadingprogressItem - the item representing the progress barisEndlessScrollEnabled(),
setEndlessProgressItem(IFlexible)public FlexibleAdapter<T> setEndlessScrollThreshold(int thresholdItems)
Default value is 1.
thresholdItems - minimum number of unbound items to start loading more itemsprotected void onLoadMore(int position)
position - the current binding positionpublic void onLoadMoreComplete(java.util.List<T> newItems)
When noMoreLoad OR onError OR onCancel, pass empty list or null to hide the progressItem.
In this case the ProgressItem is removed immediately.newItems - the list of the new items, can be empty or nullpublic void onLoadMoreComplete(java.util.List<T> newItems, long delay)
When noMoreLoad OR onError OR onCancel, pass empty list or null to hide the
progressItem. When limits are set, endless feature will be disabled. To enable
again call setEndlessProgressItem(IFlexible).
bindViewHolder of the item.
A #notifyItemChanged(int, Object) with payload Payload.NO_MORE_LOAD
will be triggered on the progressItem, so you can display a message or change the views in
this item.
newItems - the list of the new items, can be empty or nulldelay - the delay used to remove the progress item or -1 to disable the
loading forever and to keep the progress item visible.public boolean isAutoCollapseOnExpand()
collapseOnExpand is enabled, false otherwisepublic FlexibleAdapter<T> setAutoCollapseOnExpand(boolean collapseOnExpand)
Default value is false (disabled).
setMinCollapsibleLevel(int).collapseOnExpand - true to collapse others items, false to just expand the currentsetMinCollapsibleLevel(int)public boolean isRecursiveCollapse()
collapseSubLevels is enabled, false otherwisepublic FlexibleAdapter<T> setRecursiveCollapse(boolean collapseSubLevels)
false, their expanded status remains expanded=true
so when the higher parent is expanded again, the sub expandables will appear again expanded.
Default value is false (keep expanded status).
setMinCollapsibleLevel(int).collapseSubLevels - true to allow inner sub expandable to collapse, false to keep the expanded statussetMinCollapsibleLevel(int)public boolean isAutoScrollOnExpand()
scrollOnExpand is enabled, false otherwisepublic FlexibleAdapter<T> setAutoScrollOnExpand(boolean scrollOnExpand)
Default value is false (disabled).
SmoothScrollLinearLayoutManager
or with SmoothScrollGridLayoutManager available in UI extension.scrollOnExpand - true to enable automatic scroll, false to disablepublic boolean isExpanded(int position)
position - the position of the item to checkIExpandable interface and its property has
expanded = truepublic boolean isExpanded(T item)
IExpandable instance and is expanded.item - the item to checkIExpandable interface and its property has
expanded = truepublic boolean isExpandable(T item)
IExpandable instance.item - the item to checkIExpandable interface, false otherwisepublic int getMinCollapsibleLevel()
public FlexibleAdapter<T> setMinCollapsibleLevel(int minCollapsibleLevel)
Default value is mMinCollapsibleLevel (All levels including 0).
setRecursiveCollapse(boolean).minCollapsibleLevel - the minimum level to auto-collapse sub expandable itemssetRecursiveCollapse(boolean)public boolean hasSubItems(IExpandable expandable)
expandable - the IExpandable objectpublic IExpandable getExpandableOf(int position)
Only for a real child of an expanded parent.
position - the position of the child itempublic IExpandable getExpandableOf(T child)
Only for a real child of an expanded parent.
child - the child itemgetExpandablePositionOf(IFlexible),
getSubPositionOf(IFlexible)public int getExpandablePositionOf(T child)
Only for a real child of an expanded parent.
child - the child itemgetExpandableOf(IFlexible),
getSubPositionOf(IFlexible)public int getSubPositionOf(T child)
0.
Works for items under header and under expandable too.
child - any sub item of any sectiongetSameTypePositionOf(IFlexible),
getExpandableOf(IFlexible),
getExpandablePositionOf(IFlexible)public java.util.List<T> getSiblingsOf(T child)
child - the child itemgetExpandableOf(IFlexible),
getExpandablePositionOf(IFlexible),
getSubPositionOf(IFlexible),
getExpandedItems()public java.util.List<T> getExpandedItems()
getSiblingsOf(IFlexible),
getExpandedPositions()public java.util.List<java.lang.Integer> getExpandedPositions()
getSiblingsOf(IFlexible),
getExpandedItems()public int expand(int position)
IExpandable type, not yet expanded and if has subItems.
If configured, automatic smooth scroll will be performed when necessary.
Parent won't be notified.position - the position of the item to expandexpand(int, boolean),
expand(IFlexible),
expand(IFlexible, boolean),
expandAll()public int expand(int position,
boolean notifyParent)
IExpandable type, not yet expanded and if has subItems.
If configured, automatic smooth scroll will be performed when necessary.
position - the position of the item to expandnotifyParent - true to notify the parent with Payload.EXPANDEDexpand(int),
expand(IFlexible),
expand(IFlexible, boolean),
expandAll()public int expand(T item)
Expands an item that is Expandable, not yet expanded, that has subItems and no child is selected.
If configured, automatic smooth scroll will be performed.item - the item to expand, must be an Expandable and present in the listexpand(int),
expand(int, boolean),
expand(IFlexible, boolean),
expandAll()public int expand(T item, boolean init)
Note: Must be used in combination when adding new items, those require to be initially expanded.
WARNING!init = true: it will always attempt to expand
the item: If subItems are already visible and the new item has status expanded, the
subItems will appear duplicated(!) and the automatic smooth scroll will be skipped!item - the item to expand, must be an Expandable and present in the listinit - true to initially expand itemexpand(int),
expand(int, boolean),
expand(IFlexible),
expandAll()public int expandAll()
IExpandable items with minimum of level mMinCollapsibleLevel.expandAll(int),
setMinCollapsibleLevel(int)public int expandAll(int level)
IExpandable items with at least the specified level.
Parents will be notified.
level - the minimum level to expand the sub expandable itemsexpandAll(),
setMinCollapsibleLevel(int)public int collapse(int position)
IExpandable item that is already expanded and if no subItem
is selected.
Multilevel option behaviours:
IExpandable subItems, that are expanded, can be recursively collapsed,
see setRecursiveCollapse(boolean).setMinCollapsibleLevel(int).position - the position of the item to collapsecollapseAll()public int collapse(int position,
boolean notifyParent)
collapse(int) with possibility to notify/update the parent.position - the position of the item to collapsenotifyParent - notify the parent with Payload.COLLAPSEDcollapseAll()public int collapseAll()
mMinCollapsibleLevel.collapse(int, boolean),
collapseAll(int),
setMinCollapsibleLevel(int)public int collapseAll(int level)
Parents will be notified.
level - the level to start collapse sub expandable itemscollapseAll()public void updateItem(T item)
item - the item with the new contentupdateItem(IFlexible, Object),
updateItem(int, IFlexible, Object)public void updateItem(T item, java.lang.Object payload)
item - the item with the new contentpayload - any non-null user object to notify the current item (the payload will be
therefore passed to the bind method of the item ViewHolder to optimize the
content to update); pass null to rebind all fields of this item.updateItem(IFlexible),
updateItem(int, IFlexible, Object)public void updateItem(int position,
T item,
java.lang.Object payload)
updateItem(IFlexible, Object) if the
new content should be bound on the same position.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 be
therefore passed to the bind method of the item ViewHolder to optimize the
content to update); pass null to rebind all fields of this item.updateItem(IFlexible),
updateItem(IFlexible, Object)public void addItemWithDelay(int position,
T item,
long delay,
boolean scrollToPosition)
Scrolling animation is automatically preserved, meaning that, notification for animation is ignored.
Useful at startup, when there's an item to add after Adapter Animations is completed.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 otherwiseaddItem(int, IFlexible),
addItems(int, List),
addSubItems(int, int, IExpandable, List, boolean, Object),
removeItemWithDelay(IFlexible, long, boolean)public boolean addItem(T item)
Convenience method of addItem(int, IFlexible) with
position = getMainItemCount().
item - the item to addpublic boolean addItem(int position,
T item)
position - position inside the list, if negative, items will be added to the enditem - the item to addaddItem(IFlexible),
addItems(int, List),
addSubItems(int, int, IExpandable, List, boolean, Object),
addItemWithDelay(int, IFlexible, long, boolean)public boolean addItems(int position,
java.util.List<T> items)
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.
position - position inside the list, if negative, items will be added to the enditems - the set of items to addaddItem(IFlexible),
addItem(int, IFlexible),
addSubItems(int, int, IExpandable, List, boolean, Object)public boolean addSubItem(int parentPosition,
int subPosition,
T item)
addSubItem(int, int, IFlexible, boolean, Object).
addSubItems(int, int, IExpandable, List, boolean, Object)public boolean addSubItem(int parentPosition,
int subPosition,
T item,
boolean expandParent,
java.lang.Object payload)
addSubItems(int, int, IExpandable, List, boolean, Object).
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 add
the subItem, false to simply add the subItem to the parentpayload - any non-null user object to notify the parent (the payload will be
therefore passed to the bind method of the parent ViewHolder),
pass null to not notify the parentaddSubItems(int, int, IExpandable, List, boolean, Object)public boolean addSubItems(int parentPosition,
int subPosition,
java.util.List<T> items)
addSubItems(int, int, List, boolean, Object).
addSubItems(int, int, IExpandable, List, boolean, Object)public boolean addSubItems(int parentPosition,
int subPosition,
java.util.List<T> items,
boolean expandParent,
java.lang.Object payload)
addSubItems(int, int, IExpandable, List, boolean, Object).
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 add
the subItems, false to simply add the subItems to the parentpayload - any non-null user object to notify the parent (the payload will be
therefore passed to the bind method of the parent ViewHolder),
pass null to not notify the parentaddSubItems(int, int, IExpandable, List, boolean, Object)public int addSection(IHeader header)
addSection(IHeader, Comparator)public int addSection(IHeader header, java.util.Comparator<IFlexible> comparator)
IHeader item and the
position is calculated after sorting the data set.
- To add Sections to the top, set null the Comparator object or simply call
addSection(IHeader);
- To add Sections to the bottom or in the middle, implement a Comparator
object able to support all the item types this Adapter is displaying or a
ClassCastException will be raised.
header - the section header item to addcomparator - the criteria to sort the Data Set used to extract the correct position
of the new headerpublic int addItemToSection(ISectionable sectionable, IHeader header, java.util.Comparator<IFlexible> comparator)
The header can be a IExpandable type or IHeader type.
sectionable - the item to addheader - the section receiving the new itemcomparator - the criteria to sort the sectionItems used to extract the correct position
of the new item in the sectionaddItemToSection(ISectionable, IHeader, int)public int addItemToSection(ISectionable sectionable, IHeader header, int index)
The header can be a IExpandable type or IHeader type.
sectionable - the item to addheader - the section receiving the new itemindex - the known relative position where to add the new item into the sectionaddItemToSection(ISectionable, IHeader, Comparator)public void clear()
clearAllBut(Integer...),
removeRange(int, int),
removeItemsOfType(Integer...)public void clearAllBut(java.lang.Integer... viewTypes)
Tip:- This method is opposite of removeItemsOfType(Integer...).
viewTypes - the viewTypes to retainclear(),
removeItems(List),
removeItemsOfType(Integer...)public void removeItemWithDelay(T item, long delay, boolean permanent)
Scrolling animation is automatically preserved, meaning that notification for animation is ignored.
item - the item to adddelay - a non-negative delaypermanent - true to permanently delete the item (no undo), false otherwiseremoveItem(int),
removeItems(List),
removeItemsOfType(Integer...),
removeRange(int, int),
removeAllSelectedItems(),
addItemWithDelay(int, IFlexible, long, boolean)public void removeSection(IHeader header)
For header that is also expandable, it's equivalent to remove a single item.
header - the head of the sectionremoveItem(int)public void removeItem(int position)
removeItem(int, Object) providing Payload.CHANGE
as payload for the parent item.position - the position of item to removeremoveItems(List),
removeItemsOfType(Integer...),
removeRange(int, int),
removeAllSelectedItems(),
removeItemWithDelay(IFlexible, long, boolean),
removeItem(int, Object)public void removeItem(int position,
java.lang.Object payload)
The item is retained for an eventual Undo.
This method delegates the removal to removeRange.position - The position of item to removepayload - any non-null user object to notify the parent (the payload will be
therefore passed to the bind method of the parent ViewHolder),
pass null to not notify the parentremoveItems(List, Object),
removeRange(int, int, Object),
removeAllSelectedItems(Object),
removeItem(int)public void removeItems(java.util.List<java.lang.Integer> selectedPositions)
removeItems(List, Object) providing the default
Payload.CHANGE for the parent items.removeItem(int),
removeItemsOfType(Integer...),
removeRange(int, int),
removeAllSelectedItems(),
removeItems(List, Object)public void removeItems(java.util.List<java.lang.Integer> selectedPositions,
java.lang.Object payload)
Every item is retained for an eventual Undo.
Optionally you can pass any payload to notify the parent items about the change to optimize the view binding.This method delegates the removal to removeRange.
selectedPositions - list with item positions to removepayload - any non-null user object to notify the parent (the payload will be
therefore passed to the bind method of the parent ViewHolder),
pass null to not notify the parentremoveItem(int, Object),
removeRange(int, int, Object),
removeAllSelectedItems(Object),
removeItems(List)public void removeItemsOfType(java.lang.Integer... viewTypes)
Tips:
- This method is opposite of clearAllBut(Integer...).
- View types of Scrollable Headers and Footers are ignored!
viewTypes - the viewTypes to removeclear(),
clearAllBut(Integer...),
removeItem(int, Object),
removeItems(List),
removeAllSelectedItems()public void removeRange(int positionStart,
int itemCount)
removeRange(int, int, Object), but in this case the parent will not be
notified about the change, if children are removed.clear(),
clearAllBut(Integer...),
removeItem(int, Object),
removeItems(List),
removeItemsOfType(Integer...),
removeAllSelectedItems(),
removeRange(int, int, Object)public void removeRange(int positionStart,
int itemCount,
java.lang.Object payload)
If the item, resulting from the provided position:
- is not expandable with no parent, it is removed as usual.IExpandable, it is removed as usual, but
it will be collapsed if expanded.IHeader item, the header will be automatically linked to the first item
after the range or can remain orphan.
Optionally you can pass any payload to notify the parent or the header about the change and optimize the view binding.
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 be
therefore passed to the bind method of the parent ViewHolder),
pass null to not notify the parentclear(),
clearAllBut(Integer...),
removeItem(int, Object),
removeItems(List, Object),
removeRange(int, int),
removeAllSelectedItems(Object),
setPermanentDelete(boolean),
setRestoreSelectionOnUndo(boolean),
getDeletedItems(),
getDeletedChildren(IExpandable),
restoreDeletedItems(),
emptyBin()public void removeAllSelectedItems()
Parent will not be notified about the change if a child is removed.
clear(),
clearAllBut(Integer...),
removeItem(int),
removeItems(List),
removeRange(int, int),
removeItemsOfType(Integer...),
removeAllSelectedItems(Object)public void removeAllSelectedItems(java.lang.Object payload)
Optionally, the parent item can be notified about the change if a child is removed, by providing any non-null payload.
payload - any non-null user object to notify the parent (the payload will be
therefore passed to the bind method of the parent ViewHolder),
pass null to not notify the parentclear(),
clearAllBut(Integer...),
removeItem(int, Object),
removeItems(List, Object),
removeRange(int, int, Object),
removeAllSelectedItems()public boolean isPermanentDelete()
Default value is true (Undo mechanism is disabled).
public FlexibleAdapter<T> setPermanentDelete(boolean permanentDelete)
Default value is true (Undo mechanism is disabled).
permanentDelete - true to delete items forever, false to use the cache for Undo featurepublic boolean isRestoreWithSelection()
Default value is false (selection is NOT restored).
setRestoreSelectionOnUndo(boolean)public FlexibleAdapter<T> setRestoreSelectionOnUndo(boolean restoreSelection)
restoreDeletedItems()
is called.
To use in combination with ActionMode in order to not disable it.
false (selection is NOT restored).restoreSelection - true to have restored items still selected, false to empty selectionspublic void restoreDeletedItems()
Tip: If filter is active, only items that match that filter will be shown(restored).
setRestoreSelectionOnUndo(boolean)public void confirmDeletion()
Note: This method is automatically called after timer is over in UndoHelper.
public void emptyBin()
Note: This method is automatically called after timer is over in UndoHelper and after a restoration.
public final boolean isRestoreInTime()
public java.util.List<T> getDeletedItems()
public java.util.List<java.lang.Integer> getUndoPositions()
public void saveUndoPositions(java.util.List<java.lang.Integer> undoPositions)
undoPositions - the positions to Undo with UndoHelper when Action.UPDATE.public final IExpandable getExpandableOfDeletedChild(T child)
child - the deleted childpublic final java.util.List<T> getDeletedChildren(IExpandable expandable)
expandable - the parent itempublic final java.util.List<T> getCurrentChildren(IExpandable expandable)
expandable - the parent itempublic boolean hasFilter()
nullpublic boolean hasNewFilter(java.io.Serializable constraint)
constraint - the new filter entitypublic void setFilter(java.io.Serializable filter)
Note:
Serializable (String does).String), filter is automatically trimmed
and lowercase.Tip: You can highlight filtered Text or Words using FlexibleUtils
from UI extension:
FlexibleUtils#highlightText(TextView, String, String)FlexibleUtils#highlightWords(TextView, String, String)filter - the new filter entity for the itemspublic <F extends java.io.Serializable> F getFilter(java.lang.Class<F> clazz)
clazz - The class type of filter to return (eg. String.class)java.lang.ClassCastException - if the class type doesn't match with the filter type previously setpublic final FlexibleAdapter<T> setNotifyChangeOfUnfilteredItems(boolean notifyChange)
IFlexible.shouldNotifyChange(IFlexible).
By setting false all items will be skipped by an update.
Default value istrue (items will always be notified of a change).notifyChange - true to trigger #notifyItemChanged(int),
false to not update the items' content.public final FlexibleAdapter<T> setNotifyMoveOfFilteredItems(boolean notifyMove)
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 false.
notifyMove - true to animate move changes after filtering or update data set,
false otherwisepublic void filterItems()
setFilter(Serializable).filterItems(long),
filterItems(List),
onPostFilter(),
setAnimateToLimit(int)public void filterItems(long delay)
filterItems() but with a delay in the execution, useful to grab
more characters from user before starting the search.delay - any non-negative delaysetFilter(Serializable),
filterItems(),
filterItems(List, long),
onPostFilter(),
setAnimateToLimit(int)public void filterItems(java.util.List<T> unfilteredItems, long delay)
Same as filterItems(List), but with a delay in the execution, useful to grab
more characters from user before starting the search.
unfilteredItems - the list to filterdelay - any non-negative delaysetFilter(Serializable),
filterItems(long),
filterItems(List),
onPostFilter(),
setAnimateToLimit(int)public void filterItems(java.util.List<T> unfilteredItems)
This method filters the provided list with the filter previously set with
setFilter(Serializable). Filter object can be of any type.
onPostFilter() is called after the filter task is completed.filterObject(IFlexible, Serializable) for each filterable item.FlexibleAdapter.OnDeleteCompleteListener.onDeleteConfirmed(int) (implemented in UndoHelper)
is therefore invoked.null, the provided list is the new list plus any
Scrollable Headers and Footers if existent.animateTo(List, Payload) BUT a limit of
(default) items is set. Tip: Above this limit,
#notifyDataSetChanged() will be called to improve performance. You can change
this limit by calling setAnimateToLimit(int).unfilteredItems - the list to filtersetFilter(Serializable),
filterItems(),
filterItems(List, long),
onPostFilter(),
setAnimateToLimit(int)public boolean isFiltering()
protected boolean filterObject(T item, java.io.Serializable constraint)
IFilterable interface,
if yes, performs the filter on the implemented method IFilterable.filter(Serializable).
Note:
- The item will be collected if the implemented method returns true.
- IExpandable items are automatically picked up and displayed if at least a
child is collected by the current filter. You DON'T NEED to implement the scan for the
children: this is already done :-)
- If you don't want to implement the IFilterable interface on each item, then
you can override this method to have another filter logic!
item - the object to be inspectedconstraint - constraint, that the object has to fulfilpublic FlexibleAdapter<T> setAnimateToLimit(int limit)
#notifyDataSetChanged()
will be called instead.
Default value is items, number new items.
limit - the number of new items that, when reached, will skip synchronization animationspublic boolean isAnimateChangesWithDiffUtil()
setAnimateChangesWithDiffUtil(boolean)public FlexibleAdapter<T> setAnimateChangesWithDiffUtil(boolean useDiffUtil)
DiffUtil to calculate the changes between 2 lists after Update or
Filter 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 SelectableAdapter.enableLogs(int) before creating the Adapter instance!
false (default calculation is used).useDiffUtil - true to switch the calculation and use DiffUtil, false to use the default
calculation.setDiffUtilCallback(DiffUtilCallback)public FlexibleAdapter<T> setDiffUtilCallback(FlexibleAdapter.DiffUtilCallback diffUtilCallback)
FlexibleAdapter.DiffUtilCallback for the DiffUtil.diffUtilCallback - the custom callback that DiffUtil will callsetAnimateChangesWithDiffUtil(boolean)public long getTime()
public final ItemTouchHelper getItemTouchHelper()
FlexibleViewHolder.onTouch(View, MotionEvent)
to start Drag or Swipe when HandleView is touched.public final ItemTouchHelperCallback getItemTouchHelperCallback()
setItemTouchHelperCallback(ItemTouchHelperCallback)public final FlexibleAdapter<T> setItemTouchHelperCallback(ItemTouchHelperCallback itemTouchHelperCallback)
If called, Helper will be reinitialized.
If not called, the default Helper will be used.itemTouchHelperCallback - the custom callback implementation for item touchpublic final boolean isLongPressDragEnabled()
Default value is false.
false.setLongPressDragEnabled(boolean)public final FlexibleAdapter<T> setLongPressDragEnabled(boolean longPressDragEnabled)
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
FlexibleViewHolder.onActionStateChanged(int, int).
false.longPressDragEnabled - true to activate, false otherwisepublic final boolean isHandleDragEnabled()
Default value is false.
FlexibleViewHolder.setDragHandleView(View).setHandleDragEnabled(boolean)public final FlexibleAdapter<T> setHandleDragEnabled(boolean handleDragEnabled)
Default value is false.
handleDragEnabled - true to activate, false otherwisepublic final boolean isSwipeEnabled()
Default value is false.
false.setSwipeEnabled(boolean)public final FlexibleAdapter<T> setSwipeEnabled(boolean swipeEnabled)
Note:
getFrontView and at least a rear View: getRearLeftView and/or
getRearRightView in the FlexibleViewHolder.false.swipeEnabled - true to activate, false otherwisepublic void moveItem(int fromPosition,
int toPosition)
fromPosition to the position
toPosition.
fromPosition - previous position of the itemtoPosition - new position of the itemmoveItem(int, int, Object)public void moveItem(int fromPosition,
int toPosition,
java.lang.Object payload)
fromPosition to the position
toPosition.
fromPosition - previous position of the itemtoPosition - new position of the itempayload - allows to update the content of the item just movedpublic void swapItems(java.util.List<T> list, int fromPosition, int toPosition)
Selection of swiped elements is automatically updated.
fromPosition - previous position of the item.toPosition - new position of the item.public void onActionStateChanged(RecyclerView.ViewHolder viewHolder,
int actionState)
ItemTouchHelper first registers an item as being moved or swiped
or when has been released.
Override this method to receive touch events with its state.
onActionStateChanged in interface ItemTouchHelperCallback.AdapterCallbackviewHolder - the viewHolder touchedactionState - one of ItemTouchHelper#ACTION_STATE_SWIPE or
ItemTouchHelper#ACTION_STATE_DRAG or
ItemTouchHelper#ACTION_STATE_IDLE.public boolean shouldMove(int fromPosition,
int toPosition)
shouldMove in interface ItemTouchHelperCallback.AdapterCallbackfromPosition - the start position of the moving itemtoPosition - the potential target position of the moving itempublic boolean onItemMove(int fromPosition,
int toPosition)
Implementations should call Adapter#notifyItemMoved(int, int)
after adjusting the underlying data to reflect this move.
onItemMove in interface ItemTouchHelperCallback.AdapterCallbackfromPosition - the start position of the moved itemtoPosition - the resolved position of the moved itempublic void onItemSwiped(int position,
int direction)
Implementations should decide to call or not Adapter#notifyItemRemoved(int)
after adjusting the underlying data to reflect this removal.
onItemSwiped in interface ItemTouchHelperCallback.AdapterCallbackposition - the position of the item dismisseddirection - the direction to which the ViewHolder is swipedpublic void smoothScrollToPosition(int position)
position - the position to scroll to.public final void invalidateItemDecorations(long delay)
The delay will give time to the LayoutManagers to complete the layout of the child views.
Tip: A delay of100ms should be enough, anyway it can be customized.delay - delay to invalidate the decorationspublic void onSaveInstanceState(android.os.Bundle outState)
onSaveInstanceState in class SelectableAdapteroutState - Current statepublic void onRestoreInstanceState(android.os.Bundle savedInstanceState)
onRestoreInstanceState in class SelectableAdaptersavedInstanceState - Previous stateprotected void onPostUpdate()
FlexibleAdapter.OnUpdateListener for the emptyView.updateDataSet(List, boolean)protected void onPostFilter()
FlexibleAdapter.OnFilterListener for the filterView.filterItems(List)