Presenter
public abstract class Presenter implements FacetProvider
AbstractDetailsDescriptionPresenter |
An abstract |
DetailsOverviewLogoPresenter |
Presenter that responsible to create a ImageView and bind to DetailsOverviewRow. |
DividerPresenter |
DividerPresenter provides a default presentation for |
RowHeaderPresenter |
RowHeaderPresenter provides a default presentation for |
RowPresenter |
An abstract |
VerticalGridPresenter |
A presenter that renders objects in a |
AbstractMediaItemPresenter |
Abstract |
AbstractMediaListHeaderPresenter |
Abstract presenter class for rendering the header for a list of media items in a playlist. |
DetailsOverviewRowPresenter |
This class is deprecated. |
FullWidthDetailsOverviewRowPresenter |
Renders a |
ListRowPresenter |
ListRowPresenter renders |
PlaybackControlsRowPresenter |
A PlaybackControlsRowPresenter renders a |
PlaybackRowPresenter |
Subclass of |
PlaybackTransportRowPresenter |
A PlaybackTransportRowPresenter renders a |
A Presenter is used to generate Views and bind Objects to them on demand. It is closely related to the concept of an RecyclerView.Adapter, but is not position-based. The leanback framework implements the adapter concept using ObjectAdapter which refers to a Presenter (or PresenterSelector) instance.
Presenters should be stateless. Presenters typically extend ViewHolder to store all necessary view state information, such as references to child views to be used when binding to avoid expensive calls to findViewById.
A trivial Presenter that takes a string and renders it into a TextView:
public class StringTextViewPresenter extends Presenter { // This class does not need a custom ViewHolder, since it does not use // a complex layout. @Override public ViewHolder onCreateViewHolder(ViewGroup parent) { return new ViewHolder(new TextView(parent.getContext())); } @Override public void onBindViewHolder(ViewHolder viewHolder, Object item) { String str = (String) item; TextView textView = (TextView) viewHolder.mView; textView.setText(item); } @Override public void onUnbindViewHolder(ViewHolder viewHolder) { // Nothing to unbind for TextView, but if this viewHolder had // allocated bitmaps, they can be released here. } }
setFacet. Supported facets: ItemAlignmentFacet is used by HorizontalGridView and VerticalGridView to customize child alignment.
Summary
Nested types |
|---|
public class Presenter.ViewHolder implements FacetProviderViewHolder can be subclassed and used to cache any view accessors needed to improve binding performance (for example, results of findViewById) without needing to subclass a View. |
public abstract class Presenter.ViewHolderTaskBase class to perform a task on Presenter.ViewHolder. |
Public constructors |
|---|
Public methods |
|
|---|---|
final Object |
Queries optional implemented facet. |
abstract void |
onBindViewHolder(Binds a |
void |
onBindViewHolder(Binds a |
abstract @NonNull Presenter.ViewHolder |
onCreateViewHolder(@NonNull ViewGroup parent)Creates a new |
abstract void |
onUnbindViewHolder(@NonNull Presenter.ViewHolder viewHolder)Unbinds a |
void |
Called when a view created by this presenter has been attached to a window. |
void |
Called when a view created by this presenter has been detached from its window. |
final void |
Sets dynamic implemented facet in addition to basic Presenter functions. |
void |
setOnClickListener(Called to set a click listener for the given view holder. |
Protected methods |
|
|---|---|
static void |
Utility method for removing all running animations on a view. |
Public constructors
Public methods
getFacet
public final Object getFacet(Class<Object> facetClass)
Queries optional implemented facet.
| Parameters | |
|---|---|
Class<Object> facetClass |
Facet classes to query, examples are: class of |
| Returns | |
|---|---|
Object |
Facet implementation for the facetClass or null if feature not implemented. |
onBindViewHolder
public abstract void onBindViewHolder(
@NonNull Presenter.ViewHolder viewHolder,
@Nullable Object item
)
Binds a View to an item.
onBindViewHolder
public void onBindViewHolder(
@NonNull Presenter.ViewHolder viewHolder,
@NonNull Object item,
@NonNull List<Object> payloads
)
Binds a View to an item with a list of payloads.
| Parameters | |
|---|---|
@NonNull Presenter.ViewHolder viewHolder |
The ViewHolder which should be updated to represent the contents of the item at the given position in the data set. |
@NonNull Object item |
The item which should be bound to view holder. |
@NonNull List<Object> payloads |
A non-null list of merged payloads. Can be empty list if requires full update. |
onCreateViewHolder
public abstract @NonNull Presenter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent)
Creates a new View.
onUnbindViewHolder
public abstract void onUnbindViewHolder(@NonNull Presenter.ViewHolder viewHolder)
Unbinds a View from an item. Any expensive references may be released here, and any fields that are not bound for every item should be cleared here.
onViewAttachedToWindow
public void onViewAttachedToWindow(@NonNull Presenter.ViewHolder holder)
Called when a view created by this presenter 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 | |
|---|---|
@NonNull Presenter.ViewHolder holder |
Holder of the view being attached |
onViewDetachedFromWindow
public void onViewDetachedFromWindow(@NonNull Presenter.ViewHolder holder)
Called when a view created by this presenter has been detached from its window.
Becoming detached from the window is not necessarily a permanent condition; the consumer of an presenter's views may choose to cache views offscreen while they are not visible, attaching and detaching them as appropriate.
Any view property animations should be cancelled here or the view may fail to be recycled.| Parameters | |
|---|---|
@NonNull Presenter.ViewHolder holder |
Holder of the view being detached |
setFacet
public final void setFacet(Class<Object> facetClass, Object facetImpl)
Sets dynamic implemented facet in addition to basic Presenter functions.
| Parameters | |
|---|---|
Class<Object> facetClass |
Facet classes to query, can be class of |
Object facetImpl |
Facet implementation. |
setOnClickListener
public void setOnClickListener(
Presenter.ViewHolder holder,
View.OnClickListener listener
)
Called to set a click listener for the given view holder. The default implementation sets the click listener on the root view in the view holder. If the root view isn't focusable this method should be overridden to set the listener on the appropriate focusable child view(s).
| Parameters | |
|---|---|
Presenter.ViewHolder holder |
The view holder containing the view(s) on which the listener should be set. |
View.OnClickListener listener |
The click listener to be set. |
Protected methods
cancelAnimationsRecursive
protected static void cancelAnimationsRecursive(View view)
Utility method for removing all running animations on a view.