Skip to content

Commit

Permalink
Notification: "when_relative" for "chronometer" (#4273)
Browse files Browse the repository at this point in the history
"timeout" is relative, but "when" is absolute by default.

It is now possible to synchronize timers in seconds without time difference:
```yaml
timeout: 120
chronometer: "true"
when: 120
when_relative: "true"
```
  • Loading branch information
Roffild authored Mar 22, 2024
1 parent 5cda2e3 commit 5729bbe
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class MessagingManager @Inject constructor(
const val PERSISTENT = "persistent"
const val CHRONOMETER = "chronometer"
const val WHEN = "when"
const val WHEN_RELATIVE = "when_relative"
const val CAR_UI = "car_ui"
const val KEY_TEXT_REPLY = "key_text_reply"
const val INTENT_CLASS_NAME = "intent_class_name"
Expand Down Expand Up @@ -980,10 +981,15 @@ class MessagingManager @Inject constructor(
data: Map<String, String>
) {
try { // Without this, a non-numeric when value will crash the app
val notificationWhen = data[WHEN]?.toLongOrNull()?.times(1000) ?: 0
var notificationWhen = data[WHEN]?.toLongOrNull()?.times(1000) ?: 0
val isRelative = data[WHEN_RELATIVE]?.toBoolean() ?: false
val usesChronometer = data[CHRONOMETER]?.toBoolean() ?: false

if (notificationWhen != 0L) {
if (isRelative) {
notificationWhen += System.currentTimeMillis()
}

builder.setWhen(notificationWhen)
builder.setUsesChronometer(usesChronometer)

Expand Down

0 comments on commit 5729bbe

Please sign in to comment.