-
-
Notifications
You must be signed in to change notification settings - Fork 252
2. ToroPlayer, ToroAdapter, ToroAdapter.ViewHolder, ToroLayoutManager
Combination of basic Media playback methods (play/pause, ...) (see BaseMediaPlayer) and a few more methods comes from Toro's requirement (wantsToPlay, ...) and Playback event callbacks. Toro and its internal APIs will take care of the Playback events.
Client is expected to implement ToroPlayer to the ViewHolder, as follow:
public class MyPlayerViewHolder extends RecyclerView.ViewHolder implements ToroPlayer {
public MyPlayerViewHolder(View itemView) {
super(itemView);
}
// many methods need to be implemented ..
}
Default RecyclerView's Adapter and ViewHolder don't require some useful callback, and User tends to ignore them in most cases. ToroAdapter use them to make the bridge between the Adapter and the ViewHolder (for example: Adapter#onViewAttachedToWindow(ViewHolder)
, Adapter#onViewDetachedFromWindow(ViewHolder)
...).
It is not required to implement them in client, but it is highly recommended to use them. It helps carefully control the behaviour of the ViewHolder. In extensions, I have the "PlayerViewHelper" which requires ToroAdapter and its ViewHolder.
A simple usage can be seen from the following files:
- ExoVideoViewHolder.java: based ViewHolder for ExpPlayer 2 extension.
- Basic1VideoViewHolder.java: very basic ViewHolder that extends the base class above.
In Toro v1, only LinearLayoutManager, GridLayoutManager or StaggeredGridLayoutManager is supported. This limits the creativity. So I put an abstract layer on other cases by providing the interface ToroLayoutManager
. Toro just wants to know the first position and the last position of the Playable Views, therefore there is no need to limit the LayoutManager. User wants to use custom LayoutManager just need to implement the interface, provide sufficient information... See Advance1LayoutManager.java to see how I use the CarouselLayoutManager
with Toro.
Note: current implementation still assume that the ViewHolder appears in the Linear Order. A better mechanism is under investigation.