From 6a3fce19f537371fd0a6b4288a3fe6bdec78ab2d Mon Sep 17 00:00:00 2001 From: Forrest Guice Date: Thu, 6 Dec 2018 17:08:15 -0700 Subject: [PATCH] progressDialog show a progress dialog to avoid user inadvertantly killing the process while the task is running --- .../calendar/SuntimesCalendarActivity.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/forrestguice/suntimeswidget/calendar/SuntimesCalendarActivity.java b/app/src/main/java/com/forrestguice/suntimeswidget/calendar/SuntimesCalendarActivity.java index 1f85a826..d82b8e69 100644 --- a/app/src/main/java/com/forrestguice/suntimeswidget/calendar/SuntimesCalendarActivity.java +++ b/app/src/main/java/com/forrestguice/suntimeswidget/calendar/SuntimesCalendarActivity.java @@ -23,6 +23,7 @@ import android.app.Activity; import android.app.AlertDialog; +import android.app.ProgressDialog; import android.content.ClipData; import android.content.ClipboardManager; import android.content.ContentResolver; @@ -463,17 +464,30 @@ private static boolean runCalendarTask(final Activity activity, boolean enabled) } calendarTask.setTaskListener(new SuntimesCalendarTask.SuntimesCalendarTaskListener() { + private ProgressDialog progress; + @Override public void onStarted(boolean flag_clear) { - if (!flag_clear) { - Toast.makeText(activity, activity.getString(R.string.calendars_notification_adding), Toast.LENGTH_SHORT).show(); + if (!flag_clear) + { + //Toast.makeText(activity, activity.getString(R.string.calendars_notification_adding), Toast.LENGTH_SHORT).show(); + + progress = new ProgressDialog(activity); + progress.setIndeterminate(true); + progress.setMessage(activity.getString(R.string.calendars_notification_adding)); + progress.setCanceledOnTouchOutside(false); + progress.show(); } } @Override public void onSuccess(boolean flag_clear) { + if (progress != null) { + progress.dismiss(); + } + if (!flag_clear) Toast.makeText(activity, activity.getString(R.string.calendars_notification_added), Toast.LENGTH_SHORT).show(); else Toast.makeText(activity, activity.getString(R.string.calendars_notification_cleared), Toast.LENGTH_SHORT).show(); @@ -482,6 +496,10 @@ public void onSuccess(boolean flag_clear) @Override public void onFailed(final String errorMsg) { + if (progress != null) { + progress.dismiss(); + } + super.onFailed(errorMsg); AlertDialog.Builder errorDialog = new AlertDialog.Builder(activity); errorDialog.setTitle(activity.getString(R.string.calendars_notification_adding_failed))