UI revamp

This commit is contained in:
Henry Hiles 2023-12-26 06:48:53 -05:00
parent 01358325bf
commit 43d3e9ebe3
2 changed files with 30 additions and 20 deletions

View file

@ -16,6 +16,7 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import com.henryhiles.qweather.domain.weather.DailyWeatherData import com.henryhiles.qweather.domain.weather.DailyWeatherData
import java.time.format.DateTimeFormatter import java.time.format.DateTimeFormatter
@ -30,13 +31,7 @@ fun WeatherDay(dailyWeatherData: DailyWeatherData) {
} }
} }
Card( Card {
modifier = Modifier
.padding(
horizontal = 16.dp,
vertical = 8.dp
)
) {
Row( Row(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
@ -52,7 +47,8 @@ fun WeatherDay(dailyWeatherData: DailyWeatherData) {
Spacer(modifier = Modifier.width(16.dp)) Spacer(modifier = Modifier.width(16.dp))
Column { Column {
Text( Text(
text = formattedDate text = formattedDate,
fontWeight = FontWeight.Bold,
) )
Text(text = "Feels like ${dailyWeatherData.apparentTemperatureMax}°C") Text(text = "Feels like ${dailyWeatherData.apparentTemperatureMax}°C")
} }

View file

@ -1,7 +1,10 @@
package com.henryhiles.qweather.presentation.tabs package com.henryhiles.qweather.presentation.tabs
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.text.selection.SelectionContainer import androidx.compose.foundation.text.selection.SelectionContainer
@ -16,12 +19,15 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.rememberVectorPainter import androidx.compose.ui.graphics.vector.rememberVectorPainter
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import cafe.adriel.voyager.koin.getScreenModel import cafe.adriel.voyager.koin.getScreenModel
import cafe.adriel.voyager.navigator.tab.TabOptions import cafe.adriel.voyager.navigator.tab.TabOptions
import com.henryhiles.qweather.R import com.henryhiles.qweather.R
import com.henryhiles.qweather.domain.util.NavigationTab import com.henryhiles.qweather.domain.util.NavigationTab
import com.henryhiles.qweather.presentation.components.weather.WeatherDay import com.henryhiles.qweather.presentation.components.weather.WeatherDay
import com.henryhiles.qweather.presentation.components.weather.WeatherToday
import com.henryhiles.qweather.presentation.screenmodel.DailyWeatherScreenModel import com.henryhiles.qweather.presentation.screenmodel.DailyWeatherScreenModel
import com.henryhiles.qweather.presentation.screenmodel.HourlyWeatherScreenModel
object WeekTab : NavigationTab { object WeekTab : NavigationTab {
override val options: TabOptions override val options: TabOptions
@ -41,22 +47,25 @@ object WeekTab : NavigationTab {
@Composable @Composable
override fun Content() { override fun Content() {
val weatherViewModel = getScreenModel<DailyWeatherScreenModel>() val hourlyWeatherViewModel = getScreenModel<HourlyWeatherScreenModel>()
val dailyWeatherViewModel = getScreenModel<DailyWeatherScreenModel>()
LaunchedEffect(key1 = weatherViewModel.locationPreferenceManager.selectedIndex) { LaunchedEffect(key1 = dailyWeatherViewModel.locationPreferenceManager.selectedIndex) {
weatherViewModel.loadWeatherInfo() dailyWeatherViewModel.loadWeatherInfo()
hourlyWeatherViewModel.loadWeatherInfo()
} }
Box(modifier = Modifier.fillMaxSize()) { Box(modifier = Modifier.fillMaxSize()) {
when { when {
weatherViewModel.state.isLoading -> { dailyWeatherViewModel.state.isLoading -> {
CircularProgressIndicator( CircularProgressIndicator(
modifier = Modifier.align( modifier = Modifier.align(
Alignment.Center Alignment.Center
) )
) )
} }
weatherViewModel.state.error != null -> {
dailyWeatherViewModel.state.error != null -> {
AlertDialog( AlertDialog(
onDismissRequest = {}, onDismissRequest = {},
confirmButton = {}, confirmButton = {},
@ -64,18 +73,19 @@ object WeekTab : NavigationTab {
text = { text = {
SelectionContainer { SelectionContainer {
Text( Text(
text = weatherViewModel.state.error!!, text = dailyWeatherViewModel.state.error!!,
) )
} }
}, },
) )
} }
else -> { else -> {
LazyColumn( LazyColumn(contentPadding = PaddingValues(16.dp)) {
modifier = Modifier.fillMaxSize() dailyWeatherViewModel.state.dailyWeatherData?.let { data ->
) { item { WeatherToday(state = hourlyWeatherViewModel.state) }
weatherViewModel.state.dailyWeatherData?.let { data ->
items(data) { items(data) {
Spacer(modifier = Modifier.height(16.dp))
WeatherDay(dailyWeatherData = it) WeatherDay(dailyWeatherData = it)
} }
} }
@ -87,9 +97,13 @@ object WeekTab : NavigationTab {
@Composable @Composable
override fun Actions() { override fun Actions() {
val viewModel: DailyWeatherScreenModel = getScreenModel() val hourlyWeatherViewModel = getScreenModel<HourlyWeatherScreenModel>()
val dailyWeatherViewModel = getScreenModel<DailyWeatherScreenModel>()
IconButton(onClick = { viewModel.loadWeatherInfo(cache = false) }) { IconButton(onClick = {
hourlyWeatherViewModel.loadWeatherInfo(cache = false)
dailyWeatherViewModel.loadWeatherInfo(cache = false)
}) {
Icon( Icon(
imageVector = Icons.Filled.Refresh, imageVector = Icons.Filled.Refresh,
contentDescription = stringResource(R.string.action_reload) contentDescription = stringResource(R.string.action_reload)