Skip to content

Commit

Permalink
Merge pull request #32 from InkApplications/weather-sentiments
Browse files Browse the repository at this point in the history
Add sentiments and daytime indicator to weather element
  • Loading branch information
ReneeVandervelde authored Sep 4, 2024
2 parents 3969628 + 0450db6 commit 72d8823
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,41 +25,35 @@ val WeatherRenderer = renderer<WeatherElement> { 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))
}
}
}
}

private val WeatherElement.Condition.description get() = when (this) {
WeatherElement.Condition.Clear -> "Clear"
WeatherElement.Condition.Cloudy -> "Cloudy"
WeatherElement.Condition.Rainy -> "Rainy"
}
2 changes: 1 addition & 1 deletion sample-android/src/main/kotlin/example/SampleScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ val SampleScreen = ScrollingListLayout(
WeatherElement(
title = "Sun",
temperature = "72",
secondaryTemperature = "60",
secondaryText = "60",
condition = WeatherElement.Condition.Rainy,
),
),
Expand Down
14 changes: 9 additions & 5 deletions structures/api/structures.api
Original file line number Diff line number Diff line change
Expand Up @@ -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 <init> (Ljava/lang/String;Link/ui/structures/elements/WeatherElement$Condition;Ljava/lang/String;Ljava/lang/String;)V
public synthetic fun <init> (Ljava/lang/String;Link/ui/structures/elements/WeatherElement$Condition;Ljava/lang/String;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Ljava/lang/String;Link/ui/structures/elements/WeatherElement$Condition;Ljava/lang/String;Ljava/lang/String;ZLink/ui/structures/Sentiment;)V
public synthetic fun <init> (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
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down

0 comments on commit 72d8823

Please sign in to comment.