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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations