diff --git a/src/main/java/org/mtransit/android/commons/provider/serviceupdate/GTFSRealTimeServiceAlertsProvider.kt b/src/main/java/org/mtransit/android/commons/provider/serviceupdate/GTFSRealTimeServiceAlertsProvider.kt index b0e085ea..30a05bc9 100644 --- a/src/main/java/org/mtransit/android/commons/provider/serviceupdate/GTFSRealTimeServiceAlertsProvider.kt +++ b/src/main/java/org/mtransit/android/commons/provider/serviceupdate/GTFSRealTimeServiceAlertsProvider.kt @@ -18,8 +18,10 @@ import org.mtransit.android.commons.provider.gtfs.GtfsRealtimeExt.optRouteType import org.mtransit.android.commons.provider.gtfs.GtfsRealtimeExt.optTrip import org.mtransit.android.commons.provider.gtfs.GtfsRealtimeExt.toStringExt import org.mtransit.android.commons.provider.gtfs.agencyTag +import org.mtransit.android.commons.provider.gtfs.getPrimaryTargetUUIDs import org.mtransit.android.commons.provider.gtfs.getTargetUUIDs import org.mtransit.android.commons.provider.gtfs.getTripIds +import org.mtransit.android.commons.provider.gtfs.ignoreDirection import org.mtransit.android.commons.provider.gtfs.parseRouteId import org.mtransit.android.commons.provider.gtfs.parseStopId import org.mtransit.android.commons.provider.gtfs.parseTripId @@ -42,14 +44,21 @@ object GTFSRealTimeServiceAlertsProvider : MTLog.Loggable { } targetUUIDs to tripIds?.takeIf { it.isNotEmpty() } // trip IDs not required for GTFS Alerts }?.let { (targetUUIDs, tripIds) -> - getCached(targetUUIDs, tripIds) + getCached(filter, targetUUIDs, tripIds) } - fun GTFSRealTimeProvider.getCached(targetUUIDs: Map, tripIds: List?) = buildList { - // trip IDs preferred for all result filtered correctly - (tripIds?.let { getCachedServiceUpdatesS(targetUUIDs.keys, tripIds = it) }?.takeIf { it.isNotEmpty() } - // fallback to showing all w/o filtering trip IDs (main issue would be RDS UI showing other Direction alerts) - ?: getCachedServiceUpdatesS(targetUUIDs.keys, tripIds = null)) + fun GTFSRealTimeProvider.getCached(filter: ServiceUpdateProviderContract.Filter, targetUUIDs: Map, tripIds: List?) = buildList { + ( + // 1 - trip IDs preferred for all result filtered correctly + tripIds?.let { getCachedServiceUpdatesS(targetUUIDs.keys, tripIds = it) }?.takeIf { it.isNotEmpty() } + // 2 - fallback to: ignore TRIP IDS (outdated?) and try using primary target UUID only + // - only works if Route & Direction! provided + // -> can NOT show service alerts for the wrong direction + ?: if (ignoreDirection) null + else filter.getPrimaryTargetUUIDs(this@getCached, ignoreDirection = false, includeStopTags = true)?.let { (providerTargetUUID, _) -> + getCachedServiceUpdatesS(setOf(providerTargetUUID), tripIds = null) + }?.takeIf { it.isNotEmpty() } + ) ?.let { addAll(it) } diff --git a/src/main/java/org/mtransit/android/commons/provider/vehiclelocations/GTFSRealTimeVehiclePositionsProvider.kt b/src/main/java/org/mtransit/android/commons/provider/vehiclelocations/GTFSRealTimeVehiclePositionsProvider.kt index 42303ebb..2339eab5 100644 --- a/src/main/java/org/mtransit/android/commons/provider/vehiclelocations/GTFSRealTimeVehiclePositionsProvider.kt +++ b/src/main/java/org/mtransit/android/commons/provider/vehiclelocations/GTFSRealTimeVehiclePositionsProvider.kt @@ -110,13 +110,10 @@ object GTFSRealTimeVehiclePositionsProvider : MTLog.Loggable { getCachedVehicleLocationsS(targetUUIDs.keys, tripIds = it) }?.takeIf { it.isNotEmpty() } // 2 - fallback to: ignore TRIP IDS (outdated?) and try using primary target UUID only - // - only works if Route (& Direction) provided - // -> can show vehicle in wrong direction - ?: filter.getPrimaryTargetUUIDs(this@getCached, ignoreDirection = ignoreDirection)?.let { (providerTargetUUID, _) -> - getCachedVehicleLocationsS(setOf(providerTargetUUID), tripIds = null) - }?.takeIf { it.isNotEmpty() } - // 3 - fallback to: for ignore direction - ?: if (ignoreDirection) null else filter.getPrimaryTargetUUIDs(this@getCached, ignoreDirection = true)?.let { (providerTargetUUID, _) -> + // - only works if Route & Direction! provided + // -> can NOT show vehicle in wrong direction + ?: if (ignoreDirection) null + else filter.getPrimaryTargetUUIDs(this@getCached, ignoreDirection = false)?.let { (providerTargetUUID, _) -> getCachedVehicleLocationsS(setOf(providerTargetUUID), tripIds = null) }?.takeIf { it.isNotEmpty() } )