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);
});
}
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);
}
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);
}
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);
});
}
});
}
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());
}
}
Aggregations