diff --git a/app/src/main/java/org/schabi/newpipe/NewVersionWorker.kt b/app/src/main/java/org/schabi/newpipe/NewVersionWorker.kt index fb48d3f70..4cdcc6c69 100644 --- a/app/src/main/java/org/schabi/newpipe/NewVersionWorker.kt +++ b/app/src/main/java/org/schabi/newpipe/NewVersionWorker.kt @@ -82,7 +82,9 @@ class NewVersionWorker( ) val notificationManager = NotificationManagerCompat.from(applicationContext) - notificationManager.notify(2000, notificationBuilder.build()) + if (notificationManager.areNotificationsEnabled()) { + notificationManager.notify(2000, notificationBuilder.build()) + } } @Throws(IOException::class, ReCaptchaException::class) diff --git a/app/src/main/java/org/schabi/newpipe/error/ErrorUtil.kt b/app/src/main/java/org/schabi/newpipe/error/ErrorUtil.kt index 7facb5d85..0fa302623 100644 --- a/app/src/main/java/org/schabi/newpipe/error/ErrorUtil.kt +++ b/app/src/main/java/org/schabi/newpipe/error/ErrorUtil.kt @@ -134,8 +134,11 @@ class ErrorUtil { ) ) - NotificationManagerCompat.from(context) - .notify(ERROR_REPORT_NOTIFICATION_ID, notificationBuilder.build()) + val notificationManager = NotificationManagerCompat.from(context) + if (notificationManager.areNotificationsEnabled()) { + notificationManager + .notify(ERROR_REPORT_NOTIFICATION_ID, notificationBuilder.build()) + } ContextCompat.getMainExecutor(context).execute { // since the notification is silent, also show a toast, otherwise the user is confused diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationHelper.kt b/app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationHelper.kt index d2d16a755..6bfb37984 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationHelper.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationHelper.kt @@ -92,8 +92,10 @@ class NotificationHelper(val context: Context) { // Show individual stream notifications, set channel icon only if there is actually // one showStreamNotifications(newStreams, data.serviceId, data.url, bitmap) - // Show summary notification - manager.notify(data.pseudoId, summaryBuilder.build()) + // Show summary notification if enabled + if (manager.areNotificationsEnabled()) { + manager.notify(data.pseudoId, summaryBuilder.build()) + } iconLoadingTargets.remove(this) // allow it to be garbage-collected } @@ -101,8 +103,10 @@ class NotificationHelper(val context: Context) { override fun onBitmapFailed(e: Exception, errorDrawable: Drawable) { // Show individual stream notifications showStreamNotifications(newStreams, data.serviceId, data.url, null) - // Show summary notification - manager.notify(data.pseudoId, summaryBuilder.build()) + // Show summary notification if enabled + if (manager.areNotificationsEnabled()) { + manager.notify(data.pseudoId, summaryBuilder.build()) + } iconLoadingTargets.remove(this) // allow it to be garbage-collected } @@ -126,7 +130,9 @@ class NotificationHelper(val context: Context) { ) { for (stream in newStreams) { val notification = createStreamNotification(stream, serviceId, channelUrl, channelIcon) - manager.notify(stream.url.hashCode(), notification) + if (manager.areNotificationsEnabled()) { + manager.notify(stream.url.hashCode(), notification) + } } } diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/service/FeedLoadService.kt b/app/src/main/java/org/schabi/newpipe/local/feed/service/FeedLoadService.kt index 48ad5df94..bd128b3bc 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/service/FeedLoadService.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/service/FeedLoadService.kt @@ -185,7 +185,9 @@ class FeedLoadService : Service() { } } - notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build()) + if (notificationManager.areNotificationsEnabled()) { + notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build()) + } } // ///////////////////////////////////////////////////////////////////////// diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/services/BaseImportExportService.java b/app/src/main/java/org/schabi/newpipe/local/subscription/services/BaseImportExportService.java index b7c11b160..850409e25 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/services/BaseImportExportService.java +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/services/BaseImportExportService.java @@ -144,7 +144,9 @@ public abstract class BaseImportExportService extends Service { notificationBuilder.setContentText(text); } - notificationManager.notify(getNotificationId(), notificationBuilder.build()); + if (notificationManager.areNotificationsEnabled()) { + notificationManager.notify(getNotificationId(), notificationBuilder.build()); + } } protected void stopService() { @@ -174,7 +176,10 @@ public abstract class BaseImportExportService extends Service { .setContentTitle(title) .setStyle(new NotificationCompat.BigTextStyle().bigText(textOrEmpty)) .setContentText(textOrEmpty); - notificationManager.notify(getNotificationId(), notificationBuilder.build()); + + if (notificationManager.areNotificationsEnabled()) { + notificationManager.notify(getNotificationId(), notificationBuilder.build()); + } } protected NotificationCompat.Builder createNotification() { diff --git a/app/src/main/java/org/schabi/newpipe/player/notification/NotificationUtil.java b/app/src/main/java/org/schabi/newpipe/player/notification/NotificationUtil.java index 9b9c47b0e..be98abb7a 100644 --- a/app/src/main/java/org/schabi/newpipe/player/notification/NotificationUtil.java +++ b/app/src/main/java/org/schabi/newpipe/player/notification/NotificationUtil.java @@ -72,7 +72,9 @@ public final class NotificationUtil { notificationBuilder = createNotification(); } updateNotification(); - notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build()); + if (notificationManager.areNotificationsEnabled()) { + notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build()); + } } public synchronized void updateThumbnail() { @@ -84,7 +86,9 @@ public final class NotificationUtil { } setLargeIcon(notificationBuilder); - notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build()); + if (notificationManager.areNotificationsEnabled()) { + notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build()); + } } }