Use different group keys for DMs and Zaps.

This commit is contained in:
KotlinGeekDev
2023-07-29 17:04:55 +01:00
parent e8170398e3
commit 492bc76957

View File

@@ -18,7 +18,8 @@ import com.vitorpamplona.amethyst.ui.MainActivity
object NotificationUtils { object NotificationUtils {
private var dmChannel: NotificationChannel? = null private var dmChannel: NotificationChannel? = null
private var zapChannel: NotificationChannel? = null private var zapChannel: NotificationChannel? = null
const val NOTIFICATION_GROUP_KEY = "com.vitorpamplona.amethyst.NOTIFICATION" private const val DM_GROUP_KEY = "com.vitorpamplona.amethyst.DM_NOTIFICATION"
private const val ZAP_GROUP_KEY = "com.vitorpamplona.amethyst.ZAP_NOTIFICATION"
private fun getOrCreateDMChannel(applicationContext: Context): NotificationChannel { private fun getOrCreateDMChannel(applicationContext: Context): NotificationChannel {
if (dmChannel != null) return dmChannel!! if (dmChannel != null) return dmChannel!!
@@ -71,7 +72,7 @@ object NotificationUtils {
val zapChannel = getOrCreateZapChannel(applicationContext) val zapChannel = getOrCreateZapChannel(applicationContext)
val channelId = applicationContext.getString(R.string.app_notification_zaps_channel_id) val channelId = applicationContext.getString(R.string.app_notification_zaps_channel_id)
sendNotification(id, messageBody, messageTitle, pictureUrl, uri, channelId, applicationContext) sendNotification(id, messageBody, messageTitle, pictureUrl, uri, channelId, ZAP_GROUP_KEY, applicationContext)
} }
fun NotificationManager.sendDMNotification( fun NotificationManager.sendDMNotification(
@@ -85,7 +86,7 @@ object NotificationUtils {
val dmChannel = getOrCreateDMChannel(applicationContext) val dmChannel = getOrCreateDMChannel(applicationContext)
val channelId = applicationContext.getString(R.string.app_notification_dms_channel_id) val channelId = applicationContext.getString(R.string.app_notification_dms_channel_id)
sendNotification(id, messageBody, messageTitle, pictureUrl, uri, channelId, applicationContext) sendNotification(id, messageBody, messageTitle, pictureUrl, uri, channelId, DM_GROUP_KEY, applicationContext)
} }
fun NotificationManager.sendNotification( fun NotificationManager.sendNotification(
@@ -95,6 +96,7 @@ object NotificationUtils {
pictureUrl: String?, pictureUrl: String?,
uri: String, uri: String,
channelId: String, channelId: String,
notificationGroupKey: String,
applicationContext: Context applicationContext: Context
) { ) {
if (pictureUrl != null) { if (pictureUrl != null) {
@@ -111,6 +113,7 @@ object NotificationUtils {
picture = imageResult.drawable as? BitmapDrawable, picture = imageResult.drawable as? BitmapDrawable,
uri = uri, uri = uri,
channelId, channelId,
notificationGroupKey,
applicationContext = applicationContext applicationContext = applicationContext
) )
} else { } else {
@@ -121,6 +124,7 @@ object NotificationUtils {
picture = null, picture = null,
uri = uri, uri = uri,
channelId, channelId,
notificationGroupKey,
applicationContext = applicationContext applicationContext = applicationContext
) )
} }
@@ -133,6 +137,7 @@ object NotificationUtils {
picture: BitmapDrawable?, picture: BitmapDrawable?,
uri: String, uri: String,
channelId: String, channelId: String,
notificationGroupKey: String,
applicationContext: Context applicationContext: Context
) { ) {
val notId = id.hashCode() val notId = id.hashCode()
@@ -165,7 +170,7 @@ object NotificationUtils {
.setContentTitle(messageTitle) .setContentTitle(messageTitle)
.setContentText(applicationContext.getString(R.string.app_notification_private_message)) .setContentText(applicationContext.getString(R.string.app_notification_private_message))
.setLargeIcon(picture?.bitmap) .setLargeIcon(picture?.bitmap)
.setGroup(NOTIFICATION_GROUP_KEY) .setGroup(notificationGroupKey)
.setContentIntent(contentPendingIntent) .setContentIntent(contentPendingIntent)
.setPriority(NotificationCompat.PRIORITY_HIGH) .setPriority(NotificationCompat.PRIORITY_HIGH)
.setAutoCancel(true) .setAutoCancel(true)
@@ -179,7 +184,7 @@ object NotificationUtils {
.setContentTitle(messageTitle) .setContentTitle(messageTitle)
.setContentText(messageBody) .setContentText(messageBody)
.setLargeIcon(picture?.bitmap) .setLargeIcon(picture?.bitmap)
.setGroup(NOTIFICATION_GROUP_KEY) .setGroup(notificationGroupKey)
.setContentIntent(contentPendingIntent) .setContentIntent(contentPendingIntent)
.setPublicVersion(builderPublic.build()) .setPublicVersion(builderPublic.build())
.setPriority(NotificationCompat.PRIORITY_HIGH) .setPriority(NotificationCompat.PRIORITY_HIGH)