use of com.amazon.android.contentbrowser.database.helpers.RecentDatabaseHelper 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;
}
use of com.amazon.android.contentbrowser.database.helpers.RecentDatabaseHelper 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.contentbrowser.database.helpers.RecentDatabaseHelper in project zype-firebuilder by zype.
the class PlaybackActivity method storeContentPlaybackState.
/**
* Store the current playback state of the selected content to the database. Calculates if
* playback was finished or not using the {@link ContentBrowser#GRACE_TIME_MS}.
* If the content playback is finished, recommendation manager will dismiss the recommendation
* for this content (if it exists).
*/
private void storeContentPlaybackState() {
// Calculate if the content has finished playing
boolean isFinished = (mPlayer.getDuration() - ContentBrowser.GRACE_TIME_MS) <= mPlayer.getCurrentPosition();
RecommendationDatabaseHelper recommendationDatabaseHelper = RecommendationDatabaseHelper.getInstance();
// Dismiss the recommendation notification for this content if the content is finished.
if (isFinished && recommendationDatabaseHelper != null) {
if (recommendationDatabaseHelper.recordExists(getApplicationContext(), mSelectedContent.getId())) {
ContentBrowser.getInstance(this).getRecommendationManager().dismissRecommendation(mSelectedContent.getId());
AnalyticsHelper.trackDismissRecommendationForCompleteContent(mSelectedContent);
}
}
// Save the recently played content to database
RecentDatabaseHelper recentDatabaseHelper = RecentDatabaseHelper.getInstance();
if (recentDatabaseHelper != null && !isContentLive(mSelectedContent)) {
recentDatabaseHelper.addRecord(getApplicationContext(), mSelectedContent.getId(), mPlayer.getCurrentPosition(), isFinished, DateAndTimeHelper.getCurrentDate().getTime(), mPlayer.getDuration());
if (ZypeConfiguration.displayWatchedBarOnVideoThumbnails()) {
EventBus.getDefault().post(new ContentUpdateEvent(mSelectedContent.getId()));
}
Log.d(TAG, "storeContentPlaybackState(): saved position " + mPlayer.getCurrentPosition());
} else {
Log.e(TAG, "Cannot update recent content playback state. Database is null");
}
}
use of com.amazon.android.contentbrowser.database.helpers.RecentDatabaseHelper in project zype-firebuilder by zype.
the class PlaybackActivity method loadContentPlaybackState.
/**
* Uses the {@link RecentDatabaseHelper} to check the database for a stored playback state
* of the current selected content. If the state exists and playback is not complete,
* it loads the content's current playback position.
*/
private void loadContentPlaybackState() {
RecentDatabaseHelper database = RecentDatabaseHelper.getInstance();
if (database != null) {
// Check database for content's previously watched position.
if (database.recordExists(getApplicationContext(), mSelectedContent.getId())) {
RecentRecord record = database.getRecord(getApplicationContext(), mSelectedContent.getId());
// exists for this content and playback is not complete.
if (record != null && !record.isPlaybackComplete()) {
mCurrentPlaybackPosition = record.getPlaybackLocation();
Log.d(TAG, "loadContentPlaybackState(): restored position " + mCurrentPlaybackPosition);
}
}
} else {
Log.e(TAG, "Unable to load content playback state because database is null");
}
}
use of com.amazon.android.contentbrowser.database.helpers.RecentDatabaseHelper in project zype-firebuilder by zype.
the class ContentBrowser method switchToRendererScreen.
/**
* Switch to renderer screen.
*
* @param content Content.
* @param actionId Action id.
*/
public void switchToRendererScreen(Content content, int actionId) {
switchToScreen(ContentBrowser.CONTENT_RENDERER_SCREEN, content, intent -> {
intent.putExtra(Content.class.getSimpleName(), content);
// Reset saved seek position if watching content from beginning.
if (actionId == CONTENT_ACTION_WATCH_FROM_BEGINNING) {
RecentDatabaseHelper databaseHelper = RecentDatabaseHelper.getInstance();
if (databaseHelper == null) {
Log.e(TAG, "Error retrieving database. Recent not saved.");
return;
}
databaseHelper.addRecord(mAppContext, content.getId(), 0, false, DateAndTimeHelper.getCurrentDate().getTime(), content.getDuration());
}
});
}
Aggregations