Skip to content
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 @@ -107,7 +107,7 @@ object PreviewData {
val transferLeg = LegDto(
id = "111",
duration = Duration.parse("PT5M"),
legType = TransferLegDto(
transferLeg = TransferLegDto(
transferType = TransferType.WALK,
legStart = LegStartEndDto(
stopPointRef = "8500218",
Expand All @@ -126,7 +126,7 @@ object PreviewData {
val timedLeg = LegDto(
id = "222",
duration = Duration.parse("PT1H10M"),
legType = TimedLegDto(
timedLeg = TimedLegDto(
legBoard = LegBoardDto(
stopPointRef = "ch:1:sloid:10:3:6",
stopPointName = NameDto(text = "Basel SBB"),
Expand Down Expand Up @@ -210,7 +210,7 @@ object PreviewData {
val cancelledTimedLeg = LegDto(
id = "345",
duration = Duration.parse("PT1H10M"),
legType = TimedLegDto(
timedLeg = TimedLegDto(
legBoard = LegBoardDto(
stopPointRef = "ch:1:sloid:10:3:6",
stopPointName = NameDto(text = "Basel SBB"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package ch.opentransportdata.ojp.data.dto.response.tir

import android.os.Parcelable
import ch.opentransportdata.ojp.data.dto.response.tir.leg.AbstractLegType
import ch.opentransportdata.ojp.data.dto.response.tir.leg.ContinuousLegDto
import ch.opentransportdata.ojp.data.dto.response.tir.leg.TimedLegDto
import ch.opentransportdata.ojp.data.dto.response.tir.leg.TransferLegDto
import com.tickaroo.tikxml.annotation.Element
import com.tickaroo.tikxml.annotation.PropertyElement
import com.tickaroo.tikxml.annotation.Xml
Expand All @@ -18,14 +21,25 @@ data class LegDto(
val id: String,
@PropertyElement(name = "Duration")
val duration: Duration?,
@Element
val legType: AbstractLegType
) : Parcelable
@Element(name = "TimedLeg")
val timedLeg: TimedLegDto? = null,
@Element(name = "TransferLeg")
val transferLeg: TransferLegDto? = null,
@Element(name = "ContinuousLeg")
val continuousLeg: ContinuousLegDto? = null

) : Parcelable {

val legType: AbstractLegType?
get() = timedLeg ?: transferLeg ?: continuousLeg
}

fun LegDto.minimalCopy(): LegDto {
return LegDto(
id = id,
duration = duration,
legType = legType
timedLeg = timedLeg,
transferLeg = transferLeg,
continuousLeg = continuousLeg
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fun DatedJourneyDto.minimalCopy(): DatedJourneyDto {
attributes = attributes,
originText = originText,
conventionalModeOfOperation = null,
trainNumber = null,
trainNumber = trainNumber,
operatorRef = null,
publicCode = null,
directionRef = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,27 @@ data class LegIntermediateDto(
get() = estimatedQuay ?: plannedQuay

}

fun LegIntermediateDto.minimalCopy(): LegIntermediateDto {
return LegIntermediateDto(
stopPointRef = stopPointRef,
stopPointName = stopPointName,
serviceArrival = ServiceTimeDto(
timetabledTime = serviceArrival.timetabledTime,
estimatedTime = serviceArrival.estimatedTime
),
serviceDeparture = ServiceTimeDto(
timetabledTime = serviceDeparture.timetabledTime,
estimatedTime = serviceDeparture.estimatedTime
),
plannedQuay = null,
estimatedQuay = null,
nameSuffix = null,
order = null,
requestStop = null,
unplannedStop = null,
notServicedStop = null,
noBoardingAtStop = null,
noAlightingAtStop = null
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ data class TimedLegDto(
fun TimedLegDto.minimalCopy(): TimedLegDto {
return TimedLegDto(
legBoard = legBoard.minimalCopy(),
legIntermediate = emptyList(),
legIntermediate = legIntermediate?.map { it.minimalCopy() },
legAlight = legAlight.minimalCopy(),
service = service.minimalCopy(),
legTrack = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,29 +67,28 @@ data class TripDto(
get() = if (lastTimedLeg.legAlight.serviceArrival.hasDelay) lastTimedLeg.legAlight.serviceArrival.delay.toMinutes() else 0

val isCarTrainTrip: Boolean
get() = legs.any { it.legType is TimedLegDto && it.legType.service.isCarTrain }

get() = legs.any { (it.legType as? TimedLegDto)?.service?.isCarTrain == true }
/**
* If the trip has [TimedLegDto.isCancelled], [isInfeasible] or [TimedLegDto.hasAnyPlatformChanges]
* set to true, it is marked to have disruptions
*/
val hasAnyDisruption: Boolean
get() = this.legs.any { it.legType is TimedLegDto && it.legType.isCancelled }
get() = legs.any { (it.legType as? TimedLegDto)?.isCancelled == true }
|| isInfeasible
// || this.deviation == true
|| this.legs.any { it.legType is TimedLegDto && it.legType.hasAnyPlatformChanges }
// || deviation == true
|| legs.any { (it.legType as? TimedLegDto)?.hasAnyPlatformChanges == true }

/**
* [infeasible] flag is also set when trip is cancelled. [isInfeasible] shows if the trip is infeasible but not cancelled
*/
val isInfeasible: Boolean
get() = this.legs.none { it.legType is TimedLegDto && it.legType.isCancelled } && this.infeasible == true
get() = !isCancelled && infeasible == true

val isCancelled: Boolean
get() = this.legs.any { it.legType is TimedLegDto && it.legType.isCancelled }
get() = legs.any { (it.legType as? TimedLegDto)?.isCancelled == true }

fun getPtSituationsForTrip(situations: List<PtSituationDto>): List<PtSituationDto> {
return this.legs.mapNotNull { it.legType as? TimedLegDto }.flatMap { it.getPtSituationsForLeg(situations) }.distinct()
return legs.mapNotNull { it.legType as? TimedLegDto }.flatMap { it.getPtSituationsForLeg(situations) }.distinct()
}

override fun equals(other: Any?): Boolean {
Expand Down Expand Up @@ -137,4 +136,4 @@ fun TripDto.minimalCopy(): TripDto {
delayed = null,
infeasible = null,
)
}
}
Loading