Search in sources :

Example 1 with Recipe

use of com.amazon.android.recipe.Recipe in project zype-firebuilder by zype.

the class ContentBrowser method getContentById.

public Observable<Content> getContentById(String videoId) {
    ContentContainer contentContainer = new ContentContainer();
    Recipe recipeDynamicParserVideos = Recipe.newInstance(mAppContext, "recipes/ZypeSearchContentsRecipe.json");
    return mContentLoader.getLoadContentsByVideoIdsObservable(Observable.just(contentContainer), recipeDynamicParserVideos, Arrays.asList(videoId)).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).flatMap(o -> {
        Pair pair = (Pair) o;
        return Observable.just((Content) pair.second);
    });
}
Also used : Recipe(com.amazon.android.recipe.Recipe) ContentContainer(com.amazon.android.model.content.ContentContainer) Pair(android.util.Pair)

Example 2 with Recipe

use of com.amazon.android.recipe.Recipe in project zype-firebuilder by zype.

the class ContentBrowser method loadLocalFavoritesVideos.

public void loadLocalFavoritesVideos(ContentContainer contentContainer) {
    Observable<Object> observable = Observable.just(contentContainer.getContentContainers().get(0));
    Recipe recipeDynamicParserVideos = Recipe.newInstance(mAppContext, "recipes/ZypeSearchContentsRecipe.json");
    Subscription subscription = observable.subscribeOn(Schedulers.newThread()).concatMap(contentContainerAsObject -> {
        List<VideoFavoriteRecord> videoFavorites = favoritesManager.getVideoFavorites();
        List<String> videoIds = new ArrayList<>();
        for (VideoFavoriteRecord record : videoFavorites) {
            videoIds.add(record.getVideoId());
        }
        return mContentLoader.getLoadContentsByVideoIdsObservable(Observable.just(contentContainerAsObject), recipeDynamicParserVideos, videoIds);
    }).onBackpressureBuffer().doOnNext(o -> {
    }).observeOn(AndroidSchedulers.mainThread()).subscribe(result -> {
    }, throwable -> {
        Log.e(TAG, "loadLocalFavoritesVideos(): failed: ", throwable);
        ErrorHelper.injectErrorFragment(mNavigator.getActiveActivity(), ErrorUtils.ERROR_CATEGORY.FEED_ERROR, (errorDialogFragment, errorButtonType, errorCategory) -> {
            if (errorButtonType == ErrorUtils.ERROR_BUTTON_TYPE.EXIT_APP) {
                mNavigator.getActiveActivity().finishAffinity();
            }
        });
    }, () -> {
        Log.v(TAG, "loadLocalFavoritesVideos(): completed");
        setFavoritesLoaded(true);
        mEventBus.post(new FavoritesLoadEvent(favoritesLoaded));
    });
    mCompositeSubscription.add(subscription);
}
Also used : Recipe(com.amazon.android.recipe.Recipe) ArrayList(java.util.ArrayList) VideoFavoriteRecord(com.amazon.android.contentbrowser.database.records.VideoFavoriteRecord) Subscription(rx.Subscription) CompositeSubscription(rx.subscriptions.CompositeSubscription) FavoritesLoadEvent(com.amazon.android.model.event.FavoritesLoadEvent)

Example 3 with Recipe

use of com.amazon.android.recipe.Recipe in project zype-firebuilder by zype.

the class ContentLoader method runZypeGlobalRecipeAtIndex.

public Observable<Object> runZypeGlobalRecipeAtIndex(NavigatorModel.GlobalRecipes recipe, Recipe recipeDynamicParserVideos, int index, ContentContainer root) {
    Recipe dataLoaderRecipeForCategories = recipe.getCategories().dataLoaderRecipe;
    Recipe dataLoaderRecipeForContents = recipe.getContents().dataLoaderRecipe;
    Recipe dynamicParserRecipeForCategories = recipe.getCategories().dynamicParserRecipe;
    Recipe dynamicParserRecipeForContents = recipe.getContents().dynamicParserRecipe;
    // Add any extra configurations that the parser recipe needs from the navigator recipe.
    if (recipe.getRecipeConfig() != null) {
        // Add if the recipe is for live feed data.
        dynamicParserRecipeForContents.getMap().put(Recipe.LIVE_FEED_TAG, recipe.getRecipeConfig().liveContent);
    }
    String hardCodedCategoryName = recipe.getCategories().name;
    return getLoadContentChainObservable(hardCodedCategoryName, dataLoaderRecipeForCategories, dynamicParserRecipeForCategories, recipeDynamicParserVideos, root);
}
Also used : Recipe(com.amazon.android.recipe.Recipe)

Example 4 with Recipe

use of com.amazon.android.recipe.Recipe in project zype-firebuilder by zype.

the class ContentLoader method getLoadContentsObservable.

/*
     * Zype, Evgeny Cherkasov
     */
public Observable<Object> getLoadContentsObservable(Observable<Object> observable, Recipe recipeDynamicParser) {
    return observable.map(contentContainerAsObject -> {
        ContentContainer contentContainer = (ContentContainer) contentContainerAsObject;
        if (contentContainer.getExtraStringValue(Recipe.KEY_DATA_TYPE_TAG).equals(ZypeSettings.MY_LIBRARY_PLAYLIST_ID)) {
            ContentContainer rootMyLibrary = getRootContentContainer().findContentContainerByName(ZypeSettings.ROOT_MY_LIBRARY_PLAYLIST_ID);
            if (rootMyLibrary.getExtraValueAsInt(ExtraKeys.NEXT_PAGE) == 1) {
                contentContainer.getContents().clear();
            }
        } else {
            if (contentContainer.getExtraValueAsInt(ExtraKeys.NEXT_PAGE) == 1) {
                contentContainer.getContents().clear();
            }
        }
        return contentContainerAsObject;
    }).concatMap(contentContainerAsObject -> {
        ContentContainer contentContainer = (ContentContainer) contentContainerAsObject;
        if (DEBUG_RECIPE_CHAIN) {
            Log.d(TAG, "getLoadContentsObservable:" + contentContainer.getName());
        }
        if (contentContainer.getExtraStringValue(Recipe.KEY_DATA_TYPE_TAG).equals(ZypeSettings.MY_LIBRARY_PLAYLIST_ID)) {
            // Loading My Library videos
            return getMyLibraryVideosObservable(contentContainerAsObject);
        } else if (contentContainer.getExtraStringValue(Recipe.KEY_DATA_TYPE_TAG).equals(ZypeSettings.FAVORITES_PLAYLIST_ID)) {
            // Load favorites videos
            return getFavoriteVideosFeedObservable(contentContainerAsObject);
        } else {
            LocalBroadcastManager.getInstance(mContext).sendBroadcast(new Intent(BROADCAST_VIDEO_DETAIL_DATA_LOADED));
            // Loading playlist videos
            return getPlaylistVideosFeedObservable(contentContainerAsObject);
        }
    }).concatMap(objectPair -> {
        ContentContainer contentContainer = (ContentContainer) objectPair.first;
        String feed = (String) objectPair.second;
        String[] params = new String[] { contentContainer.getExtraStringValue(Recipe.KEY_DATA_TYPE_TAG) };
        if (TextUtils.isEmpty(feed)) {
            return Observable.just(Pair.create(contentContainer, null));
        } else {
            return mDynamicParser.cookRecipeObservable(recipeDynamicParser, feed, null, params).map(contentAsObject -> {
                if (DEBUG_RECIPE_CHAIN) {
                    Log.d(TAG, "Parser got an content");
                }
                Content content = (Content) contentAsObject;
                if (content != null) {
                    contentContainer.addContent(content);
                    if (ZypeConfiguration.displayWatchedBarOnVideoThumbnails()) {
                        content.setExtraValue(Content.EXTRA_PLAYBACK_POSITION_PERCENTAGE, getContentPlaybackPositionPercentage(content));
                    }
                }
                return Pair.create(contentContainer, contentAsObject);
            });
        }
    });
}
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) Content(com.amazon.android.model.content.Content) ContentContainer(com.amazon.android.model.content.ContentContainer) Intent(android.content.Intent)

Example 5 with Recipe

use of com.amazon.android.recipe.Recipe in project zype-firebuilder by zype.

the class ContentLoader method getSubCategoriesObservable.

/* Zype, Evgeny Cherkasov */
private Observable<Object> getSubCategoriesObservable(ContentContainer parentContentContainer, Recipe dataLoaderRecipeForCategories, Recipe dynamicParserRecipeForCategories) {
    parentContentContainer.getContentContainers().clear();
    if (Integer.valueOf(parentContentContainer.getExtraStringValue("playlistItemCount")) > 0) {
        // If playlist contains videos just return itself and ignore nested playlists
        return Observable.just(parentContentContainer);
    } else {
        return Observable.concat(Observable.just(parentContentContainer), mDataLoadManager.cookRecipeObservable(dataLoaderRecipeForCategories, null, null, null).map(feedDataForCategories -> {
            if (CAUSE_A_FEED_ERROR_FOR_DEBUGGING) {
                return Observable.error(new Exception());
            }
            return feedDataForCategories;
        }).concatMap(feedDataForCategories -> {
            String[] params = new String[] { (String) parentContentContainer.getExtraStringValue(Recipe.KEY_DATA_TYPE_TAG) };
            return mDynamicParser.cookRecipeObservable(dynamicParserRecipeForCategories, feedDataForCategories, null, params);
        }).filter(contentSubContainerAsObject -> contentSubContainerAsObject != null).map(contentSubContainerAsObject -> {
            ContentContainer contentSubContainer = (ContentContainer) contentSubContainerAsObject;
            if (DEBUG_RECIPE_CHAIN) {
                Log.d(TAG, "getSubCategoriesObservable(): " + contentSubContainer.getName());
            }
            if (contentSubContainer.getExtraValueAsInt(ContentContainer.EXTRA_PLAYLIST_ITEM_COUNT) > 0) {
                contentSubContainer.setExtraValue(ExtraKeys.NEXT_PAGE, 1);
            } else {
                contentSubContainer.setExtraValue(ExtraKeys.NEXT_PAGE, -1);
            }
            parentContentContainer.getContentContainers().add(contentSubContainer);
            return parentContentContainer;
        // if (Integer.valueOf(contentSubContainer.getExtraStringValue("playlistItemCount")) > 0) {
        // return parentContentContainer;
        // }
        // else {
        // return parentContentContainer;
        // }
        }).distinct());
    }
}
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) ContentContainer(com.amazon.android.model.content.ContentContainer)

Aggregations

Recipe (com.amazon.android.recipe.Recipe)76 Test (org.junit.Test)51 ArrayList (java.util.ArrayList)15 HashMap (java.util.HashMap)13 Content (com.amazon.android.model.content.Content)11 ContentContainer (com.amazon.android.model.content.ContentContainer)11 Map (java.util.Map)11 List (java.util.List)10 Subscription (rx.Subscription)10 NavigatorModel (com.amazon.android.navigator.NavigatorModel)8 Data (com.amazon.utils.model.Data)8 Intent (android.content.Intent)7 Pair (android.util.Pair)6 Context (android.content.Context)5 TextUtils (android.text.TextUtils)5 Log (android.util.Log)5 LocalBroadcastManager (androidx.localbroadcastmanager.content.LocalBroadcastManager)5 BROADCAST_DATA_LOADED (com.amazon.android.contentbrowser.ContentBrowser.BROADCAST_DATA_LOADED)5 BROADCAST_VIDEO_DETAIL_DATA_LOADED (com.amazon.android.contentbrowser.ContentBrowser.BROADCAST_VIDEO_DETAIL_DATA_LOADED)5 RecentDatabaseHelper (com.amazon.android.contentbrowser.database.helpers.RecentDatabaseHelper)5