fix highlighted charger after moving map

This commit is contained in:
Johan von Forstner
2020-05-19 20:50:54 +02:00
parent f4b174efe1
commit 084084c26c
2 changed files with 12 additions and 10 deletions

View File

@@ -496,15 +496,14 @@ class MapFragment : Fragment(), OnMapReadyCallback, MapsActivity.FragmentCallbac
// remove markers that disappeared
markers.entries.toList().forEach {
if (!chargepointIds.contains(it.value.id)) {
val tint = getMarkerTint(it.value)
if (it.key.isVisible) {
animator.animateMarkerDisappear(it.key, tint)
val tint = getMarkerTint(it.value)
val highlight = it.value == vm.chargerSparse.value
animator.animateMarkerDisappear(it.key, tint, highlight)
} else {
it.key.remove()
}
markers.remove(it.key)
} else {
true
}
}
// add new markers
@@ -512,14 +511,15 @@ class MapFragment : Fragment(), OnMapReadyCallback, MapsActivity.FragmentCallbac
!markers.containsValue(it)
}.forEach { charger ->
val tint = getMarkerTint(charger)
val highlight = charger == vm.chargerSparse.value
val marker = map.addMarker(
MarkerOptions()
.position(LatLng(charger.coordinates.lat, charger.coordinates.lng))
.icon(
chargerIconGenerator.getBitmapDescriptor(tint)
chargerIconGenerator.getBitmapDescriptor(tint, highlight = highlight)
)
)
animator.animateMarkerAppear(marker, tint)
animator.animateMarkerAppear(marker, tint, highlight)
markers[marker] = charger
}
clusterMarkers = clusters.map { cluster ->

View File

@@ -23,7 +23,8 @@ class MarkerAnimator(val gen: ChargerIconGenerator) {
fun animateMarkerAppear(
marker: Marker,
tint: Int
tint: Int,
highlight: Boolean
) {
animatingMarkers[marker]?.cancel()
animatingMarkers.remove(marker)
@@ -39,7 +40,7 @@ class MarkerAnimator(val gen: ChargerIconGenerator) {
}
val scale = animationState.animatedValue as Int
marker.setIcon(
gen.getBitmapDescriptor(tint, scale = scale)
gen.getBitmapDescriptor(tint, scale = scale, highlight = highlight)
)
}
addListener(onEnd = {
@@ -52,7 +53,8 @@ class MarkerAnimator(val gen: ChargerIconGenerator) {
fun animateMarkerDisappear(
marker: Marker,
tint: Int
tint: Int,
highlight: Boolean
) {
animatingMarkers[marker]?.cancel()
animatingMarkers.remove(marker)
@@ -68,7 +70,7 @@ class MarkerAnimator(val gen: ChargerIconGenerator) {
}
val scale = animationState.animatedValue as Int
marker.setIcon(
gen.getBitmapDescriptor(tint, scale = scale)
gen.getBitmapDescriptor(tint, scale = scale, highlight = highlight)
)
}
addListener(onEnd = {