From f3f256e0d30e34ddf29c3d445925474f3d8889fb Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Tue, 26 Apr 2022 21:57:56 +0100 Subject: [PATCH] fixing notifications being dismissed early when there's only 1 left and fixes wrong room being opened when tapping notification --- .../app/dapk/st/notifications/NotificationFactory.kt | 10 +++++++--- .../app/dapk/st/notifications/NotificationRenderer.kt | 3 +++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/features/notifications/src/main/kotlin/app/dapk/st/notifications/NotificationFactory.kt b/features/notifications/src/main/kotlin/app/dapk/st/notifications/NotificationFactory.kt index 61bf94b..9c440c7 100644 --- a/features/notifications/src/main/kotlin/app/dapk/st/notifications/NotificationFactory.kt +++ b/features/notifications/src/main/kotlin/app/dapk/st/notifications/NotificationFactory.kt @@ -4,8 +4,11 @@ import android.app.Notification import android.app.PendingIntent import android.app.Person import android.content.Context +import android.content.Intent import android.os.Build import androidx.annotation.RequiresApi +import app.dapk.st.core.AppLogTag +import app.dapk.st.core.log import app.dapk.st.imageloader.IconLoader import app.dapk.st.matrix.sync.RoomEvent import app.dapk.st.matrix.sync.RoomOverview @@ -28,7 +31,7 @@ class NotificationFactory( } } - val summaryNotification = if (notifications.filterIsInstance().size > 1) { + val summaryNotification = if (notifications.filterIsInstance().isNotEmpty()) { createSummary(notifications) } else { null @@ -102,8 +105,9 @@ class NotificationFactory( val openRoomIntent = PendingIntent.getActivity( context, roomOverview.roomId.hashCode(), - MessengerActivity.newInstance(context, roomOverview.roomId), - PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE + MessengerActivity.newInstance(context, roomOverview.roomId) + .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK), + PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE ) return NotificationDelegate.Room( diff --git a/features/notifications/src/main/kotlin/app/dapk/st/notifications/NotificationRenderer.kt b/features/notifications/src/main/kotlin/app/dapk/st/notifications/NotificationRenderer.kt index 8ca8992..d380008 100644 --- a/features/notifications/src/main/kotlin/app/dapk/st/notifications/NotificationRenderer.kt +++ b/features/notifications/src/main/kotlin/app/dapk/st/notifications/NotificationRenderer.kt @@ -2,7 +2,9 @@ package app.dapk.st.notifications import android.app.Notification import android.app.NotificationManager +import app.dapk.st.core.AppLogTag import app.dapk.st.core.extensions.ifNull +import app.dapk.st.core.log import app.dapk.st.matrix.common.RoomId import app.dapk.st.matrix.sync.RoomEvent import app.dapk.st.matrix.sync.RoomOverview @@ -20,6 +22,7 @@ class NotificationRenderer( val notifications = notificationFactory.createNotifications(result) notifications.summaryNotification.ifNull { + log(AppLogTag.NOTIFICATION, "cancelling summary") notificationManager.cancel(SUMMARY_NOTIFICATION_ID) }