Some bug fixes
This commit is contained in:
parent
edeea501eb
commit
dde95a1c6b
7 changed files with 53 additions and 26 deletions
|
@ -31,16 +31,15 @@ class QWeatherActivity : ComponentActivity() {
|
|||
Theme.LIGHT -> false
|
||||
Theme.DARK -> true
|
||||
}
|
||||
val locations = location.locations
|
||||
val isLocationSet = locations.isNotEmpty()
|
||||
|
||||
WeatherAppTheme(darkTheme = isDark, monet = prefs.monet) {
|
||||
Surface(modifier = Modifier.fillMaxSize()) {
|
||||
Navigator(
|
||||
screen = if (isLocationSet) MainScreen() else LocationPickerScreen(),
|
||||
screen = if (location.locations.isEmpty()) LocationPickerScreen() else MainScreen(),
|
||||
onBackPressed = {
|
||||
it !is MainScreen
|
||||
}) {
|
||||
}
|
||||
) {
|
||||
SlideTransition(it)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,6 +52,9 @@ fun LocationsDrawer(
|
|||
IconButton(onClick = {
|
||||
locationPreferenceManager.locations -= data
|
||||
if (selected) locationPreferenceManager.selectedIndex = 0
|
||||
if (locationPreferenceManager.locations.isEmpty()) navigator?.push(
|
||||
LocationPickerScreen()
|
||||
)
|
||||
}) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Delete,
|
||||
|
|
|
@ -7,7 +7,7 @@ import androidx.compose.runtime.Composable
|
|||
@Composable
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
fun SmallToolbar(
|
||||
backButton: Boolean = true,
|
||||
backButton: Boolean = false,
|
||||
title: @Composable () -> Unit,
|
||||
actions: @Composable RowScope.() -> Unit = {},
|
||||
navigationIcon: @Composable () -> Unit = { if (backButton) BackButton() },
|
||||
|
|
|
@ -18,12 +18,12 @@ fun SettingsCategory(
|
|||
destination: (() -> Screen)? = null
|
||||
) {
|
||||
val screen = destination?.invoke()
|
||||
val nav = LocalNavigator.current?.parent
|
||||
val navigator = LocalNavigator.current?.parent
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.clickable {
|
||||
screen?.let { nav?.push(it) }
|
||||
screen?.let { navigator?.push(it) }
|
||||
}
|
||||
) {
|
||||
SettingItem(
|
||||
|
|
|
@ -49,7 +49,6 @@ class AppearanceSettingsScreen : Screen {
|
|||
pref = screenModel.prefs.theme,
|
||||
labelFactory = { context.getString(it.label) }
|
||||
) { screenModel.prefs.theme = it }
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,13 +39,22 @@ class LocationPickerScreen : Screen {
|
|||
var isAboutOpen by remember { mutableStateOf(false) }
|
||||
val navigator = LocalNavigator.current
|
||||
|
||||
Scaffold(modifier = Modifier.imePadding(),
|
||||
Scaffold(
|
||||
modifier = Modifier.imePadding(),
|
||||
floatingActionButton = {
|
||||
FloatingActionButton(onClick = {
|
||||
location?.let {
|
||||
screenModel.prefs.locations += it
|
||||
screenModel.prefs.selectedIndex = screenModel.prefs.locations.count() - 1
|
||||
navigator?.push(MainScreen())
|
||||
with(screenModel.prefs) {
|
||||
if (it !in locations) {
|
||||
this.locations += it
|
||||
selectedIndex =
|
||||
locations.count() - 1
|
||||
}
|
||||
}
|
||||
|
||||
with(navigator) {
|
||||
if (this != null) if (canPop) pop() else push(MainScreen())
|
||||
}
|
||||
} ?: kotlin.run { isAboutOpen = true }
|
||||
}) {
|
||||
Icon(
|
||||
|
@ -53,10 +62,12 @@ class LocationPickerScreen : Screen {
|
|||
contentDescription = stringResource(id = R.string.action_apply)
|
||||
)
|
||||
}
|
||||
}) {
|
||||
}
|
||||
) {
|
||||
Column {
|
||||
SmallToolbar(
|
||||
title = { Text(text = stringResource(id = R.string.location_choose)) },
|
||||
backButton = true,
|
||||
actions = {
|
||||
IconButton(
|
||||
onClick = { isAboutOpen = true }) {
|
||||
|
@ -81,7 +92,8 @@ class LocationPickerScreen : Screen {
|
|||
)
|
||||
} ?: kotlin.run {
|
||||
Column(modifier = Modifier.padding(16.dp)) {
|
||||
if (isAboutOpen) AlertDialog(
|
||||
if (isAboutOpen)
|
||||
AlertDialog(
|
||||
title = { Text(text = stringResource(id = R.string.location_choose)) },
|
||||
text = { Text(text = stringResource(id = R.string.help_location_picker)) },
|
||||
onDismissRequest = { isAboutOpen = false },
|
||||
|
@ -90,7 +102,8 @@ class LocationPickerScreen : Screen {
|
|||
onClick = { isAboutOpen = false }) {
|
||||
Text(text = stringResource(id = R.string.action_confirm))
|
||||
}
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
OutlinedTextField(
|
||||
label = { Text(text = stringResource(id = R.string.location)) },
|
||||
|
@ -128,9 +141,19 @@ class LocationPickerScreen : Screen {
|
|||
Alignment.CenterHorizontally
|
||||
)
|
||||
.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 {
|
||||
items(it) {
|
||||
items(results) {
|
||||
val selected = it == location
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
Card(modifier = Modifier.clickable { location = it }) {
|
||||
|
|
|
@ -32,17 +32,20 @@ class MainScreen : Screen {
|
|||
val drawerState =
|
||||
rememberDrawerState(initialValue = DrawerValue.Closed)
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
|
||||
TabNavigator(tab = TodayTab) {
|
||||
LocationsDrawer(
|
||||
drawerState = drawerState,
|
||||
onClose = { coroutineScope.launch { drawerState.close() } }) {
|
||||
onClose = { coroutineScope.launch { drawerState.close() } }
|
||||
) {
|
||||
Scaffold(
|
||||
topBar = {
|
||||
SmallToolbar(
|
||||
title = {
|
||||
with(locationPreferenceManager) {
|
||||
Text(
|
||||
text = locations[selectedIndex].location,
|
||||
text = locations.getOrNull(selectedIndex)?.location
|
||||
?: stringResource(id = R.string.unknown),
|
||||
maxLines = 1,
|
||||
modifier = Modifier.basicMarquee()
|
||||
)
|
||||
|
|
Reference in a new issue