diff --git a/app/src/main/java/de/westnordost/streetcomplete/screens/main/map/EditHistoryPinsManager.kt b/app/src/main/java/de/westnordost/streetcomplete/screens/main/map/EditHistoryPinsManager.kt index 4ae023b71f..a91d02a273 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/screens/main/map/EditHistoryPinsManager.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/screens/main/map/EditHistoryPinsManager.kt @@ -62,8 +62,8 @@ class EditHistoryPinsManager( } private fun stop() { - pinsMapComponent.clear() viewLifecycleScope.coroutineContext.cancelChildren() + viewLifecycleScope.launch { pinsMapComponent.clear() } editHistorySource.removeListener(editHistoryListener) } diff --git a/app/src/main/java/de/westnordost/streetcomplete/screens/main/map/QuestPinsManager.kt b/app/src/main/java/de/westnordost/streetcomplete/screens/main/map/QuestPinsManager.kt index 2cce67c4d2..8f599ef6d1 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/screens/main/map/QuestPinsManager.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/screens/main/map/QuestPinsManager.kt @@ -57,11 +57,7 @@ class QuestPinsManager( private val visibleQuestsListener = object : VisibleQuestsSource.Listener { override fun onUpdatedVisibleQuests(added: Collection, removed: Collection) { - synchronized(questsInView) { - added.forEach { questsInView[it.key] = createQuestPins(it) } - removed.forEach { questsInView.remove(it) } - } - updatePins() + viewLifecycleScope.launch { updateQuestPins(added, removed) } } override fun onVisibleQuestsInvalidated() { @@ -92,8 +88,8 @@ class QuestPinsManager( } private fun stop() { - clear() viewLifecycleScope.coroutineContext.cancelChildren() + clear() visibleQuestsSource.removeListener(visibleQuestsListener) questTypeOrderSource.removeListener(questTypeOrderListener) } @@ -106,7 +102,7 @@ class QuestPinsManager( private fun clear() { synchronized(questsInView) { questsInView.clear() } lastDisplayedRect = null - pinsMapComponent.clear() + viewLifecycleScope.launch { pinsMapComponent.clear() } } fun getQuestKey(properties: Map): QuestKey? = @@ -130,16 +126,25 @@ class QuestPinsManager( val bbox = tilesRect.asBoundingBox(TILES_ZOOM) viewLifecycleScope.launch { val quests = withContext(Dispatchers.IO) { visibleQuestsSource.getAllVisible(bbox) } - synchronized(questsInView) { - questsInView.clear() - quests.forEach { questsInView[it.key] = createQuestPins(it) } - } - updatePins() + setQuestPins(quests) } } - private fun updatePins() { - val pins = synchronized(questsInView) { questsInView.values.flatten() } + private fun setQuestPins(quests: List) { + val pins = synchronized(questsInView) { + questsInView.clear() + quests.forEach { questsInView[it.key] = createQuestPins(it) } + questsInView.values.flatten() + } + pinsMapComponent.set(pins) + } + + private fun updateQuestPins(added: Collection, removed: Collection) { + val pins = synchronized(questsInView) { + added.forEach { questsInView[it.key] = createQuestPins(it) } + removed.forEach { questsInView.remove(it) } + questsInView.values.flatten() + } pinsMapComponent.set(pins) } diff --git a/app/src/main/java/de/westnordost/streetcomplete/screens/main/map/StyleableOverlayManager.kt b/app/src/main/java/de/westnordost/streetcomplete/screens/main/map/StyleableOverlayManager.kt index 4e342422f6..b6c825f6e2 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/screens/main/map/StyleableOverlayManager.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/screens/main/map/StyleableOverlayManager.kt @@ -54,7 +54,7 @@ class StyleableOverlayManager( private val mapDataListener = object : MapDataWithEditsSource.Listener { override fun onUpdated(updated: MapDataWithGeometry, deleted: Collection) { - updateStyledElements(updated, deleted) + viewLifecycleScope.launch { updateStyledElements(updated, deleted) } } override fun onReplacedForBBox(bbox: BoundingBox, mapDataWithGeometry: MapDataWithGeometry) { @@ -90,17 +90,11 @@ class StyleableOverlayManager( } private fun hide() { - clear() viewLifecycleScope.coroutineContext.cancelChildren() + clear() mapDataSource.removeListener(mapDataListener) } - private fun clear() { - synchronized(mapDataInView) { mapDataInView.clear() } - lastDisplayedRect = null - mapComponent.clear() - } - fun onNewScreenPosition() { if (overlay == null) return val zoom = ctrl.cameraPosition.zoom @@ -123,6 +117,12 @@ class StyleableOverlayManager( } } + private fun clear() { + synchronized(mapDataInView) { mapDataInView.clear() } + lastDisplayedRect = null + viewLifecycleScope.launch { mapComponent.clear() } + } + private fun setStyledElements(mapData: MapDataWithGeometry) { val layer = overlay ?: return synchronized(mapDataInView) {