Skip to content

Commit

Permalink
refactor: transfer process complex args (#2666)
Browse files Browse the repository at this point in the history
  • Loading branch information
AvneetSingh2001 authored Aug 11, 2024
1 parent cbb30d3 commit b4d5463
Show file tree
Hide file tree
Showing 27 changed files with 310 additions and 119 deletions.
11 changes: 7 additions & 4 deletions app/src/main/java/org/mifos/mobile/navigation/MifosNavGraph.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,16 @@ import org.mifos.mobile.feature.savings.navigation.navigateToSavingsApplicationS
import org.mifos.mobile.feature.savings.navigation.navigateToSavingsDetailScreen
import org.mifos.mobile.feature.savings.navigation.navigateToSavingsMakeTransfer
import org.mifos.mobile.feature.savings.navigation.savingsNavGraph
import org.mifos.mobile.feature.savings.savings_make_transfer.SavingsMakeTransferScreen
import org.mifos.mobile.feature.transfer.process.navigation.navigateToTransferProcessScreen
import org.mifos.mobile.ui.activities.PassCodeActivity
import org.mifos.mobile.ui.activities.PrivacyPolicyActivity
import android.provider.Settings
import android.widget.Toast
import org.mifos.mobile.R
import org.mifos.mobile.core.common.Constants
import org.mifos.mobile.core.common.Constants.TRANSFER_PAY_FROM
import org.mifos.mobile.core.common.Constants.TRANSFER_PAY_TO
import org.mifos.mobile.core.model.enums.TransferType
import org.mifos.mobile.ui.activities.HomeActivity


Expand Down Expand Up @@ -119,7 +122,7 @@ fun RootNavGraph(
thirdPartyTransferNavGraph(
navController = navController,
addBeneficiary = navController::navigateToAddBeneficiaryScreen,
reviewTransfer = { } // navigate To Transfer Process Screen with payload
reviewTransfer = navController::navigateToTransferProcessScreen
)

settingsNavGraph(
Expand Down Expand Up @@ -178,7 +181,7 @@ fun RootNavGraph(
viewCharges = navController::navigateToClientChargeScreen,
viewQrCode = navController::navigateToQrDisplayScreen,
callHelpline = { callHelpline(context) },
reviewTransfer = { } // navigate To Transfer Process Screen with payload
reviewTransfer = navController::navigateToTransferProcessScreen
)

clientAccountsNavGraph(
Expand Down Expand Up @@ -215,7 +218,7 @@ fun handleHomeNavigation(
HomeDestinations.SHARE -> { shareApp(context) }
HomeDestinations.APP_INFO -> { openAppInfo(context) }
HomeDestinations.LOGOUT -> navController.navigateToLoginScreen()
HomeDestinations.TRANSFER -> navController.navigateToTransferProcessScreen()
HomeDestinations.TRANSFER -> navController.navigateToSavingsMakeTransfer(accountId = 1, transferType = TRANSFER_PAY_TO)
HomeDestinations.BENEFICIARIES -> navController.navigateToBeneficiaryListScreen()
HomeDestinations.SURVEY -> Unit
HomeDestinations.NOTIFICATIONS -> navController.navigateToNotificationScreen()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ class LoanApplicationFragment : BaseFragment() {
savedInstanceState: Bundle?,
): View {
return mifosComposeView(requireContext()) {
LoanApplicationScreen(
navigateBack = { activity?.finish() },
reviewNewLoanApplication = { reviewNewLoanApplication() },
submitUpdateLoanApplication = { submitUpdateLoanApplication() }
)

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,16 @@ class ReviewLoanApplicationFragment : BaseFragment() {
(activity as? BaseActivity)?.hideToolbar()
val loanState =
arguments?.getCheckedSerializable(LoanState::class.java, LOAN_STATE) as LoanState
viewModel.insertData(
loanState = loanState,
loansPayload = arguments?.getCheckedParcelable(
LoansPayload::class.java,
LOANS_PAYLOAD
)!!,
loanName = arguments?.getString(LOAN_NAME),
accountNo = arguments?.getString(ACCOUNT_NO),
loanId = arguments?.getLong(LOAN_ID),
)
// viewModel.insertData(
// loanState = loanState,
// loansPayload = arguments?.getCheckedParcelable(
// LoansPayload::class.java,
// LOANS_PAYLOAD
// )!!,
// loanName = arguments?.getString(LOAN_NAME),
// accountNo = arguments?.getString(ACCOUNT_NO),
// loanId = arguments?.getLong(LOAN_ID),
// )
return ComposeView(requireContext()).apply {
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
setContent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import org.mifos.mobile.ui.transfer_process.TransferProcessComposeFragment
import org.mifos.mobile.core.model.entity.payload.TransferPayload
import org.mifos.mobile.core.common.utils.DateHelper
import org.mifos.mobile.core.common.utils.getTodayFormatted
import org.mifos.mobile.feature.savings.savings_make_transfer.ReviewTransferPayload
import org.mifos.mobile.core.model.entity.payload.ReviewTransferPayload
import org.mifos.mobile.feature.savings.savings_make_transfer.SavingsMakeTransferScreen
import org.mifos.mobile.feature.savings.savings_make_transfer.SavingsMakeTransferViewModel

Expand All @@ -37,11 +37,11 @@ class SavingsMakeTransferComposeFragment : BaseFragment() {
savedInstanceState: Bundle?,
): View {
return mifosComposeView(requireContext()) {
SavingsMakeTransferScreen(
navigateBack = { activity?.onBackPressedDispatcher?.onBackPressed() },
onCancelledClicked = { activity?.onBackPressedDispatcher?.onBackPressed() },
reviewTransfer = { reviewTransfer(payload = it) }
)
// SavingsMakeTransferScreen(
// navigateBack = { activity?.onBackPressedDispatcher?.onBackPressed() },
// onCancelledClicked = { activity?.onBackPressedDispatcher?.onBackPressed() },
// reviewTransfer = { reviewTransfer(payload = it) }
// )
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ class ThirdPartyTransferComposeFragment : BaseFragment() {
): View {
(activity as? BaseActivity)?.hideToolbar()
return mifosComposeView(requireContext()) {
ThirdPartyTransferScreen(
navigateBack = { activity?.onBackPressed() },
addBeneficiary = { addBeneficiary() },
reviewTransfer = { reviewTransfer(it) }
)

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@ class TransferProcessComposeFragment : BaseFragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (activity != null) {
arguments?.getCheckedParcelable(TransferPayload::class.java, Constants.PAYLOAD)?.let {
viewModel.setContent(it)
}
(arguments?.getCheckedSerializable(TransferType::class.java, Constants.TRANSFER_TYPE) as TransferType).let {
viewModel.setTransferType(it)
}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ object Constants {
const val CLIENT_ID = "clientId"
const val ACCOUNT_ID = "accountId"
const val LOAN_ID = "loanId"
const val LOAN_NAME = "loanName"
const val SAVINGS_ID = "savingsId"
const val ACCOUNT_NUMBER = "accountNo"
const val BASIC = "Basic "
const val BACK_SLASH = "/"
const val SAVINGS_ACCOUNTS = "savingsAccounts"
Expand All @@ -27,6 +29,7 @@ object Constants {
const val LOAN_STATE = "loanType"
const val LOAN_ACCOUNT = "loanAccount"
const val PAYLOAD = "payload"
const val LOANS_PAYLOAD = "loans_payload"
const val REQUEST_PERMISSION_SETTING = 254
const val PERMISSIONS_REQUEST_CAMERA = 1
const val PERMISSIONS_REQUEST_READ_PHONE_STATE = 2
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.mifos.mobile.core.model.entity.payload

import org.mifos.mobile.core.model.entity.templates.account.AccountOption

data class ReviewTransferPayload(
var payToAccount: AccountOption? = null,
var payFromAccount: AccountOption? = null,
var amount: String = "",
var review: String = ""
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Card
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
Expand All @@ -26,26 +27,30 @@ fun TransferDialog(
navigateToThirdPartyTransfer: () -> Unit
) {
Dialog(onDismissRequest = onDismissRequest) {
Surface {
Card {
Column(
modifier = Modifier
.fillMaxWidth()
.padding(all = 20.dp),
) {
Text(
text = stringResource(id = R.string.transfer),
modifier = Modifier.clickable {
navigateToTransfer()
}
modifier = Modifier
.fillMaxWidth()
.clickable {
navigateToTransfer()
}
)
Spacer(modifier = Modifier.height(20.dp))
HorizontalDivider()
Spacer(modifier = Modifier.height(20.dp))
Text(
text = stringResource(id = R.string.third_party_transfer),
modifier = Modifier.clickable {
navigateToThirdPartyTransfer()
}
modifier = Modifier
.fillMaxWidth()
.clickable {
navigateToThirdPartyTransfer()
}
)
}
}
Expand Down
1 change: 1 addition & 0 deletions feature/loan/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencies {
implementation(projects.core.model)
implementation(projects.core.data)
implementation(projects.feature.qr)
implementation(libs.squareup.retrofit.converter.gson)

testImplementation(libs.junit)
androidTestImplementation(libs.androidx.test.ext.junit)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.mifos.mobile.feature.loan.loan_account_application

import android.content.Context
import androidx.compose.animation.core.updateTransition
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
Expand All @@ -18,25 +20,30 @@ import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.google.gson.Gson
import org.mifos.mobile.core.ui.component.MifosErrorComponent
import org.mifos.mobile.core.ui.component.MifosProgressIndicatorOverlay
import org.mifos.mobile.core.ui.component.MifosTopBar
import org.mifos.mobile.core.ui.theme.MifosMobileTheme
import org.mifos.mobile.core.common.Network
import org.mifos.mobile.core.common.utils.DateHelper
import org.mifos.mobile.core.model.entity.payload.LoansPayload
import org.mifos.mobile.core.model.enums.LoanState
import org.mifos.mobile.feature.loan.R
import org.mifos.mobile.feature.loan.navigation.LoanRoute


@Composable
fun LoanApplicationScreen(
viewModel: LoanApplicationViewModel = hiltViewModel(),
navigateBack: () -> Unit,
reviewNewLoanApplication: () -> Unit,
submitUpdateLoanApplication: () -> Unit
reviewNewLoanApplication: (loanState: LoanState, loansPayloadString: String, loanId: Long?, loanName: String, accountNo: String) -> Unit,
submitUpdateLoanApplication: (loanState: LoanState, loansPayloadString: String, loanId: Long?, loanName: String, accountNo: String) -> Unit,
) {
val uiState by viewModel.loanUiState.collectAsStateWithLifecycle()
val uiData by viewModel.loanApplicationScreenData.collectAsStateWithLifecycle()
val loanState by viewModel.loanState.collectAsStateWithLifecycle()
val context = LocalContext.current

LaunchedEffect(key1 = loanState) {
viewModel.loadLoanApplicationTemplate(loanState)
Expand All @@ -53,8 +60,13 @@ fun LoanApplicationScreen(
setDisbursementDate = { viewModel.setDisburseDate(it) },
reviewClicked = {
viewModel.setPrincipalAmount(it)
if (loanState == LoanState.CREATE) reviewNewLoanApplication()
else submitUpdateLoanApplication()
getLoanPayload(
context = context,
loanState = loanState,
reviewNewLoanApplication = reviewNewLoanApplication,
submitUpdateLoanApplication = submitUpdateLoanApplication,
viewModel = viewModel
)
}
)
}
Expand Down Expand Up @@ -149,3 +161,51 @@ fun ReviewLoanApplicationScreenPreview(
}
}

private fun getLoanPayload(
context: Context,
viewModel: LoanApplicationViewModel,
loanState: LoanState,
reviewNewLoanApplication: (loanState: LoanState, loansPayloadString: String, loanId: Long?, loanName: String, accountNo: String) -> Unit,
submitUpdateLoanApplication: (loanState: LoanState, loansPayloadString: String, loanId: Long?, loanName: String, accountNo: String) -> Unit,
) {
val payload = LoansPayload().apply {
clientId = viewModel.loanTemplate.clientId.takeIf { loanState == LoanState.CREATE }
loanPurpose = viewModel.loanApplicationScreenData.value.selectedLoanPurpose ?: "Not provided"
productName = viewModel.loanApplicationScreenData.value.selectedLoanProduct
currency = viewModel.loanApplicationScreenData.value.currencyLabel
if (viewModel.purposeId > 0) loanPurposeId = viewModel.purposeId
productId = viewModel.productId
principal = viewModel.loanApplicationScreenData.value.principalAmount?.toDoubleOrNull() ?: 0.0
loanTermFrequency = viewModel.loanTemplate.termFrequency
loanTermFrequencyType = viewModel.loanTemplate.interestRateFrequencyType?.id
loanType = "individual".takeIf { loanState == LoanState.CREATE }
numberOfRepayments = viewModel.loanTemplate.numberOfRepayments
repaymentEvery = viewModel.loanTemplate.repaymentEvery
repaymentFrequencyType = viewModel.loanTemplate.interestRateFrequencyType?.id
interestRatePerPeriod = viewModel.loanTemplate.interestRatePerPeriod
expectedDisbursementDate = DateHelper.getSpecificFormat(DateHelper.FORMAT_dd_MMMM_yyyy, viewModel.loanApplicationScreenData.value.disbursementDate)
submittedOnDate = DateHelper.getSpecificFormat(DateHelper.FORMAT_dd_MMMM_yyyy, viewModel.loanApplicationScreenData.value.submittedDate).takeIf { loanState == LoanState.CREATE }
transactionProcessingStrategyId = viewModel.loanTemplate.transactionProcessingStrategyId
amortizationType = viewModel.loanTemplate.amortizationType?.id
interestCalculationPeriodType = viewModel.loanTemplate.interestCalculationPeriodType?.id
interestType = viewModel.loanTemplate.interestType?.id
}

val loansPayloadString = Gson().toJson(payload)
when(loanState) {
LoanState.CREATE -> reviewNewLoanApplication(
loanState,
loansPayloadString,
viewModel.loanId.value,
context.getString(R.string.string_and_string, context.getString(R.string.new_loan_application) + " ", viewModel.loanApplicationScreenData.value.clientName ?: ""),
context.getString(R.string.string_and_string, context.getString(R.string.account_number) + " ", viewModel.loanApplicationScreenData.value.accountNumber ?: "")
)
LoanState.UPDATE -> submitUpdateLoanApplication(
loanState,
loansPayloadString,
null,
context.getString(R.string.string_and_string, context.getString(R.string.update_loan_application) + " ", viewModel.loanApplicationScreenData.value.clientName ?: ""),
context.getString(R.string.string_and_string, context.getString(R.string.account_number) + " ", viewModel.loanApplicationScreenData.value.accountNumber ?: "")
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.mifos.mobile.core.common.utils.getTodayFormatted
import org.mifos.mobile.core.network.Result
import org.mifos.mobile.core.data.repositories.LoanRepository
import org.mifos.mobile.core.model.entity.accounts.loan.LoanWithAssociations
import org.mifos.mobile.core.model.entity.payload.LoansPayload
import org.mifos.mobile.core.model.entity.templates.loans.LoanTemplate
import org.mifos.mobile.core.model.enums.ChargeType
import org.mifos.mobile.core.model.enums.LoanState
Expand Down Expand Up @@ -239,6 +240,7 @@ class LoanApplicationViewModel @Inject constructor(
fun setPrincipalAmount(amount: String) {
_loanApplicationScreenData.update { it.copy(principalAmount = amount) }
}

}

data class LoanApplicationScreenData(
Expand Down
Loading

0 comments on commit b4d5463

Please sign in to comment.