Package 

Class FlexibleAdapter

  • 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:

    • Method Detail

      • 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
      • 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} event

        Usage:

        • 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}.

      • 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.
        Note: The following methods will be also called at the end of the operation:
        Parameters:
        items - the new data set
        animate - 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 list
        clazz - 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).
        Note: This method cannot be overridden since internal methods rely on it.
      • 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
      • 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 {@code Comparator} object should be customized to support alltypes of items this Adapter is managing or a {@code ClassCastException} will be raised.

        If the {@code Comparator} is {@code null} the returned position is 0 (first position).
        Parameters:
        item - the item to evaluate the insertion
        comparator - the Comparator object with the logic to sort the list
      • 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
      • 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 added
        delay - the delay in ms
        scrollToPosition - 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 added
        delay - the delay in ms
        scrollToPosition - true to scroll to the footer item position once it has been added
      • 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
      • isHeader

         boolean isHeader(T item)
        Parameters:
        item - the item to check
      • 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 header
        header - 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
      • 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).
        Important! In order to display the Refresh circle AND the FastScroller on the Top ofthe sticky container, the RecyclerView must be wrapped with a {@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 them
        stickyContainer - 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 {@code notifyItemInserted()} and scrollinganimations are instead performed if the header item was configured with animation:Headers will be loaded/bound along with others items.

        Note: Headers can only be shown or hidden all together.

        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 {@code notifyItemInserted} for adifferent loading effect: Headers will be inserted after the items!

        Note: Headers can only be shown or hidden all together.
      • 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.

      • 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 loading
        progressItem - 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 null
        delay - the delay used to remove the progress item or -1 to disable theloading forever and to keep the progress item visible.
      • setAutoCollapseOnExpand

         FlexibleAdapter<T> setAutoCollapseOnExpand(boolean collapseOnExpand)

        Automatically collapse all previous expanded parents before expand the new clicked parent.

        Default value is {@code false} (disabled).

        Tip: This parameter works in collaboration with setMinCollapsibleLevel.
        Parameters:
        collapseOnExpand - true to collapse others items, false to just expand the current
      • 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 {@code false} (keep expanded status).

        Tip: This parameter works in collaboration with setMinCollapsibleLevel.
        Parameters:
        collapseSubLevels - true to allow inner sub expandable to collapse, false to keep the expanded status
      • setAutoScrollOnExpand

         FlexibleAdapter<T> setAutoScrollOnExpand(boolean scrollOnExpand)

        Automatically scroll the clicked expandable item to the first visible position.

        Default value is {@code false} (disabled).

        Note: This works ONLY in combination with {@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
      • 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
      • 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 expand
        notifyParent - 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 list
        init - 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:

        Parent won't be notified.
        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 collapse
        notifyParent - 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 content
        payload - 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 rebound
        item - the item with the new content
        payload - 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 add
        item - the item to add
        delay - a non-negative delay
        scrollToPosition - 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 end
        item - 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 end
        items - 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 subItem
        subPosition - the position of the subItem in the expandable list
        item - the subItem to add in the expandable list
        expandParent - true to initially expand the parent (if needed) and after to addthe subItem, false to simply add the subItem to the parent
        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
      • 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 subItems
        subPosition - the start position in the parent where the new items shall be inserted
        items - the list of the subItems to add
        expandParent - true to initially expand the parent (if needed) and after to addthe subItems, false to simply add the subItems to the parent
        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
      • 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 add
        comparator - 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 {@code IExpandable} type or {@code IHeader} type.

        The Comparator object must support all the item types this Adapter is displaying ora ClassCastException will be raised.
        Parameters:
        sectionable - the item to add
        header - the section receiving the new item
        comparator - 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 add
        header - the section receiving the new item
        index - 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 add
        delay - a non-negative delay
        permanent - 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 remove
        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
      • 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 remove
        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
      • 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 item
        itemCount - how many items should be removed
        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
      • 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 {@code ActionMode} in order to not disable it.

        Default value is {@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.

      • saveUndoPositions

         void saveUndoPositions(@NonNull() List<Integer> undoPositions)
        Parameters:
        undoPositions - the positions to Undo with UndoHelper when {@code Action.UPDATE}.
      • 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
      • 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
      • 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 filter
        delay - 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
      • 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
      • 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.
      • 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 {@code false}.

        To use, it is sufficient to set the HandleView by calling setDragHandleView.
      • 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}.
        Default value is {@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 item
        toPosition - 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 item
        toPosition - new position of the item
        payload - 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