@@ -57,6 +57,7 @@ import org.nitri.opentopo.util.MapOrientation
5757import org.nitri.opentopo.util.OrientationSensor
5858import org.nitri.opentopo.util.Utils
5959import org.nitri.opentopo.view.AboutDialog
60+ import org.nitri.opentopo.view.MarkerEditorDialog
6061import org.nitri.opentopo.viewmodel.LocationViewModel
6162import org.nitri.opentopo.viewmodel.MarkerViewModel
6263import org.nitri.ors.OrsClient
@@ -319,7 +320,7 @@ class MapFragment : Fragment(), LocationListener, PopupMenu.OnMenuItemClickListe
319320 locationOverlay?.isOptionsMenuEnabled = true
320321 compassOverlay?.enableCompass()
321322 mapView.visibility = View .VISIBLE
322- overlayHelper = OverlayHelper (hostActivity, mapView)
323+ overlayHelper = OverlayHelper (hostActivity, mapView, parentFragmentManager )
323324 setTilesOverlay()
324325 }
325326
@@ -328,6 +329,30 @@ class MapFragment : Fragment(), LocationListener, PopupMenu.OnMenuItemClickListe
328329 override fun onViewCreated (view : View , savedInstanceState : Bundle ? ) {
329330 super .onViewCreated(view, savedInstanceState)
330331
332+ parentFragmentManager.setFragmentResultListener(
333+ MarkerEditorDialog .RESULT_REQUEST_KEY ,
334+ viewLifecycleOwner
335+ ) { _, result ->
336+ val markerId = result.getInt(MarkerEditorDialog .RESULT_MARKER_ID )
337+ when (result.getString(MarkerEditorDialog .RESULT_ACTION )) {
338+ MarkerEditorDialog .RESULT_ACTION_UPDATE -> {
339+ val currentMarker = markerViewModel.markers.value
340+ ?.firstOrNull { it.id == markerId }
341+ ? : return @setFragmentResultListener
342+
343+ val updated = currentMarker.copy(
344+ name = result.getString(MarkerEditorDialog .RESULT_NAME ).orEmpty(),
345+ description = result.getString(MarkerEditorDialog .RESULT_DESCRIPTION ).orEmpty()
346+ )
347+ markerViewModel.updateMarker(updated)
348+ }
349+
350+ MarkerEditorDialog .RESULT_ACTION_DELETE -> {
351+ markerViewModel.removeMarker(markerId)
352+ }
353+ }
354+ }
355+
331356 viewLifecycleOwner.lifecycleScope.launch {
332357 if (! mapViewInitialized) {
333358 initializeMapView()
0 commit comments