Skip to content

Commit

Permalink
UI: Display intermediate stops in journey timeline (#247)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksharma-xyz authored Oct 24, 2024
1 parent d580276 commit a5796ee
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,19 @@ data class TimeTableState(
* transportation.disassembledName -> lineName
* transportation.product.class -> TransportModeType
*/
val transportModeLines: ImmutableList<TransportModeLine>? = null,
val transportModeLines: ImmutableList<TransportModeLine>,

val legs: ImmutableList<Leg>,
) {
val journeyId: String
get() = (
originUtcDateTime + destinationTime + transportModeLines
?.joinToString { it.lineName }
).filter { it.isLetterOrDigit() }
get() = buildString {
append(originUtcDateTime)
append(destinationTime)
append(
transportModeLines.joinToString { it.lineName }
.filter { it.isLetterOrDigit() },
)
}

sealed class Leg {
data class WalkingLeg(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ fun JourneyCard(
destinationTime: String,
totalTravelTime: String,
isWheelchairAccessible: Boolean,
transportModeList: ImmutableList<TransportMode>,
onClick: () -> Unit,
modifier: Modifier = Modifier,
platformNumber: Char? = null,
transportModeList: ImmutableList<TransportMode>? = null,
) {
val onSurface: Color = KrailTheme.colors.onSurface
val borderColors = remember(transportModeList) { transportModeList.toColors(onSurface) }
val themeColor = transportModeList?.firstOrNull()?.colorCode?.hexToComposeColor()
val themeColor = transportModeList.firstOrNull()?.colorCode?.hexToComposeColor()
?: KrailTheme.colors.onSurface

Column(
Expand Down Expand Up @@ -102,7 +102,7 @@ fun JourneyCard(
.weight(1f),
horizontalArrangement = Arrangement.spacedBy(6.dp),
) {
transportModeList?.forEachIndexed { index, mode ->
transportModeList.forEachIndexed { index, mode ->
TransportModeIcon(
letter = mode.name.first(),
backgroundColor = mode.colorCode.hexToComposeColor(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ fun TimeTableScreen(
originTime = journey.originTime,
destinationTime = journey.destinationTime,
durationText = journey.travelTime,
transportModeLineList = journey.transportModeLines?.map {
transportModeLineList = journey.transportModeLines.map {
TransportModeLine(
transportMode = it.transportMode,
lineName = it.lineName,
)
}?.toImmutableList(),
}.toImmutableList(),
onClick = {
onEvent(TimeTableUiEvent.JourneyCardClicked(journey.journeyId))
},
Expand All @@ -127,16 +127,17 @@ fun JourneyCardItem(
modifier: Modifier = Modifier,
transportModeLineList: ImmutableList<TransportModeLine>? = null,
) {
JourneyCard(
timeToDeparture = timeToDeparture,
originTime = originTime,
destinationTime = destinationTime,
totalTravelTime = durationText,
platformNumber = departureLocationNumber,
isWheelchairAccessible = false,
transportModeList = transportModeLineList.takeIf { it?.isNotEmpty() == true }
?.map { it.transportMode }?.toImmutableList(),
onClick = onClick,
modifier = modifier,
)
if (!transportModeLineList.isNullOrEmpty()) {
JourneyCard(
timeToDeparture = timeToDeparture,
originTime = originTime,
destinationTime = destinationTime,
totalTravelTime = durationText,
platformNumber = departureLocationNumber,
isWheelchairAccessible = false,
transportModeList = transportModeLineList.map { it.transportMode }.toImmutableList(),
onClick = onClick,
modifier = modifier,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ internal fun TripResponse.buildJourneyList(): ImmutableList<TimeTableState.Journ
val transportModeLines = legs?.getTransportModeLines()
val legsList = legs?.getLegsList()

if (originTimeUTC != null && arrivalTimeUTC != null && totalStops > 0 && legsList != null) {
if (originTimeUTC != null && arrivalTimeUTC != null && totalStops > 0 && legsList != null &&
transportModeLines != null
) {
TimeTableState.JourneyCardInfo(
timeText = originTimeUTC.getTimeText(),
platformText = platformText,
Expand Down

0 comments on commit a5796ee

Please sign in to comment.