use of org.edx.mobile.model.db.DownloadEntry in project edx-app-android by edx.
the class EnqueueDownloadTask method call.
@Override
public Long call() throws Exception {
int count = 0;
for (DownloadEntry de : downloadList) {
if (environment.getStorage().addDownload(de) != -1) {
count++;
transcriptManager.downloadTranscriptsForVideo(de.transcript);
}
}
return (long) count;
}
use of org.edx.mobile.model.db.DownloadEntry in project edx-app-android by edx.
the class VideoDownloadHelper method showDownloadSizeExceedDialog.
// Dialog fragment to display message to user regarding
private void showDownloadSizeExceedDialog(final ArrayList<DownloadEntry> de, final int noOfDownloads, final FragmentActivity activity, final DownloadManagerCallback callback) {
Map<String, String> dialogMap = new HashMap<String, String>();
dialogMap.put("title", activity.getString(R.string.download_exceed_title));
dialogMap.put("message_1", activity.getString(R.string.download_exceed_message));
downloadFragment = DownloadSizeExceedDialog.newInstance(dialogMap, new IDialogCallback() {
@Override
public void onPositiveClicked() {
if (!de.isEmpty()) {
startDownload(de, activity, callback);
final DownloadEntry downloadEntry = de.get(0);
analyticsRegistry.trackSubSectionBulkVideoDownload(downloadEntry.getSectionName(), downloadEntry.getChapterName(), downloadEntry.getEnrollmentId(), noOfDownloads);
EventBus.getDefault().post(new BulkVideosDownloadStartedEvent());
}
}
@Override
public void onNegativeClicked() {
// updateList();
downloadFragment.dismiss();
EventBus.getDefault().post(new BulkVideosDownloadCancelledEvent());
}
});
downloadFragment.setStyle(DialogFragment.STYLE_NO_TITLE, 0);
downloadFragment.show(activity.getSupportFragmentManager(), "dialog");
downloadFragment.setCancelable(false);
}
use of org.edx.mobile.model.db.DownloadEntry in project edx-app-android by edx.
the class DatabaseModelFactory method getModel.
/**
* Returns an object of IVideoModel which has all the fields copied from given VideoData.
*
* @param vrm
* @return
*/
public static VideoModel getModel(VideoData vrm, VideoBlockModel block) {
DownloadEntry e = new DownloadEntry();
// FIXME - current database schema is not suitable for arbitary level of course structure tree
// solution - store the navigation path info in into one column field in the database,
// rather than individual column fields.
BlockPath path = block.getPath();
e.chapter = path.get(1) == null ? "" : path.get(1).getDisplayName();
e.section = path.get(2) == null ? "" : path.get(2).getDisplayName();
IBlock root = block.getRoot();
e.eid = root.getCourseId();
e.duration = vrm.duration;
final VideoInfo preferredVideoInfo = vrm.encodedVideos.getPreferredVideoInfo();
e.size = preferredVideoInfo.fileSize;
e.title = block.getDisplayName();
e.url = preferredVideoInfo.url;
e.url_high_quality = getVideoNetworkUrlOrNull(vrm.encodedVideos.mobileHigh);
e.url_low_quality = getVideoNetworkUrlOrNull(vrm.encodedVideos.mobileLow);
e.url_youtube = getVideoNetworkUrlOrNull(vrm.encodedVideos.youtube);
e.videoId = block.getId();
e.transcript = vrm.transcripts;
e.lmsUrl = block.getBlockUrl();
e.isVideoForWebOnly = vrm.onlyOnWeb;
return e;
}
use of org.edx.mobile.model.db.DownloadEntry in project edx-app-android by edx.
the class DatabaseModelFactory method getModel.
/**
* Returns new instance of {@link org.edx.mobile.model.VideoModel} initialized with given cursor.
*
* @param c
* @return
*/
public static VideoModel getModel(Cursor c) {
DownloadEntry de = new DownloadEntry();
de.dmId = c.getLong(c.getColumnIndex(DbStructure.Column.DM_ID));
de.downloaded = DownloadEntry.DownloadedState.values()[c.getInt(c.getColumnIndex(DbStructure.Column.DOWNLOADED))];
de.duration = c.getLong(c.getColumnIndex(DbStructure.Column.DURATION));
de.filepath = c.getString(c.getColumnIndex(DbStructure.Column.FILEPATH));
de.id = c.getInt(c.getColumnIndex(DbStructure.Column.ID));
de.size = c.getLong(c.getColumnIndex(DbStructure.Column.SIZE));
de.username = c.getString(c.getColumnIndex(DbStructure.Column.USERNAME));
de.title = c.getString(c.getColumnIndex(DbStructure.Column.TITLE));
de.url = c.getString(c.getColumnIndex(DbStructure.Column.URL));
de.url_high_quality = c.getString(c.getColumnIndex(DbStructure.Column.URL_HIGH_QUALITY));
de.url_low_quality = c.getString(c.getColumnIndex(DbStructure.Column.URL_LOW_QUALITY));
de.url_youtube = c.getString(c.getColumnIndex(DbStructure.Column.URL_YOUTUBE));
de.videoId = c.getString(c.getColumnIndex(DbStructure.Column.VIDEO_ID));
de.watched = DownloadEntry.WatchedState.values()[c.getInt(c.getColumnIndex(DbStructure.Column.WATCHED))];
de.eid = c.getString(c.getColumnIndex(DbStructure.Column.EID));
de.chapter = c.getString(c.getColumnIndex(DbStructure.Column.CHAPTER));
de.section = c.getString(c.getColumnIndex(DbStructure.Column.SECTION));
de.downloadedOn = c.getLong(c.getColumnIndex(DbStructure.Column.DOWNLOADED_ON));
de.lastPlayedOffset = c.getInt(c.getColumnIndex(DbStructure.Column.LAST_PLAYED_OFFSET));
de.isCourseActive = c.getInt(c.getColumnIndex(DbStructure.Column.IS_COURSE_ACTIVE));
de.isVideoForWebOnly = c.getInt(c.getColumnIndex(DbStructure.Column.VIDEO_FOR_WEB_ONLY)) == 1;
de.lmsUrl = c.getString(c.getColumnIndex(DbStructure.Column.UNIT_URL));
return de;
}
use of org.edx.mobile.model.db.DownloadEntry in project edx-app-android by edx.
the class VideoDownloadHelper method startDownloadVideos.
private void startDownloadVideos(List<? extends HasDownloadEntry> model, FragmentActivity activity, DownloadManagerCallback callback) {
long downloadSize = 0;
ArrayList<DownloadEntry> downloadList = new ArrayList<>();
int downloadCount = 0;
for (HasDownloadEntry v : model) {
DownloadEntry de = v.getDownloadEntry(storage);
if (!TextUtils.isEmpty(v.getDownloadUrl())) {
// Prefer download url to download
de.url = v.getDownloadUrl();
}
if (null == de || de.downloaded == DownloadEntry.DownloadedState.DOWNLOADING || de.downloaded == DownloadEntry.DownloadedState.DOWNLOADED || de.isVideoForWebOnly) {
continue;
} else {
downloadSize = downloadSize + de.getSize();
downloadList.add(de);
downloadCount++;
}
}
if (downloadSize > MemoryUtil.getAvailableExternalMemory(activity)) {
((BaseFragmentActivity) activity).showInfoMessage(activity.getString(R.string.file_size_exceeded));
callback.updateListUI();
EventBus.getDefault().post(new BulkVideosDownloadCancelledEvent());
} else {
if (isDownloadSizeWithinLimit(downloadSize, MemoryUtil.GB) && !downloadList.isEmpty()) {
startDownload(downloadList, activity, callback);
final DownloadEntry downloadEntry = downloadList.get(0);
analyticsRegistry.trackSubSectionBulkVideoDownload(downloadEntry.getSectionName(), downloadEntry.getChapterName(), downloadEntry.getEnrollmentId(), downloadCount);
} else {
showDownloadSizeExceedDialog(downloadList, downloadCount, activity, callback);
}
}
}
Aggregations