Search in sources :

Example 1 with DataCallback

use of org.edx.mobile.module.db.DataCallback 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)

Example 2 with DataCallback

use of org.edx.mobile.module.db.DataCallback in project edx-app-android by edx.

the class BaseVideosDownloadStateActivity method onCreateOptionsMenu.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.download_state, menu);
    MenuItem newProgressMenuItem = menu.findItem(R.id.download_progress);
    View progressView = newProgressMenuItem.getActionView();
    ProgressWheel newProgressWheel = (ProgressWheel) progressView.findViewById(R.id.progress_wheel);
    if (progressMenuItem != null) {
        newProgressMenuItem.setVisible(progressMenuItem.isVisible());
        newProgressWheel.setProgress(progressWheel.getProgress());
    }
    progressMenuItem = newProgressMenuItem;
    progressWheel = newProgressWheel;
    progressView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            environment.getRouter().showDownloads(BaseVideosDownloadStateActivity.this);
        }
    });
    if (updateDownloadProgressRunnable == null) {
        updateDownloadProgressRunnable = new Runnable() {

            @Override
            public void run() {
                if (!NetworkUtil.isConnected(BaseVideosDownloadStateActivity.this) || !environment.getDatabase().isAnyVideoDownloading(null)) {
                    progressMenuItem.setVisible(false);
                } else {
                    progressMenuItem.setVisible(true);
                    environment.getStorage().getAverageDownloadProgress(new DataCallback<Integer>() {

                        @Override
                        public void onResult(Integer result) {
                            int progressPercent = result;
                            if (progressPercent >= 0 && progressPercent <= 100) {
                                progressWheel.setProgressPercent(progressPercent);
                            }
                        }

                        @Override
                        public void onFail(Exception ex) {
                            logger.error(ex);
                        }
                    });
                }
                progressWheel.postDelayed(this, DateUtils.SECOND_IN_MILLIS);
            }
        };
        updateDownloadProgressRunnable.run();
    }
    return true;
}
Also used : ProgressWheel(org.edx.mobile.view.custom.ProgressWheel) MenuItem(android.view.MenuItem) DataCallback(org.edx.mobile.module.db.DataCallback) View(android.view.View)

Example 3 with DataCallback

use of org.edx.mobile.module.db.DataCallback in project edx-app-android by edx.

the class CourseTabsDashboardFragment method handleDownloadProgressMenuItem.

public void handleDownloadProgressMenuItem(Menu menu) {
    downloadsMenuItem = menu.findItem(R.id.menu_item_download_progress);
    final View progressView = downloadsMenuItem.getActionView();
    final ProgressWheel progressWheel = (ProgressWheel) progressView.findViewById(R.id.progress_wheel);
    downloadsMenuItem.setVisible(downloadsMenuItem.isVisible());
    progressWheel.setProgress(progressWheel.getProgress());
    progressView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            environment.getRouter().showDownloads(getActivity());
        }
    });
    if (updateDownloadProgressRunnable == null) {
        updateDownloadProgressRunnable = new Runnable() {

            @Override
            public void run() {
                if (!NetworkUtil.isConnected(getContext()) || !environment.getDatabase().isAnyVideoDownloading(null)) {
                    downloadsMenuItem.setVisible(false);
                } else {
                    downloadsMenuItem.setVisible(true);
                    environment.getStorage().getAverageDownloadProgress(new DataCallback<Integer>() {

                        @Override
                        public void onResult(Integer result) {
                            int progressPercent = result;
                            if (progressPercent >= 0 && progressPercent <= 100) {
                                progressWheel.setProgressPercent(progressPercent);
                            }
                        }

                        @Override
                        public void onFail(Exception ex) {
                            logger.error(ex);
                        }
                    });
                }
                handler.postDelayed(this, DateUtils.SECOND_IN_MILLIS);
            }
        };
        updateDownloadProgressRunnable.run();
    }
}
Also used : ProgressWheel(org.edx.mobile.view.custom.ProgressWheel) DataCallback(org.edx.mobile.module.db.DataCallback) View(android.view.View)

Aggregations

DataCallback (org.edx.mobile.module.db.DataCallback)3 View (android.view.View)2 ProgressWheel (org.edx.mobile.view.custom.ProgressWheel)2 MenuItem (android.view.MenuItem)1 VideoModel (org.edx.mobile.model.VideoModel)1 DownloadEntry (org.edx.mobile.model.db.DownloadEntry)1 NativeDownloadModel (org.edx.mobile.model.download.NativeDownloadModel)1 AnalyticsRegistry (org.edx.mobile.module.analytics.AnalyticsRegistry)1