Skip to content
This repository was archived by the owner on May 9, 2025. It is now read-only.

Commit f82fdaf

Browse files
✨ Implement circle shape (#466)
Signed-off-by: The one with the braid <info@braid.business>
1 parent a27d4c7 commit f82fdaf

File tree

2 files changed

+34
-19
lines changed

2 files changed

+34
-19
lines changed

app/src/main/kotlin/de/hbch/traewelling/api/models/lineIcons/LineIcon.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ data class LineIcon(
1919
}
2020

2121
enum class LineIconShape {
22-
rectangle,
22+
circle,
23+
hexagon,
2324
pill,
25+
rectangle,
26+
rectangle_rounded_corner,
2427
trapezoid,
25-
hexagon,
26-
rectangle_rounded_corner
2728
}

app/src/main/kotlin/de/hbch/traewelling/ui/composables/LineIcon.kt

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@ package de.hbch.traewelling.ui.composables
22

33
import androidx.compose.foundation.background
44
import androidx.compose.foundation.border
5-
import androidx.compose.foundation.layout.Arrangement
6-
import androidx.compose.foundation.layout.Box
7-
import androidx.compose.foundation.layout.Row
8-
import androidx.compose.foundation.layout.padding
9-
import androidx.compose.foundation.layout.widthIn
5+
import androidx.compose.foundation.layout.*
6+
import androidx.compose.foundation.shape.CircleShape
107
import androidx.compose.foundation.shape.RoundedCornerShape
118
import androidx.compose.material3.Text
129
import androidx.compose.runtime.Composable
@@ -56,6 +53,7 @@ fun LineIcon(
5653
}
5754

5855
val shape: Shape = when (lineIcon?.shape) {
56+
LineIconShape.circle -> CircleShape
5957
LineIconShape.hexagon -> HexagonShape()
6058
LineIconShape.pill -> RoundedCornerShape(percent = 50)
6159
LineIconShape.rectangle_rounded_corner -> RoundedCornerShape(percent = 20)
@@ -79,14 +77,26 @@ fun LineIcon(
7977
) {
8078
if (lineIcon != null) {
8179
Box(
82-
modifier = Modifier
83-
.widthIn(48.dp, 144.dp)
84-
.background(
85-
color = lineIcon.getBackgroundColor(),
86-
shape = shape
87-
)
88-
.border(2.dp, borderColor, shape)
89-
.padding(2.dp)
80+
modifier = when (lineIcon.shape) {
81+
LineIconShape.circle -> Modifier
82+
.width(32.dp)
83+
.aspectRatio(1f)
84+
.background(
85+
color = lineIcon.getBackgroundColor(),
86+
shape = shape
87+
)
88+
.border(2.dp, borderColor, shape)
89+
.padding(2.dp)
90+
91+
else -> Modifier
92+
.widthIn(48.dp, 144.dp)
93+
.background(
94+
color = lineIcon.getBackgroundColor(),
95+
shape = shape
96+
)
97+
.border(2.dp, borderColor, shape)
98+
.padding(2.dp)
99+
}
90100
) {
91101
Text(
92102
text = displayedName,
@@ -96,7 +106,7 @@ fun LineIcon(
96106
fontWeight = FontWeight.Bold
97107
)
98108
}
99-
} else if (switzerlandString?.first != null) {
109+
} else if (switzerlandString?.first != null) {
100110
Box(
101111
modifier = Modifier
102112
.widthIn(48.dp, 144.dp)
@@ -125,7 +135,8 @@ fun LineIcon(
125135
if (displayJourneyNumber
126136
&& displayJourneyNumberSetting
127137
&& !displayedName.contains(journeyNumber.toString())
128-
&& journeyNumber != null && journeyNumber != 0) {
138+
&& journeyNumber != null && journeyNumber != 0
139+
) {
129140
Text(
130141
text = "($journeyNumber)",
131142
style = LocalFont.current.bodySmall
@@ -150,8 +161,11 @@ fun LineIconView(
150161
}
151162

152163
val shape: Shape = when (lineIcon?.shape) {
164+
LineIconShape.circle -> CircleShape
165+
LineIconShape.hexagon -> HexagonShape()
153166
LineIconShape.pill -> RoundedCornerShape(percent = 50)
154167
LineIconShape.rectangle_rounded_corner -> RoundedCornerShape(percent = 20)
168+
LineIconShape.trapezoid -> TrapezoidShape()
155169
else -> RectangleShape
156170
}
157171
val borderColor: Color = lineIcon?.getBorderColor() ?: Color.Transparent
@@ -188,7 +202,7 @@ fun LineIconView(
188202
fontWeight = FontWeight.Bold
189203
)
190204
}
191-
} else if (switzerlandString?.first != null) {
205+
} else if (switzerlandString?.first != null) {
192206
Box(
193207
modifier = Modifier
194208
.widthIn(48.dp, 144.dp)

0 commit comments

Comments
 (0)