The Android Developer Challenge is back! Submit your idea before December 2.

AbstractMediaItemPresenter

abstract class AbstractMediaItemPresenter : RowPresenter
kotlin.Any
   ↳ androidx.leanback.widget.Presenter
   ↳ androidx.leanback.widget.RowPresenter
   ↳ androidx.leanback.widget.AbstractMediaItemPresenter

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(Object) 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(boolean) 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 classes

open

The ViewHolder for the AbstractMediaItemPresenter.

Constants

static Int

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

static Int

Indicating that the media item is currently paused.

static Int

Indicating that the media item is currently playing

Inherited constants

Public constructors

Constructor used for creating an abstract media item presenter.

<init>(themeId: Int)

Constructor used for creating an abstract media item presenter.

Public methods

open Presenter!

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

open Int

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

open Boolean

open Boolean

open Unit

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

open Unit

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

open Unit
setActionPresenter(actionPresenter: Presenter!)

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

open Unit

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

open Unit

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

open Unit
setThemeId(themeId: Int)

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

Protected methods

open RowPresenter.ViewHolder!

open Int

Returns the current play state of the given media item.

open Boolean

abstract Unit

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

open Unit

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

open Unit

open Unit

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

Inherited functions

Constants

PLAY_STATE_INITIAL

static val PLAY_STATE_INITIAL: Int

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

Value: 0

PLAY_STATE_PAUSED

static val PLAY_STATE_PAUSED: Int

Indicating that the media item is currently paused.

Value: 1

PLAY_STATE_PLAYING

static val PLAY_STATE_PLAYING: Int

Indicating that the media item is currently playing

Value: 2

Public constructors

<init>

AbstractMediaItemPresenter()

Constructor used for creating an abstract media item presenter.

<init>

AbstractMediaItemPresenter(themeId: Int)

Constructor used for creating an abstract media item presenter.

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

Public methods

getActionPresenter

open fun getActionPresenter(): Presenter!

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

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

getThemeId

open fun getThemeId(): Int

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

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

hasMediaRowSeparator

open fun hasMediaRowSeparator(): Boolean

isUsingDefaultSelectEffect

open fun isUsingDefaultSelectEffect(): Boolean

onBindMediaPlayState

open fun onBindMediaPlayState(vh: AbstractMediaItemPresenter.ViewHolder!): Unit

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(Object) 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

open fun onUnbindMediaPlayState(vh: AbstractMediaItemPresenter.ViewHolder!): Unit

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

Parameters
vh AbstractMediaItemPresenter.ViewHolder!: The ViewHolder to unbind from.

setActionPresenter

open fun setActionPresenter(actionPresenter: Presenter!): Unit

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

Parameters
actionPresenter Presenter!: the presenter to be used for rendering a media item row actions.

setBackgroundColor

open fun setBackgroundColor(color: Int): Unit

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
color Int: The ARGB color used to set as the media list background color.

setHasMediaRowSeparator

open fun setHasMediaRowSeparator(hasSeparator: Boolean): Unit

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

Parameters
hasSeparator Boolean: true if a separator should be displayed, false otherwise.

setThemeId

open fun setThemeId(themeId: Int): Unit

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

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

Protected methods

createRowViewHolder

protected open fun createRowViewHolder(parent: ViewGroup!): RowPresenter.ViewHolder!

getMediaPlayState

protected open fun getMediaPlayState(item: Any!): Int

Returns the current play state of the given media item. By default, this method returns PLAY_STATE_INITIAL which causes the media item number ViewHolder#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
item Any!: The media item
Return
Int: The current play state of this media item

isClippingChildren

protected open fun isClippingChildren(): Boolean

onBindMediaDetails

protected abstract fun onBindMediaDetails(vh: AbstractMediaItemPresenter.ViewHolder!, item: Any!): Unit

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 ViewHolder#getMediaItemNumberView(), ViewHolder#getMediaItemNameView(), and ViewHolder#getMediaItemDurationView(), on the ViewHolder provided as the argument vh of this presenter.

Parameters
vh AbstractMediaItemPresenter.ViewHolder!: The ViewHolder for this AbstractMediaItemPresenter.
item AbstractMediaItemPresenter.ViewHolder!: The media item row object being presented.

onBindRowActions

protected open fun onBindRowActions(vh: AbstractMediaItemPresenter.ViewHolder!): Unit

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

Parameters
vh AbstractMediaItemPresenter.ViewHolder!: ViewHolder for the media item.

onBindRowViewHolder

protected open fun onBindRowViewHolder(vh: RowPresenter.ViewHolder!, item: Any!): Unit

onUnbindMediaDetails

protected open fun onUnbindMediaDetails(vh: AbstractMediaItemPresenter.ViewHolder!): Unit

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
vh AbstractMediaItemPresenter.ViewHolder!: ViewHolder to unbind from.