AbstractMediaItemPresenter

public abstract class AbstractMediaItemPresenter extends RowPresenter


Abstract Presenter class for rendering media items in a playlist format. Media item data provided for this presenter can implement the interface MultiActionsProvider, if the media rows wish to contain custom actions. Media items in the playlist are arranged as a vertical list with each row holding each media item's details provided by the user of this class and a set of optional custom actions. Each media item's details and actions are separately focusable. The appearance of each one of the media row components can be controlled through setting theme's attributes. Each media item row provides a view flipper for switching between different views depending on the playback state. A default layout is provided by this presenter for rendering different playback states, or a custom layout can be provided by the user by overriding the playbackMediaItemNumberViewFlipperLayout attribute in the currently specified theme. Subclasses should also override getMediaPlayState to provide the current play state of their media item model in case they wish to use different views depending on the playback state. The presenter can optionally provide line separators between media rows by setting setHasMediaRowSeparator to true.

Subclasses must override onBindMediaDetails to implement their media item model data binding to each row view.

The OnItemViewClickedListener and OnItemViewSelectedListener can be used in the same fashion to handle selection or click events on either of media details or each individual action views.

AbstractMediaListHeaderPresenter can be used in conjunction with this presenter in order to display a playlist with a header view.

Summary

Nested types

The ViewHolder for the AbstractMediaItemPresenter.

Constants

static final int

Indicating that the media item is currently neither playing nor paused.

static final int

Indicating that the media item is currently paused.

static final int

Indicating that the media item is currently playing

Public constructors

Constructor used for creating an abstract media item presenter.

Constructor used for creating an abstract media item presenter.

Public methods

Presenter

Return the presenter used to render a media item row actions.

int

Return The resource id of the theme that defines attributes controlling the appearance of different widgets in a media item row.

boolean
boolean

Returns true if this RowPresenter is using the default dimming effect.

void

Binds the media item number view to the appropriate play state view of the media item.

void

Called when the given ViewHolder wants to unbind the play state view.

void
setActionPresenter(Presenter actionPresenter)

Sets the action presenter rendering each optional custom action within each media item row.

void
setBackgroundColor(int color)

Sets the background color for the row views within the playlist.

void
setHasMediaRowSeparator(boolean hasSeparator)

Specifies whether a line separator should be used between media item rows.

void
setThemeId(int themeId)

Sets the theme used to style a media item row components.

Protected methods

RowPresenter.ViewHolder

Called to create a ViewHolder object for a Row.

int

Returns the current play state of the given media item.

boolean

Returns true if the Row view should clip its children.

abstract void

Binds the media item details to their views provided by the AbstractMediaItemPresenter.

void

Binds the given media item object action to the given ViewHolder's action views.

void

Binds the given row object to the given ViewHolder.

void

Unbinds the media item details from their views provided by the AbstractMediaItemPresenter.

Inherited Constants

From androidx.leanback.widget.RowPresenter
static final int

Don't synchronize row view activated status with selected status or expanded status, application will do its own through setActivated.

static final int

Synchronizes row view's activated status to expand status of the row view holder.

static final int

Sets the row view's activated status to true when both expand and selected are true.

static final int

Synchronizes row view's activated status to selected status of the row view holder.

Inherited methods

From androidx.leanback.widget.FacetProvider
abstract @Nullable Object
getFacet(@NonNull Class<Object> facetClass)

Queries optional implemented facet.

From androidx.leanback.widget.Presenter
static void

Utility method for removing all running animations on a view.

final Object
getFacet(Class<Object> facetClass)

Queries optional implemented facet.

abstract void
onBindViewHolder(
    @NonNull Presenter.ViewHolder viewHolder,
    @Nullable Object item
)

Binds a View to an item.

void
onBindViewHolder(
    @NonNull Presenter.ViewHolder viewHolder,
    @NonNull Object item,
    @NonNull List<Object> payloads
)

Binds a View to an item with a list of payloads.

abstract @NonNull Presenter.ViewHolder

Creates a new View.

abstract void

Unbinds a View from an item.

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
setFacet(Class<Object> facetClass, Object facetImpl)

Sets dynamic implemented facet in addition to basic Presenter functions.

void

Called to set a click listener for the given view holder.

From androidx.leanback.widget.RowPresenter
void
dispatchItemSelectedListener(
    RowPresenter.ViewHolder vh,
    boolean selected
)

This method is only called from onRowViewSelected onRowViewSelected.

void
freeze(@NonNull RowPresenter.ViewHolder holder, boolean freeze)

Freezes/unfreezes the row, typically used when a transition starts/ends.

final RowHeaderPresenter

Returns the Presenter used for rendering the header, or null if none has been set.

final RowPresenter.ViewHolder

Returns the RowPresenter.ViewHolder from the given RowPresenter ViewHolder.

final boolean

Returns true if the row selection effect is enabled.

final float

Returns the current select level.

final int

Returns the policy of updating row view activated status.

void

Called after a RowPresenter.ViewHolder is created for a Row.

final void
onBindViewHolder(
    @NonNull Presenter.ViewHolder viewHolder,
    @Nullable Object item
)

Binds a View to an item.

final Presenter.ViewHolder

Creates a new View.

void

Invoked when the row view is attached to the window.

void

Invoked when the row view is detached from the window.

void

Called when the row view's expanded state changes.

void

Called when the given row view changes selection state.

void

Callback when the select level changes.

void

Unbinds the given ViewHolder.

final void

Unbinds a View from an item.

final void

Called when a view created by this presenter has been attached to a window.

final void

Called when a view created by this presenter has been detached from its window.

void
setEntranceTransitionState(
    @NonNull RowPresenter.ViewHolder holder,
    boolean afterEntrance
)

Changes the visibility of views.

final void

Sets the Presenter used for rendering the header.

final void
setRowViewExpanded(Presenter.ViewHolder holder, boolean expanded)

Sets the expanded state of a Row view.

final void
setRowViewSelected(Presenter.ViewHolder holder, boolean selected)

Sets the selected state of a Row view.

final void
setSelectEffectEnabled(boolean applyDimOnSelect)

Enables or disables the row selection effect.

final void

Sets the current select level to a value between 0 (unselected) and 1 (selected).

final void
setSyncActivatePolicy(int syncActivatePolicy)

Sets the policy of updating row view activated status.

Constants

PLAY_STATE_INITIAL

Added in 1.1.0
public static final int PLAY_STATE_INITIAL = 0

Indicating that the media item is currently neither playing nor paused.

PLAY_STATE_PAUSED

Added in 1.1.0
public static final int PLAY_STATE_PAUSED = 1

Indicating that the media item is currently paused.

PLAY_STATE_PLAYING

Added in 1.1.0
public static final int PLAY_STATE_PLAYING = 2

Indicating that the media item is currently playing

Public constructors

AbstractMediaItemPresenter

Added in 1.1.0
public AbstractMediaItemPresenter()

Constructor used for creating an abstract media item presenter.

AbstractMediaItemPresenter

Added in 1.1.0
public AbstractMediaItemPresenter(int themeId)

Constructor used for creating an abstract media item presenter.

Parameters
int themeId

The resource id of the theme that defines attributes controlling the appearance of different widgets in a media item row.

Public methods

getActionPresenter

Added in 1.1.0
public Presenter getActionPresenter()

Return the presenter used to render a media item row actions.

Returns
Presenter

the presenter used to render a media item row actions.

getThemeId

Added in 1.1.0
public int getThemeId()

Return The resource id of the theme that defines attributes controlling the appearance of different widgets in a media item row.

Returns
int

The resource id of the theme that defines attributes controlling the appearance of different widgets in a media item row.

hasMediaRowSeparator

Added in 1.1.0
public boolean hasMediaRowSeparator()

isUsingDefaultSelectEffect

public boolean isUsingDefaultSelectEffect()

Returns true if this RowPresenter is using the default dimming effect. A subclass may (most likely) return false and override onSelectLevelChanged.

onBindMediaPlayState

Added in 1.1.0
public void onBindMediaPlayState(AbstractMediaItemPresenter.ViewHolder vh)

Binds the media item number view to the appropriate play state view of the media item. The play state of the media item is extracted by calling getMediaPlayState for the media item embedded within this view. This method triggers updating of the playback state UI if corresponding views are specified for the current playback state. By default, 3 views are provided for each playback state, or these views can be provided by the user.

onUnbindMediaPlayState

Added in 1.1.0
public void onUnbindMediaPlayState(AbstractMediaItemPresenter.ViewHolder vh)

Called when the given ViewHolder wants to unbind the play state view.

Parameters
AbstractMediaItemPresenter.ViewHolder vh

The ViewHolder to unbind from.

setActionPresenter

Added in 1.1.0
public void setActionPresenter(Presenter actionPresenter)

Sets the action presenter rendering each optional custom action within each media item row.

Parameters
Presenter actionPresenter

the presenter to be used for rendering a media item row actions.

setBackgroundColor

Added in 1.1.0
public void setBackgroundColor(int color)

Sets the background color for the row views within the playlist. If this is not set, a default color, defaultBrandColor, from theme is used. This defaultBrandColor defaults to android:attr/colorPrimary on v21, if it's specified.

Parameters
int color

The ARGB color used to set as the media list background color.

setHasMediaRowSeparator

Added in 1.1.0
public void setHasMediaRowSeparator(boolean hasSeparator)

Specifies whether a line separator should be used between media item rows.

Parameters
boolean hasSeparator

true if a separator should be displayed, false otherwise.

setThemeId

Added in 1.1.0
public void setThemeId(int themeId)

Sets the theme used to style a media item row components.

Parameters
int themeId

The resource id of the theme that defines attributes controlling the appearance of different widgets in a media item row.

Protected methods

createRowViewHolder

Added in 1.2.0-alpha04
protected RowPresenter.ViewHolder createRowViewHolder(ViewGroup parent)

Called to create a ViewHolder object for a Row. Subclasses will override this method to return a different concrete ViewHolder object.

Parameters
ViewGroup parent

The parent View for the Row's view holder.

Returns
RowPresenter.ViewHolder

A ViewHolder for the Row's View.

getMediaPlayState

Added in 1.1.0
protected int getMediaPlayState(Object item)

Returns the current play state of the given media item. By default, this method returns PLAY_STATE_INITIAL which causes the media item number getMediaItemNameView to be displayed for different playback states. Users of this class should override this method in order to provide the play state of their custom media item data model.

Parameters
Object item

The media item

Returns
int

The current play state of this media item

isClippingChildren

protected boolean isClippingChildren()

Returns true if the Row view should clip its children. The clipChildren flag is set on view in initializeRowViewHolder. Note that Slide transition or explode transition need turn off clipChildren. Default value is false.

onBindMediaDetails

Added in 1.1.0
protected abstract void onBindMediaDetails(
    AbstractMediaItemPresenter.ViewHolder vh,
    Object item
)

Binds the media item details to their views provided by the AbstractMediaItemPresenter. This method is to be overridden by the users of this presenter. The subclasses of this presenter can access and bind individual views for either of the media item number, name, or duration (depending on whichever views are visible according to the providing theme attributes), by calling getMediaItemNumberView, getMediaItemNameView, and getMediaItemDurationView, on the ViewHolder provided as the argument vh of this presenter.

Parameters
AbstractMediaItemPresenter.ViewHolder vh

The ViewHolder for this AbstractMediaItemPresenter.

Object item

The media item row object being presented.

onBindRowActions

Added in 1.1.0
protected void onBindRowActions(AbstractMediaItemPresenter.ViewHolder vh)

Binds the given media item object action to the given ViewHolder's action views.

Parameters
AbstractMediaItemPresenter.ViewHolder vh

ViewHolder for the media item.

onBindRowViewHolder

protected void onBindRowViewHolder(
    @NonNull RowPresenter.ViewHolder vh,
    @NonNull Object item
)

Binds the given row object to the given ViewHolder. Derived classes of RowPresenter overriding onBindRowViewHolder must call through the super class's implementation of this method.

onUnbindMediaDetails

Added in 1.1.0
protected void onUnbindMediaDetails(AbstractMediaItemPresenter.ViewHolder vh)

Unbinds the media item details from their views provided by the AbstractMediaItemPresenter. This method can be overridden by the subclasses of this presenter if required.

Parameters
AbstractMediaItemPresenter.ViewHolder vh

ViewHolder to unbind from.