diff --git a/app/src/main/java/com/pranshulgg/weather_master_app/widgets/uvindex/UvIndexWidget.kt b/app/src/main/java/com/pranshulgg/weather_master_app/widgets/uvindex/UvIndexWidget.kt index 7e9f5abf5..8ed5c39d4 100644 --- a/app/src/main/java/com/pranshulgg/weather_master_app/widgets/uvindex/UvIndexWidget.kt +++ b/app/src/main/java/com/pranshulgg/weather_master_app/widgets/uvindex/UvIndexWidget.kt @@ -7,7 +7,6 @@ import androidx.compose.ui.graphics.Color import androidx.glance.ColorFilter import androidx.glance.GlanceId import androidx.glance.GlanceModifier -import androidx.glance.GlanceTheme import androidx.glance.ImageProvider import androidx.glance.action.actionStartActivity import androidx.glance.action.clickable @@ -28,9 +27,7 @@ import com.pranshulgg.weather_master_app.widgets.WeatherWidgetStateDefinition import com.pranshulgg.weather_master_app.widgets.WeatherWidgetStateJson import com.pranshulgg.weather_master_app.widgets.model.WidgetVariant import com.pranshulgg.weather_master_app.widgets.model.WidgetWeather -import com.pranshulgg.weather_master_app.widgets.pill.ui.WeatherWidgetPill -import com.pranshulgg.weather_master_app.widgets.ui.colors.WidgetColors -import com.pranshulgg.weather_master_app.widgets.ui.colors.WidgetTheme +import com.pranshulgg.weather_master_app.widgets.ui.ReloadButton import com.pranshulgg.weather_master_app.widgets.uvindex.ui.variants.UvIndexWidgetCompact import com.pranshulgg.weather_master_app.widgets.uvindex.ui.variants.UvIndexWidgetLarge import kotlinx.serialization.json.Json @@ -41,6 +38,7 @@ class UvIndexWidget : GlanceAppWidget() { override val stateDefinition = WeatherWidgetStateDefinition + override suspend fun provideGlance( context: Context, id: GlanceId @@ -56,24 +54,26 @@ class UvIndexWidget : GlanceAppWidget() { Json.decodeFromString(it) } val config = widgetState.config - val widgetColors = WidgetColors() + if (state != null) { + Box( + GlanceModifier.fillMaxSize() + .clickable(actionStartActivity()) + ) { + when (config.variant) { + WidgetVariant.LARGE -> UvIndexWidgetLarge( + state, + GlanceModifier.appWidgetBackgroundShape(getUvIndex(state.uvIndex ?: 0)) + ) - Box( - GlanceModifier.fillMaxSize() - .clickable(actionStartActivity()) - ) { - when (config.variant) { - WidgetVariant.LARGE -> UvIndexWidgetLarge( - state, - GlanceModifier.appWidgetBackgroundShape(getUvIndex(state?.uvIndex ?: 0)) - ) - - else -> UvIndexWidgetCompact( - state, - GlanceModifier.appWidgetBackgroundShape(getUvIndex(state?.uvIndex ?: 0)) - ) + else -> UvIndexWidgetCompact( + state, + GlanceModifier.appWidgetBackgroundShape(getUvIndex(state.uvIndex ?: 0)) + ) + } } + } else { + ReloadButton() } } } diff --git a/app/src/main/java/com/pranshulgg/weather_master_app/widgets/uvindex/ui/variants/UvIndexWidgetCompact.kt b/app/src/main/java/com/pranshulgg/weather_master_app/widgets/uvindex/ui/variants/UvIndexWidgetCompact.kt index 0d2f587fb..c95c4d468 100644 --- a/app/src/main/java/com/pranshulgg/weather_master_app/widgets/uvindex/ui/variants/UvIndexWidgetCompact.kt +++ b/app/src/main/java/com/pranshulgg/weather_master_app/widgets/uvindex/ui/variants/UvIndexWidgetCompact.kt @@ -26,52 +26,48 @@ import com.pranshulgg.weather_master_app.widgets.uvindex.getUvIndexTextColorForW @Composable fun UvIndexWidgetCompact( - state: WidgetWeather?, + state: WidgetWeather, glanceModifier: GlanceModifier ) { val context = LocalContext.current - if (state != null) { - val textColor = getUvIndexTextColorForWidget(getUvIndex(state.uvIndex ?: 0)) - val textColorVariant = getUvIndexSecondaryTextColorForWidget(getUvIndex(state.uvIndex ?: 0)) + val textColor = getUvIndexTextColorForWidget(getUvIndex(state.uvIndex ?: 0)) + val textColorVariant = getUvIndexSecondaryTextColorForWidget(getUvIndex(state.uvIndex ?: 0)) - Column( - modifier = glanceModifier.fillMaxSize().padding(horizontal = 16.dp), - verticalAlignment = Alignment.CenterVertically - ) { + Column( + modifier = glanceModifier.fillMaxSize().padding(horizontal = 16.dp), + verticalAlignment = Alignment.CenterVertically + ) { + Text( + context.getString(R.string.weather_current), + style = TextStyle( + color = textColorVariant, + fontSize = 18.sp, + ), + ) + Row(verticalAlignment = Alignment.Bottom) { Text( - stringResource(R.string.weather_current), + "${state.uvIndex ?: "No data"}", style = TextStyle( - color = textColorVariant, + color = textColor, + fontSize = 32.sp, + fontWeight = FontWeight.Bold + ), + ) + Spacer(GlanceModifier.width(5.dp)) + Text( + state.uvIndex?.let { + getUvIndex(it).toLabel(context) + } ?: "No data", + style = TextStyle( + color = textColor, fontSize = 18.sp, + fontWeight = FontWeight.Medium ), ) - Row(verticalAlignment = Alignment.Bottom) { - Text( - "${state.uvIndex ?: "No data"}", - style = TextStyle( - color = textColor, - fontSize = 32.sp, - fontWeight = FontWeight.Bold - ), - ) - Spacer(GlanceModifier.width(5.dp)) - Text( - state.uvIndex?.let { - getUvIndex(it).toLabel(context) - } ?: "No data", - style = TextStyle( - color = textColor, - fontSize = 18.sp, - fontWeight = FontWeight.Medium - ), - ) - } } - } else { - ReloadButton() } } \ No newline at end of file diff --git a/app/src/main/java/com/pranshulgg/weather_master_app/widgets/uvindex/ui/variants/UvIndexWidgetLarge.kt b/app/src/main/java/com/pranshulgg/weather_master_app/widgets/uvindex/ui/variants/UvIndexWidgetLarge.kt index 191950bb6..58222a40e 100644 --- a/app/src/main/java/com/pranshulgg/weather_master_app/widgets/uvindex/ui/variants/UvIndexWidgetLarge.kt +++ b/app/src/main/java/com/pranshulgg/weather_master_app/widgets/uvindex/ui/variants/UvIndexWidgetLarge.kt @@ -24,68 +24,62 @@ import com.pranshulgg.weather_master_app.widgets.uvindex.getUvIndexTextColorForW @Composable fun UvIndexWidgetLarge( - state: WidgetWeather?, + state: WidgetWeather, glanceModifier: GlanceModifier ) { val context = LocalContext.current - if (state != null) { + + val textColor = getUvIndexTextColorForWidget(getUvIndex(state.uvIndex ?: 0)) + val textColorVariant = getUvIndexSecondaryTextColorForWidget(getUvIndex(state.uvIndex ?: 0)) - val textColor = getUvIndexTextColorForWidget(getUvIndex(state.uvIndex ?: 0)) - val textColorVariant = getUvIndexSecondaryTextColorForWidget(getUvIndex(state.uvIndex ?: 0)) - Column(modifier = glanceModifier.fillMaxSize().padding(16.dp)) { - Text( - stringResource(R.string.weather_current), - style = TextStyle( - color = textColorVariant, - fontSize = 18.sp, - ), - ) - Text( - state.uvIndex?.let { - getUvIndex(it).toLabel(context) - } ?: "No data", - style = TextStyle( - color = textColor, - fontSize = 22.sp, - fontWeight = FontWeight.Medium - ), - ) - Text( - "${state.uvIndex ?: "No data"}", - style = TextStyle( - color = textColor, - fontSize = 48.sp, - fontWeight = FontWeight.Bold - ), - ) - Spacer(GlanceModifier.defaultWeight()) - Text( - stringResource( - R.string.widget_weather_today_max_uv, - "${state.daily[0].maxUvIndex}" - ), - style = TextStyle( - color = textColorVariant, - fontSize = 20.sp, - ), - ) - Text( - stringResource( - R.string.widget_weather_today_max_uv_at, - "${state.daily[0].maxUvIndexAt}" - ), - style = TextStyle( - color = textColorVariant, - fontSize = 18.sp, - ), - ) - } - - } else { - ReloadButton() + Column(modifier = glanceModifier.fillMaxSize().padding(16.dp)) { + Text( + context.getString(R.string.weather_current), + style = TextStyle( + color = textColorVariant, + fontSize = 18.sp, + ), + ) + Text( + state.uvIndex?.let { + getUvIndex(it).toLabel(context) + } ?: "No data", + style = TextStyle( + color = textColor, + fontSize = 22.sp, + fontWeight = FontWeight.Medium + ), + ) + Text( + "${state.uvIndex ?: "No data"}", + style = TextStyle( + color = textColor, + fontSize = 48.sp, + fontWeight = FontWeight.Bold + ), + ) + Spacer(GlanceModifier.defaultWeight()) + Text( + context.getString(R.string.widget_weather_today_max_uv, "${state.daily[0].maxUvIndex}"), + style = TextStyle( + color = textColorVariant, + fontSize = 20.sp, + ), + ) + Text( + context.getString( + R.string.widget_weather_today_max_uv_at, + "${state.daily[0].maxUvIndexAt}" + ), + style = TextStyle( + color = textColorVariant, + fontSize = 18.sp, + ), + ) } + }