Fix HR zones

This commit is contained in:
Tim Kluge 2024-12-07 15:22:31 +01:00
parent 90871d18f6
commit 629416d0a1
7 changed files with 16 additions and 16 deletions

View File

@ -13,8 +13,8 @@ android {
applicationId = "de.timklge.karoopowerbar"
minSdk = 26
targetSdk = 33
versionCode = 1
versionName = "1.0.0"
versionCode = 2
versionName = "1.0.1"
}
buildTypes {

View File

@ -3,8 +3,8 @@
"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.0.0",
"latestVersionCode": 1,
"latestVersion": "1.0.1",
"latestVersionCode": 2,
"developer": "timklge",
"description": "Adds a colored power bar to the bottom of the screen",
"releaseNotes": "Initial release"

View File

@ -10,7 +10,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
class KarooPowerbarExtension : KarooExtension("karoo-powerbar", "1.0.0") {
class KarooPowerbarExtension : KarooExtension("karoo-powerbar", "1.0.1") {
companion object {
const val TAG = "karoo-powerbar"

View File

@ -42,6 +42,7 @@ enum class HrZone(val colorResource: Int) {
ACTIVE_RECOVERY(R.color.zoneActiveRecovery),
ENDURANCE(R.color.zoneEndurance),
TEMPO(R.color.zoneTempo),
THRESHOLD(R.color.zoneThreshold),
VO2_MAX(R.color.zoneAerobic),
}
@ -84,7 +85,7 @@ class Window(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE.or(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE),
PixelFormat.TRANSLUCENT
)

View File

@ -10,6 +10,7 @@ import androidx.compose.material3.MenuAnchorType
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
@ -21,9 +22,8 @@ data class DropdownOption(val id: String, val name: String)
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun Dropdown(label: String, options: List<DropdownOption>, initialSelection: DropdownOption, onSelect: (selectedOption: DropdownOption) -> Unit) {
fun Dropdown(label: String, options: List<DropdownOption>, selected: DropdownOption, onSelect: (selectedOption: DropdownOption) -> Unit) {
var expanded by remember { mutableStateOf(false) }
var selected by remember { mutableStateOf(initialSelection) }
ExposedDropdownMenuBox(
expanded = expanded,
@ -50,9 +50,8 @@ fun Dropdown(label: String, options: List<DropdownOption>, initialSelection: Dro
DropdownMenuItem(
text = { Text(option.name, style = MaterialTheme.typography.bodyLarge) },
onClick = {
selected = option
expanded = false
onSelect(selected)
onSelect(option)
},
contentPadding = ExposedDropdownMenuDefaults.ItemContentPadding,
)

View File

@ -64,11 +64,11 @@ fun MainScreen() {
var givenPermissions by remember { mutableStateOf(false) }
LaunchedEffect(Unit) {
givenPermissions = Settings.canDrawOverlays(ctx)
ctx.streamSettings().collect { settings ->
selectedSource = settings.source
}
givenPermissions = Settings.canDrawOverlays(ctx)
}
LaunchedEffect(Unit) {
@ -99,8 +99,10 @@ fun MainScreen() {
.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(10.dp)) {
val powerSourceDropdownOptions = SelectedSource.entries.toList().map { unit -> DropdownOption(unit.id, unit.label) }
val powerSourceInitialSelection = powerSourceDropdownOptions.find { option -> option.id == selectedSource.id }!!
Dropdown(label = "Data Source", options = powerSourceDropdownOptions, initialSelection = powerSourceInitialSelection) { selectedOption ->
val powerSourceInitialSelection by remember(selectedSource) {
mutableStateOf(powerSourceDropdownOptions.find { option -> option.id == selectedSource.id }!!)
}
Dropdown(label = "Data Source", options = powerSourceDropdownOptions, selected = powerSourceInitialSelection) { selectedOption ->
selectedSource = SelectedSource.entries.find { unit -> unit.id == selectedOption.id }!!
}

View File

@ -40,8 +40,6 @@ androidx-compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling", versi
androidx-compose-material = { module = "androidx.compose.material3:material3", version.ref = "androidxComposeMaterial" }
# Glance
androidx-glance-appwidget = { group = "androidx.glance", name = "glance-appwidget", version.ref = "glance" }
androidx-glance-preview = { group = "androidx.glance", name = "glance-preview", version.ref = "glance" }
androidx-navigation-runtime-ktx = { group = "androidx.navigation", name = "navigation-runtime-ktx", version.ref = "navigationRuntimeKtx" }
androidx-navigation-compose = { group = "androidx.navigation", name = "navigation-compose", version.ref = "navigationCompose" }
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerializationJson" }