Class DataBindingEpoxyModel
- java.lang.Object
-
- com.airbnb.epoxy.EpoxyModel<T>
-
- com.airbnb.epoxy.EpoxyModelWithHolder<DataBindingEpoxyModel.DataBindingHolder>
-
- com.airbnb.epoxy.DataBindingEpoxyModel
-
public abstract class DataBindingEpoxyModel extends com.airbnb.epoxy.EpoxyModelWithHolder<DataBindingEpoxyModel.DataBindingHolder>
A version ofEpoxyModelthat can be used with databinding. The layout resource used with this model must be a databinding layout. This class will create the databinding object from the layout and call thesetDataBindingVariables(androidx.databinding.ViewDataBinding)methods when the view needs binding to the model.The easiest way to use this model is to have Epoxy generate a model to do all the binding work for you. To do this, create an abstract subclass of this model, annotate it with
EpoxyModelClass, and pass your layout resource as the layout param. (You must pass the layout this way instead of implementingEpoxyModel.getDefaultLayout()).Then, make a field to represent each of the data variables in your layout and annotate each one with
EpoxyAttribute. The name of each field must match the name of the variable in the layout exactly.Epoxy will generate a subclass of your model at compile time that implements
setDataBindingVariables(ViewDataBinding)andsetDataBindingVariables(ViewDataBinding, EpoxyModel)for you. This will do all binding for you, and also only bind variables that change if you update your model (Note: The change optimization only works when used withEpoxyController).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDataBindingEpoxyModel.DataBindingHolder
-
Constructor Summary
Constructors Constructor Description DataBindingEpoxyModel()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidbind(DataBindingEpoxyModel.DataBindingHolder holder)voidbind(DataBindingEpoxyModel.DataBindingHolder holder, com.airbnb.epoxy.EpoxyModel<?> previouslyBoundModel)voidbind(DataBindingEpoxyModel.DataBindingHolder holder, List<Object> payloads)ViewbuildView(ViewGroup parent)protected DataBindingEpoxyModel.DataBindingHoldercreateNewHolder(ViewParent parent)protected abstract voidsetDataBindingVariables(androidx.databinding.ViewDataBinding binding)This is called when the model is bound to a view, and the view's variables should be updated with the model's data.protected voidsetDataBindingVariables(androidx.databinding.ViewDataBinding dataBinding, com.airbnb.epoxy.EpoxyModel<?> previouslyBoundModel)Similar tosetDataBindingVariables(ViewDataBinding), but this method only binds variables that have changed.protected voidsetDataBindingVariables(androidx.databinding.ViewDataBinding dataBinding, List<Object> payloads)voidunbind(DataBindingEpoxyModel.DataBindingHolder holder)-
Methods inherited from class com.airbnb.epoxy.EpoxyModelWithHolder
onFailedToRecycleView, onViewAttachedToWindow, onViewDetachedFromWindow, onVisibilityChanged, onVisibilityStateChanged
-
Methods inherited from class com.airbnb.epoxy.EpoxyModel
addIf, addIf, addTo, addWithDebugValidation, equals, getDefaultLayout, getLayout, getSpanSize, getViewType, hashCode, hide, id, id, id, id, id, id, id, isShown, layout, onMutation, preBind, reset, shouldSaveViewState, show, show, spanSize, spanSizeOverride, toString, validateStateHasNotChangedSinceAdded
-
-
-
-
Method Detail
-
buildView
public View buildView(@NonNull ViewGroup parent)
- Overrides:
buildViewin classcom.airbnb.epoxy.EpoxyModel<DataBindingEpoxyModel.DataBindingHolder>
-
bind
public void bind(@NonNull DataBindingEpoxyModel.DataBindingHolder holder)- Overrides:
bindin classcom.airbnb.epoxy.EpoxyModelWithHolder<DataBindingEpoxyModel.DataBindingHolder>
-
bind
public void bind(@NonNull DataBindingEpoxyModel.DataBindingHolder holder, @NonNull com.airbnb.epoxy.EpoxyModel<?> previouslyBoundModel)- Overrides:
bindin classcom.airbnb.epoxy.EpoxyModelWithHolder<DataBindingEpoxyModel.DataBindingHolder>
-
bind
public void bind(@NonNull DataBindingEpoxyModel.DataBindingHolder holder, @NonNull List<Object> payloads)- Overrides:
bindin classcom.airbnb.epoxy.EpoxyModelWithHolder<DataBindingEpoxyModel.DataBindingHolder>
-
setDataBindingVariables
protected abstract void setDataBindingVariables(androidx.databinding.ViewDataBinding binding)
This is called when the model is bound to a view, and the view's variables should be updated with the model's data.ViewDataBinding.executePendingBindings()is called for you after this method is run.If you leave your class abstract and have a model generated for you via annotations this will be implemented for you. However, you may choose to implement this manually if you like.
-
setDataBindingVariables
protected void setDataBindingVariables(androidx.databinding.ViewDataBinding dataBinding, com.airbnb.epoxy.EpoxyModel<?> previouslyBoundModel)Similar tosetDataBindingVariables(ViewDataBinding), but this method only binds variables that have changed. The changed model comes frombind(DataBindingHolder, EpoxyModel). This will only be called if the model is used in anEpoxyControllerIf you leave your class abstract and have a model generated for you via annotations this will be implemented for you. However, you may choose to implement this manually if you like.
-
setDataBindingVariables
protected void setDataBindingVariables(androidx.databinding.ViewDataBinding dataBinding, List<Object> payloads)
-
unbind
public void unbind(@NonNull DataBindingEpoxyModel.DataBindingHolder holder)- Overrides:
unbindin classcom.airbnb.epoxy.EpoxyModelWithHolder<DataBindingEpoxyModel.DataBindingHolder>
-
createNewHolder
protected final DataBindingEpoxyModel.DataBindingHolder createNewHolder(@NonNull ViewParent parent)
- Specified by:
createNewHolderin classcom.airbnb.epoxy.EpoxyModelWithHolder<DataBindingEpoxyModel.DataBindingHolder>
-
-