Search in sources :

Example 1 with RecentRecord

use of com.amazon.android.contentbrowser.database.records.RecentRecord 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;
}
Also used : Action(com.amazon.android.model.Action) ArrayList(java.util.ArrayList) ContentContainer(com.amazon.android.model.content.ContentContainer) RecentRecord(com.amazon.android.contentbrowser.database.records.RecentRecord)

Example 2 with RecentRecord

use of com.amazon.android.contentbrowser.database.records.RecentRecord in project zype-firebuilder by zype.

the class ContentBrowser method getContentTimeRemaining.

/**
 * Get content time remaining
 *
 * @param content Content.
 * @return Time remaining in ms.
 */
public long getContentTimeRemaining(Content content) {
    RecentRecord record = getRecentRecord(content);
    if (record != null && !record.isPlaybackComplete()) {
        // Calculate time remaining as duration minus playback location
        long duration = record.getDuration();
        long currentPlaybackPosition = record.getPlaybackLocation();
        if ((duration > 0) && (currentPlaybackPosition > 0) && (duration > currentPlaybackPosition)) {
            return (duration - currentPlaybackPosition);
        }
    }
    return 0;
}
Also used : RecentRecord(com.amazon.android.contentbrowser.database.records.RecentRecord)

Example 3 with RecentRecord

use of com.amazon.android.contentbrowser.database.records.RecentRecord in project zype-firebuilder by zype.

the class ContentLoader method getContentPlaybackPositionPercentage.

/**
 * Get content playback position percentage for progress bar.
 *
 * @param content Content.
 * @return Percentage playback complete.
 */
public double getContentPlaybackPositionPercentage(Content content) {
    RecentRecord record = getRecentRecord(content);
    // over the entire video duration
    if (record != null && !record.isPlaybackComplete()) {
        // Calculate time remaining as duration minus playback location
        long duration = record.getDuration();
        long currentPlaybackPosition = record.getPlaybackLocation();
        if ((duration > 0) && (currentPlaybackPosition > 0) && (duration > currentPlaybackPosition)) {
            return (((double) currentPlaybackPosition) / duration);
        }
    }
    return 0;
}
Also used : RecentRecord(com.amazon.android.contentbrowser.database.records.RecentRecord)

Example 4 with RecentRecord

use of com.amazon.android.contentbrowser.database.records.RecentRecord in project zype-firebuilder by zype.

the class ContentLoader method getRecentRecord.

/**
 * Get Recent Record from database based on content id
 *
 * @param content Content.
 * @return Recent Record.
 */
public RecentRecord getRecentRecord(Content content) {
    RecentRecord record = null;
    RecentDatabaseHelper databaseHelper = RecentDatabaseHelper.getInstance();
    if (databaseHelper != null) {
        if (databaseHelper.recordExists(mContext, content.getId())) {
            record = databaseHelper.getRecord(mContext, content.getId());
        }
    } else {
        Log.e(TAG, "Unable to load content because database is null");
    }
    return record;
}
Also used : RecentDatabaseHelper(com.amazon.android.contentbrowser.database.helpers.RecentDatabaseHelper) RecentRecord(com.amazon.android.contentbrowser.database.records.RecentRecord)

Example 5 with RecentRecord

use of com.amazon.android.contentbrowser.database.records.RecentRecord 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;
}
Also used : ArrayList(java.util.ArrayList) RecentRecord(com.amazon.android.contentbrowser.database.records.RecentRecord) RecentDatabaseHelper(com.amazon.android.contentbrowser.database.helpers.RecentDatabaseHelper) Content(com.amazon.android.model.content.Content) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

RecentRecord (com.amazon.android.contentbrowser.database.records.RecentRecord)12 RecentDatabaseHelper (com.amazon.android.contentbrowser.database.helpers.RecentDatabaseHelper)5 ArrayList (java.util.ArrayList)3 Content (com.amazon.android.model.content.Content)2 ContentValues (android.content.ContentValues)1 Context (android.content.Context)1 Action (com.amazon.android.model.Action)1 ContentContainer (com.amazon.android.model.content.ContentContainer)1 Date (java.util.Date)1 List (java.util.List)1 Test (org.junit.Test)1