From ed2af89add211bc7ca9ec5be6715ea69f262ed06 Mon Sep 17 00:00:00 2001 From: Shobhit Agarwal Date: Wed, 28 Feb 2024 21:47:53 +0530 Subject: [PATCH 1/2] Fix key value for time type tasks (#2263) Co-authored-by: Gino Miceli <228050+gino-m@users.noreply.github.com> --- .../ground/persistence/remote/firebase/schema/TaskConverter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ground/src/main/java/com/google/android/ground/persistence/remote/firebase/schema/TaskConverter.kt b/ground/src/main/java/com/google/android/ground/persistence/remote/firebase/schema/TaskConverter.kt index d484777656..691eee4755 100644 --- a/ground/src/main/java/com/google/android/ground/persistence/remote/firebase/schema/TaskConverter.kt +++ b/ground/src/main/java/com/google/android/ground/persistence/remote/firebase/schema/TaskConverter.kt @@ -55,7 +55,7 @@ internal object TaskConverter { "draw_area" -> Task.Type.DRAW_AREA "number" -> Task.Type.NUMBER "date" -> Task.Type.DATE - "time" -> Task.Type.TIME + "date_time" -> Task.Type.TIME "capture_location" -> Task.Type.CAPTURE_LOCATION else -> Task.Type.UNKNOWN } From 5184ee4b420534a22177897c06e5d2afc000ebca Mon Sep 17 00:00:00 2001 From: Shobhit Agarwal Date: Wed, 28 Feb 2024 21:48:24 +0530 Subject: [PATCH 2/2] Display the task only when the task fragment is actually visible to the user (#2262) Co-authored-by: Gino Miceli <228050+gino-m@users.noreply.github.com> --- .../ui/datacollection/tasks/AbstractTaskFragment.kt | 12 +++++++++++- .../tasks/polygon/DrawAreaTaskFragment.kt | 2 ++ .../tasks/polygon/DrawAreaTaskFragmentTest.kt | 3 +++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/AbstractTaskFragment.kt b/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/AbstractTaskFragment.kt index 171cfee1db..3cde535964 100644 --- a/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/AbstractTaskFragment.kt +++ b/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/AbstractTaskFragment.kt @@ -32,7 +32,7 @@ import com.google.android.ground.ui.datacollection.components.ButtonAction import com.google.android.ground.ui.datacollection.components.TaskButton import com.google.android.ground.ui.datacollection.components.TaskButtonFactory import com.google.android.ground.ui.datacollection.components.TaskView -import java.util.* +import java.util.EnumMap import kotlin.properties.Delegates import kotlinx.coroutines.launch import org.jetbrains.annotations.TestOnly @@ -91,6 +91,13 @@ abstract class AbstractTaskFragment : AbstractFragmen } } + override fun setMenuVisibility(menuVisible: Boolean) { + super.setMenuVisibility(menuVisible) + if (menuVisible) { + onTaskVisibleToUser() + } + } + /** Creates the view for common task template with/without header. */ abstract fun onCreateTaskView(inflater: LayoutInflater): TaskView @@ -100,6 +107,9 @@ abstract class AbstractTaskFragment : AbstractFragmen /** Invoked after the task view gets attached to the fragment. */ open fun onTaskViewAttached() {} + /** Invoked when the task fragment is visible to the user. */ + open fun onTaskVisibleToUser() {} + /** Invoked when the fragment is ready to add buttons to the current [TaskView]. */ open fun onCreateActionButtons() { addSkipButton() diff --git a/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/polygon/DrawAreaTaskFragment.kt b/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/polygon/DrawAreaTaskFragment.kt index 5b649309ed..c7c48ec257 100644 --- a/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/polygon/DrawAreaTaskFragment.kt +++ b/ground/src/main/java/com/google/android/ground/ui/datacollection/tasks/polygon/DrawAreaTaskFragment.kt @@ -96,7 +96,9 @@ class DrawAreaTaskFragment : AbstractTaskFragment() { viewLifecycleOwner.lifecycleScope.launch { viewModel.draftArea.collectLatest { onFeatureUpdated(it) } } + } + override fun onTaskVisibleToUser() { if (!viewModel.instructionsDialogShown) { showInstructionsDialog() } diff --git a/ground/src/test/java/com/google/android/ground/ui/datacollection/tasks/polygon/DrawAreaTaskFragmentTest.kt b/ground/src/test/java/com/google/android/ground/ui/datacollection/tasks/polygon/DrawAreaTaskFragmentTest.kt index 00e35211ea..1c666f088c 100644 --- a/ground/src/test/java/com/google/android/ground/ui/datacollection/tasks/polygon/DrawAreaTaskFragmentTest.kt +++ b/ground/src/test/java/com/google/android/ground/ui/datacollection/tasks/polygon/DrawAreaTaskFragmentTest.kt @@ -110,6 +110,7 @@ class DrawAreaTaskFragmentTest : @Test fun testDrawArea_incompleteWhenTaskIsOptional() = runWithTestDispatcher { setupTaskFragment(job, task.copy(isRequired = false)) + fragment.onTaskVisibleToUser() // Dismiss the instructions dialog ShadowDialog.getLatestDialog().dismiss() @@ -142,6 +143,7 @@ class DrawAreaTaskFragmentTest : @Test fun testDrawArea() = runWithTestDispatcher { setupTaskFragment(job, task.copy(isRequired = false)) + fragment.onTaskVisibleToUser() // Dismiss the instructions dialog ShadowDialog.getLatestDialog().dismiss() @@ -178,6 +180,7 @@ class DrawAreaTaskFragmentTest : @Test fun `Instructions dialog is shown`() = runWithTestDispatcher { setupTaskFragment(job, task) + fragment.onTaskVisibleToUser() assertThat(ShadowDialog.getLatestDialog()).isNotNull() }