Search in sources :

Example 1 with ProgressWheel

use of org.edx.mobile.view.custom.ProgressWheel 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 2 with ProgressWheel

use of org.edx.mobile.view.custom.ProgressWheel 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

View (android.view.View)2 DataCallback (org.edx.mobile.module.db.DataCallback)2 ProgressWheel (org.edx.mobile.view.custom.ProgressWheel)2 MenuItem (android.view.MenuItem)1