Search in sources :

Example 26 with DownloadEntry

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;
}
Also used : DownloadEntry(org.edx.mobile.model.db.DownloadEntry)

Example 27 with DownloadEntry

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);
}
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 28 with DownloadEntry

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;
}
Also used : BlockPath(org.edx.mobile.model.course.BlockPath) IBlock(org.edx.mobile.model.course.IBlock) VideoInfo(org.edx.mobile.model.course.VideoInfo) DownloadEntry(org.edx.mobile.model.db.DownloadEntry)

Example 29 with DownloadEntry

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;
}
Also used : DownloadEntry(org.edx.mobile.model.db.DownloadEntry)

Example 30 with DownloadEntry

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

DownloadEntry (org.edx.mobile.model.db.DownloadEntry)50 Test (org.junit.Test)36 VideoModel (org.edx.mobile.model.VideoModel)10 List (java.util.List)6 HasDownloadEntry (org.edx.mobile.model.course.HasDownloadEntry)4 CourseComponent (org.edx.mobile.model.course.CourseComponent)2 DiscussionBlockModel (org.edx.mobile.model.course.DiscussionBlockModel)2 VideoBlockModel (org.edx.mobile.model.course.VideoBlockModel)2 WatchedState (org.edx.mobile.model.db.DownloadEntry.WatchedState)2 BulkVideosDownloadCancelledEvent (org.edx.mobile.module.storage.BulkVideosDownloadCancelledEvent)2 MenuItem (android.view.MenuItem)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 BaseFragmentActivity (org.edx.mobile.base.BaseFragmentActivity)1 BaseVideosDownloadStateActivity (org.edx.mobile.base.BaseVideosDownloadStateActivity)1 BlockPath (org.edx.mobile.model.course.BlockPath)1 IBlock (org.edx.mobile.model.course.IBlock)1 VideoInfo (org.edx.mobile.model.course.VideoInfo)1 DownloadedState (org.edx.mobile.model.db.DownloadEntry.DownloadedState)1