Search in sources :

Example 6 with ArrayObjectAdapter

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

the class SortedBrowserFragment method updateList.

@Override
public void updateList() {
    Activity activity = getActivity();
    if (activity == null)
        return;
    mAdapter = new ArrayObjectAdapter(new ListRowPresenter());
    setAdapter(mAdapter);
    ArrayObjectAdapter adapter;
    HeaderItem header;
    synchronized (mMediaItemMap) {
        if (mTempMap != null)
            mMediaItemMap = mTempMap;
    }
    for (ListItem item : mMediaItemMap.values()) {
        adapter = new ArrayObjectAdapter(new CardPresenter(activity));
        header = new HeaderItem(0, item.Letter);
        adapter.addAll(0, item.mediaList);
        mAdapter.add(new ListRow(header, adapter));
    }
    mHandler.sendEmptyMessageDelayed(HIDE_LOADING, 3000);
}
Also used : ListRowPresenter(android.support.v17.leanback.widget.ListRowPresenter) CardPresenter(org.videolan.vlc.gui.tv.CardPresenter) MainTvActivity(org.videolan.vlc.gui.tv.MainTvActivity) DetailsActivity(org.videolan.vlc.gui.tv.DetailsActivity) Activity(android.app.Activity) ArrayObjectAdapter(android.support.v17.leanback.widget.ArrayObjectAdapter) HeaderItem(android.support.v17.leanback.widget.HeaderItem) ListRow(android.support.v17.leanback.widget.ListRow)

Example 7 with ArrayObjectAdapter

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

the class MainTvActivity method updateHistory.

@MainThread
private synchronized void updateHistory(MediaWrapper[] history) {
    if (history == null || mRowsAdapter == null)
        return;
    final boolean createAdapter = mHistoryAdapter == null;
    if (createAdapter)
        mHistoryAdapter = new ArrayObjectAdapter(new CardPresenter(mContext));
    else
        mHistoryAdapter.clear();
    if (!mSettings.getBoolean(PreferencesFragment.PLAYBACK_HISTORY, true))
        return;
    for (int i = 0; i < history.length; ++i) {
        final MediaWrapper item = history[i];
        mHistoryAdapter.add(item);
        mHistoryIndex.put(item.getLocation(), i);
    }
    if (createAdapter) {
        final HeaderItem historyHeader = new HeaderItem(HEADER_HISTORY, getString(R.string.history));
        mRowsAdapter.add(Math.min(2, mRowsAdapter.size()), new ListRow(historyHeader, mHistoryAdapter));
    }
}
Also used : MediaWrapper(org.videolan.medialibrary.media.MediaWrapper) ArrayObjectAdapter(android.support.v17.leanback.widget.ArrayObjectAdapter) HeaderItem(android.support.v17.leanback.widget.HeaderItem) ListRow(android.support.v17.leanback.widget.ListRow) MainThread(android.support.annotation.MainThread)

Example 8 with ArrayObjectAdapter

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

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

the class GridFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mContext = getActivity();
    VerticalGridPresenter gridPresenter = new VerticalGridPresenter();
    gridPresenter.setNumberOfColumns(NUM_COLUMNS);
    setGridPresenter(gridPresenter);
    mAdapter = new ArrayObjectAdapter(new CardPresenter(mContext));
    mAdapter.clear();
    setAdapter(mAdapter);
}
Also used : VerticalGridPresenter(android.support.v17.leanback.widget.VerticalGridPresenter) CardPresenter(org.videolan.vlc.gui.tv.CardPresenter) ArrayObjectAdapter(android.support.v17.leanback.widget.ArrayObjectAdapter)

Example 10 with ArrayObjectAdapter

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

the class TVSearchFragment method createLoadingRow.

private ListRow createLoadingRow() {
    final HeaderItem loadingHeader = new HeaderItem(getString(R.string.search_results));
    ClassPresenterSelector presenterSelector = new ClassPresenterSelector();
    presenterSelector.addClassPresenter(MediaCardItem.class, new MediaCardPresenter(getActivity(), picasso));
    presenterSelector.addClassPresenter(LoadingCardItem.class, new LoadingCardPresenter(getActivity()));
    ArrayObjectAdapter loadingRowAdapter = new ArrayObjectAdapter(presenterSelector);
    loadingRowAdapter.add(new LoadingCardItem());
    return new ListRow(loadingHeader, loadingRowAdapter);
}
Also used : LoadingCardPresenter(butter.droid.tv.presenters.LoadingCardPresenter) HeaderItem(android.support.v17.leanback.widget.HeaderItem) ArrayObjectAdapter(android.support.v17.leanback.widget.ArrayObjectAdapter) LoadingCardItem(butter.droid.tv.presenters.LoadingCardPresenter.LoadingCardItem) ClassPresenterSelector(android.support.v17.leanback.widget.ClassPresenterSelector) MediaCardPresenter(butter.droid.tv.presenters.MediaCardPresenter) 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