Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -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;

Expand Down Expand Up @@ -1005,14 +1019,12 @@ private HashSet<ServiceUpdate> 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);
Expand Down Expand Up @@ -1288,6 +1300,20 @@ private ArrayMap<String, String> 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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(gRouteId: String) = gRouteId.originalIdToId(agencyIdCleanupPattern)
Comment thread
mmathieum marked this conversation as resolved.
Outdated
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) }
Expand Down
1 change: 1 addition & 0 deletions src/main/res/values/gtfs_rts_values_gen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<integer name="gtfs_rts_agency_extended_type">-1</integer> <!-- -1: set in module app -->
<string name="gtfs_rts_timezone" /> <!-- empty: set in module app -->
<string name="gtfs_rts_color" /> <!-- empty: set in module app -->
<string name="gtfs_rts_agency_id_cleanup_regex" /> <!-- empty: set in module app -->
<string name="gtfs_rts_service_id_cleanup_regex" /> <!-- empty: set in module app -->
<string name="gtfs_rts_route_id_cleanup_regex" /> <!-- empty: set in module app -->
<string name="gtfs_rts_trip_id_cleanup_regex" /> <!-- empty: set in module app -->
Expand Down