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
89cb87b2a9
commit
582f852e7a
@ -82,8 +82,10 @@ class NewVersionWorker(
|
||||
)
|
||||
|
||||
val notificationManager = NotificationManagerCompat.from(applicationContext)
|
||||
if (notificationManager.areNotificationsEnabled()) {
|
||||
notificationManager.notify(2000, notificationBuilder.build())
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(IOException::class, ReCaptchaException::class)
|
||||
private fun checkNewVersion() {
|
||||
|
||||
@ -134,8 +134,11 @@ class ErrorUtil {
|
||||
)
|
||||
)
|
||||
|
||||
NotificationManagerCompat.from(context)
|
||||
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
|
||||
|
||||
@ -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
|
||||
// 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
|
||||
// Show summary notification if enabled
|
||||
if (manager.areNotificationsEnabled()) {
|
||||
manager.notify(data.pseudoId, summaryBuilder.build())
|
||||
}
|
||||
iconLoadingTargets.remove(this) // allow it to be garbage-collected
|
||||
}
|
||||
|
||||
@ -124,11 +128,14 @@ class NotificationHelper(val context: Context) {
|
||||
channelUrl: String,
|
||||
channelIcon: Bitmap?
|
||||
) {
|
||||
for (stream in newStreams) {
|
||||
val notification = createStreamNotification(stream, serviceId, channelUrl, channelIcon)
|
||||
if (manager.areNotificationsEnabled()) {
|
||||
newStreams.forEach { stream ->
|
||||
val notification =
|
||||
createStreamNotification(stream, serviceId, channelUrl, channelIcon)
|
||||
manager.notify(stream.url.hashCode(), notification)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun createStreamNotification(
|
||||
item: StreamInfoItem,
|
||||
|
||||
@ -185,8 +185,10 @@ class FeedLoadService : Service() {
|
||||
}
|
||||
}
|
||||
|
||||
if (notificationManager.areNotificationsEnabled()) {
|
||||
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build())
|
||||
}
|
||||
}
|
||||
|
||||
// /////////////////////////////////////////////////////////////////////////
|
||||
// Notification Actions
|
||||
|
||||
@ -144,8 +144,10 @@ public abstract class BaseImportExportService extends Service {
|
||||
notificationBuilder.setContentText(text);
|
||||
}
|
||||
|
||||
if (notificationManager.areNotificationsEnabled()) {
|
||||
notificationManager.notify(getNotificationId(), notificationBuilder.build());
|
||||
}
|
||||
}
|
||||
|
||||
protected void stopService() {
|
||||
postErrorResult(null, null);
|
||||
@ -174,8 +176,11 @@ public abstract class BaseImportExportService extends Service {
|
||||
.setContentTitle(title)
|
||||
.setStyle(new NotificationCompat.BigTextStyle().bigText(textOrEmpty))
|
||||
.setContentText(textOrEmpty);
|
||||
|
||||
if (notificationManager.areNotificationsEnabled()) {
|
||||
notificationManager.notify(getNotificationId(), notificationBuilder.build());
|
||||
}
|
||||
}
|
||||
|
||||
protected NotificationCompat.Builder createNotification() {
|
||||
return new NotificationCompat.Builder(this, getString(R.string.notification_channel_id))
|
||||
|
||||
@ -72,8 +72,10 @@ public final class NotificationUtil {
|
||||
notificationBuilder = createNotification();
|
||||
}
|
||||
updateNotification();
|
||||
if (notificationManager.areNotificationsEnabled()) {
|
||||
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void updateThumbnail() {
|
||||
if (notificationBuilder != null) {
|
||||
@ -84,9 +86,11 @@ public final class NotificationUtil {
|
||||
}
|
||||
|
||||
setLargeIcon(notificationBuilder);
|
||||
if (notificationManager.areNotificationsEnabled()) {
|
||||
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized NotificationCompat.Builder createNotification() {
|
||||
if (DEBUG) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user