ItemBridgeAdapter


class ItemBridgeAdapter : RecyclerView.Adapter, FacetProviderAdapter


Bridge from Presenter to RecyclerView.Adapter. Public to allow use by third party Presenters.

Summary

Nested types

Interface for listening to ViewHolder operations.

ViewHolder for the ItemBridgeAdapter.

Interface for wrapping a view created by a Presenter into another view.

Public constructors

ItemBridgeAdapter(
    adapter: ObjectAdapter!,
    presenterSelector: PresenterSelector!
)

Public functions

Unit

Clears the adapter.

FacetProvider!

Queries FacetProvider for a given type within Adapter.

Int

Returns the total number of items in the data set held by the adapter.

Long
getItemId(position: Int)

Return the stable ID for the item at position.

Int
getItemViewType(position: Int)

Return the view type of the item at position for the purposes of view recycling.

ArrayList<Presenter!>!

Returns the presenter mapper array.

ItemBridgeAdapter.Wrapper!

Returns the Wrapper.

Unit

Called by RecyclerView to display the data at the specified position.

Unit
onBindViewHolder(
    holder: RecyclerView.ViewHolder!,
    position: Int,
    payloads: (Mutable)List!
)

Called by RecyclerView to display the data at the specified position.

RecyclerView.ViewHolder!
onCreateViewHolder(parent: ViewGroup!, viewType: Int)

View.OnFocusChangeListener that assigned in onCreateViewHolder may be chained, user should never change View.OnFocusChangeListener after that.

Boolean

Called by the RecyclerView if a ViewHolder created by this Adapter cannot be recycled due to its transient state.

Unit

Called when a view created by this adapter has been attached to a window.

Unit

Called when a view created by this adapter has been detached from its window.

Unit

Called when a view created by this adapter has been recycled.

Unit

Sets the ObjectAdapter.

Unit

Sets the AdapterListener.

Unit
setPresenter(presenterSelector: PresenterSelector!)

Changes Presenter that creates and binds the view.

Unit

Sets the presenter mapper array.

Unit

Sets the Wrapper.

Protected functions

Unit
onAddPresenter(presenter: Presenter!, type: Int)

Called when presenter is added to Adapter.

Unit

Called when ViewHolder has been attached to window.

Unit

Called when ViewHolder has been bound to data.

Unit

Called when ViewHolder is created.

Unit

Called when ViewHolder has been detached from window.

Unit

Called when ViewHolder has been unbound from data.

Inherited functions

From androidx.recyclerview.widget.RecyclerView.Adapter
Unit
bindViewHolder(holder: VH, position: Int)

This method internally calls onBindViewHolder to update the ViewHolder contents with the item at the given position and also sets up some private fields to be used by RecyclerView.

VH
createViewHolder(parent: ViewGroup, viewType: Int)

This method calls onCreateViewHolder to create a new ViewHolder and initializes some private fields to be used by RecyclerView.

Int
findRelativeAdapterPositionIn(
    adapter: RecyclerView.Adapter<RecyclerView.ViewHolder!>,
    viewHolder: RecyclerView.ViewHolder,
    localPosition: Int
)

Returns the position of the given ViewHolder in the given Adapter.

RecyclerView.Adapter.StateRestorationPolicy

Returns when this Adapter wants to restore the state.

Boolean

Returns true if one or more observers are attached to this adapter.

Boolean

Returns true if this adapter publishes a unique long value that can act as a key for the item at a given position in the data set.

Unit

Notify any registered observers that the data set has changed.

Unit

Notify any registered observers that the item at position has changed.

Unit
notifyItemChanged(position: Int, payload: Any?)

Notify any registered observers that the item at position has changed with an optional payload object.

Unit

Notify any registered observers that the item reflected at position has been newly inserted.

Unit
notifyItemMoved(fromPosition: Int, toPosition: Int)

Notify any registered observers that the item reflected at fromPosition has been moved to toPosition.

Unit
notifyItemRangeChanged(positionStart: Int, itemCount: Int)

Notify any registered observers that the itemCount items starting at position positionStart have changed.

Unit
notifyItemRangeChanged(positionStart: Int, itemCount: Int, payload: Any?)

Notify any registered observers that the itemCount items starting at position positionStart have changed.

Unit
notifyItemRangeInserted(positionStart: Int, itemCount: Int)

Notify any registered observers that the currently reflected itemCount items starting at positionStart have been newly inserted.

Unit
notifyItemRangeRemoved(positionStart: Int, itemCount: Int)

Notify any registered observers that the itemCount items previously located at positionStart have been removed from the data set.

Unit

Notify any registered observers that the item previously located at position has been removed from the data set.

Unit

Called by RecyclerView when it starts observing this Adapter.

Unit

Called by RecyclerView when it stops observing this Adapter.

Unit

Register a new observer to listen for data changes.

Unit
setHasStableIds(hasStableIds: Boolean)

Indicates whether each item in the data set can be represented with a unique identifier of type java.lang.Long.

Unit

Sets the state restoration strategy for the Adapter.

Unit

Unregister an observer currently listening for data changes.

Public constructors

ItemBridgeAdapter

Added in 1.1.0
ItemBridgeAdapter()

ItemBridgeAdapter

Added in 1.1.0
ItemBridgeAdapter(adapter: ObjectAdapter!)

ItemBridgeAdapter

Added in 1.1.0
ItemBridgeAdapter(
    adapter: ObjectAdapter!,
    presenterSelector: PresenterSelector!
)

Public functions

clear

Added in 1.1.0
fun clear(): Unit

Clears the adapter.

getFacetProvider

Added in 1.2.0-alpha04
fun getFacetProvider(type: Int): FacetProvider!

Queries FacetProvider for a given type within Adapter.

Parameters
type: Int

type of the item.

Returns
FacetProvider!

Facet provider for the type.

getItemCount

Added in 1.1.0
fun getItemCount(): Int

Returns the total number of items in the data set held by the adapter.

Returns
Int

The total number of items in this adapter.

getItemId

fun getItemId(position: Int): Long

Return the stable ID for the item at position. If hasStableIds would return false this method should return NO_ID. The default implementation of this method returns NO_ID.

Parameters
position: Int

Adapter position to query

Returns
Long

the stable ID of the item at position

getItemViewType

fun getItemViewType(position: Int): Int

Return the view type of the item at position for the purposes of view recycling.

The default implementation of this method returns 0, making the assumption of a single view type for the adapter. Unlike ListView adapters, types need not be contiguous. Consider using id resources to uniquely identify item view types.

Parameters
position: Int

position to query

Returns
Int

integer value identifying the type of the view needed to represent the item at position. Type codes need not be contiguous.

getPresenterMapper

Added in 1.1.0
fun getPresenterMapper(): ArrayList<Presenter!>!

Returns the presenter mapper array.

getWrapper

Added in 1.1.0
fun getWrapper(): ItemBridgeAdapter.Wrapper!

Returns the Wrapper.

onBindViewHolder

Added in 1.1.0
fun onBindViewHolder(holder: RecyclerView.ViewHolder!, position: Int): Unit

Called by RecyclerView to display the data at the specified position. This method should update the contents of the itemView to reflect the item at the given position.

Note that unlike android.widget.ListView, RecyclerView will not call this method again if the position of the item changes in the data set unless the item itself is invalidated or the new position cannot be determined. For this reason, you should only use the position parameter while acquiring the related data item inside this method and should not keep a copy of it. If you need the position of an item later on (e.g. in a click listener), use getBindingAdapterPosition which will have the updated adapter position. Override onBindViewHolder instead if Adapter can handle efficient partial bind.

Parameters
holder: RecyclerView.ViewHolder!

The ViewHolder which should be updated to represent the contents of the item at the given position in the data set.

position: Int

The position of the item within the adapter's data set.

onBindViewHolder

Added in 1.1.0
fun onBindViewHolder(
    holder: RecyclerView.ViewHolder!,
    position: Int,
    payloads: (Mutable)List!
): Unit

Called by RecyclerView to display the data at the specified position. This method should update the contents of the itemView to reflect the item at the given position.

Note that unlike android.widget.ListView, RecyclerView will not call this method again if the position of the item changes in the data set unless the item itself is invalidated or the new position cannot be determined. For this reason, you should only use the position parameter while acquiring the related data item inside this method and should not keep a copy of it. If you need the position of an item later on (e.g. in a click listener), use getBindingAdapterPosition which will have the updated adapter position.

Partial bind vs full bind:

The payloads parameter is a merge list from notifyItemChanged or notifyItemRangeChanged. If the payloads list is not empty, the ViewHolder is currently bound to old data and Adapter may run an efficient partial update using the payload info. If the payload is empty, Adapter must run a full bind. Adapter should not assume that the payload passed in notify methods will be received by onBindViewHolder(). For example when the view is not attached to the screen, the payload in notifyItemChange() will be simply dropped.

Parameters
holder: RecyclerView.ViewHolder!

The ViewHolder which should be updated to represent the contents of the item at the given position in the data set.

position: Int

The position of the item within the adapter's data set.

payloads: (Mutable)List!

A non-null list of merged payloads. Can be empty list if requires full update.

onCreateViewHolder

Added in 1.1.0
fun onCreateViewHolder(parent: ViewGroup!, viewType: Int): RecyclerView.ViewHolder!

View.OnFocusChangeListener that assigned in onCreateViewHolder may be chained, user should never change View.OnFocusChangeListener after that.

onFailedToRecycleView

Added in 1.1.0
fun onFailedToRecycleView(holder: RecyclerView.ViewHolder!): Boolean

Called by the RecyclerView if a ViewHolder created by this Adapter cannot be recycled due to its transient state. Upon receiving this callback, Adapter can clear the animation(s) that effect the View's transient state and return true so that the View can be recycled. Keep in mind that the View in question is already removed from the RecyclerView.

In some cases, it is acceptable to recycle a View although it has transient state. Most of the time, this is a case where the transient state will be cleared in onBindViewHolder call when View is rebound to a new position. For this reason, RecyclerView leaves the decision to the Adapter and uses the return value of this method to decide whether the View should be recycled or not.

Note that when all animations are created by RecyclerView.ItemAnimator, you should never receive this callback because RecyclerView keeps those Views as children until their animations are complete. This callback is useful when children of the item views create animations which may not be easy to implement using an ItemAnimator.

You should never fix this issue by calling holder.itemView.setHasTransientState(false); unless you've previously called holder.itemView.setHasTransientState(true);. Each View.setHasTransientState(true) call must be matched by a View.setHasTransientState(false) call, otherwise, the state of the View may become inconsistent. You should always prefer to end or cancel animations that are triggering the transient state instead of handling it manually.

Parameters
holder: RecyclerView.ViewHolder!

The ViewHolder containing the View that could not be recycled due to its transient state.

Returns
Boolean

True if the View should be recycled, false otherwise. Note that if this method returns true, RecyclerView will ignore the transient state of the View and recycle it regardless. If this method returns false, RecyclerView will check the View's transient state again before giving a final decision. Default implementation returns false.

onViewAttachedToWindow

Added in 1.1.0
fun onViewAttachedToWindow(holder: RecyclerView.ViewHolder!): Unit

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. If the adapter previously freed any resources in onViewDetachedFromWindow those resources should be restored here.

Parameters
holder: RecyclerView.ViewHolder!

Holder of the view being attached

onViewDetachedFromWindow

Added in 1.1.0
fun onViewDetachedFromWindow(holder: RecyclerView.ViewHolder!): Unit

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 an Adapter's views may choose to cache views offscreen while they are not visible, attaching and detaching them as appropriate.

Parameters
holder: RecyclerView.ViewHolder!

Holder of the view being detached

onViewRecycled

Added in 1.1.0
fun onViewRecycled(holder: RecyclerView.ViewHolder!): Unit

Called when a view created by this adapter has been recycled.

A view is recycled when a LayoutManager decides that it no longer needs to be attached to its parent RecyclerView. This can be because it has fallen out of visibility or a set of cached views represented by views still attached to the parent RecyclerView. If an item view has large or expensive data bound to it such as large bitmaps, this may be a good place to release those resources.

RecyclerView calls this method right before clearing ViewHolder's internal data and sending it to RecycledViewPool. This way, if ViewHolder was holding valid information before being recycled, you can call getBindingAdapterPosition to get its adapter position.

Parameters
holder: RecyclerView.ViewHolder!

The ViewHolder for the view being recycled

setAdapter

Added in 1.1.0
fun setAdapter(adapter: ObjectAdapter!): Unit

Sets the ObjectAdapter.

setAdapterListener

Added in 1.1.0
fun setAdapterListener(listener: ItemBridgeAdapter.AdapterListener!): Unit

Sets the AdapterListener.

setPresenter

Added in 1.1.0
fun setPresenter(presenterSelector: PresenterSelector!): Unit

Changes Presenter that creates and binds the view.

Parameters
presenterSelector: PresenterSelector!

Presenter that creates and binds the view.

setPresenterMapper

Added in 1.1.0
fun setPresenterMapper(presenters: ArrayList<Presenter!>!): Unit

Sets the presenter mapper array.

setWrapper

Added in 1.1.0
fun setWrapper(wrapper: ItemBridgeAdapter.Wrapper!): Unit

Sets the Wrapper.

Protected functions

onAddPresenter

Added in 1.1.0
protected fun onAddPresenter(presenter: Presenter!, type: Int): Unit

Called when presenter is added to Adapter.

onAttachedToWindow

Added in 1.1.0
protected fun onAttachedToWindow(viewHolder: ItemBridgeAdapter.ViewHolder!): Unit

Called when ViewHolder has been attached to window.

onBind

Added in 1.1.0
protected fun onBind(viewHolder: ItemBridgeAdapter.ViewHolder!): Unit

Called when ViewHolder has been bound to data.

onCreate

Added in 1.1.0
protected fun onCreate(viewHolder: ItemBridgeAdapter.ViewHolder!): Unit

Called when ViewHolder is created.

onDetachedFromWindow

Added in 1.1.0
protected fun onDetachedFromWindow(viewHolder: ItemBridgeAdapter.ViewHolder!): Unit

Called when ViewHolder has been detached from window.

onUnbind

Added in 1.1.0
protected fun onUnbind(viewHolder: ItemBridgeAdapter.ViewHolder!): Unit

Called when ViewHolder has been unbound from data.