Search in sources :

Example 1 with BulkVideosDownloadCancelledEvent

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);
}
Also used : BulkVideosDownloadCancelledEvent(org.edx.mobile.module.storage.BulkVideosDownloadCancelledEvent) IDialogCallback(org.edx.mobile.view.dialog.IDialogCallback)

Example 2 with BulkVideosDownloadCancelledEvent

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);
}
Also used : HashMap(java.util.HashMap) BulkVideosDownloadCancelledEvent(org.edx.mobile.module.storage.BulkVideosDownloadCancelledEvent) IDialogCallback(org.edx.mobile.view.dialog.IDialogCallback) HasDownloadEntry(org.edx.mobile.model.course.HasDownloadEntry) DownloadEntry(org.edx.mobile.model.db.DownloadEntry) BulkVideosDownloadStartedEvent(org.edx.mobile.module.storage.BulkVideosDownloadStartedEvent)

Example 3 with BulkVideosDownloadCancelledEvent

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);
        }
    }
}
Also used : BaseFragmentActivity(org.edx.mobile.base.BaseFragmentActivity) ArrayList(java.util.ArrayList) BulkVideosDownloadCancelledEvent(org.edx.mobile.module.storage.BulkVideosDownloadCancelledEvent) HasDownloadEntry(org.edx.mobile.model.course.HasDownloadEntry) DownloadEntry(org.edx.mobile.model.db.DownloadEntry) HasDownloadEntry(org.edx.mobile.model.course.HasDownloadEntry)

Aggregations

BulkVideosDownloadCancelledEvent (org.edx.mobile.module.storage.BulkVideosDownloadCancelledEvent)3 HasDownloadEntry (org.edx.mobile.model.course.HasDownloadEntry)2 DownloadEntry (org.edx.mobile.model.db.DownloadEntry)2 IDialogCallback (org.edx.mobile.view.dialog.IDialogCallback)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 BaseFragmentActivity (org.edx.mobile.base.BaseFragmentActivity)1 BulkVideosDownloadStartedEvent (org.edx.mobile.module.storage.BulkVideosDownloadStartedEvent)1