fix #8: Add delay between reminders triggered at the same time
This commit is contained in:
parent
9ab7a85ab1
commit
85012bf228
@ -13,8 +13,8 @@ android {
|
|||||||
applicationId = "de.timklge.karooreminder"
|
applicationId = "de.timklge.karooreminder"
|
||||||
minSdk = 26
|
minSdk = 26
|
||||||
targetSdk = 34
|
targetSdk = 34
|
||||||
versionCode = 6
|
versionCode = 7
|
||||||
versionName = "1.0.5"
|
versionName = "1.0.6"
|
||||||
}
|
}
|
||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
|
|||||||
@ -3,8 +3,8 @@
|
|||||||
"packageName": "de.timklge.karooreminder",
|
"packageName": "de.timklge.karooreminder",
|
||||||
"iconUrl": "https://github.com/timklge/karoo-reminder/releases/latest/download/karoo-reminder.png",
|
"iconUrl": "https://github.com/timklge/karoo-reminder/releases/latest/download/karoo-reminder.png",
|
||||||
"latestApkUrl": "https://github.com/timklge/karoo-reminder/releases/latest/download/app-release.apk",
|
"latestApkUrl": "https://github.com/timklge/karoo-reminder/releases/latest/download/app-release.apk",
|
||||||
"latestVersion": "1.0.5",
|
"latestVersion": "1.0.6",
|
||||||
"latestVersionCode": 6,
|
"latestVersionCode": 7,
|
||||||
"developer": "timklge",
|
"developer": "timklge",
|
||||||
"description": "Simple karoo extension that shows in-ride alerts every X minutes",
|
"description": "Simple karoo extension that shows in-ride alerts every X minutes",
|
||||||
"releaseNotes": "Added display duration setting, bluetooth alert sound"
|
"releaseNotes": "Added display duration setting, bluetooth alert sound"
|
||||||
|
|||||||
@ -18,6 +18,7 @@ import kotlinx.coroutines.CoroutineScope
|
|||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
|
import kotlinx.coroutines.flow.collectLatest
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
import kotlinx.coroutines.flow.drop
|
import kotlinx.coroutines.flow.drop
|
||||||
@ -27,7 +28,7 @@ import kotlinx.coroutines.flow.mapNotNull
|
|||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
|
|
||||||
class KarooReminderExtension : KarooExtension("karoo-reminder", "1.0.5") {
|
class KarooReminderExtension : KarooExtension("karoo-reminder", "1.0.6") {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val TAG = "karoo-reminder"
|
const val TAG = "karoo-reminder"
|
||||||
@ -69,35 +70,39 @@ class KarooReminderExtension : KarooExtension("karoo-reminder", "1.0.5") {
|
|||||||
.filterNot { it == 0 }
|
.filterNot { it == 0 }
|
||||||
.combine(preferences) { elapsedMinutes, reminders -> elapsedMinutes to reminders}
|
.combine(preferences) { elapsedMinutes, reminders -> elapsedMinutes to reminders}
|
||||||
.distinctUntilChanged { old, new -> old.first == new.first }
|
.distinctUntilChanged { old, new -> old.first == new.first }
|
||||||
.collect { (elapsedMinutes, reminders) ->
|
.collectLatest { (elapsedMinutes, reminders) ->
|
||||||
reminders
|
val rs = reminders
|
||||||
.filter { reminder -> reminder.isActive && elapsedMinutes % reminder.interval == 0 }
|
.filter { reminder -> reminder.isActive && elapsedMinutes % reminder.interval == 0 }
|
||||||
.forEach { reminder ->
|
|
||||||
karooSystem.dispatch(TurnScreenOn)
|
|
||||||
|
|
||||||
val intent = Intent("de.timklge.HIDE_POWERBAR").apply {
|
for (reminder in rs){
|
||||||
putExtra("duration", (if(reminder.isAutoDismiss) reminder.autoDismissSeconds * 1000L else 15_000L) + 1000L)
|
karooSystem.dispatch(TurnScreenOn)
|
||||||
putExtra("location", "top")
|
|
||||||
}
|
|
||||||
|
|
||||||
delay(1_000)
|
val intent = Intent("de.timklge.HIDE_POWERBAR").apply {
|
||||||
applicationContext.sendBroadcast(intent)
|
putExtra("duration", (if(reminder.isAutoDismiss) reminder.autoDismissSeconds * 1000L else 15_000L) + 1000L)
|
||||||
|
putExtra("location", "top")
|
||||||
|
}
|
||||||
|
|
||||||
if (reminder.tone != ReminderBeepPattern.NO_TONES){
|
delay(1_000)
|
||||||
karooSystem.dispatch(PlayBeepPattern(reminder.tone.tones))
|
applicationContext.sendBroadcast(intent)
|
||||||
mediaPlayer.start()
|
|
||||||
}
|
if (reminder.tone != ReminderBeepPattern.NO_TONES){
|
||||||
karooSystem.dispatch(
|
karooSystem.dispatch(PlayBeepPattern(reminder.tone.tones))
|
||||||
InRideAlert(
|
mediaPlayer.start()
|
||||||
id = "reminder-${reminder.id}-${elapsedMinutes}",
|
}
|
||||||
detail = reminder.text,
|
karooSystem.dispatch(
|
||||||
title = reminder.name,
|
InRideAlert(
|
||||||
autoDismissMs = if(reminder.isAutoDismiss) reminder.autoDismissSeconds * 1000L else null,
|
id = "reminder-${reminder.id}-${elapsedMinutes}",
|
||||||
icon = R.drawable.ic_launcher,
|
detail = reminder.text,
|
||||||
textColor = R.color.white,
|
title = reminder.name,
|
||||||
backgroundColor = reminder.getResourceColor(applicationContext)
|
autoDismissMs = if(reminder.isAutoDismiss) reminder.autoDismissSeconds * 1000L else null,
|
||||||
),
|
icon = R.drawable.ic_launcher,
|
||||||
)
|
textColor = R.color.white,
|
||||||
|
backgroundColor = reminder.getResourceColor(applicationContext)
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
val delayMs = if(reminder.isAutoDismiss) reminder.autoDismissSeconds * 1000L else 20000L
|
||||||
|
delay(delayMs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user