Search in sources :

Example 1 with Presenter

use of android.support.v17.leanback.widget.Presenter 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);
                }
            });
        }
    });
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) FullWidthDetailsOverviewRowPresenter(android.support.v17.leanback.widget.FullWidthDetailsOverviewRowPresenter) Action(android.support.v17.leanback.widget.Action) Bundle(android.os.Bundle) OnActionClickedListener(android.support.v17.leanback.widget.OnActionClickedListener) VideoPlayerActivity(org.videolan.vlc.gui.video.VideoPlayerActivity) AudioPlayerActivity(org.videolan.vlc.gui.tv.audioplayer.AudioPlayerActivity) Activity(android.app.Activity) Intent(android.content.Intent) ArrayObjectAdapter(android.support.v17.leanback.widget.ArrayObjectAdapter) ClassPresenterSelector(android.support.v17.leanback.widget.ClassPresenterSelector) DetailsOverviewRow(android.support.v17.leanback.widget.DetailsOverviewRow) Bitmap(android.graphics.Bitmap) ListRowPresenter(android.support.v17.leanback.widget.ListRowPresenter) List(java.util.List) AudioPlayerActivity(org.videolan.vlc.gui.tv.audioplayer.AudioPlayerActivity)

Example 2 with Presenter

use of android.support.v17.leanback.widget.Presenter in project ring-client-android by savoirfairelinux.

the class CardPresenterSelector method getPresenter.

@Override
public Presenter getPresenter(Object item) {
    if (!(item instanceof Card))
        throw new RuntimeException(String.format("The PresenterSelector only supports data items of type '%s'", Card.class.getName()));
    Card card = (Card) item;
    Presenter presenter = presenters.get(card.getType());
    if (presenter == null) {
        switch(card.getType()) {
            case ABOUT_VERSION:
            case ABOUT_CONTRIBUTOR:
            case ABOUT_LICENCES:
            case ACCOUNT_ADD_DEVICE:
            case ACCOUNT_EDIT_PROFILE:
            case ACCOUNT_SETTINGS:
                presenter = new IconCardPresenter(mContext);
                break;
            case SEARCH_RESULT:
                presenter = new ContactCardPresenter(mContext, R.style.SearchCardTheme);
                break;
            case CONTACT:
                presenter = new ContactCardPresenter(mContext, R.style.ContactCardTheme);
                break;
            case CONTACT_ONLINE:
                presenter = new ContactCardPresenter(mContext, R.style.ContactCardOnlineTheme);
                break;
            case CONTACT_WITH_USERNAME:
                presenter = new ContactCardPresenter(mContext, R.style.ContactCompleteCardTheme);
                break;
            case CONTACT_WITH_USERNAME_ONLINE:
                presenter = new ContactCardPresenter(mContext, R.style.ContactCompleteCardOnlineTheme);
                break;
            case CONTACT_REQUEST:
                presenter = new ContactRequestCardPresenter(mContext, R.style.ContactCardTheme);
                break;
            case CONTACT_REQUEST_WITH_USERNAME:
                presenter = new ContactRequestCardPresenter(mContext, R.style.ContactCompleteCardTheme);
                break;
            default:
                throw new InvalidParameterException("Uncatched card type");
        }
    }
    presenters.put(card.getType(), presenter);
    return presenter;
}
Also used : InvalidParameterException(java.security.InvalidParameterException) ContactRequestCardPresenter(cx.ring.tv.cards.contactrequests.ContactRequestCardPresenter) ContactCardPresenter(cx.ring.tv.cards.contacts.ContactCardPresenter) IconCardPresenter(cx.ring.tv.cards.iconcards.IconCardPresenter) Presenter(android.support.v17.leanback.widget.Presenter) ContactRequestCardPresenter(cx.ring.tv.cards.contactrequests.ContactRequestCardPresenter) IconCardPresenter(cx.ring.tv.cards.iconcards.IconCardPresenter) ContactCardPresenter(cx.ring.tv.cards.contacts.ContactCardPresenter)

Example 3 with Presenter

use of android.support.v17.leanback.widget.Presenter in project ring-client-android by savoirfairelinux.

the class MainFragment method setupUIElements.

private void setupUIElements() {
    mBackgroundManager = BackgroundManager.getInstance(getActivity());
    mBackgroundManager.attach(getActivity().getWindow());
    mMetrics = new DisplayMetrics();
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(mMetrics);
    // over title
    setHeadersState(HEADERS_ENABLED);
    setHeadersTransitionOnBackEnabled(true);
    // set fastLane (or headers) background color
    setBrandColor(getResources().getColor(R.color.color_primary_dark));
    // set search icon color
    setSearchAffordanceColor(getResources().getColor(R.color.color_primary_light));
    mRowsAdapter = new ArrayObjectAdapter(new ShadowRowPresenterSelector());
    /* Contact Presenter */
    List<Card> cards = new ArrayList<>();
    CardRow contactRow = new CardRow(CardRow.TYPE_DEFAULT, true, getString(R.string.tv_contact_row_header), cards);
    HeaderItem cardPresenterHeader = new HeaderItem(HEADER_CONTACTS, getString(R.string.tv_contact_row_header));
    cardRowAdapter = new ArrayObjectAdapter(new CardPresenterSelector(getActivity()));
    CardListRow contactListRow = new CardListRow(cardPresenterHeader, cardRowAdapter, contactRow);
    /* CardPresenter */
    mRowsAdapter.add(contactListRow);
    mRowsAdapter.add(createMyAccountRow());
    mRowsAdapter.add(createAboutCardRow());
    setAdapter(mRowsAdapter);
    // listeners
    setOnSearchClickedListener(view -> {
        Intent intent = new Intent(getActivity(), SearchActivity.class);
        startActivity(intent);
    });
    setOnItemViewClickedListener(new ItemViewClickedListener());
}
Also used : CardListRow(cx.ring.tv.cards.CardListRow) CardRow(cx.ring.tv.cards.CardRow) OnItemViewClickedListener(android.support.v17.leanback.widget.OnItemViewClickedListener) ArrayList(java.util.ArrayList) CardPresenterSelector(cx.ring.tv.cards.CardPresenterSelector) Intent(android.content.Intent) ArrayObjectAdapter(android.support.v17.leanback.widget.ArrayObjectAdapter) HeaderItem(android.support.v17.leanback.widget.HeaderItem) ShadowRowPresenterSelector(cx.ring.tv.cards.ShadowRowPresenterSelector) DisplayMetrics(android.util.DisplayMetrics) VCard(ezvcard.VCard) IconCard(cx.ring.tv.cards.iconcards.IconCard) ContactRequestCard(cx.ring.tv.cards.contactrequests.ContactRequestCard) ContactCard(cx.ring.tv.cards.contacts.ContactCard) Card(cx.ring.tv.cards.Card)

Example 4 with Presenter

use of android.support.v17.leanback.widget.Presenter in project butter-android by butterproject.

the class TVShowDetailsFragment method showSeasons.

@Override
public void showSeasons(final Season[] seasons) {
    ArrayObjectAdapter objectAdapter = getObjectArrayAdapter();
    for (int i = 0; i < seasons.length; i++) {
        Season season = seasons[i];
        HeaderItem header = new HeaderItem(i, season.getTitle());
        EpisodeCardPresenter presenter = new EpisodeCardPresenter(getActivity());
        presenter.setOnClickListener(this);
        ArrayObjectAdapter episodes = new ArrayObjectAdapter(presenter);
        for (final Episode episode : season.getEpisodes()) {
            episodes.add(episode);
        }
        objectAdapter.add(new ListRow(header, episodes));
    }
    objectAdapter.notifyArrayItemRangeChanged(1, objectAdapter.size());
}
Also used : Episode(butter.droid.provider.base.model.Episode) ArrayObjectAdapter(android.support.v17.leanback.widget.ArrayObjectAdapter) HeaderItem(android.support.v17.leanback.widget.HeaderItem) Season(butter.droid.provider.base.model.Season) ListRow(android.support.v17.leanback.widget.ListRow) EpisodeCardPresenter(butter.droid.tv.ui.detail.show.presenter.EpisodeCardPresenter)

Example 5 with Presenter

use of android.support.v17.leanback.widget.Presenter 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);
                }
            });
        }
    });
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) FullWidthDetailsOverviewRowPresenter(android.support.v17.leanback.widget.FullWidthDetailsOverviewRowPresenter) Action(android.support.v17.leanback.widget.Action) Bundle(android.os.Bundle) OnActionClickedListener(android.support.v17.leanback.widget.OnActionClickedListener) VideoPlayerActivity(org.videolan.vlc.gui.video.VideoPlayerActivity) AudioPlayerActivity(org.videolan.vlc.gui.tv.audioplayer.AudioPlayerActivity) Activity(android.app.Activity) Intent(android.content.Intent) ArrayObjectAdapter(android.support.v17.leanback.widget.ArrayObjectAdapter) ClassPresenterSelector(android.support.v17.leanback.widget.ClassPresenterSelector) DetailsOverviewRow(android.support.v17.leanback.widget.DetailsOverviewRow) Bitmap(android.graphics.Bitmap) ListRowPresenter(android.support.v17.leanback.widget.ListRowPresenter) AudioPlayerActivity(org.videolan.vlc.gui.tv.audioplayer.AudioPlayerActivity)

Aggregations

ArrayObjectAdapter (android.support.v17.leanback.widget.ArrayObjectAdapter)4 Intent (android.content.Intent)3 Activity (android.app.Activity)2 Bitmap (android.graphics.Bitmap)2 Bundle (android.os.Bundle)2 Action (android.support.v17.leanback.widget.Action)2 ClassPresenterSelector (android.support.v17.leanback.widget.ClassPresenterSelector)2 DetailsOverviewRow (android.support.v17.leanback.widget.DetailsOverviewRow)2 FullWidthDetailsOverviewRowPresenter (android.support.v17.leanback.widget.FullWidthDetailsOverviewRowPresenter)2 HeaderItem (android.support.v17.leanback.widget.HeaderItem)2 ListRowPresenter (android.support.v17.leanback.widget.ListRowPresenter)2 OnActionClickedListener (android.support.v17.leanback.widget.OnActionClickedListener)2 MediaWrapper (org.videolan.medialibrary.media.MediaWrapper)2 AudioPlayerActivity (org.videolan.vlc.gui.tv.audioplayer.AudioPlayerActivity)2 VideoPlayerActivity (org.videolan.vlc.gui.video.VideoPlayerActivity)2 ListRow (android.support.v17.leanback.widget.ListRow)1 OnItemViewClickedListener (android.support.v17.leanback.widget.OnItemViewClickedListener)1 Presenter (android.support.v17.leanback.widget.Presenter)1 DisplayMetrics (android.util.DisplayMetrics)1 Episode (butter.droid.provider.base.model.Episode)1