Skip to content

Commit a6d460c

Browse files
feat : bind qr code with savings and loan details screens (#2887)
1 parent c51cab3 commit a6d460c

File tree

15 files changed

+153
-173
lines changed

15 files changed

+153
-173
lines changed

cmp-navigation/src/commonMain/kotlin/cmp/navigation/authenticated/AuthenticatedNavigation.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ internal fun NavGraphBuilder.authenticatedGraph(
124124
navigateToSavingsAccountTransactionScreen = {
125125
navController.navigateToAccountTransactionsScreen(Constants.SAVINGS_ACCOUNT, it)
126126
},
127+
navigateToQrCodeScreen = { navController.navigateToQrDisplayScreen(it) },
127128
)
128129

129130
loanNavGraph(

core/designsystem/src/commonMain/kotlin/org/mifos/mobile/core/designsystem/theme/Type.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,14 @@ object MifosTypography {
242242
fontWeight = FontWeight(700),
243243
)
244244

245+
val titleLargeEmphasized: TextStyle
246+
@Composable get() = TextStyle(
247+
fontSize = 22.sp,
248+
lineHeight = 28.sp,
249+
fontFamily = fontFamily(),
250+
fontWeight = FontWeight(500),
251+
)
252+
245253
// verified
246254
val titleMedium: TextStyle
247255
@Composable get() = TextStyle(

feature/loan-account/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ kotlin {
2929
api(projects.core.ui)
3030
api(projects.core.model)
3131
api(projects.core.common)
32+
implementation(projects.core.qrcode)
3233
}
3334
}
3435
}

feature/loan-account/src/commonMain/kotlin/org/mifos/mobile/feature/loanaccount/savingsAccountDetails/LoanAccountDetailsScreen.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ internal fun LoanAccountDetailsScreen(
9090
navigateToLoanSummaryScreen(uiState.accountId)
9191
}
9292
event.route == Constants.QR_CODE -> {
93-
// TODO Pass actual parsed string
94-
navigateToQrCodeScreen("dummy data")
93+
navigateToQrCodeScreen(viewModel.getQrString())
9594
}
9695
}
9796
}

feature/loan-account/src/commonMain/kotlin/org/mifos/mobile/feature/loanaccount/savingsAccountDetails/LoanAccountDetailsViewModel.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ import org.mifos.mobile.core.common.CurrencyFormatter
2828
import org.mifos.mobile.core.common.DataState
2929
import org.mifos.mobile.core.common.DateHelper
3030
import org.mifos.mobile.core.data.repository.LoanRepository
31+
import org.mifos.mobile.core.datastore.UserPreferencesRepository
3132
import org.mifos.mobile.core.model.entity.accounts.loan.LoanWithAssociations
33+
import org.mifos.mobile.core.model.enums.AccountType
34+
import org.mifos.mobile.core.qr.getAccountDetailsInString
3235
import org.mifos.mobile.core.ui.utils.BaseViewModel
3336
import org.mifos.mobile.feature.loanaccount.component.LoanActionItems
3437
import org.mifos.mobile.feature.loanaccount.component.loanAccountActions
@@ -40,6 +43,7 @@ import org.mifos.mobile.feature.loanaccount.component.loanAccountActions
4043
*/
4144
internal class LoanAccountDetailsViewModel(
4245
private val loanAccountRepositoryImp: LoanRepository,
46+
private val userPreferencesRepository: UserPreferencesRepository,
4347
savedStateHandle: SavedStateHandle,
4448
) : BaseViewModel<LoanAccountDetailsState, LoanAccountDetailsEvent, LoanAccountDetailsAction>(
4549
initialState = run {
@@ -94,6 +98,19 @@ internal class LoanAccountDetailsViewModel(
9498
mutableStateFlow.update { it.copy(dialogState = null) }
9599
}
96100

101+
fun getQrString(): String {
102+
val officeName = userPreferencesRepository.userInfo.value.officeName
103+
return if (officeName.isNotEmpty()) {
104+
return getAccountDetailsInString(
105+
state.accountId.toInt(),
106+
officeName,
107+
AccountType.LOAN.name,
108+
)
109+
} else {
110+
""
111+
}
112+
}
113+
97114
/**
98115
* Processes the loan account result from the repository.
99116
*/

feature/qr/src/commonMain/composeResources/values/strings.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,8 @@
3232
<string name="invalid_qr">You can't make action into your account, please scan other user
3333
Savings and Loans Account QRCode
3434
</string>
35+
<string name="scan_your_qr">Scan your QR</string>
36+
<string name="qr_scan_instruction">Import the account details in your app by scanning this QR code.</string>
37+
<string name="qr_alignment_instruction">Please, align QR Code within the frame to make scanning easily detectable.</string>
38+
<string name="generated_on">Generated on : %s</string>
3539
</resources>

feature/qr/src/commonMain/kotlin/org/mifos/mobile/feature/qr/navigation/QrNavGraph.kt

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,46 @@ package org.mifos.mobile.feature.qr.navigation
1111

1212
import androidx.navigation.NavController
1313
import androidx.navigation.NavGraphBuilder
14-
import androidx.navigation.NavType
14+
import androidx.navigation.NavOptions
1515
import androidx.navigation.compose.composable
1616
import androidx.navigation.compose.navigation
17-
import androidx.navigation.navArgument
17+
import kotlinx.serialization.Serializable
1818
import org.mifos.mobile.core.model.entity.beneficiary.Beneficiary
1919
import org.mifos.mobile.core.model.enums.BeneficiaryState
2020
import org.mifos.mobile.feature.qr.qr.QrCodeReaderScreen
2121
import org.mifos.mobile.feature.qr.qrCodeDisplay.QrCodeDisplayScreen
2222
import org.mifos.mobile.feature.qr.qrCodeImport.QrCodeImportScreen
2323

24-
fun NavController.navigateToQrDisplayScreen(qrString: String) {
25-
navigate(QrNavigation.QrDisplayScreen.passArguments(qrString = qrString))
24+
@Serializable
25+
data object QrGraphRoute
26+
27+
@Serializable
28+
data object QrReaderScreenRoute
29+
30+
@Serializable
31+
data class QrDisplayScreenRoute(val qrString: String = "")
32+
33+
@Serializable
34+
data object QrImportScreenRoute
35+
36+
fun NavController.navigateToQrReaderScreen(navOptions: NavOptions? = null) {
37+
this.navigate(QrReaderScreenRoute, navOptions)
2638
}
2739

28-
fun NavController.navigateToQrImportScreen() {
29-
navigate(QrNavigation.QrImportScreen.route)
40+
fun NavController.navigateToQrImportScreen(navOptions: NavOptions? = null) {
41+
this.navigate(QrImportScreenRoute, navOptions)
3042
}
3143

32-
fun NavController.navigateToQrReaderScreen() {
33-
navigate(QrNavigation.QrReaderScreen.route)
44+
fun NavController.navigateToQrDisplayScreen(qrString: String, navOptions: NavOptions? = null) {
45+
this.navigate(QrDisplayScreenRoute(qrString), navOptions)
3446
}
3547

3648
fun NavGraphBuilder.qrNavGraph(
3749
navController: NavController,
3850
openBeneficiaryApplication: (Beneficiary, BeneficiaryState) -> Unit,
3951
) {
40-
navigation(
41-
startDestination = QrNavigation.QrDisplayScreen.route,
42-
route = QrNavigation.QrBase.route,
52+
navigation<QrGraphRoute>(
53+
startDestination = QrDisplayScreenRoute(),
4354
) {
4455
readerRoute(
4556
navigateBack = navController::popBackStack,
@@ -61,7 +72,7 @@ fun NavGraphBuilder.readerRoute(
6172
navigateBack: () -> Unit,
6273
openBeneficiaryApplication: (Beneficiary, BeneficiaryState) -> Unit,
6374
) {
64-
composable(route = QrNavigation.QrReaderScreen.route) {
75+
composable<QrReaderScreenRoute> {
6576
QrCodeReaderScreen(
6677
navigateBack = navigateBack,
6778
openBeneficiaryApplication = openBeneficiaryApplication,
@@ -72,12 +83,7 @@ fun NavGraphBuilder.readerRoute(
7283
fun NavGraphBuilder.displayRoute(
7384
navigateBack: () -> Unit,
7485
) {
75-
composable(
76-
route = QrNavigation.QrDisplayScreen.route,
77-
arguments = listOf(
78-
navArgument(name = QR_ARGS) { type = NavType.StringType },
79-
),
80-
) {
86+
composable<QrDisplayScreenRoute> {
8187
QrCodeDisplayScreen(
8288
navigateBack = navigateBack,
8389
)
@@ -88,7 +94,7 @@ fun NavGraphBuilder.importRoute(
8894
navigateBack: () -> Unit,
8995
openBeneficiaryApplication: (Beneficiary, BeneficiaryState) -> Unit,
9096
) {
91-
composable(route = QrNavigation.QrImportScreen.route) {
97+
composable<QrImportScreenRoute> {
9298
QrCodeImportScreen(
9399
navigateBack = navigateBack,
94100
openBeneficiaryApplication = openBeneficiaryApplication,

feature/qr/src/commonMain/kotlin/org/mifos/mobile/feature/qr/navigation/QrNavigationScreen.kt

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)