Search in sources :

Example 1 with VideoModel

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

the class DownloadListActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_downloads_list);
    super.setToolbarAsActionBar();
    environment.getAnalyticsRegistry().trackScreenView(Analytics.Screens.DOWNLOADS);
    adapter = new DownloadEntryAdapter(this, environment) {

        @Override
        public void onItemClicked(DownloadEntryAdapter.Item model) {
        // nothing to do here
        }

        @Override
        public void onDeleteClicked(DownloadEntryAdapter.Item item) {
            assert adapter != null;
            final VideoModel videoModel = ((DownloadItem) item).model;
            if (environment.getStorage().removeDownload(videoModel) >= 1) {
                adapter.remove(item);
            }
        }
    };
    loadingIndicator = findViewById(R.id.loading_indicator);
    downloadListView = (ListView) findViewById(R.id.my_downloads_list);
    downloadListView.setAdapter(adapter);
    loadingIndicator.setVisibility(View.VISIBLE);
    downloadListView.setVisibility(View.GONE);
}
Also used : DownloadEntryAdapter(org.edx.mobile.view.adapters.DownloadEntryAdapter) VideoModel(org.edx.mobile.model.VideoModel)

Example 2 with VideoModel

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

the class DbTests method testgetAllVideos.

@Test
public void testgetAllVideos() throws Exception {
    db.clearDataByUser(username);
    db.getAllVideos(username, new DataCallback<List<VideoModel>>() {

        @Override
        public void onResult(List<VideoModel> result) {
            assertNotNull(result);
            assertTrue("there should not be any video present in cleared database", result.size() == 0);
            unlock();
        }

        @Override
        public void onFail(Exception ex) {
            fail(ex.getMessage());
        }
    });
    lock();
    DownloadEntry de = getDummyVideoModel();
    db.addVideoData(de, null);
    db.getAllVideos(username, new DataCallback<List<VideoModel>>() {

        @Override
        public void onResult(List<VideoModel> result) {
            assertNotNull(result);
            assertTrue(result.size() == 1);
            // assertFalse("something is downloading", result);
            print("result for getAllVideos :" + result.toString());
            unlock();
        }

        @Override
        public void onFail(Exception ex) {
            fail(ex.getMessage());
        }
    });
    lock();
}
Also used : List(java.util.List) VideoModel(org.edx.mobile.model.VideoModel) DownloadEntry(org.edx.mobile.model.db.DownloadEntry) Test(org.junit.Test)

Example 3 with VideoModel

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

the class DbTests method testDeleteVideo.

@Test
public void testDeleteVideo() throws Exception {
    String videoId = "testVideoId";
    db.clearDataByUser(username);
    DownloadEntry de = getDummyVideoModel();
    de.videoId = videoId;
    Long rowId = db.addVideoData(de, null);
    assertNotNull(rowId);
    assertTrue("Row Id must be non zero positive number", rowId > 0);
    VideoModel video = db.getVideoEntryByVideoId(videoId, null);
    assertNotNull("Should have got one video object", video);
    Integer count = db.deleteVideoByVideoId(video, null);
    assertNotNull(count);
    assertTrue("Should have deleted ONE video only", count == 1);
}
Also used : VideoModel(org.edx.mobile.model.VideoModel) DownloadEntry(org.edx.mobile.model.db.DownloadEntry) Test(org.junit.Test)

Example 4 with VideoModel

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

the class IDatabaseImpl method addVideoData.

@Override
public Long addVideoData(final VideoModel de, final DataCallback<Long> callback) {
    VideoModel result = getVideoEntryByVideoId(de.getVideoId(), null);
    if (result == null) {
        ContentValues values = new ContentValues();
        values.put(DbStructure.Column.USERNAME, username());
        values.put(DbStructure.Column.TITLE, de.getTitle());
        values.put(DbStructure.Column.VIDEO_ID, de.getVideoId());
        values.put(DbStructure.Column.SIZE, de.getSize());
        values.put(DbStructure.Column.DURATION, de.getDuration());
        values.put(DbStructure.Column.FILEPATH, de.getFilePath());
        values.put(DbStructure.Column.URL, de.getVideoUrl());
        values.put(DbStructure.Column.URL_HIGH_QUALITY, de.getHighQualityVideoUrl());
        values.put(DbStructure.Column.URL_LOW_QUALITY, de.getLowQualityVideoUrl());
        values.put(DbStructure.Column.URL_YOUTUBE, de.getYoutubeVideoUrl());
        values.put(DbStructure.Column.WATCHED, de.getWatchedStateOrdinal());
        values.put(DbStructure.Column.DOWNLOADED, de.getDownloadedStateOrdinal());
        values.put(DbStructure.Column.DM_ID, de.getDmId());
        values.put(DbStructure.Column.EID, de.getEnrollmentId());
        values.put(DbStructure.Column.CHAPTER, de.getChapterName());
        values.put(DbStructure.Column.SECTION, de.getSectionName());
        values.put(DbStructure.Column.LAST_PLAYED_OFFSET, de.getLastPlayedOffset());
        values.put(DbStructure.Column.UNIT_URL, de.getLmsUrl());
        values.put(DbStructure.Column.IS_COURSE_ACTIVE, de.isCourseActive());
        values.put(DbStructure.Column.VIDEO_FOR_WEB_ONLY, de.isVideoForWebOnly());
        DbOperationInsert op = new DbOperationInsert(DbStructure.Table.DOWNLOADS, values);
        op.setCallback(callback);
        return enqueue(op);
    } else {
        if (callback != null) {
            callback.sendResult(0L);
        }
        logger.warn("Not inserting, this seems a duplicate record");
    }
    return 0L;
}
Also used : ContentValues(android.content.ContentValues) VideoModel(org.edx.mobile.model.VideoModel)

Example 5 with VideoModel

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

the class DownloadCompleteReceiver method handleDownloadCompleteIntent.

private void handleDownloadCompleteIntent(final Intent data) {
    if (data.hasExtra(DownloadManager.EXTRA_DOWNLOAD_ID)) {
        final long id = data.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
        if (id != -1) {
            AsyncTask.execute(new Runnable() {

                @Override
                public void run() {
                    logger.debug("Received download notification for id: " + id);
                    // check if download was SUCCESSFUL
                    NativeDownloadModel nm = environment.getDownloadManager().getDownload(id);
                    if (nm == null || nm.status != DownloadManager.STATUS_SUCCESSFUL) {
                        logger.debug("Download seems failed or cancelled for id : " + id);
                        environment.getDownloadManager().removeDownloads(id);
                        return;
                    } else {
                        logger.debug("Download successful for id : " + id);
                    }
                    // mark download as completed
                    environment.getStorage().markDownloadAsComplete(id, new DataCallback<VideoModel>() {

                        @Override
                        public void onResult(VideoModel result) {
                            if (result != null) {
                                DownloadEntry download = (DownloadEntry) result;
                                AnalyticsRegistry analyticsRegistry = environment.getAnalyticsRegistry();
                                analyticsRegistry.trackDownloadComplete(download.videoId, download.eid, download.lmsUrl);
                            }
                        }

                        @Override
                        public void onFail(Exception ex) {
                            logger.error(ex);
                        }
                    });
                }
            });
        }
    }
}
Also used : AnalyticsRegistry(org.edx.mobile.module.analytics.AnalyticsRegistry) NativeDownloadModel(org.edx.mobile.model.download.NativeDownloadModel) DataCallback(org.edx.mobile.module.db.DataCallback) VideoModel(org.edx.mobile.model.VideoModel) DownloadEntry(org.edx.mobile.model.db.DownloadEntry)

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