Search in sources :

Example 1 with CardPresenter

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

the class ContentSearchFragment method loadRows.

private void loadRows() {
    mListRowAdapter = new ArrayObjectAdapter(new CardPresenter());
    ContentBrowser.getInstance(getActivity()).search(mQuery, (t, done) -> updateResults(t, done));
}
Also used : CardPresenter(com.amazon.android.tv.tenfoot.presenter.CardPresenter) ArrayObjectAdapter(androidx.leanback.widget.ArrayObjectAdapter)

Example 2 with CardPresenter

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

the class ContentSearchFragment method updateResults.

/**
 * This method is the entry point for new content to be added to the view.
 * If there is no more new content coming in the current in flight query the boolean is set to
 * true and we send a new {@link ListRow} to the {@link #mRowsAdapter}
 *
 * @param inputContent the new content to be added
 * @param done         a boolean that tells us that there are no new items coming in the
 *                     current
 *                     in flight query
 */
private void updateResults(Object inputContent, boolean done) {
    // If done then add the content to the mRowsAdapter.
    if (done) {
        mRowsAdapter.clear();
        HeaderItem header = new HeaderItem(getString(R.string.search_results, mQuery));
        int elementsInRow = (int) getResources().getInteger(R.integer.num_of_search_elements_in_row);
        int rows = mListRowAdapter.size() / elementsInRow;
        if (mListRowAdapter.size() % elementsInRow > 0) {
            rows++;
        }
        int index = 0;
        for (int i = 0; i < rows; i++) {
            ArrayObjectAdapter row = new ArrayObjectAdapter(new CardPresenter());
            for (int j = index; j < (index + elementsInRow) && (j < mListRowAdapter.size()); j++) {
                row.add(mListRowAdapter.get(j));
            }
            if (i > 0) {
                mRowsAdapter.add(new ListRow(row));
            } else {
                mRowsAdapter.add(new ListRow(header, row));
            }
            index += elementsInRow;
        }
    } else // Add the found content to the mListRowAdapter
    {
        // Only add the content if the adapter does not already contain it.
        if (mListRowAdapter.indexOf(inputContent) == -1) {
            mListRowAdapter.add(inputContent);
        }
    }
}
Also used : CardPresenter(com.amazon.android.tv.tenfoot.presenter.CardPresenter) HeaderItem(androidx.leanback.widget.HeaderItem) ArrayObjectAdapter(androidx.leanback.widget.ArrayObjectAdapter) ListRow(androidx.leanback.widget.ListRow)

Example 3 with CardPresenter

use of com.amazon.android.tv.tenfoot.presenter.CardPresenter 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 CardPresenter

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

the class PlaybackOverlayFragment method addOtherRows.

private void addOtherRows() {
    ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(new CardPresenter());
    for (Content content : mRelatedContentList) {
        // Do not show the selected content under recommendation list.
        if (!StringManipulation.areStringsEqual(content.getId(), mSelectedContent.getId())) {
            listRowAdapter.add(content);
        }
    }
    HeaderItem header = new HeaderItem(0, getString(R.string.related_contents));
    mRowsAdapter.add(new ListRow(header, listRowAdapter));
}
Also used : Content(com.amazon.android.model.content.Content) CardPresenter(com.amazon.android.tv.tenfoot.presenter.CardPresenter) ArrayObjectAdapter(androidx.leanback.widget.ArrayObjectAdapter) HeaderItem(androidx.leanback.widget.HeaderItem) ListRow(androidx.leanback.widget.ListRow)

Example 5 with CardPresenter

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

the class BrowseHelper method createListRow.

/**
 * Creates a list row of content with the given header string.
 *
 * @param context        The context.
 * @param contents       The contents for the list row.
 * @param headerStringId The string resource id for the row's header.
 * @param maxItems       The maximum number of content to put in the row.
 * @return A list row.
 */
private static ListRow createListRow(Context context, List<Content> contents, int headerStringId, int maxItems) {
    // Only create the row if the content list is not empty.
    if (!contents.isEmpty()) {
        CardPresenter cardPresenter = new CardPresenter();
        HeaderItem header = new HeaderItem(0, context.getResources().getString(headerStringId));
        ArrayObjectAdapter recentRowAdapter = new ArrayObjectAdapter(cardPresenter);
        if (contents.size() == maxItems) {
            recentRowAdapter.addAll(0, contents);
        } else {
            for (int i = 0; i < contents.size() && i < maxItems; i++) {
                recentRowAdapter.add(contents.get(i));
            }
        }
        return new ListRow(header, recentRowAdapter);
    }
    return null;
}
Also used : PosterCardPresenter(com.amazon.android.tv.tenfoot.presenter.PosterCardPresenter) CardPresenter(com.amazon.android.tv.tenfoot.presenter.CardPresenter) SettingsCardPresenter(com.amazon.android.tv.tenfoot.presenter.SettingsCardPresenter) 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