Skip to content

Commit

Permalink
Fix Picker rotary input on some devices and update design (#3919)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpelgrom committed Oct 6, 2023
1 parent f23a6cb commit f2e9541
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@ 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
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
Expand All @@ -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(
Expand All @@ -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(
Expand Down

0 comments on commit f2e9541

Please sign in to comment.