Search in sources :

Example 1 with Data

use of com.amazon.utils.model.Data 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 2 with Data

use of com.amazon.utils.model.Data in project zype-firebuilder by zype.

the class CacheManagerAdapter method loadData.

/**
 * {@inheritDoc}
 *
 * Loads the data from the cache and returns it via the {@link com.amazon.dataloader
 * .datadownloader.IDataLoader.IDataLoadRequestHandler}. A null value is returned if the key is
 * not present in the cache. Any exception received is communicated via
 * {@link com.amazon.dataloader.datadownloader.IDataLoader.IDataLoadRequestHandler#onFailure
 * (Recipe, String[], Throwable)}.
 */
@Override
public boolean loadData(Recipe dataLoadRecipe, String[] params, IDataLoadRequestHandler requestHandle) {
    try {
        String key = generateKey(dataLoadRecipe, params);
        Data data = mCacheManager.get(key);
        requestHandle.onSuccess(dataLoadRecipe, params, data);
        return true;
    } catch (Exception e) {
        requestHandle.onFailure(dataLoadRecipe, params, e);
        return false;
    }
}
Also used : Data(com.amazon.utils.model.Data) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 3 with Data

use of com.amazon.utils.model.Data in project zype-firebuilder by zype.

the class DataLoadManagerTest method createSuccessfulCookedRecipe.

/**
 * Creates a recipe callback handler that expects a successful response with mock data. It
 * fails the test if its {@link IRecipeCookerCallbacks#onRecipeError(Recipe, Exception,
 * String)}
 * method is called
 *
 * @return A recipe callback handler which expects successful response with mock data.
 */
private IRecipeCookerCallbacks createSuccessfulCookedRecipe() {
    return new IRecipeCookerCallbacks() {

        @Override
        public void onPreRecipeCook(Recipe recipe, Object output, Bundle bundle) {
        }

        @Override
        public void onRecipeCooked(Recipe recipe, Object output, Bundle bundle, boolean done) {
            Data data = (Data) output;
            assertTrue(mData.equals(data));
            assertTrue(done);
            verifyUtil.verified();
        }

        @Override
        public void onPostRecipeCooked(Recipe recipe, Object output, Bundle bundle) {
        }

        @Override
        public void onRecipeError(Recipe recipe, Exception e, String msg) {
            Log.e("Test failed", msg, e);
            fail(e.getMessage());
        }
    };
}
Also used : IRecipeCookerCallbacks(com.amazon.android.recipe.IRecipeCookerCallbacks) Recipe(com.amazon.android.recipe.Recipe) Bundle(android.os.Bundle) Data(com.amazon.utils.model.Data) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 4 with Data

use of com.amazon.utils.model.Data in project zype-firebuilder by zype.

the class DataUpdaterModuleTest method testNonScheduledDataUpdater.

/**
 * Tests non-scheduled data updater, verifying that DataUpdaterTask is not executed by
 * Scheduler
 */
@Test
public void testNonScheduledDataUpdater() throws Exception {
    MockDataLoadManager testDataLoadManagerNoUpdater = new MockDataLoadManagerWithoutDataUpdater(InstrumentationRegistry.getTargetContext());
    testDataLoadManagerNoUpdater.registerUpdateListener(mUpdateListener);
    Thread.sleep(5000);
    verify(MockCacheManagerAdapter.mockCacheManagerAdapter, never()).clearCache();
    verify(mUpdateListener, never()).onSuccess(any(Data.class));
}
Also used : MockDataLoadManagerWithoutDataUpdater(com.amazon.dataloader.testResources.MockDataLoadManagerWithoutDataUpdater) MockDataLoadManager(com.amazon.dataloader.testResources.MockDataLoadManager) Data(com.amazon.utils.model.Data) Test(org.junit.Test)

Example 5 with Data

use of com.amazon.utils.model.Data in project zype-firebuilder by zype.

the class BasicFileBasedDataDownloaderTest method createSuccessfulDataLoadHandler.

/**
 * Creates a sample {@link com.amazon.dataloader.datadownloader.IDataLoader
 * .IDataLoadRequestHandler} for successful requests.
 *
 * @return A successful instance of {@link com.amazon.dataloader.datadownloader.IDataLoader
 * .IDataLoadRequestHandler}
 */
private IDataLoader.IDataLoadRequestHandler createSuccessfulDataLoadHandler() {
    // The expected Data from the call to match with actual data received from the call
    final Data expectedData;
    try {
        expectedData = Data.createDataForPayload(FileHelper.readFile(context, "SampleData.json"));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return new IDataLoader.IDataLoadRequestHandler() {

        @Override
        public void onSuccess(Recipe dataLoadRecipe, String[] params, Data data) {
            assertEquals(expectedData, data);
            verifyUtil.verified();
        }

        @Override
        public void onFailure(Recipe dataLoadRecipe, String[] params, Throwable throwable) {
            Log.e("Test failed", throwable.getMessage(), throwable);
            fail(throwable.getMessage());
        }
    };
}
Also used : Recipe(com.amazon.android.recipe.Recipe) Data(com.amazon.utils.model.Data) IOException(java.io.IOException)

Aggregations

Data (com.amazon.utils.model.Data)8 Recipe (com.amazon.android.recipe.Recipe)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 Context (android.content.Context)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 TextUtils (android.text.TextUtils)1 Log (android.util.Log)1 Pair (android.util.Pair)1 LocalBroadcastManager (androidx.localbroadcastmanager.content.LocalBroadcastManager)1 BROADCAST_DATA_LOADED (com.amazon.android.contentbrowser.ContentBrowser.BROADCAST_DATA_LOADED)1 BROADCAST_VIDEO_DETAIL_DATA_LOADED (com.amazon.android.contentbrowser.ContentBrowser.BROADCAST_VIDEO_DETAIL_DATA_LOADED)1 RecentDatabaseHelper (com.amazon.android.contentbrowser.database.helpers.RecentDatabaseHelper)1 VideoFavoritesHelper (com.amazon.android.contentbrowser.database.helpers.VideoFavoritesHelper)1 RecentRecord (com.amazon.android.contentbrowser.database.records.RecentRecord)1 Content (com.amazon.android.model.content.Content)1 ContentContainer (com.amazon.android.model.content.ContentContainer)1 ExtraKeys (com.amazon.android.model.content.constants.ExtraKeys)1 ContentContainerTranslator (com.amazon.android.model.translators.ContentContainerTranslator)1 ContentTranslator (com.amazon.android.model.translators.ContentTranslator)1