Refactor alert notification logic

- Change `notificationLightColor` to be lazy initialized.
- Update alert notification to use `CATEGORY_ALARM`.
- Use `dataPacket.alert` instead of `dataPacket.text` for alert content.
- Add `alert` property to `DataPacket` to handle alert messages.
pull/1515/head
James Rich 2025-02-27 14:56:43 -06:00 zatwierdzone przez James Rich
rodzic deae9b17b6
commit 1d867facf0
3 zmienionych plików z 15 dodań i 6 usunięć

Wyświetl plik

@ -85,6 +85,13 @@ data class DataPacket(
null
}
val alert: String?
get() = if (dataType == Portnums.PortNum.ALERT_APP_VALUE) {
bytes?.decodeToString()
} else {
null
}
constructor(to: String?, channel: Int, waypoint: MeshProtos.Waypoint) : this(
to = to,
bytes = waypoint.toByteArray(),

Wyświetl plik

@ -305,7 +305,7 @@ class MeshService : Service(), Logging {
serviceNotifications.showAlertNotification(
contactKey,
getSenderName(dataPacket),
dataPacket.text ?: getString(R.string.critical_alert)
dataPacket.alert ?: getString(R.string.critical_alert)
)
}

Wyświetl plik

@ -44,10 +44,12 @@ class MeshServiceNotifications(
private val context: Context
) {
val notificationLightColor = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
context.getColor(R.color.colorPrimary)
} else {
Color.GREEN
val notificationLightColor by lazy {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
context.getColor(R.color.colorPrimary)
} else {
Color.GREEN
}
}
companion object {
@ -361,7 +363,7 @@ class MeshServiceNotifications(
with(alertNotificationBuilder) {
setContentIntent(openMessageIntent(contactKey))
priority = NotificationCompat.PRIORITY_HIGH
setCategory(Notification.CATEGORY_MESSAGE)
setCategory(Notification.CATEGORY_ALARM)
setAutoCancel(true)
setStyle(
NotificationCompat.MessagingStyle(person)