Search in sources :

Example 1 with DownloadEntry

use of org.edx.mobile.model.db.DownloadEntry in project edx-app-android by edx.

the class CourseUnitVideoFragment method onPlaybackComplete.

public void onPlaybackComplete() {
    try {
        DownloadEntry v = videoModel;
        if (v != null && v.watched == DownloadEntry.WatchedState.PARTIALLY_WATCHED) {
            videoModel.watched = DownloadEntry.WatchedState.WATCHED;
            // mark this as partially watches, as playing has started
            DatabaseFactory.getInstance(DatabaseFactory.TYPE_DATABASE_NATIVE).updateVideoWatchedState(v.videoId, DownloadEntry.WatchedState.WATCHED, watchedStateCallback);
        }
    } catch (Exception ex) {
        logger.error(ex);
    }
}
Also used : DownloadEntry(org.edx.mobile.model.db.DownloadEntry)

Example 2 with DownloadEntry

use of org.edx.mobile.model.db.DownloadEntry in project edx-app-android by edx.

the class CourseUnitVideoFragment method getVideoPath.

private String getVideoPath(DownloadEntry video) {
    String filepath = null;
    if (video.filepath != null && video.filepath.length() > 0) {
        if (video.isDownloaded()) {
            File f = new File(video.filepath);
            if (f.exists()) {
                // play from local
                filepath = video.filepath;
                logger.debug("playing from local file");
            }
        }
    } else {
        DownloadEntry de = (DownloadEntry) DatabaseFactory.getInstance(DatabaseFactory.TYPE_DATABASE_NATIVE).getIVideoModelByVideoUrl(video.url, null);
        if (de != null) {
            if (de.filepath != null) {
                File f = new File(de.filepath);
                if (f.exists()) {
                    // play from local
                    filepath = de.filepath;
                    logger.debug("playing from local file for " + "another Download Entry");
                }
            }
        }
    }
    if (TextUtils.isEmpty(filepath)) {
        // not available on local, so play online
        logger.warn("Local file path not available");
        filepath = video.getBestEncodingUrl(getActivity());
    }
    return filepath;
}
Also used : File(java.io.File) DownloadEntry(org.edx.mobile.model.db.DownloadEntry)

Example 3 with DownloadEntry

use of org.edx.mobile.model.db.DownloadEntry in project edx-app-android by edx.

the class DbTests method testupdateDownloadingVideoInfoByVideoId.

@Test
public void testupdateDownloadingVideoInfoByVideoId() throws Exception {
    db.clearDataByUser(username);
    DownloadEntry model = getDummyVideoModel();
    db.updateDownloadingVideoInfoByVideoId(model, new DataCallback<Integer>() {

        @Override
        public void onResult(Integer result) {
            assertNotNull(result);
            assertTrue(result == 0);
            print("Result for update Downloading Video Info By VideoId for 0= " + result);
            unlock();
        }

        @Override
        public void onFail(Exception ex) {
            fail(ex.getMessage());
        }
    });
    lock();
    DownloadEntry de = getDummyVideoModel();
    de.downloaded = DownloadedState.DOWNLOADING;
    de.id = 1;
    db.addVideoData(de, null);
    db.updateDownloadingVideoInfoByVideoId(de, new DataCallback<Integer>() {

        @Override
        public void onResult(Integer result) {
            assertNotNull(result);
            assertTrue(result == 1);
            print("Result for update Downloading Video Info By VideoId for 1= " + result);
            unlock();
        }

        @Override
        public void onFail(Exception ex) {
            fail(ex.getMessage());
        }
    });
    lock();
}
Also used : DownloadEntry(org.edx.mobile.model.db.DownloadEntry) Test(org.junit.Test)

Example 4 with DownloadEntry

use of org.edx.mobile.model.db.DownloadEntry in project edx-app-android by edx.

the class DbTests method testisDmIdExists.

@Test
public void testisDmIdExists() throws Exception {
    db.clearDataByUser(username);
    final long dmId = 1;
    db.isDmIdExists(dmId, new DataCallback<Boolean>() {

        @Override
        public void onResult(Boolean result) {
            assertNotNull(result);
            assertFalse("DmId should not be present for " + dmId, result);
            unlock();
        }

        @Override
        public void onFail(Exception ex) {
            fail(ex.getMessage());
        }
    });
    lock();
    DownloadEntry de = getDummyVideoModel();
    de.dmId = 1;
    db.addVideoData(de, null);
    db.isDmIdExists(dmId, new DataCallback<Boolean>() {

        @Override
        public void onResult(Boolean result) {
            assertNotNull(result);
            assertTrue("DmId  should be present for " + dmId, result);
            unlock();
        }

        @Override
        public void onFail(Exception ex) {
            fail(ex.getMessage());
        }
    });
    lock();
}
Also used : DownloadEntry(org.edx.mobile.model.db.DownloadEntry) Test(org.junit.Test)

Example 5 with DownloadEntry

use of org.edx.mobile.model.db.DownloadEntry in project edx-app-android by edx.

the class DbTests method testupdateVideosActivatedForCourse.

@Test
public void testupdateVideosActivatedForCourse() throws Exception {
    db.clearDataByUser(username);
    String enrollmentId = "enrollmentId";
    db.updateVideosActivatedForCourse(enrollmentId, new DataCallback<Integer>() {

        @Override
        public void onResult(Integer result) {
            assertNotNull(result);
            assertTrue(result == 0);
            // assertFalse("something is downloading", result);
            print("Result for update Videos Activated For Course is:" + result.intValue());
            unlock();
        }

        @Override
        public void onFail(Exception ex) {
            fail(ex.getMessage());
        }
    });
    lock();
    DownloadEntry de = getDummyVideoModel();
    de.eid = "enrollmentId";
    db.addVideoData(de, null);
    db.updateVideosActivatedForCourse(enrollmentId, new DataCallback<Integer>() {

        @Override
        public void onResult(Integer result) {
            assertNotNull(result);
            assertTrue(result == 1);
            // assertFalse("something is downloading", result);
            print("Result for update Videos Activated For Course is:" + result.intValue());
            unlock();
        }

        @Override
        public void onFail(Exception ex) {
            fail(ex.getMessage());
        }
    });
    lock();
}
Also used : DownloadEntry(org.edx.mobile.model.db.DownloadEntry) Test(org.junit.Test)

Aggregations

DownloadEntry (org.edx.mobile.model.db.DownloadEntry)50 Test (org.junit.Test)36 VideoModel (org.edx.mobile.model.VideoModel)10 List (java.util.List)6 HasDownloadEntry (org.edx.mobile.model.course.HasDownloadEntry)4 CourseComponent (org.edx.mobile.model.course.CourseComponent)2 DiscussionBlockModel (org.edx.mobile.model.course.DiscussionBlockModel)2 VideoBlockModel (org.edx.mobile.model.course.VideoBlockModel)2 WatchedState (org.edx.mobile.model.db.DownloadEntry.WatchedState)2 BulkVideosDownloadCancelledEvent (org.edx.mobile.module.storage.BulkVideosDownloadCancelledEvent)2 MenuItem (android.view.MenuItem)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 BaseFragmentActivity (org.edx.mobile.base.BaseFragmentActivity)1 BaseVideosDownloadStateActivity (org.edx.mobile.base.BaseVideosDownloadStateActivity)1 BlockPath (org.edx.mobile.model.course.BlockPath)1 IBlock (org.edx.mobile.model.course.IBlock)1 VideoInfo (org.edx.mobile.model.course.VideoInfo)1 DownloadedState (org.edx.mobile.model.db.DownloadEntry.DownloadedState)1