-
- All Implemented Interfaces:
-
eu.davidea.flexibleadapter.items.IFlexible
public abstract class AbstractFlexibleItem<VH extends RecyclerView.ViewHolder> implements IFlexible<VH>
Generic implementation of IFlexible interface with most useful methods to manage selection and view holder methods.
-
-
Method Summary
Modifier and Type Method Description abstract booleanequals(Object o)You MUST implement this method to compare items unique identifiers. booleanisEnabled()Returns if the Item is enabled. voidsetEnabled(boolean enabled)Setter to change enabled behaviour. booleanisHidden()(Internal usage).When and item has been deleted (with Undo) or has been filtered out by theadapter, then, it has hidden status. voidsetHidden(boolean hidden)Setter to change hidden behaviour. intgetSpanSize(int spanCount, int position)Individual item's span size to use only with {@code GridLayoutManager}.booleanshouldNotifyChange(IFlexible newItem)Called by the FlexibleAdapter when it wants to check if this item should be boundagain with new content. booleanisSelectable()Checks if the item can be selected. voidsetSelectable(boolean selectable)Setter to change selectable behaviour. StringgetBubbleText(int position)Custom bubble text for FastScroller. booleanisDraggable()voidsetDraggable(boolean draggable)booleanisSwipeable()voidsetSwipeable(boolean swipeable)intgetItemViewType()Identifies a specific view type for this item, used by FlexibleAdapter to auto-mapthe ViewTypes. abstract intgetLayoutRes()Returns the layout resource ID to auto-inflate the View for this item. abstract VHcreateViewHolder(View view, FlexibleAdapter<IFlexible> adapter)Delegates the creation of the ViewHolder to the user (AutoMap). abstract voidbindViewHolder(FlexibleAdapter<IFlexible> adapter, VH holder, int position, List<Object> payloads)Delegates the binding of this item's data to the given Layout. voidunbindViewHolder(FlexibleAdapter<IFlexible> adapter, VH holder, int position)Called when a view created by this adapter has been recycled. voidonViewAttached(FlexibleAdapter<IFlexible> adapter, VH holder, int position)Called when a view created by this adapter has been attached to a window. voidonViewDetached(FlexibleAdapter<IFlexible> adapter, VH holder, int position)Called when a view created by this adapter has been detached from its window. -
-
Method Detail
-
equals
abstract boolean equals(Object o)
You MUST implement this method to compare items unique identifiers.
Adapter needs this method to distinguish them and pick up correct items.
See Writing a correct{@code equals}method to implement your own{@code equals}method.Hint: If you don't use unique IDs, reimplement with Basic Java implementation:
public boolean equals(Object o) { return this == o; }Important Note: When used with
{@code Hash[Map,Set]}, the general contract for the{@code equals}and hashCode methods is that if{@code equals}returns{@code true}for any two objects, then{@code hashCode()}must return the same value for these objects.This means that subclasses of{@code Object}usually override either both methods or neitherof them.- Parameters:
o- instance to compare
-
isEnabled
boolean isEnabled()
Returns if the Item is enabled.
-
setEnabled
void setEnabled(boolean enabled)
Setter to change enabled behaviour.
- Parameters:
enabled- false to disable all operations on this item
-
isHidden
boolean isHidden()
(Internal usage).When and item has been deleted (with Undo) or has been filtered out by theadapter, then, it has hidden status.
-
setHidden
void setHidden(boolean hidden)
Setter to change hidden behaviour. Useful while filtering this item.Default value is false.
- Parameters:
hidden- true if this item should remain hidden, false otherwise
-
getSpanSize
int getSpanSize(int spanCount, int position)
Individual item's span size to use only with
{@code GridLayoutManager}.Note:
- Default implementation in AbstractFlexibleItem already returns 1.
- Not used when
{@code StaggeredGridLayoutManager}is set. With such layout use setFullSpan.
- Parameters:
spanCount- current column countposition- the adapter position of the item
-
shouldNotifyChange
boolean shouldNotifyChange(IFlexible newItem)
Called by the FlexibleAdapter when it wants to check if this item should be boundagain with new content.
You should return
Note: This method won't be called if setNotifyChangeOfUnfilteredItems is disabled.{@code true}whether you want this item will be updated becauseits visual representations will change.Default value is
{@code true}.- Parameters:
newItem- The new item object with the new content
-
isSelectable
boolean isSelectable()
Checks if the item can be selected.
-
setSelectable
void setSelectable(boolean selectable)
Setter to change selectable behaviour.
- Parameters:
selectable- false to disable selection on this item
-
getBubbleText
String getBubbleText(int position)
Custom bubble text for FastScroller.
To be called from the implementation of
{@code onCreateBubbleText()}. Example:public String onCreateBubbleText(int position) { return getItem(position).getBubbleText(position); }- Parameters:
position- the current mapped position
-
isDraggable
boolean isDraggable()
-
setDraggable
void setDraggable(boolean draggable)
-
isSwipeable
boolean isSwipeable()
-
setSwipeable
void setSwipeable(boolean swipeable)
-
getItemViewType
int getItemViewType()
Identifies a specific view type for this item, used by FlexibleAdapter to auto-mapthe ViewTypes.
HELP: To know how to implement AutoMap for ViewTypes please refer to theFlexibleAdapter Wiki Pageon GitHub.
If not overridden return value is the same of getLayoutRes.
-
getLayoutRes
abstract int getLayoutRes()
Returns the layout resource ID to auto-inflate the View for this item. Optionally, youcan assign same layout for multiple item types, but #getItemViewType() mustreturn unique values!
NOTE: Should identify a resource Layout reference .
-
createViewHolder
abstract VH createViewHolder(View view, FlexibleAdapter<IFlexible> adapter)
Delegates the creation of the ViewHolder to the user (AutoMap).
HELP: To know how to implement AutoMap for ViewTypes please refer to theFlexibleAdapter Wiki Pageon GitHub.
-
bindViewHolder
abstract void bindViewHolder(FlexibleAdapter<IFlexible> adapter, VH holder, int position, List<Object> payloads)
Delegates the binding of this item's data to the given Layout.
HELP: To know how to implement AutoMap for ViewTypes please refer to theFlexibleAdapter Wiki Pageon GitHub.
How to use Payload, please refer to RecyclerView.Adapter#onBindViewHolder(RecyclerView.ViewHolder, int, List).
-
unbindViewHolder
void unbindViewHolder(FlexibleAdapter<IFlexible> adapter, VH holder, int position)
Called when a view created by this adapter has been recycled.
A view is recycled when a RecyclerView.LayoutManager} decides that it no longerneeds to be attached to its parent RecyclerView. This can be because it has fallen outof visibility or a set of cached views represented by views still attached to the parentRecyclerView.
If an item view has large or expensive data bound to it such as large bitmaps, this may bea good place to release those resources.
-
onViewAttached
void onViewAttached(FlexibleAdapter<IFlexible> adapter, VH holder, int position)
Called when a view created by this adapter has been attached to a window.
This can be used as a reasonable signal that the view is about to be seen by the user.
-
onViewDetached
void onViewDetached(FlexibleAdapter<IFlexible> adapter, VH holder, int position)
Called when a view created by this adapter has been detached from its window.
Becoming detached from the window is not necessarily a permanent condition; the consumer of anAdapter's views may choose to cache views offscreen while they are not visible, attaching anddetaching them as appropriate.
-
-
-
-