Refactor onboarding validation 5103387645092597876#126
Conversation
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.
Summary of ChangesHello @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
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
| if (!viewModel.saveName()) { | ||
| Toast.makeText(context, "Name cannot be blank", Toast.LENGTH_SHORT).show() | ||
| return@Button | ||
| } |
There was a problem hiding this comment.
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
Toastmessage 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>
No description provided.