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
|
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(
|
constructor(to: String?, channel: Int, waypoint: MeshProtos.Waypoint) : this(
|
||||||
to = to,
|
to = to,
|
||||||
bytes = waypoint.toByteArray(),
|
bytes = waypoint.toByteArray(),
|
||||||
|
|
|
@ -305,7 +305,7 @@ class MeshService : Service(), Logging {
|
||||||
serviceNotifications.showAlertNotification(
|
serviceNotifications.showAlertNotification(
|
||||||
contactKey,
|
contactKey,
|
||||||
getSenderName(dataPacket),
|
getSenderName(dataPacket),
|
||||||
dataPacket.text ?: getString(R.string.critical_alert)
|
dataPacket.alert ?: getString(R.string.critical_alert)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,11 +44,13 @@ class MeshServiceNotifications(
|
||||||
private val context: Context
|
private val context: Context
|
||||||
) {
|
) {
|
||||||
|
|
||||||
val notificationLightColor = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
val notificationLightColor by lazy {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
context.getColor(R.color.colorPrimary)
|
context.getColor(R.color.colorPrimary)
|
||||||
} else {
|
} else {
|
||||||
Color.GREEN
|
Color.GREEN
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val FIFTEEN_MINUTES_IN_MILLIS = 15L * 60 * 1000
|
private const val FIFTEEN_MINUTES_IN_MILLIS = 15L * 60 * 1000
|
||||||
|
@ -361,7 +363,7 @@ class MeshServiceNotifications(
|
||||||
with(alertNotificationBuilder) {
|
with(alertNotificationBuilder) {
|
||||||
setContentIntent(openMessageIntent(contactKey))
|
setContentIntent(openMessageIntent(contactKey))
|
||||||
priority = NotificationCompat.PRIORITY_HIGH
|
priority = NotificationCompat.PRIORITY_HIGH
|
||||||
setCategory(Notification.CATEGORY_MESSAGE)
|
setCategory(Notification.CATEGORY_ALARM)
|
||||||
setAutoCancel(true)
|
setAutoCancel(true)
|
||||||
setStyle(
|
setStyle(
|
||||||
NotificationCompat.MessagingStyle(person)
|
NotificationCompat.MessagingStyle(person)
|
||||||
|
|
Ładowanie…
Reference in New Issue