Fix Picker rotary input on some devices and update design (#3919)

This commit is contained in:
Joris Pelgröm 2023-10-06 17:38:40 +02:00 committed by GitHub
parent f23a6cb046
commit f2e9541264
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,7 +2,6 @@ package io.homeassistant.companion.android.home.views
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Check
import androidx.compose.runtime.Composable
@ -10,15 +9,17 @@ import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.wear.compose.material.Picker
import androidx.wear.compose.material.rememberPickerState
import androidx.wear.compose.material3.Button
import androidx.wear.compose.material3.ButtonDefaults
import androidx.wear.compose.material3.Icon
import androidx.wear.compose.material3.MaterialTheme
import androidx.wear.compose.material3.Text
import androidx.wear.tooling.preview.devices.WearDevices
import com.google.android.horologist.annotations.ExperimentalHorologistApi
@ -39,8 +40,7 @@ fun RefreshIntervalPickerView(
val initialIndex = options.indexOf(currentInterval)
val state = rememberPickerState(
initialNumberOfOptions = options.size,
initiallySelectedOption = if (initialIndex != -1) initialIndex else 0,
repeatItems = true
initiallySelectedOption = if (initialIndex != -1) initialIndex else 0
)
Column(
@ -53,13 +53,17 @@ fun RefreshIntervalPickerView(
contentDescription = stringResource(R.string.refresh_interval),
modifier = Modifier
.weight(1f)
.padding(all = 8.dp)
.rotaryWithSnap(state.toRotaryScrollAdapter())
) {
Text(
intervalToString(LocalContext.current, options[it]),
fontSize = 24.sp,
color = if (it != this.selectedOption) wearColorScheme.onBackground else wearColorScheme.primary
text = intervalToString(LocalContext.current, options[it]),
style = with(LocalDensity.current) {
MaterialTheme.typography.displayMedium.copy(
fontWeight = FontWeight.Medium,
fontSize = MaterialTheme.typography.displayMedium.fontSize.value.dp.toSp() // Ignore text scaling
)
},
color = wearColorScheme.primary
)
}
Button(