-
Notifications
You must be signed in to change notification settings - Fork 143
Migrate DropPinTaskFragment to use TaskScreen Component #3670
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e3075d5
refactor: migrate DropPinTask to Jetpack Compose screen and update re…
shobhitagarwal1612 c03449f
refactor: replace mutable state with StateFlow for instructions and s…
shobhitagarwal1612 8e0a3ab
refactor: integrate LOI name dialog into task action handling flow in…
shobhitagarwal1612 703fa9d
fix imports
shobhitagarwal1612 8d11ff9
Fix detekt issues
shobhitagarwal1612 0d5c1c2
Update `renderFeatures` to return `Flow` instead of `LiveData`
shobhitagarwal1612 dc7f38b
Add missing tests
shobhitagarwal1612 e10c212
Apply formatting
shobhitagarwal1612 fa2e320
Merge branch 'master' into drop-pin-task-compose
shobhitagarwal1612 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
...c/main/java/org/groundplatform/android/ui/datacollection/tasks/point/DropPinTaskScreen.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.groundplatform.android.ui.datacollection.tasks.point | ||
|
|
||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.getValue | ||
| import androidx.compose.ui.tooling.preview.Preview | ||
| import androidx.lifecycle.compose.collectAsStateWithLifecycle | ||
| import org.groundplatform.android.R | ||
| import org.groundplatform.android.ui.common.ExcludeFromJacocoGeneratedReport | ||
| import org.groundplatform.android.ui.datacollection.components.ButtonAction | ||
| import org.groundplatform.android.ui.datacollection.components.ButtonActionState | ||
| import org.groundplatform.android.ui.datacollection.components.InstructionData | ||
| import org.groundplatform.android.ui.datacollection.components.TaskHeader | ||
| import org.groundplatform.android.ui.datacollection.tasks.TaskScreen | ||
| import org.groundplatform.android.ui.datacollection.tasks.TaskScreenAction | ||
| import org.groundplatform.ui.theme.AppTheme | ||
|
|
||
| /** | ||
| * A screen for dropping a pin on the map. | ||
| * | ||
| * This is the stateful wrapper that collects state from [DropPinTaskViewModel] and handles event | ||
| * routing. | ||
| * | ||
| * @param viewModel The view model for this task. | ||
| * @param onFooterPositionUpdated Callback when the footer position changes. | ||
| * @param onAction Callback for screen actions (e.g., navigation). | ||
| * @param mapContent Composable for rendering the map. | ||
| */ | ||
| @Composable | ||
| fun DropPinTaskScreen( | ||
| viewModel: DropPinTaskViewModel, | ||
| onFooterPositionUpdated: (Float) -> Unit, | ||
| shouldShowLoiNameDialog: Boolean, | ||
| loiName: String, | ||
| onAction: (TaskScreenAction) -> Unit, | ||
| mapContent: @Composable () -> Unit, | ||
| ) { | ||
| val taskActionButtonsStates by viewModel.taskActionButtonStates.collectAsStateWithLifecycle() | ||
| val showInstructionsDialog by viewModel.showInstructionsDialog.collectAsStateWithLifecycle() | ||
|
|
||
| DropPinTaskContent( | ||
| taskLabel = viewModel.task.label, | ||
| taskActionButtonsStates = taskActionButtonsStates, | ||
| showInstructionsDialog = showInstructionsDialog, | ||
| shouldShowLoiNameDialog = shouldShowLoiNameDialog, | ||
| loiName = loiName, | ||
| onFooterPositionUpdated = onFooterPositionUpdated, | ||
| onAction = { action -> | ||
| if (action is TaskScreenAction.OnInstructionsDismiss) { | ||
| viewModel.dismissDropPinInstructions() | ||
| } else { | ||
| onAction(action) | ||
| } | ||
| }, | ||
| mapContent = mapContent, | ||
| ) | ||
| } | ||
|
|
||
| /** | ||
| * The stateless content of the drop pin task screen. | ||
| * | ||
| * @param taskLabel The label of the task. | ||
| * @param taskActionButtonsStates The states of the action buttons. | ||
| * @param showInstructionsDialog Whether to show the instructions' dialog. | ||
| * @param onFooterPositionUpdated Callback when the footer position changes. | ||
| * @param onAction Callback for screen actions. | ||
| * @param mapContent Composable for rendering the map. | ||
| */ | ||
| @Composable | ||
| private fun DropPinTaskContent( | ||
| taskLabel: String, | ||
| taskActionButtonsStates: List<ButtonActionState>, | ||
| showInstructionsDialog: Boolean, | ||
| shouldShowLoiNameDialog: Boolean, | ||
| loiName: String, | ||
| onFooterPositionUpdated: (Float) -> Unit, | ||
| onAction: (TaskScreenAction) -> Unit, | ||
| mapContent: @Composable () -> Unit, | ||
| ) { | ||
| TaskScreen( | ||
| taskHeader = TaskHeader(taskLabel, R.drawable.outline_pin_drop), | ||
| instructionData = | ||
| InstructionData(iconId = R.drawable.swipe_24, stringId = R.string.drop_a_pin_tooltip_text), | ||
| taskActionButtonsStates = taskActionButtonsStates, | ||
| showInstructionsDialog = showInstructionsDialog, | ||
| shouldShowLoiNameDialog = shouldShowLoiNameDialog, | ||
| loiName = loiName, | ||
| onFooterPositionUpdated = onFooterPositionUpdated, | ||
| onAction = onAction, | ||
| taskBody = mapContent, | ||
| ) | ||
| } | ||
|
|
||
| @Preview(showBackground = true) | ||
| @Composable | ||
| @ExcludeFromJacocoGeneratedReport | ||
| private fun DropPinTaskScreenPreview() { | ||
| AppTheme { | ||
| DropPinTaskContent( | ||
| taskLabel = "Task for dropping a pin", | ||
| taskActionButtonsStates = | ||
| listOf( | ||
| ButtonActionState(ButtonAction.PREVIOUS, isEnabled = true, isVisible = true), | ||
| ButtonActionState(ButtonAction.SKIP, isEnabled = true, isVisible = true), | ||
| ButtonActionState(ButtonAction.UNDO, isEnabled = false, isVisible = false), | ||
| ButtonActionState(ButtonAction.DROP_PIN, isEnabled = true, isVisible = true), | ||
| ButtonActionState(ButtonAction.NEXT, isEnabled = false, isVisible = false), | ||
| ), | ||
| showInstructionsDialog = true, | ||
| shouldShowLoiNameDialog = false, | ||
| loiName = "", | ||
| onFooterPositionUpdated = {}, | ||
| onAction = {}, | ||
| mapContent = {}, | ||
| ) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.