From 80de539fd977b90819df652a977aa83a6c9804da Mon Sep 17 00:00:00 2001 From: Jonas Heubuch Date: Wed, 31 Jul 2024 16:35:40 +0200 Subject: [PATCH 1/4] interregio --- .../traewelling/ui/composables/LineIcon.kt | 30 +++++++++--- .../de/hbch/traewelling/util/Adapters.kt | 47 ++++++++++++++++--- app/src/main/res/drawable/ic_ch_ir.xml | 5 ++ 3 files changed, 70 insertions(+), 12 deletions(-) create mode 100644 app/src/main/res/drawable/ic_ch_ir.xml diff --git a/app/src/main/kotlin/de/hbch/traewelling/ui/composables/LineIcon.kt b/app/src/main/kotlin/de/hbch/traewelling/ui/composables/LineIcon.kt index 353f869f..cbbde5a6 100644 --- a/app/src/main/kotlin/de/hbch/traewelling/ui/composables/LineIcon.kt +++ b/app/src/main/kotlin/de/hbch/traewelling/ui/composables/LineIcon.kt @@ -60,13 +60,13 @@ fun LineIcon( } val borderColor: Color = lineIcon?.getBorderColor() ?: Color.Transparent + val switzerlandString = getSwitzerlandLineName( + lineId = lineId ?: "", + productName = lineName.split(" ").getOrElse(0) { "" } + ) + val displayedName = - lineIcon?.displayedName - ?: getSwitzerlandLineName( - lineId = lineId ?: "", - productName = lineName.split(" ").getOrElse(0) { "" } - ) - ?: lineName + lineIcon?.displayedName ?: lineName Row( modifier = modifier, @@ -92,6 +92,24 @@ fun LineIcon( fontWeight = FontWeight.Bold ) } + } else if (switzerlandString.first != null) { + Box( + modifier = Modifier + .widthIn(48.dp, 144.dp) + .background( + color = Color.Red + ) + .padding(2.dp) + ) { + Text( + text = switzerlandString.first!!, + color = Color.White, + style = LineIconStyle, + fontWeight = FontWeight.Bold, + inlineContent = switzerlandString.second, + modifier = Modifier.align(Alignment.Center) + ) + } } else { Text( text = displayedName, diff --git a/app/src/main/kotlin/de/hbch/traewelling/util/Adapters.kt b/app/src/main/kotlin/de/hbch/traewelling/util/Adapters.kt index 80ce06ba..aa06243c 100644 --- a/app/src/main/kotlin/de/hbch/traewelling/util/Adapters.kt +++ b/app/src/main/kotlin/de/hbch/traewelling/util/Adapters.kt @@ -1,9 +1,19 @@ package de.hbch.traewelling.util +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.text.InlineTextContent +import androidx.compose.foundation.text.appendInlineContent +import androidx.compose.material3.Icon import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.colorResource +import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.AnnotatedString +import androidx.compose.ui.text.Placeholder +import androidx.compose.ui.text.PlaceholderVerticalAlign +import androidx.compose.ui.unit.sp import com.auth0.android.jwt.JWT import de.hbch.traewelling.R import de.hbch.traewelling.api.models.station.Station @@ -84,14 +94,39 @@ fun getLastDestination(trip: HafasTrip): String { } } -fun getSwitzerlandLineName(productName: String, lineId: String): String? { +fun getSwitzerlandLineName(productName: String, lineId: String): Pair> { // Switzerland lines start with 85 in the second block of line id - val splitLineId = lineId.split("-") - if (splitLineId.getOrNull(1)?.startsWith("85") == true) { - val lineNumber = lineId.split("-").getOrNull(2) ?: return null - return "$productName ${lineNumber.uppercase()}" + val match = "\\w+-85\\w*-(\\w+)\$".toRegex().find(lineId) + if (match != null) { + val inlineTextContent = mutableMapOf() + val builder = AnnotatedString.Builder() + + val icon = when(productName) { + "IR" -> R.drawable.ic_ch_ir + else -> null + } + + if (icon == null) { + builder.append(productName) + } else { + builder.appendInlineContent("product", productName) + inlineTextContent["product"] = InlineTextContent( + Placeholder(28.sp, 12.sp, PlaceholderVerticalAlign.Center) + ) { + Icon( + painter = painterResource(id = icon), + contentDescription = null, + tint = Color.White, + modifier = Modifier.fillMaxSize() + ) + //Box(modifier = Modifier.fillMaxSize().background(color = Color.Green)) + } + } + builder.append(" ") + builder.append(match.groupValues.getOrNull(1)?.uppercase() ?: "") + return Pair(builder.toAnnotatedString(), inlineTextContent) } - return null + return Pair(null, mapOf()) } private fun clarifyRingbahnBerlin(trip: HafasTrip): String { diff --git a/app/src/main/res/drawable/ic_ch_ir.xml b/app/src/main/res/drawable/ic_ch_ir.xml new file mode 100644 index 00000000..f65c8d85 --- /dev/null +++ b/app/src/main/res/drawable/ic_ch_ir.xml @@ -0,0 +1,5 @@ + + + + + From d777a6b6ba2d24f85fb347e841ab20f5c52e1ddf Mon Sep 17 00:00:00 2001 From: Jonas Heubuch Date: Wed, 31 Jul 2024 18:54:33 +0200 Subject: [PATCH 2/4] intercity --- .../main/kotlin/de/hbch/traewelling/util/Adapters.kt | 1 + app/src/main/res/drawable/ic_ch_ic.xml | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100644 app/src/main/res/drawable/ic_ch_ic.xml diff --git a/app/src/main/kotlin/de/hbch/traewelling/util/Adapters.kt b/app/src/main/kotlin/de/hbch/traewelling/util/Adapters.kt index aa06243c..548aee67 100644 --- a/app/src/main/kotlin/de/hbch/traewelling/util/Adapters.kt +++ b/app/src/main/kotlin/de/hbch/traewelling/util/Adapters.kt @@ -103,6 +103,7 @@ fun getSwitzerlandLineName(productName: String, lineId: String): Pair R.drawable.ic_ch_ir + "IC" -> R.drawable.ic_ch_ic else -> null } diff --git a/app/src/main/res/drawable/ic_ch_ic.xml b/app/src/main/res/drawable/ic_ch_ic.xml new file mode 100644 index 00000000..e744dfea --- /dev/null +++ b/app/src/main/res/drawable/ic_ch_ic.xml @@ -0,0 +1,11 @@ + + + From 44b51c7813f50f5905c99b992fe53b5b9511bc1f Mon Sep 17 00:00:00 2001 From: Jonas Heubuch Date: Wed, 31 Jul 2024 20:41:15 +0200 Subject: [PATCH 3/4] :sparkles: Add swiss product icons --- .../traewelling/ui/composables/LineIcon.kt | 2 +- .../de/hbch/traewelling/util/Adapters.kt | 21 +++++++++++++------ app/src/main/res/drawable/ic_ch_ec.xml | 11 ++++++++++ 3 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 app/src/main/res/drawable/ic_ch_ec.xml diff --git a/app/src/main/kotlin/de/hbch/traewelling/ui/composables/LineIcon.kt b/app/src/main/kotlin/de/hbch/traewelling/ui/composables/LineIcon.kt index cbbde5a6..095a0b17 100644 --- a/app/src/main/kotlin/de/hbch/traewelling/ui/composables/LineIcon.kt +++ b/app/src/main/kotlin/de/hbch/traewelling/ui/composables/LineIcon.kt @@ -92,7 +92,7 @@ fun LineIcon( fontWeight = FontWeight.Bold ) } - } else if (switzerlandString.first != null) { + } else if (switzerlandString?.first != null) { Box( modifier = Modifier .widthIn(48.dp, 144.dp) diff --git a/app/src/main/kotlin/de/hbch/traewelling/util/Adapters.kt b/app/src/main/kotlin/de/hbch/traewelling/util/Adapters.kt index 548aee67..a11738cb 100644 --- a/app/src/main/kotlin/de/hbch/traewelling/util/Adapters.kt +++ b/app/src/main/kotlin/de/hbch/traewelling/util/Adapters.kt @@ -13,6 +13,8 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.AnnotatedString import androidx.compose.ui.text.Placeholder import androidx.compose.ui.text.PlaceholderVerticalAlign +import androidx.compose.ui.text.SpanStyle +import androidx.compose.ui.text.font.FontStyle import androidx.compose.ui.unit.sp import com.auth0.android.jwt.JWT import de.hbch.traewelling.R @@ -94,7 +96,7 @@ fun getLastDestination(trip: HafasTrip): String { } } -fun getSwitzerlandLineName(productName: String, lineId: String): Pair> { +fun getSwitzerlandLineName(productName: String, lineId: String): Pair>? { // Switzerland lines start with 85 in the second block of line id val match = "\\w+-85\\w*-(\\w+)\$".toRegex().find(lineId) if (match != null) { @@ -104,15 +106,18 @@ fun getSwitzerlandLineName(productName: String, lineId: String): Pair R.drawable.ic_ch_ir "IC" -> R.drawable.ic_ch_ic + "EC" -> R.drawable.ic_ch_ec else -> null } + val italicProduct = if (productName == "PE") "PE" else null - if (icon == null) { - builder.append(productName) - } else { + if (icon == null && italicProduct == null) + return null + + if (icon != null) { builder.appendInlineContent("product", productName) inlineTextContent["product"] = InlineTextContent( - Placeholder(28.sp, 12.sp, PlaceholderVerticalAlign.Center) + Placeholder(28.sp, 12.sp, PlaceholderVerticalAlign.TextCenter) ) { Icon( painter = painterResource(id = icon), @@ -120,9 +125,13 @@ fun getSwitzerlandLineName(productName: String, lineId: String): Pair + + From 07f8caeb8c7f15924bf8d592896d444898d701d3 Mon Sep 17 00:00:00 2001 From: Jonas Heubuch Date: Wed, 31 Jul 2024 20:47:11 +0200 Subject: [PATCH 4/4] :sparkles: Add swiss product icons --- .../main/kotlin/de/hbch/traewelling/ui/composables/LineIcon.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/kotlin/de/hbch/traewelling/ui/composables/LineIcon.kt b/app/src/main/kotlin/de/hbch/traewelling/ui/composables/LineIcon.kt index 095a0b17..128fb4b4 100644 --- a/app/src/main/kotlin/de/hbch/traewelling/ui/composables/LineIcon.kt +++ b/app/src/main/kotlin/de/hbch/traewelling/ui/composables/LineIcon.kt @@ -66,7 +66,7 @@ fun LineIcon( ) val displayedName = - lineIcon?.displayedName ?: lineName + lineIcon?.displayedName ?: switzerlandString?.first?.text ?: lineName Row( modifier = modifier,