use of org.edx.mobile.module.storage.BulkVideosDownloadCancelledEvent in project edx-app-android by edx.
the class VideoDownloadHelper method downloadVideos.
public void downloadVideos(final List<? extends HasDownloadEntry> model, final FragmentActivity activity, final DownloadManagerCallback callback) {
if (model == null || model.isEmpty()) {
return;
}
IDialogCallback dialogCallback = new IDialogCallback() {
@Override
public void onPositiveClicked() {
startDownloadVideos(model, activity, callback);
}
@Override
public void onNegativeClicked() {
callback.showInfoMessage(activity.getString(R.string.wifi_off_message));
EventBus.getDefault().post(new BulkVideosDownloadCancelledEvent());
}
};
MediaConsentUtils.requestStreamMedia(activity, dialogCallback);
}
use of org.edx.mobile.module.storage.BulkVideosDownloadCancelledEvent 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.module.storage.BulkVideosDownloadCancelledEvent 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