forked from upstream-mirrors/quik
feat(notif): Move persistent notification to its own channel
This commit is contained in:
@@ -80,6 +80,7 @@ class NotificationManagerImpl @Inject constructor(
|
|||||||
companion object {
|
companion object {
|
||||||
const val DEFAULT_CHANNEL_ID = "notifications_default"
|
const val DEFAULT_CHANNEL_ID = "notifications_default"
|
||||||
const val BACKUP_RESTORE_CHANNEL_ID = "notifications_backup_restore"
|
const val BACKUP_RESTORE_CHANNEL_ID = "notifications_backup_restore"
|
||||||
|
const val RECEIVING_WORKER_CHANNEL_ID = "notifications_receiving_worker"
|
||||||
|
|
||||||
val VIBRATE_PATTERN = longArrayOf(0, 200, 0, 200)
|
val VIBRATE_PATTERN = longArrayOf(0, 200, 0, 200)
|
||||||
}
|
}
|
||||||
@@ -93,7 +94,7 @@ class NotificationManagerImpl @Inject constructor(
|
|||||||
|
|
||||||
// Required for running workers on Android 12 and older
|
// Required for running workers on Android 12 and older
|
||||||
override fun getForegroundNotificationForWorkersOnOlderAndroids() =
|
override fun getForegroundNotificationForWorkersOnOlderAndroids() =
|
||||||
NotificationCompat.Builder(context, DEFAULT_CHANNEL_ID)
|
NotificationCompat.Builder(context, RECEIVING_WORKER_CHANNEL_ID)
|
||||||
.setContentTitle(context.getString(R.string.notification_foreground_worker_title))
|
.setContentTitle(context.getString(R.string.notification_foreground_worker_title))
|
||||||
.setContentText(context.getString(R.string.notification_foreground_worker_text))
|
.setContentText(context.getString(R.string.notification_foreground_worker_text))
|
||||||
.setShowWhen(false)
|
.setShowWhen(false)
|
||||||
@@ -454,39 +455,56 @@ class NotificationManagerImpl @Inject constructor(
|
|||||||
*/
|
*/
|
||||||
override fun createNotificationChannel(threadId: Long) {
|
override fun createNotificationChannel(threadId: Long) {
|
||||||
|
|
||||||
// Only proceed if the android version supports notification channels, and the channel hasn't
|
// Only proceed if the android version supports notification channels
|
||||||
// already been created
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O || getNotificationChannel(threadId) != null) {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val channel = when (threadId) {
|
val channels: List<NotificationChannel> = when (threadId) {
|
||||||
0L -> NotificationChannel(DEFAULT_CHANNEL_ID, "Default", NotificationManager.IMPORTANCE_HIGH).apply {
|
0L -> listOf(
|
||||||
enableLights(true)
|
NotificationChannel(
|
||||||
lightColor = Color.WHITE
|
DEFAULT_CHANNEL_ID,
|
||||||
enableVibration(true)
|
"Default",
|
||||||
vibrationPattern = VIBRATE_PATTERN
|
NotificationManager.IMPORTANCE_HIGH
|
||||||
}
|
).apply {
|
||||||
|
|
||||||
else -> {
|
|
||||||
val conversation = conversationRepo.getConversation(threadId) ?: return
|
|
||||||
val channelId = buildNotificationChannelId(threadId)
|
|
||||||
val title = conversation.getTitle()
|
|
||||||
NotificationChannel(channelId, title, NotificationManager.IMPORTANCE_HIGH).apply {
|
|
||||||
enableLights(true)
|
enableLights(true)
|
||||||
lightColor = Color.WHITE
|
lightColor = Color.WHITE
|
||||||
enableVibration(true)
|
enableVibration(true)
|
||||||
vibrationPattern = VIBRATE_PATTERN
|
vibrationPattern = VIBRATE_PATTERN
|
||||||
lockscreenVisibility = Notification.VISIBILITY_PUBLIC
|
},
|
||||||
setSound(prefs.ringtone().get().let(Uri::parse), AudioAttributes.Builder()
|
NotificationChannel(
|
||||||
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
|
RECEIVING_WORKER_CHANNEL_ID,
|
||||||
.setContentType(AudioAttributes.CONTENT_TYPE_SPEECH)
|
context.getString(R.string.notification_foreground_worker_channel_name),
|
||||||
.build())
|
NotificationManager.IMPORTANCE_LOW
|
||||||
}
|
).apply {
|
||||||
|
enableLights(false)
|
||||||
|
enableVibration(false)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
else -> {
|
||||||
|
if (getNotificationChannel(threadId) != null) return
|
||||||
|
val conversation = conversationRepo.getConversation(threadId) ?: return
|
||||||
|
val channelId = buildNotificationChannelId(threadId)
|
||||||
|
val title = conversation.getTitle()
|
||||||
|
listOf(
|
||||||
|
NotificationChannel(channelId, title, NotificationManager.IMPORTANCE_HIGH).apply {
|
||||||
|
enableLights(true)
|
||||||
|
lightColor = Color.WHITE
|
||||||
|
enableVibration(true)
|
||||||
|
vibrationPattern = VIBRATE_PATTERN
|
||||||
|
lockscreenVisibility = Notification.VISIBILITY_PUBLIC
|
||||||
|
setSound(prefs.ringtone().get().let(Uri::parse), AudioAttributes.Builder()
|
||||||
|
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
|
||||||
|
.setContentType(AudioAttributes.CONTENT_TYPE_SPEECH)
|
||||||
|
.build())
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
notificationManager.createNotificationChannel(channel)
|
for (channel in channels)
|
||||||
|
notificationManager.createNotificationChannel(channel)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -519,6 +519,7 @@
|
|||||||
<string name="notification_message_failed_text">The message to %s failed to send</string>
|
<string name="notification_message_failed_text">The message to %s failed to send</string>
|
||||||
<string name="notification_foreground_worker_title">Receiving message</string>
|
<string name="notification_foreground_worker_title">Receiving message</string>
|
||||||
<string name="notification_foreground_worker_text">On Android 12 and older, a notification is required for the background work that enables receiving messages.</string>
|
<string name="notification_foreground_worker_text">On Android 12 and older, a notification is required for the background work that enables receiving messages.</string>
|
||||||
|
<string name="notification_foreground_worker_channel_name">Message receiving worker notification</string>
|
||||||
<string name="notification_message_failed_action">Resend</string>
|
<string name="notification_message_failed_action">Resend</string>
|
||||||
|
|
||||||
<string-array name="night_modes">
|
<string-array name="night_modes">
|
||||||
|
|||||||
Reference in New Issue
Block a user