Skip to content

Commit

Permalink
remove inject of selectedOverlaySource
Browse files Browse the repository at this point in the history
  • Loading branch information
westnordost committed Apr 4, 2024
1 parent 04658a0 commit b71082a
Showing 1 changed file with 12 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,13 @@ class MainFragment :
// listeners to changes to data:
VisibleQuestsSource.Listener,
MapDataWithEditsSource.Listener,
SelectedOverlaySource.Listener,
// rest
ShowsGeometryMarkers {

private val visibleQuestsSource: VisibleQuestsSource by inject()
private val mapDataWithEditsSource: MapDataWithEditsSource by inject()
private val notesSource: NotesWithEditsSource by inject()
private val locationAvailabilityReceiver: LocationAvailabilityReceiver by inject()
private val selectedOverlaySource: SelectedOverlaySource by inject()
private val featureDictionary: Lazy<FeatureDictionary> by inject(named("FeatureDictionaryLazy"))
private val soundFx: SoundFx by inject()

Expand Down Expand Up @@ -242,8 +240,6 @@ class MainFragment :
binding.mapControls.respectSystemInsets(View::setMargins)
view.respectSystemInsets { windowInsets = it }

updateCreateButtonVisibility()

binding.locationPointerPin.setOnClickListener { onClickLocationPointer() }

binding.compassView.setOnClickListener { onClickCompassButton() }
Expand Down Expand Up @@ -314,6 +310,16 @@ class MainFragment :
}
controlsViewModel.teamModeChanged = false
}
observe(controlsViewModel.selectedOverlay) { overlay ->
val isCreateNodeEnabled = overlay?.isCreateNodeEnabled == true
binding.createButton.isGone = !isCreateNodeEnabled
binding.crosshairView.isGone = !isCreateNodeEnabled

val f = bottomSheetFragment
if (f is IsShowingElement) {
closeBottomSheet()
}
}
}

@UiThread
Expand Down Expand Up @@ -341,7 +347,6 @@ class MainFragment :
super.onStart()
visibleQuestsSource.addListener(this)
mapDataWithEditsSource.addListener(this)
selectedOverlaySource.addListener(this)
locationAvailabilityReceiver.addListener(::updateLocationAvailability)
updateLocationAvailability(requireContext().run { hasLocationPermission && isLocationEnabled })
}
Expand All @@ -353,7 +358,6 @@ class MainFragment :
visibleQuestsSource.removeListener(this)
locationAvailabilityReceiver.removeListener(::updateLocationAvailability)
mapDataWithEditsSource.removeListener(this)
selectedOverlaySource.removeListener(this)
locationManager.removeUpdates()
}

Expand Down Expand Up @@ -575,19 +579,6 @@ class MainFragment :

//region Data Updates - Callbacks for when data changed in the local database

/* ------------------------------ SelectedOverlaySource.Listener -----------------------------*/

override fun onSelectedOverlayChanged() {
viewLifecycleScope.launch {
updateCreateButtonVisibility()

val f = bottomSheetFragment
if (f is IsShowingElement) {
closeBottomSheet()
}
}
}

/* ---------------------------------- VisibleQuestListener ---------------------------------- */

@AnyThread
Expand Down Expand Up @@ -849,12 +840,6 @@ class MainFragment :
showOverlayFormForNewElement()
}

private fun updateCreateButtonVisibility() {
val isCreateNodeEnabled = selectedOverlaySource.selectedOverlay?.isCreateNodeEnabled == true
binding.createButton.isGone = !isCreateNodeEnabled
binding.crosshairView.isGone = !isCreateNodeEnabled
}

private fun updateCreateButtonEnablement(zoom: Float) {
binding.createButton.isEnabled = zoom >= 18f
}
Expand Down Expand Up @@ -1116,7 +1101,7 @@ class MainFragment :

@UiThread
private fun showOverlayFormForNewElement() {
val overlay = selectedOverlaySource.selectedOverlay ?: return
val overlay = controlsViewModel.selectedOverlay.value ?: return
val mapFragment = mapFragment ?: return

val f = overlay.createForm(null) ?: return
Expand All @@ -1134,7 +1119,7 @@ class MainFragment :
@UiThread
private suspend fun showElementDetails(elementKey: ElementKey) {
if (isElementCurrentlyDisplayed(elementKey)) return
val overlay = selectedOverlaySource.selectedOverlay ?: return
val overlay = controlsViewModel.selectedOverlay.value ?: return
val geometry = mapDataWithEditsSource.getGeometry(elementKey.type, elementKey.id) ?: return
val mapFragment = mapFragment ?: return

Expand Down

0 comments on commit b71082a

Please sign in to comment.