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