Search in sources :

Example 31 with ArrayObjectAdapter

use of android.support.v17.leanback.widget.ArrayObjectAdapter 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)

Example 32 with ArrayObjectAdapter

use of android.support.v17.leanback.widget.ArrayObjectAdapter in project vlc-android by GeoffreyMetais.

the class SearchFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mRowsAdapter = new ArrayObjectAdapter(new ListRowPresenter());
    setSearchResultProvider(this);
    setOnItemViewClickedListener(getDefaultItemClickedListener());
    mDelayedLoad = new SearchRunnable();
    mActivity = getActivity();
    final Intent recognitionIntent = getRecognizerIntent();
    if (Util.isCallable(recognitionIntent)) {
        final SpeechRecognitionCallback speechRecognitionCallback = new SpeechRecognitionCallback() {

            @Override
            public void recognizeSpeech() {
                startActivityForResult(recognitionIntent, REQUEST_SPEECH);
            }
        };
        setSpeechRecognitionCallback(speechRecognitionCallback);
    }
    final Intent intent = mActivity.getIntent();
    if (Intent.ACTION_SEARCH.equals(intent.getAction()) || "com.google.android.gms.actions.SEARCH_ACTION".equals(intent.getAction()))
        onQueryTextSubmit(intent.getStringExtra(SearchManager.QUERY));
}
Also used : ListRowPresenter(android.support.v17.leanback.widget.ListRowPresenter) Intent(android.content.Intent) ArrayObjectAdapter(android.support.v17.leanback.widget.ArrayObjectAdapter) SpeechRecognitionCallback(android.support.v17.leanback.widget.SpeechRecognitionCallback)

Example 33 with ArrayObjectAdapter

use of android.support.v17.leanback.widget.ArrayObjectAdapter in project vlc-android by GeoffreyMetais.

the class SearchFragment method loadRows.

private void loadRows(String query) {
    final SearchAggregate searchAggregate = VLCApplication.getMLInstance().search(query);
    CardPresenter cp = new CardPresenter(mActivity);
    final ArrayObjectAdapter videoAdapter = new ArrayObjectAdapter(cp);
    videoAdapter.addAll(0, Arrays.asList(searchAggregate.getMediaSearchAggregate().getOthers()));
    final ArrayObjectAdapter episodesAdapter = new ArrayObjectAdapter(cp);
    episodesAdapter.addAll(0, Arrays.asList(searchAggregate.getMediaSearchAggregate().getEpisodes()));
    final ArrayObjectAdapter moviesAdapter = new ArrayObjectAdapter(cp);
    moviesAdapter.addAll(0, Arrays.asList(searchAggregate.getMediaSearchAggregate().getMovies()));
    final ArrayObjectAdapter songsAdapter = new ArrayObjectAdapter(cp);
    songsAdapter.addAll(0, Arrays.asList(searchAggregate.getMediaSearchAggregate().getTracks()));
    final ArrayObjectAdapter artistsAdapter = new ArrayObjectAdapter(cp);
    artistsAdapter.addAll(0, Arrays.asList(searchAggregate.getArtists()));
    final ArrayObjectAdapter albumsAdapter = new ArrayObjectAdapter(cp);
    albumsAdapter.addAll(0, Arrays.asList(searchAggregate.getAlbums()));
    final ArrayObjectAdapter genresAdapter = new ArrayObjectAdapter(cp);
    genresAdapter.addAll(0, Arrays.asList(searchAggregate.getGenres()));
    mHandler.post(new Runnable() {

        @Override
        public void run() {
            if (videoAdapter.size() > 0)
                mRowsAdapter.add(new ListRow(new HeaderItem(0, getResources().getString(R.string.videos)), videoAdapter));
            if (episodesAdapter.size() > 0)
                mRowsAdapter.add(new ListRow(new HeaderItem(0, getResources().getString(R.string.episodes)), episodesAdapter));
            if (moviesAdapter.size() > 0)
                mRowsAdapter.add(new ListRow(new HeaderItem(0, getResources().getString(R.string.movies)), moviesAdapter));
            if (songsAdapter.size() > 0)
                mRowsAdapter.add(new ListRow(new HeaderItem(0, getResources().getString(R.string.songs)), songsAdapter));
            if (artistsAdapter.size() > 0)
                mRowsAdapter.add(new ListRow(new HeaderItem(0, getResources().getString(R.string.artists)), artistsAdapter));
            if (albumsAdapter.size() > 0)
                mRowsAdapter.add(new ListRow(new HeaderItem(0, getResources().getString(R.string.albums)), albumsAdapter));
            if (genresAdapter.size() > 0)
                mRowsAdapter.add(new ListRow(new HeaderItem(0, getResources().getString(R.string.genres)), genresAdapter));
        }
    });
}
Also used : SearchAggregate(org.videolan.medialibrary.media.SearchAggregate) ArrayObjectAdapter(android.support.v17.leanback.widget.ArrayObjectAdapter) HeaderItem(android.support.v17.leanback.widget.HeaderItem) ListRow(android.support.v17.leanback.widget.ListRow)

Aggregations

ArrayObjectAdapter (android.support.v17.leanback.widget.ArrayObjectAdapter)33 HeaderItem (android.support.v17.leanback.widget.HeaderItem)16 ListRow (android.support.v17.leanback.widget.ListRow)13 ListRowPresenter (android.support.v17.leanback.widget.ListRowPresenter)13 ClassPresenterSelector (android.support.v17.leanback.widget.ClassPresenterSelector)8 Intent (android.content.Intent)5 DetailsOverviewRow (android.support.v17.leanback.widget.DetailsOverviewRow)4 FullWidthDetailsOverviewRowPresenter (android.support.v17.leanback.widget.FullWidthDetailsOverviewRowPresenter)4 Card (cx.ring.tv.cards.Card)4 CardPresenterSelector (cx.ring.tv.cards.CardPresenterSelector)4 ContactCard (cx.ring.tv.cards.contacts.ContactCard)4 IconCard (cx.ring.tv.cards.iconcards.IconCard)4 Activity (android.app.Activity)3 Bundle (android.os.Bundle)3 OnItemViewClickedListener (android.support.v17.leanback.widget.OnItemViewClickedListener)3 VerticalGridPresenter (android.support.v17.leanback.widget.VerticalGridPresenter)3 MediaCardPresenter (butter.droid.tv.presenters.MediaCardPresenter)3 CardListRow (cx.ring.tv.cards.CardListRow)3 CardRow (cx.ring.tv.cards.CardRow)3 ContactRequestCard (cx.ring.tv.cards.contactrequests.ContactRequestCard)3