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