Search in sources :

Example 71 with Content

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);
}
Also used : Recipe(com.amazon.android.recipe.Recipe) NavigatorModel(com.amazon.android.navigator.NavigatorModel) Intent(android.content.Intent) FavoritesLoadEvent(com.amazon.android.model.event.FavoritesLoadEvent) AlertDialogFragment(com.amazon.android.ui.fragments.AlertDialogFragment) Content(com.amazon.android.model.content.Content) ContentContainer(com.amazon.android.model.content.ContentContainer) Subscription(rx.Subscription) CompositeSubscription(rx.subscriptions.CompositeSubscription)

Example 72 with Content

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;
}
Also used : RecentDatabaseHelper(com.amazon.android.contentbrowser.database.helpers.RecentDatabaseHelper) Content(com.amazon.android.model.content.Content) ArrayList(java.util.ArrayList) RecentRecord(com.amazon.android.contentbrowser.database.records.RecentRecord)

Example 73 with Content

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);
    }
}
Also used : Content(com.amazon.android.model.content.Content)

Example 74 with 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);
}
Also used : AlertDialogFragment(com.amazon.android.ui.fragments.AlertDialogFragment) Content(com.amazon.android.model.content.Content) ContentContainer(com.amazon.android.model.content.ContentContainer) Intent(android.content.Intent) Subscription(rx.Subscription) CompositeSubscription(rx.subscriptions.CompositeSubscription)

Example 75 with Content

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

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