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

✨ Display line names in Switzerland #390

Merged
merged 1 commit into from
Jul 19, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ data class HafasLine(
@SerializedName("fahrtNr") val journeyNumber: Int,
@SerializedName("name") val name: String?,
@SerializedName("product") val product: ProductType?,
@SerializedName("operator") val operator: HafasOperator?
@SerializedName("operator") val operator: HafasOperator?,
val productName: String
) {
val safeProductType get() = product ?: ProductType.UNKNOWN
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import de.hbch.traewelling.api.models.lineIcons.LineIconShape
import de.hbch.traewelling.shared.LineIcons
import de.hbch.traewelling.theme.AppTypography
import de.hbch.traewelling.theme.LineIconStyle
import de.hbch.traewelling.util.getSwitzerlandLineName

@Composable
fun LineIcon(
Expand Down Expand Up @@ -66,7 +67,10 @@ fun LineIcon(
}
} else {
Text(
text = displayedName,
text = getSwitzerlandLineName(
lineId = lineId ?: "",
productName = lineName.split(" ").getOrElse(0) { "" }
) ?: displayedName,
modifier = modifier,
style = defaultTextStyle,
fontWeight = FontWeight.ExtraBold
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import de.hbch.traewelling.ui.tag.StatusTags
import de.hbch.traewelling.ui.user.getDurationString
import de.hbch.traewelling.util.getLocalDateTimeString
import de.hbch.traewelling.util.getLocalTimeString
import de.hbch.traewelling.util.getSwitzerlandLineName
import de.hbch.traewelling.util.shareStatus
import java.time.Duration
import java.time.ZonedDateTime
Expand Down Expand Up @@ -416,7 +417,10 @@ fun StatusDetailsRow(
operatorCode = operatorCode,
lineId = lineId
)
if (displayJourneyNumber && journeyNumber != null && !line.contains(journeyNumber.toString())) {
if (
(displayJourneyNumber && journeyNumber != null && !line.contains(journeyNumber.toString())) ||
(getSwitzerlandLineName(line.split(" ").getOrElse(0) { "" }, lineId ?: "")?.contains(journeyNumber.toString()) != true)
) {
Text(
modifier = alignmentModifier.padding(start = 4.dp),
text = "($journeyNumber)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import de.hbch.traewelling.ui.include.cardSearchStation.CardSearch
import de.hbch.traewelling.util.getDelayColor
import de.hbch.traewelling.util.getLastDestination
import de.hbch.traewelling.util.getLocalTimeString
import de.hbch.traewelling.util.getSwitzerlandLineName
import kotlinx.coroutines.launch
import java.time.Instant
import java.time.ZonedDateTime
Expand Down Expand Up @@ -429,7 +430,10 @@ fun ConnectionListItem(
lineId = hafasLine?.id
)

if (displayJourneyNumber && journeyNumber != null && hafasLine.name?.contains(journeyNumber.toString()) == false) {
if (
(displayJourneyNumber && journeyNumber != null && hafasLine.name?.contains(journeyNumber.toString()) == false) ||
!(getSwitzerlandLineName((hafasLine?.name ?: "").split(" ").getOrElse(0) { "" }, hafasLine?.id ?: "") ?: hafasLine?.name ?: "").contains(journeyNumber.toString())
) {
Text(
text = "($journeyNumber)",
style = AppTypography.bodySmall
Expand Down
11 changes: 10 additions & 1 deletion app/src/main/kotlin/de/hbch/traewelling/util/Adapters.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.stringResource
import com.auth0.android.jwt.JWT
import de.hbch.traewelling.R
import de.hbch.traewelling.api.models.mastodon.CustomEmoji
import de.hbch.traewelling.api.models.station.Station
import de.hbch.traewelling.api.models.trip.HafasTrip
import java.lang.Exception
Expand Down Expand Up @@ -85,6 +84,16 @@ fun getLastDestination(trip: HafasTrip): String {
}
}

fun getSwitzerlandLineName(productName: String, lineId: String): String? {
// 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"
}
return null
}

private fun clarifyRingbahnBerlin(trip: HafasTrip): String {
if (trip.line == null || trip.direction == null || trip.line.operator == null)
return ""
Expand Down
Loading