Skip to content

Commit a76c878

Browse files
committed
BUG: service update provider > cached list need to be mutable
1 parent 3f173ef commit a76c878

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

src/main/java/org/mtransit/android/commons/provider/StmInfoSubwayProvider.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,11 @@ public void cacheServiceUpdates(@NonNull List<ServiceUpdate> newServiceUpdates)
189189
@Nullable
190190
@Override
191191
public List<ServiceUpdate> getCachedServiceUpdates(@NonNull Filter serviceUpdateFilter) {
192-
if ((serviceUpdateFilter.getPoi() instanceof RouteDirectionStop)) {
192+
if (serviceUpdateFilter.getPoi() instanceof RouteDirectionStop) {
193193
return getCachedServiceUpdates((RouteDirectionStop) serviceUpdateFilter.getPoi());
194-
} else if ((serviceUpdateFilter.getRouteDirection() != null)) {
194+
} else if (serviceUpdateFilter.getRouteDirection() != null) {
195195
return getCachedServiceUpdates(serviceUpdateFilter.getRouteDirection());
196-
} else if ((serviceUpdateFilter.getRoute() != null)) {
196+
} else if (serviceUpdateFilter.getRoute() != null) {
197197
return getCachedServiceUpdates(serviceUpdateFilter.getRoute());
198198
} else {
199199
MTLog.w(this, "getCachedServiceUpdates() > no service update (poi null or not RDS or no route)");
@@ -314,11 +314,11 @@ private int deleteAllAgencyServiceUpdateData() {
314314
@Nullable
315315
@Override
316316
public List<ServiceUpdate> getNewServiceUpdates(@NonNull Filter serviceUpdateFilter) {
317-
if ((serviceUpdateFilter.getPoi() instanceof RouteDirectionStop)) {
317+
if (serviceUpdateFilter.getPoi() instanceof RouteDirectionStop) {
318318
return getNewServiceUpdates((RouteDirectionStop) serviceUpdateFilter.getPoi(), serviceUpdateFilter.isInFocusOrDefault());
319-
} else if ((serviceUpdateFilter.getRouteDirection() != null)) {
319+
} else if (serviceUpdateFilter.getRouteDirection() != null) {
320320
return getNewServiceUpdates(serviceUpdateFilter.getRouteDirection(), serviceUpdateFilter.isInFocusOrDefault());
321-
} else if ((serviceUpdateFilter.getRoute() != null)) {
321+
} else if (serviceUpdateFilter.getRoute() != null) {
322322
return getNewServiceUpdates(serviceUpdateFilter.getRoute(), serviceUpdateFilter.isInFocusOrDefault());
323323
} else {
324324
MTLog.w(this, "getNewServiceUpdates() > no service update (poi null or not RDS or no route)");

src/main/java/org/mtransit/android/commons/provider/serviceupdate/ServiceUpdateProviderExt.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import org.mtransit.android.commons.SqlUtils
77
import org.mtransit.android.commons.data.ServiceUpdate
88
import org.mtransit.commons.FeatureFlags
99

10-
private val LOG_TAG: String = ServiceUpdateProvider::class.java.simpleName
10+
private const val LOG_TAG: String = "ServiceUpdateProviderExt"
1111

1212
@JvmOverloads
1313
fun <P : ServiceUpdateProviderContract> P.getCachedServiceUpdatesS(
@@ -19,7 +19,7 @@ fun <P : ServiceUpdateProviderContract> P.getCachedServiceUpdatesS(
1919
fun <P : ServiceUpdateProviderContract> P.getCachedServiceUpdatesS(
2020
targetUUIDs: Collection<String>,
2121
tripIds: List<String>? = null
22-
): List<ServiceUpdate>? {
22+
): MutableList<ServiceUpdate>? {
2323
return getCachedServiceUpdatesS(
2424
this.contentUri,
2525
buildString {
@@ -45,8 +45,8 @@ fun <P : ServiceUpdateProviderContract> P.getCachedServiceUpdatesS(
4545
private fun <P : ServiceUpdateProviderContract> P.getCachedServiceUpdatesS(
4646
@Suppress("unused") uri: Uri?,
4747
selection: String?,
48-
): List<ServiceUpdate>? =
49-
try {
48+
): MutableList<ServiceUpdate>? {
49+
return try {
5050
SQLiteQueryBuilder()
5151
.apply {
5252
tables = dbTableName
@@ -62,12 +62,13 @@ private fun <P : ServiceUpdateProviderContract> P.getCachedServiceUpdatesS(
6262
} while (cursor.moveToNext())
6363
}
6464
}
65-
}
65+
}.toMutableList() // need to be mutable to call "iterator().remove()"
6666
}
6767
} catch (e: Exception) {
6868
MTLog.w(LOG_TAG, e, "Error!")
6969
null
7070
}
71+
}
7172

7273
private val ServiceUpdateProviderContract.contentUri: Uri
7374
get() = Uri.withAppendedPath(this.authorityUri, ServiceUpdateProviderContract.SERVICE_UPDATE_PATH)

0 commit comments

Comments
 (0)