use of com.amazon.android.model.content.Content in project zype-firebuilder by zype.
the class ZypeSearchManager method getSearchContentsObservable.
private Observable<Object> getSearchContentsObservable(String feed, ISearchResult iSearchResult) {
DynamicParser parser = new DynamicParser();
ZypeContentTranslator zypeContentTranslator = new ZypeContentTranslator();
parser.addTranslatorImpl(zypeContentTranslator.getName(), zypeContentTranslator);
String[] params = new String[] { (String) "" };
return parser.cookRecipeObservable(recipeSearchContents, feed, null, params).map(contentAsObject -> {
Content content = (Content) contentAsObject;
if (content != null) {
iSearchResult.onSearchResult(content, false);
}
return content;
});
}
use of com.amazon.android.model.content.Content in project zype-firebuilder by zype.
the class ContentLoader method loadContentForContentContainer.
// TODO: Move 'loadPlaylistVideos()' from 'ContentBrowser' to here,
// - update definition of 'loadPlaylistVideos' to use listener
// - update all calls of 'loadPlaylistVideos' with listeners instead of listening to broadcast receivers
// for updating content with result of this function
// - replace all calls of 'loadContentForContentContainer' function with 'loadPlaylistVideos'
public void loadContentForContentContainer(ContentContainer contentContainer, Context context, ILoadContentForContentContainer callback) {
// NavigatorModel.GlobalRecipes recipe = mNavigator.getNavigatorModel().getGlobalRecipes().get(0);
// Recipe dataLoaderRecipeForContents = recipe.getContents().dataLoaderRecipe;
// Recipe dynamicParserRecipeForContents = recipe.getContents().dynamicParserRecipe;
//
HashMap<String, String> params = new HashMap<>();
params.put(ZypeApi.APP_KEY, ZypeSettings.APP_KEY);
params.put(ZypeApi.PER_PAGE, String.valueOf(ZypeApi.PER_PAGE_DEFAULT));
ZypeApi.getInstance().getApi().getPlaylistVideos(contentContainer.getExtraStringValue(Recipe.KEY_DATA_TYPE_TAG), 1, params).enqueue(new Callback<VideosResponse>() {
@Override
public void onResponse(Call<VideosResponse> call, Response<VideosResponse> response) {
if (response.isSuccessful()) {
if (response.body().pagination.current == response.body().pagination.pages) {
contentContainer.setExtraValue(ExtraKeys.NEXT_PAGE, -1);
} else {
contentContainer.setExtraValue(ExtraKeys.NEXT_PAGE, response.body().pagination.next);
}
if (!response.body().videoData.isEmpty()) {
Log.d(TAG, "loadContentForContentContainer(): onResponse(): size=" + response.body().videoData.size());
for (VideoData videoData : response.body().videoData) {
if (TextUtils.isEmpty(videoData.description) || videoData.description.equals("null")) {
videoData.description = " ";
}
videoData.playlistId = (String) contentContainer.getExtraStringValue(Recipe.KEY_DATA_TYPE_TAG);
videoData.playerUrl = "null";
}
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
String feed = gson.toJson(response.body().videoData);
// TODO: Rename the recipe file
Recipe recipe = Recipe.newInstance(context, "recipes/ZypeSearchContentsRecipe.json");
Subscription subscription = getContentsForContentContainerObservable(feed, recipe, contentContainer).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribe(result -> {
}, throwable -> {
if (contentContainer.getContentCount() > 0) {
callback.onContentsLoaded();
}
}, () -> {
callback.onContentsLoaded();
});
// mCompositeSubscription.add(subscription);
}
} else {
// TODO: Handle error
}
}
@Override
public void onFailure(Call<VideosResponse> call, Throwable t) {
// TODO: Handle exception
}
});
}
use of com.amazon.android.model.content.Content in project zype-firebuilder by zype.
the class RecommendationSender method buildRecommendation.
/**
* Builds the recommendation.
*
* @param contentId The content id.
* @param recommendationId The recommendation id.
* @param group The recommendation type.
* @return The recommendation.
*/
Notification buildRecommendation(String contentId, int recommendationId, String group) {
Content content = getContentFromRoot(contentId);
if (content == null) {
Log.e(TAG, "Could not build recommendation for content with id " + contentId + " " + "because content not found");
return null;
}
// Try getting the content's playback progress (if it exists)
int playbackProgress = 0;
long lastWatchedDateTime = 0;
RecentDatabaseHelper database = RecentDatabaseHelper.getInstance();
if (database != null) {
if (database.recordExists(mContext, contentId)) {
// Need to get recent db from content browser. Maybe shoudl do that for all instead of passing?
RecentRecord record = database.getRecord(mContext, contentId);
playbackProgress = (int) record.getPlaybackLocation();
lastWatchedDateTime = record.getLastWatched();
}
} else {
Log.e(TAG, "Could not get recent playback progress for content because database is " + "null");
}
// Create the recommendation builder.
RecommendationBuilder builder = new RecommendationBuilder().setContext(mContext);
Log.d(TAG, "Built recommendation - " + content.getTitle());
try {
int live = content.getExtraValueAsBoolean(Content.LIVE_TAG) ? 1 : 0;
List genres = content.getExtraValueAsList(Content.GENRES_TAG);
List contentType = content.getExtraValueAsList(Content.CONTENT_TYPE_TAG);
ArrayList<Integer> actions = (ArrayList<Integer>) content.getExtraValueAsList(Content.RECOMMENDATION_ACTIONS_TAG);
ArrayList<String> contentCategories = (ArrayList<String>) content.getExtraValueAsList(Content.FIRE_TV_CATEGORIES_TAG);
return builder.setBackgroundUrl(content.getBackgroundImageUrl()).setRecommendationId(recommendationId).setTitle(content.getTitle()).setText(content.getDescription()).setLargeIconUrl(content.getCardImageUrl()).setContentIntent(buildContentIntent(mContext, content.getId())).setDismissIntent(buildDismissIntent(mContext, recommendationId)).setContentDuration(content.getDuration()).setMaturityRating(String.valueOf(content.getExtraValue(Content.MATURITY_RATING_TAG))).setContentId(content.getId()).setContentCategories(contentCategories).setDescription(content.getDescription()).setRank(// highest priority
0).setLiveContent(live).setContentStartTime(content.getExtraValueAsLong(Content.START_TIME_TAG)).setContentEndTime(content.getExtraValueAsLong(Content.END_TIME_TAG)).setContentReleaseDate(String.valueOf(content.getAvailableDate())).setContentClosedCaptions(content.hasCloseCaption() ? 1 : 0).setGroup(group).setContentCustomerRating(content.getExtraValueAsInt(Content.CUSTOMER_RATING_TAG)).setContentCustomerRatingCount(content.getExtraValueAsInt(Content.CUSTOMER_RATING_COUNT_TAG)).setPreviewVideoUrl(String.valueOf(content.getExtraValue(Content.VIDEO_PREVIEW_URL_TAG))).setImdbId(String.valueOf(content.getExtraValue(Content.IMDB_ID_TAG))).setPlaybackProgress(playbackProgress).setGenres((String[]) genres.toArray(new String[genres.size()])).setContentTypes((String[]) contentType.toArray(new String[contentType.size()])).setActions(actions).setLastWatchedDateTime(lastWatchedDateTime).build();
} catch (Exception e) {
Log.e(TAG, "Unable to build recommendation", e);
}
return null;
}
use of com.amazon.android.model.content.Content in project zype-firebuilder by zype.
the class ContentTranslatorTest method testValidateModelFalseCardImageUrl.
/**
* Tests the {@link ContentTranslator#validateModel(Content)} method for the false case where
* the cardImageUrl is invalid.
*/
@Test
public void testValidateModelFalseCardImageUrl() throws Exception {
Content content = createValidContent();
// make good content bad
content.setCardImageUrl("");
assertFalse(mContentTranslator.validateModel(content));
}
use of com.amazon.android.model.content.Content in project zype-firebuilder by zype.
the class ContentTranslatorTest method testMapToModel.
/**
* Tests the {@link ContentTranslator#mapToModel(Map, Recipe)} with valid map and recipe
* arguments.
*/
@Test
public void testMapToModel() throws Exception {
Content expected = createValidContent();
Content result = mContentTranslator.mapToModel(createValidMap(), mGoodRecipe);
assertEquals(expected, result);
}
Aggregations