Configure only summary or single stream notifications to make noise.

This commit is contained in:
Isira Seneviratne 2023-04-14 16:16:28 +05:30
parent 68a0fd088b
commit 2bb22cfbae

View File

@ -139,17 +139,15 @@ class NotificationWorker(appContext: Context, parameters: WorkerParameters) :
private suspend fun createNotificationsForChannel(group: String, streams: List<StreamItem>) { private suspend fun createNotificationsForChannel(group: String, streams: List<StreamItem>) {
// Create stream notifications. These are automatically grouped on Android 7.0 and later. // Create stream notifications. These are automatically grouped on Android 7.0 and later.
if (streams.size == 1) { if (streams.size == 1) {
showStreamNotification(group, streams[0]) showStreamNotification(group, streams[0], true)
} else { } else {
streams.forEach { streams.forEach {
showStreamNotification(group, it) showStreamNotification(group, it, false)
} }
val summaryId = ++notificationId val summaryId = ++notificationId
val intentFlags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK or
Intent.FLAG_ACTIVITY_CLEAR_TASK
val intent = Intent(applicationContext, MainActivity::class.java) val intent = Intent(applicationContext, MainActivity::class.java)
.setFlags(intentFlags) .setFlags(INTENT_FLAGS)
.putExtra(IntentData.channelId, group.toID()) .putExtra(IntentData.channelId, group.toID())
val pendingIntent = PendingIntentCompat val pendingIntent = PendingIntentCompat
@ -169,18 +167,20 @@ class NotificationWorker(appContext: Context, parameters: WorkerParameters) :
.setContentIntent(pendingIntent) .setContentIntent(pendingIntent)
.setGroupSummary(true) .setGroupSummary(true)
.setStyle(summary) .setStyle(summary)
.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY)
.build() .build()
notificationManager.notify(summaryId, summaryNotification) notificationManager.notify(summaryId, summaryNotification)
} }
} }
private suspend fun showStreamNotification(group: String, stream: StreamItem) { private suspend fun showStreamNotification(
val intentFlags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK or group: String,
Intent.FLAG_ACTIVITY_CLEAR_TASK stream: StreamItem,
isSingleNotification: Boolean
) {
val intent = Intent(applicationContext, MainActivity::class.java) val intent = Intent(applicationContext, MainActivity::class.java)
.setFlags(intentFlags) .setFlags(INTENT_FLAGS)
.putExtra(IntentData.videoId, stream.url!!.toID()) .putExtra(IntentData.videoId, stream.url!!.toID())
val code = ++notificationId val code = ++notificationId
val pendingIntent = PendingIntentCompat val pendingIntent = PendingIntentCompat
@ -191,6 +191,7 @@ class NotificationWorker(appContext: Context, parameters: WorkerParameters) :
.setContentText(stream.uploaderName) .setContentText(stream.uploaderName)
// The intent that will fire when the user taps the notification // The intent that will fire when the user taps the notification
.setContentIntent(pendingIntent) .setContentIntent(pendingIntent)
.setSilent(!isSingleNotification)
// Load stream thumbnails if the relevant toggle is enabled. // Load stream thumbnails if the relevant toggle is enabled.
if (PreferenceHelper.getBoolean(PreferenceKeys.SHOW_STREAM_THUMBNAILS, false)) { if (PreferenceHelper.getBoolean(PreferenceKeys.SHOW_STREAM_THUMBNAILS, false)) {
@ -217,4 +218,9 @@ class NotificationWorker(appContext: Context, parameters: WorkerParameters) :
.setAutoCancel(true) .setAutoCancel(true)
.setGroup(group) .setGroup(group)
} }
companion object {
private const val INTENT_FLAGS = Intent.FLAG_ACTIVITY_CLEAR_TOP or
Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
}
} }