Search in sources :

Example 1 with ContentContainer

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

the class RecommendationSenderTest method testSetRootContentContainer.

/**
 * Test setting the root content container for a {@link RecommendationSender}.
 */
@Test
public void testSetRootContentContainer() throws Exception {
    ContentContainer newRoot = new ContentContainer("newRoot");
    mSender.setRootContentContainer(newRoot);
    assertEquals("The root container should now be newRoot", "newRoot", mSender.getRootContentContainer().getName());
}
Also used : ContentContainer(com.amazon.android.model.content.ContentContainer) Test(org.junit.Test)

Example 2 with ContentContainer

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

the class PerformanceTest method init.

/**
 * Set up environment for testing.
 */
private void init() throws Exception {
    final String APP_NAME = "com.fireappbuilder.android.calypso";
    // TODO: handle situations in which clearing logs takes an arbitrary amount of time
    // not needed for later versions of Android as Logcat supports time-based filtering
    Runtime.getRuntime().exec("logcat -c");
    // use ActivityManager to measure memory usage
    mActivityManager = (ActivityManager) mSplashActivity.getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
    ActivityManager.RunningAppProcessInfo calypsoProcess = null;
    // find the process for Calypso
    for (ActivityManager.RunningAppProcessInfo p : mActivityManager.getRunningAppProcesses()) {
        if (p.processName.equals(APP_NAME)) {
            calypsoProcess = p;
            break;
        }
    }
    assertNotNull("Calypso process not found.", calypsoProcess);
    calypsoPID = new int[] { calypsoProcess.pid };
    long startTime = System.currentTimeMillis();
    solo.waitForView(R.id.full_content_browse_fragment, 0, TestConfig.LONG_TIMEOUT);
    loadTime = (int) (System.currentTimeMillis() - startTime);
    // get item count
    count = 0;
    ContentContainer mContentContainer = ContentBrowser.getInstance(mSplashActivity).getRootContentContainer();
    List<Content> contentFound = new ArrayList<>();
    for (Content c : mContentContainer) {
        if (!contentFound.contains(c)) {
            contentFound.add(c);
            count++;
        }
    }
    // check if we are using sample feed
    Content firstItem = contentFound.get(0);
    boolean hasSampleVideo = firstItem.getTitle().contains("Sample item");
    boolean isValidSize = false;
    for (int s : SAMPLE_SIZES) {
        if (count == s) {
            isValidSize = true;
            break;
        }
    }
    isSampleFeed = hasSampleVideo && isValidSize;
}
Also used : Content(com.amazon.android.model.content.Content) ArrayList(java.util.ArrayList) ContentContainer(com.amazon.android.model.content.ContentContainer) ActivityManager(android.app.ActivityManager)

Example 3 with ContentContainer

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

the class ContentBrowser method getContentActionList.

/**
 * Get content action list.
 *
 * @param content Content.
 * @return List of action for provided content.
 */
public List<Action> getContentActionList(Content content) {
    if (content == null) {
        return Collections.emptyList();
    }
    List<Action> contentActionList = new ArrayList<>();
    boolean isSubscriptionNotRequired = !content.isSubscriptionRequired();
    if (isSubscriptionNotRequired && mOverrideAllContentsSubscriptionFlag) {
        isSubscriptionNotRequired = false;
    }
    /* Zype, Evgeny Cherkasov */
    // if (mSubscribed || isSubscriptionNotRequired || mIAPDisabled) {
    boolean showWatch = false;
    boolean showSubscribe = false;
    boolean showPurchase = false;
    boolean showPurchasePlaylist = false;
    boolean showAdFree = false;
    boolean showFavorites = false;
    boolean subscriptionRequired = content.isSubscriptionRequired();
    boolean purchaseRequired = false;
    boolean playlistPurchaseRequired = false;
    boolean entitled = entitlementsManager.isVideoEntitled(content);
    if (ZypeConfiguration.isUniversalTVODEnabled(mAppContext)) {
        purchaseRequired = content.getExtraValueAsBoolean(Content.EXTRA_PURCHASE_REQUIRED);
        if (ZypeSettings.PLAYLIST_PURCHASE_ENABLED) {
            ContentContainer playlist = getRootContentContainer().findContentContainerById(content.getExtraValueAsString(Content.EXTRA_PLAYLIST_ID));
            if (playlist != null) {
                playlistPurchaseRequired = playlist.getExtraValueAsBoolean(ContentContainer.EXTRA_PURCHASE_REQUIRED);
            // if (!entitled && playlistPurchaseRequired && content.getExtras().containsKey(Content.EXTRA_ENTITLED)) {
            // entitled = content.getExtraValueAsBoolean(Content.EXTRA_ENTITLED);
            // }
            }
        }
    }
    if (isSubscriptionNotRequired && !purchaseRequired && !playlistPurchaseRequired || mIAPDisabled) {
        showWatch = true;
    } else if (subscriptionRequired && purchaseRequired) {
        if (!isUserSubscribed() && !entitled) {
            showSubscribe = true;
            showPurchase = true;
        } else {
            showWatch = true;
        }
    } else {
        if (subscriptionRequired) {
            if (isUserSubscribed()) {
                showWatch = true;
            } else {
                if (ZypeConfiguration.isNativeSubscriptionEnabled(mAppContext) || ZypeConfiguration.marketplaceConnectSvodEnabled(mAppContext)) {
                    showSubscribe = true;
                } else {
                    showWatch = true;
                }
            }
        }
        if (purchaseRequired) {
            if (entitled) {
                showWatch = true;
            } else {
                if (ZypeConfiguration.isNativeTVODEnabled(mAppContext)) {
                    showPurchase = true;
                }
            }
        }
        if (playlistPurchaseRequired) {
            if (entitled) {
                showWatch = true;
            } else {
                if (ZypeConfiguration.isNativeTVODEnabled(mAppContext)) {
                    showPurchasePlaylist = true;
                    showWatch = false;
                }
            }
        }
    }
    if (ZypeConfiguration.isSubscribeToWatchAdFreeEnabled(mAppContext) && !showSubscribe && !ZypeConfiguration.isNativeSubscriptionEnabled(mAppContext) && !userLoggedIn) {
        showAdFree = true;
    }
    showFavorites = true;
    boolean registrationRequired = content.getExtraValueAsBoolean(Content.EXTRA_REGISTRATION_REQUIRED);
    if (registrationRequired) {
        if (!isUserLoggedIn()) {
            showWatch = false;
        } else {
            registrationRequired = false;
        }
    }
    if (showWatch) {
        // Check if the content is meant for live watching. Live content requires only a
        // watch now button.
        boolean liveContent = content.getExtraValue(Recipe.LIVE_FEED_TAG) != null && Boolean.valueOf(content.getExtraValue(Recipe.LIVE_FEED_TAG).toString());
        // Check database for stored playback position of content.
        if (!liveContent) {
            RecentRecord record = getRecentRecord(content);
            // Add "Resume" button if content playback is not complete.
            if (record != null && !record.isPlaybackComplete()) {
                contentActionList.add(createActionButton(1, CONTENT_ACTION_RESUME, R.string.resume_1, R.string.resume_2));
                // Add "Watch From Beginning" button to start content over.
                contentActionList.add(createActionButton(CONTENT_ACTION_WATCH_FROM_BEGINNING, R.string.watch_from_beginning_1, R.string.watch_from_beginning_2));
            } else // If the content has not been played yet, add the "Watch Now" button.
            {
                contentActionList.add(createActionButton(1, CONTENT_ACTION_WATCH_NOW, R.string.watch_now_1, R.string.watch_now_2));
            }
            if (isWatchlistRowEnabled()) {
                addWatchlistAction(contentActionList, content.getId());
            }
        } else {
            contentActionList.add(createActionButton(1, CONTENT_ACTION_WATCH_NOW, R.string.watch_now_1, R.string.watch_now_2));
        }
    }
    if (registrationRequired) {
        contentActionList.add(createActionButton(2, CONTENT_REGISTRATION_REQUIRED, R.string.action_signup_to_watch1, R.string.action_signup_to_watch2));
        if (content.hasTrailer()) {
            contentActionList.add(createActionButton(CONTENT_PLAY_TRAILER, R.string.action_play_trailer_1, R.string.action_play_trailer_2));
        }
        return contentActionList;
    }
    if (showSubscribe) {
        contentActionList.add(createActionButton(3, CONTENT_ACTION_CHOOSE_PLAN, R.string.action_subscription_1, R.string.action_subscription_2));
    }
    if (showPurchase) {
        contentActionList.add(createActionButton(4, CONTENT_ACTION_CONFIRM_PURCHASE, R.string.action_buy_video_1, R.string.action_buy_video_2));
    }
    if (showPurchasePlaylist) {
        ContentContainer playlist = getRootContentContainer().findContentContainerById(content.getExtraValueAsString(Content.EXTRA_PLAYLIST_ID));
        if (playlist != null) {
            String purchasePrice = playlist.getExtraStringValue(ContentContainer.EXTRA_PURCHASE_PRICE);
            int itemCount = playlist.getExtraValueAsInt(ContentContainer.EXTRA_PLAYLIST_ITEM_COUNT);
            Action action = createActionButton(5, CONTENT_ACTION_CONFIRM_PURCHASE_PLAYLIST, R.string.action_buy_playlist_1, R.string.action_buy_playlist_2);
            action.setLabel1(5, String.format(mAppContext.getResources().getString(R.string.action_buy_playlist_1), String.valueOf(itemCount)));
            action.setLabel2(5, String.format(mAppContext.getResources().getString(R.string.action_buy_playlist_2), purchasePrice));
            contentActionList.add(action);
        }
    }
    if (showAdFree) {
        contentActionList.add(createActionButton(CONTENT_ACTION_SWAF, R.string.action_swaf_1, R.string.action_swaf_2));
    }
    if (showFavorites) {
        ContentContainer favoritesContainer = getRootContentContainer().findContentContainerById(ZypeSettings.ROOT_FAVORITES_PLAYLIST_ID);
        if (favoritesContainer != null) {
            if (isFavoritesLoaded()) {
                if (!VideoFavoritesHelper.getInstance().recordExists(mAppContext, content.getId())) {
                    contentActionList.add(createActionButton(CONTENT_ACTION_FAVORITES_ADD, R.string.action_favorites_add_1, R.string.action_favorites_add_2));
                } else {
                    contentActionList.add(createActionButton(CONTENT_ACTION_FAVORITES_REMOVE, R.string.action_favorites_remove_1, R.string.action_favorites_remove_2));
                }
            } else {
                if (ZypeConfiguration.isFavoritesViaApiEnabled(mAppContext)) {
                    // Set next page to 1 for initial loading
                    favoritesContainer.getContentContainers().get(0).setExtraValue(ExtraKeys.NEXT_PAGE, 1);
                    loadFavoritesVideos(favoritesContainer);
                } else {
                    loadLocalFavoritesVideos(favoritesContainer);
                }
            }
        }
    }
    // contentActionList.add(new Action()
    // .setId(CONTENT_ACTION_SUBSCRIPTION)
    // .setLabel1(mAppContext.getResources()
    // .getString(R.string.premium_1))
    // .setLabel2(mAppContext.getResources()
    // .getString(R.string.premium_2)));
    // 
    // contentActionList.add(new Action()
    // .setId(CONTENT_ACTION_DAILY_PASS)
    // .setLabel1(mAppContext.getResources()
    // .getString(R.string.daily_pass_1))
    // .setLabel2(mAppContext.getResources()
    // .getString(R.string.daily_pass_2)));
    contentActionList.addAll(mGlobalContentActionList);
    if (content.hasTrailer()) {
        contentActionList.add(createActionButton(CONTENT_PLAY_TRAILER, R.string.action_play_trailer_1, R.string.action_play_trailer_2));
    }
    return contentActionList;
}
Also used : Action(com.amazon.android.model.Action) ArrayList(java.util.ArrayList) ContentContainer(com.amazon.android.model.content.ContentContainer) RecentRecord(com.amazon.android.contentbrowser.database.records.RecentRecord)

Example 4 with ContentContainer

use of com.amazon.android.model.content.ContentContainer 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 5 with ContentContainer

use of com.amazon.android.model.content.ContentContainer 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)

Aggregations

ContentContainer (com.amazon.android.model.content.ContentContainer)60 Content (com.amazon.android.model.content.Content)29 ListRow (androidx.leanback.widget.ListRow)13 ArrayObjectAdapter (androidx.leanback.widget.ArrayObjectAdapter)11 Recipe (com.amazon.android.recipe.Recipe)11 Gson (com.google.gson.Gson)11 Intent (android.content.Intent)10 GsonBuilder (com.google.gson.GsonBuilder)10 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)9 HashMap (java.util.HashMap)8 ZypeDataDownloaderHelper (com.amazon.dataloader.datadownloader.ZypeDataDownloaderHelper)7 Context (android.content.Context)6 TextUtils (android.text.TextUtils)6 Action (com.amazon.android.model.Action)6 PlaylistAction (com.amazon.android.model.PlaylistAction)6 NavigatorModel (com.amazon.android.navigator.NavigatorModel)6 CardPresenter (com.amazon.android.tv.tenfoot.presenter.CardPresenter)6 Subscription (rx.Subscription)6 Pair (android.util.Pair)5