From 0450db6bb8a7d3c56cf7257e58c2f21c2071cb5e Mon Sep 17 00:00:00 2001 From: Renee Vandervelde Date: Tue, 3 Sep 2024 21:06:40 -0500 Subject: [PATCH] Add sentiments and daytime indicator to weather element --- .../compose/renderer/WeatherRenderer.kt | 49 ++++++++----------- .../src/main/kotlin/example/SampleScreen.kt | 2 +- structures/api/structures.api | 14 ++++-- .../ui/structures/elements/WeatherElement.kt | 7 ++- 4 files changed, 37 insertions(+), 35 deletions(-) diff --git a/render-compose/src/commonMain/kotlin/ink/ui/render/compose/renderer/WeatherRenderer.kt b/render-compose/src/commonMain/kotlin/ink/ui/render/compose/renderer/WeatherRenderer.kt index 7714690..2f2931a 100644 --- a/render-compose/src/commonMain/kotlin/ink/ui/render/compose/renderer/WeatherRenderer.kt +++ b/render-compose/src/commonMain/kotlin/ink/ui/render/compose/renderer/WeatherRenderer.kt @@ -6,7 +6,6 @@ import androidx.compose.foundation.text.BasicText import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.ColorFilter -import ink.ui.structures.Sentiment import ink.ui.structures.Symbol import ink.ui.structures.elements.WeatherElement import org.jetbrains.compose.resources.painterResource @@ -26,32 +25,31 @@ val WeatherRenderer = renderer { theme, element -> ) } - when (element.condition) { - WeatherElement.Condition.Clear -> Image( - painterResource(Symbol.Sunshine.resource), - colorFilter = ColorFilter.tint(theme.colors.forSentiment(Sentiment.Nominal)), - contentDescription = element.condition.description, - modifier = Modifier.size(theme.sizing.widgetIcons).padding(theme.spacing.item) - ) - - WeatherElement.Condition.Cloudy -> Image( - painterResource(Symbol.Cloud.resource), - colorFilter = ColorFilter.tint(theme.colors.forSentiment(Sentiment.Nominal)), - contentDescription = element.condition.description, - modifier = Modifier.size(theme.sizing.widgetIcons).padding(theme.spacing.item) - ) - - WeatherElement.Condition.Rainy -> Image( - painterResource(Symbol.Rain.resource), - colorFilter = ColorFilter.tint(theme.colors.forSentiment(Sentiment.Nominal)), - contentDescription = element.condition.description, - modifier = Modifier.size(theme.sizing.widgetIcons).padding(theme.spacing.item) - ) + val description = when (element.condition) { + WeatherElement.Condition.Clear -> "Clear" + WeatherElement.Condition.Cloudy -> "Cloudy" + WeatherElement.Condition.Rainy -> "Rainy" + } + val icon = when (element.condition) { + WeatherElement.Condition.Clear -> if (element.daytime) { + Symbol.Sunshine.resource + } else { + Symbol.Moon.resource + } + WeatherElement.Condition.Cloudy -> Symbol.Cloud.resource + WeatherElement.Condition.Rainy -> Symbol.Rain.resource } + Image( + painterResource(icon), + colorFilter = ColorFilter.tint(theme.colors.forSentiment(element.sentiment)), + contentDescription = description, + modifier = Modifier.size(theme.sizing.widgetIcons).padding(theme.spacing.item) + ) + BasicText(element.temperature, style = theme.typography.body.copy(color = theme.colors.foreground)) - val secondaryTemperature = element.secondaryTemperature + val secondaryTemperature = element.secondaryText if (secondaryTemperature != null) { BasicText(secondaryTemperature, style = theme.typography.caption.copy(color = theme.colors.foreground)) } @@ -59,8 +57,3 @@ val WeatherRenderer = renderer { theme, element -> } } -private val WeatherElement.Condition.description get() = when (this) { - WeatherElement.Condition.Clear -> "Clear" - WeatherElement.Condition.Cloudy -> "Cloudy" - WeatherElement.Condition.Rainy -> "Rainy" -} diff --git a/sample-android/src/main/kotlin/example/SampleScreen.kt b/sample-android/src/main/kotlin/example/SampleScreen.kt index 87b204c..cfe02ec 100644 --- a/sample-android/src/main/kotlin/example/SampleScreen.kt +++ b/sample-android/src/main/kotlin/example/SampleScreen.kt @@ -91,7 +91,7 @@ val SampleScreen = ScrollingListLayout( WeatherElement( title = "Sun", temperature = "72", - secondaryTemperature = "60", + secondaryText = "60", condition = WeatherElement.Condition.Rainy, ), ), diff --git a/structures/api/structures.api b/structures/api/structures.api index 9c07b93..99831c8 100644 --- a/structures/api/structures.api +++ b/structures/api/structures.api @@ -395,17 +395,21 @@ public abstract interface class ink/ui/structures/elements/UiElement$Static : in } public final class ink/ui/structures/elements/WeatherElement : ink/ui/structures/elements/UiElement$Static { - public fun (Ljava/lang/String;Link/ui/structures/elements/WeatherElement$Condition;Ljava/lang/String;Ljava/lang/String;)V - public synthetic fun (Ljava/lang/String;Link/ui/structures/elements/WeatherElement$Condition;Ljava/lang/String;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun (Ljava/lang/String;Link/ui/structures/elements/WeatherElement$Condition;Ljava/lang/String;Ljava/lang/String;ZLink/ui/structures/Sentiment;)V + public synthetic fun (Ljava/lang/String;Link/ui/structures/elements/WeatherElement$Condition;Ljava/lang/String;Ljava/lang/String;ZLink/ui/structures/Sentiment;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public final fun component1 ()Ljava/lang/String; public final fun component2 ()Link/ui/structures/elements/WeatherElement$Condition; public final fun component3 ()Ljava/lang/String; public final fun component4 ()Ljava/lang/String; - public final fun copy (Ljava/lang/String;Link/ui/structures/elements/WeatherElement$Condition;Ljava/lang/String;Ljava/lang/String;)Link/ui/structures/elements/WeatherElement; - public static synthetic fun copy$default (Link/ui/structures/elements/WeatherElement;Ljava/lang/String;Link/ui/structures/elements/WeatherElement$Condition;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Link/ui/structures/elements/WeatherElement; + public final fun component5 ()Z + public final fun component6 ()Link/ui/structures/Sentiment; + public final fun copy (Ljava/lang/String;Link/ui/structures/elements/WeatherElement$Condition;Ljava/lang/String;Ljava/lang/String;ZLink/ui/structures/Sentiment;)Link/ui/structures/elements/WeatherElement; + public static synthetic fun copy$default (Link/ui/structures/elements/WeatherElement;Ljava/lang/String;Link/ui/structures/elements/WeatherElement$Condition;Ljava/lang/String;Ljava/lang/String;ZLink/ui/structures/Sentiment;ILjava/lang/Object;)Link/ui/structures/elements/WeatherElement; public fun equals (Ljava/lang/Object;)Z public final fun getCondition ()Link/ui/structures/elements/WeatherElement$Condition; - public final fun getSecondaryTemperature ()Ljava/lang/String; + public final fun getDaytime ()Z + public final fun getSecondaryText ()Ljava/lang/String; + public final fun getSentiment ()Link/ui/structures/Sentiment; public final fun getTemperature ()Ljava/lang/String; public final fun getTitle ()Ljava/lang/String; public fun hashCode ()I diff --git a/structures/src/commonMain/kotlin/ink/ui/structures/elements/WeatherElement.kt b/structures/src/commonMain/kotlin/ink/ui/structures/elements/WeatherElement.kt index 01ed537..448b2c9 100644 --- a/structures/src/commonMain/kotlin/ink/ui/structures/elements/WeatherElement.kt +++ b/structures/src/commonMain/kotlin/ink/ui/structures/elements/WeatherElement.kt @@ -1,11 +1,16 @@ package ink.ui.structures.elements +import ink.ui.structures.Sentiment + data class WeatherElement( val temperature: String, val condition: Condition, - val secondaryTemperature: String? = null, + val secondaryText: String? = null, val title: String? = null, + val daytime: Boolean = true, + val sentiment: Sentiment = Sentiment.Nominal, ): UiElement.Static { + enum class Condition { Clear, Cloudy,