epoxy-adapter / com.airbnb.epoxy / EpoxyModelGroup

EpoxyModelGroup

open class EpoxyModelGroup : EpoxyModelWithHolder<ModelGroupHolder!>

An EpoxyModel that contains other models, and allows you to combine those models in whatever view configuration you want.

The constructors take a list of models and a layout resource. The layout must have a viewgroup as its top level view; it determines how the view of each model is laid out. There are two ways to specify this

1. Leave the viewgroup empty. The view for each model will be inflated and added in order. This works fine if you don't need to include any other views, your model views don't need their layout params changed, and your views don't need ids (eg for saving state).

Alternatively you can have nested view groups, with the innermost viewgroup given the id "epoxy_model_group_child_container" to mark it as the viewgroup that should have the model views added to it. The viewgroup marked with this id should be empty. This allows you to nest viewgroups, such as a LinearLayout inside of a CardView.

2. Include a ViewStub for each of the models in the list. There should be at least as many view stubs as models. Extra stubs will be ignored. Each model will have its view replace the stub in order of the view stub's position in the view group. That is, the view group's children will be iterated through in order. The first view stub found will be used for the first model in the models list, the second view stub will be used for the second model, and so on. A depth first recursive search through nested viewgroups is done to find these viewstubs.

The layout can be of any ViewGroup subclass, and can have arbitrary other child views besides the view stubs. It can arrange the views and view stubs however is needed.

Any layout param options set on the view stubs will be transferred to the corresponding model view by default. If you want a model to keep the layout params from it's own layout resource you can override #useViewStubLayoutParams(EpoxyModel, int)

If you want to override the id used for a model's view you can set via xml. That id will be transferred over to the view taking that stub's place. This is necessary if you want your model to save view state, since without this the model's view won't have an id to associate the saved state with.

By default this model inherits the same id as the first model in the list. Call #id(long) to override that if needed.

When a model group is recycled, its child views are automatically recycled to a pool that is shared with all other model groups in the activity. This enables model groups to more efficiently manage their children. The shared pool is cleaned up when the activity is destroyed.

Constructors

<init>

EpoxyModelGroup(layoutRes: Int, models: MutableCollection<out EpoxyModel<*>!>!)
EpoxyModelGroup(layoutRes: Int, vararg models: EpoxyModel<*>!)EpoxyModelGroup()
EpoxyModelGroup(layoutRes: Int)

Constructor use for DSL

Properties

models

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

Functions

addModel

open fun addModel(model: EpoxyModel<*>): Unit

bind

open fun bind(holder: ModelGroupHolder): Unit
open fun bind(holder: ModelGroupHolder, payloads: MutableList<Any!>): Unit
open fun bind(holder: ModelGroupHolder, previouslyBoundModel: EpoxyModel<*>): Unit

createNewHolder

fun createNewHolder(parent: ViewParent): ModelGroupHolder!

equals

open fun equals(other: Any?): Boolean

getDefaultLayout

fun getDefaultLayout(): Int

getSpanSize

open fun getSpanSize(totalSpanCount: Int, position: Int, itemCount: Int): Int

hashCode

open fun hashCode(): Int

onViewAttachedToWindow

open fun onViewAttachedToWindow(holder: ModelGroupHolder): Unit

onViewDetachedFromWindow

open fun onViewDetachedFromWindow(holder: ModelGroupHolder): Unit

shouldSaveViewState

open fun shouldSaveViewState(shouldSaveViewState: Boolean): EpoxyModelGroup
open fun shouldSaveViewState(): Boolean

unbind

open fun unbind(holder: ModelGroupHolder): Unit

useViewStubLayoutParams

open fun useViewStubLayoutParams(model: EpoxyModel<*>!, modelPosition: Int): Boolean

Whether the layout params set on the view stub for the given model should be carried over to the model's view. Default is true

Inherited Functions

onFailedToRecycleView

open fun onFailedToRecycleView(holder: T): Boolean

onVisibilityChanged

open fun onVisibilityChanged(percentVisibleHeight: Float, percentVisibleWidth: Float, visibleHeight: Int, visibleWidth: Int, holder: T): Unit

onVisibilityStateChanged

open fun onVisibilityStateChanged(visibilityState: Int, holder: T): Unit

Inheritors

GroupModel

abstract class GroupModel : EpoxyModelGroup, ModelCollector

An EpoxyModelGroup usable in a DSL manner via the group extension.