epoxy-adapter / com.airbnb.epoxy / EpoxyAdapter

EpoxyAdapter

abstract class EpoxyAdapter : BaseEpoxyAdapter

Allows you to easily combine different view types in the same adapter, and handles view holder creation, binding, and ids for you. Subclasses just need to add their desired EpoxyModel objects and the rest is done automatically.

androidx.recyclerview.widget.RecyclerView.Adapter#setHasStableIds(boolean) is set to true by default, since EpoxyModel makes it easy to support unique ids. If you don't want to support this then disable it in your base class (not recommended).

Constructors

<init>

EpoxyAdapter()

Allows you to easily combine different view types in the same adapter, and handles view holder creation, binding, and ids for you. Subclasses just need to add their desired EpoxyModel objects and the rest is done automatically.

Properties

models

val models: MutableList<EpoxyModel<*>!>!

Subclasses should modify this list as necessary with the models they want to show. Subclasses are responsible for notifying data changes whenever this list is changed.

Functions

addModel

open fun addModel(modelToAdd: EpoxyModel<*>!): Unit

Adds the model to the end of the #models list and notifies that the item was inserted.

addModels

open fun addModels(vararg modelsToAdd: EpoxyModel<*>!): Unit
open fun addModels(modelsToAdd: MutableCollection<out EpoxyModel<*>!>!): Unit

Adds the models to the end of the #models list and notifies that the items were inserted.

enableDiffing

open fun enableDiffing(): Unit

Enables support for automatically notifying model changes via #notifyModelsChanged(). If used, this should be called in the constructor, before any models are changed.

getAllModelsAfter

open fun getAllModelsAfter(model: EpoxyModel<*>!): MutableList<EpoxyModel<*>!>!

Returns a sub list of all items in #models that occur after the given model. This list is backed by the original models list, any changes to the returned list will be reflected in the original #models list.

hideAllAfterModel

open fun hideAllAfterModel(model: EpoxyModel<*>!): Unit

Hides all models currently located after the given model in the #models list.

hideModel

open fun hideModel(model: EpoxyModel<*>!): Unit

Hides the given model, and notifies that the item changed if the item wasn't already hidden.

hideModels

open fun hideModels(models: MutableIterable<EpoxyModel<*>!>!): Unit
open fun hideModels(vararg models: EpoxyModel<*>!): Unit

Hides the given models, and notifies that each item changed if the item wasn't already hidden.

insertModelAfter

open fun insertModelAfter(modelToInsert: EpoxyModel<*>!, modelToInsertAfter: EpoxyModel<*>!): Unit

Inserts the given model after the other in the #models list, and notifies that the item was inserted.

insertModelBefore

open fun insertModelBefore(modelToInsert: EpoxyModel<*>!, modelToInsertBefore: EpoxyModel<*>!): Unit

Inserts the given model before the other in the #models list, and notifies that the item was inserted.

notifyModelChanged

open fun notifyModelChanged(model: EpoxyModel<*>!): Unit
open fun notifyModelChanged(model: EpoxyModel<*>!, payload: Any?): Unit

Notify that the given model has had its data changed. It should only be called if the model retained the same position.

notifyModelsChanged

open fun notifyModelsChanged(): Unit

Intelligently notify item changes by comparing the current #models list against the previous so you don't have to micromanage notification calls yourself. This may be prohibitively slow for large model lists (in the hundreds), in which case consider doing notification calls yourself. If you use this, all your view models must implement and EpoxyModel#equals(Object) to completely identify their state, so that changes to a model's content can be detected. Before using this you must enable it with #enableDiffing(), since keeping track of the model state adds extra computation time to all other data change notifications.

removeAllAfterModel

open fun removeAllAfterModel(model: EpoxyModel<*>!): Unit

Removes all models after the given model, which must have already been added. An example use case is you want to keep a header but clear everything else, like in the case of refreshing data.

removeAllModels

open fun removeAllModels(): Unit

Removes all models

removeModel

open fun removeModel(model: EpoxyModel<*>!): Unit

If the given model exists it is removed and an item removal is notified. Otherwise this does nothing.

showModel

open fun showModel(model: EpoxyModel<*>!, show: Boolean): Unit

Sets the visibility of the given model, and notifies that the item changed if the new visibility is different from the previous.

open fun showModel(model: EpoxyModel<*>!): Unit

Shows the given model, and notifies that the item changed if the item wasn't already shown.

showModels

open fun showModels(vararg models: EpoxyModel<*>!): Unit
open fun showModels(models: MutableIterable<EpoxyModel<*>!>!): Unit

Shows the given models, and notifies that each item changed if the item wasn't already shown.

open fun showModels(show: Boolean, vararg models: EpoxyModel<*>!): Unit
open fun showModels(models: MutableIterable<EpoxyModel<*>!>!, show: Boolean): Unit

Sets the visibility of the given models, and notifies that the items changed if the new visibility is different from the previous.

Inherited Functions

getBoundViewHolders

open fun getBoundViewHolders(): BoundViewHolders!

Returns an object that manages the view holders currently bound to the RecyclerView. This object is mainly used by the base Epoxy adapter to save view states, but you may find it useful to help access views or models currently shown in the RecyclerView.

getItemCount

open fun getItemCount(): Int

getItemId

open fun getItemId(position: Int): Long

getItemViewType

open fun getItemViewType(position: Int): Int

getModelPosition

open fun getModelPosition(model: EpoxyModel<*>!): Int

Finds the position of the given model in the list. Doesn't use indexOf to avoid unnecessary equals() calls since we're looking for the same object instance.

getSpanCount

open fun getSpanCount(): Int

getSpanSizeLookup

open fun getSpanSizeLookup(): SpanSizeLookup!

For use with a grid layout manager - use this to get the SpanSizeLookup for models in this adapter. This will delegate span look up calls to each model's . Make sure to also call #setSpanCount(int) so the span count is correct.

isEmpty

open fun isEmpty(): Boolean

isMultiSpan

open fun isMultiSpan(): Boolean

isStickyHeader

open fun isStickyHeader(position: Int): Boolean

Called to check if the item at the position is a sticky item, by default returns false.

onBindViewHolder

open fun onBindViewHolder(holder: EpoxyViewHolder, position: Int): Unit
open fun onBindViewHolder(holder: EpoxyViewHolder, position: Int, payloads: MutableList<Any!>): Unit

onCreateViewHolder

open fun onCreateViewHolder(parent: ViewGroup, viewType: Int): EpoxyViewHolder

onDetachedFromRecyclerView

open fun onDetachedFromRecyclerView(recyclerView: RecyclerView): Unit

onExceptionSwallowed

open fun onExceptionSwallowed(exception: RuntimeException!): Unit

This is called when recoverable exceptions happen at runtime. They can be ignored and Epoxy will recover, but you can override this to be aware of when they happen.

onFailedToRecycleView

open fun onFailedToRecycleView(holder: EpoxyViewHolder): Boolean

onModelBound

open fun onModelBound(holder: EpoxyViewHolder!, model: EpoxyModel<*>!, position: Int, payloads: MutableList<Any!>?): Unit
open fun onModelBound(holder: EpoxyViewHolder!, model: EpoxyModel<*>!, position: Int): Unit

Called immediately after a model is bound to a view holder. Subclasses can override this if they want alerts on when a model is bound.

onModelUnbound

open fun onModelUnbound(holder: EpoxyViewHolder!, model: EpoxyModel<*>!): Unit

Called immediately after a model is unbound from a view holder. Subclasses can override this if they want alerts on when a model is unbound.

onRestoreInstanceState

open fun onRestoreInstanceState(inState: Bundle?): Unit

onSaveInstanceState

open fun onSaveInstanceState(outState: Bundle!): Unit

onViewAttachedToWindow

open fun onViewAttachedToWindow(holder: EpoxyViewHolder): Unit

onViewDetachedFromWindow

open fun onViewDetachedFromWindow(holder: EpoxyViewHolder): Unit

onViewRecycled

open fun onViewRecycled(holder: EpoxyViewHolder): Unit

setSpanCount

open fun setSpanCount(spanCount: Int): Unit

If you are using a grid layout manager you must call this to set the span count of the grid. This span count will be passed on to the models so models can choose what span count to be.

setupStickyHeaderView

open fun setupStickyHeaderView(stickyHeader: View): Unit

Optional callback to setup the sticky view, by default it doesn't do anything.

teardownStickyHeaderView

open fun teardownStickyHeaderView(stickyHeader: View): Unit

Optional callback to perform tear down operation on the sticky view, by default it doesn't do anything.

Inheritors

SimpleEpoxyAdapter

open class SimpleEpoxyAdapter : EpoxyAdapter

A non-abstract version of com.airbnb.epoxy.EpoxyAdapter that exposes all methods and models as public. Use this if you don't want to create your own adapter subclass and instead want to modify the adapter from elsewhere, such as from an activity.