diff --git a/feature/trip-planner/network/src/commonMain/kotlin/xyz/ksharma/krail/trip/planner/network/api/model/TripResponse.kt b/feature/trip-planner/network/src/commonMain/kotlin/xyz/ksharma/krail/trip/planner/network/api/model/TripResponse.kt index cd6c4efa..7cb9d3ea 100644 --- a/feature/trip-planner/network/src/commonMain/kotlin/xyz/ksharma/krail/trip/planner/network/api/model/TripResponse.kt +++ b/feature/trip-planner/network/src/commonMain/kotlin/xyz/ksharma/krail/trip/planner/network/api/model/TripResponse.kt @@ -79,6 +79,11 @@ data class TripResponse( */ @SerialName("footPathInfo") val footPathInfo: List? = null, + /** + * This element indicates whether the walking directions are redundant in [footPathInfo]. + */ + @SerialName("footPathInfoRedundant") val footPathInfoRedundant: Boolean? = null, + /** * This element describes a single information message that may be associated with a journey leg. * The data in this is similar to that from add_info endpoint, but is presented differently. diff --git a/feature/trip-planner/ui/src/commonMain/kotlin/xyz/ksharma/krail/trip/planner/ui/timetable/business/TripResponseMapper.kt b/feature/trip-planner/ui/src/commonMain/kotlin/xyz/ksharma/krail/trip/planner/ui/timetable/business/TripResponseMapper.kt index e438eeae..1075efa4 100644 --- a/feature/trip-planner/ui/src/commonMain/kotlin/xyz/ksharma/krail/trip/planner/ui/timetable/business/TripResponseMapper.kt +++ b/feature/trip-planner/ui/src/commonMain/kotlin/xyz/ksharma/krail/trip/planner/ui/timetable/business/TripResponseMapper.kt @@ -37,22 +37,17 @@ internal fun TripResponse.buildJourneyList(): ImmutableList 0 && legsList != null && transportModeLines != null ) { - // A walking leg consists of walking leg + footpath info from public transport leg - val walkingDurationStr = legs.sumOf { leg -> - if (leg.isWalkingLeg()) leg.duration ?: 0L else 0L - }.let { totalDuration -> - val footPathDuration = legs.sumOf { leg -> - leg.footPathInfo?.firstOrNull()?.duration ?: 0L - } - val combinedDuration = totalDuration + footPathDuration - if (combinedDuration == 0L) { - null - } else { - combinedDuration.toDuration(DurationUnit.SECONDS) - .toFormattedDurationTimeString() - } + // A walking leg consists of walking leg + // + footpath info from public transport leg (if footPathInfoRedundant is true) + val totalWalkingDuration = legs.sumOf { leg -> + if (leg.isWalkingLeg() && leg.footPathInfoRedundant != true) + leg.duration ?: 0L else 0L } + val walkingDurationStr = + totalWalkingDuration.takeIf { it > 0L }?.toDuration(DurationUnit.SECONDS) + ?.toFormattedDurationTimeString() + TimeTableState.JourneyCardInfo( timeText = originTimeUTC.getTimeText(), platformText = firstPublicTransportLeg.getPlatformText(), @@ -171,11 +166,9 @@ private fun TripResponse.Leg.toUiModel(): TimeTableState.JourneyCardInfo.Leg? { return when { // Walking Leg - Always check before public transport leg - isWalkingLeg() -> { - displayDuration?.let { - TimeTableState.JourneyCardInfo.Leg.WalkingLeg(duration = displayDuration) - } - } + isWalkingLeg() -> if (displayDuration != null && this.footPathInfoRedundant != true) { + TimeTableState.JourneyCardInfo.Leg.WalkingLeg(duration = displayDuration) + } else null else -> { // Public Transport Leg if (transportMode != null && lineName != null && displayText != null &&