Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
176 changes: 176 additions & 0 deletions docs/images/graphs/dep_graph_feature_onboarding_language.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions feature/onboarding-language/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Onboarding Language Module

## Dependencies

![Dependency Graph](../docs/images/graphs/dep_graph_feature_onboarding_language.svg)

## Sequence Diagram

```mermaid
sequenceDiagram
participant User
participant Screen as SetOnboardingLanguageScreen
participant ViewModel as SetOnboardingLanguageViewModel
participant Repository as UserPreferencesRepository

User->>Screen: Selects language
Screen->>ViewModel: handleAction(SetLanguage(language))
ViewModel->>Repository: setLanguage(language)
Repository-->>ViewModel: Language updated
ViewModel->>Screen: Update UI with new language

Note over Screen,Repository: Language preference is now persisted
```

## Architecture

```mermaid
graph TD
subgraph UI Layer
A[SetOnboardingLanguageScreen] -->|Observes| B[SetOnboardingLanguageViewModel]
end

subgraph Domain Layer
B -->|Uses| C[UserPreferencesRepository]
end

subgraph Data Layer
C -->|Manages| D[Language Preferences]
end

style A fill:#e3f2fd,stroke:#1565c0
style B fill:#e8f5e9,stroke:#2e7d32
style C fill:#fff3e0,stroke:#f57c00
style D fill:#f3e5f5,stroke:#7b1fa2
```
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ import org.mifos.mobile.core.datastore.UserPreferencesRepository
import org.mifos.mobile.core.model.LanguageConfig
import org.mifos.mobile.core.ui.utils.BaseViewModel

/**
* ViewModel responsible for managing the onboarding language selection screen state and business logic.
*
* This ViewModel handles:
* - Loading the current language preference
* - Updating the selected language
* - Managing the onboarding flow state
*
* @property repository [UserPreferencesRepository] for accessing and modifying user preferences
*/
internal class SetOnboardingLanguageViewModel(
private val repository: UserPreferencesRepository,
) : BaseViewModel<OnboardingLanguageState, OnboardingLanguageEvent, OnboardingLanguageAction>(
Expand All @@ -31,13 +41,35 @@ internal class SetOnboardingLanguageViewModel(
.launchIn(viewModelScope)
}

/**
* Processes incoming actions and delegates to appropriate handlers.
* @param action The action to process
*/
override fun handleAction(action: OnboardingLanguageAction) {
when (action) {
is OnboardingLanguageAction.Internal.LoadLanguage -> handleLoadLanguage(action)
is OnboardingLanguageAction.SetLanguage -> handleSetLanguage(action)
}
}

/**
* Updates the selected language and updates onboarding state.
*
* This method will:
* 1. Persist the new language preference
* 2. Update the UI state
* 3. Mark onboarding as complete
*
* @param action Contains the new language configuration
*
* Example:
* ```kotlin
* // When user selects a language
* viewModel.trySendAction(
* OnboardingLanguageAction.SetLanguage(selectedLanguage)
* )
* ```
*/
private fun handleSetLanguage(action: OnboardingLanguageAction.SetLanguage) {
viewModelScope.launch {
repository.setLanguage(action.languageConfig)
Expand All @@ -49,23 +81,62 @@ internal class SetOnboardingLanguageViewModel(
}
}

/**
* Updates the current language in the state.
*
* This is called internally when the language preference changes.
*
* @param action Contains the language to load
*
* Example:
* ```kotlin
* // Internal usage - triggered by language preference changes
* private fun onLanguagePreferenceChanged(newLanguage: LanguageConfig) {
* trySendAction(
* OnboardingLanguageAction.Internal.LoadLanguage(newLanguage)
* )
* }
* ```
*/
private fun handleLoadLanguage(action: OnboardingLanguageAction.Internal.LoadLanguage) {
mutableStateFlow.update {
it.copy(currentLanguage = action.language)
}
}
}

/**
* Represents the UI state for the language selection screen.
* @property currentLanguage The currently selected language
*/
internal data class OnboardingLanguageState(
val currentLanguage: LanguageConfig,
)

/**
* Events that can be triggered from the UI.
* Currently not used but available for future extensions.
*/
internal sealed interface OnboardingLanguageEvent

/**
* Actions that can be processed by the ViewModel.
*/
internal sealed interface OnboardingLanguageAction {
/**
* Action to set a new language.
* @property languageConfig The language configuration to set
*/
data class SetLanguage(val languageConfig: LanguageConfig) : OnboardingLanguageAction

/**
* Internal actions used by the ViewModel for state management.
*/
sealed interface Internal : OnboardingLanguageAction {
/**
* Action to load a language configuration.
* @property language The language configuration to load
*/
data class LoadLanguage(val language: LanguageConfig) : Internal
}
}
Loading