diff --git a/src/main/java/org/mtransit/android/commons/provider/ServiceUpdateProvider.java b/src/main/java/org/mtransit/android/commons/provider/ServiceUpdateProvider.java index c5770c27..d92d9785 100644 --- a/src/main/java/org/mtransit/android/commons/provider/ServiceUpdateProvider.java +++ b/src/main/java/org/mtransit/android/commons/provider/ServiceUpdateProvider.java @@ -217,6 +217,17 @@ public static ArrayList getCachedServiceUpdatesS(@NonNull Service ); } + @Nullable + public static ArrayList getCachedServiceUpdatesStartsWithS(@NonNull ServiceUpdateProviderContract provider, @NonNull String targetUUID, @NonNull Integer charCount) { + return getCachedServiceUpdatesS( + provider, + getServiceUpdateContentUri(provider), + SqlUtils.getLikeEndsWithCharCount(Columns.T_SERVICE_UPDATE_K_TARGET_UUID, targetUUID, charCount) + + SqlUtils.AND + + SqlUtils.getWhereEqualsString(Columns.T_SERVICE_UPDATE_K_LANGUAGE, provider.getServiceUpdateLanguage()) + ); + } + @Nullable private static ArrayList getCachedServiceUpdatesS(@NonNull ServiceUpdateProviderContract provider, Uri uri, String selection) { ArrayList cache = new ArrayList<>(); diff --git a/src/main/java/org/mtransit/android/commons/provider/ServiceUpdateProviderContract.java b/src/main/java/org/mtransit/android/commons/provider/ServiceUpdateProviderContract.java index 078e49ee..f2e58c6d 100644 --- a/src/main/java/org/mtransit/android/commons/provider/ServiceUpdateProviderContract.java +++ b/src/main/java/org/mtransit/android/commons/provider/ServiceUpdateProviderContract.java @@ -101,6 +101,7 @@ public String getLogTag() { private final String authority; @Nullable private final Route route; + private final boolean includeAllDirections; @Nullable private final RouteDirection routeDirection; @@ -114,15 +115,22 @@ public String getLogTag() { private Map providedEncryptKeysMap = null; public Filter(@NonNull POI poi) { - this.poi = poi; this.authority = poi.getAuthority(); + this.poi = poi; this.route = null; + this.includeAllDirections = false; this.routeDirection = null; } + @Deprecated public Filter(@NonNull String authority, @NonNull Route route) { + this(authority, route, false); + } + + public Filter(@NonNull String authority, @NonNull Route route, boolean includeAllDirections) { this.authority = authority; this.route = route; + this.includeAllDirections = includeAllDirections; this.routeDirection = null; this.poi = null; } @@ -131,6 +139,7 @@ public Filter(@NonNull String authority, @NonNull RouteDirection routeDirection) this.authority = authority; this.routeDirection = routeDirection; this.route = null; + this.includeAllDirections = false; this.poi = null; } diff --git a/src/main/java/org/mtransit/android/commons/provider/StmInfoApiProvider.java b/src/main/java/org/mtransit/android/commons/provider/StmInfoApiProvider.java index 580f2ec4..9482b1d9 100644 --- a/src/main/java/org/mtransit/android/commons/provider/StmInfoApiProvider.java +++ b/src/main/java/org/mtransit/android/commons/provider/StmInfoApiProvider.java @@ -253,7 +253,7 @@ public ArrayList getCachedServiceUpdates(@NonNull ServiceUpdatePr } else if (serviceUpdateFilter.getRouteDirection() != null) { return getCachedServiceUpdates(context, serviceUpdateFilter.getRouteDirection()); } else if ((serviceUpdateFilter.getRoute() != null)) { // NOT SUPPORTED - return makeServiceUpdateNoneList(this, serviceUpdateFilter.getRoute().getUUID(), SERVICE_UPDATE_SOURCE_ID); + return getCachedServiceUpdates(context, serviceUpdateFilter.getRoute()); } else { MTLog.w(this, "getCachedServiceUpdates() > no service update (poi null or not RDS or no route)"); return null; @@ -299,6 +299,20 @@ private ArrayList getCachedServiceUpdates(@NonNull Context contex return cachedServiceUpdates; } + @NonNull + private ArrayList getCachedServiceUpdates(@NonNull Context context, @NonNull Route route) { + final ArrayList cachedServiceUpdates = new ArrayList<>(); + final String routeWithoutDirectionUUIDs = getRouteDirectionServiceUpdateTargetUUID(getAgencyTag(context), route.getShortName(), StringUtils.EMPTY); + final ArrayList routeCachedServiceUpdatesS = ServiceUpdateProvider.getCachedServiceUpdatesStartsWithS(this, routeWithoutDirectionUUIDs, 1); + if (routeCachedServiceUpdatesS != null) { + cachedServiceUpdates.addAll(routeCachedServiceUpdatesS); + } + for (ServiceUpdate serviceUpdate : cachedServiceUpdates) { + serviceUpdate.setTargetUUID(route.getUUID()); + } + return cachedServiceUpdates; + } + private void enhanceRDServiceUpdatesForStop(@NonNull Context context, ArrayList serviceUpdates, Map targetUUIDs, // different UUID from provider target UUID @@ -562,7 +576,7 @@ public ArrayList getNewServiceUpdates(@NonNull ServiceUpdateProvi } else if (serviceUpdateFilter.getRouteDirection() != null) { return getNewServiceUpdates(context, serviceUpdateFilter.getRouteDirection()); } else if ((serviceUpdateFilter.getRoute() != null)) { // NOT SUPPORTED - return makeServiceUpdateNoneList(this, serviceUpdateFilter.getRoute().getUUID(), SERVICE_UPDATE_SOURCE_ID); + return getNewServiceUpdates(context, serviceUpdateFilter.getRoute()); } else { MTLog.w(this, "getNewServiceUpdates() > no service update (poi null or not RDS or no route)"); return null; @@ -581,6 +595,18 @@ private ArrayList getNewServiceUpdates(@NonNull Context context, return getCachedServiceUpdates(context, rds); } + @SuppressWarnings("SameReturnValue") + @Nullable + private ArrayList getNewServiceUpdates(@SuppressWarnings("unused") @NonNull Context context, @NonNull Route route) { + if (route.getShortName().isEmpty()) { + MTLog.d(this, "getNewServiceUpdates() > skip (stop w/o code OR route w/o short name: %s)", route); + return null; + } + // USING same feed as real-time POI status schedule + // -> can't load status without stop code + return null; + } + @SuppressWarnings("SameReturnValue") @Nullable private ArrayList getNewServiceUpdates(@SuppressWarnings("unused") @NonNull Context context, @NonNull RouteDirection rd) {