Made notifications for update silent.

This commit is contained in:
Koen J
2025-12-03 17:33:41 +01:00
parent 68886502d1
commit 7f77c39296
2 changed files with 13 additions and 5 deletions
@@ -36,12 +36,17 @@ object UpdateNotificationManager {
fun ensureChannel(context: Context) { fun ensureChannel(context: Context) {
val manager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager val manager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
if (manager.getNotificationChannel(CHANNEL_ID) == null) { if (manager.getNotificationChannel(CHANNEL_ID) == null) {
val channel = NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT) val channel = NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT).apply {
channel.description = CHANNEL_DESCRIPTION description = CHANNEL_DESCRIPTION
enableVibration(false)
enableLights(false)
setSound(null, null)
}
manager.createNotificationChannel(channel) manager.createNotificationChannel(channel)
} }
} }
fun showUpdateAvailableNotification(context: Context, version: Int) { fun showUpdateAvailableNotification(context: Context, version: Int) {
if (ContextCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { if (ContextCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
return return
@@ -70,6 +75,7 @@ object UpdateNotificationManager {
.setContentText("A new version ($version) is available.") .setContentText("A new version ($version) is available.")
.setPriority(NotificationCompat.PRIORITY_DEFAULT) .setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setAutoCancel(true) .setAutoCancel(true)
.setSilent(true)
.addAction(0, "Download", yesPendingIntent) .addAction(0, "Download", yesPendingIntent)
.addAction(0, "Not now", noPendingIntent) .addAction(0, "Not now", noPendingIntent)
.addAction(0, "Never", neverPendingIntent) .addAction(0, "Never", neverPendingIntent)
@@ -97,6 +103,7 @@ object UpdateNotificationManager {
.setContentText("Downloading version $version") .setContentText("Downloading version $version")
.setPriority(NotificationCompat.PRIORITY_LOW) .setPriority(NotificationCompat.PRIORITY_LOW)
.setOngoing(true) .setOngoing(true)
.setSilent(true)
.addAction(0, "Cancel", cancelPendingIntent) .addAction(0, "Cancel", cancelPendingIntent)
if (indeterminate) { if (indeterminate) {
@@ -141,6 +148,7 @@ object UpdateNotificationManager {
.setContentText("Tap to install version $version.") .setContentText("Tap to install version $version.")
.setPriority(NotificationCompat.PRIORITY_DEFAULT) .setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setAutoCancel(true) .setAutoCancel(true)
.setSilent(true)
.addAction(0, "Install", installPendingIntent) .addAction(0, "Install", installPendingIntent)
NotificationManagerCompat.from(context).notify(NOTIF_ID_READY, builder.build()) NotificationManagerCompat.from(context).notify(NOTIF_ID_READY, builder.build())
@@ -159,6 +167,7 @@ object UpdateNotificationManager {
.setContentText(error?.message ?: "Unknown error") .setContentText(error?.message ?: "Unknown error")
.setPriority(NotificationCompat.PRIORITY_DEFAULT) .setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setAutoCancel(true) .setAutoCancel(true)
.setSilent(true)
NotificationManagerCompat.from(context).notify(NOTIF_ID_READY, builder.build()) NotificationManagerCompat.from(context).notify(NOTIF_ID_READY, builder.build())
} }
@@ -445,8 +445,7 @@ fun addressScore(addr: InetAddress): Int {
fun <T> Enumeration<T>.toList(): List<T> = Collections.list(this) fun <T> Enumeration<T>.toList(): List<T> = Collections.list(this)
fun <T> RequestBuilder<T>.withMaxSizePx(maxSizePx: Int = 1920): RequestBuilder<T> { fun <T> RequestBuilder<T>.withMaxSizePx(maxSizePx: Int = 1920): RequestBuilder<T> {
return this return this/*
.downsample(DownsampleStrategy.AT_MOST) .downsample(DownsampleStrategy.AT_MOST)
.override(maxSizePx, maxSizePx) .override(maxSizePx, maxSizePx)*/
.centerInside()
} }