From b73c53bc1136420f1b1da6fb3d05385e2708f684 Mon Sep 17 00:00:00 2001 From: James Rich <2199651+jamesarich@users.noreply.github.com> Date: Fri, 18 Oct 2024 10:46:56 -0500 Subject: [PATCH] feat: Add Chronometer and Timestamp to Service Notification (#1327) Adds a chronometer to the service notification, counting down to the next stats update. Also adds timestamps to the service notification, message notification, and new node seen notification. --- .../mesh/service/MeshServiceNotifications.kt | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/service/MeshServiceNotifications.kt b/app/src/main/java/com/geeksville/mesh/service/MeshServiceNotifications.kt index 2b5b01a92..d603b0a35 100644 --- a/app/src/main/java/com/geeksville/mesh/service/MeshServiceNotifications.kt +++ b/app/src/main/java/com/geeksville/mesh/service/MeshServiceNotifications.kt @@ -163,7 +163,11 @@ class MeshServiceNotifications( val statsString = formatStatsString(localStats, currentStatsUpdatedAtMillis) notificationManager.notify( notifyId, - createServiceStateNotification(summaryString.orEmpty(), statsString) + createServiceStateNotification( + name = summaryString.orEmpty(), + message = statsString, + nextUpdateAt = currentStatsUpdatedAtMillis?.plus(FIFTEEN_MINUTES_IN_MILLIS) + ) ) } @@ -226,7 +230,11 @@ class MeshServiceNotifications( } lateinit var serviceNotificationBuilder: NotificationCompat.Builder - fun createServiceStateNotification(name: String, message: String? = null): Notification { + fun createServiceStateNotification( + name: String, + message: String? = null, + nextUpdateAt: Long? = null + ): Notification { if (!::serviceNotificationBuilder.isInitialized) { serviceNotificationBuilder = commonBuilder(channelId) } @@ -242,6 +250,16 @@ class MeshServiceNotifications( .bigText(message), ) } + nextUpdateAt?.let { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + setWhen(it) + setUsesChronometer(true) + setChronometerCountDown(true) + } + } ?: { + setWhen(System.currentTimeMillis()) + } + setShowWhen(true) } return serviceNotificationBuilder.build() } @@ -261,6 +279,8 @@ class MeshServiceNotifications( NotificationCompat.BigTextStyle() .bigText(message), ) + setWhen(System.currentTimeMillis()) + setShowWhen(true) } return messageNotificationBuilder.build() } @@ -282,6 +302,8 @@ class MeshServiceNotifications( .bigText(message), ) } + setWhen(System.currentTimeMillis()) + setShowWhen(true) } return newNodeSeenNotificationBuilder.build() }