-
Notifications
You must be signed in to change notification settings - Fork 768
Order Savings Accounts by Active State Etc #2986
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,11 +23,11 @@ import org.mifos.mobile.core.common.DataState | |
| import org.mifos.mobile.core.data.repository.AccountsRepository | ||
| import org.mifos.mobile.core.data.util.NetworkMonitor | ||
| import org.mifos.mobile.core.datastore.UserPreferencesRepository | ||
| import org.mifos.mobile.core.model.SavingStatus | ||
| import org.mifos.mobile.core.model.entity.accounts.savings.SavingAccount | ||
| import org.mifos.mobile.core.model.entity.client.ClientAccounts | ||
| import org.mifos.mobile.core.ui.utils.BaseViewModel | ||
| import org.mifos.mobile.core.ui.utils.ScreenUiState | ||
| import org.mifos.mobile.core.ui.utils.ScreenUiState.Network | ||
| import org.mifos.mobile.feature.savingsaccount.utils.FilterUtil | ||
| import kotlin.collections.orEmpty | ||
|
|
||
|
|
@@ -55,9 +55,7 @@ class SavingsAccountViewmodel( | |
| observeNetwork() | ||
| } | ||
|
|
||
| /** | ||
| * Observes the network connectivity status and updates state accordingly. | ||
| */ | ||
| /** Observes the network connectivity status and updates state accordingly. */ | ||
| private fun observeNetwork() { | ||
| viewModelScope.launch { | ||
| networkMonitor.isOnline | ||
|
|
@@ -140,9 +138,9 @@ class SavingsAccountViewmodel( | |
| } | ||
|
|
||
| /** | ||
| * Retries the data fetching process. If the network is unavailable, it shows | ||
| * a network error dialog. Otherwise, it triggers the `loadAccounts` `fetchClient`, | ||
| * `fetchLonPurpose` function. | ||
| * A helper function to update the mutable state flow. | ||
| * | ||
| * @param update A lambda function that takes the current state and returns a new state. | ||
|
Comment on lines
+141
to
+143
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix incorrect documentation. The KDoc describes Apply this diff to correct the documentation: - /**
- * A helper function to update the mutable state flow.
- *
- * @param update A lambda function that takes the current state and returns a new state.
- */
+ /**
+ * Retries loading accounts based on network status.
+ * Shows network error if offline, otherwise reloads accounts.
+ */
private fun retry() {🤖 Prompt for AI Agents |
||
| */ | ||
| private fun retry() { | ||
| viewModelScope.launch { | ||
|
|
@@ -155,17 +153,15 @@ class SavingsAccountViewmodel( | |
| } | ||
|
|
||
| /** | ||
| * Toggles visibility of the total savings amount in UI. | ||
| */ | ||
| * Toggles visibility of total savings amount in UI. | ||
| * */ | ||
| private fun handleAmountVisible() { | ||
| mutableStateFlow.update { | ||
| it.copy(isAmountVisible = !state.isAmountVisible) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Dismisses any active dialog in the UI. | ||
| */ | ||
| /** Dismisses any active dialog. */ | ||
| private fun handleDismissDialog() { | ||
| mutableStateFlow.update { | ||
| it.copy(dialogState = null) | ||
|
|
@@ -230,9 +226,10 @@ class SavingsAccountViewmodel( | |
| is DataState.Success -> { | ||
| val allSavings = dataState.data.savingsAccounts.orEmpty() | ||
| val filtered = filterAccounts(selectedFilters, allSavings) | ||
| val sortedAccounts = sortAccountsByStatus(filtered) | ||
| updateState { | ||
| it.copy( | ||
| decimals = filtered.firstOrNull()?.currency?.decimalPlaces ?: 2, | ||
| decimals = sortedAccounts.firstOrNull()?.currency?.decimalPlaces ?: 2, | ||
| ) | ||
| } | ||
WizCoderr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
@@ -242,12 +239,12 @@ class SavingsAccountViewmodel( | |
|
|
||
| updateState { | ||
| val isEmptyAccounts = allSavings.isEmpty() | ||
| val isFilteredEmpty = filtered.isEmpty() | ||
| val isFilteredEmpty = sortedAccounts.isEmpty() | ||
|
|
||
| it.copy( | ||
| items = filtered.size, | ||
| items = sortedAccounts.size, | ||
| isFilteredEmpty = isFilteredEmpty, | ||
| savingsAccount = filtered, | ||
| savingsAccount = sortedAccounts, | ||
| originalAccounts = allSavings, | ||
| selectedFilters = selectedFilters, | ||
| currency = allSavings.firstOrNull()?.currency?.displaySymbol, | ||
|
|
@@ -280,7 +277,6 @@ class SavingsAccountViewmodel( | |
| } else { | ||
| accounts | ||
| } | ||
|
|
||
| return filteredByStatus.distinct() | ||
| } | ||
|
|
||
|
|
@@ -289,6 +285,11 @@ class SavingsAccountViewmodel( | |
| * | ||
| * @param accounts List of [SavingAccount] to compute totals from. | ||
| */ | ||
| private fun sortAccountsByStatus(accounts: List<SavingAccount>): List<SavingAccount> { | ||
| return accounts.sortedWith(compareBy { state.statusOrder.indexOf(it.status?.value) }) | ||
| } | ||
WizCoderr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** Calculates total savings balance and updates state. */ | ||
| private fun getTotalSavingAmount(accounts: List<SavingAccount>?) { | ||
| var amount = 0.0 | ||
| var items = 0 | ||
|
|
@@ -352,6 +353,14 @@ data class SavingsAccountState( | |
| val uiState: ScreenUiState? = ScreenUiState.Loading, | ||
|
|
||
| val networkStatus: Boolean = false, | ||
|
|
||
| /** Order of statuses for consistent sorting */ | ||
| val statusOrder: List<String> = listOf( | ||
| SavingStatus.ACTIVE.status, | ||
| SavingStatus.SUBMIT_AND_PENDING_APPROVAL.status, | ||
| SavingStatus.CLOSED.status, | ||
| SavingStatus.INACTIVE.status, | ||
| ), | ||
| ) { | ||
|
|
||
| /** | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.