fixing notifications being dismissed early when there's only 1 left and fixes wrong room being opened when tapping notification

This commit is contained in:
Adam Brown 2022-04-26 21:57:56 +01:00
parent f71f7e9099
commit f3f256e0d3
2 changed files with 10 additions and 3 deletions

View File

@ -4,8 +4,11 @@ import android.app.Notification
import android.app.PendingIntent import android.app.PendingIntent
import android.app.Person import android.app.Person
import android.content.Context import android.content.Context
import android.content.Intent
import android.os.Build import android.os.Build
import androidx.annotation.RequiresApi 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.imageloader.IconLoader
import app.dapk.st.matrix.sync.RoomEvent import app.dapk.st.matrix.sync.RoomEvent
import app.dapk.st.matrix.sync.RoomOverview import app.dapk.st.matrix.sync.RoomOverview
@ -28,7 +31,7 @@ class NotificationFactory(
} }
} }
val summaryNotification = if (notifications.filterIsInstance<NotificationDelegate.Room>().size > 1) { val summaryNotification = if (notifications.filterIsInstance<NotificationDelegate.Room>().isNotEmpty()) {
createSummary(notifications) createSummary(notifications)
} else { } else {
null null
@ -102,8 +105,9 @@ class NotificationFactory(
val openRoomIntent = PendingIntent.getActivity( val openRoomIntent = PendingIntent.getActivity(
context, context,
roomOverview.roomId.hashCode(), roomOverview.roomId.hashCode(),
MessengerActivity.newInstance(context, roomOverview.roomId), MessengerActivity.newInstance(context, roomOverview.roomId)
PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK),
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
) )
return NotificationDelegate.Room( return NotificationDelegate.Room(

View File

@ -2,7 +2,9 @@ package app.dapk.st.notifications
import android.app.Notification import android.app.Notification
import android.app.NotificationManager import android.app.NotificationManager
import app.dapk.st.core.AppLogTag
import app.dapk.st.core.extensions.ifNull 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.common.RoomId
import app.dapk.st.matrix.sync.RoomEvent import app.dapk.st.matrix.sync.RoomEvent
import app.dapk.st.matrix.sync.RoomOverview import app.dapk.st.matrix.sync.RoomOverview
@ -20,6 +22,7 @@ class NotificationRenderer(
val notifications = notificationFactory.createNotifications(result) val notifications = notificationFactory.createNotifications(result)
notifications.summaryNotification.ifNull { notifications.summaryNotification.ifNull {
log(AppLogTag.NOTIFICATION, "cancelling summary")
notificationManager.cancel(SUMMARY_NOTIFICATION_ID) notificationManager.cancel(SUMMARY_NOTIFICATION_ID)
} }