From 683d91e59b0e5116442165025824f8aa4820edcc Mon Sep 17 00:00:00 2001 From: JSunde Date: Mon, 2 Oct 2023 16:34:48 +0000 Subject: [PATCH 1/3] Show features on other map views --- .../ui/datacollection/tasks/point/DropAPinMapFragment.kt | 8 ++++++++ .../tasks/polygon/PolygonDrawingMapFragment.kt | 8 ++++++++ .../offlineareas/selector/OfflineAreaSelectorFragment.kt | 9 +++++++++ 3 files changed, 25 insertions(+) diff --git a/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/point/DropAPinMapFragment.kt b/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/point/DropAPinMapFragment.kt index 51f0cbeaeb..6ad9644e39 100644 --- a/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/point/DropAPinMapFragment.kt +++ b/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/point/DropAPinMapFragment.kt @@ -30,6 +30,7 @@ import com.google.android.ground.ui.common.AbstractMapContainerFragment import com.google.android.ground.ui.common.BaseMapViewModel import com.google.android.ground.ui.datacollection.components.TaskHeaderPopupView import com.google.android.ground.ui.datacollection.tasks.point.LatLngConverter.processCoordinates +import com.google.android.ground.ui.home.mapcontainer.HomeScreenMapContainerViewModel import com.google.android.ground.ui.map.CameraPosition import com.google.android.ground.ui.map.MapFragment import dagger.hilt.android.AndroidEntryPoint @@ -41,9 +42,11 @@ class DropAPinMapFragment(private val viewModel: DropAPinTaskViewModel) : private lateinit var binding: MapTaskFragBinding private lateinit var mapViewModel: BaseMapViewModel + private lateinit var mapContainerViewModel: HomeScreenMapContainerViewModel override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + mapContainerViewModel = getViewModel(HomeScreenMapContainerViewModel::class.java) mapViewModel = getViewModel(BaseMapViewModel::class.java) } @@ -106,6 +109,11 @@ class DropAPinMapFragment(private val viewModel: DropAPinTaskViewModel) : } override fun onMapReady(map: MapFragment) { + // Observe events emitted by the ViewModel. + viewLifecycleOwner.lifecycleScope.launch { + mapContainerViewModel.mapLoiFeatures.collect { map.renderFeatures(it) } + } + viewModel.features.observe(this) { map.renderFeatures(it) } } diff --git a/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/polygon/PolygonDrawingMapFragment.kt b/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/polygon/PolygonDrawingMapFragment.kt index 22b8fbd7c1..1b7423c890 100644 --- a/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/polygon/PolygonDrawingMapFragment.kt +++ b/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/polygon/PolygonDrawingMapFragment.kt @@ -26,6 +26,7 @@ import com.google.android.ground.R import com.google.android.ground.databinding.MapTaskFragBinding import com.google.android.ground.ui.common.AbstractMapContainerFragment import com.google.android.ground.ui.common.BaseMapViewModel +import com.google.android.ground.ui.home.mapcontainer.HomeScreenMapContainerViewModel import com.google.android.ground.ui.map.CameraPosition import com.google.android.ground.ui.map.Feature import com.google.android.ground.ui.map.MapFragment @@ -38,9 +39,11 @@ class PolygonDrawingMapFragment(private val viewModel: PolygonDrawingViewModel) private lateinit var binding: MapTaskFragBinding private lateinit var mapViewModel: BaseMapViewModel + private lateinit var mapContainerViewModel: HomeScreenMapContainerViewModel override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + mapContainerViewModel = getViewModel(HomeScreenMapContainerViewModel::class.java) mapViewModel = getViewModel(BaseMapViewModel::class.java) } @@ -80,6 +83,11 @@ class PolygonDrawingMapFragment(private val viewModel: PolygonDrawingViewModel) } override fun onMapReady(map: MapFragment) { + // Observe events emitted by the ViewModel. + viewLifecycleOwner.lifecycleScope.launch { + mapContainerViewModel.mapLoiFeatures.collect { map.renderFeatures(it) } + } + viewLifecycleOwner.lifecycleScope.launch { viewModel.featureValue.collect { feature: Feature? -> map.renderFeatures(if (feature == null) setOf() else setOf(feature)) diff --git a/ground/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorFragment.kt b/ground/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorFragment.kt index c84a4def9c..8f911793a0 100644 --- a/ground/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorFragment.kt +++ b/ground/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorFragment.kt @@ -20,12 +20,15 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.lifecycle.lifecycleScope import com.google.android.ground.databinding.OfflineAreaSelectorFragBinding import com.google.android.ground.ui.common.AbstractMapContainerFragment import com.google.android.ground.ui.common.BaseMapViewModel import com.google.android.ground.ui.common.EphemeralPopups +import com.google.android.ground.ui.home.mapcontainer.HomeScreenMapContainerViewModel import com.google.android.ground.ui.map.MapFragment import dagger.hilt.android.AndroidEntryPoint +import kotlinx.coroutines.launch import javax.inject.Inject /** Map UI used to select areas for download and viewing offline. */ @@ -35,11 +38,13 @@ class OfflineAreaSelectorFragment : Hilt_OfflineAreaSelectorFragment() { @Inject lateinit var popups: EphemeralPopups private lateinit var viewModel: OfflineAreaSelectorViewModel + private lateinit var mapContainerViewModel: HomeScreenMapContainerViewModel private var downloadProgressDialogFragment = DownloadProgressDialogFragment() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + mapContainerViewModel = getViewModel(HomeScreenMapContainerViewModel::class.java) viewModel = getViewModel(OfflineAreaSelectorViewModel::class.java) viewModel.isDownloadProgressVisible.observe(this) { downloadProgressDialogFragment.setVisibility(childFragmentManager, it) @@ -59,6 +64,10 @@ class OfflineAreaSelectorFragment : Hilt_OfflineAreaSelectorFragment() { } override fun onMapReady(map: MapFragment) { + // Observe events emitted by the ViewModel. + viewLifecycleOwner.lifecycleScope.launch { + mapContainerViewModel.mapLoiFeatures.collect { map.renderFeatures(it) } + } viewModel.remoteTileSources.forEach { map.addTileOverlay(it) } } From 4c5d3857c085471db8e4a694f068c425344b2037 Mon Sep 17 00:00:00 2001 From: JSunde Date: Mon, 2 Oct 2023 19:18:59 +0000 Subject: [PATCH 2/3] Add missing imports --- .../ground/ui/datacollection/tasks/point/DropAPinMapFragment.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/point/DropAPinMapFragment.kt b/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/point/DropAPinMapFragment.kt index 1f5c9f3b04..cf4fee42ad 100644 --- a/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/point/DropAPinMapFragment.kt +++ b/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/point/DropAPinMapFragment.kt @@ -19,6 +19,7 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.lifecycle.lifecycleScope import com.google.android.ground.R import com.google.android.ground.ui.common.AbstractMapFragmentWithControls import com.google.android.ground.ui.common.BaseMapViewModel @@ -27,6 +28,7 @@ import com.google.android.ground.ui.home.mapcontainer.HomeScreenMapContainerView import com.google.android.ground.ui.map.CameraPosition import com.google.android.ground.ui.map.MapFragment import dagger.hilt.android.AndroidEntryPoint +import kotlinx.coroutines.launch @AndroidEntryPoint(AbstractMapFragmentWithControls::class) class DropAPinMapFragment(private val viewModel: DropAPinTaskViewModel) : From ca48f02572643dde42207d1d20215903d17a3d05 Mon Sep 17 00:00:00 2001 From: JSunde Date: Mon, 2 Oct 2023 20:28:29 +0000 Subject: [PATCH 3/3] Format OfflineAreaSelectorFragment --- .../ui/offlineareas/selector/OfflineAreaSelectorFragment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ground/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorFragment.kt b/ground/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorFragment.kt index 8f911793a0..662ee1db0e 100644 --- a/ground/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorFragment.kt +++ b/ground/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorFragment.kt @@ -28,8 +28,8 @@ import com.google.android.ground.ui.common.EphemeralPopups import com.google.android.ground.ui.home.mapcontainer.HomeScreenMapContainerViewModel import com.google.android.ground.ui.map.MapFragment import dagger.hilt.android.AndroidEntryPoint -import kotlinx.coroutines.launch import javax.inject.Inject +import kotlinx.coroutines.launch /** Map UI used to select areas for download and viewing offline. */ @AndroidEntryPoint(AbstractMapContainerFragment::class)