use of android.support.v17.leanback.widget.RowPresenter in project vlc-android by videolan.
the class MediaItemDetailsFragment method buildDetails.
private void buildDetails() {
Bundle extras = getActivity().getIntent().getExtras();
mMedia = extras.getParcelable("item");
boolean hasMedia = extras.containsKey("media");
ClassPresenterSelector selector = new ClassPresenterSelector();
final MediaWrapper media = hasMedia ? (MediaWrapper) extras.getParcelable("media") : new MediaWrapper(AndroidUtil.LocationToUri(mMedia.getLocation()));
if (!hasMedia) {
media.setDisplayTitle(mMedia.getTitle());
}
mMediaWrapper = media;
setTitle(media.getTitle());
final List<MediaWrapper> mediaList = (List<MediaWrapper>) VLCApplication.getData(SortedBrowserFragment.CURRENT_BROWSER_LIST);
// Attach your media item details presenter to the row presenter:
FullWidthDetailsOverviewRowPresenter rowPresenter = new FullWidthDetailsOverviewRowPresenter(new DetailsDescriptionPresenter());
final Activity activity = getActivity();
final DetailsOverviewRow detailsOverview = new DetailsOverviewRow(mMedia);
final Action actionAdd = new Action(ID_FAVORITE_ADD, getString(R.string.favorites_add));
final Action actionDelete = new Action(ID_FAVORITE_DELETE, getString(R.string.favorites_remove));
rowPresenter.setBackgroundColor(ContextCompat.getColor(activity, R.color.orange500));
rowPresenter.setOnActionClickedListener(new OnActionClickedListener() {
@Override
public void onActionClicked(Action action) {
switch((int) action.getId()) {
case ID_LISTEN:
PlaybackServiceFragment.registerPlaybackService(MediaItemDetailsFragment.this, MediaItemDetailsFragment.this);
break;
case ID_PLAY:
TvUtil.playMedia(getActivity(), media);
getActivity().finish();
break;
case ID_FAVORITE_ADD:
mDb.addNetworkFavItem(Uri.parse(mMedia.getLocation()), mMedia.getTitle(), mMedia.getArtworkUrl());
detailsOverview.removeAction(actionAdd);
detailsOverview.addAction(actionDelete);
mRowsAdapter.notifyArrayItemRangeChanged(0, mRowsAdapter.size());
Toast.makeText(VLCApplication.getAppContext(), R.string.favorite_added, Toast.LENGTH_SHORT).show();
break;
case ID_FAVORITE_DELETE:
mDb.deleteNetworkFav(Uri.parse(mMedia.getLocation()));
detailsOverview.removeAction(actionDelete);
detailsOverview.addAction(actionAdd);
mRowsAdapter.notifyArrayItemRangeChanged(0, mRowsAdapter.size());
Toast.makeText(VLCApplication.getAppContext(), R.string.favorite_removed, Toast.LENGTH_SHORT).show();
break;
case ID_BROWSE:
TvUtil.openMedia(getActivity(), media, null);
break;
case ID_DL_SUBS:
MediaUtils.getSubs(getActivity(), media);
break;
case ID_PLAY_ALL:
if (mediaList != null) {
int position = -1;
for (int i = 0; i < mediaList.size(); ++i) if (media.equals(mediaList.get(i)))
position = i;
Activity activity = getActivity();
MediaUtils.openList(activity, mediaList, position);
if (media.getType() == MediaWrapper.TYPE_AUDIO)
getActivity().startActivity(new Intent(activity, AudioPlayerActivity.class));
getActivity().finish();
}
break;
case ID_PLAY_FROM_START:
VideoPlayerActivity.start(getActivity(), media.getUri(), true);
getActivity().finish();
break;
}
}
});
selector.addClassPresenter(DetailsOverviewRow.class, rowPresenter);
selector.addClassPresenter(ListRow.class, new ListRowPresenter());
mRowsAdapter = new ArrayObjectAdapter(selector);
VLCApplication.runBackground(new Runnable() {
@Override
public void run() {
final Bitmap cover = media.getType() == MediaWrapper.TYPE_AUDIO || media.getType() == MediaWrapper.TYPE_VIDEO ? AudioUtil.readCoverBitmap(mMedia.getArtworkUrl(), 512) : null;
VLCApplication.runOnMainThread(new Runnable() {
@Override
public void run() {
if (isDetached())
return;
if (media.getType() == MediaWrapper.TYPE_DIR && FileUtils.canSave(media)) {
mDb = MediaDatabase.getInstance();
detailsOverview.setImageDrawable(ContextCompat.getDrawable(activity, TextUtils.equals(media.getUri().getScheme(), "file") ? R.drawable.ic_menu_folder_big : R.drawable.ic_menu_network_big));
detailsOverview.setImageScaleUpAllowed(true);
detailsOverview.addAction(new Action(ID_BROWSE, getString(R.string.browse_folder)));
if (mDb.networkFavExists(Uri.parse(mMedia.getLocation())))
detailsOverview.addAction(actionDelete);
else
detailsOverview.addAction(actionAdd);
} else if (media.getType() == MediaWrapper.TYPE_AUDIO) {
// Add images and action buttons to the details view
if (cover == null)
detailsOverview.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.ic_default_cone));
else
detailsOverview.setImageBitmap(getActivity(), cover);
detailsOverview.addAction(new Action(ID_PLAY, getString(R.string.play)));
detailsOverview.addAction(new Action(ID_LISTEN, getString(R.string.listen)));
if (mediaList != null && mediaList.contains(media))
detailsOverview.addAction(new Action(ID_PLAY_ALL, getString(R.string.play_all)));
} else if (media.getType() == MediaWrapper.TYPE_VIDEO) {
// Add images and action buttons to the details view
if (cover == null)
detailsOverview.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.ic_default_cone));
else
detailsOverview.setImageBitmap(getActivity(), cover);
detailsOverview.addAction(new Action(ID_PLAY, getString(R.string.play)));
detailsOverview.addAction(new Action(ID_PLAY_FROM_START, getString(R.string.play_from_start)));
if (FileUtils.canWrite(media.getUri()))
detailsOverview.addAction(new Action(ID_DL_SUBS, getString(R.string.download_subtitles)));
if (mediaList != null && mediaList.contains(media))
detailsOverview.addAction(new Action(ID_PLAY_ALL, getString(R.string.play_all)));
}
mRowsAdapter.add(detailsOverview);
setAdapter(mRowsAdapter);
if (cover != null)
mBackgroundManager.setBitmap(cover);
}
});
}
});
}
use of android.support.v17.leanback.widget.RowPresenter in project ring-client-android by savoirfairelinux.
the class AboutDetailsFragment method setupUi.
private void setupUi() {
Bundle extras = getActivity().getIntent().getExtras();
Card.Type cardType = Card.Type.DEFAULT;
if (extras != null && extras.containsKey("abouttype")) {
int ordinal = extras.getInt("abouttype", 0);
cardType = Card.Type.values()[ordinal];
}
IconCard card = IconCardHelper.getAboutCardByType(getActivity(), cardType);
ClassPresenterSelector selector = new ClassPresenterSelector();
FullWidthDetailsOverviewRowPresenter rowPresenter = new FullWidthDetailsOverviewRowPresenter(new AboutDetailsPresenter(getActivity())) {
@Override
protected RowPresenter.ViewHolder createRowViewHolder(ViewGroup parent) {
// Customize Actionbar and Content by using custom colors.
RowPresenter.ViewHolder viewHolder = super.createRowViewHolder(parent);
View actionsView = viewHolder.view.findViewById(R.id.details_overview_actions_background);
actionsView.setBackgroundColor(getActivity().getResources().getColor(R.color.color_primary_dark));
View detailsView = viewHolder.view.findViewById(R.id.details_frame);
detailsView.setBackgroundColor(getResources().getColor(R.color.color_primary_dark));
return viewHolder;
}
};
selector.addClassPresenter(DetailsOverviewRow.class, rowPresenter);
selector.addClassPresenter(ListRow.class, new ListRowPresenter());
ArrayObjectAdapter mRowsAdapter = new ArrayObjectAdapter(selector);
Resources res = getActivity().getResources();
DetailsOverviewRow detailsOverview = new DetailsOverviewRow(card);
// Add images and action buttons to the details view
detailsOverview.setImageDrawable(res.getDrawable(R.drawable.ic_logo_ring_white));
mRowsAdapter.add(detailsOverview);
setAdapter(mRowsAdapter);
initializeBackground();
}
use of android.support.v17.leanback.widget.RowPresenter in project vlc-android by GeoffreyMetais.
the class MediaItemDetailsFragment method buildDetails.
private void buildDetails() {
Bundle extras = getActivity().getIntent().getExtras();
mMedia = extras.getParcelable("item");
boolean hasMedia = extras.containsKey("media");
ClassPresenterSelector selector = new ClassPresenterSelector();
final MediaWrapper media = hasMedia ? (MediaWrapper) extras.getParcelable("media") : new MediaWrapper(AndroidUtil.LocationToUri(mMedia.getLocation()));
if (!hasMedia) {
media.setDisplayTitle(mMedia.getTitle());
}
mMediaWrapper = media;
setTitle(media.getTitle());
final List<MediaWrapper> mediaList = null;
// Attach your media item details presenter to the row presenter:
FullWidthDetailsOverviewRowPresenter rowPresenter = new FullWidthDetailsOverviewRowPresenter(new DetailsDescriptionPresenter());
final Activity activity = getActivity();
final DetailsOverviewRow detailsOverview = new DetailsOverviewRow(mMedia);
final Action actionAdd = new Action(ID_FAVORITE_ADD, getString(R.string.favorites_add));
final Action actionDelete = new Action(ID_FAVORITE_DELETE, getString(R.string.favorites_remove));
rowPresenter.setBackgroundColor(ContextCompat.getColor(activity, R.color.orange500));
rowPresenter.setOnActionClickedListener(new OnActionClickedListener() {
@Override
public void onActionClicked(Action action) {
switch((int) action.getId()) {
case ID_LISTEN:
PlaybackServiceFragment.registerPlaybackService(MediaItemDetailsFragment.this, MediaItemDetailsFragment.this);
break;
case ID_PLAY:
TvUtil.INSTANCE.playMedia(getActivity(), media);
getActivity().finish();
break;
case ID_FAVORITE_ADD:
mDb.addNetworkFavItem(Uri.parse(mMedia.getLocation()), mMedia.getTitle(), mMedia.getArtworkUrl());
detailsOverview.removeAction(actionAdd);
detailsOverview.addAction(actionDelete);
mRowsAdapter.notifyArrayItemRangeChanged(0, mRowsAdapter.size());
Toast.makeText(VLCApplication.getAppContext(), R.string.favorite_added, Toast.LENGTH_SHORT).show();
break;
case ID_FAVORITE_DELETE:
mDb.deleteNetworkFav(Uri.parse(mMedia.getLocation()));
detailsOverview.removeAction(actionDelete);
detailsOverview.addAction(actionAdd);
mRowsAdapter.notifyArrayItemRangeChanged(0, mRowsAdapter.size());
Toast.makeText(VLCApplication.getAppContext(), R.string.favorite_removed, Toast.LENGTH_SHORT).show();
break;
case ID_BROWSE:
TvUtil.INSTANCE.openMedia(getActivity(), media, null);
break;
case ID_DL_SUBS:
MediaUtils.getSubs(getActivity(), media);
break;
case ID_PLAY_ALL:
if (mediaList != null) {
int position = -1;
for (int i = 0; i < mediaList.size(); ++i) if (media.equals(mediaList.get(i)))
position = i;
Activity activity = getActivity();
MediaUtils.openList(activity, mediaList, position);
if (media.getType() == MediaWrapper.TYPE_AUDIO)
getActivity().startActivity(new Intent(activity, AudioPlayerActivity.class));
getActivity().finish();
}
break;
case ID_PLAY_FROM_START:
VideoPlayerActivity.start(getActivity(), media.getUri(), true);
getActivity().finish();
break;
}
}
});
selector.addClassPresenter(DetailsOverviewRow.class, rowPresenter);
selector.addClassPresenter(ListRow.class, new ListRowPresenter());
mRowsAdapter = new ArrayObjectAdapter(selector);
WorkersKt.runBackground(new Runnable() {
@Override
public void run() {
final Bitmap cover = media.getType() == MediaWrapper.TYPE_AUDIO || media.getType() == MediaWrapper.TYPE_VIDEO ? AudioUtil.readCoverBitmap(mMedia.getArtworkUrl(), 512) : null;
WorkersKt.runOnMainThread(new Runnable() {
@Override
public void run() {
if (isDetached())
return;
if (media.getType() == MediaWrapper.TYPE_DIR && FileUtils.canSave(media)) {
mDb = MediaDatabase.getInstance();
detailsOverview.setImageDrawable(ContextCompat.getDrawable(activity, TextUtils.equals(media.getUri().getScheme(), "file") ? R.drawable.ic_menu_folder_big : R.drawable.ic_menu_network_big));
detailsOverview.setImageScaleUpAllowed(true);
detailsOverview.addAction(new Action(ID_BROWSE, getString(R.string.browse_folder)));
if (mDb.networkFavExists(Uri.parse(mMedia.getLocation())))
detailsOverview.addAction(actionDelete);
else
detailsOverview.addAction(actionAdd);
} else if (media.getType() == MediaWrapper.TYPE_AUDIO) {
// Add images and action buttons to the details view
if (cover == null)
detailsOverview.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.ic_default_cone));
else
detailsOverview.setImageBitmap(getActivity(), cover);
detailsOverview.addAction(new Action(ID_PLAY, getString(R.string.play)));
detailsOverview.addAction(new Action(ID_LISTEN, getString(R.string.listen)));
if (mediaList != null && mediaList.contains(media))
detailsOverview.addAction(new Action(ID_PLAY_ALL, getString(R.string.play_all)));
} else if (media.getType() == MediaWrapper.TYPE_VIDEO) {
// Add images and action buttons to the details view
if (cover == null)
detailsOverview.setImageDrawable(ContextCompat.getDrawable(activity, R.drawable.ic_default_cone));
else
detailsOverview.setImageBitmap(getActivity(), cover);
detailsOverview.addAction(new Action(ID_PLAY, getString(R.string.play)));
detailsOverview.addAction(new Action(ID_PLAY_FROM_START, getString(R.string.play_from_start)));
if (FileUtils.canWrite(media.getUri()))
detailsOverview.addAction(new Action(ID_DL_SUBS, getString(R.string.download_subtitles)));
if (mediaList != null && mediaList.contains(media))
detailsOverview.addAction(new Action(ID_PLAY_ALL, getString(R.string.play_all)));
}
mRowsAdapter.add(detailsOverview);
setAdapter(mRowsAdapter);
if (cover != null)
mBackgroundManager.setBitmap(cover);
}
});
}
});
}
Aggregations