Search in sources :

Example 6 with RecentRecord

use of com.amazon.android.contentbrowser.database.records.RecentRecord 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");
    }
}
Also used : RecentDatabaseHelper(com.amazon.android.contentbrowser.database.helpers.RecentDatabaseHelper) RecentRecord(com.amazon.android.contentbrowser.database.records.RecentRecord)

Example 7 with RecentRecord

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

the class ContentBrowser 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 8 with RecentRecord

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

the class ContentBrowser method getRecentContent.

/**
 * Get a list of contents to display in the "Continue Watching" row that have been watched for
 * more than the grace period value located in the custom.xml as recent_grace_period.
 *
 * @return A list of contents.
 */
public List<Content> getRecentContent() {
    List<Content> contentList = new ArrayList<>();
    RecentDatabaseHelper databaseHelper = RecentDatabaseHelper.getInstance();
    if (databaseHelper != null) {
        List<RecentRecord> records = databaseHelper.getUnfinishedRecords(mAppContext, mAppContext.getResources().getInteger(R.integer.recent_grace_period));
        for (RecentRecord record : records) {
            Content content = mContentLoader.getRootContentContainer().findContentById(record.getContentId());
            if (content != null) {
                contentList.add(content);
            }
        }
    }
    return contentList;
}
Also used : RecentDatabaseHelper(com.amazon.android.contentbrowser.database.helpers.RecentDatabaseHelper) Content(com.amazon.android.model.content.Content) ArrayList(java.util.ArrayList) RecentRecord(com.amazon.android.contentbrowser.database.records.RecentRecord)

Example 9 with RecentRecord

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

the class ContentBrowser 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(mAppContext, content.getId())) {
            record = databaseHelper.getRecord(mAppContext, 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 10 with RecentRecord

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

the class RecentDatabaseHelperTest method testGetRecord.

/**
 * Tests reading recent records from the database.
 */
@Test
public void testGetRecord() throws Exception {
    RecentDatabaseHelper recentDatabaseHelper = RecentDatabaseHelper.getInstance();
    assertNotNull(recentDatabaseHelper);
    Context context = InstrumentationRegistry.getContext();
    long currentTime = DateAndTimeHelper.getCurrentDate().getTime();
    RecentRecord expectedContentId1 = new RecentRecord("ContentId1", 10, false, currentTime, 20);
    RecentRecord expectedContentId2 = new RecentRecord("ContentId2", 123456789, true, currentTime, 987654321);
    recentDatabaseHelper.addRecord(context, "ContentId1", 10, false, currentTime, 20);
    recentDatabaseHelper.addRecord(context, "ContentId2", 123456789, true, currentTime, 987654321);
    RecentRecord actualContentId1 = recentDatabaseHelper.getRecord(context, "ContentId1");
    assertTrue("The retrieved content should have matched.", actualContentId1.equals(expectedContentId1));
    RecentRecord actualContentId2 = recentDatabaseHelper.getRecord(context, "ContentId2");
    assertTrue("The retrieved content should have matched.", actualContentId2.equals(expectedContentId2));
    recentDatabaseHelper.getDatabase(context).close();
}
Also used : Context(android.content.Context) RecentRecord(com.amazon.android.contentbrowser.database.records.RecentRecord) Test(org.junit.Test)

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