Search in sources :

Example 6 with VideoModel

use of org.edx.mobile.model.VideoModel in project edx-app-android by edx.

the class DbOperationGetVideos method execute.

@Override
public List<VideoModel> execute(SQLiteDatabase db) {
    List<VideoModel> list = new ArrayList<VideoModel>();
    Cursor c = getCursor(db);
    if (c.moveToFirst()) {
        do {
            VideoModel video = DatabaseModelFactory.getModel(c);
            list.add(video);
        } while (c.moveToNext());
    }
    c.close();
    return list;
}
Also used : ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) VideoModel(org.edx.mobile.model.VideoModel)

Example 7 with VideoModel

use of org.edx.mobile.model.VideoModel in project edx-app-android by edx.

the class Storage method removeDownloadsFromApp.

private int removeDownloadsFromApp(List<VideoModel> result, String username) {
    // Remove all downloads from db
    long[] videoIds = new long[result.size()];
    VideoModel model;
    for (int i = 0; i < result.size(); i++) {
        model = result.get(i);
        if (username == null) {
            db.deleteVideoByVideoId(model, null);
        } else {
            db.deleteVideoByVideoId(model, username, null);
        }
        deleteFile(model.getFilePath());
        videoIds[i] = model.getDmId();
    }
    // Remove all downloads from NativeDownloadManager
    return videoIds.length > 0 ? dm.removeDownloads(videoIds) : 0;
}
Also used : VideoModel(org.edx.mobile.model.VideoModel)

Example 8 with VideoModel

use of org.edx.mobile.model.VideoModel in project edx-app-android by edx.

the class Storage method getDownloadProgressOfCourseVideos.

@Override
public void getDownloadProgressOfCourseVideos(@Nullable String courseId, final DataCallback<NativeDownloadModel> callback) {
    final IDatabase db = DatabaseFactory.getInstance(DatabaseFactory.TYPE_DATABASE_NATIVE);
    db.getListOfOngoingDownloadsByCourseId(courseId, new DataCallback<List<VideoModel>>() {

        @Override
        public void onResult(List<VideoModel> result) {
            final long[] dmids = new long[result.size()];
            for (int i = 0; i < result.size(); i++) {
                dmids[i] = result.get(i).getDmId();
            }
            callback.onResult(dm.getProgressDetailsForDownloads(dmids));
        }

        @Override
        public void onFail(Exception ex) {
            callback.onFail(ex);
        }
    });
}
Also used : IDatabase(org.edx.mobile.module.db.IDatabase) List(java.util.List) VideoModel(org.edx.mobile.model.VideoModel)

Example 9 with VideoModel

use of org.edx.mobile.model.VideoModel in project edx-app-android by edx.

the class Storage method getAverageDownloadProgress.

@Override
public void getAverageDownloadProgress(final DataCallback<Integer> callback) {
    IDatabase db = DatabaseFactory.getInstance(DatabaseFactory.TYPE_DATABASE_NATIVE);
    db.getListOfOngoingDownloads(new DataCallback<List<VideoModel>>() {

        @Override
        public void onResult(List<VideoModel> result) {
            long[] dmids = new long[result.size()];
            for (int i = 0; i < result.size(); i++) {
                dmids[i] = result.get(i).getDmId();
            }
            int averageProgress = dm.getAverageProgressForDownloads(dmids);
            callback.onResult(averageProgress);
        }

        @Override
        public void onFail(Exception ex) {
            callback.onFail(ex);
        }
    });
}
Also used : IDatabase(org.edx.mobile.module.db.IDatabase) List(java.util.List) VideoModel(org.edx.mobile.model.VideoModel)

Example 10 with VideoModel

use of org.edx.mobile.model.VideoModel in project edx-app-android by edx.

the class DbOperationGetVideo method execute.

@Override
public VideoModel execute(SQLiteDatabase db) {
    VideoModel video = null;
    Cursor c = getCursor(db);
    if (c.moveToFirst()) {
        video = DatabaseModelFactory.getModel(c);
    }
    if (c.moveToNext()) {
        logger.warn("More than one records available that match your query, " + "but you chose only first one");
    }
    c.close();
    return video;
}
Also used : Cursor(android.database.Cursor) VideoModel(org.edx.mobile.model.VideoModel)

Aggregations

VideoModel (org.edx.mobile.model.VideoModel)18 DownloadEntry (org.edx.mobile.model.db.DownloadEntry)10 Test (org.junit.Test)9 List (java.util.List)5 Cursor (android.database.Cursor)2 NativeDownloadModel (org.edx.mobile.model.download.NativeDownloadModel)2 IDatabase (org.edx.mobile.module.db.IDatabase)2 ContentValues (android.content.ContentValues)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 AnalyticsRegistry (org.edx.mobile.module.analytics.AnalyticsRegistry)1 DataCallback (org.edx.mobile.module.db.DataCallback)1 DownloadEntryAdapter (org.edx.mobile.view.adapters.DownloadEntryAdapter)1