Search in sources :

Example 16 with DownloadEntry

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

the class DbTests method testupdateAsDownloadingByVideoId.

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

        @Override
        public void onResult(Integer result) {
            assertNotNull(result);
            // assertTrue(result >= 0);
            assertTrue(result == 0);
            print("Result for update As Downloading ByVideoId is for size 0= " + result.toString());
            unlock();
        }

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

        @Override
        public void onResult(Integer result) {
            assertNotNull(result);
            // assertTrue(result >= 0);
            assertTrue(result == 1);
            print("Result for update As Downloading ByVideoId is= " + result.toString());
            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 17 with DownloadEntry

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

the class DbTests method testupdateAllVideosAsDeactivated.

@Test
public void testupdateAllVideosAsDeactivated() throws Exception {
    db.clearDataByUser(username);
    db.updateAllVideosAsDeactivated(new DataCallback<Integer>() {

        @Override
        public void onResult(Integer result) {
            assertNotNull(result);
            assertTrue(result == 0);
            // assertFalse("something is downloading", result);
            print("Result for update All Videos As Deactivated is" + result.toString());
            unlock();
        }

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

        @Override
        public void onResult(Integer result) {
            assertNotNull(result);
            assertTrue(result == 1);
            // assertFalse("something is downloading", result);
            print("Result for update All Videos As Deactivated is" + result.toString());
            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 18 with DownloadEntry

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

the class DbTests method testgetVideoCountBydmId.

@Test
public void testgetVideoCountBydmId() throws Exception {
    db.clearDataByUser(username);
    long dmId = 1;
    db.getVideoCountBydmId(dmId, new DataCallback<Integer>() {

        @Override
        public void onResult(Integer result) {
            assertNotNull(result);
            assertTrue(result == 0);
            // assertFalse("something is downloading", result);
            print("Video Count By dmId is:" + result.toString());
            unlock();
        }

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

        @Override
        public void onResult(Integer result) {
            assertNotNull(result);
            assertTrue(result == 1);
            // assertFalse("something is downloading", result);
            print("Video Count By dmId for result 1 is:" + result.toString());
            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 19 with DownloadEntry

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

the class BaseVideosDownloadStateActivityTest method downloadProgressViewTest.

/**
 * Testing download progress menu visibility states and click behaviour
 * (starting DownloadActivity). Only when both AppConstants.offline_flag
 * is true and there is a downloading entry in the database, should the
 * progress bar be visible.
 */
@Test
public void downloadProgressViewTest() {
    connectToNetwork();
    assertFalse(Shadows.shadowOf(Robolectric.buildActivity(getActivityClass()).withIntent(getIntent()).setup().get()).getOptionsMenu().findItem(R.id.download_progress).isVisible());
    disconnectFromNetwork();
    assertFalse(Shadows.shadowOf(Robolectric.buildActivity(getActivityClass()).withIntent(getIntent()).setup().get()).getOptionsMenu().findItem(R.id.download_progress).isVisible());
    IDatabase db = environment.getDatabase();
    DownloadEntry de = new DownloadEntry();
    de.username = "unittest";
    de.title = "title";
    de.videoId = "videoId-" + System.currentTimeMillis();
    de.size = 1024;
    de.duration = 3600;
    de.filepath = "/fakepath";
    de.url = "http://fake/url";
    de.eid = "fake_eid";
    de.chapter = "fake_chapter";
    de.section = "fake_section";
    de.lastPlayedOffset = 0;
    de.lmsUrl = "http://fake/lms/url";
    de.isCourseActive = 1;
    de.downloaded = DownloadEntry.DownloadedState.DOWNLOADING;
    Long rowId = db.addVideoData(de, null);
    assertNotNull(rowId);
    assertThat(rowId).isGreaterThan(0);
    assertFalse(Shadows.shadowOf(Robolectric.buildActivity(getActivityClass()).withIntent(getIntent()).setup().get()).getOptionsMenu().findItem(R.id.download_progress).isVisible());
    connectToNetwork();
    BaseVideosDownloadStateActivity activity = Robolectric.buildActivity(getActivityClass()).withIntent(getIntent()).setup().get();
    ShadowActivity shadowActivity = Shadows.shadowOf(activity);
    MenuItem downloadProgressMenuItem = shadowActivity.getOptionsMenu().findItem(R.id.download_progress);
    assertTrue(downloadProgressMenuItem.isVisible());
    assertTrue(downloadProgressMenuItem.getActionView().performClick());
    assertNextStartedActivity(activity, DownloadListActivity.class);
}
Also used : IDatabase(org.edx.mobile.module.db.IDatabase) BaseVideosDownloadStateActivity(org.edx.mobile.base.BaseVideosDownloadStateActivity) ShadowActivity(org.robolectric.shadows.ShadowActivity) MenuItem(android.view.MenuItem) DownloadEntry(org.edx.mobile.model.db.DownloadEntry) Test(org.junit.Test)

Example 20 with DownloadEntry

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

the class DownloadCompleteReceiver method handleDownloadCompleteIntent.

private void handleDownloadCompleteIntent(final Intent data) {
    if (data.hasExtra(DownloadManager.EXTRA_DOWNLOAD_ID)) {
        final long id = data.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
        if (id != -1) {
            AsyncTask.execute(new Runnable() {

                @Override
                public void run() {
                    logger.debug("Received download notification for id: " + id);
                    // check if download was SUCCESSFUL
                    NativeDownloadModel nm = environment.getDownloadManager().getDownload(id);
                    if (nm == null || nm.status != DownloadManager.STATUS_SUCCESSFUL) {
                        logger.debug("Download seems failed or cancelled for id : " + id);
                        environment.getDownloadManager().removeDownloads(id);
                        return;
                    } else {
                        logger.debug("Download successful for id : " + id);
                    }
                    // mark download as completed
                    environment.getStorage().markDownloadAsComplete(id, new DataCallback<VideoModel>() {

                        @Override
                        public void onResult(VideoModel result) {
                            if (result != null) {
                                DownloadEntry download = (DownloadEntry) result;
                                AnalyticsRegistry analyticsRegistry = environment.getAnalyticsRegistry();
                                analyticsRegistry.trackDownloadComplete(download.videoId, download.eid, download.lmsUrl);
                            }
                        }

                        @Override
                        public void onFail(Exception ex) {
                            logger.error(ex);
                        }
                    });
                }
            });
        }
    }
}
Also used : AnalyticsRegistry(org.edx.mobile.module.analytics.AnalyticsRegistry) NativeDownloadModel(org.edx.mobile.model.download.NativeDownloadModel) DataCallback(org.edx.mobile.module.db.DataCallback) VideoModel(org.edx.mobile.model.VideoModel) DownloadEntry(org.edx.mobile.model.db.DownloadEntry)

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