Skip to content

Conversation

@andreia-ferreira
Copy link
Collaborator

Towards #3437

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @andreia-ferreira, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the task button implementation within the data collection flow. The changes aim to create a more consistent and maintainable system for handling user interactions with task-specific buttons. By introducing a dedicated state class and a Composable for buttons, and centralizing button logic within ViewModels, the PR enhances the reactivity and clarity of the UI, making it easier to manage button states dynamically based on task data and user progress.

Highlights

  • Standardized Button Management: Introduced a new ButtonActionState data class and a TaskButton Composable to centralize and standardize the display and behavior of task action buttons across the application.
  • Reactive Button States: The AbstractTaskViewModel and its subclasses now expose a taskActionButtonStates StateFlow, allowing button visibility and enabled states to be dynamically controlled and observed, leading to a more reactive UI.
  • ViewModel Initialization Enhancements: The initialize method in DataCollectionViewModel and AbstractTaskViewModel has been updated to accept lambdas for isFirstPosition and isLastPositionWithValue, providing more context for button logic.
  • Abstract Class Enforcement: AbstractMapTaskViewModel and AbstractTaskViewModel have been changed from open to abstract, enforcing their role as base classes for specific task ViewModels.
  • Map Task Specific Button Logic: Implemented specific button logic for map-related tasks like CaptureLocationTaskViewModel, DropPinTaskViewModel, and DrawAreaTaskViewModel, including actions like 'Capture Location', 'Drop Pin', 'Undo', 'Redo', 'Add Point', and 'Complete'.
  • Camera Movement Events for Draw Area Task: Added cameraMoveEvents to DrawAreaTaskViewModel to allow one-shot camera movements, particularly useful for 'Undo' and 'Redo' actions in polygon drawing.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a great step towards refactoring the task button implementation. Moving the button state logic into the respective ViewModels and using a declarative approach with StateFlow and ButtonActionState significantly improves the separation of concerns and maintainability. The new TaskButton composable is a clean implementation.

I've found a critical issue in DrawAreaTaskViewModel where some state changes don't trigger UI updates for the buttons. I've also left a minor suggestion to improve code readability in AbstractTaskFragment. Please see the detailed comments.

Comment on lines +151 to +171
override val taskActionButtonStates: StateFlow<List<ButtonActionState>> by lazy {
combine(
taskTaskData,
merge(draftArea, draftUpdates).filterNotNull().map {
(it?.geometry as? LineString)?.isClosed() ?: false
},
_isMarkedComplete,
_isTooClose,
) { taskData, closed, isMarkedComplete, isTooClose ->
listOfNotNull(
getPreviousButtonState(),
getSkipButtonState(taskData),
getUndoButtonState(taskData),
getRedoButtonState(taskData),
getAddPointButtonState(closed, isTooClose),
getCompleteButton(closed, isMarkedComplete, hasSelfIntersection),
getNextButtonState(taskData).takeIf { isMarkedComplete() },
)
}
.stateIn(viewModelScope, SharingStarted.Lazily, emptyList())
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The combine operator for taskActionButtonStates is missing dependencies, which will cause the UI to not update correctly. The states for the "Redo" and "Complete" buttons depend on redoVertexStack and hasSelfIntersection respectively. Since these are mutable properties and not StateFlows, changes to them will not trigger a recalculation of the button states, leading to a stale UI.

To fix this, you should:

  1. Convert _redoVertexStack and hasSelfIntersection to be StateFlows. For example:
    private val _redoVertexStack = MutableStateFlow<List<Coordinates>>(emptyList())
    val redoVertexStack: StateFlow<List<Coordinates>> = _redoVertexStack.asStateFlow()
    
    private val _hasSelfIntersection = MutableStateFlow(false)
    val hasSelfIntersection: StateFlow<Boolean> = _hasSelfIntersection.asStateFlow()
  2. Update the places where these properties are modified to use .update{} or .value = ....
  3. Add these new StateFlows to the combine block and pass their values to getRedoButtonState and getCompleteButton.

This is a critical issue as it leads to incorrect button states being displayed to the user.

Comment on lines +268 to +271
org.groundplatform.android.ui.datacollection.components.refactor.TaskButton(
state = state,
onClick = { handleButtonClick(state.action) },
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using the fully qualified name for TaskButton makes the code a bit harder to read. It's better to add an import for org.groundplatform.android.ui.datacollection.components.refactor.TaskButton at the top of the file and use the class name directly here.

          TaskButton(
            state = state,
            onClick = { handleButtonClick(state.action) },
          )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant