Skip to content

Commit

Permalink
avoid stutter when moving map away from current location
Browse files Browse the repository at this point in the history
  • Loading branch information
johan12345 committed Aug 11, 2024
1 parent 2af87f4 commit a6373d5
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions app/src/main/java/net/vonforst/evmap/auto/MapScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class MapScreen(ctx: CarContext, val session: EVMapSession) :
private var map: AnyMap? = null
private var markerManager: MarkerManager? = null
private var myLocationEnabled = false
private var myLocationNeedsUpdate = false

private val formatter = ChargerListFormatter(ctx, this)
private val backPressedCallback = object : OnBackPressedCallback(false) {
Expand Down Expand Up @@ -625,18 +626,23 @@ class MapScreen(ctx: CarContext, val session: EVMapSession) :
mapSurfaceCallback.cameraMoveStartedListener = {
if (myLocationEnabled) {
myLocationEnabled = false
invalidate()
myLocationNeedsUpdate = true
}
}

mapSurfaceCallback.cameraIdleListener = {
loadChargers()
if (myLocationNeedsUpdate) {
invalidate()
myLocationNeedsUpdate = false
}
}
loadChargers()
}

private fun enableLocation() {
myLocationEnabled = true
myLocationNeedsUpdate = true
if (location != null) {
val map = map ?: return
mapSurfaceCallback.animateCamera(
Expand All @@ -646,6 +652,5 @@ class MapScreen(ctx: CarContext, val session: EVMapSession) :
)
)
}
invalidate()
}
}

0 comments on commit a6373d5

Please sign in to comment.