Skip to content

Commit 7159c6d

Browse files
committed
Documentation for features/loan-account
1 parent 9e45f31 commit 7159c6d

File tree

16 files changed

+529
-60
lines changed

16 files changed

+529
-60
lines changed

feature/loan-account/src/commonMain/kotlin/org/mifos/mobile/feature/loanaccount/component/AccountSummaryCard.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ import org.mifos.mobile.core.designsystem.theme.MifosTypography
5252
import kotlin.collections.component1
5353
import kotlin.collections.component2
5454

55+
/**
56+
* A composable that displays a summary of account details in a card format.
57+
* The card is expandable to show more details.
58+
*
59+
* @param keyValuePairs A map of key-value pairs to display as account details. The key is a
60+
* [StringResource] for the label, and the value is the string to display.
61+
* @param modifier The modifier to be applied to the component.
62+
* @param title The title of the card.
63+
*/
5564
@Composable
5665
fun AccountSummaryCard(
5766
keyValuePairs: Map<StringResource, String?>,

feature/loan-account/src/commonMain/kotlin/org/mifos/mobile/feature/loanaccount/component/LoanActionItems.kt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,47 +29,74 @@ import org.jetbrains.compose.resources.StringResource
2929
import org.mifos.mobile.core.common.Constants
3030
import org.mifos.mobile.core.designsystem.icon.MifosIcons
3131

32+
/**
33+
* Represents the different actions that can be performed on a loan account.
34+
* Each action has a title, subtitle, icon, and a route for navigation.
35+
*
36+
* @property title The title of the action item.
37+
* @property subTitle A brief description of the action.
38+
* @property icon The icon representing the action.
39+
* @property route The navigation route associated with the action.
40+
*/
3241
sealed class LoanActionItems(
3342
val title: StringResource,
3443
val subTitle: StringResource,
3544
val icon: ImageVector,
3645
val route: String,
3746
) {
47+
/**
48+
* Action to make a payment on the loan account.
49+
*/
3850
data object MakePayment : LoanActionItems(
3951
title = Res.string.feature_account_action_make_payment,
4052
subTitle = Res.string.feature_account_action_make_payment_tip,
4153
icon = MifosIcons.Money,
4254
route = Constants.MAKE_PAYMENT,
4355
)
4456

57+
/**
58+
* Action to view the loan summary.
59+
*/
4560
data object LoanSummary : LoanActionItems(
4661
title = Res.string.feature_account_action_loan_summary,
4762
subTitle = Res.string.feature_account_action_loan_summary_tip,
4863
icon = MifosIcons.MoneyHand,
4964
route = Constants.LOAN_SUMMARY,
5065
)
5166

67+
/**
68+
* Action to view the repayment schedule of the loan.
69+
*/
5270
data object RepaymentSchedule : LoanActionItems(
5371
title = Res.string.feature_account_action_repayment_schedule,
5472
subTitle = Res.string.feature_account_action_repayment_schedule_tip,
5573
icon = MifosIcons.MoneyHand,
5674
route = Constants.REPAYMENT_SCHEDULE,
5775
)
5876

77+
/**
78+
* Action to view the transaction history of the loan account.
79+
*/
5980
data object Transactions : LoanActionItems(
6081
title = Res.string.feature_account_action_transactions,
6182
subTitle = Res.string.feature_account_action_transactions_tip,
6283
icon = MifosIcons.ChatHistory,
6384
route = Constants.TRANSACTIONS,
6485
)
6586

87+
/**
88+
* Action to view the charges associated with the loan account.
89+
*/
6690
data object Charges : LoanActionItems(
6791
title = Res.string.feature_account_action_charges,
6892
subTitle = Res.string.feature_account_action_charges_tip,
6993
icon = MifosIcons.ReceiptMoney,
7094
route = Constants.CHARGES,
7195
)
7296

97+
/**
98+
* Action to generate a QR code for the loan account.
99+
*/
73100
data object QrCode : LoanActionItems(
74101
title = Res.string.feature_account_action_qr,
75102
subTitle = Res.string.feature_account_action_qr_tip,
@@ -78,6 +105,9 @@ sealed class LoanActionItems(
78105
)
79106
}
80107

108+
/**
109+
* A list of all available loan account actions.
110+
*/
81111
internal val loanAccountActions: ImmutableList<LoanActionItems> = persistentListOf(
82112
LoanActionItems.MakePayment,
83113
LoanActionItems.LoanSummary,

feature/loan-account/src/commonMain/kotlin/org/mifos/mobile/feature/loanaccount/component/RepaymentPeriodCard.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ import org.mifos.mobile.core.model.entity.accounts.loan.Periods
4949
import kotlin.time.Clock
5050
import kotlin.time.ExperimentalTime
5151

52+
/**
53+
* A composable that displays a single item in a repayment schedule.
54+
* It shows details such as the installment number, due date, and amount.
55+
* It also provides a button to pay the installment if it's due.
56+
*
57+
* @param period The [Periods] object containing the details of the repayment period.
58+
* @param currencyCode The currency code to use for formatting the amount.
59+
* @param maxDigits The maximum number of digits to display for the fractional part of the amount.
60+
* @param modifier The modifier to be applied to the component.
61+
* @param onPayClick A callback that is invoked when the pay button is clicked.
62+
*/
5263
@OptIn(ExperimentalTime::class)
5364
@Composable
5465
fun RepaymentScheduleItem(

feature/loan-account/src/commonMain/kotlin/org/mifos/mobile/feature/loanaccount/loanAccount/LoanAccountNavigation.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,25 @@ import androidx.navigation.NavOptions
1717
import kotlinx.serialization.Serializable
1818
import org.mifos.mobile.core.ui.composableWithSlideTransitions
1919

20+
/**
21+
* A route for the loan account screen.
22+
*/
2023
@Serializable
2124
data object LoanAccountRoute
2225

26+
/**
27+
* Navigates to the loan account screen.
28+
*
29+
* @param navOptions The navigation options.
30+
*/
2331
fun NavController.navigateToLoanAccountScreen(navOptions: NavOptions? = null) =
2432
navigate(LoanAccountRoute, navOptions)
2533

34+
/**
35+
* Defines the loan account screen destination in the navigation graph.
36+
*
37+
* @param navigateBack A callback to navigate back to the previous screen.
38+
*/
2639
fun NavGraphBuilder.loanAccountDestination(
2740
navigateBack: () -> Unit,
2841
) {

feature/loan-account/src/commonMain/kotlin/org/mifos/mobile/feature/loanaccount/loanAccount/LoanAccountScreen.kt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,19 @@ import org.mifos.mobile.core.ui.utils.EventsEffect
6161
import org.mifos.mobile.core.ui.utils.ScreenUiState
6262
import kotlin.collections.orEmpty
6363

64+
/**
65+
* The main composable for the loan account screen.
66+
* It displays a list of loan accounts and allows the user to filter them.
67+
*
68+
* @param navigateBack A callback to navigate back to the previous screen.
69+
* @param onAccountClicked A callback that is invoked when a loan account is clicked.
70+
* @param refreshSignal A signal to trigger a refresh of the account list.
71+
* @param onLoadingCompleted A callback that is invoked when the initial loading is completed.
72+
* @param accountTypeFilters A list of account type filters to apply.
73+
* @param accountStatusFilters A list of account status filters to apply.
74+
* @param filtersClicked A callback that is invoked when the filter button is clicked.
75+
* @param viewModel The [LoanAccountsViewmodel] for this screen.
76+
*/
6477
@Composable
6578
fun LoanAccountScreen(
6679
navigateBack: () -> Unit,
@@ -117,6 +130,13 @@ fun LoanAccountScreen(
117130
)
118131
}
119132

133+
/**
134+
* A composable that displays a dialog for the loan account screen.
135+
* It can show an error dialog.
136+
*
137+
* @param dialogState The state of the dialog to display.
138+
* @param onAction A callback to handle actions from the dialog.
139+
*/
120140
@Composable
121141
internal fun LoanAccountDialog(
122142
dialogState: LoanAccountsState.DialogState?,
@@ -135,6 +155,15 @@ internal fun LoanAccountDialog(
135155
}
136156
}
137157

158+
/**
159+
* The content of the loan account screen.
160+
* It displays a dashboard card with the total loan amount and a list of loan accounts.
161+
* It also handles different UI states such as loading, error, network, and empty.
162+
*
163+
* @param state The [LoanAccountsState] for this screen.
164+
* @param onAction A callback to handle actions from the screen.
165+
* @param filtersClicked A callback that is invoked when the filter button is clicked.
166+
*/
138167
@Composable
139168
internal fun LoanAccountContent(
140169
state: LoanAccountsState,

feature/loan-account/src/commonMain/kotlin/org/mifos/mobile/feature/loanaccount/loanAccount/LoanAccountViewModel.kt

Lines changed: 77 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ import org.mifos.mobile.feature.loanaccount.utils.FilterUtil
3131
import kotlin.collections.firstOrNull
3232

3333
/**
34-
* ViewModel responsible for managing loan account UI state, fetching, filtering,
35-
* and reacting to user actions and network changes.
34+
* ViewModel for the loan accounts screen.
35+
* It is responsible for fetching and filtering loan accounts, and for handling user actions.
3636
*
37-
* @param accountsRepositoryImpl Provides access to account data.
38-
* @param networkMonitor Observes network connectivity.
39-
* @param userPreferencesRepositoryImpl Provides user-specific data such as client ID.
37+
* @param accountsRepositoryImpl The repository for fetching account data.
38+
* @param networkMonitor The network monitor to observe network connectivity.
39+
* @param userPreferencesRepositoryImpl The repository for user preferences.
4040
*/
4141
class LoanAccountsViewmodel(
4242
private val accountsRepositoryImpl: AccountsRepository,
@@ -307,8 +307,22 @@ class LoanAccountsViewmodel(
307307
}
308308

309309
/**
310-
* State holder for the Loan Account screen.
311-
* Contains all values needed to render the UI and manage logic.
310+
* Represents the state of the loan accounts screen.
311+
*
312+
* @property loanAccounts The list of loan accounts to display.
313+
* @property originalAccounts The original, unfiltered list of loan accounts.
314+
* @property isFilteredEmpty Whether the filtered list of accounts is empty.
315+
* @property firstLaunch Whether this is the first time the screen is launched.
316+
* @property items The number of filtered accounts.
317+
* @property totalLoanAmount The total loan amount computed from the accounts.
318+
* @property currency The currency symbol (e.g., ₹, $, etc.).
319+
* @property decimals The number of decimals to display for the amount.
320+
* @property clientId The current client ID from user preferences.
321+
* @property dialogState The currently active dialog (Error).
322+
* @property selectedFilters The filters currently applied.
323+
* @property isAmountVisible Whether the account balances are visible.
324+
* @property networkStatus The network connectivity status.
325+
* @property uiState The overall state of the screen.
312326
*/
313327
data class LoanAccountsState(
314328
val loanAccounts: List<LoanAccount>?,
@@ -353,48 +367,83 @@ data class LoanAccountsState(
353367
* Sealed class representing possible dialog states.
354368
*/
355369
sealed interface DialogState {
370+
/**
371+
* An error dialog with a message.
372+
*
373+
* @param message The error message to display.
374+
*/
356375
data class Error(val message: String) : DialogState
357376
}
358377
}
359378

360379
/**
361-
* Represents user or system actions for the Loan Account screen.
380+
* Represents the actions that can be taken on the loan accounts screen.
362381
*/
363382
sealed interface LoanAccountsAction {
364383

384+
/**
385+
* Action to indicate that the screen is being launched for the first time.
386+
*/
365387
data object OnFirstLaunched : LoanAccountsAction
366388

367-
/** Dismiss any open dialog */
389+
/**
390+
* Action to dismiss any open dialog.
391+
*/
368392
data object OnDismissDialog : LoanAccountsAction
369393

370-
/** Navigate back from the screen */
394+
/**
395+
* Action to navigate back from the screen.
396+
*/
371397
data object OnNavigateBack : LoanAccountsAction
372398

373-
/** Toggle visibility of loan amount */
399+
/**
400+
* Action to toggle the visibility of the loan amount.
401+
*/
374402
data object ToggleAmountVisible : LoanAccountsAction
375403

404+
/**
405+
* Action to retry a failed operation.
406+
*/
376407
data object OnRetry : LoanAccountsAction
377408

378-
/** Load loan accounts with applied filters */
409+
/**
410+
* Action to load the loan accounts with the given filters.
411+
*
412+
* @param filters The filters to apply.
413+
*/
379414
data class LoadAccounts(
380415
val filters: List<StringResource?>,
381416
) : LoanAccountsAction
382417

383-
/** Navigate to a selected account's detail page */
418+
/**
419+
* Action to handle a click on a loan account.
420+
*
421+
* @param accountId The ID of the clicked account.
422+
* @param accountType The type of the clicked account.
423+
*/
384424
data class OnAccountClicked(
385425
val accountId: Long,
386426
val accountType: String,
387427
) : LoanAccountsAction
388428

389-
/** Action to observe network status */
429+
/**
430+
* Action to receive the network status.
431+
*
432+
* @param isOnline Whether the device is online.
433+
*/
390434
data class ReceiveNetworkStatus(val isOnline: Boolean) : LoanAccountsAction
391435

392436
/**
393437
* Internal-only actions triggered by repository/data flow.
394438
*/
395439
sealed interface Internal : LoanAccountsAction {
396440

397-
/** Called when account data is received from repository */
441+
/**
442+
* Action to receive the loan accounts from the repository.
443+
*
444+
* @param filters The filters that were applied.
445+
* @param dataState The result of the data fetch.
446+
*/
398447
data class ReceiveLoanAccounts(
399448
val filters: List<StringResource?>,
400449
val dataState: DataState<ClientAccounts>,
@@ -403,19 +452,28 @@ sealed interface LoanAccountsAction {
403452
}
404453

405454
/**
406-
* One-time UI events for the Loan Account screen.
455+
* Represents the one-time events that can be sent from the ViewModel to the UI.
407456
*/
408457
sealed interface LoanAccountsEvent {
409458

410-
/** Trigger navigation to selected account's detail screen */
459+
/**
460+
* Event to trigger navigation to the selected account's detail screen.
461+
*
462+
* @param accountId The ID of the clicked account.
463+
* @param accountType The type of the clicked account.
464+
*/
411465
data class AccountClicked(
412466
val accountId: Long,
413467
val accountType: String,
414468
) : LoanAccountsEvent
415469

416-
/** Signals the UI that loading is complete */
470+
/**
471+
* Event to signal that the loading is complete.
472+
*/
417473
data object LoadingCompleted : LoanAccountsEvent
418474

419-
/** Navigates back to the previous screen */
475+
/**
476+
* Event to navigate back to the previous screen.
477+
*/
420478
data object NavigateBack : LoanAccountsEvent
421479
}

feature/loan-account/src/commonMain/kotlin/org/mifos/mobile/feature/loanaccount/loanAccountDetails/LoanAccountDetailsNavigation.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,36 @@ import kotlinx.serialization.Serializable
1818
import org.mifos.mobile.core.model.entity.AccountDetails
1919
import org.mifos.mobile.core.ui.composableWithSlideTransitions
2020

21+
/**
22+
* A route for the loan account details screen.
23+
*
24+
* @property accountId The ID of the loan account.
25+
*/
2126
@Serializable
2227
data class LoanAccountDetailsRoute(
2328
val accountId: Long,
2429
)
2530

31+
/**
32+
* Navigates to the loan account details screen.
33+
*
34+
* @param accountId The ID of the loan account.
35+
* @param navOptions The navigation options.
36+
*/
2637
fun NavController.navigateToLoanAccountDetailsScreen(accountId: Long, navOptions: NavOptions? = null) =
2738
navigate(LoanAccountDetailsRoute(accountId), navOptions)
2839

40+
/**
41+
* Defines the loan account details screen destination in the navigation graph.
42+
*
43+
* @param navigateBack A callback to navigate back to the previous screen.
44+
* @param navigateToMakePaymentScreen A callback to navigate to the make payment screen.
45+
* @param navigateToRepaymentScheduleScreen A callback to navigate to the repayment schedule screen.
46+
* @param navigateToLoanSummaryScreen A callback to navigate to the loan summary screen.
47+
* @param navigateToQrCodeScreen A callback to navigate to the QR code screen.
48+
* @param navigateToClientChargeScreen A callback to navigate to the client charge screen.
49+
* @param navigateToLoanAccountTransactionScreen A callback to navigate to the loan account transaction screen.
50+
*/
2951
fun NavGraphBuilder.loanAccountDetailsDestination(
3052
navigateBack: () -> Unit,
3153
navigateToMakePaymentScreen: (AccountDetails) -> Unit,

0 commit comments

Comments
 (0)