diff --git a/app/build.gradle.kts b/app/build.gradle.kts index f2c33da..5d8c6f9 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -15,8 +15,8 @@ android { applicationId = "de.timklge.karoopowerbar" minSdk = 26 targetSdk = 33 - versionCode = 7 - versionName = "1.2.2" + versionCode = 8 + versionName = "1.2.3" } signingConfigs { diff --git a/app/manifest.json b/app/manifest.json index 6e899e2..41f38a2 100644 --- a/app/manifest.json +++ b/app/manifest.json @@ -3,9 +3,9 @@ "packageName": "de.timklge.karoopowerbar", "iconUrl": "https://github.com/timklge/karoo-powerbar/releases/latest/download/karoo-powerbar.png", "latestApkUrl": "https://github.com/timklge/karoo-powerbar/releases/latest/download/app-release.apk", - "latestVersion": "1.2.2", - "latestVersionCode": 7, + "latestVersion": "1.2.3", + "latestVersionCode": 8, "developer": "timklge", "description": "Adds a colored power bar to the bottom of the screen", - "releaseNotes": "Slightly adjusts bar appearance. First build with new CI/CD pipeline." + "releaseNotes": "Add option to set bar to single color" } \ No newline at end of file diff --git a/app/src/main/kotlin/de/timklge/karoopowerbar/Extensions.kt b/app/src/main/kotlin/de/timklge/karoopowerbar/Extensions.kt index 26a9a3e..7383877 100644 --- a/app/src/main/kotlin/de/timklge/karoopowerbar/Extensions.kt +++ b/app/src/main/kotlin/de/timklge/karoopowerbar/Extensions.kt @@ -29,7 +29,8 @@ data class PowerbarSettings( val source: SelectedSource = SelectedSource.POWER, val topBarSource: SelectedSource = SelectedSource.NONE, val onlyShowWhileRiding: Boolean = true, - val showLabelOnBars: Boolean = true + val showLabelOnBars: Boolean = true, + val useZoneColors: Boolean = true, ){ companion object { val defaultSettings = Json.encodeToString(PowerbarSettings()) diff --git a/app/src/main/kotlin/de/timklge/karoopowerbar/KarooPowerbarExtension.kt b/app/src/main/kotlin/de/timklge/karoopowerbar/KarooPowerbarExtension.kt index d09017a..817bd5a 100644 --- a/app/src/main/kotlin/de/timklge/karoopowerbar/KarooPowerbarExtension.kt +++ b/app/src/main/kotlin/de/timklge/karoopowerbar/KarooPowerbarExtension.kt @@ -10,7 +10,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job import kotlinx.coroutines.launch -class KarooPowerbarExtension : KarooExtension("karoo-powerbar", "1.2.2") { +class KarooPowerbarExtension : KarooExtension("karoo-powerbar", "1.2.3") { companion object { const val TAG = "karoo-powerbar" diff --git a/app/src/main/kotlin/de/timklge/karoopowerbar/Window.kt b/app/src/main/kotlin/de/timklge/karoopowerbar/Window.kt index 023b603..8a0f770 100644 --- a/app/src/main/kotlin/de/timklge/karoopowerbar/Window.kt +++ b/app/src/main/kotlin/de/timklge/karoopowerbar/Window.kt @@ -98,7 +98,7 @@ class Window( private val karooSystem: KarooSystemService = KarooSystemService(context) - data class StreamData(val userProfile: UserProfile, val value: Double?) + data class StreamData(val userProfile: UserProfile, val value: Double?, val settings: PowerbarSettings? = null) private var serviceJob: Job? = null @@ -145,29 +145,31 @@ class Window( } private suspend fun streamHeartrate() { - val powerFlow = karooSystem.streamDataFlow(DataType.Type.HEART_RATE) + val hrFlow = karooSystem.streamDataFlow(DataType.Type.HEART_RATE) .map { (it as? StreamState.Streaming)?.dataPoint?.singleValue } .distinctUntilChanged() + val settingsFlow = context.streamSettings() + karooSystem.streamUserProfile() .distinctUntilChanged() - .combine(powerFlow) { userProfile, hr -> userProfile to hr } - .map { (userProfile, hr) -> StreamData(userProfile, hr) } + .combine(hrFlow) { userProfile, hr -> StreamData(userProfile, hr) } + .combine(settingsFlow) { streamData, settings -> streamData.copy(settings = settings) } .distinctUntilChanged() .collect { streamData -> val value = streamData.value?.roundToInt() if (value != null) { - val color = context.getColor( - getZone(streamData.userProfile.heartRateZones, value)?.colorResource - ?: R.color.zone7 - ) val minHr = streamData.userProfile.restingHr val maxHr = streamData.userProfile.maxHr val progress = remap(value.toDouble(), minHr.toDouble(), maxHr.toDouble(), 0.0, 1.0) - powerbar.progressColor = color + powerbar.progressColor = if (streamData.settings?.useZoneColors == true) { + context.getColor(getZone(streamData.userProfile.heartRateZones, value)?.colorResource ?: R.color.zone7) + } else { + context.getColor(R.color.zone0) + } powerbar.progress = progress powerbar.label = "$value" @@ -194,25 +196,27 @@ class Window( .map { (it as? StreamState.Streaming)?.dataPoint?.singleValue } .distinctUntilChanged() + val settingsFlow = context.streamSettings() + karooSystem.streamUserProfile() .distinctUntilChanged() - .combine(powerFlow) { userProfile, power -> userProfile to power } - .map { (userProfile, power) -> StreamData(userProfile, power) } + .combine(powerFlow) { userProfile, hr -> StreamData(userProfile, hr) } + .combine(settingsFlow) { streamData, settings -> streamData.copy(settings = settings) } .distinctUntilChanged() .collect { streamData -> val value = streamData.value?.roundToInt() if (value != null) { - val color = context.getColor( - getZone(streamData.userProfile.powerZones, value)?.colorResource - ?: R.color.zone7 - ) val minPower = streamData.userProfile.powerZones.first().min val maxPower = streamData.userProfile.powerZones.last().min + 50 val progress = remap(value.toDouble(), minPower.toDouble(), maxPower.toDouble(), 0.0, 1.0) - powerbar.progressColor = color + powerbar.progressColor = if (streamData.settings?.useZoneColors == true) { + context.getColor(getZone(streamData.userProfile.powerZones, value)?.colorResource ?: R.color.zone7) + } else { + context.getColor(R.color.zone0) + } powerbar.progress = progress powerbar.label = "${value}W" diff --git a/app/src/main/kotlin/de/timklge/karoopowerbar/screens/MainScreen.kt b/app/src/main/kotlin/de/timklge/karoopowerbar/screens/MainScreen.kt index 67b9445..2dc208f 100644 --- a/app/src/main/kotlin/de/timklge/karoopowerbar/screens/MainScreen.kt +++ b/app/src/main/kotlin/de/timklge/karoopowerbar/screens/MainScreen.kt @@ -70,6 +70,7 @@ fun MainScreen() { var givenPermissions by remember { mutableStateOf(false) } var onlyShowWhileRiding by remember { mutableStateOf(false) } + var colorBasedOnZones by remember { mutableStateOf(false) } var showLabelOnBars by remember { mutableStateOf(true) } LaunchedEffect(Unit) { @@ -80,6 +81,7 @@ fun MainScreen() { topSelectedSource = settings.topBarSource onlyShowWhileRiding = settings.onlyShowWhileRiding showLabelOnBars = settings.showLabelOnBars + colorBasedOnZones = settings.useZoneColors } } @@ -130,6 +132,12 @@ fun MainScreen() { } } + Row(verticalAlignment = Alignment.CenterVertically) { + Switch(checked = colorBasedOnZones, onCheckedChange = { colorBasedOnZones = it}) + Spacer(modifier = Modifier.width(10.dp)) + Text("Color based on HR / power zones") + } + Row(verticalAlignment = Alignment.CenterVertically) { Switch(checked = showLabelOnBars, onCheckedChange = { showLabelOnBars = it}) Spacer(modifier = Modifier.width(10.dp)) @@ -147,7 +155,8 @@ fun MainScreen() { .height(50.dp), onClick = { val newSettings = PowerbarSettings( source = bottomSelectedSource, topBarSource = topSelectedSource, - onlyShowWhileRiding = onlyShowWhileRiding, showLabelOnBars = showLabelOnBars + onlyShowWhileRiding = onlyShowWhileRiding, showLabelOnBars = showLabelOnBars, + useZoneColors = colorBasedOnZones ) coroutineScope.launch {