From 115782fe2ae773e813cfc19e3d84475aa6743097 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=D0=9A=D0=BE=D0=B6?= =?UTF-8?q?=D0=B5=D0=B2?= Date: Thu, 18 Aug 2022 13:11:54 +0300 Subject: [PATCH] Add a ProgressBar to the notification if the build is underway. (#388) * Add a progress bar to the notification if the build is underway --- .../services/GradleBuildService.java | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/itsaky/androidide/services/GradleBuildService.java b/app/src/main/java/com/itsaky/androidide/services/GradleBuildService.java index d67ed6486..4c702156c 100644 --- a/app/src/main/java/com/itsaky/androidide/services/GradleBuildService.java +++ b/app/src/main/java/com/itsaky/androidide/services/GradleBuildService.java @@ -102,15 +102,15 @@ public class GradleBuildService extends Service implements BuildService, IToolin @Override public void onCreate() { notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); - showNotification(getString(R.string.build_status_idle)); + showNotification(getString(R.string.build_status_idle), false); } - private void showNotification(final String message) { + private void showNotification(final String message, final boolean isProgress) { LOG.info("Showing notification to user..."); - startForeground(NOTIFICATION_ID, buildNotification(message)); + startForeground(NOTIFICATION_ID, buildNotification(message, isProgress)); } - private Notification buildNotification(final String message) { + private Notification buildNotification(final String message, final boolean isProgress) { final var ticker = getString(R.string.title_gradle_service_notification_ticker); final var title = getString(R.string.title_gradle_service_notification); @@ -126,6 +126,12 @@ public class GradleBuildService extends Service implements BuildService, IToolin .setContentTitle(title) .setContentText(message) .setContentIntent(intent); + + // Checking whether to add a ProgressBar to the notification + if (isProgress) { + // Add ProgressBar to Notification + builder.setProgress(100, 0, true); + } return builder.build(); } @@ -173,7 +179,7 @@ public class GradleBuildService extends Service implements BuildService, IToolin @Override public void prepareBuild() { - updateNotification(getString(R.string.build_status_in_progress)); + updateNotification(getString(R.string.build_status_in_progress), true); if (eventListener != null) { eventListener.prepareBuild(); } @@ -181,7 +187,7 @@ public class GradleBuildService extends Service implements BuildService, IToolin @Override public void onBuildSuccessful(@NonNull BuildResult result) { - updateNotification(getString(R.string.build_status_sucess)); + updateNotification(getString(R.string.build_status_sucess), false); if (eventListener != null) { eventListener.onBuildSuccessful(result.getTasks()); } @@ -189,7 +195,7 @@ public class GradleBuildService extends Service implements BuildService, IToolin @Override public void onBuildFailed(@NonNull BuildResult result) { - updateNotification(getString(R.string.build_status_failed)); + updateNotification(getString(R.string.build_status_failed), false); if (eventListener != null) { eventListener.onBuildFailed(result.getTasks()); } @@ -300,13 +306,13 @@ public class GradleBuildService extends Service implements BuildService, IToolin } @SuppressWarnings("ConstantConditions") - protected void updateNotification(final String message) { - ThreadUtils.runOnUiThread(() -> doUpdateNotification(message)); + protected void updateNotification(final String message, final boolean isProgress) { + ThreadUtils.runOnUiThread(() -> doUpdateNotification(message, isProgress)); } - protected void doUpdateNotification(final String message) { + protected void doUpdateNotification(final String message, final boolean isProgress) { ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)) - .notify(NOTIFICATION_ID, buildNotification(message)); + .notify(NOTIFICATION_ID, buildNotification(message, isProgress)); } @Override