diff --git a/app/src/main/java/net/vonforst/evmap/fragment/MapFragment.kt b/app/src/main/java/net/vonforst/evmap/fragment/MapFragment.kt index 34666adab..609ff29e3 100644 --- a/app/src/main/java/net/vonforst/evmap/fragment/MapFragment.kt +++ b/app/src/main/java/net/vonforst/evmap/fragment/MapFragment.kt @@ -1332,6 +1332,12 @@ class MapFragment : Fragment(), OnMapReadyCallback, MapsActivity.FragmentCallbac ).show() true } + + val reloadItem = menu.findItem(R.id.menu_reload) + reloadItem.setOnMenuItemClickListener { + vm.reloadChargepoints(true) + true + } } 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 9c9e6028c..3b1c69976 100644 --- a/app/src/main/java/net/vonforst/evmap/storage/ChargeLocationsDao.kt +++ b/app/src/main/java/net/vonforst/evmap/storage/ChargeLocationsDao.kt @@ -142,7 +142,8 @@ class ChargeLocationsRepository( fun getChargepoints( bounds: LatLngBounds, zoom: Float, - filters: FilterValues? + filters: FilterValues?, + overrideCache: Boolean = false ): LiveData>> { val api = api.value!! @@ -200,7 +201,11 @@ class ChargeLocationsRepository( } } } - return CacheLiveData(dbResult, apiResult, savedRegionResult).distinctUntilChanged() + return if (overrideCache) { + apiResult + } else { + CacheLiveData(dbResult, apiResult, savedRegionResult).distinctUntilChanged() + } } fun getChargepointsRadius( diff --git a/app/src/main/java/net/vonforst/evmap/viewmodel/MapViewModel.kt b/app/src/main/java/net/vonforst/evmap/viewmodel/MapViewModel.kt index e7b098cc5..b65c26489 100644 --- a/app/src/main/java/net/vonforst/evmap/viewmodel/MapViewModel.kt +++ b/app/src/main/java/net/vonforst/evmap/viewmodel/MapViewModel.kt @@ -480,10 +480,10 @@ class MapViewModel(application: Application, private val state: SavedStateHandle } } - fun reloadChargepoints() { + fun reloadChargepoints(overrideCache: Boolean = false) { val pos = mapPosition.value ?: return val filters = filtersWithValue.value ?: return - chargepointLoader(pos to filters) + chargepointLoader(Triple(pos, filters, overrideCache)) } private val miniMarkerThreshold = 13f @@ -515,11 +515,10 @@ class MapViewModel(application: Application, private val state: SavedStateHandle throttleLatest( 500L, viewModelScope - ) { data: Pair -> + ) { data: Triple -> chargepoints.value = Resource.loading(chargepoints.value?.data) - val mapPosition = data.first - val filters = data.second + val (mapPosition, filters, overrideCache) = data val bounds = extendBounds(mapPosition.bounds) if (filterStatus.value == FILTERS_FAVORITES) { @@ -542,7 +541,7 @@ class MapViewModel(application: Application, private val state: SavedStateHandle return@throttleLatest } - val result = repo.getChargepoints(bounds, mapPosition.zoom, filters) + val result = repo.getChargepoints(bounds, mapPosition.zoom, filters, overrideCache) chargepointsInternal?.let { chargepoints.removeSource(it) } chargepointsInternal = result chargepoints.addSource(result) { diff --git a/app/src/main/res/menu/map.xml b/app/src/main/res/menu/map.xml index 3de50203c..de9175ac3 100644 --- a/app/src/main/res/menu/map.xml +++ b/app/src/main/res/menu/map.xml @@ -8,4 +8,8 @@ android:icon="@drawable/ic_filter" app:showAsAction="ifRoom" app:actionLayout="@layout/action_filter" /> + + \ No newline at end of file diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index c2cc48887..d2f619ac2 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -359,4 +359,5 @@ Lade… Seite %d (%d/%d) + Neu laden \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index eeb42c562..a34cdef88 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -359,4 +359,5 @@ Loading… Page %d (%d/%d) + Reload \ No newline at end of file