Search in sources :

Example 11 with Content

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

the class ZypeSearchManager method getSearchContentsObservable.

private Observable<Object> getSearchContentsObservable(String feed, ISearchResult iSearchResult) {
    DynamicParser parser = new DynamicParser();
    ZypeContentTranslator zypeContentTranslator = new ZypeContentTranslator();
    parser.addTranslatorImpl(zypeContentTranslator.getName(), zypeContentTranslator);
    String[] params = new String[] { (String) "" };
    return parser.cookRecipeObservable(recipeSearchContents, feed, null, params).map(contentAsObject -> {
        Content content = (Content) contentAsObject;
        if (content != null) {
            iSearchResult.onSearchResult(content, false);
        }
        return content;
    });
}
Also used : ZypeContentTranslator(com.amazon.android.model.translators.ZypeContentTranslator) Content(com.amazon.android.model.content.Content) DynamicParser(com.amazon.dynamicparser.DynamicParser)

Example 12 with Content

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

the class ContentLoader method loadContentForContentContainer.

// TODO: Move 'loadPlaylistVideos()' from 'ContentBrowser' to here,
// - update definition of 'loadPlaylistVideos' to use listener
// - update all calls of 'loadPlaylistVideos' with listeners instead of listening to broadcast receivers
// for updating content with result of this function
// - replace all calls of 'loadContentForContentContainer' function with 'loadPlaylistVideos'
public void loadContentForContentContainer(ContentContainer contentContainer, Context context, ILoadContentForContentContainer callback) {
    // NavigatorModel.GlobalRecipes recipe = mNavigator.getNavigatorModel().getGlobalRecipes().get(0);
    // Recipe dataLoaderRecipeForContents = recipe.getContents().dataLoaderRecipe;
    // Recipe dynamicParserRecipeForContents = recipe.getContents().dynamicParserRecipe;
    // 
    HashMap<String, String> params = new HashMap<>();
    params.put(ZypeApi.APP_KEY, ZypeSettings.APP_KEY);
    params.put(ZypeApi.PER_PAGE, String.valueOf(ZypeApi.PER_PAGE_DEFAULT));
    ZypeApi.getInstance().getApi().getPlaylistVideos(contentContainer.getExtraStringValue(Recipe.KEY_DATA_TYPE_TAG), 1, params).enqueue(new Callback<VideosResponse>() {

        @Override
        public void onResponse(Call<VideosResponse> call, Response<VideosResponse> response) {
            if (response.isSuccessful()) {
                if (response.body().pagination.current == response.body().pagination.pages) {
                    contentContainer.setExtraValue(ExtraKeys.NEXT_PAGE, -1);
                } else {
                    contentContainer.setExtraValue(ExtraKeys.NEXT_PAGE, response.body().pagination.next);
                }
                if (!response.body().videoData.isEmpty()) {
                    Log.d(TAG, "loadContentForContentContainer(): onResponse(): size=" + response.body().videoData.size());
                    for (VideoData videoData : response.body().videoData) {
                        if (TextUtils.isEmpty(videoData.description) || videoData.description.equals("null")) {
                            videoData.description = " ";
                        }
                        videoData.playlistId = (String) contentContainer.getExtraStringValue(Recipe.KEY_DATA_TYPE_TAG);
                        videoData.playerUrl = "null";
                    }
                    GsonBuilder builder = new GsonBuilder();
                    Gson gson = builder.create();
                    String feed = gson.toJson(response.body().videoData);
                    // TODO: Rename the recipe file
                    Recipe recipe = Recipe.newInstance(context, "recipes/ZypeSearchContentsRecipe.json");
                    Subscription subscription = getContentsForContentContainerObservable(feed, recipe, contentContainer).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribe(result -> {
                    }, throwable -> {
                        if (contentContainer.getContentCount() > 0) {
                            callback.onContentsLoaded();
                        }
                    }, () -> {
                        callback.onContentsLoaded();
                    });
                // mCompositeSubscription.add(subscription);
                }
            } else {
            // TODO: Handle error
            }
        }

        @Override
        public void onFailure(Call<VideosResponse> call, Throwable t) {
        // TODO: Handle exception
        }
    });
}
Also used : Arrays(java.util.Arrays) ZypeDataDownloaderHelper(com.amazon.dataloader.datadownloader.ZypeDataDownloaderHelper) VideoFavoriteResponse(com.zype.fire.api.Model.VideoFavoriteResponse) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) GsonBuilder(com.google.gson.GsonBuilder) NavigatorModel(com.amazon.android.navigator.NavigatorModel) PlaylistData(com.zype.fire.api.Model.PlaylistData) Gson(com.google.gson.Gson) VideosResponse(com.zype.fire.api.Model.VideosResponse) Map(java.util.Map) Schedulers(rx.schedulers.Schedulers) ExtraKeys(com.amazon.android.model.content.constants.ExtraKeys) ContentContainerTranslator(com.amazon.android.model.translators.ContentContainerTranslator) Log(android.util.Log) ResponseBody(okhttp3.ResponseBody) Preferences(com.amazon.android.utils.Preferences) List(java.util.List) ZypeConfiguration(com.zype.fire.api.ZypeConfiguration) NavigatorModelParser(com.amazon.android.navigator.NavigatorModelParser) Data(com.amazon.utils.model.Data) ZypeSettings(com.zype.fire.api.ZypeSettings) BROADCAST_VIDEO_DETAIL_DATA_LOADED(com.amazon.android.contentbrowser.ContentBrowser.BROADCAST_VIDEO_DETAIL_DATA_LOADED) ZypeContentContainerTranslator(com.amazon.android.model.translators.ZypeContentContainerTranslator) Call(retrofit2.Call) Subscription(rx.Subscription) Context(android.content.Context) Recipe(com.amazon.android.recipe.Recipe) VideoFavoritesHelper(com.amazon.android.contentbrowser.database.helpers.VideoFavoritesHelper) Pair(android.util.Pair) ZypeContentTranslator(com.amazon.android.model.translators.ZypeContentTranslator) Intent(android.content.Intent) LocalBroadcastManager(androidx.localbroadcastmanager.content.LocalBroadcastManager) HashMap(java.util.HashMap) Response(retrofit2.Response) RecentRecord(com.amazon.android.contentbrowser.database.records.RecentRecord) ArrayList(java.util.ArrayList) Observable(rx.Observable) ZypeAuthentication(com.zype.fire.auth.ZypeAuthentication) VideoResponse(com.zype.fire.api.Model.VideoResponse) VideoEntitlementsResponse(com.zype.fire.api.Model.VideoEntitlementsResponse) BROADCAST_DATA_LOADED(com.amazon.android.contentbrowser.ContentBrowser.BROADCAST_DATA_LOADED) TextUtils(android.text.TextUtils) VideoData(com.zype.fire.api.Model.VideoData) Content(com.amazon.android.model.content.Content) DynamicParser(com.amazon.dynamicparser.DynamicParser) ZypeApi(com.zype.fire.api.ZypeApi) Callback(retrofit2.Callback) VideoEntitlementData(com.zype.fire.api.Model.VideoEntitlementData) RecentDatabaseHelper(com.amazon.android.contentbrowser.database.helpers.RecentDatabaseHelper) ContentTranslator(com.amazon.android.model.translators.ContentTranslator) DataLoadManager(com.amazon.dataloader.dataloadmanager.DataLoadManager) Navigator(com.amazon.android.navigator.Navigator) ContentContainer(com.amazon.android.model.content.ContentContainer) HashMap(java.util.HashMap) GsonBuilder(com.google.gson.GsonBuilder) Recipe(com.amazon.android.recipe.Recipe) Gson(com.google.gson.Gson) VideoData(com.zype.fire.api.Model.VideoData) VideosResponse(com.zype.fire.api.Model.VideosResponse) Subscription(rx.Subscription)

Example 13 with Content

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

the class RecommendationSender method buildRecommendation.

/**
 * Builds the recommendation.
 *
 * @param contentId        The content id.
 * @param recommendationId The recommendation id.
 * @param group            The recommendation type.
 * @return The recommendation.
 */
Notification buildRecommendation(String contentId, int recommendationId, String group) {
    Content content = getContentFromRoot(contentId);
    if (content == null) {
        Log.e(TAG, "Could not build recommendation for content with id " + contentId + " " + "because content not found");
        return null;
    }
    // Try getting the content's playback progress (if it exists)
    int playbackProgress = 0;
    long lastWatchedDateTime = 0;
    RecentDatabaseHelper database = RecentDatabaseHelper.getInstance();
    if (database != null) {
        if (database.recordExists(mContext, contentId)) {
            // Need to get recent db from content browser. Maybe shoudl do that for all instead of passing?
            RecentRecord record = database.getRecord(mContext, contentId);
            playbackProgress = (int) record.getPlaybackLocation();
            lastWatchedDateTime = record.getLastWatched();
        }
    } else {
        Log.e(TAG, "Could not get recent playback progress for content because database is " + "null");
    }
    // Create the recommendation builder.
    RecommendationBuilder builder = new RecommendationBuilder().setContext(mContext);
    Log.d(TAG, "Built recommendation - " + content.getTitle());
    try {
        int live = content.getExtraValueAsBoolean(Content.LIVE_TAG) ? 1 : 0;
        List genres = content.getExtraValueAsList(Content.GENRES_TAG);
        List contentType = content.getExtraValueAsList(Content.CONTENT_TYPE_TAG);
        ArrayList<Integer> actions = (ArrayList<Integer>) content.getExtraValueAsList(Content.RECOMMENDATION_ACTIONS_TAG);
        ArrayList<String> contentCategories = (ArrayList<String>) content.getExtraValueAsList(Content.FIRE_TV_CATEGORIES_TAG);
        return builder.setBackgroundUrl(content.getBackgroundImageUrl()).setRecommendationId(recommendationId).setTitle(content.getTitle()).setText(content.getDescription()).setLargeIconUrl(content.getCardImageUrl()).setContentIntent(buildContentIntent(mContext, content.getId())).setDismissIntent(buildDismissIntent(mContext, recommendationId)).setContentDuration(content.getDuration()).setMaturityRating(String.valueOf(content.getExtraValue(Content.MATURITY_RATING_TAG))).setContentId(content.getId()).setContentCategories(contentCategories).setDescription(content.getDescription()).setRank(// highest priority
        0).setLiveContent(live).setContentStartTime(content.getExtraValueAsLong(Content.START_TIME_TAG)).setContentEndTime(content.getExtraValueAsLong(Content.END_TIME_TAG)).setContentReleaseDate(String.valueOf(content.getAvailableDate())).setContentClosedCaptions(content.hasCloseCaption() ? 1 : 0).setGroup(group).setContentCustomerRating(content.getExtraValueAsInt(Content.CUSTOMER_RATING_TAG)).setContentCustomerRatingCount(content.getExtraValueAsInt(Content.CUSTOMER_RATING_COUNT_TAG)).setPreviewVideoUrl(String.valueOf(content.getExtraValue(Content.VIDEO_PREVIEW_URL_TAG))).setImdbId(String.valueOf(content.getExtraValue(Content.IMDB_ID_TAG))).setPlaybackProgress(playbackProgress).setGenres((String[]) genres.toArray(new String[genres.size()])).setContentTypes((String[]) contentType.toArray(new String[contentType.size()])).setActions(actions).setLastWatchedDateTime(lastWatchedDateTime).build();
    } catch (Exception e) {
        Log.e(TAG, "Unable to build recommendation", e);
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) RecentRecord(com.amazon.android.contentbrowser.database.records.RecentRecord) RecentDatabaseHelper(com.amazon.android.contentbrowser.database.helpers.RecentDatabaseHelper) Content(com.amazon.android.model.content.Content) ArrayList(java.util.ArrayList) List(java.util.List)

Example 14 with Content

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

the class ContentTranslatorTest method testValidateModelFalseCardImageUrl.

/**
 * Tests the {@link ContentTranslator#validateModel(Content)} method for the false case where
 * the cardImageUrl is invalid.
 */
@Test
public void testValidateModelFalseCardImageUrl() throws Exception {
    Content content = createValidContent();
    // make good content bad
    content.setCardImageUrl("");
    assertFalse(mContentTranslator.validateModel(content));
}
Also used : Content(com.amazon.android.model.content.Content) Test(org.junit.Test)

Example 15 with Content

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

the class ContentTranslatorTest method testMapToModel.

/**
 * Tests the {@link ContentTranslator#mapToModel(Map, Recipe)} with valid map and recipe
 * arguments.
 */
@Test
public void testMapToModel() throws Exception {
    Content expected = createValidContent();
    Content result = mContentTranslator.mapToModel(createValidMap(), mGoodRecipe);
    assertEquals(expected, result);
}
Also used : Content(com.amazon.android.model.content.Content) Test(org.junit.Test)

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