Some bug fixes

This commit is contained in:
Henry Hiles 2023-05-08 14:15:05 -04:00
parent edeea501eb
commit dde95a1c6b
7 changed files with 53 additions and 26 deletions

View file

@ -31,16 +31,15 @@ class QWeatherActivity : ComponentActivity() {
Theme.LIGHT -> false Theme.LIGHT -> false
Theme.DARK -> true Theme.DARK -> true
} }
val locations = location.locations
val isLocationSet = locations.isNotEmpty()
WeatherAppTheme(darkTheme = isDark, monet = prefs.monet) { WeatherAppTheme(darkTheme = isDark, monet = prefs.monet) {
Surface(modifier = Modifier.fillMaxSize()) { Surface(modifier = Modifier.fillMaxSize()) {
Navigator( Navigator(
screen = if (isLocationSet) MainScreen() else LocationPickerScreen(), screen = if (location.locations.isEmpty()) LocationPickerScreen() else MainScreen(),
onBackPressed = { onBackPressed = {
it !is MainScreen it !is MainScreen
}) { }
) {
SlideTransition(it) SlideTransition(it)
} }
} }

View file

@ -52,6 +52,9 @@ fun LocationsDrawer(
IconButton(onClick = { IconButton(onClick = {
locationPreferenceManager.locations -= data locationPreferenceManager.locations -= data
if (selected) locationPreferenceManager.selectedIndex = 0 if (selected) locationPreferenceManager.selectedIndex = 0
if (locationPreferenceManager.locations.isEmpty()) navigator?.push(
LocationPickerScreen()
)
}) { }) {
Icon( Icon(
imageVector = Icons.Default.Delete, imageVector = Icons.Default.Delete,

View file

@ -7,7 +7,7 @@ import androidx.compose.runtime.Composable
@Composable @Composable
@OptIn(ExperimentalMaterial3Api::class) @OptIn(ExperimentalMaterial3Api::class)
fun SmallToolbar( fun SmallToolbar(
backButton: Boolean = true, backButton: Boolean = false,
title: @Composable () -> Unit, title: @Composable () -> Unit,
actions: @Composable RowScope.() -> Unit = {}, actions: @Composable RowScope.() -> Unit = {},
navigationIcon: @Composable () -> Unit = { if (backButton) BackButton() }, navigationIcon: @Composable () -> Unit = { if (backButton) BackButton() },

View file

@ -18,12 +18,12 @@ fun SettingsCategory(
destination: (() -> Screen)? = null destination: (() -> Screen)? = null
) { ) {
val screen = destination?.invoke() val screen = destination?.invoke()
val nav = LocalNavigator.current?.parent val navigator = LocalNavigator.current?.parent
Box( Box(
modifier = Modifier modifier = Modifier
.clickable { .clickable {
screen?.let { nav?.push(it) } screen?.let { navigator?.push(it) }
} }
) { ) {
SettingItem( SettingItem(

View file

@ -49,7 +49,6 @@ class AppearanceSettingsScreen : Screen {
pref = screenModel.prefs.theme, pref = screenModel.prefs.theme,
labelFactory = { context.getString(it.label) } labelFactory = { context.getString(it.label) }
) { screenModel.prefs.theme = it } ) { screenModel.prefs.theme = it }
} }
} }
} }

View file

@ -39,13 +39,22 @@ class LocationPickerScreen : Screen {
var isAboutOpen by remember { mutableStateOf(false) } var isAboutOpen by remember { mutableStateOf(false) }
val navigator = LocalNavigator.current val navigator = LocalNavigator.current
Scaffold(modifier = Modifier.imePadding(), Scaffold(
modifier = Modifier.imePadding(),
floatingActionButton = { floatingActionButton = {
FloatingActionButton(onClick = { FloatingActionButton(onClick = {
location?.let { location?.let {
screenModel.prefs.locations += it with(screenModel.prefs) {
screenModel.prefs.selectedIndex = screenModel.prefs.locations.count() - 1 if (it !in locations) {
navigator?.push(MainScreen()) this.locations += it
selectedIndex =
locations.count() - 1
}
}
with(navigator) {
if (this != null) if (canPop) pop() else push(MainScreen())
}
} ?: kotlin.run { isAboutOpen = true } } ?: kotlin.run { isAboutOpen = true }
}) { }) {
Icon( Icon(
@ -53,10 +62,12 @@ class LocationPickerScreen : Screen {
contentDescription = stringResource(id = R.string.action_apply) contentDescription = stringResource(id = R.string.action_apply)
) )
} }
}) { }
) {
Column { Column {
SmallToolbar( SmallToolbar(
title = { Text(text = stringResource(id = R.string.location_choose)) }, title = { Text(text = stringResource(id = R.string.location_choose)) },
backButton = true,
actions = { actions = {
IconButton( IconButton(
onClick = { isAboutOpen = true }) { onClick = { isAboutOpen = true }) {
@ -81,16 +92,18 @@ class LocationPickerScreen : Screen {
) )
} ?: kotlin.run { } ?: kotlin.run {
Column(modifier = Modifier.padding(16.dp)) { Column(modifier = Modifier.padding(16.dp)) {
if (isAboutOpen) AlertDialog( if (isAboutOpen)
title = { Text(text = stringResource(id = R.string.location_choose)) }, AlertDialog(
text = { Text(text = stringResource(id = R.string.help_location_picker)) }, title = { Text(text = stringResource(id = R.string.location_choose)) },
onDismissRequest = { isAboutOpen = false }, text = { Text(text = stringResource(id = R.string.help_location_picker)) },
confirmButton = { onDismissRequest = { isAboutOpen = false },
TextButton( confirmButton = {
onClick = { isAboutOpen = false }) { TextButton(
Text(text = stringResource(id = R.string.action_confirm)) onClick = { isAboutOpen = false }) {
Text(text = stringResource(id = R.string.action_confirm))
}
} }
}) )
OutlinedTextField( OutlinedTextField(
label = { Text(text = stringResource(id = R.string.location)) }, label = { Text(text = stringResource(id = R.string.location)) },
@ -128,9 +141,19 @@ class LocationPickerScreen : Screen {
Alignment.CenterHorizontally Alignment.CenterHorizontally
) )
.padding(16.dp) .padding(16.dp)
) else screenModel.state.locations?.let { ) else screenModel.state.locations?.let { results ->
if (results.isEmpty()) Card {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
verticalAlignment = Alignment.CenterVertically
) {
Text(text = "No locations found")
}
}
LazyColumn { LazyColumn {
items(it) { items(results) {
val selected = it == location 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 { location = it }) {

View file

@ -32,17 +32,20 @@ class MainScreen : Screen {
val drawerState = val drawerState =
rememberDrawerState(initialValue = DrawerValue.Closed) rememberDrawerState(initialValue = DrawerValue.Closed)
val coroutineScope = rememberCoroutineScope() val coroutineScope = rememberCoroutineScope()
TabNavigator(tab = TodayTab) { TabNavigator(tab = TodayTab) {
LocationsDrawer( LocationsDrawer(
drawerState = drawerState, drawerState = drawerState,
onClose = { coroutineScope.launch { drawerState.close() } }) { onClose = { coroutineScope.launch { drawerState.close() } }
) {
Scaffold( Scaffold(
topBar = { topBar = {
SmallToolbar( SmallToolbar(
title = { title = {
with(locationPreferenceManager) { with(locationPreferenceManager) {
Text( Text(
text = locations[selectedIndex].location, text = locations.getOrNull(selectedIndex)?.location
?: stringResource(id = R.string.unknown),
maxLines = 1, maxLines = 1,
modifier = Modifier.basicMarquee() modifier = Modifier.basicMarquee()
) )