Do not re-notify warning

This commit is contained in:
S1m 2021-12-01 00:54:20 +01:00
parent 24dd9caeac
commit 830d612095
1 changed files with 6 additions and 0 deletions

View File

@ -15,6 +15,8 @@ import org.unifiedpush.distributor.nextpush.activities.MainActivity
const val NOTIF_ID_FOREGROUND = 51115 const val NOTIF_ID_FOREGROUND = 51115
const val NOTIF_ID_WARNING = 51215 const val NOTIF_ID_WARNING = 51215
private var warningShown = false
fun createForegroundNotification(context: Context): Notification { fun createForegroundNotification(context: Context): Notification {
val appName = context.getString(R.string.app_name) val appName = context.getString(R.string.app_name)
val notificationChannelId = "$appName.Listener" val notificationChannelId = "$appName.Listener"
@ -58,6 +60,8 @@ fun createForegroundNotification(context: Context): Notification {
} }
fun createWarningNotification(context: Context) { fun createWarningNotification(context: Context) {
if (warningShown)
return
val appName = context.getString(R.string.app_name) val appName = context.getString(R.string.app_name)
val notificationChannelId = "$appName.Warning" val notificationChannelId = "$appName.Warning"
@ -101,9 +105,11 @@ fun createWarningNotification(context: Context) {
with(NotificationManagerCompat.from(context)) { with(NotificationManagerCompat.from(context)) {
notify(NOTIF_ID_WARNING, builder.build()) notify(NOTIF_ID_WARNING, builder.build())
} }
warningShown = true
} }
fun deleteWarningNotification(context: Context) { fun deleteWarningNotification(context: Context) {
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager; val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager;
notificationManager.cancel(NOTIF_ID_WARNING) notificationManager.cancel(NOTIF_ID_WARNING)
warningShown = false
} }