Search in sources :

Example 11 with VideoModel

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

the class Storage method addDownload.

public long addDownload(VideoModel model) {
    if (model.getVideoUrl() == null || model.getVideoUrl().length() <= 0) {
        return -1;
    }
    VideoModel videoByUrl = db.getVideoByVideoUrl(model.getVideoUrl(), null);
    db.addVideoData(model, null);
    if (model.isVideoForWebOnly())
        // we may need to return different error code.
        return -1;
    if (videoByUrl == null || videoByUrl.getDmId() < 0) {
        boolean downloadPreference = pref.isDownloadOverWifiOnly();
        if (NetworkUtil.isOnZeroRatedNetwork(context, config)) {
            // If the device has zero rated network, then allow downloading
            // on mobile network even if user has "Only on wifi" settings as ON
            downloadPreference = false;
        }
        // Fail the download if download directory isn't available
        final File downloadDirectory = pref.getDownloadDirectory();
        if (downloadDirectory == null)
            return -1;
        // there is no any download ever marked for this URL
        // so, add a download and map download info to given video
        long dmid = dm.addDownload(downloadDirectory, model.getVideoUrl(), downloadPreference, model.getTitle());
        if (dmid == -1) {
            // Download did not start for the video because of an issue in DownloadManager
            return -1;
        }
        NativeDownloadModel download = dm.getDownload(dmid);
        if (download != null) {
            // copy download info
            model.setDownloadingInfo(download);
        }
    } else {
        // download for this URL already exists, just map download info to given video
        model.setDownloadInfo(videoByUrl);
    }
    db.updateDownloadingVideoInfoByVideoId(model, new DataCallback<Integer>() {

        @Override
        public void onResult(Integer noOfRows) {
            if (noOfRows > 1) {
                logger.warn("Should have updated only one video, " + "but seems more than one videos are updated");
            }
            logger.debug("Video download info updated for " + noOfRows + " videos");
        }

        @Override
        public void onFail(Exception ex) {
            logger.error(ex);
        }
    });
    return model.getDmId();
}
Also used : NativeDownloadModel(org.edx.mobile.model.download.NativeDownloadModel) VideoModel(org.edx.mobile.model.VideoModel) File(java.io.File)

Example 12 with VideoModel

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

the class DbTests method testgetListOfOngoingDownloads.

@Test
public void testgetListOfOngoingDownloads() throws Exception {
    db.clearDataByUser(username);
    db.getListOfOngoingDownloads(new DataCallback<List<VideoModel>>() {

        @Override
        public void onResult(List<VideoModel> result) {
            assertNotNull(result);
            assertTrue(result.size() == 0);
            for (VideoModel model : result) {
                print(model.getChapterName());
                print("ID : " + model.getVideoId());
                print("result for get ListOfOngoingDownloads is:" + result.size());
            }
            unlock();
        }

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

        @Override
        public void onResult(List<VideoModel> result) {
            assertNotNull(result);
            assertTrue(result.size() == 1);
            for (VideoModel model : result) {
                print(model.getChapterName());
                print("ID : " + model.getVideoId());
                print("result for get ListOfOngoingDownloads is:" + result.size());
            }
            unlock();
        }

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

Example 13 with VideoModel

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

the class DbTests method testgetIVideoModelByVideoUrl.

@Test
public void testgetIVideoModelByVideoUrl() throws Exception {
    db.clearDataByUser(username);
    final String videoUrl = "url";
    db.getIVideoModelByVideoUrl(videoUrl, new DataCallback<VideoModel>() {

        @Override
        public void onResult(VideoModel result) {
            assertNull("result should be null", result);
            unlock();
        }

        @Override
        public void onFail(Exception ex) {
            logger.error(ex);
            fail(ex.getMessage());
        }
    });
    lock();
    DownloadEntry de = getDummyVideoModel();
    de.url = "http://fake/url";
    db.addVideoData(de, null);
    db.getIVideoModelByVideoUrl(de.url, new DataCallback<VideoModel>() {

        @Override
        public void onResult(VideoModel result) {
            assertNotNull(result);
            print("VideoModel  present for url= " + result.getVideoUrl());
            unlock();
        }

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

Example 14 with VideoModel

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

the class DbTests method testGetVideoEntryByVideoId.

@Test
public void testGetVideoEntryByVideoId() throws Exception {
    db.clearDataByUser(username);
    String videoId = "videoId";
    // String videoId = "videoId-" + System.currentTimeMillis();
    db.getVideoEntryByVideoId(videoId, new DataCallback<VideoModel>() {

        @Override
        public void onResult(VideoModel result) {
            assertTrue(result == null);
            print("Result for Video Entry By VideoId= " + result);
            unlock();
        }

        @Override
        public void onFail(Exception ex) {
            fail(ex.getMessage());
        }
    });
    lock();
    DownloadEntry de = getDummyVideoModel();
    // de.videoId = "videoId-" + System.currentTimeMillis();
    de.videoId = "videoId";
    db.addVideoData(de, null);
    db.getVideoEntryByVideoId(videoId, new DataCallback<VideoModel>() {

        @Override
        public void onResult(VideoModel result) {
            assertTrue(result != null);
            print("Result for Video Entry By VideoId in AssertTrue= " + result.getVideoId());
            unlock();
        }

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

Example 15 with VideoModel

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

the class DbTests method testgetAllDeactivatedVideos.

@Test
public void testgetAllDeactivatedVideos() throws Exception {
    db.clearDataByUser(username);
    db.getAllDeactivatedVideos(new DataCallback<List<VideoModel>>() {

        @Override
        public void onResult(List<VideoModel> result) {
            // assertNotNull(result);
            assertTrue(result.isEmpty());
            print("Result for getAllDeactivatedVideos for size 0 is" + result);
            unlock();
        }

        @Override
        public void onFail(Exception ex) {
            fail(ex.getMessage());
        }
    });
    lock();
    DownloadEntry de = getDummyVideoModel();
    // inactive video
    de.isCourseActive = 0;
    db.addVideoData(de, null);
    db.getAllDeactivatedVideos(new DataCallback<List<VideoModel>>() {

        @Override
        public void onResult(List<VideoModel> result) {
            assertNotNull(result);
            assertTrue("result size = " + result.size(), result.size() == 1);
            print("Result for getAllDeactivatedVideos for size 1 is" + result.toString());
            unlock();
        }

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

Aggregations

VideoModel (org.edx.mobile.model.VideoModel)18 DownloadEntry (org.edx.mobile.model.db.DownloadEntry)10 Test (org.junit.Test)9 List (java.util.List)5 Cursor (android.database.Cursor)2 NativeDownloadModel (org.edx.mobile.model.download.NativeDownloadModel)2 IDatabase (org.edx.mobile.module.db.IDatabase)2 ContentValues (android.content.ContentValues)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 AnalyticsRegistry (org.edx.mobile.module.analytics.AnalyticsRegistry)1 DataCallback (org.edx.mobile.module.db.DataCallback)1 DownloadEntryAdapter (org.edx.mobile.view.adapters.DownloadEntryAdapter)1