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.
This commit is contained in:
James Rich 2024-10-18 10:46:56 -05:00 committed by GitHub
parent 85b0cda109
commit b73c53bc11
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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()
}