Skip to content

Commit

Permalink
Merge branch 'master' into sufy/2115/offline-imagery-redux
Browse files Browse the repository at this point in the history
  • Loading branch information
sufyanAbbasi authored Feb 28, 2024
2 parents 55ebcd2 + 5184ee4 commit 32fc8c7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -91,6 +91,13 @@ abstract class AbstractTaskFragment<T : AbstractTaskViewModel> : 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

Expand All @@ -100,6 +107,9 @@ abstract class AbstractTaskFragment<T : AbstractTaskViewModel> : 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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ class DrawAreaTaskFragment : AbstractTaskFragment<DrawAreaTaskViewModel>() {
viewLifecycleOwner.lifecycleScope.launch {
viewModel.draftArea.collectLatest { onFeatureUpdated(it) }
}
}

override fun onTaskVisibleToUser() {
if (!viewModel.instructionsDialogShown) {
showInstructionsDialog()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class DrawAreaTaskFragmentTest :
@Test
fun testDrawArea_incompleteWhenTaskIsOptional() = runWithTestDispatcher {
setupTaskFragment<DrawAreaTaskFragment>(job, task.copy(isRequired = false))
fragment.onTaskVisibleToUser()

// Dismiss the instructions dialog
ShadowDialog.getLatestDialog().dismiss()
Expand Down Expand Up @@ -142,6 +143,7 @@ class DrawAreaTaskFragmentTest :
@Test
fun testDrawArea() = runWithTestDispatcher {
setupTaskFragment<DrawAreaTaskFragment>(job, task.copy(isRequired = false))
fragment.onTaskVisibleToUser()

// Dismiss the instructions dialog
ShadowDialog.getLatestDialog().dismiss()
Expand Down Expand Up @@ -178,6 +180,7 @@ class DrawAreaTaskFragmentTest :
@Test
fun `Instructions dialog is shown`() = runWithTestDispatcher {
setupTaskFragment<DrawAreaTaskFragment>(job, task)
fragment.onTaskVisibleToUser()

assertThat(ShadowDialog.getLatestDialog()).isNotNull()
}
Expand Down

0 comments on commit 32fc8c7

Please sign in to comment.