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..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 @@ -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 ?: switzerlandString?.first?.text ?: 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..a11738cb 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,21 @@ 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.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 import de.hbch.traewelling.api.models.station.Station @@ -84,14 +96,47 @@ 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 + "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 && italicProduct == null) + return null + + if (icon != null) { + builder.appendInlineContent("product", productName) + inlineTextContent["product"] = InlineTextContent( + Placeholder(28.sp, 12.sp, PlaceholderVerticalAlign.TextCenter) + ) { + Icon( + painter = painterResource(id = icon), + contentDescription = null, + tint = Color.White, + modifier = Modifier.fillMaxSize() + ) + } + } + if (italicProduct != null) { + builder.pushStyle(SpanStyle(fontStyle = FontStyle.Italic)) + builder.append(italicProduct) + builder.pop() + } + 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_ec.xml b/app/src/main/res/drawable/ic_ch_ec.xml new file mode 100644 index 00000000..0bb67c19 --- /dev/null +++ b/app/src/main/res/drawable/ic_ch_ec.xml @@ -0,0 +1,11 @@ + + + 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 @@ + + + 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 @@ + + + + +