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

Reuse addNextButton() for Capture location and drop pin tasks #2997

Merged
merged 1 commit into from
Jan 13, 2025
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 @@ -147,10 +147,13 @@ abstract class AbstractTaskFragment<T : AbstractTaskViewModel> : AbstractFragmen
.setOnClickListener { moveToPrevious() }
.enableIfTrue(!dataCollectionViewModel.isFirstPosition(taskId))

protected fun addNextButton() =
protected fun addNextButton(hideIfEmpty: Boolean = false) =
addButton(ButtonAction.NEXT)
.setOnClickListener { handleNext() }
.setOnValueChanged { button, value ->
if (hideIfEmpty) {
button.showIfTrue(value.isNotNullOrEmpty())
}
button.enableIfTrue(value.isNotNullOrEmpty())
button.toggleDone(checkLastPositionWithTaskData(value))
}
Expand Down Expand Up @@ -179,7 +182,7 @@ abstract class AbstractTaskFragment<T : AbstractTaskViewModel> : AbstractFragmen
dataCollectionViewModel.onNextClicked(viewModel)
}

fun handleNext() {
private fun handleNext() {
if (getTask().isAddLoiTask) {
launchLoiNameDialog()
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.platform.ComposeView
import androidx.lifecycle.lifecycleScope
import com.google.android.ground.R
import com.google.android.ground.model.submission.isNotNullOrEmpty
import com.google.android.ground.model.submission.isNullOrEmpty
import com.google.android.ground.ui.datacollection.components.ButtonAction
import com.google.android.ground.ui.datacollection.components.TaskView
Expand Down Expand Up @@ -83,13 +82,7 @@ class CaptureLocationTaskFragment @Inject constructor() :
addButton(ButtonAction.CAPTURE_LOCATION)
.setOnClickListener { viewModel.updateResponse() }
.setOnValueChanged { button, value -> button.showIfTrue(value.isNullOrEmpty()) }
addButton(ButtonAction.NEXT)
.setOnClickListener { handleNext() }
.setOnValueChanged { button, value ->
button.showIfTrue(value.isNotNullOrEmpty())
button.toggleDone(checkLastPositionWithTaskData(value))
}
.hide()
addNextButton(hideIfEmpty = true)
}

@Suppress("LabeledExpression")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.ComposeView
import com.google.android.ground.R
import com.google.android.ground.model.submission.isNotNullOrEmpty
import com.google.android.ground.model.submission.isNullOrEmpty
import com.google.android.ground.ui.datacollection.components.ButtonAction
import com.google.android.ground.ui.datacollection.components.InstructionsDialog
Expand Down Expand Up @@ -67,13 +66,7 @@ class DropPinTaskFragment @Inject constructor() : AbstractTaskFragment<DropPinTa
addButton(ButtonAction.DROP_PIN)
.setOnClickListener { viewModel.dropPin() }
.setOnValueChanged { button, value -> button.showIfTrue(value.isNullOrEmpty()) }
addButton(ButtonAction.NEXT)
.setOnClickListener { handleNext() }
.setOnValueChanged { button, value ->
button.showIfTrue(value.isNotNullOrEmpty())
button.toggleDone(checkLastPositionWithTaskData(value))
}
.hide()
addNextButton(hideIfEmpty = true)
}

override fun onTaskResume() {
Expand Down
Loading