Skip to content

Conversation

moehamade
Copy link
Contributor

Closes #127
This commit introduces a MainViewModel to manage the UI state for the onboarding flow. This change centralizes the onboarding state (including Bluetooth status, location status, error messages, and loading indicators) within the ViewModel, allowing it to survive configuration changes and simplifying state management within MainActivity.

Key changes:

  • Created MainViewModel.kt to hold and manage onboarding-related UI state.
  • Moved onboarding state variables (e.g., onboardingState, bluetoothStatus, locationStatus) from MainActivity to MainViewModel.
  • Updated MainActivity to observe and update onboarding state through the MainViewModel.
  • Created OnboardingState.kt to define the possible states of the onboarding process.
  • Ensured that the onboarding process is not restarted on configuration changes by checking mainViewModel.onboardingState before initiating.

Description

Checklist

This commit introduces a `MainViewModel` to manage the UI state for the onboarding flow. This change centralizes the onboarding state (including Bluetooth status, location status, error messages, and loading indicators) within the ViewModel, allowing it to survive configuration changes and simplifying state management within `MainActivity`.

Key changes:
- Created `MainViewModel.kt` to hold and manage onboarding-related UI state.
- Moved onboarding state variables (e.g., `onboardingState`, `bluetoothStatus`, `locationStatus`) from `MainActivity` to `MainViewModel`.
- Updated `MainActivity` to observe and update onboarding state through the `MainViewModel`.
- Created `OnboardingState.kt` to define the possible states of the onboarding process.
- Ensured that the onboarding process is not restarted on configuration changes by checking `mainViewModel.onboardingState` before initiating.
@moehamade
Copy link
Contributor Author

Code can still be optimized, no need for 2 variables for compose mutable state (can use private set), but preferably switch to stateflow , move enum to related package (onboarding)

This commit refactors the `MainViewModel` to use `StateFlow` instead of `mutableStateOf` for managing its observable properties. This change improves the way UI state is handled and observed, aligning with modern Android development best practices.

Additionally, `OnboardingState.kt` has been moved to the `onboarding` package for better organization.
@moehamade moehamade marked this pull request as ready for review July 15, 2025 22:15
@moehamade
Copy link
Contributor Author

This is ready for review now, @callebtc appreciate if you can please take a look :)

Copy link
Collaborator

@callebtc callebtc left a comment

Choose a reason for hiding this comment

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

looks great, thank you for helping refactor the project into a better state

@callebtc callebtc added the complete Ready to merge label Jul 16, 2025
@callebtc callebtc merged commit 01d6a81 into permissionlesstech:main Jul 17, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
complete Ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Onboarding state is lost on configuration change due to variables in MainActivity
2 participants