From 8e3edf095976b754be287c77374370ae7b787693 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathieu=20M=C3=A9a?= Date: Fri, 19 Jun 2026 08:51:13 -0400 Subject: [PATCH 1/7] Providers > + `asyncOnly` --- .../provider/common/ProviderContract.java | 63 +++++++++++++++++++ .../provider/news/NewsProviderContract.java | 39 ++++-------- .../provider/poi/POIProviderContract.java | 12 ++-- .../ServiceUpdateProviderContract.java | 34 +++------- .../status/StatusProviderContract.java | 27 ++------ .../VehicleLocationProvider.kt | 2 +- .../VehicleLocationProviderContract.kt | 11 +--- 7 files changed, 98 insertions(+), 90 deletions(-) diff --git a/src/main/java/org/mtransit/android/commons/provider/common/ProviderContract.java b/src/main/java/org/mtransit/android/commons/provider/common/ProviderContract.java index fda619e7..1ef9b153 100644 --- a/src/main/java/org/mtransit/android/commons/provider/common/ProviderContract.java +++ b/src/main/java/org/mtransit/android/commons/provider/common/ProviderContract.java @@ -5,8 +5,11 @@ import android.database.sqlite.SQLiteDatabase; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.annotation.WorkerThread; +import org.json.JSONException; +import org.json.JSONObject; import org.mtransit.android.commons.MTLog; import java.util.concurrent.TimeUnit; @@ -30,4 +33,64 @@ public interface ProviderContract extends MTLog.Loggable { @NonNull Context requireContextCompat(); + + abstract class Filter { + + private static final boolean CACHE_ONLY_DEFAULT = false; + private static final boolean ASYNC_ONLY_DEFAULT = false; + + @Nullable + private Boolean cacheOnly = null; + @Nullable + private Boolean asyncOnly = null; + + public boolean isCacheOnlyOrDefault() { + return this.cacheOnly == null ? CACHE_ONLY_DEFAULT : this.cacheOnly; + } + + @Nullable + public Boolean getCacheOnlyOrNull() { + return this.cacheOnly; + } + + @NonNull + public void setCacheOnly(@Nullable Boolean cacheOnly) { + this.cacheOnly = cacheOnly; + } + + public void setAsyncOnly(@Nullable Boolean asyncOnly) { + this.asyncOnly = asyncOnly; + } + + public boolean isAsyncOnlyOrDefault() { + return this.asyncOnly == null ? ASYNC_ONLY_DEFAULT : this.asyncOnly; + } + + @Nullable + public Boolean getAsyncOnlyOrNull() { + return this.asyncOnly; + } + + private static final String JSON_CACHE_ONLY = "cacheOnly"; + private static final String JSON_ASYNC_ONLY = "asyncOnly"; + + public static void toJSON(@NonNull Filter filter, @NonNull JSONObject json) throws JSONException { + if (filter.getCacheOnlyOrNull() != null) { + json.put(JSON_CACHE_ONLY, filter.getCacheOnlyOrNull()); + } + if (filter.getAsyncOnlyOrNull() != null) { + json.put(JSON_ASYNC_ONLY, filter.getAsyncOnlyOrNull()); + } + } + + public static void fromJSON(@NonNull Filter filter, @NonNull JSONObject json) throws JSONException { + if (json.has(JSON_CACHE_ONLY)) { + filter.cacheOnly = json.getBoolean(JSON_CACHE_ONLY); + } + if (json.has(JSON_ASYNC_ONLY)) { + filter.asyncOnly = json.getBoolean(JSON_ASYNC_ONLY); + } + } + } } + diff --git a/src/main/java/org/mtransit/android/commons/provider/news/NewsProviderContract.java b/src/main/java/org/mtransit/android/commons/provider/news/NewsProviderContract.java index b46c1c66..4303fc4d 100644 --- a/src/main/java/org/mtransit/android/commons/provider/news/NewsProviderContract.java +++ b/src/main/java/org/mtransit/android/commons/provider/news/NewsProviderContract.java @@ -135,7 +135,7 @@ interface Columns { }; @SuppressWarnings("WeakerAccess") - class Filter implements MTLog.Loggable { + class Filter extends ProviderContract.Filter implements MTLog.Loggable { private static final String LOG_TAG = NewsProviderContract.class.getSimpleName() + ">" + Filter.class.getSimpleName(); @@ -145,8 +145,6 @@ public String getLogTag() { return LOG_TAG; } - private static final boolean CACHE_ONLY_DEFAULT = false; - private static final boolean IN_FOCUS_DEFAULT = false; @Nullable @@ -154,8 +152,6 @@ public String getLogTag() { @Nullable private List targets; @Nullable - private Boolean cacheOnly = null; - @Nullable private Long cacheValidityInMs = null; @Nullable private Boolean inFocus = null; @@ -258,7 +254,8 @@ public String toString() { } else if (isTargetFilter(this)) { sb.append("targets:").append(this.targets).append(','); } - sb.append("cacheOnly:").append(this.cacheOnly).append(','); + sb.append("cacheOnly:").append(getCacheOnlyOrNull()).append(','); + sb.append("asyncOnly:").append(getAsyncOnlyOrNull()).append(','); sb.append("inFocus:").append(this.inFocus).append(','); sb.append("cacheValidityInMs:").append(this.cacheValidityInMs).append(','); sb.append("minCreatedAtInMs:").append(this.minCreatedAtInMs); @@ -306,22 +303,13 @@ public String getSqlSelection(@NonNull String uuidTableColumn, @NonNull String t @SuppressWarnings("unused") @NonNull - public Filter setCacheOnly(@Nullable Boolean cacheOnly) { - this.cacheOnly = cacheOnly; + public Filter setCacheOnlyAnd(@Nullable Boolean cacheOnly) { + super.setCacheOnly(cacheOnly); return this; } - public boolean isCacheOnlyOrDefault() { - return this.cacheOnly == null ? CACHE_ONLY_DEFAULT : this.cacheOnly; - } - - @Nullable - public Boolean getCacheOnlyOrNull() { - return this.cacheOnly; - } - @NonNull - public Filter setInFocus(@Nullable Boolean inFocus) { + public Filter setInFocusAnd(@Nullable Boolean inFocus) { this.inFocus = inFocus; return this; } @@ -402,7 +390,6 @@ public static Filter fromJSONString(@Nullable String jsonString) { private static final String JSON_UUIDS = "uuids"; private static final String JSON_TARGETS = "targets"; - private static final String JSON_CACHE_ONLY = "cacheOnly"; private static final String JSON_IN_FOCUS = "inFocus"; private static final String JSON_CACHE_VALIDITY_IN_MS = "cacheValidityInMs"; private static final String JSON_MIN_CREATED_AT_IN_MS = "minCreatedAtInMs"; @@ -411,7 +398,8 @@ public static Filter fromJSONString(@Nullable String jsonString) { @Nullable public static Filter fromJSON(@NonNull JSONObject json) { try { - Filter newsFilter = new Filter(); + final Filter newsFilter = new Filter(); + ProviderContract.Filter.fromJSON(newsFilter, json); JSONArray jUUIDs = json.optJSONArray(JSON_UUIDS); JSONArray jTargets = json.optJSONArray(JSON_TARGETS); if (jUUIDs != null && jUUIDs.length() > 0) { @@ -427,9 +415,6 @@ public static Filter fromJSON(@NonNull JSONObject json) { } newsFilter.setTargets(targets); } - if (json.has(JSON_CACHE_ONLY)) { - newsFilter.cacheOnly = json.getBoolean(JSON_CACHE_ONLY); - } if (json.has(JSON_IN_FOCUS)) { newsFilter.inFocus = json.getBoolean(JSON_IN_FOCUS); } @@ -456,20 +441,18 @@ public String toJSONString() { @Nullable public static String toJSONString(@NonNull Filter newsFilter) { - JSONObject json = toJSON(newsFilter); + final JSONObject json = toJSON(newsFilter); return json == null ? null : json.toString(); } @Nullable public static JSONObject toJSON(@NonNull Filter newsFilter) { try { - JSONObject json = new JSONObject(); + final JSONObject json = new JSONObject(); + ProviderContract.Filter.toJSON(newsFilter, json); if (newsFilter.getMinCreatedAtInMsOrNull() != null) { json.put(JSON_MIN_CREATED_AT_IN_MS, newsFilter.getMinCreatedAtInMsOrNull()); } - if (newsFilter.getCacheOnlyOrNull() != null) { - json.put(JSON_CACHE_ONLY, newsFilter.getCacheOnlyOrNull()); - } if (newsFilter.getInFocusOrNull() != null) { json.put(JSON_IN_FOCUS, newsFilter.getInFocusOrNull()); } diff --git a/src/main/java/org/mtransit/android/commons/provider/poi/POIProviderContract.java b/src/main/java/org/mtransit/android/commons/provider/poi/POIProviderContract.java index 208580f5..7dd2d9ad 100644 --- a/src/main/java/org/mtransit/android/commons/provider/poi/POIProviderContract.java +++ b/src/main/java/org/mtransit/android/commons/provider/poi/POIProviderContract.java @@ -106,7 +106,7 @@ public static String getFkColumnName(@NonNull String key) { } @SuppressWarnings({"WeakerAccess", "unused"}) - class Filter implements MTLog.Loggable { + class Filter extends ProviderContract.Filter implements MTLog.Loggable { private static final String LOG_TAG = POIProviderContract.class.getSimpleName() + ">" + Filter.class.getSimpleName(); @@ -252,7 +252,7 @@ private Filter setArea(double minLat, double maxLat, double minLng, double maxLn @NonNull @Override public String toString() { - StringBuilder sb = new StringBuilder(Filter.class.getSimpleName()).append('['); + final StringBuilder sb = new StringBuilder(Filter.class.getSimpleName()).append('['); if (isAreaFilter(this)) { sb.append("lat:").append(this.lat).append(','); sb.append("lng:").append(this.lng).append(','); @@ -274,6 +274,8 @@ public String toString() { sb.append("sqlSelection:").append(this.sqlSelection).append(','); } sb.append("extras:").append(this.extras).append(','); + sb.append("cacheOnly:").append(getCacheOnlyOrNull()).append(','); + sb.append("asyncOnly:").append(getAsyncOnlyOrNull()).append(','); sb.append(']'); return sb.toString(); } @@ -506,7 +508,8 @@ public static Filter fromJSONString(@Nullable String jsonString) { @SuppressWarnings("ConstantConditions") private static Filter fromJSON(JSONObject json) { try { - Filter poiFilter = new Filter(); + final Filter poiFilter = new Filter(); + ProviderContract.Filter.fromJSON(poiFilter, json); Double lat; Double lng; Double aroundDiff; @@ -606,7 +609,7 @@ private static Filter fromJSON(JSONObject json) { @Nullable public static JSONObject toJSON(@Nullable Filter poiFilter) { try { - JSONObject json = new JSONObject(); + final JSONObject json = new JSONObject(); if (isAreaFilter(poiFilter)) { json.put(JSON_LAT, poiFilter.lat); json.put(JSON_LNG, poiFilter.lng); @@ -647,6 +650,7 @@ public static JSONObject toJSON(@Nullable Filter poiFilter) { } JSONArray jExtras = new JSONArray(); if (poiFilter != null) { + ProviderContract.Filter.toJSON(poiFilter, json); for (int i = 0; i < poiFilter.extras.size(); i++) { JSONObject jExtra = new JSONObject(); jExtra.put(JSON_EXTRAS_KEY, poiFilter.extras.keyAt(i)); diff --git a/src/main/java/org/mtransit/android/commons/provider/serviceupdate/ServiceUpdateProviderContract.java b/src/main/java/org/mtransit/android/commons/provider/serviceupdate/ServiceUpdateProviderContract.java index ce2aff4c..eb666ce4 100644 --- a/src/main/java/org/mtransit/android/commons/provider/serviceupdate/ServiceUpdateProviderContract.java +++ b/src/main/java/org/mtransit/android/commons/provider/serviceupdate/ServiceUpdateProviderContract.java @@ -98,7 +98,7 @@ class Columns { } @SuppressWarnings("WeakerAccess") - class Filter implements GTFSRealTimeProviderFilter, MTLog.Loggable { + class Filter extends ProviderContract.Filter implements GTFSRealTimeProviderFilter, MTLog.Loggable { private static final String LOG_TAG = ServiceUpdateProviderContract.class.getSimpleName() + ">" + Filter.class.getSimpleName(); @@ -108,8 +108,6 @@ public String getLogTag() { return LOG_TAG; } - private static final boolean CACHE_ONLY_DEFAULT = false; - private static final boolean IN_FOCUS_DEFAULT = false; @Nullable @@ -121,8 +119,6 @@ public String getLogTag() { @Nullable private final RouteDirection routeDirection; - @Nullable - private Boolean cacheOnly = null; @Nullable private Long cacheValidityInMs = null; @Nullable @@ -156,7 +152,8 @@ public Filter(@NonNull String authority, @NonNull RouteDirection routeDirection) public String toString() { final StringBuilder sb = new StringBuilder(); sb.append(Filter.class.getSimpleName()) - .append("cacheOnly:").append(this.cacheOnly).append(',') + .append("cacheOnly:").append(getCacheOnlyOrNull()).append(',') + .append("asyncOnly:").append(getAsyncOnlyOrNull()).append(',') .append("inFocus:").append(this.inFocus).append(',') .append("cacheValidityInMs:").append(this.cacheValidityInMs).append(','); if (this.poi != null) { @@ -264,20 +261,6 @@ public RouteDirection getRouteDirection() { return routeDirection; } - @SuppressWarnings("unused") - public void setCacheOnly(@Nullable Boolean cacheOnly) { - this.cacheOnly = cacheOnly; - } - - public boolean isCacheOnlyOrDefault() { - return this.cacheOnly == null ? CACHE_ONLY_DEFAULT : this.cacheOnly; - } - - @Nullable - public Boolean getCacheOnlyOrNull() { - return this.cacheOnly; - } - public void setInFocus(@Nullable Boolean inFocus) { this.inFocus = inFocus; } @@ -359,7 +342,6 @@ public static Filter fromJSONString(@Nullable String jsonString) { private static final String JSON_ROUTE = "route"; private static final String JSON_ROUTE_DIRECTION = "routeDirection"; private static final String JSON_AUTHORITY = "authority"; - private static final String JSON_CACHE_ONLY = "cacheOnly"; private static final String JSON_IN_FOCUS = "inFocus"; private static final String JSON_CACHE_VALIDITY_IN_MS = "cacheValidityInMs"; private static final String JSON_PROVIDED_ENCRYPT_KEYS_MAP = "providedEncryptKeysMap"; @@ -383,7 +365,7 @@ public static Filter fromJSON(@NonNull JSONObject json) { } else { return null; // WTF? } - serviceUpdateFilter.cacheOnly = JSONUtils.optBoolean(json, JSON_CACHE_ONLY); + ProviderContract.Filter.fromJSON(serviceUpdateFilter, json); serviceUpdateFilter.inFocus = JSONUtils.optBoolean(json, JSON_IN_FOCUS); if (json.has(JSON_CACHE_VALIDITY_IN_MS)) { serviceUpdateFilter.cacheValidityInMs = json.getLong(JSON_CACHE_VALIDITY_IN_MS); @@ -405,14 +387,15 @@ public String toJSONString() { @Nullable public static String toJSONString(@NonNull Filter serviceUpdateFilter) { - JSONObject json = toJSON(serviceUpdateFilter); + final JSONObject json = toJSON(serviceUpdateFilter); return json == null ? null : json.toString(); } @Nullable public static JSONObject toJSON(@NonNull Filter serviceUpdateFilter) { try { - JSONObject json = new JSONObject(); + final JSONObject json = new JSONObject(); + ProviderContract.Filter.toJSON(serviceUpdateFilter, json); if (serviceUpdateFilter.poi != null) { json.put(JSON_POI, serviceUpdateFilter.poi.toJSON()); } @@ -425,9 +408,6 @@ public static JSONObject toJSON(@NonNull Filter serviceUpdateFilter) { if (serviceUpdateFilter.authority != null) { json.put(JSON_AUTHORITY, serviceUpdateFilter.authority); } - if (serviceUpdateFilter.getCacheOnlyOrNull() != null) { - json.put(JSON_CACHE_ONLY, serviceUpdateFilter.getCacheOnlyOrNull()); - } if (serviceUpdateFilter.getInFocusOrNull() != null) { json.put(JSON_IN_FOCUS, serviceUpdateFilter.getInFocusOrNull()); } diff --git a/src/main/java/org/mtransit/android/commons/provider/status/StatusProviderContract.java b/src/main/java/org/mtransit/android/commons/provider/status/StatusProviderContract.java index a4489f55..979201a5 100644 --- a/src/main/java/org/mtransit/android/commons/provider/status/StatusProviderContract.java +++ b/src/main/java/org/mtransit/android/commons/provider/status/StatusProviderContract.java @@ -68,7 +68,7 @@ class Columns { } @SuppressWarnings("WeakerAccess") - abstract class Filter implements MTLog.Loggable { + abstract class Filter extends ProviderContract.Filter implements MTLog.Loggable { private static final String LOG_TAG = StatusProviderContract.class.getSimpleName() + ">" + Filter.class.getSimpleName(); @@ -78,16 +78,12 @@ public String getLogTag() { return LOG_TAG; } - private static final boolean CACHE_ONLY_DEFAULT = false; - private static final boolean IN_FOCUS_DEFAULT = false; @NonNull private String targetUUID; private int type; @Nullable - private Boolean cacheOnly = null; - @Nullable private Long cacheValidityInMs = null; @Nullable private Boolean inFocus = null; @@ -108,15 +104,6 @@ public int getType() { return this.type; } - public boolean isCacheOnlyOrDefault() { - return this.cacheOnly == null ? CACHE_ONLY_DEFAULT : this.cacheOnly; - } - - @Nullable - public Boolean getCacheOnlyOrNull() { - return this.cacheOnly; - } - public void setInFocus(@Nullable Boolean inFocus) { this.inFocus = inFocus; } @@ -208,11 +195,9 @@ public static Long getCacheValidityInMsFromJSON(@NonNull JSONObject json) throws } public static void toJSON(@NonNull Filter statusFilter, @NonNull JSONObject json) throws JSONException { + ProviderContract.Filter.toJSON(statusFilter, json); json.put(JSON_TYPE, statusFilter.getType()); json.put(JSON_TARGET, statusFilter.getTargetUUID()); - if (statusFilter.getCacheOnlyOrNull() != null) { - json.put(JSON_CACHE_ONLY, statusFilter.getCacheOnlyOrNull()); - } if (statusFilter.getInFocusOrNull() != null) { json.put(JSON_IN_FOCUS, statusFilter.getInFocusOrNull()); } @@ -226,17 +211,14 @@ public static void toJSON(@NonNull Filter statusFilter, @NonNull JSONObject json private static final String JSON_TYPE = "type"; private static final String JSON_TARGET = "target"; - private static final String JSON_CACHE_ONLY = "cacheOnly"; private static final String JSON_IN_FOCUS = "inFocus"; private static final String JSON_CACHE_VALIDITY_IN_MS = "cacheValidityInMs"; private static final String JSON_PROVIDED_ENCRYPT_KEYS_MAP = "providedEncryptKeysMap"; public static void fromJSON(@NonNull Filter statusFilter, @NonNull JSONObject json) throws JSONException { + ProviderContract.Filter.fromJSON(statusFilter, json); statusFilter.type = json.getInt(JSON_TYPE); statusFilter.targetUUID = json.getString(JSON_TARGET); - if (json.has(JSON_CACHE_ONLY)) { - statusFilter.cacheOnly = json.getBoolean(JSON_CACHE_ONLY); - } if (json.has(JSON_IN_FOCUS)) { statusFilter.inFocus = json.getBoolean(JSON_IN_FOCUS); } @@ -262,7 +244,8 @@ public String toString() { return Filter.class.getSimpleName() + "{" + "targetUUID='" + targetUUID + '\'' + ", type=" + type + - ", cacheOnly=" + cacheOnly + + ", cacheOnly=" + getCacheOnlyOrNull() + + ", asyncOnly=" + getAsyncOnlyOrNull() + ", cacheValidityInMs=" + cacheValidityInMs + ", inFocus=" + inFocus + '}'; diff --git a/src/main/java/org/mtransit/android/commons/provider/vehiclelocations/VehicleLocationProvider.kt b/src/main/java/org/mtransit/android/commons/provider/vehiclelocations/VehicleLocationProvider.kt index 55530b51..60408284 100644 --- a/src/main/java/org/mtransit/android/commons/provider/vehiclelocations/VehicleLocationProvider.kt +++ b/src/main/java/org/mtransit/android/commons/provider/vehiclelocations/VehicleLocationProvider.kt @@ -72,7 +72,7 @@ abstract class VehicleLocationProvider : MTContentProvider(), } } } - if (filter.cacheOnlyOrDefault) { + if (filter.isCacheOnlyOrDefault) { if (cachedVehicleLocations.isNullOrEmpty()) { MTLog.w(this, "getVehicleLocations() > No useful cache found!") } diff --git a/src/main/java/org/mtransit/android/commons/provider/vehiclelocations/VehicleLocationProviderContract.kt b/src/main/java/org/mtransit/android/commons/provider/vehiclelocations/VehicleLocationProviderContract.kt index 28c9e99b..9f5d7b4a 100644 --- a/src/main/java/org/mtransit/android/commons/provider/vehiclelocations/VehicleLocationProviderContract.kt +++ b/src/main/java/org/mtransit/android/commons/provider/vehiclelocations/VehicleLocationProviderContract.kt @@ -95,14 +95,11 @@ interface VehicleLocationProviderContract : ProviderContract { override val poi: POI? = null, // RouteDirectionStop or DefaultPOI override val route: Route? = null, override val routeDirection: RouteDirection? = null, - ) : GTFSRealTimeProviderFilter, MTLog.Loggable { + ) : ProviderContract.Filter(), GTFSRealTimeProviderFilter, MTLog.Loggable { var inFocus: Boolean? = null val inFocusOrDefault get() = inFocus ?: false - var cacheOnly: Boolean? = null - val cacheOnlyOrDefault get() = cacheOnly ?: false - var providedEncryptKeysMap: Map? = null private set @@ -138,7 +135,6 @@ interface VehicleLocationProviderContract : ProviderContract { private const val JSON_POI = "poi" private const val JSON_ROUTE = "route" private const val JSON_ROUTE_DIRECTION = "routeDirection" - private const val JSON_CACHE_ONLY = "cacheOnly" private const val JSON_IN_FOCUS = "inFocus" private const val JSON_PROVIDED_ENCRYPT_KEYS_MAP = "providedEncryptKeysMap" @@ -164,7 +160,6 @@ interface VehicleLocationProviderContract : ProviderContract { authority?.let { RouteDirection.fromJSON(jRouteDirection, it) } } val inFocus = JSONUtils.optBoolean(json, JSON_IN_FOCUS) - val cacheOnly = JSONUtils.optBoolean(json, JSON_CACHE_ONLY) val providedEncryptKeysMap: Map? = json.optJSONObject(JSON_PROVIDED_ENCRYPT_KEYS_MAP)?.let { jProvidedEncryptKeysMap -> JSONUtils.toMapOfStrings(jProvidedEncryptKeysMap) } @@ -173,7 +168,7 @@ interface VehicleLocationProviderContract : ProviderContract { ?: routeDirection?.let { Filter(authority = routeDirection.authority, routeDirection = it) }) ?.apply { this.inFocus = inFocus - this.cacheOnly = cacheOnly + fromJSON(this, json) this.providedEncryptKeysMap = providedEncryptKeysMap } } @@ -184,12 +179,12 @@ interface VehicleLocationProviderContract : ProviderContract { fun toJSON(vehicleLocationFilter: Filter): JSONObject? { return try { JSONObject().apply { + toJSON(vehicleLocationFilter, this) put(JSON_AUTHORITY, vehicleLocationFilter.authority) vehicleLocationFilter.poi?.let { put(JSON_POI, it.toJSON()) } vehicleLocationFilter.route?.let { put(JSON_ROUTE, Route.toJSON(it)) } vehicleLocationFilter.routeDirection?.let { put(JSON_ROUTE_DIRECTION, RouteDirection.toJSON(it)) } vehicleLocationFilter.inFocus?.let { put(JSON_IN_FOCUS, it) } - vehicleLocationFilter.cacheOnly?.let { put(JSON_CACHE_ONLY, it) } vehicleLocationFilter.providedEncryptKeysMap?.let { put(JSON_PROVIDED_ENCRYPT_KEYS_MAP, JSONUtils.toJSONObject(it)) } } } catch (jsone: JSONException) { From 0bd622da9239fa82337534a10f690e56d2a8a491 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathieu=20M=C3=A9a?= Date: Fri, 19 Jun 2026 11:49:18 -0400 Subject: [PATCH 2/7] inFocus --- .../provider/common/ProviderContract.java | 32 +++++++++++++++ .../provider/news/NewsProviderContract.java | 39 +------------------ .../ServiceUpdateProviderContract.java | 26 +------------ .../status/StatusProviderContract.java | 28 +------------ .../GTFSRealTimeVehiclePositionsProvider.kt | 2 +- .../NextBusVehicleLocationsProvider.kt | 2 +- .../VehicleLocationProvider.kt | 2 +- .../VehicleLocationProviderContract.kt | 7 ---- 8 files changed, 39 insertions(+), 99 deletions(-) diff --git a/src/main/java/org/mtransit/android/commons/provider/common/ProviderContract.java b/src/main/java/org/mtransit/android/commons/provider/common/ProviderContract.java index 1ef9b153..45f9179d 100644 --- a/src/main/java/org/mtransit/android/commons/provider/common/ProviderContract.java +++ b/src/main/java/org/mtransit/android/commons/provider/common/ProviderContract.java @@ -38,11 +38,14 @@ abstract class Filter { private static final boolean CACHE_ONLY_DEFAULT = false; private static final boolean ASYNC_ONLY_DEFAULT = false; + private static final boolean IN_FOCUS_DEFAULT = false; @Nullable private Boolean cacheOnly = null; @Nullable private Boolean asyncOnly = null; + @Nullable + private Boolean inFocus = null; public boolean isCacheOnlyOrDefault() { return this.cacheOnly == null ? CACHE_ONLY_DEFAULT : this.cacheOnly; @@ -71,8 +74,22 @@ public Boolean getAsyncOnlyOrNull() { return this.asyncOnly; } + public boolean isInFocusOrDefault() { + return this.inFocus == null ? IN_FOCUS_DEFAULT : this.inFocus; + } + + @Nullable + public Boolean getInFocusOrNull() { + return this.inFocus; + } + + public void setInFocus(@Nullable Boolean inFocus) { + this.inFocus = inFocus; + } + private static final String JSON_CACHE_ONLY = "cacheOnly"; private static final String JSON_ASYNC_ONLY = "asyncOnly"; + private static final String JSON_IN_FOCUS = "inFocus"; public static void toJSON(@NonNull Filter filter, @NonNull JSONObject json) throws JSONException { if (filter.getCacheOnlyOrNull() != null) { @@ -81,6 +98,9 @@ public static void toJSON(@NonNull Filter filter, @NonNull JSONObject json) thro if (filter.getAsyncOnlyOrNull() != null) { json.put(JSON_ASYNC_ONLY, filter.getAsyncOnlyOrNull()); } + if (filter.getInFocusOrNull() != null) { + json.put(JSON_IN_FOCUS, filter.getInFocusOrNull()); + } } public static void fromJSON(@NonNull Filter filter, @NonNull JSONObject json) throws JSONException { @@ -90,6 +110,18 @@ public static void fromJSON(@NonNull Filter filter, @NonNull JSONObject json) th if (json.has(JSON_ASYNC_ONLY)) { filter.asyncOnly = json.getBoolean(JSON_ASYNC_ONLY); } + if (json.has(JSON_IN_FOCUS)) { + filter.inFocus = json.getBoolean(JSON_IN_FOCUS); + } + } + + @NonNull + public String toStringParts() { + final StringBuilder sb = new StringBuilder(); + sb.append("cacheOnly:").append(this.cacheOnly).append(','); + sb.append("asyncOnly:").append(this.asyncOnly).append(','); + sb.append("inFocus:").append(this.inFocus).append(","); + return sb.toString(); } } } diff --git a/src/main/java/org/mtransit/android/commons/provider/news/NewsProviderContract.java b/src/main/java/org/mtransit/android/commons/provider/news/NewsProviderContract.java index 4303fc4d..28332a4e 100644 --- a/src/main/java/org/mtransit/android/commons/provider/news/NewsProviderContract.java +++ b/src/main/java/org/mtransit/android/commons/provider/news/NewsProviderContract.java @@ -145,8 +145,6 @@ public String getLogTag() { return LOG_TAG; } - private static final boolean IN_FOCUS_DEFAULT = false; - @Nullable private List uuids; @Nullable @@ -154,8 +152,6 @@ public String getLogTag() { @Nullable private Long cacheValidityInMs = null; @Nullable - private Boolean inFocus = null; - @Nullable private Long minCreatedAtInMs = null; @Nullable private Map providedEncryptKeysMap = null; @@ -248,15 +244,13 @@ public Long getMinCreatedAtInMsOrNull() { @NonNull @Override public String toString() { - StringBuilder sb = new StringBuilder(Filter.class.getSimpleName()).append('['); + final StringBuilder sb = new StringBuilder(Filter.class.getSimpleName()).append('['); if (isUUIDFilter(this)) { sb.append("uuids:").append(this.uuids).append(','); } else if (isTargetFilter(this)) { sb.append("targets:").append(this.targets).append(','); } - sb.append("cacheOnly:").append(getCacheOnlyOrNull()).append(','); - sb.append("asyncOnly:").append(getAsyncOnlyOrNull()).append(','); - sb.append("inFocus:").append(this.inFocus).append(','); + sb.append(super.toStringParts()); sb.append("cacheValidityInMs:").append(this.cacheValidityInMs).append(','); sb.append("minCreatedAtInMs:").append(this.minCreatedAtInMs); sb.append(']'); @@ -301,28 +295,6 @@ public String getSqlSelection(@NonNull String uuidTableColumn, @NonNull String t return sb.toString(); } - @SuppressWarnings("unused") - @NonNull - public Filter setCacheOnlyAnd(@Nullable Boolean cacheOnly) { - super.setCacheOnly(cacheOnly); - return this; - } - - @NonNull - public Filter setInFocusAnd(@Nullable Boolean inFocus) { - this.inFocus = inFocus; - return this; - } - - public boolean isInFocusOrDefault() { - return this.inFocus == null ? IN_FOCUS_DEFAULT : this.inFocus; - } - - @Nullable - public Boolean getInFocusOrNull() { - return this.inFocus; - } - @Nullable public Long getCacheValidityInMsOrNull() { return this.cacheValidityInMs; @@ -390,7 +362,6 @@ public static Filter fromJSONString(@Nullable String jsonString) { private static final String JSON_UUIDS = "uuids"; private static final String JSON_TARGETS = "targets"; - private static final String JSON_IN_FOCUS = "inFocus"; private static final String JSON_CACHE_VALIDITY_IN_MS = "cacheValidityInMs"; private static final String JSON_MIN_CREATED_AT_IN_MS = "minCreatedAtInMs"; private static final String JSON_PROVIDED_ENCRYPT_KEYS_MAP = "providedEncryptKeysMap"; @@ -415,9 +386,6 @@ public static Filter fromJSON(@NonNull JSONObject json) { } newsFilter.setTargets(targets); } - if (json.has(JSON_IN_FOCUS)) { - newsFilter.inFocus = json.getBoolean(JSON_IN_FOCUS); - } if (json.has(JSON_CACHE_VALIDITY_IN_MS)) { newsFilter.cacheValidityInMs = json.getLong(JSON_CACHE_VALIDITY_IN_MS); } @@ -453,9 +421,6 @@ public static JSONObject toJSON(@NonNull Filter newsFilter) { if (newsFilter.getMinCreatedAtInMsOrNull() != null) { json.put(JSON_MIN_CREATED_AT_IN_MS, newsFilter.getMinCreatedAtInMsOrNull()); } - if (newsFilter.getInFocusOrNull() != null) { - json.put(JSON_IN_FOCUS, newsFilter.getInFocusOrNull()); - } if (newsFilter.getCacheValidityInMsOrNull() != null) { json.put(JSON_CACHE_VALIDITY_IN_MS, newsFilter.getCacheValidityInMsOrNull()); } diff --git a/src/main/java/org/mtransit/android/commons/provider/serviceupdate/ServiceUpdateProviderContract.java b/src/main/java/org/mtransit/android/commons/provider/serviceupdate/ServiceUpdateProviderContract.java index eb666ce4..c869bd38 100644 --- a/src/main/java/org/mtransit/android/commons/provider/serviceupdate/ServiceUpdateProviderContract.java +++ b/src/main/java/org/mtransit/android/commons/provider/serviceupdate/ServiceUpdateProviderContract.java @@ -108,8 +108,6 @@ public String getLogTag() { return LOG_TAG; } - private static final boolean IN_FOCUS_DEFAULT = false; - @Nullable private final POI poi; // RouteDirectionStop or DefaultPOI @Nullable @@ -122,8 +120,6 @@ public String getLogTag() { @Nullable private Long cacheValidityInMs = null; @Nullable - private Boolean inFocus = null; - @Nullable private Map providedEncryptKeysMap = null; public Filter(@NonNull POI poi) { @@ -152,9 +148,7 @@ public Filter(@NonNull String authority, @NonNull RouteDirection routeDirection) public String toString() { final StringBuilder sb = new StringBuilder(); sb.append(Filter.class.getSimpleName()) - .append("cacheOnly:").append(getCacheOnlyOrNull()).append(',') - .append("asyncOnly:").append(getAsyncOnlyOrNull()).append(',') - .append("inFocus:").append(this.inFocus).append(',') + .append(super.toStringParts()) .append("cacheValidityInMs:").append(this.cacheValidityInMs).append(','); if (this.poi != null) { sb.append("poi:").append(this.poi).append(','); @@ -261,19 +255,6 @@ public RouteDirection getRouteDirection() { return routeDirection; } - public void setInFocus(@Nullable Boolean inFocus) { - this.inFocus = inFocus; - } - - public boolean isInFocusOrDefault() { - return this.inFocus == null ? IN_FOCUS_DEFAULT : this.inFocus; - } - - @Nullable - public Boolean getInFocusOrNull() { - return this.inFocus; - } - @Nullable public Long getCacheValidityInMsOrNull() { return this.cacheValidityInMs; @@ -342,7 +323,6 @@ public static Filter fromJSONString(@Nullable String jsonString) { private static final String JSON_ROUTE = "route"; private static final String JSON_ROUTE_DIRECTION = "routeDirection"; private static final String JSON_AUTHORITY = "authority"; - private static final String JSON_IN_FOCUS = "inFocus"; private static final String JSON_CACHE_VALIDITY_IN_MS = "cacheValidityInMs"; private static final String JSON_PROVIDED_ENCRYPT_KEYS_MAP = "providedEncryptKeysMap"; @@ -366,7 +346,6 @@ public static Filter fromJSON(@NonNull JSONObject json) { return null; // WTF? } ProviderContract.Filter.fromJSON(serviceUpdateFilter, json); - serviceUpdateFilter.inFocus = JSONUtils.optBoolean(json, JSON_IN_FOCUS); if (json.has(JSON_CACHE_VALIDITY_IN_MS)) { serviceUpdateFilter.cacheValidityInMs = json.getLong(JSON_CACHE_VALIDITY_IN_MS); } @@ -408,9 +387,6 @@ public static JSONObject toJSON(@NonNull Filter serviceUpdateFilter) { if (serviceUpdateFilter.authority != null) { json.put(JSON_AUTHORITY, serviceUpdateFilter.authority); } - if (serviceUpdateFilter.getInFocusOrNull() != null) { - json.put(JSON_IN_FOCUS, serviceUpdateFilter.getInFocusOrNull()); - } if (serviceUpdateFilter.getCacheValidityInMsOrNull() != null) { json.put(JSON_CACHE_VALIDITY_IN_MS, serviceUpdateFilter.getCacheValidityInMsOrNull()); } diff --git a/src/main/java/org/mtransit/android/commons/provider/status/StatusProviderContract.java b/src/main/java/org/mtransit/android/commons/provider/status/StatusProviderContract.java index 979201a5..fdbe28be 100644 --- a/src/main/java/org/mtransit/android/commons/provider/status/StatusProviderContract.java +++ b/src/main/java/org/mtransit/android/commons/provider/status/StatusProviderContract.java @@ -78,16 +78,12 @@ public String getLogTag() { return LOG_TAG; } - private static final boolean IN_FOCUS_DEFAULT = false; - @NonNull private String targetUUID; private int type; @Nullable private Long cacheValidityInMs = null; @Nullable - private Boolean inFocus = null; - @Nullable private Map providedEncryptKeysMap = null; public Filter(int type, @NonNull String targetUUID) { @@ -104,19 +100,6 @@ public int getType() { return this.type; } - public void setInFocus(@Nullable Boolean inFocus) { - this.inFocus = inFocus; - } - - public boolean isInFocusOrDefault() { - return this.inFocus == null ? IN_FOCUS_DEFAULT : this.inFocus; - } - - @Nullable - public Boolean getInFocusOrNull() { - return this.inFocus; - } - @Nullable public Long getCacheValidityInMsOrNull() { return this.cacheValidityInMs; @@ -198,9 +181,6 @@ public static void toJSON(@NonNull Filter statusFilter, @NonNull JSONObject json ProviderContract.Filter.toJSON(statusFilter, json); json.put(JSON_TYPE, statusFilter.getType()); json.put(JSON_TARGET, statusFilter.getTargetUUID()); - if (statusFilter.getInFocusOrNull() != null) { - json.put(JSON_IN_FOCUS, statusFilter.getInFocusOrNull()); - } if (statusFilter.getCacheValidityInMsOrNull() != null) { json.put(JSON_CACHE_VALIDITY_IN_MS, statusFilter.getCacheValidityInMsOrNull()); } @@ -211,7 +191,6 @@ public static void toJSON(@NonNull Filter statusFilter, @NonNull JSONObject json private static final String JSON_TYPE = "type"; private static final String JSON_TARGET = "target"; - private static final String JSON_IN_FOCUS = "inFocus"; private static final String JSON_CACHE_VALIDITY_IN_MS = "cacheValidityInMs"; private static final String JSON_PROVIDED_ENCRYPT_KEYS_MAP = "providedEncryptKeysMap"; @@ -219,9 +198,6 @@ public static void fromJSON(@NonNull Filter statusFilter, @NonNull JSONObject js ProviderContract.Filter.fromJSON(statusFilter, json); statusFilter.type = json.getInt(JSON_TYPE); statusFilter.targetUUID = json.getString(JSON_TARGET); - if (json.has(JSON_IN_FOCUS)) { - statusFilter.inFocus = json.getBoolean(JSON_IN_FOCUS); - } if (json.has(JSON_CACHE_VALIDITY_IN_MS)) { statusFilter.cacheValidityInMs = json.getLong(JSON_CACHE_VALIDITY_IN_MS); } @@ -244,10 +220,8 @@ public String toString() { return Filter.class.getSimpleName() + "{" + "targetUUID='" + targetUUID + '\'' + ", type=" + type + - ", cacheOnly=" + getCacheOnlyOrNull() + - ", asyncOnly=" + getAsyncOnlyOrNull() + ", cacheValidityInMs=" + cacheValidityInMs + - ", inFocus=" + inFocus + + super.toStringParts() + '}'; } } 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 97cfe75e..7f7a4563 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 @@ -144,7 +144,7 @@ object GTFSRealTimeVehiclePositionsProvider : MTLog.Loggable { @JvmStatic fun GTFSRealTimeProvider.getNew(filter: VehicleLocationProviderContract.Filter): List? { - updateAgencyDataIfRequired(filter.inFocusOrDefault) + updateAgencyDataIfRequired(filter.isInFocusOrDefault) return getCached(filter) } diff --git a/src/main/java/org/mtransit/android/commons/provider/vehiclelocations/NextBusVehicleLocationsProvider.kt b/src/main/java/org/mtransit/android/commons/provider/vehiclelocations/NextBusVehicleLocationsProvider.kt index ce7a3d24..00ff1a01 100644 --- a/src/main/java/org/mtransit/android/commons/provider/vehiclelocations/NextBusVehicleLocationsProvider.kt +++ b/src/main/java/org/mtransit/android/commons/provider/vehiclelocations/NextBusVehicleLocationsProvider.kt @@ -94,7 +94,7 @@ object NextBusVehicleLocationsProvider { @JvmStatic fun NextBusProvider.getNew(filter: VehicleLocationProviderContract.Filter): List? { - updateAgencyDataIfRequired(filter.inFocusOrDefault) + updateAgencyDataIfRequired(filter.isInFocusOrDefault) return getCached(filter) } diff --git a/src/main/java/org/mtransit/android/commons/provider/vehiclelocations/VehicleLocationProvider.kt b/src/main/java/org/mtransit/android/commons/provider/vehiclelocations/VehicleLocationProvider.kt index 60408284..62611fa0 100644 --- a/src/main/java/org/mtransit/android/commons/provider/vehiclelocations/VehicleLocationProvider.kt +++ b/src/main/java/org/mtransit/android/commons/provider/vehiclelocations/VehicleLocationProvider.kt @@ -78,7 +78,7 @@ abstract class VehicleLocationProvider : MTContentProvider(), } return getVehicleLocationCursor(cachedVehicleLocations) } - val cacheValidityInMs = getVehicleLocationValidityInMs(filter.inFocusOrDefault) + val cacheValidityInMs = getVehicleLocationValidityInMs(filter.isInFocusOrDefault) // TODO filter cache validity override like service update? var loadNewVehicleLocations = false if (cachedVehicleLocations.isNullOrEmpty()) { diff --git a/src/main/java/org/mtransit/android/commons/provider/vehiclelocations/VehicleLocationProviderContract.kt b/src/main/java/org/mtransit/android/commons/provider/vehiclelocations/VehicleLocationProviderContract.kt index 9f5d7b4a..5c0030bb 100644 --- a/src/main/java/org/mtransit/android/commons/provider/vehiclelocations/VehicleLocationProviderContract.kt +++ b/src/main/java/org/mtransit/android/commons/provider/vehiclelocations/VehicleLocationProviderContract.kt @@ -97,9 +97,6 @@ interface VehicleLocationProviderContract : ProviderContract { override val routeDirection: RouteDirection? = null, ) : ProviderContract.Filter(), GTFSRealTimeProviderFilter, MTLog.Loggable { - var inFocus: Boolean? = null - val inFocusOrDefault get() = inFocus ?: false - var providedEncryptKeysMap: Map? = null private set @@ -135,7 +132,6 @@ interface VehicleLocationProviderContract : ProviderContract { private const val JSON_POI = "poi" private const val JSON_ROUTE = "route" private const val JSON_ROUTE_DIRECTION = "routeDirection" - private const val JSON_IN_FOCUS = "inFocus" private const val JSON_PROVIDED_ENCRYPT_KEYS_MAP = "providedEncryptKeysMap" fun fromJSONString(jsonString: String?): Filter? { @@ -159,7 +155,6 @@ interface VehicleLocationProviderContract : ProviderContract { val routeDirection = json.optJSONObject(JSON_ROUTE_DIRECTION)?.let { jRouteDirection -> authority?.let { RouteDirection.fromJSON(jRouteDirection, it) } } - val inFocus = JSONUtils.optBoolean(json, JSON_IN_FOCUS) val providedEncryptKeysMap: Map? = json.optJSONObject(JSON_PROVIDED_ENCRYPT_KEYS_MAP)?.let { jProvidedEncryptKeysMap -> JSONUtils.toMapOfStrings(jProvidedEncryptKeysMap) } @@ -167,7 +162,6 @@ interface VehicleLocationProviderContract : ProviderContract { ?: route?.let { Filter(authority = route.authority, route = it) } ?: routeDirection?.let { Filter(authority = routeDirection.authority, routeDirection = it) }) ?.apply { - this.inFocus = inFocus fromJSON(this, json) this.providedEncryptKeysMap = providedEncryptKeysMap } @@ -184,7 +178,6 @@ interface VehicleLocationProviderContract : ProviderContract { vehicleLocationFilter.poi?.let { put(JSON_POI, it.toJSON()) } vehicleLocationFilter.route?.let { put(JSON_ROUTE, Route.toJSON(it)) } vehicleLocationFilter.routeDirection?.let { put(JSON_ROUTE_DIRECTION, RouteDirection.toJSON(it)) } - vehicleLocationFilter.inFocus?.let { put(JSON_IN_FOCUS, it) } vehicleLocationFilter.providedEncryptKeysMap?.let { put(JSON_PROVIDED_ENCRYPT_KEYS_MAP, JSONUtils.toJSONObject(it)) } } } catch (jsone: JSONException) { From a5bba18a62d6da1c28245b883e259e0a0bfe5a41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathieu=20M=C3=A9a?= Date: Fri, 19 Jun 2026 11:55:51 -0400 Subject: [PATCH 3/7] cacheValidityInMs --- .../provider/common/ProviderContract.java | 32 +++++++++++++-- .../provider/news/NewsProviderContract.java | 27 ------------- .../ServiceUpdateProviderContract.java | 39 ++----------------- .../status/StatusProviderContract.java | 39 +------------------ 4 files changed, 35 insertions(+), 102 deletions(-) diff --git a/src/main/java/org/mtransit/android/commons/provider/common/ProviderContract.java b/src/main/java/org/mtransit/android/commons/provider/common/ProviderContract.java index 45f9179d..d5cedb6d 100644 --- a/src/main/java/org/mtransit/android/commons/provider/common/ProviderContract.java +++ b/src/main/java/org/mtransit/android/commons/provider/common/ProviderContract.java @@ -43,6 +43,8 @@ abstract class Filter { @Nullable private Boolean cacheOnly = null; @Nullable + private Long cacheValidityInMs = null; + @Nullable private Boolean asyncOnly = null; @Nullable private Boolean inFocus = null; @@ -61,6 +63,16 @@ public void setCacheOnly(@Nullable Boolean cacheOnly) { this.cacheOnly = cacheOnly; } + @Nullable + public Long getCacheValidityInMsOrNull() { + return this.cacheValidityInMs; + } + + @NonNull + public void setCacheValidityInMs(@Nullable Long cacheValidityInMs) { + this.cacheValidityInMs = cacheValidityInMs; + } + public void setAsyncOnly(@Nullable Boolean asyncOnly) { this.asyncOnly = asyncOnly; } @@ -88,13 +100,23 @@ public void setInFocus(@Nullable Boolean inFocus) { } private static final String JSON_CACHE_ONLY = "cacheOnly"; + private static final String JSON_CACHE_VALIDITY_IN_MS = "cacheValidityInMs"; private static final String JSON_ASYNC_ONLY = "asyncOnly"; private static final String JSON_IN_FOCUS = "inFocus"; + @Nullable + @SuppressWarnings("unused") + public static Long getCacheValidityInMsFromJSON(@NonNull JSONObject json) throws JSONException { + return json.has(JSON_CACHE_VALIDITY_IN_MS) ? json.getLong(JSON_CACHE_VALIDITY_IN_MS) : null; + } + public static void toJSON(@NonNull Filter filter, @NonNull JSONObject json) throws JSONException { if (filter.getCacheOnlyOrNull() != null) { json.put(JSON_CACHE_ONLY, filter.getCacheOnlyOrNull()); } + if (filter.getCacheValidityInMsOrNull() != null) { + json.put(JSON_CACHE_VALIDITY_IN_MS, filter.getCacheValidityInMsOrNull()); + } if (filter.getAsyncOnlyOrNull() != null) { json.put(JSON_ASYNC_ONLY, filter.getAsyncOnlyOrNull()); } @@ -107,6 +129,9 @@ public static void fromJSON(@NonNull Filter filter, @NonNull JSONObject json) th if (json.has(JSON_CACHE_ONLY)) { filter.cacheOnly = json.getBoolean(JSON_CACHE_ONLY); } + if (json.has(JSON_CACHE_VALIDITY_IN_MS)) { + filter.cacheValidityInMs = json.getLong(JSON_CACHE_VALIDITY_IN_MS); + } if (json.has(JSON_ASYNC_ONLY)) { filter.asyncOnly = json.getBoolean(JSON_ASYNC_ONLY); } @@ -118,9 +143,10 @@ public static void fromJSON(@NonNull Filter filter, @NonNull JSONObject json) th @NonNull public String toStringParts() { final StringBuilder sb = new StringBuilder(); - sb.append("cacheOnly:").append(this.cacheOnly).append(','); - sb.append("asyncOnly:").append(this.asyncOnly).append(','); - sb.append("inFocus:").append(this.inFocus).append(","); + if (this.cacheOnly != null) sb.append("cacheOnly:").append(this.cacheOnly).append(','); + if (this.cacheValidityInMs != null) sb.append("cacheValidityInMs:").append(MTLog.formatDuration(this.cacheValidityInMs)).append(','); + if (this.asyncOnly != null) sb.append("asyncOnly:").append(this.asyncOnly).append(','); + if (this.inFocus != null) sb.append("inFocus:").append(this.inFocus).append(","); return sb.toString(); } } diff --git a/src/main/java/org/mtransit/android/commons/provider/news/NewsProviderContract.java b/src/main/java/org/mtransit/android/commons/provider/news/NewsProviderContract.java index 28332a4e..b28fa9b8 100644 --- a/src/main/java/org/mtransit/android/commons/provider/news/NewsProviderContract.java +++ b/src/main/java/org/mtransit/android/commons/provider/news/NewsProviderContract.java @@ -150,8 +150,6 @@ public String getLogTag() { @Nullable private List targets; @Nullable - private Long cacheValidityInMs = null; - @Nullable private Long minCreatedAtInMs = null; @Nullable private Map providedEncryptKeysMap = null; @@ -251,7 +249,6 @@ public String toString() { sb.append("targets:").append(this.targets).append(','); } sb.append(super.toStringParts()); - sb.append("cacheValidityInMs:").append(this.cacheValidityInMs).append(','); sb.append("minCreatedAtInMs:").append(this.minCreatedAtInMs); sb.append(']'); return sb.toString(); @@ -295,23 +292,6 @@ public String getSqlSelection(@NonNull String uuidTableColumn, @NonNull String t return sb.toString(); } - @Nullable - public Long getCacheValidityInMsOrNull() { - return this.cacheValidityInMs; - } - - @SuppressWarnings("unused") - public boolean hasCacheValidityInMs() { - return this.cacheValidityInMs != null && this.cacheValidityInMs > 0; - } - - @SuppressWarnings("unused") - @NonNull - public Filter setCacheValidityInMs(@Nullable Long cacheValidityInMs) { - this.cacheValidityInMs = cacheValidityInMs; - return this; - } - @NonNull public Filter setProvidedEncryptKeysMap(@Nullable Map providedEncryptKeysMap) { this.providedEncryptKeysMap = providedEncryptKeysMap; @@ -362,7 +342,6 @@ public static Filter fromJSONString(@Nullable String jsonString) { private static final String JSON_UUIDS = "uuids"; private static final String JSON_TARGETS = "targets"; - private static final String JSON_CACHE_VALIDITY_IN_MS = "cacheValidityInMs"; private static final String JSON_MIN_CREATED_AT_IN_MS = "minCreatedAtInMs"; private static final String JSON_PROVIDED_ENCRYPT_KEYS_MAP = "providedEncryptKeysMap"; @@ -386,9 +365,6 @@ public static Filter fromJSON(@NonNull JSONObject json) { } newsFilter.setTargets(targets); } - if (json.has(JSON_CACHE_VALIDITY_IN_MS)) { - newsFilter.cacheValidityInMs = json.getLong(JSON_CACHE_VALIDITY_IN_MS); - } if (json.has(JSON_MIN_CREATED_AT_IN_MS)) { newsFilter.minCreatedAtInMs = json.getLong(JSON_MIN_CREATED_AT_IN_MS); } @@ -421,9 +397,6 @@ public static JSONObject toJSON(@NonNull Filter newsFilter) { if (newsFilter.getMinCreatedAtInMsOrNull() != null) { json.put(JSON_MIN_CREATED_AT_IN_MS, newsFilter.getMinCreatedAtInMsOrNull()); } - if (newsFilter.getCacheValidityInMsOrNull() != null) { - json.put(JSON_CACHE_VALIDITY_IN_MS, newsFilter.getCacheValidityInMsOrNull()); - } if (isUUIDFilter(newsFilter) && newsFilter.uuids != null) { JSONArray jUUIDs = new JSONArray(); for (String uuid : newsFilter.uuids) { diff --git a/src/main/java/org/mtransit/android/commons/provider/serviceupdate/ServiceUpdateProviderContract.java b/src/main/java/org/mtransit/android/commons/provider/serviceupdate/ServiceUpdateProviderContract.java index c869bd38..b2fd4e59 100644 --- a/src/main/java/org/mtransit/android/commons/provider/serviceupdate/ServiceUpdateProviderContract.java +++ b/src/main/java/org/mtransit/android/commons/provider/serviceupdate/ServiceUpdateProviderContract.java @@ -116,9 +116,6 @@ public String getLogTag() { private final Route route; @Nullable private final RouteDirection routeDirection; - - @Nullable - private Long cacheValidityInMs = null; @Nullable private Map providedEncryptKeysMap = null; @@ -146,10 +143,8 @@ public Filter(@NonNull String authority, @NonNull RouteDirection routeDirection) @NonNull @Override public String toString() { - final StringBuilder sb = new StringBuilder(); - sb.append(Filter.class.getSimpleName()) - .append(super.toStringParts()) - .append("cacheValidityInMs:").append(this.cacheValidityInMs).append(','); + final StringBuilder sb = new StringBuilder(Filter.class.getSimpleName()); + sb.append(super.toStringParts()); if (this.poi != null) { sb.append("poi:").append(this.poi).append(','); } @@ -255,21 +250,6 @@ public RouteDirection getRouteDirection() { return routeDirection; } - @Nullable - public Long getCacheValidityInMsOrNull() { - return this.cacheValidityInMs; - } - - @SuppressWarnings("unused") - public boolean hasCacheValidityInMs() { - return this.cacheValidityInMs != null && this.cacheValidityInMs > 0; - } - - @SuppressWarnings("unused") - public void setCacheValidityInMs(@Nullable Long cacheValidityInMs) { - this.cacheValidityInMs = cacheValidityInMs; - } - @NonNull public Filter setProvidedEncryptKeysMap(@Nullable Map providedEncryptKeysMap) { this.providedEncryptKeysMap = providedEncryptKeysMap; @@ -288,13 +268,9 @@ public Map getProvidedEncryptKeysMap() { @Nullable public String getProvidedEncryptKey(@NonNull String key) { - if (this.providedEncryptKeysMap == null) { - return null; - } + if (this.providedEncryptKeysMap == null) return null; final String value = this.providedEncryptKeysMap.get(key); - if (value == null || value.trim().isEmpty()) { - return null; - } + if (value == null || value.trim().isEmpty()) return null; return value; } @@ -323,7 +299,6 @@ public static Filter fromJSONString(@Nullable String jsonString) { private static final String JSON_ROUTE = "route"; private static final String JSON_ROUTE_DIRECTION = "routeDirection"; private static final String JSON_AUTHORITY = "authority"; - private static final String JSON_CACHE_VALIDITY_IN_MS = "cacheValidityInMs"; private static final String JSON_PROVIDED_ENCRYPT_KEYS_MAP = "providedEncryptKeysMap"; @Nullable @@ -346,9 +321,6 @@ public static Filter fromJSON(@NonNull JSONObject json) { return null; // WTF? } ProviderContract.Filter.fromJSON(serviceUpdateFilter, json); - if (json.has(JSON_CACHE_VALIDITY_IN_MS)) { - serviceUpdateFilter.cacheValidityInMs = json.getLong(JSON_CACHE_VALIDITY_IN_MS); - } if (json.has(JSON_PROVIDED_ENCRYPT_KEYS_MAP)) { serviceUpdateFilter.providedEncryptKeysMap = JSONUtils.toMapOfStrings(json.getJSONObject(JSON_PROVIDED_ENCRYPT_KEYS_MAP)); } @@ -387,9 +359,6 @@ public static JSONObject toJSON(@NonNull Filter serviceUpdateFilter) { if (serviceUpdateFilter.authority != null) { json.put(JSON_AUTHORITY, serviceUpdateFilter.authority); } - if (serviceUpdateFilter.getCacheValidityInMsOrNull() != null) { - json.put(JSON_CACHE_VALIDITY_IN_MS, serviceUpdateFilter.getCacheValidityInMsOrNull()); - } if (serviceUpdateFilter.getProvidedEncryptKeysMap() != null) { json.put(JSON_PROVIDED_ENCRYPT_KEYS_MAP, JSONUtils.toJSONObject(serviceUpdateFilter.getProvidedEncryptKeysMap())); } diff --git a/src/main/java/org/mtransit/android/commons/provider/status/StatusProviderContract.java b/src/main/java/org/mtransit/android/commons/provider/status/StatusProviderContract.java index fdbe28be..c93d4eea 100644 --- a/src/main/java/org/mtransit/android/commons/provider/status/StatusProviderContract.java +++ b/src/main/java/org/mtransit/android/commons/provider/status/StatusProviderContract.java @@ -82,8 +82,6 @@ public String getLogTag() { private String targetUUID; private int type; @Nullable - private Long cacheValidityInMs = null; - @Nullable private Map providedEncryptKeysMap = null; public Filter(int type, @NonNull String targetUUID) { @@ -100,21 +98,6 @@ public int getType() { return this.type; } - @Nullable - public Long getCacheValidityInMsOrNull() { - return this.cacheValidityInMs; - } - - @SuppressWarnings("unused") - public boolean hasCacheValidityInMs() { - return cacheValidityInMs != null && cacheValidityInMs > 0; - } - - @SuppressWarnings("unused") - public void setCacheValidityInMs(@Nullable Long cacheValidityInMs) { - this.cacheValidityInMs = cacheValidityInMs; - } - @NonNull public Filter setProvidedEncryptKeysMap(@Nullable Map providedEncryptKeysMap) { this.providedEncryptKeysMap = providedEncryptKeysMap; @@ -132,13 +115,9 @@ public Map getProvidedEncryptKeysMap() { @Nullable public String getProvidedEncryptKey(@NonNull String key) { - if (this.providedEncryptKeysMap == null) { - return null; - } + if (this.providedEncryptKeysMap == null) return null; final String value = this.providedEncryptKeysMap.get(key); - if (value == null || value.trim().isEmpty()) { - return null; - } + if (value == null || value.trim().isEmpty()) return null; return value; } @@ -171,19 +150,10 @@ public static String getTargetUUIDFromJSON(@NonNull JSONObject json) throws JSON return json.getString(JSON_TARGET); } - @Nullable - @SuppressWarnings("unused") - public static Long getCacheValidityInMsFromJSON(@NonNull JSONObject json) throws JSONException { - return json.has(JSON_CACHE_VALIDITY_IN_MS) ? json.getLong(JSON_CACHE_VALIDITY_IN_MS) : null; - } - public static void toJSON(@NonNull Filter statusFilter, @NonNull JSONObject json) throws JSONException { ProviderContract.Filter.toJSON(statusFilter, json); json.put(JSON_TYPE, statusFilter.getType()); json.put(JSON_TARGET, statusFilter.getTargetUUID()); - if (statusFilter.getCacheValidityInMsOrNull() != null) { - json.put(JSON_CACHE_VALIDITY_IN_MS, statusFilter.getCacheValidityInMsOrNull()); - } if (statusFilter.getProvidedEncryptKeysMap() != null) { json.put(JSON_PROVIDED_ENCRYPT_KEYS_MAP, JSONUtils.toJSONObject(statusFilter.getProvidedEncryptKeysMap())); } @@ -191,16 +161,12 @@ public static void toJSON(@NonNull Filter statusFilter, @NonNull JSONObject json private static final String JSON_TYPE = "type"; private static final String JSON_TARGET = "target"; - private static final String JSON_CACHE_VALIDITY_IN_MS = "cacheValidityInMs"; private static final String JSON_PROVIDED_ENCRYPT_KEYS_MAP = "providedEncryptKeysMap"; public static void fromJSON(@NonNull Filter statusFilter, @NonNull JSONObject json) throws JSONException { ProviderContract.Filter.fromJSON(statusFilter, json); statusFilter.type = json.getInt(JSON_TYPE); statusFilter.targetUUID = json.getString(JSON_TARGET); - if (json.has(JSON_CACHE_VALIDITY_IN_MS)) { - statusFilter.cacheValidityInMs = json.getLong(JSON_CACHE_VALIDITY_IN_MS); - } if (json.has(JSON_PROVIDED_ENCRYPT_KEYS_MAP)) { statusFilter.providedEncryptKeysMap = JSONUtils.toMapOfStrings(json.getJSONObject(JSON_PROVIDED_ENCRYPT_KEYS_MAP)); } @@ -220,7 +186,6 @@ public String toString() { return Filter.class.getSimpleName() + "{" + "targetUUID='" + targetUUID + '\'' + ", type=" + type + - ", cacheValidityInMs=" + cacheValidityInMs + super.toStringParts() + '}'; } From f06e1c6af280adee061905a3dd055cae10757126 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathieu=20M=C3=A9a?= Date: Fri, 19 Jun 2026 14:08:25 -0400 Subject: [PATCH 4/7] cleanup --- .../org/mtransit/android/commons/data/AppStatus.java | 10 +++++----- .../android/commons/data/AvailabilityPercent.java | 8 ++++---- .../mtransit/android/commons/data/ServiceUpdates.kt | 5 +++++ .../provider/agency/AgencyProviderDeployWorker.kt | 4 ++-- .../common/MTSearchRecentSuggestionsProvider.java | 2 +- .../commons/provider/poi/POIProviderContract.java | 3 +-- .../commons/provider/status/StatusProvider.java | 2 +- .../provider/status/StatusProviderContract.java | 5 ++++- 8 files changed, 23 insertions(+), 16 deletions(-) create mode 100644 src/main/java/org/mtransit/android/commons/data/ServiceUpdates.kt diff --git a/src/main/java/org/mtransit/android/commons/data/AppStatus.java b/src/main/java/org/mtransit/android/commons/data/AppStatus.java index 23cd748a..70cebde9 100644 --- a/src/main/java/org/mtransit/android/commons/data/AppStatus.java +++ b/src/main/java/org/mtransit/android/commons/data/AppStatus.java @@ -236,9 +236,9 @@ public static StatusProviderContract.Filter fromJSONString(@Nullable String json @Nullable public static StatusProviderContract.Filter fromJSON(@NonNull JSONObject json) { try { - String targetUUID = StatusProviderContract.Filter.getTargetUUIDFromJSON(json); - String pkg = json.getString(JSON_PKG); - AppStatusFilter appStatusFilter = new AppStatusFilter(targetUUID, pkg); + final String targetUUID = StatusProviderContract.Filter.getTargetUUIDFromJSON(json); + final String pkg = json.getString(JSON_PKG); + final AppStatusFilter appStatusFilter = new AppStatusFilter(targetUUID, pkg); StatusProviderContract.Filter.fromJSON(appStatusFilter, json); return appStatusFilter; } catch (JSONException jsone) { @@ -255,14 +255,14 @@ public String toJSONStringStatic(@NonNull StatusProviderContract.Filter statusFi @Nullable private static String toJSONString(@NonNull StatusProviderContract.Filter statusFilter) { - JSONObject json = toJSON(statusFilter); + final JSONObject json = toJSON(statusFilter); return json == null ? null : json.toString(); } @Nullable private static JSONObject toJSON(@NonNull StatusProviderContract.Filter statusFilter) { try { - JSONObject json = new JSONObject(); + final JSONObject json = new JSONObject(); StatusProviderContract.Filter.toJSON(statusFilter, json); if (statusFilter instanceof AppStatusFilter) { AppStatusFilter appStatusFilter = (AppStatusFilter) statusFilter; diff --git a/src/main/java/org/mtransit/android/commons/data/AvailabilityPercent.java b/src/main/java/org/mtransit/android/commons/data/AvailabilityPercent.java index 19c8c9d9..2c990e40 100644 --- a/src/main/java/org/mtransit/android/commons/data/AvailabilityPercent.java +++ b/src/main/java/org/mtransit/android/commons/data/AvailabilityPercent.java @@ -642,8 +642,8 @@ public static StatusProviderContract.Filter fromJSONString(@Nullable String json @Nullable public static StatusProviderContract.Filter fromJSON(@NonNull JSONObject json) { try { - String targetUUID = StatusProviderContract.Filter.getTargetUUIDFromJSON(json); - AvailabilityPercentStatusFilter availabilityPercentStatusFilter = new AvailabilityPercentStatusFilter(targetUUID); + final String targetUUID = StatusProviderContract.Filter.getTargetUUIDFromJSON(json); + final AvailabilityPercentStatusFilter availabilityPercentStatusFilter = new AvailabilityPercentStatusFilter(targetUUID); StatusProviderContract.Filter.fromJSON(availabilityPercentStatusFilter, json); return availabilityPercentStatusFilter; } catch (JSONException jsone) { @@ -660,14 +660,14 @@ public String toJSONStringStatic(@NonNull StatusProviderContract.Filter statusFi @Nullable private static String toJSONString(@NonNull StatusProviderContract.Filter statusFilter) { - JSONObject json = toJSON(statusFilter); + final JSONObject json = toJSON(statusFilter); return json == null ? null : json.toString(); } @Nullable private static JSONObject toJSON(@NonNull StatusProviderContract.Filter statusFilter) { try { - JSONObject json = new JSONObject(); + final JSONObject json = new JSONObject(); StatusProviderContract.Filter.toJSON(statusFilter, json); return json; } catch (JSONException jsone) { diff --git a/src/main/java/org/mtransit/android/commons/data/ServiceUpdates.kt b/src/main/java/org/mtransit/android/commons/data/ServiceUpdates.kt new file mode 100644 index 00000000..c81e4ad9 --- /dev/null +++ b/src/main/java/org/mtransit/android/commons/data/ServiceUpdates.kt @@ -0,0 +1,5 @@ +package org.mtransit.android.commons.data + +data class ServiceUpdates( + val serviceUpdates: List?, +) diff --git a/src/main/java/org/mtransit/android/commons/provider/agency/AgencyProviderDeployWorker.kt b/src/main/java/org/mtransit/android/commons/provider/agency/AgencyProviderDeployWorker.kt index 80ce8b78..1c99b6fc 100644 --- a/src/main/java/org/mtransit/android/commons/provider/agency/AgencyProviderDeployWorker.kt +++ b/src/main/java/org/mtransit/android/commons/provider/agency/AgencyProviderDeployWorker.kt @@ -41,7 +41,7 @@ class AgencyProviderDeployWorker( override fun getLogTag() = LOG_TAG - override suspend fun doWork() = withContext(Dispatchers.IO) { + override suspend fun doWork(): Result = withContext(Dispatchers.IO) { val agencyProviderMetaData = context.getString(R.string.agency_provider) val agencyProvider = PackageManagerUtils.findContentProvidersWithMetaData(context, context.packageName) @@ -49,7 +49,7 @@ class AgencyProviderDeployWorker( agencyProviderMetaData == provider.metaData?.getString(agencyProviderMetaData) } ?: return@withContext Result.failure(Data.Builder().putString("reason", "no agency provider!").build()) ping(agencyProvider) - Result.success() + return@withContext Result.success() } private fun ping(agencyProvider: ProviderInfo) { diff --git a/src/main/java/org/mtransit/android/commons/provider/common/MTSearchRecentSuggestionsProvider.java b/src/main/java/org/mtransit/android/commons/provider/common/MTSearchRecentSuggestionsProvider.java index 249f16e0..74b3bbe6 100644 --- a/src/main/java/org/mtransit/android/commons/provider/common/MTSearchRecentSuggestionsProvider.java +++ b/src/main/java/org/mtransit/android/commons/provider/common/MTSearchRecentSuggestionsProvider.java @@ -28,7 +28,7 @@ protected void setupSuggestions(@NonNull String authority, int mode) { super.setupSuggestions(authority, mode); } - // INHERITED FROM CONTENTPROVIDER + // INHERITED FROM CONTENT PROVIDER @Override public boolean onCreate() { diff --git a/src/main/java/org/mtransit/android/commons/provider/poi/POIProviderContract.java b/src/main/java/org/mtransit/android/commons/provider/poi/POIProviderContract.java index 7dd2d9ad..1e9da172 100644 --- a/src/main/java/org/mtransit/android/commons/provider/poi/POIProviderContract.java +++ b/src/main/java/org/mtransit/android/commons/provider/poi/POIProviderContract.java @@ -274,8 +274,7 @@ public String toString() { sb.append("sqlSelection:").append(this.sqlSelection).append(','); } sb.append("extras:").append(this.extras).append(','); - sb.append("cacheOnly:").append(getCacheOnlyOrNull()).append(','); - sb.append("asyncOnly:").append(getAsyncOnlyOrNull()).append(','); + sb.append(super.toStringParts()); sb.append(']'); return sb.toString(); } diff --git a/src/main/java/org/mtransit/android/commons/provider/status/StatusProvider.java b/src/main/java/org/mtransit/android/commons/provider/status/StatusProvider.java index 9eefc5ab..18584b22 100644 --- a/src/main/java/org/mtransit/android/commons/provider/status/StatusProvider.java +++ b/src/main/java/org/mtransit/android/commons/provider/status/StatusProvider.java @@ -133,7 +133,7 @@ private static Cursor getStatus(@NonNull StatusProviderContract provider, @Nulla @Nullable private static StatusProviderContract.Filter extractStatusFilter(@Nullable String selection) { - int type = StatusProviderContract.Filter.getTypeFromJSONString(selection); + final int type = StatusProviderContract.Filter.getTypeFromJSONString(selection); StatusProviderContract.Filter statusFilter; switch (type) { case POI.ITEM_STATUS_TYPE_NONE: diff --git a/src/main/java/org/mtransit/android/commons/provider/status/StatusProviderContract.java b/src/main/java/org/mtransit/android/commons/provider/status/StatusProviderContract.java index c93d4eea..f81b59d0 100644 --- a/src/main/java/org/mtransit/android/commons/provider/status/StatusProviderContract.java +++ b/src/main/java/org/mtransit/android/commons/provider/status/StatusProviderContract.java @@ -11,6 +11,7 @@ import org.mtransit.android.commons.JSONUtils; import org.mtransit.android.commons.MTLog; import org.mtransit.android.commons.SecureStringUtils; +import org.mtransit.android.commons.data.POI; import org.mtransit.android.commons.data.POIStatus; import org.mtransit.android.commons.provider.common.ProviderContract; @@ -80,11 +81,12 @@ public String getLogTag() { @NonNull private String targetUUID; + @POI.ItemStatusType private int type; @Nullable private Map providedEncryptKeysMap = null; - public Filter(int type, @NonNull String targetUUID) { + public Filter(@POI.ItemStatusType int type, @NonNull String targetUUID) { this.type = type; this.targetUUID = targetUUID; } @@ -94,6 +96,7 @@ public String getTargetUUID() { return this.targetUUID; } + @POI.ItemStatusType public int getType() { return this.type; } From b68fccff75954641305f276c99e273308300191f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathieu=20M=C3=A9a?= Date: Fri, 19 Jun 2026 14:21:42 -0400 Subject: [PATCH 5/7] wip --- .../provider/common/ProviderContract.java | 43 +++++-------------- 1 file changed, 10 insertions(+), 33 deletions(-) diff --git a/src/main/java/org/mtransit/android/commons/provider/common/ProviderContract.java b/src/main/java/org/mtransit/android/commons/provider/common/ProviderContract.java index d5cedb6d..73105ef1 100644 --- a/src/main/java/org/mtransit/android/commons/provider/common/ProviderContract.java +++ b/src/main/java/org/mtransit/android/commons/provider/common/ProviderContract.java @@ -37,7 +37,6 @@ public interface ProviderContract extends MTLog.Loggable { abstract class Filter { private static final boolean CACHE_ONLY_DEFAULT = false; - private static final boolean ASYNC_ONLY_DEFAULT = false; private static final boolean IN_FOCUS_DEFAULT = false; @Nullable @@ -45,20 +44,18 @@ abstract class Filter { @Nullable private Long cacheValidityInMs = null; @Nullable - private Boolean asyncOnly = null; - @Nullable private Boolean inFocus = null; public boolean isCacheOnlyOrDefault() { return this.cacheOnly == null ? CACHE_ONLY_DEFAULT : this.cacheOnly; } + @SuppressWarnings("unused") @Nullable public Boolean getCacheOnlyOrNull() { return this.cacheOnly; } - @NonNull public void setCacheOnly(@Nullable Boolean cacheOnly) { this.cacheOnly = cacheOnly; } @@ -68,28 +65,16 @@ public Long getCacheValidityInMsOrNull() { return this.cacheValidityInMs; } - @NonNull + @SuppressWarnings("unused") public void setCacheValidityInMs(@Nullable Long cacheValidityInMs) { this.cacheValidityInMs = cacheValidityInMs; } - public void setAsyncOnly(@Nullable Boolean asyncOnly) { - this.asyncOnly = asyncOnly; - } - - public boolean isAsyncOnlyOrDefault() { - return this.asyncOnly == null ? ASYNC_ONLY_DEFAULT : this.asyncOnly; - } - - @Nullable - public Boolean getAsyncOnlyOrNull() { - return this.asyncOnly; - } - public boolean isInFocusOrDefault() { return this.inFocus == null ? IN_FOCUS_DEFAULT : this.inFocus; } + @SuppressWarnings("unused") @Nullable public Boolean getInFocusOrNull() { return this.inFocus; @@ -101,7 +86,6 @@ public void setInFocus(@Nullable Boolean inFocus) { private static final String JSON_CACHE_ONLY = "cacheOnly"; private static final String JSON_CACHE_VALIDITY_IN_MS = "cacheValidityInMs"; - private static final String JSON_ASYNC_ONLY = "asyncOnly"; private static final String JSON_IN_FOCUS = "inFocus"; @Nullable @@ -111,17 +95,14 @@ public static Long getCacheValidityInMsFromJSON(@NonNull JSONObject json) throws } public static void toJSON(@NonNull Filter filter, @NonNull JSONObject json) throws JSONException { - if (filter.getCacheOnlyOrNull() != null) { - json.put(JSON_CACHE_ONLY, filter.getCacheOnlyOrNull()); - } - if (filter.getCacheValidityInMsOrNull() != null) { - json.put(JSON_CACHE_VALIDITY_IN_MS, filter.getCacheValidityInMsOrNull()); + if (filter.cacheOnly != null) { + json.put(JSON_CACHE_ONLY, filter.cacheOnly); } - if (filter.getAsyncOnlyOrNull() != null) { - json.put(JSON_ASYNC_ONLY, filter.getAsyncOnlyOrNull()); + if (filter.cacheValidityInMs != null) { + json.put(JSON_CACHE_VALIDITY_IN_MS, filter.cacheValidityInMs); } - if (filter.getInFocusOrNull() != null) { - json.put(JSON_IN_FOCUS, filter.getInFocusOrNull()); + if (filter.inFocus != null) { + json.put(JSON_IN_FOCUS, filter.inFocus); } } @@ -132,20 +113,16 @@ public static void fromJSON(@NonNull Filter filter, @NonNull JSONObject json) th if (json.has(JSON_CACHE_VALIDITY_IN_MS)) { filter.cacheValidityInMs = json.getLong(JSON_CACHE_VALIDITY_IN_MS); } - if (json.has(JSON_ASYNC_ONLY)) { - filter.asyncOnly = json.getBoolean(JSON_ASYNC_ONLY); - } if (json.has(JSON_IN_FOCUS)) { filter.inFocus = json.getBoolean(JSON_IN_FOCUS); } } @NonNull - public String toStringParts() { + protected String toStringParts() { final StringBuilder sb = new StringBuilder(); if (this.cacheOnly != null) sb.append("cacheOnly:").append(this.cacheOnly).append(','); if (this.cacheValidityInMs != null) sb.append("cacheValidityInMs:").append(MTLog.formatDuration(this.cacheValidityInMs)).append(','); - if (this.asyncOnly != null) sb.append("asyncOnly:").append(this.asyncOnly).append(','); if (this.inFocus != null) sb.append("inFocus:").append(this.inFocus).append(","); return sb.toString(); } From 0eebc9318bd4e75a11c9291ff311fa59f74e89e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathieu=20M=C3=A9a?= Date: Fri, 19 Jun 2026 15:39:30 -0400 Subject: [PATCH 6/7] wip --- .../provider/bike/BikeStationProvider.java | 2 +- .../provider/common/ProviderContract.java | 6 +++--- .../commons/provider/news/NewsProvider.java | 2 +- .../serviceupdate/ServiceUpdateProvider.java | 2 +- .../commons/provider/status/StatusProvider.java | 2 +- .../commons/task/MTCancellableAsyncTask.kt | 16 ++++++---------- 6 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/mtransit/android/commons/provider/bike/BikeStationProvider.java b/src/main/java/org/mtransit/android/commons/provider/bike/BikeStationProvider.java index 97a8f14e..660c2447 100644 --- a/src/main/java/org/mtransit/android/commons/provider/bike/BikeStationProvider.java +++ b/src/main/java/org/mtransit/android/commons/provider/bike/BikeStationProvider.java @@ -256,7 +256,7 @@ public Cursor getSearchSuggest(@Nullable String query) { public Cursor getPOI(@Nullable POIProviderContract.Filter poiFilter) { if (poiFilter != null && poiFilter.getExtraBoolean(POIProviderContract.POI_FILTER_EXTRA_AVOID_LOADING, false)) { if (getLastUpdateInMs() + getPOIMaxValidityInMs() > TimeUtils.currentTimeMillis()) { // not too old to display - Cursor cursor = getPOIFromDB(poiFilter); + final Cursor cursor = getPOIFromDB(poiFilter); if (cursor != null && cursor.getCount() > 0) { return cursor; // returned cached results instead of loading while user is waiting } diff --git a/src/main/java/org/mtransit/android/commons/provider/common/ProviderContract.java b/src/main/java/org/mtransit/android/commons/provider/common/ProviderContract.java index 73105ef1..7e0e47ea 100644 --- a/src/main/java/org/mtransit/android/commons/provider/common/ProviderContract.java +++ b/src/main/java/org/mtransit/android/commons/provider/common/ProviderContract.java @@ -52,7 +52,7 @@ public boolean isCacheOnlyOrDefault() { @SuppressWarnings("unused") @Nullable - public Boolean getCacheOnlyOrNull() { + public Boolean getCacheOnly() { return this.cacheOnly; } @@ -61,7 +61,7 @@ public void setCacheOnly(@Nullable Boolean cacheOnly) { } @Nullable - public Long getCacheValidityInMsOrNull() { + public Long getCacheValidityInMs() { return this.cacheValidityInMs; } @@ -76,7 +76,7 @@ public boolean isInFocusOrDefault() { @SuppressWarnings("unused") @Nullable - public Boolean getInFocusOrNull() { + public Boolean getInFocus() { return this.inFocus; } diff --git a/src/main/java/org/mtransit/android/commons/provider/news/NewsProvider.java b/src/main/java/org/mtransit/android/commons/provider/news/NewsProvider.java index bb2079fb..3e342f9e 100644 --- a/src/main/java/org/mtransit/android/commons/provider/news/NewsProvider.java +++ b/src/main/java/org/mtransit/android/commons/provider/news/NewsProvider.java @@ -189,7 +189,7 @@ private static Cursor getNews(@NonNull NewsProviderContract provider, @Nullable return getNewsCursor(cachedNews); } long cacheValidityInMs = provider.getNewsValidityInMs(newsFilter.isInFocusOrDefault()); - final Long filterCacheValidityInMs = newsFilter.getCacheValidityInMsOrNull(); + final Long filterCacheValidityInMs = newsFilter.getCacheValidityInMs(); if (filterCacheValidityInMs != null && filterCacheValidityInMs > provider.getMinDurationBetweenNewsRefreshInMs(newsFilter.isInFocusOrDefault())) { cacheValidityInMs = filterCacheValidityInMs; } diff --git a/src/main/java/org/mtransit/android/commons/provider/serviceupdate/ServiceUpdateProvider.java b/src/main/java/org/mtransit/android/commons/provider/serviceupdate/ServiceUpdateProvider.java index 0bd8a311..1583a106 100644 --- a/src/main/java/org/mtransit/android/commons/provider/serviceupdate/ServiceUpdateProvider.java +++ b/src/main/java/org/mtransit/android/commons/provider/serviceupdate/ServiceUpdateProvider.java @@ -122,7 +122,7 @@ private static Cursor getServiceUpdates(ServiceUpdateProviderContract provider, return getServiceUpdateCursor(cachedServiceUpdates); } long cacheValidityInMs = provider.getServiceUpdateValidityInMs(serviceUpdateFilter.isInFocusOrDefault()); - Long filterCacheValidityInMs = serviceUpdateFilter.getCacheValidityInMsOrNull(); + Long filterCacheValidityInMs = serviceUpdateFilter.getCacheValidityInMs(); if (filterCacheValidityInMs != null && filterCacheValidityInMs > provider.getMinDurationBetweenServiceUpdateRefreshInMs(serviceUpdateFilter.isInFocusOrDefault())) { cacheValidityInMs = filterCacheValidityInMs; diff --git a/src/main/java/org/mtransit/android/commons/provider/status/StatusProvider.java b/src/main/java/org/mtransit/android/commons/provider/status/StatusProvider.java index 18584b22..b8a68e5b 100644 --- a/src/main/java/org/mtransit/android/commons/provider/status/StatusProvider.java +++ b/src/main/java/org/mtransit/android/commons/provider/status/StatusProvider.java @@ -116,7 +116,7 @@ private static Cursor getStatus(@NonNull StatusProviderContract provider, @Nulla } // 3 - check if usable cache still valid (or if it could be refreshed) long cacheValidityInMs = provider.getStatusValidityInMs(statusFilter.isInFocusOrDefault()); - Long filterCacheValidityInMs = statusFilter.getCacheValidityInMsOrNull(); + Long filterCacheValidityInMs = statusFilter.getCacheValidityInMs(); if (filterCacheValidityInMs != null && filterCacheValidityInMs > provider.getMinDurationBetweenRefreshInMs(statusFilter.isInFocusOrDefault())) { cacheValidityInMs = filterCacheValidityInMs; } diff --git a/src/main/java/org/mtransit/android/commons/task/MTCancellableAsyncTask.kt b/src/main/java/org/mtransit/android/commons/task/MTCancellableAsyncTask.kt index 1858e622..4084a0fe 100644 --- a/src/main/java/org/mtransit/android/commons/task/MTCancellableAsyncTask.kt +++ b/src/main/java/org/mtransit/android/commons/task/MTCancellableAsyncTask.kt @@ -11,12 +11,12 @@ abstract class MTCancellableAsyncTask : @WorkerThread override fun doInBackgroundMT(vararg params: Params?): Result? { - if (isCancelled) { - return null - } + if (isCancelledMT) return null return doInBackgroundNotCancelledMT(*params) } + open val isCancelledMT: Boolean get() = isCancelled + @WorkerThread protected abstract fun doInBackgroundNotCancelledMT(vararg params: Params?): Result? @@ -24,9 +24,7 @@ abstract class MTCancellableAsyncTask : @MainThread override fun onProgressUpdate(vararg values: Progress?) { super.onProgressUpdate(*values) - if (isCancelled) { - return - } + if (isCancelledMT) return onProgressUpdateNotCancelledMT(*values) } @@ -42,9 +40,7 @@ abstract class MTCancellableAsyncTask : @MainThread override fun onPostExecute(result: Result?) { super.onPostExecute(result) - if (isCancelled) { - return - } + if (isCancelledMT) return onPostExecuteNotCancelledMT(result) } @@ -55,4 +51,4 @@ abstract class MTCancellableAsyncTask : ) { // not mandatory } -} \ No newline at end of file +} From f9521b6ee2f16e0acae20b298791dbae0b1ed9f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathieu=20M=C3=A9a?= Date: Fri, 19 Jun 2026 16:04:54 -0400 Subject: [PATCH 7/7] wip --- .../android/commons/provider/gtfs/GTFSRDSProviderExt.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/mtransit/android/commons/provider/gtfs/GTFSRDSProviderExt.kt b/src/main/java/org/mtransit/android/commons/provider/gtfs/GTFSRDSProviderExt.kt index 9655ae26..4f46f343 100644 --- a/src/main/java/org/mtransit/android/commons/provider/gtfs/GTFSRDSProviderExt.kt +++ b/src/main/java/org/mtransit/android/commons/provider/gtfs/GTFSRDSProviderExt.kt @@ -37,7 +37,7 @@ fun Context.getRDS( append(SqlUtils.getWhereEquals(GTFSProviderContract.RouteDirectionStopColumns.T_DIRECTION_K_ID, it)) } } - ) + ).apply { cacheOnly = true } ).toString(), null, SqlUtils.getSortOrderAscending(GTFSProviderContract.RouteDirectionStopColumns.T_DIRECTION_STOPS_K_STOP_SEQUENCE)