kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
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
rodzic
deae9b17b6
commit
1d867facf0
|
@ -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(),
|
||||
|
|
|
@ -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)
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Ładowanie…
Reference in New Issue