Skip to content

Commit

Permalink
Always expand tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
Henry-Hiles committed Dec 25, 2023
1 parent 43b7b42 commit e75c7f7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.henryhiles.qweather.presentation.components.weather

import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Water
Expand All @@ -22,7 +21,7 @@ import com.henryhiles.qweather.domain.weather.DailyWeatherData
import java.time.format.DateTimeFormatter

@Composable
fun WeatherDay(dailyWeatherData: DailyWeatherData, expanded: Boolean, onExpand: () -> Unit) {
fun WeatherDay(dailyWeatherData: DailyWeatherData) {
val formattedDate by remember {
derivedStateOf {
dailyWeatherData.date.format(
Expand All @@ -37,7 +36,6 @@ fun WeatherDay(dailyWeatherData: DailyWeatherData, expanded: Boolean, onExpand:
horizontal = 16.dp,
vertical = 8.dp
)
.clickable(onClick = onExpand)
) {
Row(
modifier = Modifier
Expand Down Expand Up @@ -65,34 +63,32 @@ fun WeatherDay(dailyWeatherData: DailyWeatherData, expanded: Boolean, onExpand:
style = MaterialTheme.typography.titleLarge,
)
}
if (expanded) {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(start = 16.dp, end = 16.dp, bottom = 16.dp),
horizontalArrangement = Arrangement.Center
) {
WeatherDataDisplay(
value = dailyWeatherData.precipitationProbabilityMax,
unit = "%",
icon = Icons.Outlined.WaterDrop,
description = "Chance of rain"
)
Spacer(modifier = Modifier.width(16.dp))
WeatherDataDisplay(
value = dailyWeatherData.windSpeedMax,
unit = "mm",
icon = Icons.Outlined.Water,
description = "Precipitation Amount"
)
Spacer(modifier = Modifier.width(16.dp))
WeatherDataDisplay(
value = dailyWeatherData.windSpeedMax,
unit = "km/h",
icon = Icons.Outlined.WindPower,
description = "Wind Speed"
)
}
Row(
modifier = Modifier
.fillMaxWidth()
.padding(start = 16.dp, end = 16.dp, bottom = 16.dp),
horizontalArrangement = Arrangement.Center
) {
WeatherDataDisplay(
value = dailyWeatherData.precipitationProbabilityMax,
unit = "%",
icon = Icons.Outlined.WaterDrop,
description = "Chance of rain"
)
Spacer(modifier = Modifier.width(16.dp))
WeatherDataDisplay(
value = dailyWeatherData.windSpeedMax,
unit = "mm",
icon = Icons.Outlined.Water,
description = "Precipitation Amount"
)
Spacer(modifier = Modifier.width(16.dp))
WeatherDataDisplay(
value = dailyWeatherData.windSpeedMax,
unit = "km/h",
icon = Icons.Outlined.WindPower,
description = "Wind Speed"
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.henryhiles.qweather.presentation.tabs
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.DateRange
Expand Down Expand Up @@ -75,13 +75,8 @@ object WeekTab : NavigationTab {
modifier = Modifier.fillMaxSize()
) {
weatherViewModel.state.dailyWeatherData?.let { data ->
itemsIndexed(data) { index, dailyData ->
val expanded = weatherViewModel.state.expanded == index
WeatherDay(
dailyWeatherData = dailyData,
expanded = expanded,
onExpand = { weatherViewModel.setExpanded(if (expanded) null else index) }
)
items(data) {
WeatherDay(dailyWeatherData = it)
}
}
}
Expand Down

0 comments on commit e75c7f7

Please sign in to comment.