Skip to content

Commit

Permalink
add menu item to manually reload map content
Browse files Browse the repository at this point in the history
  • Loading branch information
johan12345 committed Jul 1, 2023
1 parent 687ef2e commit 024e3ce
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 8 deletions.
6 changes: 6 additions & 0 deletions app/src/main/java/net/vonforst/evmap/fragment/MapFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ class ChargeLocationsRepository(
fun getChargepoints(
bounds: LatLngBounds,
zoom: Float,
filters: FilterValues?
filters: FilterValues?,
overrideCache: Boolean = false
): LiveData<Resource<List<ChargepointListItem>>> {
val api = api.value!!

Expand Down Expand Up @@ -200,7 +201,11 @@ class ChargeLocationsRepository(
}
}
}
return CacheLiveData(dbResult, apiResult, savedRegionResult).distinctUntilChanged()
return if (overrideCache) {
apiResult
} else {
CacheLiveData(dbResult, apiResult, savedRegionResult).distinctUntilChanged()
}
}

fun getChargepointsRadius(
Expand Down
11 changes: 5 additions & 6 deletions app/src/main/java/net/vonforst/evmap/viewmodel/MapViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -515,11 +515,10 @@ class MapViewModel(application: Application, private val state: SavedStateHandle
throttleLatest(
500L,
viewModelScope
) { data: Pair<MapPosition, FilterValues> ->
) { data: Triple<MapPosition, FilterValues, Boolean> ->
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) {
Expand All @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/menu/map.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@
android:icon="@drawable/ic_filter"
app:showAsAction="ifRoom"
app:actionLayout="@layout/action_filter" />

<item
android:id="@+id/menu_reload"
android:title="@string/reload" />
</menu>
1 change: 1 addition & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -359,4 +359,5 @@
<string name="loading">Lade…</string>
<string name="auto_multipage_goto">Seite %d</string>
<string name="auto_multipage">(%d/%d)</string>
<string name="reload">Neu laden</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -359,4 +359,5 @@
<string name="loading">Loading…</string>
<string name="auto_multipage_goto">Page %d</string>
<string name="auto_multipage">(%d/%d)</string>
<string name="reload">Reload</string>
</resources>

0 comments on commit 024e3ce

Please sign in to comment.