Simplify location picker
This commit is contained in:
parent
3c9e1b4557
commit
1a8b022681
1 changed files with 23 additions and 38 deletions
|
@ -33,39 +33,23 @@ class LocationPickerScreen : Screen {
|
||||||
@Composable
|
@Composable
|
||||||
override fun Content() {
|
override fun Content() {
|
||||||
val screenModel: LocationPickerScreenModel = getScreenModel()
|
val screenModel: LocationPickerScreenModel = getScreenModel()
|
||||||
var location by remember {
|
|
||||||
mutableStateOf<GeocodingData?>(null)
|
|
||||||
}
|
|
||||||
var locationSearch by remember { mutableStateOf("") }
|
var locationSearch by remember { mutableStateOf("") }
|
||||||
var isAboutOpen by remember { mutableStateOf(false) }
|
var isAboutOpen by remember { mutableStateOf(false) }
|
||||||
val navigator = LocalNavigator.currentOrThrow
|
val navigator = LocalNavigator.currentOrThrow
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
modifier = Modifier.imePadding(),
|
modifier = Modifier.imePadding(),
|
||||||
floatingActionButton = {
|
// FloatingActionButton(onClick = {
|
||||||
FloatingActionButton(onClick = {
|
|
||||||
location?.let {
|
|
||||||
with(screenModel.prefs) {
|
|
||||||
if (it !in locations) {
|
|
||||||
this.locations += it
|
|
||||||
selectedIndex =
|
|
||||||
locations.count() - 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
with(navigator) {
|
// } ?: kotlin.run { isAboutOpen = true }
|
||||||
if (canPop) pop() else push(MainScreen())
|
// }) {
|
||||||
}
|
// Icon(
|
||||||
} ?: kotlin.run { isAboutOpen = true }
|
// imageVector = Icons.Default.Check,
|
||||||
}) {
|
// contentDescription = stringResource(id = R.string.action_apply)
|
||||||
Icon(
|
// )
|
||||||
imageVector = Icons.Default.Check,
|
// }
|
||||||
contentDescription = stringResource(id = R.string.action_apply)
|
) {padding ->
|
||||||
)
|
Column(modifier = Modifier.padding(padding)) {
|
||||||
}
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
Column(modifier = Modifier.padding(it)) {
|
|
||||||
SmallToolbar(
|
SmallToolbar(
|
||||||
title = { Text(text = stringResource(id = R.string.location_choose)) },
|
title = { Text(text = stringResource(id = R.string.location_choose)) },
|
||||||
backButton = screenModel.prefs.locations.isNotEmpty(),
|
backButton = screenModel.prefs.locations.isNotEmpty(),
|
||||||
|
@ -159,25 +143,26 @@ class LocationPickerScreen : Screen {
|
||||||
}
|
}
|
||||||
LazyColumn {
|
LazyColumn {
|
||||||
items(results) {
|
items(results) {
|
||||||
val selected = it == location
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
Card(modifier = Modifier.clickable { location = it }) {
|
Card(modifier = Modifier.clickable {
|
||||||
|
with(screenModel.prefs) {
|
||||||
|
if (it !in locations) {
|
||||||
|
locations += it
|
||||||
|
selectedIndex =
|
||||||
|
locations.count() - 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
with(navigator) {
|
||||||
|
if (canPop) pop() else push(MainScreen())
|
||||||
|
}
|
||||||
|
}) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(16.dp),
|
.padding(16.dp),
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
if (selected) {
|
|
||||||
Icon(
|
|
||||||
imageVector = Icons.Default.Check,
|
|
||||||
contentDescription = stringResource(
|
|
||||||
id = R.string.selected
|
|
||||||
),
|
|
||||||
modifier = Modifier.height(16.dp)
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.width(8.dp))
|
|
||||||
}
|
|
||||||
Text(text = it.location)
|
Text(text = it.location)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue