Add missing permission checks for notifications
Notifications can be disabled manually even after permission has been granted once. Always check if they are enabled before notifying the user. Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
parent
d33c3737ec
commit
d35d5fa5d4
6 changed files with 38 additions and 15 deletions
|
|
@ -82,7 +82,9 @@ class NewVersionWorker(
|
||||||
)
|
)
|
||||||
|
|
||||||
val notificationManager = NotificationManagerCompat.from(applicationContext)
|
val notificationManager = NotificationManagerCompat.from(applicationContext)
|
||||||
notificationManager.notify(2000, notificationBuilder.build())
|
if (notificationManager.areNotificationsEnabled()) {
|
||||||
|
notificationManager.notify(2000, notificationBuilder.build())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Throws(IOException::class, ReCaptchaException::class)
|
@Throws(IOException::class, ReCaptchaException::class)
|
||||||
|
|
|
||||||
|
|
@ -134,8 +134,11 @@ class ErrorUtil {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
NotificationManagerCompat.from(context)
|
val notificationManager = NotificationManagerCompat.from(context)
|
||||||
.notify(ERROR_REPORT_NOTIFICATION_ID, notificationBuilder.build())
|
if (notificationManager.areNotificationsEnabled()) {
|
||||||
|
notificationManager
|
||||||
|
.notify(ERROR_REPORT_NOTIFICATION_ID, notificationBuilder.build())
|
||||||
|
}
|
||||||
|
|
||||||
ContextCompat.getMainExecutor(context).execute {
|
ContextCompat.getMainExecutor(context).execute {
|
||||||
// since the notification is silent, also show a toast, otherwise the user is confused
|
// since the notification is silent, also show a toast, otherwise the user is confused
|
||||||
|
|
|
||||||
|
|
@ -92,8 +92,10 @@ class NotificationHelper(val context: Context) {
|
||||||
// Show individual stream notifications, set channel icon only if there is actually
|
// Show individual stream notifications, set channel icon only if there is actually
|
||||||
// one
|
// one
|
||||||
showStreamNotifications(newStreams, data.serviceId, data.url, bitmap)
|
showStreamNotifications(newStreams, data.serviceId, data.url, bitmap)
|
||||||
// Show summary notification
|
// Show summary notification if enabled
|
||||||
manager.notify(data.pseudoId, summaryBuilder.build())
|
if (manager.areNotificationsEnabled()) {
|
||||||
|
manager.notify(data.pseudoId, summaryBuilder.build())
|
||||||
|
}
|
||||||
|
|
||||||
iconLoadingTargets.remove(this) // allow it to be garbage-collected
|
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) {
|
override fun onBitmapFailed(e: Exception, errorDrawable: Drawable) {
|
||||||
// Show individual stream notifications
|
// Show individual stream notifications
|
||||||
showStreamNotifications(newStreams, data.serviceId, data.url, null)
|
showStreamNotifications(newStreams, data.serviceId, data.url, null)
|
||||||
// Show summary notification
|
// Show summary notification if enabled
|
||||||
manager.notify(data.pseudoId, summaryBuilder.build())
|
if (manager.areNotificationsEnabled()) {
|
||||||
|
manager.notify(data.pseudoId, summaryBuilder.build())
|
||||||
|
}
|
||||||
iconLoadingTargets.remove(this) // allow it to be garbage-collected
|
iconLoadingTargets.remove(this) // allow it to be garbage-collected
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -124,9 +128,12 @@ class NotificationHelper(val context: Context) {
|
||||||
channelUrl: String,
|
channelUrl: String,
|
||||||
channelIcon: Bitmap?
|
channelIcon: Bitmap?
|
||||||
) {
|
) {
|
||||||
for (stream in newStreams) {
|
if (manager.areNotificationsEnabled()) {
|
||||||
val notification = createStreamNotification(stream, serviceId, channelUrl, channelIcon)
|
newStreams.forEach { stream ->
|
||||||
manager.notify(stream.url.hashCode(), notification)
|
val notification =
|
||||||
|
createStreamNotification(stream, serviceId, channelUrl, channelIcon)
|
||||||
|
manager.notify(stream.url.hashCode(), notification)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -185,7 +185,9 @@ class FeedLoadService : Service() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build())
|
if (notificationManager.areNotificationsEnabled()) {
|
||||||
|
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// /////////////////////////////////////////////////////////////////////////
|
// /////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
||||||
|
|
@ -144,7 +144,9 @@ public abstract class BaseImportExportService extends Service {
|
||||||
notificationBuilder.setContentText(text);
|
notificationBuilder.setContentText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
notificationManager.notify(getNotificationId(), notificationBuilder.build());
|
if (notificationManager.areNotificationsEnabled()) {
|
||||||
|
notificationManager.notify(getNotificationId(), notificationBuilder.build());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void stopService() {
|
protected void stopService() {
|
||||||
|
|
@ -174,7 +176,10 @@ public abstract class BaseImportExportService extends Service {
|
||||||
.setContentTitle(title)
|
.setContentTitle(title)
|
||||||
.setStyle(new NotificationCompat.BigTextStyle().bigText(textOrEmpty))
|
.setStyle(new NotificationCompat.BigTextStyle().bigText(textOrEmpty))
|
||||||
.setContentText(textOrEmpty);
|
.setContentText(textOrEmpty);
|
||||||
notificationManager.notify(getNotificationId(), notificationBuilder.build());
|
|
||||||
|
if (notificationManager.areNotificationsEnabled()) {
|
||||||
|
notificationManager.notify(getNotificationId(), notificationBuilder.build());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected NotificationCompat.Builder createNotification() {
|
protected NotificationCompat.Builder createNotification() {
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,9 @@ public final class NotificationUtil {
|
||||||
notificationBuilder = createNotification();
|
notificationBuilder = createNotification();
|
||||||
}
|
}
|
||||||
updateNotification();
|
updateNotification();
|
||||||
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
|
if (notificationManager.areNotificationsEnabled()) {
|
||||||
|
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void updateThumbnail() {
|
public synchronized void updateThumbnail() {
|
||||||
|
|
@ -84,7 +86,9 @@ public final class NotificationUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
setLargeIcon(notificationBuilder);
|
setLargeIcon(notificationBuilder);
|
||||||
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
|
if (notificationManager.areNotificationsEnabled()) {
|
||||||
|
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue