feat: Improve (battery) notification behavior (#1661)

* feat: Improve notification behavior

- Changes low battery notifications to be non-cancelable
- Cancel low battery notifications when battery level is no longer low.
- Add notification groups and improve notification settings.
- Add vibration to low battery notifications.

* Improve low battery notification

Add battery level progress bar to the low battery notification.
pull/1667/head^2
James Rich 2025-03-12 05:02:14 -05:00 zatwierdzone przez GitHub
rodzic e0cedc5e01
commit 5846bf5ee4
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
2 zmienionych plików z 20 dodań i 1 usunięć

Wyświetl plik

@ -949,6 +949,8 @@ class MeshService : Service(), Logging {
if (t.deviceMetrics.voltage > batteryPercentUnsupported &&
t.deviceMetrics.batteryLevel < batteryPercentLowThreshold) {
serviceNotifications.showOrUpdateLowBatteryNotification(it, isRemote)
} else {
serviceNotifications.cancelLowBatteryNotification(it)
}
}
}

Wyświetl plik

@ -51,6 +51,12 @@ class MeshServiceNotifications(
const val OPEN_MESSAGE_ACTION = "com.geeksville.mesh.OPEN_MESSAGE_ACTION"
const val OPEN_MESSAGE_EXTRA_CONTACT_KEY =
"com.geeksville.mesh.OPEN_MESSAGE_EXTRA_CONTACT_KEY"
const val SERVICE_GROUP = "SERVICE_NOTIFICATION_GROUP"
const val MESSAGE_GROUP = "MESSAGE_NOTIFICATION_GROUP"
const val ALERT_GROUP = "ALERT_NOTIFICATION_GROUP"
const val NEW_NODE_GROUP = "NEW_NODE_NOTIFICATION_GROUP"
const val LOW_BATTERY_GROUP = "LOW_BATTERY_NOTIFICATION_GROUP"
const val MAX_BATTERY_LEVEL = 100
}
private val notificationManager: NotificationManager get() = context.notificationManager
@ -215,6 +221,7 @@ class MeshServiceNotifications(
).apply {
lightColor = notificationLightColor
lockscreenVisibility = Notification.VISIBILITY_PUBLIC
enableVibration(true)
setShowBadge(true)
setSound(
RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION),
@ -339,6 +346,10 @@ class MeshServiceNotifications(
)
}
fun cancelLowBatteryNotification(node: NodeEntity) {
notificationManager.cancel(node.num)
}
private val openAppIntent: PendingIntent by lazy {
PendingIntent.getActivity(
context,
@ -396,6 +407,7 @@ class MeshServiceNotifications(
}
with(serviceNotificationBuilder) {
priority = NotificationCompat.PRIORITY_MIN
setGroup(SERVICE_GROUP)
setCategory(Notification.CATEGORY_SERVICE)
setOngoing(true)
setContentTitle(name)
@ -434,6 +446,7 @@ class MeshServiceNotifications(
setContentIntent(openMessageIntent(contactKey))
priority = NotificationCompat.PRIORITY_DEFAULT
setCategory(Notification.CATEGORY_MESSAGE)
setGroup(MESSAGE_GROUP)
setAutoCancel(true)
setStyle(
NotificationCompat.MessagingStyle(person)
@ -459,6 +472,7 @@ class MeshServiceNotifications(
setContentIntent(openMessageIntent(contactKey))
priority = NotificationCompat.PRIORITY_HIGH
setCategory(Notification.CATEGORY_ALARM)
setGroup(ALERT_GROUP)
setAutoCancel(true)
setStyle(
NotificationCompat.MessagingStyle(person)
@ -475,6 +489,7 @@ class MeshServiceNotifications(
}
with(newNodeSeenNotificationBuilder) {
priority = NotificationCompat.PRIORITY_DEFAULT
setGroup(NEW_NODE_GROUP)
setCategory(Notification.CATEGORY_STATUS)
setAutoCancel(true)
setContentTitle("New Node Seen: $name")
@ -508,10 +523,12 @@ class MeshServiceNotifications(
with(tempNotificationBuilder) {
priority = NotificationCompat.PRIORITY_DEFAULT
setCategory(Notification.CATEGORY_STATUS)
setAutoCancel(true)
setOngoing(true)
setGroup(LOW_BATTERY_GROUP)
setShowWhen(true)
setOnlyAlertOnce(true)
setWhen(System.currentTimeMillis())
setProgress(MAX_BATTERY_LEVEL, node.deviceMetrics.batteryLevel, false)
setContentTitle(
context.getString(R.string.low_battery_title).format(
node.shortName