public abstract class AbstractMediaItemPresenter extends RowPresenter
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(android.support.v17.leanback.widget.AbstractMediaItemPresenter.ViewHolder, java.lang.Object)
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.
Modifier and Type | Class and Description |
---|---|
static class |
AbstractMediaItemPresenter.ViewHolder
The ViewHolder for the
AbstractMediaItemPresenter . |
Presenter.ViewHolderTask
Modifier and Type | Field and Description |
---|---|
static int |
PLAY_STATE_INITIAL
Indicating that the media item is currently neither playing nor paused.
|
static int |
PLAY_STATE_PAUSED
Indicating that the media item is currently paused.
|
static int |
PLAY_STATE_PLAYING
Indicating that the media item is currently playing
|
SYNC_ACTIVATED_CUSTOM, SYNC_ACTIVATED_TO_EXPANDED, SYNC_ACTIVATED_TO_EXPANDED_AND_SELECTED, SYNC_ACTIVATED_TO_SELECTED
Constructor and Description |
---|
AbstractMediaItemPresenter()
Constructor used for creating an abstract media item presenter.
|
AbstractMediaItemPresenter(int themeId)
Constructor used for creating an abstract media item presenter.
|
Modifier and Type | Method and Description |
---|---|
protected RowPresenter.ViewHolder |
createRowViewHolder(ViewGroup parent)
Called to create a ViewHolder object for a Row.
|
Presenter |
getActionPresenter()
Return the presenter used to render a media item row actions.
|
protected int |
getMediaPlayState(Object item)
Returns the current play state of the given media item.
|
int |
getThemeId()
Return The resource id of the theme that defines attributes controlling the appearance of
different widgets in a media item row.
|
boolean |
hasMediaRowSeparator() |
protected boolean |
isClippingChildren()
Returns true if the Row view should clip it's children.
|
boolean |
isUsingDefaultSelectEffect()
Returns true if this RowPresenter is using the default dimming effect.
|
protected abstract void |
onBindMediaDetails(AbstractMediaItemPresenter.ViewHolder vh,
Object item)
Binds the media item details to their views provided by the
AbstractMediaItemPresenter . |
void |
onBindMediaPlayState(AbstractMediaItemPresenter.ViewHolder vh)
Binds the media item number view to the appropriate play state view of the media item.
|
protected void |
onBindRowActions(AbstractMediaItemPresenter.ViewHolder vh)
Binds the given media item object action to the given ViewHolder's action views.
|
protected void |
onBindRowViewHolder(RowPresenter.ViewHolder vh,
Object item)
Binds the given row object to the given ViewHolder.
|
protected void |
onUnbindMediaDetails(AbstractMediaItemPresenter.ViewHolder vh)
Unbinds the media item details from their views provided by the
AbstractMediaItemPresenter . |
void |
onUnbindMediaPlayState(AbstractMediaItemPresenter.ViewHolder vh)
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.
|
dispatchItemSelectedListener, freeze, getHeaderPresenter, getRowViewHolder, getSelectEffectEnabled, getSelectLevel, getSyncActivatePolicy, initializeRowViewHolder, onBindViewHolder, onCreateViewHolder, onRowViewAttachedToWindow, onRowViewDetachedFromWindow, onRowViewExpanded, onRowViewSelected, onSelectLevelChanged, onUnbindRowViewHolder, onUnbindViewHolder, onViewAttachedToWindow, onViewDetachedFromWindow, setEntranceTransitionState, setHeaderPresenter, setRowViewExpanded, setRowViewSelected, setSelectEffectEnabled, setSelectLevel, setSyncActivatePolicy
cancelAnimationsRecursive, getFacet, setFacet, setOnClickListener
public static final int PLAY_STATE_INITIAL
public static final int PLAY_STATE_PAUSED
public static final int PLAY_STATE_PLAYING
public AbstractMediaItemPresenter()
public AbstractMediaItemPresenter(int themeId)
themeId
- The resource id of the theme that defines attributes controlling the
appearance of different widgets in a media item row.public void setThemeId(int themeId)
themeId
- The resource id of the theme that defines attributes controlling the
appearance of different widgets in a media item row.public int getThemeId()
public void setActionPresenter(Presenter actionPresenter)
actionPresenter
- the presenter to be used for rendering a media item row actions.public Presenter getActionPresenter()
protected RowPresenter.ViewHolder createRowViewHolder(ViewGroup parent)
RowPresenter
createRowViewHolder
in class RowPresenter
parent
- The parent View for the Row's view holder.public boolean isUsingDefaultSelectEffect()
RowPresenter
RowPresenter.onSelectLevelChanged(ViewHolder)
.isUsingDefaultSelectEffect
in class RowPresenter
protected boolean isClippingChildren()
RowPresenter
RowPresenter.initializeRowViewHolder(ViewHolder)
. Note that
Slide transition or explode transition need turn off clipChildren.
Default value is false.isClippingChildren
in class RowPresenter
protected void onBindRowViewHolder(RowPresenter.ViewHolder vh, Object item)
RowPresenter
RowPresenter
overriding
RowPresenter.onBindRowViewHolder(ViewHolder, Object)
must call through the super class's
implementation of this method.onBindRowViewHolder
in class RowPresenter
protected void onBindRowActions(AbstractMediaItemPresenter.ViewHolder vh)
vh
- ViewHolder for the media item.public void setBackgroundColor(int color)
color
- The ARGB color used to set as the media list background color.public void setHasMediaRowSeparator(boolean hasSeparator)
hasSeparator
- true if a separator should be displayed, false otherwise.public boolean hasMediaRowSeparator()
protected abstract void onBindMediaDetails(AbstractMediaItemPresenter.ViewHolder vh, Object item)
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 AbstractMediaItemPresenter.ViewHolder.getMediaItemNumberView()
,
AbstractMediaItemPresenter.ViewHolder.getMediaItemNameView()
, and AbstractMediaItemPresenter.ViewHolder.getMediaItemDurationView()
,
on the AbstractMediaItemPresenter.ViewHolder
provided as the argument vh
of this presenter.vh
- The ViewHolder for this AbstractMediaItemPresenter
.item
- The media item row object being presented.protected void onUnbindMediaDetails(AbstractMediaItemPresenter.ViewHolder vh)
AbstractMediaItemPresenter
.
This method can be overridden by the subclasses of this presenter if required.vh
- ViewHolder to unbind from.public void onBindMediaPlayState(AbstractMediaItemPresenter.ViewHolder vh)
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.public void onUnbindMediaPlayState(AbstractMediaItemPresenter.ViewHolder vh)
vh
- The ViewHolder to unbind from.protected int getMediaPlayState(Object item)
AbstractMediaItemPresenter.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.item
- The media item