From 2a4b2f44e514529c0e7accb76b43a761acf5f580 Mon Sep 17 00:00:00 2001 From: Hekmatullah Date: Wed, 5 Mar 2025 23:29:01 +0000 Subject: [PATCH 1/2] refactor: Fix dynamic account selection and Decimal Support in Transactions (#2795) --- .../mifos/mobile/navigation/MifosNavHost.kt | 2 + .../org/mifos/mobile/core/common/Constants.kt | 1 + .../data/repository/BeneficiaryRepository.kt | 2 +- .../repository/SavingsAccountRepository.kt | 2 +- .../ThirdPartyTransferRepository.kt | 2 +- .../data/repository/TransferRepository.kt | 2 - .../BeneficiaryRepositoryImp.kt | 10 +- .../SavingsAccountRepositoryImp.kt | 20 ++-- .../ThirdPartyTransferRepositoryImp.kt | 10 +- .../repositoryImpl/TransferRepositoryImp.kt | 4 - .../model/entity/accounts/loan/LoanAccount.kt | 1 - .../model/entity/payload/TransferPayload.kt | 2 - .../account/AccountOptionsTemplate.kt | 4 - .../org/mifos/mobile/core/network/BaseURL.kt | 3 +- .../mifos/mobile/core/network/DataManager.kt | 7 +- .../services/SavingAccountsListService.kt | 5 +- fastlane-config/android_config.rb | 3 +- .../loanAccount/LoanAccountDetailScreen.kt | 9 +- .../feature/loan/navigation/LoanNavGraph.kt | 15 ++- .../savings/navigation/SavingsNavGraph.kt | 12 ++- .../savings/navigation/SavingsNavigation.kt | 15 ++- .../SavingsMakeTransferContent.kt | 8 +- .../SavingsMakeTransferScreen.kt | 39 ++++---- .../SavingsMakeTransferViewModel.kt | 94 +++++++++++-------- .../transfer/ThirdPartyTransferContent.kt | 6 +- .../transfer/ThirdPartyTransferScreen.kt | 12 +-- .../transfer/ThirdPartyTransferViewModel.kt | 72 ++++++-------- .../transfer/process/TransferProcessScreen.kt | 8 +- .../process/TransferProcessViewModel.kt | 2 - .../navigation/TransferProcessNavGraph.kt | 4 +- 30 files changed, 207 insertions(+), 169 deletions(-) diff --git a/androidApp/src/main/kotlin/org/mifos/mobile/navigation/MifosNavHost.kt b/androidApp/src/main/kotlin/org/mifos/mobile/navigation/MifosNavHost.kt index b20e61001..346133b6d 100644 --- a/androidApp/src/main/kotlin/org/mifos/mobile/navigation/MifosNavHost.kt +++ b/androidApp/src/main/kotlin/org/mifos/mobile/navigation/MifosNavHost.kt @@ -28,6 +28,7 @@ import org.mifos.mobile.R import org.mifos.mobile.core.common.Constants.TRANSFER_PAY_TO import org.mifos.mobile.core.model.enums.AccountType import org.mifos.mobile.core.model.enums.ChargeType +import org.mifos.mobile.core.model.enums.TransferType import org.mifos.mobile.feature.about.navigation.aboutUsNavGraph import org.mifos.mobile.feature.about.navigation.navigateToAboutUsScreen import org.mifos.mobile.feature.account.navigation.clientAccountsNavGraph @@ -228,6 +229,7 @@ fun handleHomeNavigation( HomeDestinations.TRANSFER -> navController.navigateToSavingsMakeTransfer( accountId = 1, transferType = TRANSFER_PAY_TO, + transferTarget = TransferType.SELF, ) HomeDestinations.BENEFICIARIES -> navController.navigateToBeneficiaryListScreen() diff --git a/core/common/src/main/java/org/mifos/mobile/core/common/Constants.kt b/core/common/src/main/java/org/mifos/mobile/core/common/Constants.kt index d8d0c0645..095bead31 100644 --- a/core/common/src/main/java/org/mifos/mobile/core/common/Constants.kt +++ b/core/common/src/main/java/org/mifos/mobile/core/common/Constants.kt @@ -28,6 +28,7 @@ object Constants { const val TRANSACTIONS = "transactions" const val DFRAG_DATE_PICKER = "Date Picker" const val TRANSFER_TYPE = "transfer_type" + const val TRANSFER_TARGET = "transfer_target" const val TRANSFER_QUICK = "transfer_quick" const val TRANSFER_PAY_TO = "transfer_pay_to" const val TRANSFER_PAY_FROM = "transfer_pay_from" diff --git a/core/data/src/main/java/org/mifos/mobile/core/data/repository/BeneficiaryRepository.kt b/core/data/src/main/java/org/mifos/mobile/core/data/repository/BeneficiaryRepository.kt index fcb3bc06f..33671fe96 100644 --- a/core/data/src/main/java/org/mifos/mobile/core/data/repository/BeneficiaryRepository.kt +++ b/core/data/src/main/java/org/mifos/mobile/core/data/repository/BeneficiaryRepository.kt @@ -29,5 +29,5 @@ interface BeneficiaryRepository { suspend fun deleteBeneficiary(beneficiaryId: Long?): Flow - suspend fun beneficiaryList(): Flow> + fun beneficiaryList(): Flow> } diff --git a/core/data/src/main/java/org/mifos/mobile/core/data/repository/SavingsAccountRepository.kt b/core/data/src/main/java/org/mifos/mobile/core/data/repository/SavingsAccountRepository.kt index 0d9872b31..70bd4eca4 100644 --- a/core/data/src/main/java/org/mifos/mobile/core/data/repository/SavingsAccountRepository.kt +++ b/core/data/src/main/java/org/mifos/mobile/core/data/repository/SavingsAccountRepository.kt @@ -39,5 +39,5 @@ interface SavingsAccountRepository { payload: SavingsAccountWithdrawPayload?, ): Flow - fun accountTransferTemplate(accountId: Long?, accountType: Long?): Flow + fun accountTransferTemplate(): Flow } diff --git a/core/data/src/main/java/org/mifos/mobile/core/data/repository/ThirdPartyTransferRepository.kt b/core/data/src/main/java/org/mifos/mobile/core/data/repository/ThirdPartyTransferRepository.kt index 0d2f81b10..4f67419c3 100644 --- a/core/data/src/main/java/org/mifos/mobile/core/data/repository/ThirdPartyTransferRepository.kt +++ b/core/data/src/main/java/org/mifos/mobile/core/data/repository/ThirdPartyTransferRepository.kt @@ -14,5 +14,5 @@ import org.mifos.mobile.core.model.entity.templates.account.AccountOptionsTempla interface ThirdPartyTransferRepository { - suspend fun thirdPartyTransferTemplate(): Flow + fun thirdPartyTransferTemplate(): Flow } diff --git a/core/data/src/main/java/org/mifos/mobile/core/data/repository/TransferRepository.kt b/core/data/src/main/java/org/mifos/mobile/core/data/repository/TransferRepository.kt index a5324eead..d8c5c235f 100644 --- a/core/data/src/main/java/org/mifos/mobile/core/data/repository/TransferRepository.kt +++ b/core/data/src/main/java/org/mifos/mobile/core/data/repository/TransferRepository.kt @@ -29,8 +29,6 @@ interface TransferRepository { transferDescription: String?, dateFormat: String = "dd MMMM yyyy", locale: String = "en", - fromAccountNumber: String?, - toAccountNumber: String?, transferType: TransferType?, ): Flow } diff --git a/core/data/src/main/java/org/mifos/mobile/core/data/repositoryImpl/BeneficiaryRepositoryImp.kt b/core/data/src/main/java/org/mifos/mobile/core/data/repositoryImpl/BeneficiaryRepositoryImp.kt index c76e79cfb..9d00cb25f 100644 --- a/core/data/src/main/java/org/mifos/mobile/core/data/repositoryImpl/BeneficiaryRepositoryImp.kt +++ b/core/data/src/main/java/org/mifos/mobile/core/data/repositoryImpl/BeneficiaryRepositoryImp.kt @@ -9,9 +9,13 @@ */ package org.mifos.mobile.core.data.repositoryImpl +import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow +import kotlinx.coroutines.flow.flowOn import okhttp3.ResponseBody +import org.mifos.mobile.core.common.network.Dispatcher +import org.mifos.mobile.core.common.network.MifosDispatchers import org.mifos.mobile.core.data.repository.BeneficiaryRepository import org.mifos.mobile.core.model.entity.beneficiary.Beneficiary import org.mifos.mobile.core.model.entity.beneficiary.BeneficiaryPayload @@ -22,6 +26,8 @@ import javax.inject.Inject class BeneficiaryRepositoryImp @Inject constructor( private val dataManager: DataManager, + @Dispatcher(MifosDispatchers.IO) + private val ioDispatcher: CoroutineDispatcher, ) : BeneficiaryRepository { override suspend fun beneficiaryTemplate(): Flow { @@ -51,9 +57,9 @@ class BeneficiaryRepositoryImp @Inject constructor( } } - override suspend fun beneficiaryList(): Flow> { + override fun beneficiaryList(): Flow> { return flow { emit(dataManager.beneficiaryList()) - } + }.flowOn(ioDispatcher) } } diff --git a/core/data/src/main/java/org/mifos/mobile/core/data/repositoryImpl/SavingsAccountRepositoryImp.kt b/core/data/src/main/java/org/mifos/mobile/core/data/repositoryImpl/SavingsAccountRepositoryImp.kt index e02331a7e..a56d444f5 100644 --- a/core/data/src/main/java/org/mifos/mobile/core/data/repositoryImpl/SavingsAccountRepositoryImp.kt +++ b/core/data/src/main/java/org/mifos/mobile/core/data/repositoryImpl/SavingsAccountRepositoryImp.kt @@ -9,9 +9,13 @@ */ package org.mifos.mobile.core.data.repositoryImpl +import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow +import kotlinx.coroutines.flow.flowOn import okhttp3.ResponseBody +import org.mifos.mobile.core.common.network.Dispatcher +import org.mifos.mobile.core.common.network.MifosDispatchers import org.mifos.mobile.core.data.repository.SavingsAccountRepository import org.mifos.mobile.core.model.entity.accounts.savings.SavingsAccountApplicationPayload import org.mifos.mobile.core.model.entity.accounts.savings.SavingsAccountUpdatePayload @@ -24,6 +28,8 @@ import javax.inject.Inject class SavingsAccountRepositoryImp @Inject constructor( private val dataManager: DataManager, + @Dispatcher(MifosDispatchers.IO) + private val ioDispatcher: CoroutineDispatcher, ) : SavingsAccountRepository { override suspend fun getSavingsWithAssociations( @@ -69,17 +75,9 @@ class SavingsAccountRepositoryImp @Inject constructor( } } - override fun accountTransferTemplate( - accountId: Long?, - accountType: Long?, - ): Flow { + override fun accountTransferTemplate(): Flow { return flow { - emit( - dataManager.accountTransferTemplate( - accountId = accountType, - accountType = accountType, - ), - ) - } + emit(dataManager.accountTransferTemplate()) + }.flowOn(ioDispatcher) } } diff --git a/core/data/src/main/java/org/mifos/mobile/core/data/repositoryImpl/ThirdPartyTransferRepositoryImp.kt b/core/data/src/main/java/org/mifos/mobile/core/data/repositoryImpl/ThirdPartyTransferRepositoryImp.kt index 71012eb76..7a06bb1e7 100644 --- a/core/data/src/main/java/org/mifos/mobile/core/data/repositoryImpl/ThirdPartyTransferRepositoryImp.kt +++ b/core/data/src/main/java/org/mifos/mobile/core/data/repositoryImpl/ThirdPartyTransferRepositoryImp.kt @@ -9,8 +9,12 @@ */ package org.mifos.mobile.core.data.repositoryImpl +import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow +import kotlinx.coroutines.flow.flowOn +import org.mifos.mobile.core.common.network.Dispatcher +import org.mifos.mobile.core.common.network.MifosDispatchers import org.mifos.mobile.core.data.repository.ThirdPartyTransferRepository import org.mifos.mobile.core.model.entity.templates.account.AccountOptionsTemplate import org.mifos.mobile.core.network.DataManager @@ -18,11 +22,13 @@ import javax.inject.Inject class ThirdPartyTransferRepositoryImp @Inject constructor( private val dataManager: DataManager, + @Dispatcher(MifosDispatchers.IO) + private val ioDispatcher: CoroutineDispatcher, ) : ThirdPartyTransferRepository { - override suspend fun thirdPartyTransferTemplate(): Flow { + override fun thirdPartyTransferTemplate(): Flow { return flow { emit(dataManager.thirdPartyTransferTemplate()) - } + }.flowOn(ioDispatcher) } } diff --git a/core/data/src/main/java/org/mifos/mobile/core/data/repositoryImpl/TransferRepositoryImp.kt b/core/data/src/main/java/org/mifos/mobile/core/data/repositoryImpl/TransferRepositoryImp.kt index 61d4495b5..7fe5eea88 100644 --- a/core/data/src/main/java/org/mifos/mobile/core/data/repositoryImpl/TransferRepositoryImp.kt +++ b/core/data/src/main/java/org/mifos/mobile/core/data/repositoryImpl/TransferRepositoryImp.kt @@ -35,8 +35,6 @@ class TransferRepositoryImp @Inject constructor( transferDescription: String?, dateFormat: String, locale: String, - fromAccountNumber: String?, - toAccountNumber: String?, transferType: TransferType?, ): Flow { val transferPayload = TransferPayload().apply { @@ -53,8 +51,6 @@ class TransferRepositoryImp @Inject constructor( this.transferDescription = transferDescription this.dateFormat = dateFormat this.locale = locale - this.fromAccountNumber = fromAccountNumber - this.toAccountNumber = toAccountNumber } return flow { emit( diff --git a/core/model/src/main/java/org/mifos/mobile/core/model/entity/accounts/loan/LoanAccount.kt b/core/model/src/main/java/org/mifos/mobile/core/model/entity/accounts/loan/LoanAccount.kt index 432c21cfa..2def6e387 100644 --- a/core/model/src/main/java/org/mifos/mobile/core/model/entity/accounts/loan/LoanAccount.kt +++ b/core/model/src/main/java/org/mifos/mobile/core/model/entity/accounts/loan/LoanAccount.kt @@ -80,7 +80,6 @@ data class LoanAccount( parcel.readString(), parcel.readParcelable(Timeline::class.java.classLoader), ) - override fun writeToParcel(parcel: Parcel, flags: Int) { parcel.writeLong(loanProductId) parcel.writeString(externalId) diff --git a/core/model/src/main/java/org/mifos/mobile/core/model/entity/payload/TransferPayload.kt b/core/model/src/main/java/org/mifos/mobile/core/model/entity/payload/TransferPayload.kt index 2144c423c..93fe01bf0 100644 --- a/core/model/src/main/java/org/mifos/mobile/core/model/entity/payload/TransferPayload.kt +++ b/core/model/src/main/java/org/mifos/mobile/core/model/entity/payload/TransferPayload.kt @@ -44,10 +44,8 @@ data class TransferPayload( var locale: String = "en", - @Transient var fromAccountNumber: String? = null, - @Transient var toAccountNumber: String? = null, ) : Parcelable diff --git a/core/model/src/main/java/org/mifos/mobile/core/model/entity/templates/account/AccountOptionsTemplate.kt b/core/model/src/main/java/org/mifos/mobile/core/model/entity/templates/account/AccountOptionsTemplate.kt index 463ab71c9..4994528bf 100644 --- a/core/model/src/main/java/org/mifos/mobile/core/model/entity/templates/account/AccountOptionsTemplate.kt +++ b/core/model/src/main/java/org/mifos/mobile/core/model/entity/templates/account/AccountOptionsTemplate.kt @@ -22,8 +22,4 @@ data class AccountOptionsTemplate( var fromAccountOptions: List = ArrayList(), var toAccountOptions: List = ArrayList(), - - var fromAccountTypeOptions: List = ArrayList(), - - var toAccountTypeOptions: List = ArrayList(), ) : Parcelable diff --git a/core/network/src/main/java/org/mifos/mobile/core/network/BaseURL.kt b/core/network/src/main/java/org/mifos/mobile/core/network/BaseURL.kt index 7eab492e3..a38e7d7fe 100644 --- a/core/network/src/main/java/org/mifos/mobile/core/network/BaseURL.kt +++ b/core/network/src/main/java/org/mifos/mobile/core/network/BaseURL.kt @@ -21,7 +21,8 @@ class BaseURL { } companion object { - const val API_ENDPOINT = "gsoc.mifos.community" +// const val API_ENDPOINT = "gsoc.mifos.community" + const val API_ENDPOINT = "tt.mifos.community" const val API_PATH = "/fineract-provider/api/v1/" const val PROTOCOL_HTTPS = "https://" } diff --git a/core/network/src/main/java/org/mifos/mobile/core/network/DataManager.kt b/core/network/src/main/java/org/mifos/mobile/core/network/DataManager.kt index c2b84bdaa..f92693c31 100644 --- a/core/network/src/main/java/org/mifos/mobile/core/network/DataManager.kt +++ b/core/network/src/main/java/org/mifos/mobile/core/network/DataManager.kt @@ -110,11 +110,8 @@ class DataManager @Inject constructor( ) } - suspend fun accountTransferTemplate( - accountId: Long?, - accountType: Long?, - ): AccountOptionsTemplate = - baseApiManager.savingAccountsListApi.accountTransferTemplate(accountId, accountType) + suspend fun accountTransferTemplate(): AccountOptionsTemplate = + baseApiManager.savingAccountsListApi.accountTransferTemplate() suspend fun makeTransfer(transferPayload: TransferPayload?): ResponseBody { return baseApiManager.savingAccountsListApi.makeTransfer(transferPayload) diff --git a/core/network/src/main/java/org/mifos/mobile/core/network/services/SavingAccountsListService.kt b/core/network/src/main/java/org/mifos/mobile/core/network/services/SavingAccountsListService.kt index 4cf293164..3b03d27bb 100644 --- a/core/network/src/main/java/org/mifos/mobile/core/network/services/SavingAccountsListService.kt +++ b/core/network/src/main/java/org/mifos/mobile/core/network/services/SavingAccountsListService.kt @@ -33,10 +33,7 @@ interface SavingAccountsListService { ): SavingsWithAssociations @GET(ApiEndPoints.ACCOUNT_TRANSFER + "/template") - suspend fun accountTransferTemplate( - @Query("fromAccountId") accountId: Long?, - @Query("fromAccountType") accountType: Long?, - ): AccountOptionsTemplate + suspend fun accountTransferTemplate(): AccountOptionsTemplate @POST(ApiEndPoints.ACCOUNT_TRANSFER) suspend fun makeTransfer(@Body transferPayload: TransferPayload?): ResponseBody diff --git a/fastlane-config/android_config.rb b/fastlane-config/android_config.rb index 523d4e1f3..58a0ed2a2 100644 --- a/fastlane-config/android_config.rb +++ b/fastlane-config/android_config.rb @@ -11,7 +11,8 @@ module FastlaneConfig firebase_prod_app_id: "1:728434912738:android:d853a78f14af0c381a1dbb", firebase_demo_app_id: "1:728434912738:android:7845cce9777d9cf11a1dbb", firebase_service_creds_file: "secrets/firebaseAppDistributionServiceCredentialsFile.json", - firebase_groups: "mifos-mobile-testers" +# firebase_groups: "mifos-mobile-testers" + firebase_groups: "tt-mobile-testers" } BUILD_PATHS = { diff --git a/feature/loan/src/main/java/org/mifos/mobile/feature/loan/loanAccount/LoanAccountDetailScreen.kt b/feature/loan/src/main/java/org/mifos/mobile/feature/loan/loanAccount/LoanAccountDetailScreen.kt index 16a469d05..205f8d3c8 100644 --- a/feature/loan/src/main/java/org/mifos/mobile/feature/loan/loanAccount/LoanAccountDetailScreen.kt +++ b/feature/loan/src/main/java/org/mifos/mobile/feature/loan/loanAccount/LoanAccountDetailScreen.kt @@ -26,6 +26,7 @@ import org.mifos.mobile.core.designsystem.components.MifosScaffold import org.mifos.mobile.core.designsystem.theme.MifosMobileTheme import org.mifos.mobile.core.model.entity.accounts.loan.LoanWithAssociations import org.mifos.mobile.core.model.enums.ChargeType +import org.mifos.mobile.core.model.enums.TransferType import org.mifos.mobile.core.ui.component.EmptyDataView import org.mifos.mobile.core.ui.component.MifosProgressIndicator import org.mifos.mobile.core.ui.component.NoInternet @@ -43,7 +44,12 @@ internal fun LoanAccountDetailScreen( viewRepaymentSchedule: (Long) -> Unit, viewTransactions: (Long) -> Unit, viewQr: (String) -> Unit, - makePayment: (accountId: Long, outstandingBalance: Double?, transferType: String) -> Unit, + makePayment: ( + accountId: Long, + outstandingBalance: Double?, + transferType: String, + transferTarget: TransferType, + ) -> Unit, modifier: Modifier = Modifier, viewModel: LoanAccountsDetailViewModel = hiltViewModel(), ) { @@ -68,6 +74,7 @@ internal fun LoanAccountDetailScreen( loanId, viewModel.loanWithAssociations?.summary?.totalOutstanding, TRANSFER_PAY_TO, + TransferType.SELF, ) }, ) diff --git a/feature/loan/src/main/java/org/mifos/mobile/feature/loan/navigation/LoanNavGraph.kt b/feature/loan/src/main/java/org/mifos/mobile/feature/loan/navigation/LoanNavGraph.kt index 9cd1caba4..2beaf238a 100644 --- a/feature/loan/src/main/java/org/mifos/mobile/feature/loan/navigation/LoanNavGraph.kt +++ b/feature/loan/src/main/java/org/mifos/mobile/feature/loan/navigation/LoanNavGraph.kt @@ -18,6 +18,7 @@ import androidx.navigation.navArgument import org.mifos.mobile.core.common.Constants import org.mifos.mobile.core.model.enums.ChargeType import org.mifos.mobile.core.model.enums.LoanState +import org.mifos.mobile.core.model.enums.TransferType import org.mifos.mobile.feature.loan.loanAccount.LoanAccountDetailScreen import org.mifos.mobile.feature.loan.loanAccountApplication.LoanApplicationScreen import org.mifos.mobile.feature.loan.loanAccountSummary.LoanAccountSummaryScreen @@ -62,7 +63,12 @@ fun NavGraphBuilder.loanNavGraph( viewGuarantor: (Long) -> Unit, viewCharges: (ChargeType, Long) -> Unit, viewQr: (String) -> Unit, - makePayment: (accountId: Long, outstandingBalance: Double?, transferType: String) -> Unit, + makePayment: ( + accountId: Long, + outstandingBalance: Double?, + transferType: String, + transferTarget: TransferType, + ) -> Unit, ) { navigation( startDestination = LoanNavigation.LoanDetail.route, @@ -138,7 +144,12 @@ fun NavGraphBuilder.loanDetailRoute( viewRepaymentSchedule: (Long) -> Unit, viewTransactions: (Long) -> Unit, viewQr: (String) -> Unit, - makePayment: (accountId: Long, outstandingBalance: Double?, transferType: String) -> Unit, + makePayment: ( + accountId: Long, + outstandingBalance: Double?, + transferType: String, + transferTarget: TransferType, + ) -> Unit, ) { composable( route = LoanNavigation.LoanDetail.route, diff --git a/feature/savings/src/main/java/org/mifos/mobile/feature/savings/navigation/SavingsNavGraph.kt b/feature/savings/src/main/java/org/mifos/mobile/feature/savings/navigation/SavingsNavGraph.kt index b0ffe39dd..9ea808f3c 100644 --- a/feature/savings/src/main/java/org/mifos/mobile/feature/savings/navigation/SavingsNavGraph.kt +++ b/feature/savings/src/main/java/org/mifos/mobile/feature/savings/navigation/SavingsNavGraph.kt @@ -21,6 +21,7 @@ import org.mifos.mobile.core.common.Constants.OUTSTANDING_BALANCE import org.mifos.mobile.core.common.Constants.SAVINGS_ID 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.common.Constants.TRANSFER_TARGET import org.mifos.mobile.core.common.Constants.TRANSFER_TYPE import org.mifos.mobile.core.model.entity.payload.ReviewTransferPayload import org.mifos.mobile.core.model.enums.ChargeType @@ -36,12 +37,14 @@ fun NavController.navigateToSavingsMakeTransfer( accountId: Long, outstandingBalance: Double? = null, transferType: String, + transferTarget: TransferType, ) { navigate( SavingsNavigation.SavingsMakeTransfer.passArguments( - accountId, - (outstandingBalance ?: 0.0).toString(), - transferType, + accountId = accountId, + outstandingBalance = (outstandingBalance ?: 0.0).toString(), + transferType = transferType, + transferTarget = transferTarget, ), ) } @@ -76,12 +79,14 @@ fun NavGraphBuilder.savingsNavGraph( navController.navigateToSavingsMakeTransfer( accountId = it, transferType = TRANSFER_PAY_TO, + transferTarget = TransferType.TPT, ) }, makeTransfer = { navController.navigateToSavingsMakeTransfer( accountId = it, transferType = TRANSFER_PAY_FROM, + transferTarget = TransferType.TPT, ) }, navigateBack = navController::popBackStack, @@ -215,6 +220,7 @@ fun NavGraphBuilder.savingsMakeTransfer( defaultValue = null }, navArgument(name = TRANSFER_TYPE) { type = NavType.StringType }, + navArgument(name = TRANSFER_TARGET) { type = NavType.StringType }, ), ) { SavingsMakeTransferScreen( diff --git a/feature/savings/src/main/java/org/mifos/mobile/feature/savings/navigation/SavingsNavigation.kt b/feature/savings/src/main/java/org/mifos/mobile/feature/savings/navigation/SavingsNavigation.kt index d7ee0a10c..b88b9367e 100644 --- a/feature/savings/src/main/java/org/mifos/mobile/feature/savings/navigation/SavingsNavigation.kt +++ b/feature/savings/src/main/java/org/mifos/mobile/feature/savings/navigation/SavingsNavigation.kt @@ -13,8 +13,10 @@ import org.mifos.mobile.core.common.Constants.ACCOUNT_ID import org.mifos.mobile.core.common.Constants.OUTSTANDING_BALANCE import org.mifos.mobile.core.common.Constants.SAVINGS_ACCOUNT_STATE import org.mifos.mobile.core.common.Constants.SAVINGS_ID +import org.mifos.mobile.core.common.Constants.TRANSFER_TARGET import org.mifos.mobile.core.common.Constants.TRANSFER_TYPE import org.mifos.mobile.core.model.enums.SavingsAccountState +import org.mifos.mobile.core.model.enums.TransferType const val SAVINGS_NAVIGATION_ROUTE_BASE = "savings_route" const val SAVINGS_DETAIL_SCREEN_ROUTE = "savings_detail_screen_route" @@ -60,14 +62,23 @@ sealed class SavingsNavigation(val route: String) { } data object SavingsMakeTransfer : SavingsNavigation( - route = "$SAVINGS_MAKE_TRANSFER_SCREEN_ROUTE/{$ACCOUNT_ID}/{$OUTSTANDING_BALANCE}/{$TRANSFER_TYPE}", + route = "$SAVINGS_MAKE_TRANSFER_SCREEN_ROUTE/" + + "{$ACCOUNT_ID}/" + + "{$OUTSTANDING_BALANCE}/" + + "{$TRANSFER_TYPE}/" + + "{$TRANSFER_TARGET}", ) { fun passArguments( accountId: Long, outstandingBalance: String? = null, transferType: String, + transferTarget: TransferType, ): String { - return "$SAVINGS_MAKE_TRANSFER_SCREEN_ROUTE/$accountId/$outstandingBalance/$transferType" + return "$SAVINGS_MAKE_TRANSFER_SCREEN_ROUTE/" + + "$accountId/" + + "$outstandingBalance/" + + "$transferType/" + + transferTarget.name } } } diff --git a/feature/savings/src/main/java/org/mifos/mobile/feature/savings/savingsMakeTransfer/SavingsMakeTransferContent.kt b/feature/savings/src/main/java/org/mifos/mobile/feature/savings/savingsMakeTransfer/SavingsMakeTransferContent.kt index ff6a7864f..51eeb5170 100644 --- a/feature/savings/src/main/java/org/mifos/mobile/feature/savings/savingsMakeTransfer/SavingsMakeTransferContent.kt +++ b/feature/savings/src/main/java/org/mifos/mobile/feature/savings/savingsMakeTransfer/SavingsMakeTransferContent.kt @@ -112,7 +112,9 @@ internal fun SavingsMakeTransferContent( R.string.one -> PayToStepContent( modifier = processModifier, processState = payToStepState, - toAccountOptions = uiData.accountOptionsTemplate.fromAccountOptions, + toAccountOptions = uiData.toAccountOptions + .filter { it.accountType?.value == "Loan Account" } + .distinctBy { it.accountId }, prefilledAccount = payToAccount, onContinueClick = { payToAccount = it @@ -123,7 +125,8 @@ internal fun SavingsMakeTransferContent( R.string.two -> PayFromStep( modifier = processModifier, processState = payFromStepState, - fromAccountOptions = uiData.accountOptionsTemplate.fromAccountOptions, + fromAccountOptions = uiData.fromAccountOptions.distinctBy { it.accountNo } + .filter { it.accountNo != payToAccount?.accountNo }, prefilledAccount = payFromAccount, onContinueClick = { payFromAccount = it @@ -260,7 +263,6 @@ private fun EnterAmountStep( showAmountError = false amountError = when { amount.text.trim() == "" -> R.string.enter_amount - amount.text.contains(".") -> R.string.invalid_amount amount.text.toDoubleOrNull() == 0.0 -> R.string.amount_greater_than_zero else -> null } diff --git a/feature/savings/src/main/java/org/mifos/mobile/feature/savings/savingsMakeTransfer/SavingsMakeTransferScreen.kt b/feature/savings/src/main/java/org/mifos/mobile/feature/savings/savingsMakeTransfer/SavingsMakeTransferScreen.kt index 20756f820..c08d01e6b 100644 --- a/feature/savings/src/main/java/org/mifos/mobile/feature/savings/savingsMakeTransfer/SavingsMakeTransferScreen.kt +++ b/feature/savings/src/main/java/org/mifos/mobile/feature/savings/savingsMakeTransfer/SavingsMakeTransferScreen.kt @@ -39,13 +39,11 @@ internal fun SavingsMakeTransferScreen( viewModel: SavingsMakeTransferViewModel = hiltViewModel(), ) { val uiState = viewModel.savingsMakeTransferUiState.collectAsStateWithLifecycle() - val uiData = viewModel.savingsMakeTransferUiData.collectAsStateWithLifecycle() SavingsMakeTransferScreen( navigateBack = navigateBack, onCancelledClicked = onCancelledClicked, uiState = uiState.value, - uiData = uiData.value, modifier = modifier, reviewTransfer = { reviewTransfer(it, TransferType.SELF) }, ) @@ -54,7 +52,6 @@ internal fun SavingsMakeTransferScreen( @Composable private fun SavingsMakeTransferScreen( uiState: SavingsMakeTransferUiState, - uiData: SavingsMakeTransferUiData, navigateBack: () -> Unit, reviewTransfer: (ReviewTransferPayload) -> Unit, modifier: Modifier = Modifier, @@ -63,10 +60,16 @@ private fun SavingsMakeTransferScreen( val context = LocalContext.current MifosScaffold( - topBarTitleResId = if (uiData.transferType == Constants.TRANSFER_PAY_TO) { - R.string.deposit - } else { - R.string.transfer + topBarTitleResId = when (uiState) { + is SavingsMakeTransferUiState.ShowUI -> { + if (uiState.data.transferType == Constants.TRANSFER_PAY_TO) { + R.string.deposit + } else { + R.string.transfer + } + } + + else -> R.string.transfer }, navigateBack = navigateBack, modifier = modifier, @@ -76,16 +79,17 @@ private fun SavingsMakeTransferScreen( .padding(it) .fillMaxSize(), ) { - SavingsMakeTransferContent( - uiData = uiData, - reviewTransfer = reviewTransfer, - onCancelledClicked = onCancelledClicked, - ) - when (uiState) { - is SavingsMakeTransferUiState.ShowUI -> Unit + is SavingsMakeTransferUiState.ShowUI -> { + SavingsMakeTransferContent( + uiData = uiState.data, + reviewTransfer = reviewTransfer, + onCancelledClicked = onCancelledClicked, + ) + } - is SavingsMakeTransferUiState.Loading -> MifosProgressIndicatorOverlay() + is SavingsMakeTransferUiState.Loading -> + MifosProgressIndicatorOverlay() is SavingsMakeTransferUiState.Error -> { MifosErrorComponent( @@ -104,7 +108,9 @@ internal class SavingsMakeTransferUiStatesPreviews : PreviewParameterProvider { override val values: Sequence get() = sequenceOf( - SavingsMakeTransferUiState.ShowUI, + SavingsMakeTransferUiState.ShowUI( + data = SavingsMakeTransferUiData(), + ), SavingsMakeTransferUiState.Error(""), SavingsMakeTransferUiState.Loading, ) @@ -122,7 +128,6 @@ private fun SavingsMakeTransferContentPreview( onCancelledClicked = { }, reviewTransfer = { }, uiState = savingsMakeTransferUIState, - uiData = SavingsMakeTransferUiData(), ) } } diff --git a/feature/savings/src/main/java/org/mifos/mobile/feature/savings/savingsMakeTransfer/SavingsMakeTransferViewModel.kt b/feature/savings/src/main/java/org/mifos/mobile/feature/savings/savingsMakeTransfer/SavingsMakeTransferViewModel.kt index 802e5bca4..b77f63186 100644 --- a/feature/savings/src/main/java/org/mifos/mobile/feature/savings/savingsMakeTransfer/SavingsMakeTransferViewModel.kt +++ b/feature/savings/src/main/java/org/mifos/mobile/feature/savings/savingsMakeTransfer/SavingsMakeTransferViewModel.kt @@ -13,7 +13,6 @@ import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel -import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.flatMapLatest @@ -23,82 +22,99 @@ import org.mifos.mobile.core.common.Constants import org.mifos.mobile.core.common.Constants.TRANSFER_PAY_TO import org.mifos.mobile.core.data.repository.SavingsAccountRepository import org.mifos.mobile.core.model.entity.templates.account.AccountOption -import org.mifos.mobile.core.model.entity.templates.account.AccountOptionsTemplate +import org.mifos.mobile.core.model.enums.TransferType import org.mifos.mobile.core.network.Result import org.mifos.mobile.core.network.asResult import javax.inject.Inject @HiltViewModel internal class SavingsMakeTransferViewModel @Inject constructor( - private val savingsAccountRepositoryImp: SavingsAccountRepository, + savingsAccountRepositoryImp: SavingsAccountRepository, +// thirdPartyTransferRepository: ThirdPartyTransferRepository, savedStateHandle: SavedStateHandle, ) : ViewModel() { - val accountId = savedStateHandle.getStateFlow(key = Constants.ACCOUNT_ID, initialValue = -1L) + private val accountId = + savedStateHandle.getStateFlow(key = Constants.ACCOUNT_ID, initialValue = -1L) private val transferType: StateFlow = savedStateHandle.getStateFlow( key = Constants.TRANSFER_TYPE, initialValue = TRANSFER_PAY_TO, ) + private val transferTarget: StateFlow = savedStateHandle.getStateFlow( + key = Constants.TRANSFER_TARGET, + initialValue = TransferType.TPT.name, + ) + private val outstandingBalance: StateFlow = savedStateHandle.getStateFlow( key = Constants.OUTSTANDING_BALANCE, initialValue = null, ).map { balanceString -> - balanceString?.toDoubleOrNull() ?: 0.0 + balanceString?.toDoubleOrNull() }.stateIn( scope = viewModelScope, started = SharingStarted.WhileSubscribed(5_000), - initialValue = 0.0, + initialValue = null, ) - private val _savingsMakeTransferUiData = MutableStateFlow(SavingsMakeTransferUiData()) - val savingsMakeTransferUiData: StateFlow get() = _savingsMakeTransferUiData - - val savingsMakeTransferUiState = accountId - .flatMapLatest { id -> - savingsAccountRepositoryImp.accountTransferTemplate(accountId = id, accountType = 2L) + val savingsMakeTransferUiState: StateFlow = + transferTarget.flatMapLatest { target -> + savingsAccountRepositoryImp.accountTransferTemplate() +// when (target) { +// TransferType.TPT.name -> thirdPartyTransferRepository.thirdPartyTransferTemplate() +// else -> savingsAccountRepositoryImp.accountTransferTemplate() +// } } - .asResult() - .map { result -> - when (result) { - is Result.Success -> - SavingsMakeTransferUiState.ShowUI - .also { - _savingsMakeTransferUiData.value = _savingsMakeTransferUiData.value - .copy( - accountOptionsTemplate = result.data, - transferType = transferType.value, - outstandingBalance = if (outstandingBalance.value == 0.0) { - null - } else { - outstandingBalance.value - }, - accountId = accountId.value, - ) - } + .asResult() + .map { result -> + when (result) { + is Result.Success -> { + SavingsMakeTransferUiState.ShowUI( + data = SavingsMakeTransferUiData( + accountId = accountId.value, + transferType = transferType.value, + outstandingBalance = outstandingBalance.value, + fromAccountOptions = result.data.fromAccountOptions, + toAccountOptions = result.data.toAccountOptions, +// fromAccountOptionPrefilled = result.data.fromAccountOptions.find { +// accountId.value == it.accountId?.toLong() +// }, + toAccountOptionPrefilled = result.data.toAccountOptions.find { + accountId.value == it.accountId?.toLong() + }, + ), + ) + } - is Result.Loading -> SavingsMakeTransferUiState.Loading - is Result.Error -> SavingsMakeTransferUiState.Error(result.exception.message) + is Result.Loading -> { + SavingsMakeTransferUiState.Loading + } + + is Result.Error -> { + SavingsMakeTransferUiState.Error(result.exception.message) + } + } } - }.stateIn( - scope = viewModelScope, - started = SharingStarted.WhileSubscribed(5_000), - initialValue = SavingsMakeTransferUiState.Loading, - ) + .stateIn( + scope = viewModelScope, + started = SharingStarted.WhileSubscribed(5_000), + initialValue = SavingsMakeTransferUiState.Loading, + ) } internal sealed class SavingsMakeTransferUiState { data object Loading : SavingsMakeTransferUiState() data class Error(val errorMessage: String?) : SavingsMakeTransferUiState() - data object ShowUI : SavingsMakeTransferUiState() + data class ShowUI(val data: SavingsMakeTransferUiData) : SavingsMakeTransferUiState() } internal data class SavingsMakeTransferUiData( var accountId: Long? = null, var transferType: String? = null, var outstandingBalance: Double? = null, - var accountOptionsTemplate: AccountOptionsTemplate = AccountOptionsTemplate(), + var fromAccountOptions: List = ArrayList(), + var toAccountOptions: List = ArrayList(), var toAccountOptionPrefilled: AccountOption? = null, var fromAccountOptionPrefilled: AccountOption? = null, ) diff --git a/feature/third-party-transfer/src/main/java/org/mifos/mobile/feature/third/party/transfer/ThirdPartyTransferContent.kt b/feature/third-party-transfer/src/main/java/org/mifos/mobile/feature/third/party/transfer/ThirdPartyTransferContent.kt index 042bd7449..60718af88 100644 --- a/feature/third-party-transfer/src/main/java/org/mifos/mobile/feature/third/party/transfer/ThirdPartyTransferContent.kt +++ b/feature/third-party-transfer/src/main/java/org/mifos/mobile/feature/third/party/transfer/ThirdPartyTransferContent.kt @@ -56,7 +56,7 @@ import org.mifos.mobile.core.ui.utils.DevicePreviews @Composable internal fun ThirdPartyTransferContent( - accountOption: List, + fromAccountOption: List, toAccountOption: List, beneficiaryList: List, navigateBack: () -> Unit, @@ -112,7 +112,7 @@ internal fun ThirdPartyTransferContent( ) { stepModifier -> when (step.second) { R.string.one -> PayFromStep( - fromAccountOptions = accountOption, + fromAccountOptions = fromAccountOption, processState = payFromStepState, onContinueClick = { payFromAccount = it @@ -399,7 +399,7 @@ private fun RemarkStep( private fun ThirdPartyTransferContentPreview() { MifosMobileTheme { ThirdPartyTransferContent( - accountOption = listOf(), + fromAccountOption = listOf(), toAccountOption = listOf(), beneficiaryList = listOf(), navigateBack = {}, diff --git a/feature/third-party-transfer/src/main/java/org/mifos/mobile/feature/third/party/transfer/ThirdPartyTransferScreen.kt b/feature/third-party-transfer/src/main/java/org/mifos/mobile/feature/third/party/transfer/ThirdPartyTransferScreen.kt index ea2a66099..80b0bb444 100644 --- a/feature/third-party-transfer/src/main/java/org/mifos/mobile/feature/third/party/transfer/ThirdPartyTransferScreen.kt +++ b/feature/third-party-transfer/src/main/java/org/mifos/mobile/feature/third/party/transfer/ThirdPartyTransferScreen.kt @@ -38,11 +38,9 @@ internal fun ThirdPartyTransferScreen( viewModel: ThirdPartyTransferViewModel = hiltViewModel(), ) { val uiState by viewModel.uiState.collectAsStateWithLifecycle() - val uiData by viewModel.thirdPartyTransferUiData.collectAsStateWithLifecycle() ThirdPartyTransferScreen( uiState = uiState, - uiData = uiData, navigateBack = navigateBack, addBeneficiary = addBeneficiary, reviewTransfer = { reviewTransfer(it, TransferType.TPT) }, @@ -53,7 +51,6 @@ internal fun ThirdPartyTransferScreen( @Composable private fun ThirdPartyTransferScreen( uiState: ThirdPartyTransferUiState, - uiData: ThirdPartyTransferUiData, navigateBack: () -> Unit, addBeneficiary: () -> Unit, reviewTransfer: (ReviewTransferPayload) -> Unit, @@ -69,9 +66,9 @@ private fun ThirdPartyTransferScreen( when (uiState) { is ThirdPartyTransferUiState.ShowUI -> { ThirdPartyTransferContent( - accountOption = uiData.fromAccountDetail, - toAccountOption = uiData.toAccountOption, - beneficiaryList = uiData.beneficiaries, + fromAccountOption = uiState.data.fromAccountDetail, + toAccountOption = uiState.data.toAccountOption, + beneficiaryList = uiState.data.beneficiaries, navigateBack = navigateBack, addBeneficiary = addBeneficiary, reviewTransfer = reviewTransfer, @@ -99,7 +96,7 @@ internal class SavingsMakeTransferUiStatesPreviews : PreviewParameterProvider { override val values: Sequence get() = sequenceOf( - ThirdPartyTransferUiState.ShowUI, + ThirdPartyTransferUiState.ShowUI(data = ThirdPartyTransferUiData()), ThirdPartyTransferUiState.Error(""), ThirdPartyTransferUiState.Loading, ) @@ -114,7 +111,6 @@ private fun ThirdPartyTransferScreenPreview( MifosMobileTheme { ThirdPartyTransferScreen( uiState = thirdPartyTransferUiState, - uiData = ThirdPartyTransferUiData(), navigateBack = {}, addBeneficiary = {}, reviewTransfer = {}, diff --git a/feature/third-party-transfer/src/main/java/org/mifos/mobile/feature/third/party/transfer/ThirdPartyTransferViewModel.kt b/feature/third-party-transfer/src/main/java/org/mifos/mobile/feature/third/party/transfer/ThirdPartyTransferViewModel.kt index a26185e79..21122c878 100644 --- a/feature/third-party-transfer/src/main/java/org/mifos/mobile/feature/third/party/transfer/ThirdPartyTransferViewModel.kt +++ b/feature/third-party-transfer/src/main/java/org/mifos/mobile/feature/third/party/transfer/ThirdPartyTransferViewModel.kt @@ -12,12 +12,11 @@ package org.mifos.mobile.feature.third.party.transfer import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel -import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.flow.SharingStarted +import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.combine -import kotlinx.coroutines.flow.update -import kotlinx.coroutines.launch +import kotlinx.coroutines.flow.stateIn import org.mifos.mobile.core.data.repository.BeneficiaryRepository import org.mifos.mobile.core.data.repository.ThirdPartyTransferRepository import org.mifos.mobile.core.model.entity.beneficiary.Beneficiary @@ -27,51 +26,42 @@ import javax.inject.Inject @HiltViewModel internal class ThirdPartyTransferViewModel @Inject constructor( - private val transferRepository: ThirdPartyTransferRepository, - private val beneficiaryRepository: BeneficiaryRepository, + transferRepository: ThirdPartyTransferRepository, + beneficiaryRepository: BeneficiaryRepository, ) : ViewModel() { - private val mUiState = MutableStateFlow(Loading) - val uiState = mUiState.asStateFlow() - - private val _thirdPartyTransferUiData = MutableStateFlow(ThirdPartyTransferUiData()) - val thirdPartyTransferUiData = _thirdPartyTransferUiData.asStateFlow() - - init { - fetchTemplate() - } - - private fun fetchTemplate() { - viewModelScope.launch { - combine( - transferRepository.thirdPartyTransferTemplate(), - beneficiaryRepository.beneficiaryList(), - ) { templateResult, beneficiariesResult -> - _thirdPartyTransferUiData.update { - it.copy( - fromAccountDetail = templateResult.fromAccountOptions, - toAccountOption = templateResult.toAccountOptions, - beneficiaries = beneficiariesResult, - ) - } - }.catch { - mUiState.value = - ThirdPartyTransferUiState.Error(errorMessage = it.message) - }.collect { - mUiState.value = ThirdPartyTransferUiState.ShowUI - } - } - } + // in third part transfer is possible from savings to savings/loan + // cause of that we filter fromAccount only have saings. + val uiState: StateFlow = + combine( + transferRepository.thirdPartyTransferTemplate(), + beneficiaryRepository.beneficiaryList(), + ) { templateResult, beneficiariesResult -> + ThirdPartyTransferUiState.ShowUI( + ThirdPartyTransferUiData( + fromAccountDetail = templateResult.fromAccountOptions + .filter { it.accountType?.value == "Savings Account" }, + toAccountOption = templateResult.toAccountOptions, + beneficiaries = beneficiariesResult, + ), + ) + }.catch { + ThirdPartyTransferUiState.Error(errorMessage = it.message) + }.stateIn( + scope = viewModelScope, + started = SharingStarted.WhileSubscribed(5_000), + initialValue = Loading, + ) } internal sealed class ThirdPartyTransferUiState { data object Loading : ThirdPartyTransferUiState() data class Error(val errorMessage: String?) : ThirdPartyTransferUiState() - data object ShowUI : ThirdPartyTransferUiState() + data class ShowUI(val data: ThirdPartyTransferUiData) : ThirdPartyTransferUiState() } internal data class ThirdPartyTransferUiData( - val fromAccountDetail: List = listOf(), - val toAccountOption: List = listOf(), - val beneficiaries: List = listOf(), + val fromAccountDetail: List = emptyList(), + val toAccountOption: List = emptyList(), + val beneficiaries: List = emptyList(), ) diff --git a/feature/transfer-process/src/main/java/org/mifos/mobile/feature/transfer/process/TransferProcessScreen.kt b/feature/transfer-process/src/main/java/org/mifos/mobile/feature/transfer/process/TransferProcessScreen.kt index 37f72bc9a..3dc261e91 100644 --- a/feature/transfer-process/src/main/java/org/mifos/mobile/feature/transfer/process/TransferProcessScreen.kt +++ b/feature/transfer-process/src/main/java/org/mifos/mobile/feature/transfer/process/TransferProcessScreen.kt @@ -41,12 +41,10 @@ import androidx.compose.ui.tooling.preview.PreviewParameterProvider import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle -import org.mifos.mobile.core.common.Network import org.mifos.mobile.core.designsystem.components.MifosButton import org.mifos.mobile.core.designsystem.components.MifosScaffold import org.mifos.mobile.core.designsystem.theme.MifosMobileTheme import org.mifos.mobile.core.model.entity.payload.TransferPayload -import org.mifos.mobile.core.ui.component.MifosErrorComponent import org.mifos.mobile.core.ui.component.MifosProgressIndicatorOverlay import org.mifos.mobile.core.ui.utils.DevicePreviews @@ -107,7 +105,7 @@ private fun TransferProcessScreen( } is TransferProcessUiState.Error -> { - MifosErrorComponent(isNetworkConnected = Network.isConnected(context)) + Toast.makeText(context, uiState.errorMessage, Toast.LENGTH_SHORT).show() } is TransferProcessUiState.Initial -> Unit @@ -172,7 +170,7 @@ private fun TransferProcessContent( ) Text( - text = payload?.fromAccountNumber.toString(), + text = payload?.toAccountNumber.toString(), modifier = Modifier.padding(top = 4.dp, bottom = 2.dp), ) @@ -248,7 +246,7 @@ private fun TransferProcessContent( internal class UiStatesParameterProvider : PreviewParameterProvider { override val values: Sequence get() = sequenceOf( - TransferProcessUiState.Initial, +// TransferProcessUiState.Initial, TransferProcessUiState.Loading, TransferProcessUiState.Error(null), TransferProcessUiState.Success, diff --git a/feature/transfer-process/src/main/java/org/mifos/mobile/feature/transfer/process/TransferProcessViewModel.kt b/feature/transfer-process/src/main/java/org/mifos/mobile/feature/transfer/process/TransferProcessViewModel.kt index 436048f43..aefadca47 100644 --- a/feature/transfer-process/src/main/java/org/mifos/mobile/feature/transfer/process/TransferProcessViewModel.kt +++ b/feature/transfer-process/src/main/java/org/mifos/mobile/feature/transfer/process/TransferProcessViewModel.kt @@ -77,8 +77,6 @@ internal class TransferProcessViewModel @Inject constructor( transferDescription = payload.transferDescription, dateFormat = payload.dateFormat, locale = payload.locale, - fromAccountNumber = payload.fromAccountNumber, - toAccountNumber = payload.toAccountNumber, transferType = transferType.value, ).catch { e -> _transferUiState.value = TransferProcessUiState.Error(e.message) diff --git a/feature/transfer-process/src/main/java/org/mifos/mobile/feature/transfer/process/navigation/TransferProcessNavGraph.kt b/feature/transfer-process/src/main/java/org/mifos/mobile/feature/transfer/process/navigation/TransferProcessNavGraph.kt index cad5b165c..924b0941c 100644 --- a/feature/transfer-process/src/main/java/org/mifos/mobile/feature/transfer/process/navigation/TransferProcessNavGraph.kt +++ b/feature/transfer-process/src/main/java/org/mifos/mobile/feature/transfer/process/navigation/TransferProcessNavGraph.kt @@ -75,10 +75,12 @@ private fun ReviewTransferPayload.convertToTransferPayloadString(): String { fromClientId = payload.payFromAccount?.clientId fromAccountType = payload.payFromAccount?.accountType?.id fromOfficeId = payload.payFromAccount?.officeId - toOfficeId = payload.payFromAccount?.officeId + fromAccountNumber = payload.payFromAccount?.accountNo + toOfficeId = payload.payToAccount?.officeId toAccountId = payload.payToAccount?.accountId toClientId = payload.payToAccount?.clientId toAccountType = payload.payToAccount?.accountType?.id + toAccountNumber = payload.payToAccount?.accountNo transferDate = DateHelper.getSpecificFormat(DateHelper.FORMAT_MMMM, getTodayFormatted()) transferAmount = payload.amount.toDoubleOrNull() transferDescription = payload.review From be005947ea829baf03cc426860e2af924170685a Mon Sep 17 00:00:00 2001 From: Hekmatullah Date: Thu, 6 Mar 2025 15:39:26 +0000 Subject: [PATCH 2/2] fix: Fix navigation flow on successful transaction (#2800) --- .../mifos/mobile/navigation/MifosNavHost.kt | 28 +++++++++++++++++-- .../org/mifos/mobile/core/common/Constants.kt | 1 + .../entity/TransferSuccessDestination.kt | 16 +++++++++++ .../screens/ClientAccountsScreen.kt | 3 +- .../account/navigation/AccountNavGraph.kt | 13 +++++++-- .../loanAccount/LoanAccountDetailScreen.kt | 3 ++ .../feature/loan/navigation/LoanNavGraph.kt | 3 ++ .../savings/navigation/SavingsNavGraph.kt | 13 +++++++-- .../savings/navigation/SavingsNavigation.kt | 9 ++++-- .../SavingsMakeTransferScreen.kt | 14 ++++++++-- .../SavingsMakeTransferViewModel.kt | 6 ++++ .../transfer/ThirdPartyTransferScreen.kt | 5 ++-- .../navigation/ThirdPartyTransferNavGraph.kt | 5 ++-- .../transfer/process/TransferProcessScreen.kt | 10 +++++-- .../process/TransferProcessViewModel.kt | 7 +++++ .../navigation/TransferProcessNavGraph.kt | 10 +++++++ .../navigation/TransferProcessNavigation.kt | 7 +++-- 17 files changed, 134 insertions(+), 19 deletions(-) create mode 100644 core/model/src/main/java/org/mifos/mobile/core/model/entity/TransferSuccessDestination.kt diff --git a/androidApp/src/main/kotlin/org/mifos/mobile/navigation/MifosNavHost.kt b/androidApp/src/main/kotlin/org/mifos/mobile/navigation/MifosNavHost.kt index 346133b6d..c44536c0c 100644 --- a/androidApp/src/main/kotlin/org/mifos/mobile/navigation/MifosNavHost.kt +++ b/androidApp/src/main/kotlin/org/mifos/mobile/navigation/MifosNavHost.kt @@ -26,11 +26,13 @@ import org.mifos.library.passcode.navigateToPasscodeScreen import org.mifos.mobile.HomeActivity import org.mifos.mobile.R import org.mifos.mobile.core.common.Constants.TRANSFER_PAY_TO +import org.mifos.mobile.core.model.entity.TransferSuccessDestination import org.mifos.mobile.core.model.enums.AccountType import org.mifos.mobile.core.model.enums.ChargeType import org.mifos.mobile.core.model.enums.TransferType import org.mifos.mobile.feature.about.navigation.aboutUsNavGraph import org.mifos.mobile.feature.about.navigation.navigateToAboutUsScreen +import org.mifos.mobile.feature.account.navigation.ClientAccountsNavigation import org.mifos.mobile.feature.account.navigation.clientAccountsNavGraph import org.mifos.mobile.feature.account.navigation.navigateToClientAccountsScreen import org.mifos.mobile.feature.auth.navigation.authenticationNavGraph @@ -48,6 +50,7 @@ import org.mifos.mobile.feature.help.navigation.navigateToHelpScreen import org.mifos.mobile.feature.home.navigation.HomeDestinations import org.mifos.mobile.feature.home.navigation.HomeNavigation import org.mifos.mobile.feature.home.navigation.homeNavGraph +import org.mifos.mobile.feature.home.navigation.navigateToHomeScreen import org.mifos.mobile.feature.loan.navigation.loanNavGraph import org.mifos.mobile.feature.loan.navigation.navigateToLoanApplication import org.mifos.mobile.feature.loan.navigation.navigateToLoanDetailScreen @@ -158,7 +161,23 @@ fun MifosNavHost( }, ) - transferProcessNavGraph(navigateBack = navController::popBackStack) + transferProcessNavGraph( + navigateBack = navController::popBackStack, + onTransferSuccessNavigate = { destination -> + when (destination) { + TransferSuccessDestination.HOME -> navController.navigateToHomeScreen() + TransferSuccessDestination.LOAN_ACCOUNT -> navController.navigateToClientAccountsScreen( + AccountType.LOAN, + ClientAccountsNavigation.ClientAccountsBase.route, + ) + + TransferSuccessDestination.SAVINGS_ACCOUNT -> navController.navigateToClientAccountsScreen( + AccountType.SAVINGS, + ClientAccountsNavigation.ClientAccountsBase.route, + ) + } + }, + ) beneficiaryNavGraph( navController = navController, @@ -212,7 +231,11 @@ fun handleHomeNavigation( } HomeDestinations.RECENT_TRANSACTIONS -> navController.navigateToRecentTransaction() - HomeDestinations.CHARGES -> navController.navigateToClientChargeScreen(ChargeType.CLIENT, -1L) + HomeDestinations.CHARGES -> navController.navigateToClientChargeScreen( + ChargeType.CLIENT, + -1L, + ) + HomeDestinations.THIRD_PARTY_TRANSFER -> navController.navigateToThirdPartyTransfer() HomeDestinations.SETTINGS -> navController.navigateToSettings() HomeDestinations.ABOUT_US -> navController.navigateToAboutUsScreen() @@ -230,6 +253,7 @@ fun handleHomeNavigation( accountId = 1, transferType = TRANSFER_PAY_TO, transferTarget = TransferType.SELF, + transferSuccessDestination = TransferSuccessDestination.HOME, ) HomeDestinations.BENEFICIARIES -> navController.navigateToBeneficiaryListScreen() diff --git a/core/common/src/main/java/org/mifos/mobile/core/common/Constants.kt b/core/common/src/main/java/org/mifos/mobile/core/common/Constants.kt index 095bead31..a48558511 100644 --- a/core/common/src/main/java/org/mifos/mobile/core/common/Constants.kt +++ b/core/common/src/main/java/org/mifos/mobile/core/common/Constants.kt @@ -29,6 +29,7 @@ object Constants { const val DFRAG_DATE_PICKER = "Date Picker" const val TRANSFER_TYPE = "transfer_type" const val TRANSFER_TARGET = "transfer_target" + const val TRANSFER_SUCCESS_DESTINATION = "transfer_success_destination" const val TRANSFER_QUICK = "transfer_quick" const val TRANSFER_PAY_TO = "transfer_pay_to" const val TRANSFER_PAY_FROM = "transfer_pay_from" diff --git a/core/model/src/main/java/org/mifos/mobile/core/model/entity/TransferSuccessDestination.kt b/core/model/src/main/java/org/mifos/mobile/core/model/entity/TransferSuccessDestination.kt new file mode 100644 index 000000000..e68cfb9eb --- /dev/null +++ b/core/model/src/main/java/org/mifos/mobile/core/model/entity/TransferSuccessDestination.kt @@ -0,0 +1,16 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-mobile/blob/master/LICENSE.md + */ +package org.mifos.mobile.core.model.entity + +enum class TransferSuccessDestination { + SAVINGS_ACCOUNT, + LOAN_ACCOUNT, + HOME, +} diff --git a/feature/account/src/main/java/org/mifos/mobile/feature/account/clientAccount/screens/ClientAccountsScreen.kt b/feature/account/src/main/java/org/mifos/mobile/feature/account/clientAccount/screens/ClientAccountsScreen.kt index e465435c6..08c3d72e2 100644 --- a/feature/account/src/main/java/org/mifos/mobile/feature/account/clientAccount/screens/ClientAccountsScreen.kt +++ b/feature/account/src/main/java/org/mifos/mobile/feature/account/clientAccount/screens/ClientAccountsScreen.kt @@ -55,9 +55,10 @@ internal fun ClientAccountsScreen( val context = LocalContext.current var isDialogActive by rememberSaveable { mutableStateOf(false) } - var currentPage by rememberSaveable { mutableIntStateOf(0) } val accountType by viewModel.accountType.collectAsStateWithLifecycle() + + var currentPage by rememberSaveable { mutableIntStateOf(accountType?.ordinal ?: 0) } val filterList by viewModel.filterList.collectAsStateWithLifecycle() LaunchedEffect(key1 = accountType) { diff --git a/feature/account/src/main/java/org/mifos/mobile/feature/account/navigation/AccountNavGraph.kt b/feature/account/src/main/java/org/mifos/mobile/feature/account/navigation/AccountNavGraph.kt index 685018d75..1483bc626 100644 --- a/feature/account/src/main/java/org/mifos/mobile/feature/account/navigation/AccountNavGraph.kt +++ b/feature/account/src/main/java/org/mifos/mobile/feature/account/navigation/AccountNavGraph.kt @@ -19,8 +19,17 @@ import org.mifos.mobile.core.common.Constants import org.mifos.mobile.core.model.enums.AccountType import org.mifos.mobile.feature.account.clientAccount.screens.ClientAccountsScreen -fun NavController.navigateToClientAccountsScreen(accountType: AccountType = AccountType.SAVINGS) { - navigate(ClientAccountsNavigation.ClientAccountsScreen.passArguments(accountType = accountType)) +fun NavController.navigateToClientAccountsScreen( + accountType: AccountType = AccountType.SAVINGS, + popUpToDestination: String? = null, +) { + navigate(ClientAccountsNavigation.ClientAccountsScreen.passArguments(accountType = accountType)) { + if (popUpToDestination != null) { + popUpTo( + popUpToDestination, + ) + } + } } fun NavGraphBuilder.clientAccountsNavGraph( diff --git a/feature/loan/src/main/java/org/mifos/mobile/feature/loan/loanAccount/LoanAccountDetailScreen.kt b/feature/loan/src/main/java/org/mifos/mobile/feature/loan/loanAccount/LoanAccountDetailScreen.kt index 205f8d3c8..99b3497c0 100644 --- a/feature/loan/src/main/java/org/mifos/mobile/feature/loan/loanAccount/LoanAccountDetailScreen.kt +++ b/feature/loan/src/main/java/org/mifos/mobile/feature/loan/loanAccount/LoanAccountDetailScreen.kt @@ -24,6 +24,7 @@ import org.mifos.mobile.core.common.Constants.TRANSFER_PAY_TO import org.mifos.mobile.core.common.Network import org.mifos.mobile.core.designsystem.components.MifosScaffold import org.mifos.mobile.core.designsystem.theme.MifosMobileTheme +import org.mifos.mobile.core.model.entity.TransferSuccessDestination import org.mifos.mobile.core.model.entity.accounts.loan.LoanWithAssociations import org.mifos.mobile.core.model.enums.ChargeType import org.mifos.mobile.core.model.enums.TransferType @@ -49,6 +50,7 @@ internal fun LoanAccountDetailScreen( outstandingBalance: Double?, transferType: String, transferTarget: TransferType, + transferSuccessDestination: TransferSuccessDestination, ) -> Unit, modifier: Modifier = Modifier, viewModel: LoanAccountsDetailViewModel = hiltViewModel(), @@ -75,6 +77,7 @@ internal fun LoanAccountDetailScreen( viewModel.loanWithAssociations?.summary?.totalOutstanding, TRANSFER_PAY_TO, TransferType.SELF, + TransferSuccessDestination.LOAN_ACCOUNT, ) }, ) diff --git a/feature/loan/src/main/java/org/mifos/mobile/feature/loan/navigation/LoanNavGraph.kt b/feature/loan/src/main/java/org/mifos/mobile/feature/loan/navigation/LoanNavGraph.kt index 2beaf238a..a54cdad16 100644 --- a/feature/loan/src/main/java/org/mifos/mobile/feature/loan/navigation/LoanNavGraph.kt +++ b/feature/loan/src/main/java/org/mifos/mobile/feature/loan/navigation/LoanNavGraph.kt @@ -16,6 +16,7 @@ import androidx.navigation.compose.composable import androidx.navigation.compose.navigation import androidx.navigation.navArgument import org.mifos.mobile.core.common.Constants +import org.mifos.mobile.core.model.entity.TransferSuccessDestination import org.mifos.mobile.core.model.enums.ChargeType import org.mifos.mobile.core.model.enums.LoanState import org.mifos.mobile.core.model.enums.TransferType @@ -68,6 +69,7 @@ fun NavGraphBuilder.loanNavGraph( outstandingBalance: Double?, transferType: String, transferTarget: TransferType, + transferSuccessDestination: TransferSuccessDestination, ) -> Unit, ) { navigation( @@ -149,6 +151,7 @@ fun NavGraphBuilder.loanDetailRoute( outstandingBalance: Double?, transferType: String, transferTarget: TransferType, + transferSuccessDestination: TransferSuccessDestination, ) -> Unit, ) { composable( diff --git a/feature/savings/src/main/java/org/mifos/mobile/feature/savings/navigation/SavingsNavGraph.kt b/feature/savings/src/main/java/org/mifos/mobile/feature/savings/navigation/SavingsNavGraph.kt index 9ea808f3c..e271258e1 100644 --- a/feature/savings/src/main/java/org/mifos/mobile/feature/savings/navigation/SavingsNavGraph.kt +++ b/feature/savings/src/main/java/org/mifos/mobile/feature/savings/navigation/SavingsNavGraph.kt @@ -21,8 +21,10 @@ import org.mifos.mobile.core.common.Constants.OUTSTANDING_BALANCE import org.mifos.mobile.core.common.Constants.SAVINGS_ID 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.common.Constants.TRANSFER_SUCCESS_DESTINATION import org.mifos.mobile.core.common.Constants.TRANSFER_TARGET import org.mifos.mobile.core.common.Constants.TRANSFER_TYPE +import org.mifos.mobile.core.model.entity.TransferSuccessDestination import org.mifos.mobile.core.model.entity.payload.ReviewTransferPayload import org.mifos.mobile.core.model.enums.ChargeType import org.mifos.mobile.core.model.enums.SavingsAccountState @@ -38,6 +40,7 @@ fun NavController.navigateToSavingsMakeTransfer( outstandingBalance: Double? = null, transferType: String, transferTarget: TransferType, + transferSuccessDestination: TransferSuccessDestination, ) { navigate( SavingsNavigation.SavingsMakeTransfer.passArguments( @@ -45,6 +48,7 @@ fun NavController.navigateToSavingsMakeTransfer( outstandingBalance = (outstandingBalance ?: 0.0).toString(), transferType = transferType, transferTarget = transferTarget, + transferSuccessDestination = transferSuccessDestination, ), ) } @@ -66,7 +70,7 @@ fun NavGraphBuilder.savingsNavGraph( navController: NavController, viewQrCode: (String) -> Unit, viewCharges: (ChargeType, Long) -> Unit, - reviewTransfer: (ReviewTransferPayload, TransferType) -> Unit, + reviewTransfer: (ReviewTransferPayload, TransferType, TransferSuccessDestination) -> Unit, callHelpline: () -> Unit, ) { navigation( @@ -80,6 +84,7 @@ fun NavGraphBuilder.savingsNavGraph( accountId = it, transferType = TRANSFER_PAY_TO, transferTarget = TransferType.TPT, + transferSuccessDestination = TransferSuccessDestination.SAVINGS_ACCOUNT, ) }, makeTransfer = { @@ -87,6 +92,7 @@ fun NavGraphBuilder.savingsNavGraph( accountId = it, transferType = TRANSFER_PAY_FROM, transferTarget = TransferType.TPT, + transferSuccessDestination = TransferSuccessDestination.SAVINGS_ACCOUNT, ) }, navigateBack = navController::popBackStack, @@ -208,7 +214,7 @@ fun NavGraphBuilder.savingsWithdraw( fun NavGraphBuilder.savingsMakeTransfer( navigateBack: () -> Unit, - reviewTransfer: (ReviewTransferPayload, TransferType) -> Unit, + reviewTransfer: (ReviewTransferPayload, TransferType, TransferSuccessDestination) -> Unit, ) { composable( route = SavingsNavigation.SavingsMakeTransfer.route, @@ -221,6 +227,9 @@ fun NavGraphBuilder.savingsMakeTransfer( }, navArgument(name = TRANSFER_TYPE) { type = NavType.StringType }, navArgument(name = TRANSFER_TARGET) { type = NavType.StringType }, + navArgument(name = TRANSFER_SUCCESS_DESTINATION) { + type = NavType.EnumType(TransferSuccessDestination::class.java) + }, ), ) { SavingsMakeTransferScreen( diff --git a/feature/savings/src/main/java/org/mifos/mobile/feature/savings/navigation/SavingsNavigation.kt b/feature/savings/src/main/java/org/mifos/mobile/feature/savings/navigation/SavingsNavigation.kt index b88b9367e..169790fd5 100644 --- a/feature/savings/src/main/java/org/mifos/mobile/feature/savings/navigation/SavingsNavigation.kt +++ b/feature/savings/src/main/java/org/mifos/mobile/feature/savings/navigation/SavingsNavigation.kt @@ -13,8 +13,10 @@ import org.mifos.mobile.core.common.Constants.ACCOUNT_ID import org.mifos.mobile.core.common.Constants.OUTSTANDING_BALANCE import org.mifos.mobile.core.common.Constants.SAVINGS_ACCOUNT_STATE import org.mifos.mobile.core.common.Constants.SAVINGS_ID +import org.mifos.mobile.core.common.Constants.TRANSFER_SUCCESS_DESTINATION import org.mifos.mobile.core.common.Constants.TRANSFER_TARGET import org.mifos.mobile.core.common.Constants.TRANSFER_TYPE +import org.mifos.mobile.core.model.entity.TransferSuccessDestination import org.mifos.mobile.core.model.enums.SavingsAccountState import org.mifos.mobile.core.model.enums.TransferType @@ -66,19 +68,22 @@ sealed class SavingsNavigation(val route: String) { "{$ACCOUNT_ID}/" + "{$OUTSTANDING_BALANCE}/" + "{$TRANSFER_TYPE}/" + - "{$TRANSFER_TARGET}", + "{$TRANSFER_TARGET}/" + + "{$TRANSFER_SUCCESS_DESTINATION}", ) { fun passArguments( accountId: Long, outstandingBalance: String? = null, transferType: String, transferTarget: TransferType, + transferSuccessDestination: TransferSuccessDestination, ): String { return "$SAVINGS_MAKE_TRANSFER_SCREEN_ROUTE/" + "$accountId/" + "$outstandingBalance/" + "$transferType/" + - transferTarget.name + "${transferTarget.name}/" + + transferSuccessDestination } } } diff --git a/feature/savings/src/main/java/org/mifos/mobile/feature/savings/savingsMakeTransfer/SavingsMakeTransferScreen.kt b/feature/savings/src/main/java/org/mifos/mobile/feature/savings/savingsMakeTransfer/SavingsMakeTransferScreen.kt index c08d01e6b..54ae4ca57 100644 --- a/feature/savings/src/main/java/org/mifos/mobile/feature/savings/savingsMakeTransfer/SavingsMakeTransferScreen.kt +++ b/feature/savings/src/main/java/org/mifos/mobile/feature/savings/savingsMakeTransfer/SavingsMakeTransferScreen.kt @@ -13,6 +13,7 @@ import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.tooling.preview.PreviewParameter @@ -23,6 +24,7 @@ import org.mifos.mobile.core.common.Constants import org.mifos.mobile.core.common.Network import org.mifos.mobile.core.designsystem.components.MifosScaffold import org.mifos.mobile.core.designsystem.theme.MifosMobileTheme +import org.mifos.mobile.core.model.entity.TransferSuccessDestination import org.mifos.mobile.core.model.entity.payload.ReviewTransferPayload import org.mifos.mobile.core.model.enums.TransferType import org.mifos.mobile.core.ui.component.MifosErrorComponent @@ -34,18 +36,26 @@ import org.mifos.mobile.feature.savings.R internal fun SavingsMakeTransferScreen( onCancelledClicked: () -> Unit, navigateBack: () -> Unit, - reviewTransfer: (ReviewTransferPayload, TransferType) -> Unit, + reviewTransfer: (ReviewTransferPayload, TransferType, TransferSuccessDestination) -> Unit, modifier: Modifier = Modifier, viewModel: SavingsMakeTransferViewModel = hiltViewModel(), ) { val uiState = viewModel.savingsMakeTransferUiState.collectAsStateWithLifecycle() + val transferSuccessDestination by + viewModel.transferSuccessDestination.collectAsStateWithLifecycle() SavingsMakeTransferScreen( navigateBack = navigateBack, onCancelledClicked = onCancelledClicked, uiState = uiState.value, modifier = modifier, - reviewTransfer = { reviewTransfer(it, TransferType.SELF) }, + reviewTransfer = { + reviewTransfer( + it, + TransferType.SELF, + transferSuccessDestination, + ) + }, ) } diff --git a/feature/savings/src/main/java/org/mifos/mobile/feature/savings/savingsMakeTransfer/SavingsMakeTransferViewModel.kt b/feature/savings/src/main/java/org/mifos/mobile/feature/savings/savingsMakeTransfer/SavingsMakeTransferViewModel.kt index b77f63186..71a07b8ef 100644 --- a/feature/savings/src/main/java/org/mifos/mobile/feature/savings/savingsMakeTransfer/SavingsMakeTransferViewModel.kt +++ b/feature/savings/src/main/java/org/mifos/mobile/feature/savings/savingsMakeTransfer/SavingsMakeTransferViewModel.kt @@ -21,6 +21,7 @@ import kotlinx.coroutines.flow.stateIn import org.mifos.mobile.core.common.Constants import org.mifos.mobile.core.common.Constants.TRANSFER_PAY_TO import org.mifos.mobile.core.data.repository.SavingsAccountRepository +import org.mifos.mobile.core.model.entity.TransferSuccessDestination import org.mifos.mobile.core.model.entity.templates.account.AccountOption import org.mifos.mobile.core.model.enums.TransferType import org.mifos.mobile.core.network.Result @@ -47,6 +48,11 @@ internal class SavingsMakeTransferViewModel @Inject constructor( initialValue = TransferType.TPT.name, ) + val transferSuccessDestination: StateFlow = savedStateHandle.getStateFlow( + key = Constants.TRANSFER_SUCCESS_DESTINATION, + initialValue = TransferSuccessDestination.SAVINGS_ACCOUNT, + ) + private val outstandingBalance: StateFlow = savedStateHandle.getStateFlow( key = Constants.OUTSTANDING_BALANCE, initialValue = null, diff --git a/feature/third-party-transfer/src/main/java/org/mifos/mobile/feature/third/party/transfer/ThirdPartyTransferScreen.kt b/feature/third-party-transfer/src/main/java/org/mifos/mobile/feature/third/party/transfer/ThirdPartyTransferScreen.kt index 80b0bb444..eab5875c8 100644 --- a/feature/third-party-transfer/src/main/java/org/mifos/mobile/feature/third/party/transfer/ThirdPartyTransferScreen.kt +++ b/feature/third-party-transfer/src/main/java/org/mifos/mobile/feature/third/party/transfer/ThirdPartyTransferScreen.kt @@ -23,6 +23,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle import org.mifos.mobile.core.common.Network import org.mifos.mobile.core.designsystem.components.MifosScaffold import org.mifos.mobile.core.designsystem.theme.MifosMobileTheme +import org.mifos.mobile.core.model.entity.TransferSuccessDestination import org.mifos.mobile.core.model.entity.payload.ReviewTransferPayload import org.mifos.mobile.core.model.enums.TransferType import org.mifos.mobile.core.ui.component.MifosErrorComponent @@ -33,7 +34,7 @@ import org.mifos.mobile.core.ui.utils.DevicePreviews internal fun ThirdPartyTransferScreen( navigateBack: () -> Unit, addBeneficiary: () -> Unit, - reviewTransfer: (ReviewTransferPayload, TransferType) -> Unit, + reviewTransfer: (ReviewTransferPayload, TransferType, TransferSuccessDestination) -> Unit, modifier: Modifier = Modifier, viewModel: ThirdPartyTransferViewModel = hiltViewModel(), ) { @@ -43,7 +44,7 @@ internal fun ThirdPartyTransferScreen( uiState = uiState, navigateBack = navigateBack, addBeneficiary = addBeneficiary, - reviewTransfer = { reviewTransfer(it, TransferType.TPT) }, + reviewTransfer = { reviewTransfer(it, TransferType.TPT, TransferSuccessDestination.HOME) }, modifier = modifier, ) } diff --git a/feature/third-party-transfer/src/main/java/org/mifos/mobile/feature/third/party/transfer/navigation/ThirdPartyTransferNavGraph.kt b/feature/third-party-transfer/src/main/java/org/mifos/mobile/feature/third/party/transfer/navigation/ThirdPartyTransferNavGraph.kt index 9cee80a06..09df27499 100644 --- a/feature/third-party-transfer/src/main/java/org/mifos/mobile/feature/third/party/transfer/navigation/ThirdPartyTransferNavGraph.kt +++ b/feature/third-party-transfer/src/main/java/org/mifos/mobile/feature/third/party/transfer/navigation/ThirdPartyTransferNavGraph.kt @@ -13,6 +13,7 @@ import androidx.navigation.NavController import androidx.navigation.NavGraphBuilder import androidx.navigation.compose.composable import androidx.navigation.compose.navigation +import org.mifos.mobile.core.model.entity.TransferSuccessDestination import org.mifos.mobile.core.model.entity.payload.ReviewTransferPayload import org.mifos.mobile.core.model.enums.TransferType import org.mifos.mobile.feature.third.party.transfer.ThirdPartyTransferScreen @@ -24,7 +25,7 @@ fun NavController.navigateToThirdPartyTransfer() { fun NavGraphBuilder.thirdPartyTransferNavGraph( navigateBack: () -> Unit, addBeneficiary: () -> Unit, - reviewTransfer: (ReviewTransferPayload, TransferType) -> Unit, + reviewTransfer: (ReviewTransferPayload, TransferType, TransferSuccessDestination) -> Unit, ) { navigation( startDestination = ThirdPartyTransferNavigation.ThirdPartyTransferScreen.route, @@ -41,7 +42,7 @@ fun NavGraphBuilder.thirdPartyTransferNavGraph( fun NavGraphBuilder.thirdPartyTransferRoute( navigateBack: () -> Unit, addBeneficiary: () -> Unit, - reviewTransfer: (ReviewTransferPayload, TransferType) -> Unit, + reviewTransfer: (ReviewTransferPayload, TransferType, TransferSuccessDestination) -> Unit, ) { composable( route = ThirdPartyTransferNavigation.ThirdPartyTransferScreen.route, diff --git a/feature/transfer-process/src/main/java/org/mifos/mobile/feature/transfer/process/TransferProcessScreen.kt b/feature/transfer-process/src/main/java/org/mifos/mobile/feature/transfer/process/TransferProcessScreen.kt index 3dc261e91..7929dcdad 100644 --- a/feature/transfer-process/src/main/java/org/mifos/mobile/feature/transfer/process/TransferProcessScreen.kt +++ b/feature/transfer-process/src/main/java/org/mifos/mobile/feature/transfer/process/TransferProcessScreen.kt @@ -44,6 +44,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle import org.mifos.mobile.core.designsystem.components.MifosButton import org.mifos.mobile.core.designsystem.components.MifosScaffold import org.mifos.mobile.core.designsystem.theme.MifosMobileTheme +import org.mifos.mobile.core.model.entity.TransferSuccessDestination import org.mifos.mobile.core.model.entity.payload.TransferPayload import org.mifos.mobile.core.ui.component.MifosProgressIndicatorOverlay import org.mifos.mobile.core.ui.utils.DevicePreviews @@ -51,17 +52,20 @@ import org.mifos.mobile.core.ui.utils.DevicePreviews @Composable internal fun TransferProcessScreen( navigateBack: () -> Unit, + onTransferSuccessNavigate: (TransferSuccessDestination) -> Unit, modifier: Modifier = Modifier, viewModel: TransferProcessViewModel = hiltViewModel(), ) { val uiState by viewModel.transferUiState.collectAsStateWithLifecycle() val payload by viewModel.transferPayload.collectAsStateWithLifecycle() + val transferSuccessDestination by viewModel.transferSuccessDestination.collectAsStateWithLifecycle() TransferProcessScreen( uiState = uiState, transfer = viewModel::makeTransfer, payload = payload, navigateBack = navigateBack, + onTransferSuccess = { onTransferSuccessNavigate(transferSuccessDestination) }, modifier = modifier, ) } @@ -72,6 +76,7 @@ private fun TransferProcessScreen( payload: TransferPayload?, transfer: () -> Unit, navigateBack: () -> Unit, + onTransferSuccess: () -> Unit, modifier: Modifier = Modifier, ) { val context = LocalContext.current @@ -101,7 +106,7 @@ private fun TransferProcessScreen( R.string.transferred_successfully, Toast.LENGTH_SHORT, ).show() - navigateBack() + onTransferSuccess() } is TransferProcessUiState.Error -> { @@ -246,7 +251,7 @@ private fun TransferProcessContent( internal class UiStatesParameterProvider : PreviewParameterProvider { override val values: Sequence get() = sequenceOf( -// TransferProcessUiState.Initial, + TransferProcessUiState.Initial, TransferProcessUiState.Loading, TransferProcessUiState.Error(null), TransferProcessUiState.Success, @@ -271,6 +276,7 @@ private fun TransferProcessScreenPreview( ), transfer = {}, navigateBack = {}, + onTransferSuccess = {}, ) } } diff --git a/feature/transfer-process/src/main/java/org/mifos/mobile/feature/transfer/process/TransferProcessViewModel.kt b/feature/transfer-process/src/main/java/org/mifos/mobile/feature/transfer/process/TransferProcessViewModel.kt index aefadca47..f4c4f686d 100644 --- a/feature/transfer-process/src/main/java/org/mifos/mobile/feature/transfer/process/TransferProcessViewModel.kt +++ b/feature/transfer-process/src/main/java/org/mifos/mobile/feature/transfer/process/TransferProcessViewModel.kt @@ -23,8 +23,10 @@ import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch import org.mifos.mobile.core.common.Constants.PAYLOAD +import org.mifos.mobile.core.common.Constants.TRANSFER_SUCCESS_DESTINATION import org.mifos.mobile.core.common.Constants.TRANSFER_TYPE import org.mifos.mobile.core.data.repository.TransferRepository +import org.mifos.mobile.core.model.entity.TransferSuccessDestination import org.mifos.mobile.core.model.entity.payload.TransferPayload import org.mifos.mobile.core.model.enums.TransferType import org.mifos.mobile.feature.transfer.process.TransferProcessUiState.Initial @@ -48,6 +50,11 @@ internal class TransferProcessViewModel @Inject constructor( initialValue = null, ) + val transferSuccessDestination = savedStateHandle.getStateFlow( + key = TRANSFER_SUCCESS_DESTINATION, + initialValue = TransferSuccessDestination.SAVINGS_ACCOUNT, + ) + val transferPayload: StateFlow = transferPayloadString .map { jsonString -> jsonString?.let { diff --git a/feature/transfer-process/src/main/java/org/mifos/mobile/feature/transfer/process/navigation/TransferProcessNavGraph.kt b/feature/transfer-process/src/main/java/org/mifos/mobile/feature/transfer/process/navigation/TransferProcessNavGraph.kt index 924b0941c..821ff74e2 100644 --- a/feature/transfer-process/src/main/java/org/mifos/mobile/feature/transfer/process/navigation/TransferProcessNavGraph.kt +++ b/feature/transfer-process/src/main/java/org/mifos/mobile/feature/transfer/process/navigation/TransferProcessNavGraph.kt @@ -19,6 +19,7 @@ import com.google.gson.Gson import org.mifos.mobile.core.common.Constants import org.mifos.mobile.core.common.utils.DateHelper import org.mifos.mobile.core.common.utils.getTodayFormatted +import org.mifos.mobile.core.model.entity.TransferSuccessDestination import org.mifos.mobile.core.model.entity.payload.ReviewTransferPayload import org.mifos.mobile.core.model.entity.payload.TransferPayload import org.mifos.mobile.core.model.enums.TransferType @@ -28,17 +29,20 @@ import org.mifos.mobile.feature.transfer.process.TransferProcessScreen fun NavController.navigateToTransferProcessScreen( transferPayload: ReviewTransferPayload, transferType: TransferType, + transferSuccessDestination: TransferSuccessDestination, ) { navigate( TransferProcessNavigation.TransferProcessScreen.passArguments( transferType = transferType, payload = transferPayload.convertToTransferPayloadString(), + transferSuccessDestination = transferSuccessDestination, ), ) } fun NavGraphBuilder.transferProcessNavGraph( navigateBack: () -> Unit, + onTransferSuccessNavigate: (TransferSuccessDestination) -> Unit = {}, ) { navigation( startDestination = TransferProcessNavigation.TransferProcessScreen.route, @@ -46,12 +50,14 @@ fun NavGraphBuilder.transferProcessNavGraph( ) { transferProcessScreenRoute( navigateBack = navigateBack, + onTransferSuccessNavigate = onTransferSuccessNavigate, ) } } private fun NavGraphBuilder.transferProcessScreenRoute( navigateBack: () -> Unit, + onTransferSuccessNavigate: (TransferSuccessDestination) -> Unit = {}, ) { composable( route = TransferProcessNavigation.TransferProcessScreen.route, @@ -60,10 +66,14 @@ private fun NavGraphBuilder.transferProcessScreenRoute( navArgument(name = Constants.TRANSFER_TYPE) { type = NavType.EnumType(TransferType::class.java) }, + navArgument(name = Constants.TRANSFER_SUCCESS_DESTINATION) { + type = NavType.EnumType(TransferSuccessDestination::class.java) + }, ), ) { TransferProcessScreen( navigateBack = navigateBack, + onTransferSuccessNavigate = onTransferSuccessNavigate, ) } } diff --git a/feature/transfer-process/src/main/java/org/mifos/mobile/feature/transfer/process/navigation/TransferProcessNavigation.kt b/feature/transfer-process/src/main/java/org/mifos/mobile/feature/transfer/process/navigation/TransferProcessNavigation.kt index 125be71e5..ee71f65b8 100644 --- a/feature/transfer-process/src/main/java/org/mifos/mobile/feature/transfer/process/navigation/TransferProcessNavigation.kt +++ b/feature/transfer-process/src/main/java/org/mifos/mobile/feature/transfer/process/navigation/TransferProcessNavigation.kt @@ -10,7 +10,9 @@ package org.mifos.mobile.feature.transfer.process.navigation import org.mifos.mobile.core.common.Constants.PAYLOAD +import org.mifos.mobile.core.common.Constants.TRANSFER_SUCCESS_DESTINATION import org.mifos.mobile.core.common.Constants.TRANSFER_TYPE +import org.mifos.mobile.core.model.entity.TransferSuccessDestination import org.mifos.mobile.core.model.enums.TransferType // Constants for Routes @@ -24,11 +26,12 @@ internal sealed class TransferProcessNavigation(val route: String) { ) data object TransferProcessScreen : TransferProcessNavigation( - route = "$TRANSFER_PROCESS_SCREEN_ROUTE/{$PAYLOAD}/{$TRANSFER_TYPE}", + route = "$TRANSFER_PROCESS_SCREEN_ROUTE/{$PAYLOAD}/{$TRANSFER_TYPE}/{$TRANSFER_SUCCESS_DESTINATION}", ) { fun passArguments( payload: String, transferType: TransferType, - ) = "$TRANSFER_PROCESS_SCREEN_ROUTE/$payload/$transferType" + transferSuccessDestination: TransferSuccessDestination, + ) = "$TRANSFER_PROCESS_SCREEN_ROUTE/$payload/$transferType/$transferSuccessDestination" } }