Search in sources :

Example 66 with Content

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

the class HeroSliderFragment method processContentContainer.

private void processContentContainer(ContentContainer contentContainer, Slider slider) {
    ContentBrowser contentBrowser = ContentBrowser.getInstance(getActivity());
    if (contentContainer != null) {
        if (contentContainer.getContents().size() > 0) {
            Content content = contentContainer.getContents().get(0);
            openVideo(content, slider);
        } else {
            if (Integer.valueOf(contentContainer.getExtraStringValue(ContentContainer.EXTRA_PLAYLIST_ITEM_COUNT)) > 0) {
                // Playlist has  videos, but they is not loaded yet.
                // Load videos and then open video detail screen of the first video in the playlist
                ContentLoader.ILoadContentForContentContainer listener = () -> {
                    Content content = contentContainer.getContents().get(0);
                    openVideo(content, slider);
                };
                ContentLoader.getInstance(getActivity()).loadContentForContentContainer(contentContainer, getActivity(), listener);
            } else {
                contentBrowser.setLastSelectedContentContainer(contentContainer);
                contentBrowser.switchToScreen(ContentBrowser.CONTENT_SUBMENU_SCREEN);
            }
        }
    }
}
Also used : Content(com.amazon.android.model.content.Content) ContentLoader(com.amazon.android.contentbrowser.ContentLoader) ContentBrowser(com.amazon.android.contentbrowser.ContentBrowser)

Example 67 with Content

use of com.amazon.android.model.content.Content 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)

Example 68 with Content

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

the class RecommendationSenderTest method createNewContent.

/**
 * Helper method to create a new test content.
 *
 * @param id The content id. Numeric only: 1, 2, 3, ...
 * @return The test content.
 */
private Content createNewContent(String id) {
    Content content = new Content(id);
    content.setId(id);
    // Need to set a real image url. Using one from our GitHub :)
    content.setCardImageUrl("https://raw.githubusercontent.com/amzn/fire-app-builder/master/" + "TVUIComponent/lib/src/main/res/drawable/movie.png");
    // Add the next content as a recommendation (based on int ids)
    int rec = Integer.valueOf(id) + 1;
    content.setExtraValue(Content.RECOMMENDATIONS_FIELD_NAME, "[" + rec + "]");
    return content;
}
Also used : Content(com.amazon.android.model.content.Content)

Example 69 with Content

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

the class RecommendationSenderTest method testBuildRelatedRecommendations.

/**
 * Test sending related recommendations.
 */
@Test
public void testBuildRelatedRecommendations() throws Exception {
    ContentContainer root = new ContentContainer("root");
    Content c1 = createNewContent("1");
    Content c2 = createNewContent("2");
    Content c3 = createNewContent("3");
    Content c4 = createNewContent("4");
    root.addContent(c1).addContent(c2).addContent(c3);
    mSender.setRootContentContainer(root);
    RecommendationDatabaseHelper databaseHelper = RecommendationDatabaseHelper.getInstance();
    Context context = InstrumentationRegistry.getContext();
    String type = RecommendationRecord.RELATED;
    assertNotNull(databaseHelper);
    databaseHelper.clearDatabase(context);
    // Send recommendations for content 1 --> Should recommend content 2.
    List<String> ids = c1.getExtraStringValueAsList(Content.RECOMMENDATIONS_FIELD_NAME);
    assertTrue("Recommendations should build with no problems", mSender.sendRecommendationsForType(type, ids, 3));
    assertTrue("Recommendation for content 2 should exist", databaseHelper.recordExists(context, "2"));
    // Send related recommendations for content 1, 2, 3 --> Should recommend content 2, 3, 4
    ids.addAll(c2.getExtraStringValueAsList(Content.RECOMMENDATIONS_FIELD_NAME));
    ids.addAll(c3.getExtraStringValueAsList(Content.RECOMMENDATIONS_FIELD_NAME));
    assertTrue("Recommendations should build with no problems", mSender.sendRecommendationsForType(type, ids, 3));
    assertTrue("Recommendation for content 3 should exist", databaseHelper.recordExists(context, "3"));
    assertTrue("Recommendation for content 4 should exist", databaseHelper.recordExists(context, "4"));
    // Send related recommendations for content 1, 2, 3, 4 --> Should recommend content 2, 3, 4,
    // since max is only 3.
    ids.addAll(c1.getExtraStringValueAsList(Content.RECOMMENDATIONS_FIELD_NAME));
    ids.addAll(c4.getExtraStringValueAsList(Content.RECOMMENDATIONS_FIELD_NAME));
    assertTrue("Recommendations should build with no problems", mSender.sendRecommendationsForType(type, ids, 3));
    assertTrue("Recommendation for content 2 should exist", databaseHelper.recordExists(context, "2"));
    assertTrue("Recommendation for content 3 should exist", databaseHelper.recordExists(context, "3"));
    assertTrue("Recommendation for content 4 should exist", databaseHelper.recordExists(context, "4"));
    assertFalse("Recommendation for content 5 should not exist", databaseHelper.recordExists(context, "5"));
}
Also used : Context(android.content.Context) RecommendationDatabaseHelper(com.amazon.android.contentbrowser.database.helpers.RecommendationDatabaseHelper) Content(com.amazon.android.model.content.Content) ContentContainer(com.amazon.android.model.content.ContentContainer) Test(org.junit.Test)

Example 70 with Content

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

the class ContentBrowser method switchToRendererScreen.

/**
 * Switch to renderer screen.
 *
 * @param content  Content.
 * @param actionId Action id.
 */
public void switchToRendererScreen(Content content, int actionId) {
    switchToScreen(ContentBrowser.CONTENT_RENDERER_SCREEN, content, intent -> {
        intent.putExtra(Content.class.getSimpleName(), content);
        // Reset saved seek position if watching content from beginning.
        if (actionId == CONTENT_ACTION_WATCH_FROM_BEGINNING) {
            RecentDatabaseHelper databaseHelper = RecentDatabaseHelper.getInstance();
            if (databaseHelper == null) {
                Log.e(TAG, "Error retrieving database. Recent not saved.");
                return;
            }
            databaseHelper.addRecord(mAppContext, content.getId(), 0, false, DateAndTimeHelper.getCurrentDate().getTime(), content.getDuration());
        }
    });
}
Also used : RecentDatabaseHelper(com.amazon.android.contentbrowser.database.helpers.RecentDatabaseHelper) Content(com.amazon.android.model.content.Content)

Aggregations

Content (com.amazon.android.model.content.Content)76 ContentContainer (com.amazon.android.model.content.ContentContainer)28 Test (org.junit.Test)26 ArrayObjectAdapter (androidx.leanback.widget.ArrayObjectAdapter)13 ListRow (androidx.leanback.widget.ListRow)13 ArrayList (java.util.ArrayList)11 Recipe (com.amazon.android.recipe.Recipe)10 Intent (android.content.Intent)8 RecentDatabaseHelper (com.amazon.android.contentbrowser.database.helpers.RecentDatabaseHelper)7 TextUtils (android.text.TextUtils)6 RecentRecord (com.amazon.android.contentbrowser.database.records.RecentRecord)6 CardPresenter (com.amazon.android.tv.tenfoot.presenter.CardPresenter)6 List (java.util.List)6 Context (android.content.Context)5 HeaderItem (androidx.leanback.widget.HeaderItem)5 Action (com.amazon.android.model.Action)5 NavigatorModel (com.amazon.android.navigator.NavigatorModel)5 AndroidSchedulers (rx.android.schedulers.AndroidSchedulers)5 Bundle (android.os.Bundle)4 Log (android.util.Log)4