Always show weather and music widgets even if there's no data available
This commit is contained in:
parent
960c645010
commit
fb50c9bd9d
@ -415,4 +415,5 @@
|
||||
<string name="weather_wind">Wind:</string>
|
||||
<string name="preference_themed_icons">Eingefärbte Symbole</string>
|
||||
<string name="preference_themed_icons_summary">Symbole an das Farbschema der App anpassen</string>
|
||||
<string name="weather_no_data">Keine Wetterdaten verfügbar.</string>
|
||||
</resources>
|
||||
@ -445,6 +445,8 @@
|
||||
<string name="weather_widget_hide_details">Hide details</string>
|
||||
<string name="weather_humidity">Humidity:</string>
|
||||
<string name="weather_wind">Wind:</string>
|
||||
<string name="weather_no_data">No weather data available.</string>
|
||||
|
||||
<string name="weather_precipitation">Precipitation:</string>
|
||||
<string name="preference_category_license">License</string>
|
||||
<string name="preference_about_license">This app is free software.</string>
|
||||
|
||||
@ -7,14 +7,14 @@ import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.combinedClickable
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.rounded.MusicNote
|
||||
import androidx.compose.material.icons.rounded.SkipNext
|
||||
import androidx.compose.material.icons.rounded.SkipPrevious
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.livedata.observeAsState
|
||||
@ -29,7 +29,6 @@ import de.mm20.launcher2.music.MusicViewModel
|
||||
import de.mm20.launcher2.music.PlaybackState
|
||||
import de.mm20.launcher2.ui.R
|
||||
import de.mm20.launcher2.ui.ktx.conditional
|
||||
import de.mm20.launcher2.ui.locals.LocalColorScheme
|
||||
import org.koin.androidx.compose.getViewModel
|
||||
|
||||
@OptIn(
|
||||
@ -52,7 +51,6 @@ fun MusicWidget() {
|
||||
Row(
|
||||
modifier = Modifier.height(IntrinsicSize.Min)
|
||||
) {
|
||||
if (title != null) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.padding(top = 16.dp)
|
||||
@ -154,9 +152,5 @@ fun MusicWidget() {
|
||||
)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// TODO
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -13,6 +13,7 @@ import androidx.compose.material.DropdownMenu
|
||||
import androidx.compose.material.DropdownMenuItem
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.rounded.ArrowDropDown
|
||||
import androidx.compose.material.icons.rounded.LightMode
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.runtime.livedata.observeAsState
|
||||
@ -49,18 +50,22 @@ fun WeatherWidget() {
|
||||
var selectedForecastIndex by remember { mutableStateOf(0) }
|
||||
var detailsExpanded by remember { mutableStateOf(false) }
|
||||
|
||||
if (weatherData.isEmpty()) return
|
||||
|
||||
if (weatherData.size <= selectedDayIndex) {
|
||||
if (weatherData.isNotEmpty() && weatherData.size <= selectedDayIndex) {
|
||||
selectedDayIndex = 0
|
||||
return
|
||||
}
|
||||
|
||||
if (weatherData[selectedDayIndex].hourlyForecasts.size <= selectedForecastIndex) {
|
||||
if (weatherData.isNotEmpty() && weatherData[selectedDayIndex].hourlyForecasts.size <= selectedForecastIndex) {
|
||||
selectedForecastIndex = 0
|
||||
return
|
||||
}
|
||||
|
||||
if (weatherData.isEmpty()) {
|
||||
NoData()
|
||||
return
|
||||
}
|
||||
|
||||
val selectedForecast = weatherData[selectedDayIndex].hourlyForecasts[selectedForecastIndex]
|
||||
val imperialUnits = LauncherPreferences.instance.imperialUnits
|
||||
|
||||
@ -441,3 +446,25 @@ private fun weatherIconById(id: Int): WeatherIcon {
|
||||
else -> WeatherIcon.None
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun NoData() {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.wrapContentHeight(),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Icon(imageVector = Icons.Rounded.LightMode,
|
||||
contentDescription = "",
|
||||
modifier = Modifier
|
||||
.padding(24.dp)
|
||||
.size(32.dp),
|
||||
tint = MaterialTheme.colorScheme.secondary
|
||||
)
|
||||
Text(
|
||||
text = stringResource(id = R.string.weather_no_data),
|
||||
style = MaterialTheme.typography.bodySmall
|
||||
)
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user