Allow minus sign in custom range inputs (#68)
Some checks failed
Build / build (push) Failing after 7m55s

This commit is contained in:
timklge 2025-09-17 12:25:01 +02:00 committed by GitHub
parent d5fae80d9d
commit 2dbb79a586
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 11 deletions

View File

@ -72,7 +72,7 @@ tasks.register("generateManifest") {
"latestVersionCode" to android.defaultConfig.versionCode, "latestVersionCode" to android.defaultConfig.versionCode,
"developer" to "github.com/timklge", "developer" to "github.com/timklge",
"description" to "Open-source extension that adds colored progress bars representing power, heart rate etc. to the edge of the screen, similar to the LED bars on older Wahoo computers", "description" to "Open-source extension that adds colored progress bars representing power, heart rate etc. to the edge of the screen, similar to the LED bars on older Wahoo computers",
"releaseNotes" to "* Swap red / blue colorization for pedal balance source\n* Fix gear bar refresh\n* Add german localization\n* Add gear data sources\n* Show zero value on bars to indicate sensor availability\n* Fix pedal balance values", "releaseNotes" to "* Allow minus sign in custom range input fields",
"screenshotUrls" to listOf( "screenshotUrls" to listOf(
"$baseUrl/powerbar_min.gif", "$baseUrl/powerbar_min.gif",
"$baseUrl/powerbar0.png", "$baseUrl/powerbar0.png",

View File

@ -303,6 +303,9 @@ fun MainScreen(onFinish: () -> Unit) {
onPauseOrDispose { } onPauseOrDispose { }
} }
fun isCharAllowed(index: Int, c: Char): Boolean {
return c.isDigit() || (c == '-' && index == 0)
}
Box(modifier = Modifier.fillMaxSize()){ Box(modifier = Modifier.fillMaxSize()){
Column(modifier = Modifier Column(modifier = Modifier
@ -508,7 +511,7 @@ fun MainScreen(onFinish: () -> Unit) {
.weight(1f) .weight(1f)
.absolutePadding(right = 2.dp) .absolutePadding(right = 2.dp)
.onFocusEvent(::updateFocus), .onFocusEvent(::updateFocus),
onValueChange = { minSpeed = it.filter { c -> c.isDigit() } }, onValueChange = { minSpeed = it.filterIndexed(::isCharAllowed) },
label = { Text(stringResource(R.string.min_speed)) }, label = { Text(stringResource(R.string.min_speed)) },
suffix = { Text(stringResource(if (isImperial) R.string.unit_mph else R.string.unit_kph)) }, suffix = { Text(stringResource(if (isImperial) R.string.unit_mph else R.string.unit_kph)) },
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number), keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
@ -519,7 +522,7 @@ fun MainScreen(onFinish: () -> Unit) {
.weight(1f) .weight(1f)
.absolutePadding(left = 2.dp) .absolutePadding(left = 2.dp)
.onFocusEvent(::updateFocus), .onFocusEvent(::updateFocus),
onValueChange = { maxSpeed = it.filter { c -> c.isDigit() } }, onValueChange = { maxSpeed = it.filterIndexed(::isCharAllowed) },
label = { Text(stringResource(R.string.max_speed)) }, label = { Text(stringResource(R.string.max_speed)) },
suffix = { Text(stringResource(if (isImperial) R.string.unit_mph else R.string.unit_kph)) }, suffix = { Text(stringResource(if (isImperial) R.string.unit_mph else R.string.unit_kph)) },
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number), keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
@ -547,7 +550,7 @@ fun MainScreen(onFinish: () -> Unit) {
.weight(1f) .weight(1f)
.absolutePadding(right = 2.dp) .absolutePadding(right = 2.dp)
.onFocusEvent(::updateFocus), .onFocusEvent(::updateFocus),
onValueChange = { customMinPower = it.filter { c -> c.isDigit() } }, onValueChange = { customMinPower = it.filterIndexed(::isCharAllowed) },
label = { Text(stringResource(R.string.min_power), fontSize = 12.sp) }, label = { Text(stringResource(R.string.min_power), fontSize = 12.sp) },
suffix = { Text(stringResource(R.string.unit_watts)) }, suffix = { Text(stringResource(R.string.unit_watts)) },
placeholder = { Text("$profileMinPower") }, placeholder = { Text("$profileMinPower") },
@ -559,7 +562,7 @@ fun MainScreen(onFinish: () -> Unit) {
.weight(1f) .weight(1f)
.absolutePadding(left = 2.dp) .absolutePadding(left = 2.dp)
.onFocusEvent(::updateFocus), .onFocusEvent(::updateFocus),
onValueChange = { customMaxPower = it.filter { c -> c.isDigit() } }, onValueChange = { customMaxPower = it.filterIndexed(::isCharAllowed) },
label = { Text(stringResource(R.string.max_power), fontSize = 12.sp) }, label = { Text(stringResource(R.string.max_power), fontSize = 12.sp) },
suffix = { Text(stringResource(R.string.unit_watts)) }, suffix = { Text(stringResource(R.string.unit_watts)) },
placeholder = { Text("$profileMaxPower") }, placeholder = { Text("$profileMaxPower") },
@ -589,7 +592,7 @@ fun MainScreen(onFinish: () -> Unit) {
.weight(1f) .weight(1f)
.absolutePadding(right = 2.dp) .absolutePadding(right = 2.dp)
.onFocusEvent(::updateFocus), .onFocusEvent(::updateFocus),
onValueChange = { customMinHr = it.filter { c -> c.isDigit() } }, onValueChange = { customMinHr = it.filterIndexed(::isCharAllowed) },
label = { Text(stringResource(R.string.min_hr)) }, label = { Text(stringResource(R.string.min_hr)) },
suffix = { Text(stringResource(R.string.unit_bpm)) }, suffix = { Text(stringResource(R.string.unit_bpm)) },
placeholder = { if(profileRestHr > 0) Text("$profileRestHr") else Unit }, placeholder = { if(profileRestHr > 0) Text("$profileRestHr") else Unit },
@ -601,7 +604,7 @@ fun MainScreen(onFinish: () -> Unit) {
.weight(1f) .weight(1f)
.absolutePadding(left = 2.dp) .absolutePadding(left = 2.dp)
.onFocusEvent(::updateFocus), .onFocusEvent(::updateFocus),
onValueChange = { customMaxHr = it.filter { c -> c.isDigit() } }, onValueChange = { customMaxHr = it.filterIndexed(::isCharAllowed) },
label = { Text(stringResource(R.string.max_hr)) }, label = { Text(stringResource(R.string.max_hr)) },
suffix = { Text(stringResource(R.string.unit_bpm)) }, suffix = { Text(stringResource(R.string.unit_bpm)) },
placeholder = { if(profileMaxHr > 0) Text("$profileMaxHr") else Unit }, placeholder = { if(profileMaxHr > 0) Text("$profileMaxHr") else Unit },
@ -623,7 +626,7 @@ fun MainScreen(onFinish: () -> Unit) {
.weight(1f) .weight(1f)
.absolutePadding(right = 2.dp) .absolutePadding(right = 2.dp)
.onFocusEvent(::updateFocus), .onFocusEvent(::updateFocus),
onValueChange = { minCadence = it.filter { c -> c.isDigit() } }, onValueChange = { minCadence = it.filterIndexed(::isCharAllowed) },
label = { Text(stringResource(R.string.min_cadence)) }, label = { Text(stringResource(R.string.min_cadence)) },
suffix = { Text(stringResource(R.string.unit_rpm)) }, suffix = { Text(stringResource(R.string.unit_rpm)) },
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number), keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
@ -634,7 +637,7 @@ fun MainScreen(onFinish: () -> Unit) {
.weight(1f) .weight(1f)
.absolutePadding(left = 2.dp) .absolutePadding(left = 2.dp)
.onFocusEvent(::updateFocus), .onFocusEvent(::updateFocus),
onValueChange = { maxCadence = it.filter { c -> c.isDigit() } }, onValueChange = { maxCadence = it.filterIndexed(::isCharAllowed) },
label = { Text(stringResource(R.string.max_cadence)) }, label = { Text(stringResource(R.string.max_cadence)) },
suffix = { Text(stringResource(R.string.unit_rpm)) }, suffix = { Text(stringResource(R.string.unit_rpm)) },
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number), keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
@ -652,7 +655,7 @@ fun MainScreen(onFinish: () -> Unit) {
.weight(1f) .weight(1f)
.absolutePadding(right = 2.dp) .absolutePadding(right = 2.dp)
.onFocusEvent(::updateFocus), .onFocusEvent(::updateFocus),
onValueChange = { minGrade = it.filterIndexed { index, c -> c.isDigit() || (c == '-' && index == 0) } }, onValueChange = { minGrade = it.filterIndexed(::isCharAllowed) },
label = { Text(stringResource(R.string.min_grade)) }, label = { Text(stringResource(R.string.min_grade)) },
suffix = { Text(stringResource(R.string.unit_percent)) }, suffix = { Text(stringResource(R.string.unit_percent)) },
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number), keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
@ -663,7 +666,7 @@ fun MainScreen(onFinish: () -> Unit) {
.weight(1f) .weight(1f)
.absolutePadding(left = 2.dp) .absolutePadding(left = 2.dp)
.onFocusEvent(::updateFocus), .onFocusEvent(::updateFocus),
onValueChange = { maxGrade = it.filterIndexed { index, c -> c.isDigit() || (c == '-' && index == 0) } }, onValueChange = { maxGrade = it.filterIndexed(::isCharAllowed) },
label = { Text(stringResource(R.string.max_grade)) }, label = { Text(stringResource(R.string.max_grade)) },
suffix = { Text(stringResource(R.string.unit_percent)) }, suffix = { Text(stringResource(R.string.unit_percent)) },
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number), keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),