Skip to content

Refactor onboarding validation 5103387645092597876#126

Merged
harrydbarnes merged 3 commits into2.0from
refactor-onboarding-validation-5103387645092597876
Jan 26, 2026
Merged

Refactor onboarding validation 5103387645092597876#126
harrydbarnes merged 3 commits into2.0from
refactor-onboarding-validation-5103387645092597876

Conversation

@harrydbarnes
Copy link
Owner

No description provided.

Moved the user name validation logic from OnboardingScreen (Composable) to OnboardingViewModel.
Changed validation from isNotEmpty() to isNotBlank() to prevent saving whitespace-only names.
This improves separation of concerns and testability.
Updated `OnboardingViewModel.saveName` to return a `Boolean` indicating success.
Updated `OnboardingScreen` to check this return value and show a Toast message if validation fails, preventing navigation to the next step.
This addresses the feedback that the previous refactoring allowed users to proceed with a blank name.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @harrydbarnes, 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 refactors the name input validation process within the onboarding flow. The core validation logic is now encapsulated within the ViewModel, promoting a cleaner separation of concerns and making the validation more robust and testable. The user interface has been updated to gracefully handle invalid input by providing immediate feedback.

Highlights

  • Validation Logic Relocation: The responsibility for validating the user's name (checking if it's blank) has been moved from the OnboardingScreen UI component to the OnboardingViewModel.
  • ViewModel's saveName() Function Update: The saveName() function in OnboardingViewModel now returns a boolean value, indicating whether the name was successfully saved (true) or if it was blank (false).
  • UI Feedback for Invalid Input: The OnboardingScreen now checks the return value of viewModel.saveName() and displays a 'Name cannot be blank' Toast message to the user if the validation fails.
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 refactors the name validation logic during onboarding by moving it from the Composable into the OnboardingViewModel. This is a good step towards better separation of concerns. My review includes a suggestion to further improve the validation handling by adopting a more state-driven UI approach for displaying errors, which will enhance user experience and align better with modern Android architecture. I've also included a minor suggestion to improve the conciseness of the new saveName function.

Comment on lines +101 to 104
if (!viewModel.saveName()) {
Toast.makeText(context, "Name cannot be blank", Toast.LENGTH_SHORT).show()
return@Button
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

This imperative approach to validation has a couple of drawbacks:

  • Hardcoded String: The error message "Name cannot be blank" is hardcoded. It should be extracted to a string resource for maintainability and internationalization.
  • Poor User Experience: A Toast message is transient and disappears quickly. It's better to display a persistent error message near the input field itself.

A better approach would be to make this UI state-driven. The ViewModel could expose an error state, and the OutlinedTextField in WelcomeStep could use its isError and supportingText properties to display the validation error. This provides a much better user experience and follows modern Android development patterns.

For example, your ViewModel could manage state like this:

// In ViewModel
fun validateAndSaveName() {
    if (name.value.isBlank()) {
        // Update a UiState object with an error message/ID
    } else {
        // Clear error and launch save coroutine
    }
}

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@harrydbarnes harrydbarnes merged commit d92aa2d into 2.0 Jan 26, 2026
1 check passed
@harrydbarnes harrydbarnes deleted the refactor-onboarding-validation-5103387645092597876 branch January 26, 2026 04:37
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