use of com.amazon.android.model.content.Content in project zype-firebuilder by zype.
the class ContentBrowser method runGlobalRecipesForLastSelected.
public void runGlobalRecipesForLastSelected(Activity activity, ICancellableLoad cancellable) {
final ContentContainer root = getLastSelectedContentContainer();
Subscription subscription = Observable.range(0, mNavigator.getNavigatorModel().getGlobalRecipes().size()).subscribeOn(Schedulers.newThread()).concatMap(index -> {
NavigatorModel.GlobalRecipes recipe = mNavigator.getNavigatorModel().getGlobalRecipes().get(index);
Recipe recipeDynamicParserVideos = Recipe.newInstance(mAppContext, "recipes/ZypeSearchContentsRecipe.json");
return mContentLoader.runZypeGlobalRecipeAtIndex(recipe, recipeDynamicParserVideos, index, root);
}).onBackpressureBuffer().doOnNext(o -> {
if (DEBUG_RECIPE_CHAIN) {
Log.d(TAG, "doOnNext");
}
}).observeOn(AndroidSchedulers.mainThread()).subscribe(objectPair -> {
if (DEBUG_RECIPE_CHAIN) {
Log.d(TAG, "subscriber onNext called");
}
}, throwable -> {
Log.e(TAG, "Recipe chain failed:", throwable);
LocalBroadcastManager.getInstance(mNavigator.getActiveActivity()).sendBroadcast(new Intent(BROADCAST_DATA_LOADED));
// ErrorHelper.injectErrorFragment(
// mNavigator.getActiveActivity(),
// ErrorUtils.ERROR_CATEGORY.FEED_ERROR,
// (errorDialogFragment, errorButtonType,
// errorCategory) -> {
// if (errorButtonType ==
// ErrorUtils.ERROR_BUTTON_TYPE.EXIT_APP) {
// mNavigator.getActiveActivity().finishAffinity();
// }
// });
ErrorHelper.injectErrorFragment(mNavigator.getActiveActivity(), ErrorUtils.ERROR_CATEGORY.ZYPE_NO_VIDEOS, (errorDialogFragment, errorButtonType, errorCategory) -> {
errorDialogFragment.dismiss();
mNavigator.getActiveActivity().finish();
});
}, () -> {
Log.v(TAG, "Recipe chain completed");
// Remove empty sub containers.
if (!root.getExtraStringValue(Recipe.KEY_DATA_TYPE_TAG).equals(ZypeSettings.ROOT_MY_LIBRARY_PLAYLIST_ID) && !root.getExtraStringValue(Recipe.KEY_DATA_TYPE_TAG).equals(ZypeSettings.ROOT_FAVORITES_PLAYLIST_ID)) {
root.removeEmptySubContainers();
}
// mContentLoader.setRootContentContainer(root);
if (mIRootContentContainerListener != null) {
mIRootContentContainerListener.onRootContentContainerPopulated(mContentLoader.getRootContentContainer());
}
mContentLoader.setContentReloadRequired(false);
mContentLoader.setContentLoaded(true);
if (cancellable != null && cancellable.isLoadingCancelled()) {
Log.d(TAG, "Content load complete but app has been cancelled, " + "returning from here");
return;
}
if (mLauncherIntegrationManager != null && activity != null && LauncherIntegrationManager.isCallFromLauncher(activity.getIntent())) {
Log.d(TAG, "Call from launcher with intent " + activity.getIntent());
String contentId = null;
try {
contentId = LauncherIntegrationManager.getContentIdToPlay(mAppContext, activity.getIntent());
Content content = getRootContentContainer().findContentById(contentId);
if (content == null) {
mRecommendationManager.dismissRecommendation(contentId);
throw new IllegalArgumentException("No content exist " + "for " + "contentId " + contentId);
}
AnalyticsHelper.trackLauncherRequest(contentId, content, getSourceOfContentPlayRequest(activity.getIntent()));
Intent intent = new Intent();
intent.putExtra(Content.class.getSimpleName(), content);
intent.putExtra(REQUEST_FROM_LAUNCHER, true);
intent.putExtra(PreferencesConstants.CONTENT_ID, content.getId());
switchToHomeScreen(intent);
} catch (Exception e) {
Log.e(TAG, e.getLocalizedMessage(), e);
AnalyticsHelper.trackLauncherRequest(contentId, null, getSourceOfContentPlayRequest(activity.getIntent()));
AlertDialogFragment.createAndShowAlertDialogFragment(mNavigator.getActiveActivity(), "Error", "The selected content is no longer available", null, mAppContext.getString(R.string.ok), new AlertDialogFragment.IAlertDialogListener() {
@Override
public void onDialogPositiveButton(AlertDialogFragment alertDialogFragment) {
}
@Override
public void onDialogNegativeButton(AlertDialogFragment alertDialogFragment) {
alertDialogFragment.dismiss();
if (cancellable != null && cancellable.isLoadingCancelled()) {
Log.d(TAG, "switchToHomeScreen after " + "launcher integration " + "exception cancelled");
return;
}
switchToHomeScreen();
}
});
}
} else // if (mLauncherIntegrationManager != null && activity != null &&
// LauncherIntegrationManager
// .isCallFromLauncher(activity.getIntent())) {
//
// Log.i(TAG, "Call from launcher with intent " +
// activity.getIntent());
//
// try {
// long contentId = LauncherIntegrationManager
// .getContentIdToPlay(mAppContext, activity.getIntent());
//
// Content content =
// getRootContentContainer().findContentById(contentId);
// if (content == null) {
// throw new IllegalArgumentException("No content exist for " +
// "contentId " +
// contentId);
// }
// handleRendererScreenSwitch(mNavigator.getActiveActivity(),
// content,
// CONTENT_ACTION_WATCH_NOW, false);
//
// }
// catch (Exception e) {
// Log.e(TAG, e.getLocalizedMessage(), e);
// AlertDialogFragment.createAndShowAlertDialogFragment
// (mNavigator.getActiveActivity(),
// "Error",
// "The desired content does not exist",
// null,
// mAppContext.getString(R.string.ok),
// new AlertDialogFragment.IAlertDialogListener() {
//
// @Override
// public void onDialogPositiveButton
// (AlertDialogFragment alertDialogFragment) {
//
// }
//
// @Override
// public void onDialogNegativeButton
// (AlertDialogFragment alertDialogFragment) {
//
// alertDialogFragment.dismiss();
// if (cancellable != null &&
// cancellable.isLoadingCancelled()) {
// Log.d(TAG, "switchToHomeScreen after " +
// "Splash cancelled");
// return;
// }
// switchToHomeScreen();
// }
// });
// }
// }
{
if (cancellable != null && cancellable.isLoadingCancelled()) {
Log.d(TAG, "switchToHomeScreen after Splash cancelled");
return;
}
// This broadcast is handled in ZypePlaylistContentBrowseFragment to update content
if (root.getExtraStringValue(Recipe.KEY_DATA_TYPE_TAG).equals(ZypeSettings.ROOT_FAVORITES_PLAYLIST_ID)) {
setFavoritesLoaded(true);
mEventBus.post(new FavoritesLoadEvent(isFavoritesLoaded()));
} else {
LocalBroadcastManager.getInstance(mNavigator.getActiveActivity()).sendBroadcast(new Intent(BROADCAST_DATA_LOADED));
}
}
});
mCompositeSubscription.add(subscription);
}
use of com.amazon.android.model.content.Content in project zype-firebuilder by zype.
the class ContentBrowser method getRecentContent.
/**
* Get a list of contents to display in the "Continue Watching" row that have been watched for
* more than the grace period value located in the custom.xml as recent_grace_period.
*
* @return A list of contents.
*/
public List<Content> getRecentContent() {
List<Content> contentList = new ArrayList<>();
RecentDatabaseHelper databaseHelper = RecentDatabaseHelper.getInstance();
if (databaseHelper != null) {
List<RecentRecord> records = databaseHelper.getUnfinishedRecords(mAppContext, mAppContext.getResources().getInteger(R.integer.recent_grace_period));
for (RecentRecord record : records) {
Content content = mContentLoader.getRootContentContainer().findContentById(record.getContentId());
if (content != null) {
contentList.add(content);
}
}
}
return contentList;
}
use of com.amazon.android.model.content.Content in project zype-firebuilder by zype.
the class ContentBrowser method restoreActivityState.
/**
* Restores the last active activity that was saved before the app went to the background or
* was closed.
*
* @param screenName The screen name of the activity to resume.
*/
private void restoreActivityState(String screenName) {
String lastActivity = Preferences.getString(com.amazon.android.ui.constants.PreferencesConstants.LAST_ACTIVITY);
String lastContent = Preferences.getString(PreferencesConstants.CONTENT_ID);
Content content = mContentLoader.getRootContentContainer().findContentById(lastContent);
Log.d(TAG, "Restoring to last activity: " + lastActivity + " with content: " + lastContent);
// Switch the last activity if its not the current one.
if (!StringManipulation.isNullOrEmpty(lastActivity) && !lastActivity.equals(screenName) && content != null) {
setLastSelectedContent(content);
switchToScreen(lastActivity, content);
}
}
use of com.amazon.android.model.content.Content in project zype-firebuilder by zype.
the class ContentBrowser method runGlobalRecipes.
/**
* Run global recipes.
*/
public void runGlobalRecipes(Activity activity, ICancellableLoad cancellable, Content autoPlayContent) {
final ContentContainer root = new ContentContainer("Root");
/* Zype, Evgeny Cherkasov */
// Set Zype playlist id to the root container
root.setExtraValue(Recipe.KEY_DATA_TYPE_TAG, ZypeConfiguration.getRootPlaylistId(mAppContext));
Subscription subscription = Observable.range(0, mNavigator.getNavigatorModel().getGlobalRecipes().size()).subscribeOn(Schedulers.newThread()).concatMap(index -> mContentLoader.runGlobalRecipeAtIndex(index, root)).onBackpressureBuffer().doOnNext(o -> {
if (DEBUG_RECIPE_CHAIN) {
Log.d(TAG, "doOnNext");
}
}).observeOn(AndroidSchedulers.mainThread()).subscribe(objectPair -> {
if (DEBUG_RECIPE_CHAIN) {
Log.d(TAG, "subscriber onNext called");
}
}, throwable -> {
Log.e(TAG, "Recipe chain 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, "Recipe chain completed");
// Remove empty sub containers.
root.removeEmptySubContainers();
mContentLoader.setRootContentContainer(root);
if (mIRootContentContainerListener != null) {
mIRootContentContainerListener.onRootContentContainerPopulated(mContentLoader.getRootContentContainer());
}
mContentLoader.setContentReloadRequired(false);
mContentLoader.setContentLoaded(true);
if (cancellable != null && cancellable.isLoadingCancelled()) {
Log.d(TAG, "Content load complete but app has been cancelled, " + "returning from here");
return;
}
if (mLauncherIntegrationManager != null && activity != null && LauncherIntegrationManager.isCallFromLauncher(activity.getIntent())) {
Log.d(TAG, "Call from launcher with intent " + activity.getIntent());
String contentId = null;
try {
contentId = LauncherIntegrationManager.getContentIdToPlay(mAppContext, activity.getIntent());
Content content = getRootContentContainer().findContentById(contentId);
if (content == null) {
mRecommendationManager.dismissRecommendation(contentId);
throw new IllegalArgumentException("No content exist " + "for " + "contentId " + contentId);
}
AnalyticsHelper.trackLauncherRequest(contentId, content, getSourceOfContentPlayRequest(activity.getIntent()));
Intent intent = new Intent();
intent.putExtra(Content.class.getSimpleName(), content);
intent.putExtra(REQUEST_FROM_LAUNCHER, true);
intent.putExtra(PreferencesConstants.CONTENT_ID, content.getId());
switchHomeOrAutoPlayScreen(intent, autoPlayContent);
} catch (Exception e) {
Log.e(TAG, e.getLocalizedMessage(), e);
AnalyticsHelper.trackLauncherRequest(contentId, null, getSourceOfContentPlayRequest(activity.getIntent()));
AlertDialogFragment.createAndShowAlertDialogFragment(mNavigator.getActiveActivity(), "Error", "The selected content is no longer available", null, mAppContext.getString(R.string.ok), new AlertDialogFragment.IAlertDialogListener() {
@Override
public void onDialogPositiveButton(AlertDialogFragment alertDialogFragment) {
}
@Override
public void onDialogNegativeButton(AlertDialogFragment alertDialogFragment) {
alertDialogFragment.dismiss();
if (cancellable != null && cancellable.isLoadingCancelled()) {
Log.d(TAG, "switchToHomeScreen after " + "launcher integration " + "exception cancelled");
return;
}
switchHomeOrAutoPlayScreen(null, autoPlayContent);
}
});
}
} else {
if (cancellable != null && cancellable.isLoadingCancelled()) {
Log.d(TAG, "switchToHomeScreen after Splash cancelled");
return;
}
// the user is logged in.
if (!Navigator.isScreenAccessVerificationRequired(mNavigator.getNavigatorModel()) || Preferences.getBoolean(LauncherIntegrationManager.PREFERENCE_KEY_USER_AUTHENTICATED)) {
mRecommendationManager.cleanDatabase();
mRecommendationManager.updateGlobalRecommendations(mAppContext);
}
if (shouldRestoreLastActivity(activity)) {
Log.d(TAG, "Ran global recipes from app launch. Will " + "add intent extra to resume previous activity");
switchHomeOrAutoPlayScreen(activity.getIntent(), autoPlayContent);
} else {
switchHomeOrAutoPlayScreen(null, autoPlayContent);
}
}
});
mCompositeSubscription.add(subscription);
}
use of com.amazon.android.model.content.Content in project zype-firebuilder by zype.
the class ContentLoader method getLoadContentsByVideoIdsObservable.
public Observable<Object> getLoadContentsByVideoIdsObservable(Observable<Object> observable, Recipe recipeDynamicParser, List<String> videoIds) {
return observable.map(contentContainerAsObject -> {
ContentContainer contentContainer = (ContentContainer) contentContainerAsObject;
contentContainer.getContents().clear();
contentContainer.setExtraValue(ExtraKeys.NEXT_PAGE, -1);
return contentContainerAsObject;
}).concatMap(contentContainerAsObject -> {
ContentContainer contentContainer = (ContentContainer) contentContainerAsObject;
if (DEBUG_RECIPE_CHAIN) {
Log.d(TAG, "getLoadContentsByVideoIdsObservable(): " + contentContainer.getName());
}
// Loading videos
return getVideosFeedObservable(contentContainerAsObject, videoIds);
}).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);
}
return Pair.create(contentContainer, contentAsObject);
});
}
});
}
Aggregations