diff --git a/src/main/java/org/mtransit/android/commons/provider/GTFSRealTimeProvider.java b/src/main/java/org/mtransit/android/commons/provider/GTFSRealTimeProvider.java index 4c9f0ae3..e6caabdd 100644 --- a/src/main/java/org/mtransit/android/commons/provider/GTFSRealTimeProvider.java +++ b/src/main/java/org/mtransit/android/commons/provider/GTFSRealTimeProvider.java @@ -442,6 +442,20 @@ public static boolean isIGNORE_DIRECTION(@NonNull Context context) { return ignoreDirection; } + @Nullable + private static String agencyIdCleanupRegex = null; + + /** + * Override if multiple {@link GTFSRealTimeProvider} implementations in same app. + */ + @NonNull + private static String getAGENCY_ID_CLEANUP_REGEX(@NonNull Context context) { + if (agencyIdCleanupRegex == null) { + agencyIdCleanupRegex = context.getResources().getString(R.string.gtfs_rts_agency_id_cleanup_regex); // do not change to avoid breaking compat w/ old modules + } + return agencyIdCleanupRegex; + } + @Nullable private static String serviceIdCleanupRegex = null; @@ -1005,14 +1019,12 @@ private HashSet processAlerts( for (GtfsRealtime.EntitySelector gInformedEntity : gInformedEntityList) { if (gInformedEntity.hasAgencyId() && !providerAgencyId.isEmpty() - && !providerAgencyId.equals(gInformedEntity.getAgencyId())) { - MTLog.w(this, "processAlerts() > Alert targets another agency: %s", gInformedEntity.getAgencyId()); + && !providerAgencyId.equals(GTFSRealTimeProviderExtKt.parseAgencyId(this, gInformedEntity))) { + MTLog.w(this, "processAlerts() > Alert targets another agency: '%s'!", gInformedEntity.getAgencyId()); continue; } final String targetUUID = GTFSRealTimeServiceAlertsProvider.parseProviderTargetUUID(this, gInformedEntity, ignoreDirection); - if (targetUUID == null || targetUUID.isEmpty()) { - continue; - } + if (targetUUID == null || targetUUID.isEmpty()) continue; final String targetTripId = !FeatureFlags.F_USE_TRIP_IS_FOR_SERVICE_UPDATES ? null : GTFSRealTimeServiceAlertsProvider.parseTargetTripId(this, gInformedEntity); targetUUIDAndTripId.put(targetUUID, targetTripId); final int severity = GTFSRTAlertsManager.parseSeverity(gInformedEntity, gEffect); @@ -1288,12 +1300,26 @@ private ArrayMap parseTranslations(@NonNull GtfsRealtime.Transla return translations; } + @Nullable + private Pattern agencyIdCleanupPattern = null; + + private boolean agencyIdCleanupPatternSet = false; + + @Nullable + public Pattern getAgencyIdCleanupPattern(@NonNull Context context) { + if (this.agencyIdCleanupPattern == null && !agencyIdCleanupPatternSet) { + this.agencyIdCleanupPattern = GTFSCommons.makeIdCleanupPattern(getAGENCY_ID_CLEANUP_REGEX(context)); + this.agencyIdCleanupPatternSet = true; + } + return this.agencyIdCleanupPattern; + } + @Nullable private Pattern serviceIdCleanupPattern = null; private boolean serviceIdCleanupPatternSet = false; - @SuppressWarnings("unused") // TODO use later for trip_updates, vehicle_location... + @SuppressWarnings("unused") @Nullable private Pattern getServiceIdCleanupPattern(@NonNull Context context) { if (this.serviceIdCleanupPattern == null && !serviceIdCleanupPatternSet) { diff --git a/src/main/java/org/mtransit/android/commons/provider/gtfs/GTFSRealTimeProviderExt.kt b/src/main/java/org/mtransit/android/commons/provider/gtfs/GTFSRealTimeProviderExt.kt index c8299e1c..5f89f0ec 100644 --- a/src/main/java/org/mtransit/android/commons/provider/gtfs/GTFSRealTimeProviderExt.kt +++ b/src/main/java/org/mtransit/android/commons/provider/gtfs/GTFSRealTimeProviderExt.kt @@ -25,6 +25,7 @@ import org.mtransit.android.commons.provider.GTFSRealTimeProvider.getAgencyTagTa import org.mtransit.android.commons.provider.GTFSRealTimeProvider.getTARGET_AUTHORITY import org.mtransit.android.commons.provider.GTFSRealTimeProvider.isIGNORE_DIRECTION import org.mtransit.android.commons.provider.GTFSRealTimeProvider.isUSE_URL_HASH_SECRET_AND_DATE +import org.mtransit.android.commons.provider.gtfs.GtfsRealtimeExt.optAgencyId import org.mtransit.android.commons.provider.gtfs.GtfsRealtimeExt.optRouteId import org.mtransit.android.commons.provider.gtfs.GtfsRealtimeExt.optStopId import org.mtransit.android.commons.provider.gtfs.GtfsRealtimeExt.optTripId @@ -40,14 +41,18 @@ val GTFSRealTimeProvider.ignoreDirection get() = isIGNORE_DIRECTION(requireConte val GTFSRealTimeProvider.targetAuthority get() = getTARGET_AUTHORITY(requireContextCompat()) val GTFSRealTimeProvider.timeZone get() = getAGENCY_TIME_ZONE(requireContextCompat()) -private val GTFSRealTimeProvider.routeIdCleanupPattern get() = getRouteIdCleanupPattern(requireContextCompat()) +fun GTFSRealTimeProvider.parseAgencyId(es: GEntitySelector) = es.optAgencyId?.let { parseAgencyId(it) } +fun GTFSRealTimeProvider.parseAgencyId(gAgencyId: String) = gAgencyId.originalIdToId(agencyIdCleanupPattern) +private val GTFSRealTimeProvider.agencyIdCleanupPattern get() = getAgencyIdCleanupPattern(requireContextCompat()) + fun GTFSRealTimeProvider.parseRouteId(es: GEntitySelector) = es.optRouteId?.let { parseRouteId(it) } fun GTFSRealTimeProvider.parseRouteId(td: GTripDescriptor) = td.optRouteId?.let { parseRouteId(it) } fun GTFSRealTimeProvider.parseRouteId(gRouteId: String) = gRouteId.originalIdToHash(routeIdCleanupPattern) +private val GTFSRealTimeProvider.routeIdCleanupPattern get() = getRouteIdCleanupPattern(requireContextCompat()) -private val GTFSRealTimeProvider.tripIdCleanupPattern get() = getTripIdCleanupPattern(requireContextCompat()) fun GTFSRealTimeProvider.parseTripId(td: GTripDescriptor) = td.optTripId?.let { parseTripId(it) } fun GTFSRealTimeProvider.parseTripId(gTripId: String) = gTripId.originalIdToId(tripIdCleanupPattern) +private val GTFSRealTimeProvider.tripIdCleanupPattern get() = getTripIdCleanupPattern(requireContextCompat()) @Suppress("unused") fun GTFSRealTimeProvider.parseStopId(stu: GTUStopTimeUpdate) = stu.optStopId?.let { parseStopId(it) } diff --git a/src/main/res/values/gtfs_rts_values_gen.xml b/src/main/res/values/gtfs_rts_values_gen.xml index a527184f..1a56bc74 100644 --- a/src/main/res/values/gtfs_rts_values_gen.xml +++ b/src/main/res/values/gtfs_rts_values_gen.xml @@ -8,6 +8,7 @@ -1 +