Package 

Class EpoxyModelGroup


  • 
    public class EpoxyModelGroup
    extends 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

    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 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.

    • Method Summary

      Modifier and Type Method Description
      void bind(@NonNull() ModelGroupHolder holder) Binds the current data to the given view.
      void bind(@NonNull() ModelGroupHolder holder, @NonNull() List<Object> payloads) Similar to bind, but provides a non null, non empty list of payloadsdescribing what changed.
      void bind(@NonNull() ModelGroupHolder holder, @NonNull() EpoxyModel<out Object> previouslyBoundModel) Similar to bind, but provides a non null model which was previously bound tothis view.
      void unbind(@NonNull() ModelGroupHolder holder) Called when the view bound to this model is recycled.
      void onViewAttachedToWindow(ModelGroupHolder holder) Called when this model's view is attached to the window.
      void onViewDetachedFromWindow(ModelGroupHolder holder) Called when this model's view is detached from the the window.
      int getSpanSize(int totalSpanCount, int position, int itemCount) Subclasses can override this if they want their view to take up more than one span in a gridlayout.
      EpoxyModelGroup shouldSaveViewState(boolean shouldSaveViewState)
      boolean shouldSaveViewState() Whether the adapter should save the state of the view bound to this model.
      boolean equals(Object o)
      int hashCode()
      • Methods inherited from class com.airbnb.epoxy.EpoxyModelWithHolder

        bind, bind, bind, onFailedToRecycleView, onViewAttachedToWindow, onViewDetachedFromWindow, onVisibilityChanged, onVisibilityStateChanged, unbind
      • Methods inherited from class com.airbnb.epoxy.EpoxyModel

        addIf, addIf, addTo, bind, bind, bind, buildView, getLayout, hide, id, id, id, id, id, id, id, isShown, layout, onFailedToRecycleView, onViewAttachedToWindow, onViewDetachedFromWindow, onVisibilityChanged, onVisibilityStateChanged, preBind, reset, show, show, spanSize, spanSizeOverride, toString, unbind
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • EpoxyModelGroup

        EpoxyModelGroup(int layoutRes, Collection<out EpoxyModel<out Object>> models)
        Parameters:
        layoutRes - The layout to use with these models.
        models - The models that will be used to bind the views in the given layout.
      • EpoxyModelGroup

        EpoxyModelGroup(int layoutRes, Array<EpoxyModel<out Object>> models)
        Parameters:
        layoutRes - The layout to use with these models.
        models - The models that will be used to bind the views in the given layout.
    • Method Detail

      • bind

        @CallSuper() void bind(@NonNull() ModelGroupHolder holder)

        Binds the current data to the given view. You should bind all fields including unset/emptyfields to ensure proper recycling.

      • bind

        @CallSuper() void bind(@NonNull() ModelGroupHolder holder, @NonNull() List<Object> payloads)

        Similar to bind, but provides a non null, non empty list of payloadsdescribing what changed. This is the payloads list specified in the adapter's notifyItemChangedmethod. This is a useful optimization to allow you to only change part of a view instead ofupdating the whole thing, which may prevent unnecessary layout calls. If there are no payloadsthen bind is called instead. This will only be used if the model is used withan EpoxyAdapter

      • bind

         void bind(@NonNull() ModelGroupHolder holder, @NonNull() EpoxyModel<out Object> previouslyBoundModel)

        Similar to bind, but provides a non null model which was previously bound tothis view. This will only be called if the model is used with an EpoxyController.

        Parameters:
        previouslyBoundModel - This is a model with the same id that was previously bound.
      • unbind

        @CallSuper() void unbind(@NonNull() ModelGroupHolder holder)

        Called when the view bound to this model is recycled. Subclasses can override this if theirview should release resources when it's recycled.

        Note that bind can be called multiple times without an unbind call in betweenif the view has remained on screen to be reused across item changes. This means that you shouldnot rely on unbind to clear a view or model's state before bind is called again.

      • getSpanSize

         int getSpanSize(int totalSpanCount, int position, int itemCount)

        Subclasses can override this if they want their view to take up more than one span in a gridlayout.

        Parameters:
        totalSpanCount - The number of spans in the grid
        position - The position of the model
        itemCount - The total number of items in the adapter
      • shouldSaveViewState

         boolean shouldSaveViewState()

        Whether the adapter should save the state of the view bound to this model.