fix #9: Add option to set bar to fixed color
This commit is contained in:
parent
2477748ac4
commit
f5e0491df8
@ -15,8 +15,8 @@ android {
|
|||||||
applicationId = "de.timklge.karoopowerbar"
|
applicationId = "de.timklge.karoopowerbar"
|
||||||
minSdk = 26
|
minSdk = 26
|
||||||
targetSdk = 33
|
targetSdk = 33
|
||||||
versionCode = 7
|
versionCode = 8
|
||||||
versionName = "1.2.2"
|
versionName = "1.2.3"
|
||||||
}
|
}
|
||||||
|
|
||||||
signingConfigs {
|
signingConfigs {
|
||||||
|
|||||||
@ -3,9 +3,9 @@
|
|||||||
"packageName": "de.timklge.karoopowerbar",
|
"packageName": "de.timklge.karoopowerbar",
|
||||||
"iconUrl": "https://github.com/timklge/karoo-powerbar/releases/latest/download/karoo-powerbar.png",
|
"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",
|
"latestApkUrl": "https://github.com/timklge/karoo-powerbar/releases/latest/download/app-release.apk",
|
||||||
"latestVersion": "1.2.2",
|
"latestVersion": "1.2.3",
|
||||||
"latestVersionCode": 7,
|
"latestVersionCode": 8,
|
||||||
"developer": "timklge",
|
"developer": "timklge",
|
||||||
"description": "Adds a colored power bar to the bottom of the screen",
|
"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"
|
||||||
}
|
}
|
||||||
@ -29,7 +29,8 @@ data class PowerbarSettings(
|
|||||||
val source: SelectedSource = SelectedSource.POWER,
|
val source: SelectedSource = SelectedSource.POWER,
|
||||||
val topBarSource: SelectedSource = SelectedSource.NONE,
|
val topBarSource: SelectedSource = SelectedSource.NONE,
|
||||||
val onlyShowWhileRiding: Boolean = true,
|
val onlyShowWhileRiding: Boolean = true,
|
||||||
val showLabelOnBars: Boolean = true
|
val showLabelOnBars: Boolean = true,
|
||||||
|
val useZoneColors: Boolean = true,
|
||||||
){
|
){
|
||||||
companion object {
|
companion object {
|
||||||
val defaultSettings = Json.encodeToString(PowerbarSettings())
|
val defaultSettings = Json.encodeToString(PowerbarSettings())
|
||||||
|
|||||||
@ -10,7 +10,7 @@ import kotlinx.coroutines.Dispatchers
|
|||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
class KarooPowerbarExtension : KarooExtension("karoo-powerbar", "1.2.2") {
|
class KarooPowerbarExtension : KarooExtension("karoo-powerbar", "1.2.3") {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val TAG = "karoo-powerbar"
|
const val TAG = "karoo-powerbar"
|
||||||
|
|||||||
@ -98,7 +98,7 @@ class Window(
|
|||||||
|
|
||||||
private val karooSystem: KarooSystemService = KarooSystemService(context)
|
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
|
private var serviceJob: Job? = null
|
||||||
|
|
||||||
@ -145,29 +145,31 @@ class Window(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun streamHeartrate() {
|
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 }
|
.map { (it as? StreamState.Streaming)?.dataPoint?.singleValue }
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
|
|
||||||
|
val settingsFlow = context.streamSettings()
|
||||||
|
|
||||||
karooSystem.streamUserProfile()
|
karooSystem.streamUserProfile()
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.combine(powerFlow) { userProfile, hr -> userProfile to hr }
|
.combine(hrFlow) { userProfile, hr -> StreamData(userProfile, hr) }
|
||||||
.map { (userProfile, hr) -> StreamData(userProfile, hr) }
|
.combine(settingsFlow) { streamData, settings -> streamData.copy(settings = settings) }
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.collect { streamData ->
|
.collect { streamData ->
|
||||||
val value = streamData.value?.roundToInt()
|
val value = streamData.value?.roundToInt()
|
||||||
|
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
val color = context.getColor(
|
|
||||||
getZone(streamData.userProfile.heartRateZones, value)?.colorResource
|
|
||||||
?: R.color.zone7
|
|
||||||
)
|
|
||||||
val minHr = streamData.userProfile.restingHr
|
val minHr = streamData.userProfile.restingHr
|
||||||
val maxHr = streamData.userProfile.maxHr
|
val maxHr = streamData.userProfile.maxHr
|
||||||
val progress =
|
val progress =
|
||||||
remap(value.toDouble(), minHr.toDouble(), maxHr.toDouble(), 0.0, 1.0)
|
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.progress = progress
|
||||||
powerbar.label = "$value"
|
powerbar.label = "$value"
|
||||||
|
|
||||||
@ -194,25 +196,27 @@ class Window(
|
|||||||
.map { (it as? StreamState.Streaming)?.dataPoint?.singleValue }
|
.map { (it as? StreamState.Streaming)?.dataPoint?.singleValue }
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
|
|
||||||
|
val settingsFlow = context.streamSettings()
|
||||||
|
|
||||||
karooSystem.streamUserProfile()
|
karooSystem.streamUserProfile()
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.combine(powerFlow) { userProfile, power -> userProfile to power }
|
.combine(powerFlow) { userProfile, hr -> StreamData(userProfile, hr) }
|
||||||
.map { (userProfile, power) -> StreamData(userProfile, power) }
|
.combine(settingsFlow) { streamData, settings -> streamData.copy(settings = settings) }
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.collect { streamData ->
|
.collect { streamData ->
|
||||||
val value = streamData.value?.roundToInt()
|
val value = streamData.value?.roundToInt()
|
||||||
|
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
val color = context.getColor(
|
|
||||||
getZone(streamData.userProfile.powerZones, value)?.colorResource
|
|
||||||
?: R.color.zone7
|
|
||||||
)
|
|
||||||
val minPower = streamData.userProfile.powerZones.first().min
|
val minPower = streamData.userProfile.powerZones.first().min
|
||||||
val maxPower = streamData.userProfile.powerZones.last().min + 50
|
val maxPower = streamData.userProfile.powerZones.last().min + 50
|
||||||
val progress =
|
val progress =
|
||||||
remap(value.toDouble(), minPower.toDouble(), maxPower.toDouble(), 0.0, 1.0)
|
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.progress = progress
|
||||||
powerbar.label = "${value}W"
|
powerbar.label = "${value}W"
|
||||||
|
|
||||||
|
|||||||
@ -70,6 +70,7 @@ fun MainScreen() {
|
|||||||
var givenPermissions by remember { mutableStateOf(false) }
|
var givenPermissions by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
var onlyShowWhileRiding by remember { mutableStateOf(false) }
|
var onlyShowWhileRiding by remember { mutableStateOf(false) }
|
||||||
|
var colorBasedOnZones by remember { mutableStateOf(false) }
|
||||||
var showLabelOnBars by remember { mutableStateOf(true) }
|
var showLabelOnBars by remember { mutableStateOf(true) }
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
@ -80,6 +81,7 @@ fun MainScreen() {
|
|||||||
topSelectedSource = settings.topBarSource
|
topSelectedSource = settings.topBarSource
|
||||||
onlyShowWhileRiding = settings.onlyShowWhileRiding
|
onlyShowWhileRiding = settings.onlyShowWhileRiding
|
||||||
showLabelOnBars = settings.showLabelOnBars
|
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) {
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||||
Switch(checked = showLabelOnBars, onCheckedChange = { showLabelOnBars = it})
|
Switch(checked = showLabelOnBars, onCheckedChange = { showLabelOnBars = it})
|
||||||
Spacer(modifier = Modifier.width(10.dp))
|
Spacer(modifier = Modifier.width(10.dp))
|
||||||
@ -147,7 +155,8 @@ fun MainScreen() {
|
|||||||
.height(50.dp), onClick = {
|
.height(50.dp), onClick = {
|
||||||
val newSettings = PowerbarSettings(
|
val newSettings = PowerbarSettings(
|
||||||
source = bottomSelectedSource, topBarSource = topSelectedSource,
|
source = bottomSelectedSource, topBarSource = topSelectedSource,
|
||||||
onlyShowWhileRiding = onlyShowWhileRiding, showLabelOnBars = showLabelOnBars
|
onlyShowWhileRiding = onlyShowWhileRiding, showLabelOnBars = showLabelOnBars,
|
||||||
|
useZoneColors = colorBasedOnZones
|
||||||
)
|
)
|
||||||
|
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user