Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weather widget updates #93

Merged
merged 4 commits into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions render-compose/api/android/render-compose.api
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,23 @@ public final class ink/ui/render/compose/theme/ColorVariant$Defaults {
public final fun getLight ()Link/ui/render/compose/theme/ColorVariant;
}

public final class ink/ui/render/compose/theme/ColorVariant$Defaults$Colors {
public static final field $stable I
public static final field INSTANCE Link/ui/render/compose/theme/ColorVariant$Defaults$Colors;
public final fun getBLACK-0d7_KjU ()J
public final fun getBLUE-0d7_KjU ()J
public final fun getGRAY-0d7_KjU ()J
public final fun getGREEN-0d7_KjU ()J
public final fun getORANGE-0d7_KjU ()J
public final fun getPURPLE-0d7_KjU ()J
public final fun getRED-0d7_KjU ()J
public final fun getSOFT_BLACK-0d7_KjU ()J
public final fun getSOFT_GRAY-0d7_KjU ()J
public final fun getSOFT_WHITE-0d7_KjU ()J
public final fun getWHITE-0d7_KjU ()J
public final fun getYELLOW-0d7_KjU ()J
}

public final class ink/ui/render/compose/theme/ColorsKt {
public static final fun brighten-DxMtmZc (JF)J
public static final fun darken-DxMtmZc (JF)J
Expand Down
17 changes: 17 additions & 0 deletions render-compose/api/jvm/render-compose.api
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,23 @@ public final class ink/ui/render/compose/theme/ColorVariant$Defaults {
public final fun getLight ()Link/ui/render/compose/theme/ColorVariant;
}

public final class ink/ui/render/compose/theme/ColorVariant$Defaults$Colors {
public static final field $stable I
public static final field INSTANCE Link/ui/render/compose/theme/ColorVariant$Defaults$Colors;
public final fun getBLACK-0d7_KjU ()J
public final fun getBLUE-0d7_KjU ()J
public final fun getGRAY-0d7_KjU ()J
public final fun getGREEN-0d7_KjU ()J
public final fun getORANGE-0d7_KjU ()J
public final fun getPURPLE-0d7_KjU ()J
public final fun getRED-0d7_KjU ()J
public final fun getSOFT_BLACK-0d7_KjU ()J
public final fun getSOFT_GRAY-0d7_KjU ()J
public final fun getSOFT_WHITE-0d7_KjU ()J
public final fun getWHITE-0d7_KjU ()J
public final fun getYELLOW-0d7_KjU ()J
}

public final class ink/ui/render/compose/theme/ColorsKt {
public static final fun brighten-DxMtmZc (JF)J
public static final fun darken-DxMtmZc (JF)J
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:pathData="M240,760q-17,0 -28.5,-11.5T200,720q0,-17 11.5,-28.5T240,680q17,0 28.5,11.5T280,720q0,17 -11.5,28.5T240,760ZM720,760q-17,0 -28.5,-11.5T680,720q0,-17 11.5,-28.5T720,680q17,0 28.5,11.5T760,720q0,17 -11.5,28.5T720,760ZM360,920q-17,0 -28.5,-11.5T320,880q0,-17 11.5,-28.5T360,840q17,0 28.5,11.5T400,880q0,17 -11.5,28.5T360,920ZM480,760q-17,0 -28.5,-11.5T440,720q0,-17 11.5,-28.5T480,680q17,0 28.5,11.5T520,720q0,17 -11.5,28.5T480,760ZM600,920q-17,0 -28.5,-11.5T560,880q0,-17 11.5,-28.5T600,840q17,0 28.5,11.5T640,880q0,17 -11.5,28.5T600,920ZM300,640q-91,0 -155.5,-64.5T80,420q0,-83 55,-145t136,-73q32,-57 87.5,-89.5T480,80q90,0 156.5,57.5T717,281q69,6 116,57t47,122q0,75 -52.5,127.5T700,640L300,640ZM300,560h400q42,0 71,-29t29,-71q0,-42 -29,-71t-71,-29h-60v-40q0,-66 -47,-113t-113,-47q-48,0 -87.5,26T333,256l-10,24h-25q-57,2 -97.5,42.5T160,420q0,58 41,99t99,41ZM480,360Z"
android:fillColor="#5f6368"/>
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ val Symbol.resource: DrawableResource get() = when (this) {
Symbol.Person -> Res.drawable.person
Symbol.Rain -> Res.drawable.rain
Symbol.Remove -> Res.drawable.remove
Symbol.Snow -> Res.drawable.snow
Symbol.Sunshine -> Res.drawable.sunshine
Symbol.Temperature -> Res.drawable.temperature
Symbol.Water -> Res.drawable.water
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,148 @@ package ink.ui.render.compose.renderer
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.ColorFilter
import ink.ui.render.compose.theme.ColorVariant
import ink.ui.render.compose.theme.ComposeRenderTheme
import ink.ui.structures.Symbol
import ink.ui.structures.elements.WeatherElement
import org.jetbrains.compose.resources.DrawableResource
import org.jetbrains.compose.resources.painterResource

val WeatherRenderer = renderer<WeatherElement> { theme, element ->
Box(
contentAlignment = Alignment.Center,
val description = when (element.condition) {
WeatherElement.Condition.Clear -> "Clear"
WeatherElement.Condition.Cloudy -> "Cloudy"
WeatherElement.Condition.Rainy -> "Rainy"
WeatherElement.Condition.Snowy -> "Snowy"
}
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
WeatherElement.Condition.Snowy -> Symbol.Snow.resource
}

val sentiment = element.sentiment
val tint = when {
sentiment != null -> theme.colors.forSentiment(sentiment)
element.condition == WeatherElement.Condition.Rainy -> ColorVariant.Defaults.Colors.BLUE
element.condition == WeatherElement.Condition.Clear -> ColorVariant.Defaults.Colors.YELLOW
element.condition == WeatherElement.Condition.Cloudy -> ColorVariant.Defaults.Colors.GRAY
else -> theme.colors.foreground
}.let(ColorFilter::tint)

if (element.compact) {
InlineRender(
theme = theme,
title = element.title,
icon = icon,
tint = tint,
iconDescription = description,
temperature = element.temperature,
secondaryText = element.secondaryText,
)
} else {
BoxRender(
theme = theme,
title = element.title,
icon = icon,
tint = tint,
iconDescription = description,
temperature = element.temperature,
secondaryText = element.secondaryText,
)
}
}

@Composable
private fun InlineRender(
theme: ComposeRenderTheme,
title: String? = null,
icon: DrawableResource,
tint: ColorFilter,
iconDescription: String,
temperature: String,
secondaryText: String?,
) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.padding(theme.spacing.item)
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
) {
val title = element.title
if (title != null) {
if (title != null && title.isNotBlank()) {
BasicText(
text = title,
style = theme.typography.caption.copy(color = theme.colors.foreground),
)
}
Image(
painterResource(icon),
colorFilter = tint,
contentDescription = iconDescription,
modifier = Modifier.size(theme.sizing.hintIcons)
)
}

val description = when (element.condition) {
WeatherElement.Condition.Clear -> "Clear"
WeatherElement.Condition.Cloudy -> "Cloudy"
WeatherElement.Condition.Rainy -> "Rainy"
Spacer(modifier = Modifier.width(theme.spacing.item))

Column(
horizontalAlignment = Alignment.CenterHorizontally,
) {
BasicText(temperature, style = theme.typography.body.copy(color = theme.colors.foreground))

if (secondaryText != null && secondaryText.isNotBlank()) {
BasicText(secondaryText, style = theme.typography.caption.copy(color = theme.colors.foreground))
}
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
}
}
}

@Composable
private fun BoxRender(
theme: ComposeRenderTheme,
title: String? = null,
icon: DrawableResource,
tint: ColorFilter,
iconDescription: String,
temperature: String,
secondaryText: String?,
) {

Box(
contentAlignment = Alignment.Center,
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
) {
if (title != null) {
BasicText(
text = title,
style = theme.typography.caption.copy(color = theme.colors.foreground),
)
}

Image(
painterResource(icon),
colorFilter = ColorFilter.tint(theme.colors.forSentiment(element.sentiment)),
contentDescription = description,
colorFilter = tint,
contentDescription = iconDescription,
modifier = Modifier.size(theme.sizing.widgetIcons).padding(theme.spacing.item)
)

BasicText(element.temperature, style = theme.typography.body.copy(color = theme.colors.foreground))
BasicText(temperature, style = theme.typography.body.copy(color = theme.colors.foreground))

val secondaryTemperature = element.secondaryText
if (secondaryTemperature != null) {
BasicText(secondaryTemperature, style = theme.typography.caption.copy(color = theme.colors.foreground))
if (secondaryText != null) {
BasicText(secondaryText, style = theme.typography.caption.copy(color = theme.colors.foreground))
}
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,43 @@ data class ColorVariant(
Sentiment.Idle -> idle
}

object Defaults {
object Defaults
{
object Colors
{
val BLACK = Color(0xFF000000)
val WHITE = Color(0xFFFFFFFF)
val SOFT_WHITE = Color(0xFFF8F8F8)
val SOFT_BLACK = Color(0xFF212121)
val GRAY = Color(0xFF90A4AE)
val SOFT_GRAY = Color(0xFF323232)
val RED = Color(0xFFe82a70)
val GREEN = Color(0xFF00a600)
val ORANGE = Color(0xFFfe9720)
val YELLOW = Color(0xFFe3c52d)
val BLUE = Color(0xFF008DA9)
val PURPLE = Color(0xFFa175c9)
}

val light = ColorVariant(
foreground = Color(0xFF212121),
background = Color(0xFFF8F8F8),
surface = Color(0xFFFFFFFF),
primary = Color(0xFF008DA9),
positive = Color(0xFF00a600),
negative = Color(0xFFf92772),
caution = Color(0xFFfe9720),
idle = Color(0xFF90A4AE),
foreground = Colors.SOFT_BLACK,
background = Colors.WHITE,
surface = Colors.WHITE,
primary = Colors.BLUE,
positive = Colors.GREEN,
negative = Colors.RED,
caution = Colors.ORANGE,
idle = Colors.GRAY,
).let {
it.copy(
surfaceInteraction = it.surface.darken(0.1f),
)
}

val dark = light.copy(
foreground = Color(0xFFFFFFFF),
background = Color(0xFF212121),
surface = Color(0xFF323232),
foreground = Colors.WHITE,
background = Colors.SOFT_BLACK,
surface = Colors.SOFT_GRAY,
).let {
it.copy(
surfaceInteraction = it.surface.brighten(0.1f),
Expand Down
40 changes: 40 additions & 0 deletions sample-android/src/main/kotlin/example/SampleScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ val SampleScreen = ScrollingListLayout(
temperature = "72",
condition = WeatherElement.Condition.Clear,
),
WeatherElement(
title = "Sun",
temperature = "72",
secondaryText = "60",
condition = WeatherElement.Condition.Snowy,
),
WeatherElement(
temperature = "72",
condition = WeatherElement.Condition.Cloudy,
),
WeatherElement(
title = "Sun",
temperature = "72",
Expand All @@ -98,6 +108,36 @@ val SampleScreen = ScrollingListLayout(
positioning = Positioning.Center,
orientation = Orientation.Horizontal,
),
ElementList(
items = listOf(
WeatherElement(
temperature = "72",
condition = WeatherElement.Condition.Clear,
compact = true,
),
WeatherElement(
title = "Sun",
temperature = "72",
secondaryText = "60",
condition = WeatherElement.Condition.Snowy,
compact = true,
),
WeatherElement(
temperature = "72",
condition = WeatherElement.Condition.Cloudy,
compact = true,
),
WeatherElement(
title = "Sun",
temperature = "72",
secondaryText = "60",
condition = WeatherElement.Condition.Rainy,
compact = true,
),
),
positioning = Positioning.Start,
orientation = Orientation.Horizontal,
),
SpinnerElement(
value = "5",
onNextValue = {},
Expand Down
12 changes: 8 additions & 4 deletions structures/api/structures.api
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public final class ink/ui/structures/Symbol$Companion {
public final fun getPerson-ZR4vNbg ()Ljava/lang/String;
public final fun getRain-ZR4vNbg ()Ljava/lang/String;
public final fun getRemove-ZR4vNbg ()Ljava/lang/String;
public final fun getSnow-ZR4vNbg ()Ljava/lang/String;
public final fun getSunshine-ZR4vNbg ()Ljava/lang/String;
public final fun getTemperature-ZR4vNbg ()Ljava/lang/String;
public final fun getWater-ZR4vNbg ()Ljava/lang/String;
Expand Down Expand Up @@ -527,17 +528,19 @@ 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;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 fun <init> (Ljava/lang/String;Link/ui/structures/elements/WeatherElement$Condition;Ljava/lang/String;Ljava/lang/String;ZLink/ui/structures/Sentiment;Z)V
public synthetic fun <init> (Ljava/lang/String;Link/ui/structures/elements/WeatherElement$Condition;Ljava/lang/String;Ljava/lang/String;ZLink/ui/structures/Sentiment;ZILkotlin/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 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 final fun component7 ()Z
public final fun copy (Ljava/lang/String;Link/ui/structures/elements/WeatherElement$Condition;Ljava/lang/String;Ljava/lang/String;ZLink/ui/structures/Sentiment;Z)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;ZILjava/lang/Object;)Link/ui/structures/elements/WeatherElement;
public fun equals (Ljava/lang/Object;)Z
public final fun getCompact ()Z
public final fun getCondition ()Link/ui/structures/elements/WeatherElement$Condition;
public final fun getDaytime ()Z
public final fun getSecondaryText ()Ljava/lang/String;
Expand All @@ -552,6 +555,7 @@ public final class ink/ui/structures/elements/WeatherElement$Condition : java/la
public static final field Clear Link/ui/structures/elements/WeatherElement$Condition;
public static final field Cloudy Link/ui/structures/elements/WeatherElement$Condition;
public static final field Rainy Link/ui/structures/elements/WeatherElement$Condition;
public static final field Snowy Link/ui/structures/elements/WeatherElement$Condition;
public static fun getEntries ()Lkotlin/enums/EnumEntries;
public static fun valueOf (Ljava/lang/String;)Link/ui/structures/elements/WeatherElement$Condition;
public static fun values ()[Link/ui/structures/elements/WeatherElement$Condition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ value class Symbol(val key: String) {
val Movie = Symbol("Movie")
val Person = Symbol("Person")
val Rain = Symbol("Rain")
val Snow = Symbol("Snow")
val Remove = Symbol("Remove")
val Sunshine = Symbol("Sunshine")
val Temperature = Symbol("Temperature")
Expand Down
Loading
Loading