From 84e03b126772389e744dc71066361242edcb563c Mon Sep 17 00:00:00 2001 From: Janne Mareike Koschinski <mail@justjanne.de> Date: Sat, 23 Nov 2024 15:30:37 +0100 Subject: [PATCH] fix: unresponsive notifications --- .../QuasseldroidNotificationManager.kt | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/de/kuschku/quasseldroid/service/QuasseldroidNotificationManager.kt b/app/src/main/java/de/kuschku/quasseldroid/service/QuasseldroidNotificationManager.kt index e26ce8a87..4d0911c5d 100644 --- a/app/src/main/java/de/kuschku/quasseldroid/service/QuasseldroidNotificationManager.kt +++ b/app/src/main/java/de/kuschku/quasseldroid/service/QuasseldroidNotificationManager.kt @@ -40,6 +40,7 @@ import androidx.core.app.Person import androidx.core.app.RemoteInput import androidx.core.graphics.drawable.IconCompat import de.kuschku.libquassel.protocol.Buffer_Type +import de.kuschku.libquassel.protocol.MsgId import de.kuschku.libquassel.util.flag.hasFlag import de.kuschku.quasseldroid.R import de.kuschku.quasseldroid.settings.NotificationSettings @@ -55,6 +56,14 @@ class QuasseldroidNotificationManager @Inject constructor(private val context: C private val notificationManagerCompat = NotificationManagerCompat.from(context) private var translatedLocale: Context = LocaleHelper.setLocale(context) + @JvmInline + private value class RequestCode(val messageId: MsgId) { + val open: Int get() = messageId.id.toInt() * 8 + 1 + val reply: Int get() = messageId.id.toInt() * 8 + 2 + val markRead: Int get() = messageId.id.toInt() * 8 + 3 + val delete: Int get() = messageId.id.toInt() * 8 + 4 + } + fun updateTranslation() { translatedLocale = LocaleHelper.setLocale(context) } @@ -118,9 +127,12 @@ class QuasseldroidNotificationManager @Inject constructor(private val context: C selfInfo: SelfInfo, notifications: List<NotificationMessage>, isLoud: Boolean, isConnected: Boolean ): Handle { + val latestMessage = notifications.last().messageId + val requestCode = RequestCode(latestMessage) + val pendingIntentOpen = PendingIntent.getActivity( context.applicationContext, - System.currentTimeMillis().toInt(), + requestCode.open, ChatActivity.intent(context.applicationContext, bufferId = buffer.id).apply { flags = Intent.FLAG_ACTIVITY_CLEAR_TOP }, @@ -134,7 +146,7 @@ class QuasseldroidNotificationManager @Inject constructor(private val context: C val replyPendingIntent = PendingIntent.getService( context.applicationContext, - System.currentTimeMillis().toInt(), + requestCode.reply, QuasselService.intent( context, bufferId = buffer.id @@ -145,11 +157,11 @@ class QuasseldroidNotificationManager @Inject constructor(private val context: C val markReadPendingIntent = PendingIntent.getService( context.applicationContext, - System.currentTimeMillis().toInt(), + requestCode.markRead, QuasselService.intent( context, bufferId = buffer.id, - markReadMessage = notifications.last().messageId + markReadMessage = latestMessage ), if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) 0 else PendingIntent.FLAG_MUTABLE @@ -157,11 +169,11 @@ class QuasseldroidNotificationManager @Inject constructor(private val context: C val deletePendingIntent = PendingIntent.getService( context.applicationContext, - System.currentTimeMillis().toInt(), + requestCode.delete, QuasselService.intent( context, bufferId = buffer.id, - hideMessage = notifications.last().messageId + hideMessage = latestMessage ), if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) 0 else PendingIntent.FLAG_MUTABLE -- GitLab