Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent overlapping of info card and location FAB #2629

Merged
merged 2 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
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

Expand All @@ -53,8 +55,14 @@
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)
}
}
}
Expand All @@ -68,15 +76,28 @@
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(

Check warning on line 79 in ground/src/main/java/com/google/android/ground/ui/common/AbstractMapFragmentWithControls.kt

View check run for this annotation

Codecov / codecov/patch

ground/src/main/java/com/google/android/ground/ui/common/AbstractMapFragmentWithControls.kt#L79

Added line #L79 was not covered by tests
@StringRes title: Int,
locationText: String?,
accuracyText: String? = null,

Check warning on line 82 in ground/src/main/java/com/google/android/ground/ui/common/AbstractMapFragmentWithControls.kt

View check run for this annotation

Codecov / codecov/patch

ground/src/main/java/com/google/android/ground/ui/common/AbstractMapFragmentWithControls.kt#L82

Added line #L82 was not covered by tests
) =
with(binding) {
if (locationText.isNullOrEmpty()) {
infoCard.visibility = View.GONE
} else {
infoCard.visibility = View.VISIBLE
currentLocationTitle.text = getString(title)
currentLocationValue.text = locationText

Check warning on line 90 in ground/src/main/java/com/google/android/ground/ui/common/AbstractMapFragmentWithControls.kt

View check run for this annotation

Codecov / codecov/patch

ground/src/main/java/com/google/android/ground/ui/common/AbstractMapFragmentWithControls.kt#L88-L90

Added lines #L88 - L90 were not covered by tests
}

if (accuracyText.isNullOrEmpty()) {
accuracy.visibility = View.GONE

Check warning on line 94 in ground/src/main/java/com/google/android/ground/ui/common/AbstractMapFragmentWithControls.kt

View check run for this annotation

Codecov / codecov/patch

ground/src/main/java/com/google/android/ground/ui/common/AbstractMapFragmentWithControls.kt#L94

Added line #L94 was not covered by tests
} else {
accuracy.visibility = View.VISIBLE
accuracyTitle.setText(R.string.accuracy)
accuracyValue.text = accuracyText
}
}
}

@MustBeInvokedByOverriders
protected open fun onMapCameraMoved(position: CameraPosition) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
}

override fun onMapReady(map: MapFragment) {
binding.basemap.locationLockBtn.isClickable = false
binding.locationLockBtn.isClickable = false

Check warning on line 55 in ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/location/CaptureLocationTaskMapFragment.kt

View check run for this annotation

Codecov / codecov/patch

ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/location/CaptureLocationTaskMapFragment.kt#L55

Added line #L55 was not covered by tests
viewLifecycleOwner.lifecycleScope.launch { viewModel.onMapReady(mapViewModel) }
}

Expand Down
148 changes: 115 additions & 33 deletions ground/src/main/res/layout/map_task_frag.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,21 @@
type="com.google.android.ground.ui.common.BaseMapViewModel" />
</data>

<FrameLayout
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:background="?attr/colorOnSurfaceVariant">

<FrameLayout
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<include
android:id="@+id/basemap"
layout="@layout/basemap_layout"
app:fragment="@{fragment}"
app:viewModel="@{viewModel}" />
<androidx.constraintlayout.utils.widget.ImageFilterView
android:id="@+id/centerMarker"
android:layout_width="wrap_content"
Expand All @@ -46,40 +52,116 @@
android:scaleType="centerInside"
android:scaleX="0.5"
android:scaleY="0.5"
android:src="@drawable/ic_plus_sign" />
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" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/map_type_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|end"
android:onClick="@{() -> fragment.showMapTypeSelectorDialog()}"
android:tint="?attr/colorOutline"
app:backgroundTint="?attr/colorSurface"
app:fabSize="mini"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/map_layers"
app:useCompatPadding="true" />

<com.google.android.material.card.MaterialCardView
android:id="@+id/infoCard"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="bottom|start"
android:layout_margin="20dp"
app:cardCornerRadius="8dp">
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">

<LinearLayout
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:orientation="vertical"
android:paddingStart="20dp"
android:paddingTop="10dp"
android:paddingEnd="20dp"
android:paddingBottom="10dp">
<TextView
android:id="@+id/card_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#5E5E5E"
android:textSize="12sp"
tools:text="Title" />
<TextView
android:id="@+id/card_value"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#424940"
android:textSize="16sp"
tools:text="Value" />
android:orientation="horizontal"
android:padding="8dp">

<LinearLayout
android:id="@+id/current_location"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.75"
android:background="@android:color/white"
android:orientation="vertical">
<TextView
android:id="@+id/current_location_title"
style="@style/TextAppearance.Material3.LabelSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#5E5E5E"
tools:text="Current location:" />
<TextView
android:id="@+id/current_location_value"
style="@style/TextAppearance.Material3.LabelMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#424940"
tools:text="29º58’15” N 114º36’17”W" />
</LinearLayout>

<LinearLayout
android:id="@+id/accuracy"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:background="@android:color/white"
android:orientation="vertical">
<TextView
android:id="@+id/accuracy_title"
style="@style/TextAppearance.Material3.LabelSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#5E5E5E"
tools:text="Accuracy:" />
<TextView
android:id="@+id/accuracy_value"
style="@style/TextAppearance.Material3.LabelMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#424940"
tools:text="3m" />
</LinearLayout>
</LinearLayout>

</com.google.android.material.card.MaterialCardView>
</FrameLayout>

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/location_lock_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:onClick="@{() -> viewModel.onLocationLockClick()}"
app:backgroundTint="?attr/colorSurface"
app:fabSize="normal"
app:imageResource="@{viewModel.getLocationLockIcon()}"
app:layout_constraintBottom_toTopOf="@+id/bottom_container"
app:layout_constraintEnd_toEndOf="parent"
app:tint="@{viewModel.getLocationLockIconTint()}"
app:useCompatPadding="true" />

<!-- Use this container to add overlay views that are anchored to location lock button. -->
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/bottom_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
5 changes: 3 additions & 2 deletions ground/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<string name="new_site">New data collection site</string>
<string name="new_site_hint_text">Add new site and submit related data</string>
<string name="drop_a_pin_tooltip_text">Drag your map until the center pin is on the desired location</string>
<string name="current_location">Current location</string>
<string name="current_location">Current location:</string>
<string name="loading">Loading…</string>
<string name="collect_data_viewer_error">Can’t collect data as user is a VIEWER</string>
<string name="offline_map_imagery">Offline map imagery</string>
Expand Down Expand Up @@ -128,7 +128,7 @@
<string name="initializing">Initializing…</string>
<string name="draw_area_task_instruction">Move the map and tap “Add point” to add points around the desired area.</string>
<string name="close">Close</string>
<string name="map_location">Map location</string>
<string name="map_location">Map location:</string>
<string name="sign_out_dialog_title">Unsynced data</string>
<string name="sign_out_dialog_body">If you sign out, any unsynced data will be discarded</string>
<string name="suggest_data_collection_hint">Zoom in to start collecting data</string>
Expand Down Expand Up @@ -172,4 +172,5 @@
<string name="send_feedback_title">Send feedback</string>
<string name="report_summary">Report technical issues or suggest new locationsOfInterest</string>
<string name="not_yet_impl_title">Not yet implemented</string>
<string name="accuracy">Accuracy:</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ abstract class BaseTaskFragmentTest<F : AbstractTaskFragment<VM>, 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?) {
Expand Down