Search in sources :

Example 6 with Content

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

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

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

the class ContentLoader method getContentsObservable.

/**
 * Get contents observable.
 *
 * @param observable                     Rx Observable chain to continue on.
 * @param dataLoaderRecipeForContents    Data loader recipe for getting contents.
 * @param dynamicParserRecipeForContents Dynamic parser  recipe for getting contents.
 * @return RX Observable.
 */
private Observable<Object> getContentsObservable(Observable<Object> observable, Recipe dataLoaderRecipeForContents, Recipe dynamicParserRecipeForContents) {
    Map<String, Content> parsedContent = new HashMap();
    return observable.concatMap(contentContainerAsObject -> {
        ContentContainer contentContainer = (ContentContainer) contentContainerAsObject;
        if (DEBUG_RECIPE_CHAIN) {
            Log.d(TAG, "ContentContainer:" + contentContainer.getName());
        }
        return mDataLoadManager.cookRecipeObservable(dataLoaderRecipeForContents, null, null, null).map(feedDataForContent -> {
            if (DEBUG_RECIPE_CHAIN) {
                Log.d(TAG, "Feed for container complete");
            }
            return Pair.create(contentContainerAsObject, feedDataForContent);
        });
    }).concatMap(objectPair -> {
        ContentContainer contentContainer = (ContentContainer) objectPair.first;
        /* Zype, Evgeny Cherkasov */
        // Clear content list to avoid duplicate contents for nested playlist (subcategory)
        contentContainer.getContents().clear();
        String feed = (String) objectPair.second;
        String[] params = new String[] { (String) contentContainer.getExtraStringValue(Recipe.KEY_DATA_TYPE_TAG) };
        return mDynamicParser.cookRecipeObservable(dynamicParserRecipeForContents, feed, null, params).map(contentAsObject -> {
            if (DEBUG_RECIPE_CHAIN) {
                Log.d(TAG, "Parser got an content");
            }
            Content content = (Content) contentAsObject;
            if (content != null) {
                // Add information of free content available with container
                if (contentContainer.getExtraStringValue(Recipe.CONTENT_TYPE_TAG) != null) {
                    content.setExtraValue(Recipe.CONTENT_TYPE_TAG, contentContainer.getExtraStringValue(Recipe.CONTENT_TYPE_TAG));
                }
                /* Zype, Evgeny Cherkasov */
                if (ZypeConfiguration.displayWatchedBarOnVideoThumbnails()) {
                    content.setExtraValue(Content.EXTRA_PLAYBACK_POSITION_PERCENTAGE, getContentPlaybackPositionPercentage(content));
                }
                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) HashMap(java.util.HashMap) Content(com.amazon.android.model.content.Content) ContentContainer(com.amazon.android.model.content.ContentContainer)

Example 9 with Content

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

the class FavoritesManager method addVideoToFavoritesContentContainer.

// //////////
// 
// 
public void addVideoToFavoritesContentContainer(Content content) {
    ContentContainer favoritesContainer = contentLoader.getRootContentContainer().findContentContainerById(ZypeSettings.FAVORITES_PLAYLIST_ID);
    if (favoritesContainer != null) {
        Gson gson = new Gson();
        String jsonFavoriteVideo = gson.toJson(content);
        Content favoriteVideo = gson.fromJson(jsonFavoriteVideo, content.getClass());
        favoriteVideo.setExtraValue(Content.EXTRA_PLAYLIST_ID, ZypeSettings.FAVORITES_PLAYLIST_ID);
        favoritesContainer.getContents().add(0, favoriteVideo);
    }
}
Also used : Content(com.amazon.android.model.content.Content) ContentContainer(com.amazon.android.model.content.ContentContainer) Gson(com.google.gson.Gson)

Example 10 with Content

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

the class FavoritesManager method removeVideoFromFavoritesContentContainer.

public void removeVideoFromFavoritesContentContainer(Content content) {
    ContentContainer favoritesContainer = contentLoader.getRootContentContainer().findContentContainerById(ZypeSettings.FAVORITES_PLAYLIST_ID);
    if (favoritesContainer != null) {
        Content favoriteVideo = favoritesContainer.findContentById(content.getId());
        if (favoriteVideo == null) {
            return;
        }
        favoritesContainer.getContents().remove(favoriteVideo);
    }
}
Also used : 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