Search in sources :

Example 11 with CardPresenter

use of com.amazon.android.tv.tenfoot.presenter.CardPresenter in project zype-firebuilder by zype.

the class BrowseHelper method loadRootContentContainer.

/**
 * Loads the content from the root content container into the rows adapter.
 *
 * @param activity    The activity.
 * @param rowsAdapter The rows adapter.
 */
public static void loadRootContentContainer(Activity activity, ArrayObjectAdapter rowsAdapter) {
    ContentContainer rootContentContainer = ContentBrowser.getInstance(activity).getRootContentContainer();
    CardPresenter cardPresenter = new CardPresenter();
    /* Zype, Evgeny Cherkasov */
    PosterCardPresenter posterCardPresenter = new PosterCardPresenter();
    for (ContentContainer contentContainer : rootContentContainer.getContentContainers()) {
        // Don't show 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) || contentContainer.getExtraStringValue(Recipe.KEY_DATA_TYPE_TAG).equals(ZypeSettings.ROOT_SLIDERS_PLAYLIST_ID)) {
            continue;
        }
        HeaderItem header = new HeaderItem(0, contentContainer.getName());
        ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(cardPresenter);
        /* Zype, Evgeny Cherkasov */
        if (contentContainer.getExtraStringValue(ContentContainer.EXTRA_THUMBNAIL_LAYOUT).equals("poster")) {
            listRowAdapter = new ArrayObjectAdapter(posterCardPresenter);
        }
        for (ContentContainer innerContentContainer : contentContainer.getContentContainers()) {
            listRowAdapter.add(innerContentContainer);
        }
        // TODO: Probably it would better to move updating NextPage to the getContentsObservable()
        if (contentContainer.getExtraValueAsInt(ExtraKeys.NEXT_PAGE) == 1) {
            if (contentContainer.getExtraValueAsInt(ContentContainer.EXTRA_PLAYLIST_ITEM_COUNT) > ZypeApi.PER_PAGE_DEFAULT) {
                contentContainer.setExtraValue(ExtraKeys.NEXT_PAGE, 2);
            } else {
                contentContainer.setExtraValue(ExtraKeys.NEXT_PAGE, -1);
            }
        }
        for (Content content : contentContainer.getContents()) {
            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);
        }
        /* 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("activity.getString(R.string.action_load_more)");
                action.setExtraValue(PlaylistAction.EXTRA_PLAYLIST_ID, contentContainer.getExtraStringValue(Recipe.KEY_DATA_TYPE_TAG));
                listRowAdapter.add(action);
            }*/
        rowsAdapter.add(new ListRow(header, listRowAdapter));
    }
}
Also used : Content(com.amazon.android.model.content.Content) PosterCardPresenter(com.amazon.android.tv.tenfoot.presenter.PosterCardPresenter) PosterCardPresenter(com.amazon.android.tv.tenfoot.presenter.PosterCardPresenter) CardPresenter(com.amazon.android.tv.tenfoot.presenter.CardPresenter) SettingsCardPresenter(com.amazon.android.tv.tenfoot.presenter.SettingsCardPresenter) ContentContainer(com.amazon.android.model.content.ContentContainer) HeaderItem(androidx.leanback.widget.HeaderItem) ArrayObjectAdapter(androidx.leanback.widget.ArrayObjectAdapter) ListRow(androidx.leanback.widget.ListRow)

Aggregations

ArrayObjectAdapter (androidx.leanback.widget.ArrayObjectAdapter)11 CardPresenter (com.amazon.android.tv.tenfoot.presenter.CardPresenter)11 HeaderItem (androidx.leanback.widget.HeaderItem)9 ListRow (androidx.leanback.widget.ListRow)9 Content (com.amazon.android.model.content.Content)7 ContentContainer (com.amazon.android.model.content.ContentContainer)7 PosterCardPresenter (com.amazon.android.tv.tenfoot.presenter.PosterCardPresenter)5 SettingsCardPresenter (com.amazon.android.tv.tenfoot.presenter.SettingsCardPresenter)4 PlaylistAction (com.amazon.android.model.PlaylistAction)3 Intent (android.content.Intent)1 Handler (android.os.Handler)1 SparseArrayObjectAdapter (androidx.leanback.widget.SparseArrayObjectAdapter)1 VerticalGridPresenter (androidx.leanback.widget.VerticalGridPresenter)1