From 6684d3324458cc80d81a0534f6e59f15b1f5b3ae Mon Sep 17 00:00:00 2001 From: Shobhit Agarwal Date: Sat, 10 Aug 2024 21:09:52 +0530 Subject: [PATCH 1/2] Prevent overlapping of info card and location FAB --- .../common/AbstractMapFragmentWithControls.kt | 41 +++-- .../CaptureLocationTaskMapFragment.kt | 2 +- ground/src/main/res/layout/map_task_frag.xml | 148 ++++++++++++++---- ground/src/main/res/values/strings.xml | 5 +- 4 files changed, 150 insertions(+), 46 deletions(-) diff --git a/ground/src/main/java/com/google/android/ground/ui/common/AbstractMapFragmentWithControls.kt b/ground/src/main/java/com/google/android/ground/ui/common/AbstractMapFragmentWithControls.kt index 9efd4fccb9..88a63fef77 100644 --- a/ground/src/main/java/com/google/android/ground/ui/common/AbstractMapFragmentWithControls.kt +++ b/ground/src/main/java/com/google/android/ground/ui/common/AbstractMapFragmentWithControls.kt @@ -29,6 +29,8 @@ import com.google.android.ground.model.submission.CaptureLocationTaskData.Compan import com.google.android.ground.ui.map.CameraPosition import com.google.android.ground.ui.map.MapFragment import com.google.android.ground.util.toDmsFormat +import java.math.RoundingMode +import java.text.DecimalFormat import kotlinx.coroutines.launch import org.jetbrains.annotations.MustBeInvokedByOverriders @@ -53,8 +55,14 @@ abstract class AbstractMapFragmentWithControls : AbstractMapContainerFragment() viewLifecycleOwner.lifecycleScope.launch { repeatOnLifecycle(Lifecycle.State.STARTED) { getMapViewModel().location.collect { - val locationText = it?.toCaptureLocationResult()?.getDetailsText() - updateLocationInfoCard(R.string.current_location, locationText) + val taskData = it?.toCaptureLocationResult() + val locationText = taskData?.location?.coordinates?.toDmsFormat() + + val df = DecimalFormat("#.##") + df.roundingMode = RoundingMode.DOWN + val accuracyText = taskData?.accuracy?.let { value -> df.format(value) + "m" } ?: "?" + + updateLocationInfoCard(R.string.current_location, locationText, accuracyText) } } } @@ -68,15 +76,28 @@ abstract class AbstractMapFragmentWithControls : AbstractMapContainerFragment() return binding.root } - private fun updateLocationInfoCard(@StringRes title: Int, locationText: String?) { - if (locationText.isNullOrEmpty()) { - binding.infoCard.visibility = View.GONE - } else { - binding.cardTitle.setText(title) - binding.cardValue.text = locationText - binding.infoCard.visibility = View.VISIBLE + private fun updateLocationInfoCard( + @StringRes title: Int, + locationText: String?, + accuracyText: String? = null, + ) = + with(binding) { + if (locationText.isNullOrEmpty()) { + infoCard.visibility = View.GONE + } else { + infoCard.visibility = View.VISIBLE + currentLocationTitle.text = getString(title) + currentLocationValue.text = locationText + } + + if (accuracyText.isNullOrEmpty()) { + accuracy.visibility = View.GONE + } else { + accuracy.visibility = View.VISIBLE + accuracyTitle.setText(R.string.accuracy) + accuracyValue.text = accuracyText + } } - } @MustBeInvokedByOverriders protected open fun onMapCameraMoved(position: CameraPosition) { diff --git a/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/location/CaptureLocationTaskMapFragment.kt b/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/location/CaptureLocationTaskMapFragment.kt index 08438b609c..62b5668b3f 100644 --- a/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/location/CaptureLocationTaskMapFragment.kt +++ b/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/location/CaptureLocationTaskMapFragment.kt @@ -52,7 +52,7 @@ class CaptureLocationTaskMapFragment(private val viewModel: CaptureLocationTaskV } override fun onMapReady(map: MapFragment) { - binding.basemap.locationLockBtn.isClickable = false + binding.locationLockBtn.isClickable = false viewLifecycleOwner.lifecycleScope.launch { viewModel.onMapReady(mapViewModel) } } diff --git a/ground/src/main/res/layout/map_task_frag.xml b/ground/src/main/res/layout/map_task_frag.xml index 34823c5d80..af47fc817e 100644 --- a/ground/src/main/res/layout/map_task_frag.xml +++ b/ground/src/main/res/layout/map_task_frag.xml @@ -29,15 +29,21 @@ type="com.google.android.ground.ui.common.BaseMapViewModel" /> - + android:layout_height="match_parent" + android:fitsSystemWindows="true" + tools:background="?attr/colorOnSurfaceVariant"> + + - + android:src="@drawable/ic_plus_sign" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> + + + android:layout_marginStart="20dp" + android:layout_marginBottom="20dp" + app:cardCornerRadius="8dp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toStartOf="@id/location_lock_btn" + app:layout_constraintStart_toStartOf="parent"> - - + android:orientation="horizontal" + android:padding="8dp"> + + + + + + + + + + + - + + + + + + + diff --git a/ground/src/main/res/values/strings.xml b/ground/src/main/res/values/strings.xml index 6bf3f2584e..4af699890f 100644 --- a/ground/src/main/res/values/strings.xml +++ b/ground/src/main/res/values/strings.xml @@ -88,7 +88,7 @@ New data collection site Add new site and submit related data Drag your map until the center pin is on the desired location - Current location + Current location: Loading… Can’t collect data as user is a VIEWER Offline map imagery @@ -128,7 +128,7 @@ Initializing… Move the map and tap “Add point” to add points around the desired area. Close - Map location + Map location: Unsynced data If you sign out, any unsynced data will be discarded Zoom in to start collecting data @@ -172,4 +172,5 @@ Send feedback Report technical issues or suggest new locationsOfInterest Not yet implemented + Accuracy: From 005aa5a6fa794331bb1384c941600a21295873a2 Mon Sep 17 00:00:00 2001 From: Shobhit Agarwal Date: Sat, 10 Aug 2024 21:19:06 +0530 Subject: [PATCH 2/2] Update test --- .../ground/ui/datacollection/tasks/BaseTaskFragmentTest.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ground/src/test/java/com/google/android/ground/ui/datacollection/tasks/BaseTaskFragmentTest.kt b/ground/src/test/java/com/google/android/ground/ui/datacollection/tasks/BaseTaskFragmentTest.kt index eb4135ddba..e1daa6f4af 100644 --- a/ground/src/test/java/com/google/android/ground/ui/datacollection/tasks/BaseTaskFragmentTest.kt +++ b/ground/src/test/java/com/google/android/ground/ui/datacollection/tasks/BaseTaskFragmentTest.kt @@ -66,8 +66,8 @@ abstract class BaseTaskFragmentTest, VM : AbstractT protected fun infoCardShown(title: String, value: String) { onView(withId(R.id.infoCard)).check(matches(isDisplayed())) - onView(withId(R.id.card_title)).check(matches(withText(title))) - onView(withId(R.id.card_value)).check(matches(withText(value))) + onView(withId(R.id.current_location_title)).check(matches(withText(title))) + onView(withId(R.id.current_location_value)).check(matches(withText(value))) } protected suspend fun hasValue(taskData: TaskData?) {