diff --git a/app/src/main/java/net/vonforst/evmap/api/ChargepointApi.kt b/app/src/main/java/net/vonforst/evmap/api/ChargepointApi.kt index 2bb06ce8..37c252aa 100644 --- a/app/src/main/java/net/vonforst/evmap/api/ChargepointApi.kt +++ b/app/src/main/java/net/vonforst/evmap/api/ChargepointApi.kt @@ -49,6 +49,8 @@ interface ChargepointApi { fun convertFiltersToSQL(filters: FilterValues, referenceData: ReferenceData): FiltersSQLQuery + fun filteringInSQLRequiresDetails(filters: FilterValues): Boolean + val name: String val id: String diff --git a/app/src/main/java/net/vonforst/evmap/api/goingelectric/GoingElectricApi.kt b/app/src/main/java/net/vonforst/evmap/api/goingelectric/GoingElectricApi.kt index 4aa81829..b7d82f52 100644 --- a/app/src/main/java/net/vonforst/evmap/api/goingelectric/GoingElectricApi.kt +++ b/app/src/main/java/net/vonforst/evmap/api/goingelectric/GoingElectricApi.kt @@ -546,5 +546,14 @@ class GoingElectricApiWrapper( return FiltersSQLQuery(result.toString(), requiresChargepointQuery, requiresChargeCardQuery) } + + override fun filteringInSQLRequiresDetails(filters: FilterValues): Boolean { + val chargecards = filters.getMultipleChoiceValue("chargecards") + return filters.getBooleanValue("freecharging") == true + || filters.getBooleanValue("freeparking") == true + || filters.getBooleanValue("open_247") == true + || filters.getBooleanValue("barrierfree") == true + || (chargecards != null && !chargecards.all) + } } diff --git a/app/src/main/java/net/vonforst/evmap/api/openchargemap/OpenChargeMapApi.kt b/app/src/main/java/net/vonforst/evmap/api/openchargemap/OpenChargeMapApi.kt index 1da1c0f4..f82a251c 100644 --- a/app/src/main/java/net/vonforst/evmap/api/openchargemap/OpenChargeMapApi.kt +++ b/app/src/main/java/net/vonforst/evmap/api/openchargemap/OpenChargeMapApi.kt @@ -379,4 +379,10 @@ class OpenChargeMapApiWrapper( return FiltersSQLQuery(result.toString(), requiresChargepointQuery, false) } + override fun filteringInSQLRequiresDetails(filters: FilterValues): Boolean { + val operators = filters.getMultipleChoiceValue("operators") + return (operators != null && !operators.all) + // TODO: it would be possible to implement this without requiring details if we extended the data structure to also save the operator ID in the DB + } + } \ No newline at end of file diff --git a/app/src/main/java/net/vonforst/evmap/storage/ChargeLocationsDao.kt b/app/src/main/java/net/vonforst/evmap/storage/ChargeLocationsDao.kt index 961e49bd..236d30c6 100644 --- a/app/src/main/java/net/vonforst/evmap/storage/ChargeLocationsDao.kt +++ b/app/src/main/java/net/vonforst/evmap/storage/ChargeLocationsDao.kt @@ -161,6 +161,7 @@ class ChargeLocationsRepository( val filtersSerialized = filters?.filter { it.value != it.filter.defaultValue() }?.takeIf { it.isNotEmpty() } ?.serialize() + val requiresDetail = filters?.let { api.filteringInSQLRequiresDetails(it) } ?: false val savedRegionResult = savedRegionDao.savedRegionCovers( bounds.southwest.latitude, bounds.northeast.latitude, @@ -168,7 +169,8 @@ class ChargeLocationsRepository( bounds.northeast.longitude, api.id, cacheSoftLimitDate(api), - filtersSerialized + filtersSerialized, + requiresDetail ) val useClustering = shouldUseServerSideClustering(zoom) val apiResult = liveData { @@ -224,13 +226,15 @@ class ChargeLocationsRepository( val filtersSerialized = filters?.filter { it.value != it.filter.defaultValue() }?.takeIf { it.isNotEmpty() } ?.serialize() + val requiresDetail = filters?.let { api.filteringInSQLRequiresDetails(it) } ?: false val savedRegionResult = savedRegionDao.savedRegionCoversRadius( location.latitude, location.longitude, radiusMeters * 0.999, // to account for float rounding errors api.id, cacheSoftLimitDate(api), - filtersSerialized + filtersSerialized, + requiresDetail ) val useClustering = shouldUseServerSideClustering(zoom) val apiResult = liveData {