Search in sources :

Example 1 with IDatabase

use of org.edx.mobile.module.db.IDatabase 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 2 with IDatabase

use of org.edx.mobile.module.db.IDatabase in project edx-app-android by edx.

the class Storage method getDownloadProgressOfCourseVideos.

@Override
public void getDownloadProgressOfCourseVideos(@Nullable String courseId, final DataCallback<NativeDownloadModel> callback) {
    final IDatabase db = DatabaseFactory.getInstance(DatabaseFactory.TYPE_DATABASE_NATIVE);
    db.getListOfOngoingDownloadsByCourseId(courseId, new DataCallback<List<VideoModel>>() {

        @Override
        public void onResult(List<VideoModel> result) {
            final long[] dmids = new long[result.size()];
            for (int i = 0; i < result.size(); i++) {
                dmids[i] = result.get(i).getDmId();
            }
            callback.onResult(dm.getProgressDetailsForDownloads(dmids));
        }

        @Override
        public void onFail(Exception ex) {
            callback.onFail(ex);
        }
    });
}
Also used : IDatabase(org.edx.mobile.module.db.IDatabase) List(java.util.List) VideoModel(org.edx.mobile.model.VideoModel)

Example 3 with IDatabase

use of org.edx.mobile.module.db.IDatabase in project edx-app-android by edx.

the class Storage method getAverageDownloadProgress.

@Override
public void getAverageDownloadProgress(final DataCallback<Integer> callback) {
    IDatabase db = DatabaseFactory.getInstance(DatabaseFactory.TYPE_DATABASE_NATIVE);
    db.getListOfOngoingDownloads(new DataCallback<List<VideoModel>>() {

        @Override
        public void onResult(List<VideoModel> result) {
            long[] dmids = new long[result.size()];
            for (int i = 0; i < result.size(); i++) {
                dmids[i] = result.get(i).getDmId();
            }
            int averageProgress = dm.getAverageProgressForDownloads(dmids);
            callback.onResult(averageProgress);
        }

        @Override
        public void onFail(Exception ex) {
            callback.onFail(ex);
        }
    });
}
Also used : IDatabase(org.edx.mobile.module.db.IDatabase) List(java.util.List) VideoModel(org.edx.mobile.model.VideoModel)

Aggregations

IDatabase (org.edx.mobile.module.db.IDatabase)3 List (java.util.List)2 VideoModel (org.edx.mobile.model.VideoModel)2 MenuItem (android.view.MenuItem)1 BaseVideosDownloadStateActivity (org.edx.mobile.base.BaseVideosDownloadStateActivity)1 DownloadEntry (org.edx.mobile.model.db.DownloadEntry)1 Test (org.junit.Test)1 ShadowActivity (org.robolectric.shadows.ShadowActivity)1