public class

ComposedAdapter

extends RecyclerView.Adapter<VH extends RecyclerView.ViewHolder>
implements BridgeAdapterDataObserver.Subscriber WrapperAdapter<VH extends RecyclerView.ViewHolder>
java.lang.Object
   ↳ androidx.recyclerview.widget.RecyclerView.Adapter<VH extends androidx.recyclerview.widget.RecyclerView.ViewHolder>
     ↳ com.h6ah4i.android.widget.advrecyclerview.composedadapter.ComposedAdapter
Known Direct Subclasses

Class Overview

A wrapper adapter which can compose and manage several children adapters.

Summary

Fields
public static long NO_SEGMENTED_POSITION Corresponding segmented position value of NO_POSITION.
Public Constructors
ComposedAdapter()
Constructor.
Public Methods
ComposedChildAdapterTag addAdapter(Adapter adapter)
Add a child adapter to the tail.
ComposedChildAdapterTag addAdapter(Adapter adapter, int position)
Adda child adapter to the specified position.
static int extractSegmentOffsetPart(long segmentedPosition)
Returns the offset value extracted from a segmented position.
static int extractSegmentPart(long segmentedPosition)
Returns the segment value extracted from a segmented position.
int getChildAdapterCount()
Returns the total number of children adapters.
int getItemCount()
long getItemId(int position)
int getItemViewType(int position)
int getSegment(ComposedChildAdapterTag tag)
Returns the assigned segment number.
long getSegmentedPosition(int flatPosition)
Gets a "segmented position".
void getWrappedAdapters(List<Adapter> adapters)
Gets wrapped children adapters.
void onAttachedToRecyclerView(RecyclerView recyclerView)
void onBindViewHolder(RecyclerView.ViewHolder holder, int position)
void onBindViewHolder(RecyclerView.ViewHolder holder, int position, List<Object> payloads)
void onBridgedAdapterChanged(Adapter source, Object tag)
Routed onChanged() event.
void onBridgedAdapterItemRangeChanged(Adapter source, Object tag, int positionStart, int itemCount)
void onBridgedAdapterItemRangeChanged(Adapter source, Object tag, int positionStart, int itemCount, Object payload)
void onBridgedAdapterItemRangeInserted(Adapter source, Object tag, int positionStart, int itemCount)
void onBridgedAdapterItemRangeRemoved(Adapter source, Object tag, int positionStart, int itemCount)
void onBridgedAdapterRangeMoved(Adapter source, Object tag, int fromPosition, int toPosition, int itemCount)
RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
void onDetachedFromRecyclerView(RecyclerView recyclerView)
boolean onFailedToRecycleView(RecyclerView.ViewHolder holder)
boolean onFailedToRecycleView(RecyclerView.ViewHolder holder, int viewType)
void onViewAttachedToWindow(RecyclerView.ViewHolder holder)
void onViewAttachedToWindow(RecyclerView.ViewHolder holder, int viewType)
void onViewDetachedFromWindow(RecyclerView.ViewHolder holder)
void onViewDetachedFromWindow(RecyclerView.ViewHolder holder, int viewType)
void onViewRecycled(RecyclerView.ViewHolder holder)
void onViewRecycled(RecyclerView.ViewHolder holder, int viewType)
void release()
Releases bounded resources.
boolean removeAdapter(ComposedChildAdapterTag tag)
Remove a child adapter.
void setHasStableIds(boolean hasStableIds)
void unwrapPosition(UnwrapPositionResult dest, int position)
Unwraps position.
int wrapPosition(AdapterPathSegment pathSegment, int position)
Wraps position.
Protected Methods
void onHandleWrappedAdapterChanged(Adapter sourceAdapter, List<ComposedChildAdapterTag> sourceTags)
void onHandleWrappedAdapterItemRangeChanged(Adapter sourceAdapter, List<ComposedChildAdapterTag> sourceTags, int localPositionStart, int itemCount)
void onHandleWrappedAdapterItemRangeChanged(Adapter sourceAdapter, List<ComposedChildAdapterTag> sourceTags, int localPositionStart, int itemCount, Object payload)
void onHandleWrappedAdapterItemRangeInserted(Adapter sourceAdapter, List<ComposedChildAdapterTag> sourceTags, int localPositionStart, int itemCount)
void onHandleWrappedAdapterItemRangeRemoved(Adapter sourceAdapter, List<ComposedChildAdapterTag> sourceTags, int localPositionStart, int itemCount)
void onHandleWrappedAdapterRangeMoved(Adapter sourceAdapter, List<ComposedChildAdapterTag> sourceTags, int localFromPosition, int localToPosition, int itemCount)
void onRelease()
Implementation of the release() method.
[Expand]
Inherited Methods
From class androidx.recyclerview.widget.RecyclerView.Adapter
From class java.lang.Object
From interface com.h6ah4i.android.widget.advrecyclerview.adapter.BridgeAdapterDataObserver.Subscriber
From interface com.h6ah4i.android.widget.advrecyclerview.adapter.WrappedAdapter
From interface com.h6ah4i.android.widget.advrecyclerview.adapter.WrapperAdapter

Fields

public static long NO_SEGMENTED_POSITION

Corresponding segmented position value of NO_POSITION.

Public Constructors

public ComposedAdapter ()

Constructor.

Public Methods

public ComposedChildAdapterTag addAdapter (Adapter adapter)

Add a child adapter to the tail.

This method can be invoked before attaching (= call setAdapter(RecyclerView.Adapter)) to RecyclerView. Also it may throws an IllegalStateException if the ComposedAdapter has been configured to support stable IDs,

Parameters
adapter The adapter which to be managed by the ComposedAdapter
Returns

public ComposedChildAdapterTag addAdapter (Adapter adapter, int position)

Adda child adapter to the specified position.

Parameters
adapter The adapter which to be managed by the ComposedAdapter
position The position inserting a child adapter
Returns

public static int extractSegmentOffsetPart (long segmentedPosition)

Returns the offset value extracted from a segmented position.

Parameters
segmentedPosition The segment position value to be converted
Returns
  • offset part

public static int extractSegmentPart (long segmentedPosition)

Returns the segment value extracted from a segmented position.

Parameters
segmentedPosition The segment position value to be converted
Returns
  • segment part

public int getChildAdapterCount ()

Returns the total number of children adapters.

Returns
  • The total number of children adapters

public int getItemCount ()

public long getItemId (int position)

public int getItemViewType (int position)

public int getSegment (ComposedChildAdapterTag tag)

Returns the assigned segment number.

Parameters
tag The tag object linked to a child adapter
Returns
  • Number of the assigned segment

public long getSegmentedPosition (int flatPosition)

Gets a "segmented position".

The segmented position is a packed long value which contains "segment" and "offset inside of the segment" information.

Parameters
flatPosition The normal flat position to be converted
Returns
  • Segmented Position

public void getWrappedAdapters (List<Adapter> adapters)

Gets wrapped children adapters.

Parameters
adapters The destination

public void onAttachedToRecyclerView (RecyclerView recyclerView)

public void onBindViewHolder (RecyclerView.ViewHolder holder, int position)

public void onBindViewHolder (RecyclerView.ViewHolder holder, int position, List<Object> payloads)

public void onBridgedAdapterChanged (Adapter source, Object tag)

Routed onChanged() event.

Parameters
source The source adapter
tag The tag object

public void onBridgedAdapterItemRangeChanged (Adapter source, Object tag, int positionStart, int itemCount)

Parameters
source The source adapter
tag The tag object
positionStart Position of the first item that has changed
itemCount Number of items that have changed

public void onBridgedAdapterItemRangeChanged (Adapter source, Object tag, int positionStart, int itemCount, Object payload)

Parameters
source The source adapter
tag The tag object
positionStart Position of the first item that has changed
itemCount Number of items that have changed
payload Optional parameter, use null to identify a "full" update

public void onBridgedAdapterItemRangeInserted (Adapter source, Object tag, int positionStart, int itemCount)

Parameters
source The source adapter
tag The tag object
positionStart Position of the first item that was inserted
itemCount Number of items inserted

public void onBridgedAdapterItemRangeRemoved (Adapter source, Object tag, int positionStart, int itemCount)

Parameters
source The source adapter
tag The tag object
positionStart Previous position of the first item that was removed
itemCount Number of items removed from the data set

public void onBridgedAdapterRangeMoved (Adapter source, Object tag, int fromPosition, int toPosition, int itemCount)

Parameters
source The source adapter
tag The tag object
fromPosition Previous position of the item.
toPosition New position of the item.
itemCount Number of items moved (NOTE: this parameter is not actually used, always 1.)

public RecyclerView.ViewHolder onCreateViewHolder (ViewGroup parent, int viewType)

public void onDetachedFromRecyclerView (RecyclerView recyclerView)

public boolean onFailedToRecycleView (RecyclerView.ViewHolder holder)

public boolean onFailedToRecycleView (RecyclerView.ViewHolder holder, int viewType)

public void onViewAttachedToWindow (RecyclerView.ViewHolder holder)

public void onViewAttachedToWindow (RecyclerView.ViewHolder holder, int viewType)

public void onViewDetachedFromWindow (RecyclerView.ViewHolder holder)

public void onViewDetachedFromWindow (RecyclerView.ViewHolder holder, int viewType)

public void onViewRecycled (RecyclerView.ViewHolder holder)

public void onViewRecycled (RecyclerView.ViewHolder holder, int viewType)

public void release ()

Releases bounded resources.

public boolean removeAdapter (ComposedChildAdapterTag tag)

Remove a child adapter.

Parameters
tag The tag object linked to a child adapter to be removed
Returns
  • True if the child adapter is removed. Otherwise false.

public void setHasStableIds (boolean hasStableIds)

public void unwrapPosition (UnwrapPositionResult dest, int position)

Unwraps position. This method converts the passed wrapped position to child adapter's position.

Parameters
dest The destination
position The wrapped position to be unwrapped

public int wrapPosition (AdapterPathSegment pathSegment, int position)

Wraps position. This method converts the passed child adapter's position to wrapped position.

Parameters
pathSegment The path segment of the child adapter
position The child adapter's position to be wrapped
Returns
  • Wrapped position

Protected Methods

protected void onHandleWrappedAdapterChanged (Adapter sourceAdapter, List<ComposedChildAdapterTag> sourceTags)

protected void onHandleWrappedAdapterItemRangeChanged (Adapter sourceAdapter, List<ComposedChildAdapterTag> sourceTags, int localPositionStart, int itemCount)

protected void onHandleWrappedAdapterItemRangeChanged (Adapter sourceAdapter, List<ComposedChildAdapterTag> sourceTags, int localPositionStart, int itemCount, Object payload)

protected void onHandleWrappedAdapterItemRangeInserted (Adapter sourceAdapter, List<ComposedChildAdapterTag> sourceTags, int localPositionStart, int itemCount)

protected void onHandleWrappedAdapterItemRangeRemoved (Adapter sourceAdapter, List<ComposedChildAdapterTag> sourceTags, int localPositionStart, int itemCount)

protected void onHandleWrappedAdapterRangeMoved (Adapter sourceAdapter, List<ComposedChildAdapterTag> sourceTags, int localFromPosition, int localToPosition, int itemCount)

protected void onRelease ()

Implementation of the release() method.