Search in sources :

Example 1 with PlaylistAction

use of com.amazon.android.model.PlaylistAction in project zype-firebuilder by zype.

the class ContentDetailsFragment method updateRelatedContentRow.

/* Zype, Evgeny Cherkasov */
private void updateRelatedContentRow() {
    ContentContainer recommended = ContentBrowser.getInstance(getActivity()).getRecommendedListOfAContentAsAContainer(mSelectedContent);
    // Find a row for related content
    ListRow row = null;
    for (int i = 0; i < mAdapter.size(); i++) {
        Object item = mAdapter.get(i);
        if (item instanceof ListRow) {
            row = (ListRow) item;
            break;
        }
    }
    if (row == null) {
        return;
    }
    ArrayObjectAdapter listRowAdapter = (ArrayObjectAdapter) row.getAdapter();
    // Remove 'Load more' action button
    if (listRowAdapter.size() > 0 && listRowAdapter.get(listRowAdapter.size() - 1) instanceof PlaylistAction) {
        listRowAdapter.remove(listRowAdapter.get(listRowAdapter.size() - 1));
    }
    // Add new contents
    for (int i = listRowAdapter.size(); i < recommended.getContentCount(); i++) {
        listRowAdapter.add(recommended.getContents().get(i));
    }
    // Add a button for loading next page of playlist videos
    ContentContainer contentContainer = ContentBrowser.getInstance(getActivity()).getRootContentContainer().findContentContainerById(mSelectedContent.getExtraValueAsString(Content.EXTRA_PLAYLIST_ID));
    if (contentContainer.getExtraValueAsInt(ExtraKeys.NEXT_PAGE) > 0) {
        PlaylistAction action = new PlaylistAction();
        action.setAction(ContentBrowser.NEXT_PAGE).setIconResourceId(com.amazon.android.contentbrowser.R.drawable.ic_add_white_48dp).setLabel1(getString(R.string.action_load_more));
        action.setExtraValue(PlaylistAction.EXTRA_PLAYLIST_ID, contentContainer.getExtraStringValue(Recipe.KEY_DATA_TYPE_TAG));
        listRowAdapter.add(action);
    }
}
Also used : PlaylistAction(com.amazon.android.model.PlaylistAction) ContentContainer(com.amazon.android.model.content.ContentContainer) ArrayObjectAdapter(androidx.leanback.widget.ArrayObjectAdapter) SparseArrayObjectAdapter(androidx.leanback.widget.SparseArrayObjectAdapter) ListRow(androidx.leanback.widget.ListRow)

Example 2 with PlaylistAction

use of com.amazon.android.model.PlaylistAction in project zype-firebuilder by zype.

the class ZypeContentDetailsPlaylistFragment method updateContents.

public void updateContents() {
    Log.d(TAG, "updateContents()");
    ArrayObjectAdapter rowsAdapter = mRowsAdapter;
    Content video = ContentBrowser.getInstance(getActivity()).getLastSelectedContent();
    String playlistId = video.getExtraValueAsString(Content.EXTRA_PLAYLIST_ID);
    ContentContainer playlist = ContentBrowser.getInstance(getActivity()).getPlayList(playlistId);
    if (playlist == null) {
        return;
    }
    int index = 0;
    ListRow row = (ListRow) rowsAdapter.get(index);
    ArrayObjectAdapter listRowAdapter = (ArrayObjectAdapter) row.getAdapter();
    // Remove 'Load more' action button
    if (listRowAdapter.size() > 0 && listRowAdapter.get(listRowAdapter.size() - 1) instanceof PlaylistAction) {
        listRowAdapter.remove(listRowAdapter.get(listRowAdapter.size() - 1));
    }
    if (listRowAdapter.size() > 0 && listRowAdapter.get(listRowAdapter.size() - 1) instanceof Content) {
        Content content = (Content) listRowAdapter.get(listRowAdapter.size() - 1);
        content.setExtraValue(ContentBrowser.NEXT_PAGE, false);
    }
    // Add new contents
    if (playlist.getContentCount() > listRowAdapter.size()) {
        for (int i = listRowAdapter.size(); i < playlist.getContentCount(); i++) {
            Content content = playlist.getContents().get(i);
            if (playlist.getExtraValueAsInt(ExtraKeys.NEXT_PAGE) > 0 && playlist.getContents().indexOf(content) == playlist.getContentCount() - 1) {
                content.setExtraValue(ContentBrowser.NEXT_PAGE, true);
                content.setExtraValue(Content.EXTRA_PLAYLIST_ID, playlist.getExtraStringValue(Recipe.KEY_DATA_TYPE_TAG));
            }
            listRowAdapter.add(content);
        }
    }
}
Also used : PlaylistAction(com.amazon.android.model.PlaylistAction) Content(com.amazon.android.model.content.Content) ContentContainer(com.amazon.android.model.content.ContentContainer) ArrayObjectAdapter(androidx.leanback.widget.ArrayObjectAdapter) ListRow(androidx.leanback.widget.ListRow)

Example 3 with PlaylistAction

use of com.amazon.android.model.PlaylistAction in project zype-firebuilder by zype.

the class ZypePlaylistContentBrowseFragment method updateContents.

/* Zype, Evgeny Cherkasov */
public void updateContents() {
    Log.d(TAG, "updateContents()");
    ArrayObjectAdapter rowsAdapter = mRowsAdapter;
    ContentContainer rootContentContainer = ContentBrowser.getInstance(getActivity()).getLastSelectedContentContainer();
    boolean isMyLibrary = rootContentContainer.getExtraStringValue(Recipe.KEY_DATA_TYPE_TAG).equals(ZypeSettings.ROOT_MY_LIBRARY_PLAYLIST_ID);
    boolean isFavorites = rootContentContainer.getExtraStringValue(Recipe.KEY_DATA_TYPE_TAG).equals(ZypeSettings.ROOT_FAVORITES_PLAYLIST_ID);
    CardPresenter cardPresenter = new CardPresenter();
    PosterCardPresenter posterCardPresenter = new PosterCardPresenter();
    int index = 0;
    for (ContentContainer contentContainer : rootContentContainer.getContentContainers()) {
        // Skip 'My Library' and 'Favorites' content container
        if (contentContainer.getExtraStringValue(Recipe.KEY_DATA_TYPE_TAG).equals(ZypeSettings.ROOT_MY_LIBRARY_PLAYLIST_ID) || contentContainer.getExtraStringValue(Recipe.KEY_DATA_TYPE_TAG).equals(ZypeSettings.ROOT_FAVORITES_PLAYLIST_ID)) {
            continue;
        }
        if (index >= rowsAdapter.size()) {
            HeaderItem header = new HeaderItem(0, contentContainer.getName());
            ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(cardPresenter);
            if (contentContainer.getExtraStringValue(ContentContainer.EXTRA_THUMBNAIL_LAYOUT).equals("poster")) {
                listRowAdapter = new ArrayObjectAdapter(posterCardPresenter);
            }
            rowsAdapter.add(new ListRow(header, listRowAdapter));
        }
        ListRow row = (ListRow) rowsAdapter.get(index);
        ArrayObjectAdapter listRowAdapter = (ArrayObjectAdapter) row.getAdapter();
        // Remove 'Load more' action button
        if (listRowAdapter.size() > 0 && listRowAdapter.get(listRowAdapter.size() - 1) instanceof PlaylistAction) {
            listRowAdapter.remove(listRowAdapter.get(listRowAdapter.size() - 1));
        }
        // Add new contents
        for (int i = listRowAdapter.size() - contentContainer.getContentContainerCount(); i < contentContainer.getContentCount(); i++) {
            listRowAdapter.add(contentContainer.getContents().get(i));
        }
        // Add a button for loading next page of playlist videos
        if (isMyLibrary) {
            if (rootContentContainer.getExtraValueAsInt(ExtraKeys.NEXT_PAGE) > 0) {
                PlaylistAction action = new PlaylistAction();
                action.setAction(ContentBrowser.NEXT_PAGE).setIconResourceId(com.amazon.android.contentbrowser.R.drawable.ic_add_white_48dp).setLabel1(getString(R.string.action_load_more));
                listRowAdapter.add(action);
            }
        } else if (isFavorites) {
        } else {
            if (contentContainer.getExtraValueAsInt(ExtraKeys.NEXT_PAGE) > 0) {
                PlaylistAction action = new PlaylistAction();
                action.setAction(ContentBrowser.NEXT_PAGE).setIconResourceId(com.amazon.android.contentbrowser.R.drawable.ic_add_white_48dp).setLabel1(getString(R.string.action_load_more));
                action.setExtraValue(PlaylistAction.EXTRA_PLAYLIST_ID, contentContainer.getExtraStringValue(Recipe.KEY_DATA_TYPE_TAG));
                listRowAdapter.add(action);
            }
        }
        // Display message if the Favorites list is empty
        if (isFavorites && contentContainer.getContents().isEmpty() && ContentBrowser.getInstance(getActivity()).isFavoritesLoaded()) {
            showEmptyFavorites();
        }
        index++;
    }
}
Also used : PlaylistAction(com.amazon.android.model.PlaylistAction) PosterCardPresenter(com.amazon.android.tv.tenfoot.presenter.PosterCardPresenter) CardPresenter(com.amazon.android.tv.tenfoot.presenter.CardPresenter) SettingsCardPresenter(com.amazon.android.tv.tenfoot.presenter.SettingsCardPresenter) PosterCardPresenter(com.amazon.android.tv.tenfoot.presenter.PosterCardPresenter) ContentContainer(com.amazon.android.model.content.ContentContainer) ArrayObjectAdapter(androidx.leanback.widget.ArrayObjectAdapter) HeaderItem(androidx.leanback.widget.HeaderItem) ListRow(androidx.leanback.widget.ListRow)

Example 4 with PlaylistAction

use of com.amazon.android.model.PlaylistAction in project zype-firebuilder by zype.

the class ContentBrowseFragment method updateContents.

/* Zype, Evgeny Cherkasov */
private void updateContents(ArrayObjectAdapter rowsAdapter) {
    ContentContainer rootContentContainer = ContentBrowser.getInstance(getActivity()).getRootContentContainer();
    int index = 0;
    for (ContentContainer contentContainer : rootContentContainer.getContentContainers()) {
        // Skip 'My Library' and 'Favorites' content containers
        if (contentContainer.getExtraStringValue(Recipe.KEY_DATA_TYPE_TAG).equals(ZypeSettings.ROOT_MY_LIBRARY_PLAYLIST_ID) || contentContainer.getExtraStringValue(Recipe.KEY_DATA_TYPE_TAG).equals(ZypeSettings.ROOT_FAVORITES_PLAYLIST_ID)) {
            continue;
        }
        ListRow row = (ListRow) rowsAdapter.get(index);
        ArrayObjectAdapter listRowAdapter = (ArrayObjectAdapter) row.getAdapter();
        // Remove 'Load more' action button    (No need now)
        if (listRowAdapter.size() > 0 && listRowAdapter.get(listRowAdapter.size() - 1) instanceof PlaylistAction) {
            listRowAdapter.remove(listRowAdapter.get(listRowAdapter.size() - 1));
        }
        if (listRowAdapter.size() > 0 && listRowAdapter.get(listRowAdapter.size() - 1) instanceof Content && listRowAdapter.size() < contentContainer.getContentCount()) {
            Content content = (Content) listRowAdapter.get(listRowAdapter.size() - 1);
            content.setExtraValue(ContentBrowser.NEXT_PAGE, false);
        }
        // Add new contents
        for (int i = listRowAdapter.size() - contentContainer.getContentContainerCount(); i < contentContainer.getContentCount(); i++) {
            Content content = contentContainer.getContents().get(i);
            if (contentContainer.getExtraValueAsInt(ExtraKeys.NEXT_PAGE) > 0 && contentContainer.getContents().indexOf(content) == contentContainer.getContentCount() - 1) {
                content.setExtraValue(ContentBrowser.NEXT_PAGE, true);
                content.setExtraValue(Content.EXTRA_PLAYLIST_ID, contentContainer.getExtraStringValue(Recipe.KEY_DATA_TYPE_TAG));
            }
            listRowAdapter.add(content);
        }
        index++;
    }
}
Also used : PlaylistAction(com.amazon.android.model.PlaylistAction) Content(com.amazon.android.model.content.Content) ContentContainer(com.amazon.android.model.content.ContentContainer) ArrayObjectAdapter(androidx.leanback.widget.ArrayObjectAdapter) ListRow(androidx.leanback.widget.ListRow)

Example 5 with PlaylistAction

use of com.amazon.android.model.PlaylistAction in project zype-firebuilder by zype.

the class ContentDetailsFragment method setupRelatedContentRow.

/**
 * Builds the related content row. Uses contents from the selected content's category.
 */
private void setupRelatedContentRow() {
    ContentContainer recommended = ContentBrowser.getInstance(getActivity()).getRecommendedListOfAContentAsAContainer(mSelectedContent);
    ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(new CardPresenter());
    for (Content c : recommended) {
        listRowAdapter.add(c);
    }
    /* Zype, Evgeny Cherkasov */
    String playlistId = mSelectedContent.getExtraValueAsString(Content.EXTRA_PLAYLIST_ID);
    // Update header for Favorites
    if (!TextUtils.isEmpty(playlistId) && playlistId.equals(ZypeSettings.FAVORITES_PLAYLIST_ID)) {
        recommended.setName(getString(R.string.content_details_recommended_header_favorites));
    }
    // Add a button for loading next page of playlist videos
    ContentContainer contentContainer = ContentBrowser.getInstance(getActivity()).getRootContentContainer().findContentContainerById(playlistId);
    if (contentContainer != null) {
        if (contentContainer.getExtraValueAsInt(ExtraKeys.NEXT_PAGE) > 0) {
            PlaylistAction action = new PlaylistAction();
            action.setAction(ContentBrowser.NEXT_PAGE).setIconResourceId(com.amazon.android.contentbrowser.R.drawable.ic_add_white_48dp).setLabel1(getString(R.string.action_load_more));
            action.setExtraValue(PlaylistAction.EXTRA_PLAYLIST_ID, contentContainer.getExtraStringValue(Recipe.KEY_DATA_TYPE_TAG));
            listRowAdapter.add(action);
        }
    }
    // Only add the header and row for recommendations if there are any recommended content.
    if (listRowAdapter.size() > 0) {
        HeaderItem header = new HeaderItem(0, recommended.getName());
        mAdapter.add(new ListRow(header, listRowAdapter));
    }
}
Also used : PlaylistAction(com.amazon.android.model.PlaylistAction) Content(com.amazon.android.model.content.Content) CardPresenter(com.amazon.android.tv.tenfoot.presenter.CardPresenter) ContentContainer(com.amazon.android.model.content.ContentContainer) ArrayObjectAdapter(androidx.leanback.widget.ArrayObjectAdapter) SparseArrayObjectAdapter(androidx.leanback.widget.SparseArrayObjectAdapter) HeaderItem(androidx.leanback.widget.HeaderItem) ListRow(androidx.leanback.widget.ListRow)

Aggregations

ArrayObjectAdapter (androidx.leanback.widget.ArrayObjectAdapter)6 ListRow (androidx.leanback.widget.ListRow)6 PlaylistAction (com.amazon.android.model.PlaylistAction)6 ContentContainer (com.amazon.android.model.content.ContentContainer)6 Content (com.amazon.android.model.content.Content)4 HeaderItem (androidx.leanback.widget.HeaderItem)3 CardPresenter (com.amazon.android.tv.tenfoot.presenter.CardPresenter)3 SparseArrayObjectAdapter (androidx.leanback.widget.SparseArrayObjectAdapter)2 PosterCardPresenter (com.amazon.android.tv.tenfoot.presenter.PosterCardPresenter)2 SettingsCardPresenter (com.amazon.android.tv.tenfoot.presenter.SettingsCardPresenter)2