From 37ebc76a8760193d61ce50fc8adf726ec4434827 Mon Sep 17 00:00:00 2001 From: Pronay sarker Date: Sun, 10 Nov 2024 03:35:13 +0600 Subject: [PATCH] savings cleanup fix spotless fix editorconfig added --- .editorconfig | 7 + .../src/main/kotlin/org/mifos/Badging.kt | 2 +- config/detekt/.editorconfig | 0 config/detekt/detekt.yml | 6 +- feature/savings/build.gradle.kts | 9 + .../savings/ExampleInstrumentedTest.kt | 17 +- feature/savings/src/main/AndroidManifest.xml | 9 + .../savings/navigation/SavingsNavigation.kt | 91 ++++--- .../savings/navigation/SavingsScreens.kt | 12 +- .../SavingAccountUiState.kt | 13 +- .../SavingAccountViewModel.kt | 71 ++--- .../SavingsAccountScreen.kt | 178 ++++++------ .../SavingsAccountActivateScreen.kt | 87 +++--- .../SavingsAccountActivateUiState.kt | 13 +- .../SavingsAccountActivateViewModel.kt | 44 +-- .../SavingsAccountApprovalScreen.kt | 96 ++++--- .../SavingsAccountApprovalUiState.kt | 13 +- .../SavingsAccountApprovalViewModel.kt | 44 +-- .../SavingsAccountSummaryScreen.kt | 164 +++++------ .../SavingsAccountSummaryUiState.kt | 11 +- .../SavingsAccountSummaryViewModel.kt | 37 ++- .../SavingsAccountTransactionScreen.kt | 182 +++++++------ .../SavingsAccountTransactionUiState.kt | 12 +- .../SavingsAccountTransactionViewModel.kt | 86 +++--- .../res/values/feature_savings_strings.xml | 9 + .../mifos/feature/savings/ExampleUnitTest.kt | 14 +- .../SavingsAccountTransactionsListAdapter.kt | 79 ------ .../adapters/SavingsAccountsListAdapter.kt | 88 ------ .../mifosxdroid/components/Navigation.kt | 9 +- .../SavingsAccountSummaryFragment.kt | 150 ----------- .../SavingsAccountTransactionFragment.kt | 59 ---- .../savingsaccount/SavingsAccountFragment.kt | 64 ----- .../SavingsAccountActivateFragment.kt | 59 ---- .../SavingsAccountApprovalFragment.kt | 59 ---- .../dialog_fragment_approve_savings.xml | 50 ---- .../layout/fragment_add_savings_account.xml | 250 ----------------- .../fragment_savings_account_summary.xml | 255 ------------------ .../fragment_savings_account_transaction.xml | 197 -------------- .../layout/row_savings_transaction_item.xml | 45 ---- 39 files changed, 721 insertions(+), 1870 deletions(-) create mode 100644 .editorconfig create mode 100644 config/detekt/.editorconfig rename feature/savings/src/main/java/com/mifos/feature/savings/{account => savingsAccount}/SavingAccountUiState.kt (62%) rename feature/savings/src/main/java/com/mifos/feature/savings/{account => savingsAccount}/SavingAccountViewModel.kt (61%) rename feature/savings/src/main/java/com/mifos/feature/savings/{account => savingsAccount}/SavingsAccountScreen.kt (85%) rename feature/savings/src/main/java/com/mifos/feature/savings/{account_activate => savingsAccountActivate}/SavingsAccountActivateScreen.kt (82%) rename feature/savings/src/main/java/com/mifos/feature/savings/{account_activate => savingsAccountActivate}/SavingsAccountActivateUiState.kt (55%) rename feature/savings/src/main/java/com/mifos/feature/savings/{account_activate => savingsAccountActivate}/SavingsAccountActivateViewModel.kt (55%) rename feature/savings/src/main/java/com/mifos/feature/savings/{account_approval => savingsAccountApproval}/SavingsAccountApprovalScreen.kt (81%) rename feature/savings/src/main/java/com/mifos/feature/savings/{account_approval => savingsAccountApproval}/SavingsAccountApprovalUiState.kt (55%) rename feature/savings/src/main/java/com/mifos/feature/savings/{account_approval => savingsAccountApproval}/SavingsAccountApprovalViewModel.kt (53%) rename feature/savings/src/main/java/com/mifos/feature/savings/{account_summary => savingsAccountSummary}/SavingsAccountSummaryScreen.kt (85%) rename feature/savings/src/main/java/com/mifos/feature/savings/{account_summary => savingsAccountSummary}/SavingsAccountSummaryUiState.kt (55%) rename feature/savings/src/main/java/com/mifos/feature/savings/{account_summary => savingsAccountSummary}/SavingsAccountSummaryViewModel.kt (56%) rename feature/savings/src/main/java/com/mifos/feature/savings/{account_transaction => savingsAccountTransaction}/SavingsAccountTransactionScreen.kt (80%) rename feature/savings/src/main/java/com/mifos/feature/savings/{account_transaction => savingsAccountTransaction}/SavingsAccountTransactionUiState.kt (71%) rename feature/savings/src/main/java/com/mifos/feature/savings/{account_transaction => savingsAccountTransaction}/SavingsAccountTransactionViewModel.kt (63%) delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/SavingsAccountTransactionsListAdapter.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/SavingsAccountsListAdapter.kt delete mode 100755 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/savingaccountsummary/SavingsAccountSummaryFragment.kt delete mode 100755 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/savingaccounttransaction/SavingsAccountTransactionFragment.kt delete mode 100755 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/savingsaccount/SavingsAccountFragment.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/savingsaccountactivate/SavingsAccountActivateFragment.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/savingsaccountapproval/SavingsAccountApprovalFragment.kt delete mode 100644 mifosng-android/src/main/res/layout/dialog_fragment_approve_savings.xml delete mode 100755 mifosng-android/src/main/res/layout/fragment_add_savings_account.xml delete mode 100755 mifosng-android/src/main/res/layout/fragment_savings_account_summary.xml delete mode 100755 mifosng-android/src/main/res/layout/fragment_savings_account_transaction.xml delete mode 100755 mifosng-android/src/main/res/layout/row_savings_transaction_item.xml diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000000..06c4d26a321 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,7 @@ +# https://editorconfig.org/ +# This configuration is used by ktlint when spotless invokes it + +[*.{kt,kts}] +ij_kotlin_allow_trailing_comma=true +ij_kotlin_allow_trailing_comma_on_call_site=true +ktlint_function_naming_ignore_when_annotated_with=Composable, Test, Preview \ No newline at end of file diff --git a/build-logic/convention/src/main/kotlin/org/mifos/Badging.kt b/build-logic/convention/src/main/kotlin/org/mifos/Badging.kt index aab84c3ce21..b8ce7497b23 100644 --- a/build-logic/convention/src/main/kotlin/org/mifos/Badging.kt +++ b/build-logic/convention/src/main/kotlin/org/mifos/Badging.kt @@ -19,7 +19,7 @@ import org.gradle.api.tasks.OutputFile import org.gradle.api.tasks.PathSensitive import org.gradle.api.tasks.PathSensitivity import org.gradle.api.tasks.TaskAction -import org.gradle.configurationcache.extensions.capitalized +import org.gradle.internal.extensions.stdlib.capitalized import org.gradle.kotlin.dsl.register import org.gradle.language.base.plugins.LifecycleBasePlugin import org.gradle.process.ExecOperations diff --git a/config/detekt/.editorconfig b/config/detekt/.editorconfig new file mode 100644 index 00000000000..e69de29bb2d diff --git a/config/detekt/detekt.yml b/config/detekt/detekt.yml index f486f818416..dd953b74e18 100644 --- a/config/detekt/detekt.yml +++ b/config/detekt/detekt.yml @@ -168,7 +168,7 @@ complexity: threshold: 600 LongMethod: active: true - threshold: 180 #60 + threshold: 360 #180 #60 LongParameterList: active: true # Updating Common values based on current scenario @@ -785,7 +785,7 @@ style: maxChainedCalls: 5 MaxLineLength: active: true - maxLineLength: 120 + maxLineLength: 150 excludePackageStatements: true excludeImportStatements: true excludeCommentStatements: false @@ -828,7 +828,7 @@ style: active: false ReturnCount: active: true - max: 2 + max: 4 excludedFunctions: - "equals" excludeLabeled: false diff --git a/feature/savings/build.gradle.kts b/feature/savings/build.gradle.kts index fc657665f4a..e675392cb66 100644 --- a/feature/savings/build.gradle.kts +++ b/feature/savings/build.gradle.kts @@ -1,3 +1,12 @@ +/* + * Copyright 2024 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/android-client/blob/master/LICENSE.md + */ plugins { alias(libs.plugins.mifos.android.feature) alias(libs.plugins.mifos.android.library.compose) diff --git a/feature/savings/src/androidTest/java/com/mifos/feature/savings/ExampleInstrumentedTest.kt b/feature/savings/src/androidTest/java/com/mifos/feature/savings/ExampleInstrumentedTest.kt index 13e2ebecbd1..00dbd24647d 100644 --- a/feature/savings/src/androidTest/java/com/mifos/feature/savings/ExampleInstrumentedTest.kt +++ b/feature/savings/src/androidTest/java/com/mifos/feature/savings/ExampleInstrumentedTest.kt @@ -1,13 +1,20 @@ +/* + * Copyright 2024 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/android-client/blob/master/LICENSE.md + */ package com.mifos.feature.savings -import androidx.test.platform.app.InstrumentationRegistry import androidx.test.ext.junit.runners.AndroidJUnit4 - +import androidx.test.platform.app.InstrumentationRegistry +import org.junit.Assert.assertEquals import org.junit.Test import org.junit.runner.RunWith -import org.junit.Assert.* - /** * Instrumented test, which will execute on an Android device. * @@ -21,4 +28,4 @@ class ExampleInstrumentedTest { val appContext = InstrumentationRegistry.getInstrumentation().targetContext assertEquals("com.mifos.feature.savings.test", appContext.packageName) } -} \ No newline at end of file +} diff --git a/feature/savings/src/main/AndroidManifest.xml b/feature/savings/src/main/AndroidManifest.xml index a5918e68abc..1dc76da0f7e 100644 --- a/feature/savings/src/main/AndroidManifest.xml +++ b/feature/savings/src/main/AndroidManifest.xml @@ -1,4 +1,13 @@ + \ No newline at end of file diff --git a/feature/savings/src/main/java/com/mifos/feature/savings/navigation/SavingsNavigation.kt b/feature/savings/src/main/java/com/mifos/feature/savings/navigation/SavingsNavigation.kt index 9ec2cf2ac90..af3cf36ab1c 100644 --- a/feature/savings/src/main/java/com/mifos/feature/savings/navigation/SavingsNavigation.kt +++ b/feature/savings/src/main/java/com/mifos/feature/savings/navigation/SavingsNavigation.kt @@ -1,3 +1,12 @@ +/* + * Copyright 2024 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/android-client/blob/master/LICENSE.md + */ package com.mifos.feature.savings.navigation import androidx.navigation.NavController @@ -9,11 +18,11 @@ import androidx.navigation.navigation import com.mifos.core.common.utils.Constants import com.mifos.core.objects.accounts.savings.DepositType import com.mifos.core.objects.accounts.savings.SavingsAccountWithAssociations -import com.mifos.feature.savings.account.SavingsAccountScreen -import com.mifos.feature.savings.account_activate.SavingsAccountActivateScreen -import com.mifos.feature.savings.account_approval.SavingsAccountApprovalScreen -import com.mifos.feature.savings.account_summary.SavingsAccountSummaryScreen -import com.mifos.feature.savings.account_transaction.SavingsAccountTransactionScreen +import com.mifos.feature.savings.savingsAccount.SavingsAccountScreen +import com.mifos.feature.savings.savingsAccountActivate.SavingsAccountActivateScreen +import com.mifos.feature.savings.savingsAccountApproval.SavingsAccountApprovalScreen +import com.mifos.feature.savings.savingsAccountSummary.SavingsAccountSummaryScreen +import com.mifos.feature.savings.savingsAccountTransaction.SavingsAccountTransactionScreen /** * Created by Pronay Sarker on 14/08/2024 (1:10 PM) @@ -22,41 +31,41 @@ import com.mifos.feature.savings.account_transaction.SavingsAccountTransactionSc fun NavGraphBuilder.savingsNavGraph( navController: NavController, onBackPressed: () -> Unit, - loadMoreSavingsAccountInfo: (Int) -> Unit, - loadDocuments: (Int) -> Unit, + loadMoreSavingsAccountInfo: (String, Int) -> Unit, + loadDocuments: (Int, String) -> Unit, ) { navigation( startDestination = SavingsScreens.SavingsAccountSummary.route, - route = "savings_summary_route" + route = "savings_summary_route", ) { savingsSummaryScreen( onBackPressed = navController::popBackStack, - loadMoreSavingsAccountInfo = loadMoreSavingsAccountInfo, - loadDocuments = loadDocuments, + loadMoreSavingsAccountInfo = { loadMoreSavingsAccountInfo(Constants.DATA_TABLE_NAME_SAVINGS, it) }, + loadDocuments = { loadDocuments(it, Constants.ENTITY_TYPE_SAVINGS) }, onDepositClick = { savingsAccountWithAssociations, depositType -> navController.navigateToSavingsAccountTransactionScreen( savingsAccountWithAssociations = savingsAccountWithAssociations, depositType = depositType, - transactionType = Constants.SAVINGS_ACCOUNT_TRANSACTION_DEPOSIT + transactionType = Constants.SAVINGS_ACCOUNT_TRANSACTION_DEPOSIT, ) }, onWithdrawButtonClicked = { savingsAccountWithAssociations, depositType -> navController.navigateToSavingsAccountTransactionScreen( savingsAccountWithAssociations = savingsAccountWithAssociations, depositType = depositType, - transactionType = Constants.SAVINGS_ACCOUNT_TRANSACTION_WITHDRAWAL + transactionType = Constants.SAVINGS_ACCOUNT_TRANSACTION_WITHDRAWAL, ) }, approveSavings = { _, accountNumber -> navController.navigateToSavingsAccountApproval( - accountNumber + accountNumber, ) }, activateSavings = { _, accountNumber -> navController.navigateToSavingsAccountActivate( - accountNumber + accountNumber, ) - } + }, ) addSavingsAccountScreen { @@ -78,18 +87,18 @@ fun NavGraphBuilder.savingsNavGraph( } fun NavGraphBuilder.addSavingsAccountScreen( - onBackPressed: () -> Unit + onBackPressed: () -> Unit, ) { composable( route = SavingsScreens.SavingsAccount.route, arguments = listOf( navArgument(name = Constants.GROUP_ID, builder = { type = NavType.IntType }), navArgument(name = Constants.CLIENT_ID, builder = { type = NavType.IntType }), - navArgument(name = Constants.GROUP_ACCOUNT, builder = { type = NavType.BoolType }) - ) + navArgument(name = Constants.GROUP_ACCOUNT, builder = { type = NavType.BoolType }), + ), ) { SavingsAccountScreen( - navigateBack = onBackPressed + navigateBack = onBackPressed, ) } } @@ -101,13 +110,13 @@ fun NavGraphBuilder.savingsSummaryScreen( onDepositClick: (SavingsAccountWithAssociations, DepositType?) -> Unit, onWithdrawButtonClicked: (SavingsAccountWithAssociations, DepositType?) -> Unit, approveSavings: (savingsAccountType: DepositType?, savingsAccountNumber: Int) -> Unit, - activateSavings: (savingsAccountType: DepositType?, savingsAccountNumber: Int) -> Unit + activateSavings: (savingsAccountType: DepositType?, savingsAccountNumber: Int) -> Unit, ) { composable( route = SavingsScreens.SavingsAccountSummary.route, arguments = listOf( - navArgument(name = "arg" , builder = { type = NavType.StringType }) - ) + navArgument(name = "arg", builder = { type = NavType.StringType }), + ), ) { SavingsAccountSummaryScreen( navigateBack = onBackPressed, @@ -116,52 +125,52 @@ fun NavGraphBuilder.savingsSummaryScreen( onDepositClick = onDepositClick, onWithdrawButtonClicked = onWithdrawButtonClicked, approveSavings = approveSavings, - activateSavings = activateSavings + activateSavings = activateSavings, ) } } fun NavGraphBuilder.savingsAccountActivateScreen( - onBackPressed: () -> Unit + onBackPressed: () -> Unit, ) { composable( route = SavingsScreens.SavingsAccountActivate.route, arguments = listOf( - navArgument(name = Constants.SAVINGS_ACCOUNT_ID, builder = { type = NavType.IntType }) - ) + navArgument(name = Constants.SAVINGS_ACCOUNT_ID, builder = { type = NavType.IntType }), + ), ) { SavingsAccountActivateScreen( - navigateBack = onBackPressed + navigateBack = onBackPressed, ) } } fun NavGraphBuilder.savingsAccountApprovalScreen( - onBackPressed: () -> Unit + onBackPressed: () -> Unit, ) { composable( route = SavingsScreens.SavingsAccountApproval.route, arguments = listOf( - navArgument(name = Constants.SAVINGS_ACCOUNT_ID, builder = { type = NavType.IntType }) - ) + navArgument(name = Constants.SAVINGS_ACCOUNT_ID, builder = { type = NavType.IntType }), + ), ) { SavingsAccountApprovalScreen( - navigateBack = onBackPressed + navigateBack = onBackPressed, ) } } fun NavGraphBuilder.savingsAccountTransactionScreen( - onBackPressed: () -> Unit + onBackPressed: () -> Unit, ) { composable( route = SavingsScreens.SavingsAccountTransaction.route, arguments = listOf( - navArgument(name = "arg" , builder = { type = NavType.StringType }) - ) + navArgument(name = "arg", builder = { type = NavType.StringType }), + ), ) { SavingsAccountTransactionScreen( - navigateBack = onBackPressed + navigateBack = onBackPressed, ) } } @@ -169,7 +178,7 @@ fun NavGraphBuilder.savingsAccountTransactionScreen( fun NavController.navigateToAddSavingsAccount( groupId: Int, clientId: Int, - isGroupAccount: Boolean + isGroupAccount: Boolean, ) { navigate(SavingsScreens.SavingsAccount.argument(groupId, clientId, isGroupAccount)) } @@ -182,20 +191,20 @@ fun NavController.navigateToSavingsAccountActivate(savingsAccountId: Int) { navigate(SavingsScreens.SavingsAccountActivate.argument(savingsAccountId)) } -fun NavController.navigateToSavingsAccountSummaryScreen(id : Int, type: DepositType){ +fun NavController.navigateToSavingsAccountSummaryScreen(id: Int, type: DepositType) { navigate(SavingsScreens.SavingsAccountSummary.argument(id, type)) } fun NavController.navigateToSavingsAccountTransactionScreen( savingsAccountWithAssociations: SavingsAccountWithAssociations, transactionType: String, - depositType: DepositType? + depositType: DepositType?, ) { navigate( SavingsScreens.SavingsAccountTransaction.argument( savingsAccountWithAssociations, transactionType, - depositType - ) + depositType, + ), ) -} \ No newline at end of file +} diff --git a/feature/savings/src/main/java/com/mifos/feature/savings/navigation/SavingsScreens.kt b/feature/savings/src/main/java/com/mifos/feature/savings/navigation/SavingsScreens.kt index 02f0ad2891e..de5e9db8224 100644 --- a/feature/savings/src/main/java/com/mifos/feature/savings/navigation/SavingsScreens.kt +++ b/feature/savings/src/main/java/com/mifos/feature/savings/navigation/SavingsScreens.kt @@ -1,3 +1,12 @@ +/* + * Copyright 2024 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/android-client/blob/master/LICENSE.md + */ package com.mifos.feature.savings.navigation import com.google.gson.Gson @@ -45,7 +54,7 @@ sealed class SavingsScreens(val route: String) { fun argument( savingsAccountWithAssociations: SavingsAccountWithAssociations, transactionType: String, - depositType: DepositType? + depositType: DepositType?, ): String { val gson = Gson() val arg = SavingsTransactionData(savingsAccountWithAssociations, depositType, transactionType) @@ -58,4 +67,3 @@ sealed class SavingsScreens(val route: String) { data object SavingsSyncAccountTransaction : SavingsScreens("savings_sync_account_transaction") } - diff --git a/feature/savings/src/main/java/com/mifos/feature/savings/account/SavingAccountUiState.kt b/feature/savings/src/main/java/com/mifos/feature/savings/savingsAccount/SavingAccountUiState.kt similarity index 62% rename from feature/savings/src/main/java/com/mifos/feature/savings/account/SavingAccountUiState.kt rename to feature/savings/src/main/java/com/mifos/feature/savings/savingsAccount/SavingAccountUiState.kt index 546eda57d4d..a76a0c16532 100644 --- a/feature/savings/src/main/java/com/mifos/feature/savings/account/SavingAccountUiState.kt +++ b/feature/savings/src/main/java/com/mifos/feature/savings/savingsAccount/SavingAccountUiState.kt @@ -1,4 +1,13 @@ -package com.mifos.feature.savings.account +/* + * Copyright 2024 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/android-client/blob/master/LICENSE.md + */ +package com.mifos.feature.savings.savingsAccount import com.mifos.core.objects.client.Savings import com.mifos.core.objects.zipmodels.SavingProductsAndTemplate @@ -18,4 +27,4 @@ sealed class SavingAccountUiState { data class ShowSavingsAccountCreatedSuccessfully(val savings: Savings?) : SavingAccountUiState() data class ShowFetchingErrorString(val message: String) : SavingAccountUiState() -} \ No newline at end of file +} diff --git a/feature/savings/src/main/java/com/mifos/feature/savings/account/SavingAccountViewModel.kt b/feature/savings/src/main/java/com/mifos/feature/savings/savingsAccount/SavingAccountViewModel.kt similarity index 61% rename from feature/savings/src/main/java/com/mifos/feature/savings/account/SavingAccountViewModel.kt rename to feature/savings/src/main/java/com/mifos/feature/savings/savingsAccount/SavingAccountViewModel.kt index b958f36e2b0..74bcb39710d 100644 --- a/feature/savings/src/main/java/com/mifos/feature/savings/account/SavingAccountViewModel.kt +++ b/feature/savings/src/main/java/com/mifos/feature/savings/savingsAccount/SavingAccountViewModel.kt @@ -1,20 +1,25 @@ -package com.mifos.feature.savings.account +/* + * Copyright 2024 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/android-client/blob/master/LICENSE.md + */ +package com.mifos.feature.savings.savingsAccount -import androidx.compose.runtime.key import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.mifos.core.common.utils.Constants import com.mifos.core.common.utils.Resource import com.mifos.core.data.SavingsPayload -import com.mifos.core.data.repository.SavingsAccountRepository import com.mifos.core.domain.use_cases.CreateSavingsAccountUseCase import com.mifos.core.domain.use_cases.GetClientSavingsAccountTemplateByProductUseCase import com.mifos.core.domain.use_cases.GetGroupSavingsAccountTemplateByProductUseCase import com.mifos.core.domain.use_cases.LoadSavingsAccountsAndTemplateUseCase -import com.mifos.core.objects.client.Savings import com.mifos.core.objects.templates.savings.SavingProductsTemplate -import com.mifos.core.objects.zipmodels.SavingProductsAndTemplate import com.mifos.feature.savings.R import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.Dispatchers @@ -22,10 +27,6 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch -import rx.Observable -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers import javax.inject.Inject /** @@ -37,12 +38,12 @@ class SavingAccountViewModel @Inject constructor( private val createSavingsAccountUseCase: CreateSavingsAccountUseCase, private val getGroupSavingsAccountTemplateByProductUseCase: GetGroupSavingsAccountTemplateByProductUseCase, private val getClientSavingsAccountTemplateByProductUseCase: GetClientSavingsAccountTemplateByProductUseCase, - savedStateHandle: SavedStateHandle + savedStateHandle: SavedStateHandle, ) : ViewModel() { val groupId = savedStateHandle.getStateFlow(key = Constants.GROUP_ID, initialValue = 0) val clientId = savedStateHandle.getStateFlow(key = Constants.CLIENT_ID, initialValue = 0) - val isGroupAccount = savedStateHandle.getStateFlow(key = Constants.GROUP_ACCOUNT , initialValue = false) + val isGroupAccount = savedStateHandle.getStateFlow(key = Constants.GROUP_ACCOUNT, initialValue = false) private val _savingAccountUiState = MutableStateFlow(SavingAccountUiState.ShowProgress) val savingAccountUiState: StateFlow get() = _savingAccountUiState @@ -54,11 +55,13 @@ class SavingAccountViewModel @Inject constructor( viewModelScope.launch(Dispatchers.IO) { loadSavingsAccountsAndTemplateUseCase().collect { result -> when (result) { - is Resource.Error -> _savingAccountUiState.value = - SavingAccountUiState.ShowFetchingError(R.string.feature_savings_failed_to_load_savings_products_and_template) + is Resource.Error -> + _savingAccountUiState.value = + SavingAccountUiState.ShowFetchingError(R.string.feature_savings_failed_to_load_savings_products_and_template) - is Resource.Loading -> _savingAccountUiState.value = - SavingAccountUiState.ShowProgress + is Resource.Loading -> + _savingAccountUiState.value = + SavingAccountUiState.ShowProgress is Resource.Success -> if (result.data != null) { _savingAccountUiState.value = @@ -72,13 +75,15 @@ class SavingAccountViewModel @Inject constructor( viewModelScope.launch(Dispatchers.IO) { getClientSavingsAccountTemplateByProductUseCase(clientId, productId).collect { result -> when (result) { - is Resource.Error -> _savingAccountUiState.value = - SavingAccountUiState.ShowFetchingError(R.string.feature_savings_failed_to_load_savings_products_and_template) + is Resource.Error -> + _savingAccountUiState.value = + SavingAccountUiState.ShowFetchingError(R.string.feature_savings_failed_to_load_savings_products_and_template) is Resource.Loading -> Unit - is Resource.Success -> _savingProductsTemplate.value = - result.data ?: SavingProductsTemplate() + is Resource.Success -> + _savingProductsTemplate.value = + result.data ?: SavingProductsTemplate() } } } @@ -87,13 +92,15 @@ class SavingAccountViewModel @Inject constructor( viewModelScope.launch(Dispatchers.IO) { getGroupSavingsAccountTemplateByProductUseCase(groupId, productId).collect { result -> when (result) { - is Resource.Error -> _savingAccountUiState.value = - SavingAccountUiState.ShowFetchingError(R.string.feature_savings_failed_to_load_savings_products_and_template) + is Resource.Error -> + _savingAccountUiState.value = + SavingAccountUiState.ShowFetchingError(R.string.feature_savings_failed_to_load_savings_products_and_template) is Resource.Loading -> Unit - is Resource.Success -> _savingProductsTemplate.value = - result.data ?: SavingProductsTemplate() + is Resource.Success -> + _savingProductsTemplate.value = + result.data ?: SavingProductsTemplate() } } } @@ -102,16 +109,18 @@ class SavingAccountViewModel @Inject constructor( viewModelScope.launch(Dispatchers.IO) { createSavingsAccountUseCase(savingsPayload).collect { result -> when (result) { - is Resource.Error -> _savingAccountUiState.value = - SavingAccountUiState.ShowFetchingErrorString(result.message.toString()) + is Resource.Error -> + _savingAccountUiState.value = + SavingAccountUiState.ShowFetchingErrorString(result.message.toString()) - is Resource.Loading -> _savingAccountUiState.value = - SavingAccountUiState.ShowProgress + is Resource.Loading -> + _savingAccountUiState.value = + SavingAccountUiState.ShowProgress - is Resource.Success -> _savingAccountUiState.value = - SavingAccountUiState.ShowSavingsAccountCreatedSuccessfully(result.data) + is Resource.Success -> + _savingAccountUiState.value = + SavingAccountUiState.ShowSavingsAccountCreatedSuccessfully(result.data) } } } - -} \ No newline at end of file +} diff --git a/feature/savings/src/main/java/com/mifos/feature/savings/account/SavingsAccountScreen.kt b/feature/savings/src/main/java/com/mifos/feature/savings/savingsAccount/SavingsAccountScreen.kt similarity index 85% rename from feature/savings/src/main/java/com/mifos/feature/savings/account/SavingsAccountScreen.kt rename to feature/savings/src/main/java/com/mifos/feature/savings/savingsAccount/SavingsAccountScreen.kt index f25451e4b1a..cc6973c32c9 100644 --- a/feature/savings/src/main/java/com/mifos/feature/savings/account/SavingsAccountScreen.kt +++ b/feature/savings/src/main/java/com/mifos/feature/savings/savingsAccount/SavingsAccountScreen.kt @@ -1,4 +1,13 @@ -package com.mifos.feature.savings.account +/* + * Copyright 2024 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/android-client/blob/master/LICENSE.md + */ +package com.mifos.feature.savings.savingsAccount import android.widget.Toast import androidx.compose.animation.AnimatedVisibility @@ -78,10 +87,10 @@ import java.util.Locale */ @Composable -fun SavingsAccountScreen( - navigateBack: () -> Unit +internal fun SavingsAccountScreen( + navigateBack: () -> Unit, + viewModel: SavingAccountViewModel = hiltViewModel(), ) { - val viewModel: SavingAccountViewModel = hiltViewModel() val uiState by viewModel.savingAccountUiState.collectAsStateWithLifecycle() val savingProductsTemplate by viewModel.savingProductsTemplate.collectAsStateWithLifecycle() val groupId by viewModel.groupId.collectAsStateWithLifecycle() @@ -100,26 +109,30 @@ fun SavingsAccountScreen( viewModel.loadSavingsAccountsAndTemplate() }, onSavingsProductSelected = { productId -> - if(isGroupAccount){ + if (isGroupAccount) { viewModel.loadGroupSavingAccountTemplateByProduct(groupId, productId) - } else viewModel.loadClientSavingAccountTemplateByProduct(clientId, productId) + } else { + viewModel.loadClientSavingAccountTemplateByProduct(clientId, productId) + } }, fetchTemplate = { productId -> - if(isGroupAccount){ + if (isGroupAccount) { viewModel.loadGroupSavingAccountTemplateByProduct(groupId, productId) - } else viewModel.loadClientSavingAccountTemplateByProduct(clientId, productId) + } else { + viewModel.loadClientSavingAccountTemplateByProduct(clientId, productId) + } }, clientId = clientId, groupId = groupId, isGroupAccount = isGroupAccount, createSavingsAccount = { savingsPayload -> viewModel.createSavingsAccount(savingsPayload) - } + }, ) } @Composable -fun SavingsAccountScreen( +internal fun SavingsAccountScreen( uiState: SavingAccountUiState, savingProductsTemplate: SavingProductsTemplate, onSavingsProductSelected: (Int) -> Unit, @@ -129,6 +142,7 @@ fun SavingsAccountScreen( isGroupAccount: Boolean, clientId: Int, groupId: Int, + modifier: Modifier = Modifier, createSavingsAccount: (savingsPayload: SavingsPayload) -> Unit, ) { val snackBarHostState = remember { @@ -137,15 +151,16 @@ fun SavingsAccountScreen( val context = LocalContext.current MifosScaffold( + modifier = modifier, snackbarHostState = snackBarHostState, title = stringResource(id = R.string.feature_savings_create_savings_account), icon = MifosIcons.arrowBack, - onBackPressed = navigateBack + onBackPressed = navigateBack, ) { Box( modifier = Modifier .padding(it) - .fillMaxSize() + .fillMaxSize(), ) { when (uiState) { is SavingAccountUiState.ShowProgress -> { @@ -162,7 +177,7 @@ fun SavingsAccountScreen( MifosSweetError( message = uiState.message, buttonText = stringResource(id = R.string.feature_savings_go_back), - onclick = { onRetry() } + onclick = { onRetry() }, ) } @@ -178,7 +193,7 @@ fun SavingsAccountScreen( savingProductsTemplate = uiState.savingsTemplate, productSavings = productSavingsList, onSavingsProductSelected = onSavingsProductSelected, - createSavingsAccount = createSavingsAccount + createSavingsAccount = createSavingsAccount, ) productSavingsList[0].id?.let { it2 -> fetchTemplate.invoke(it2) } @@ -188,7 +203,7 @@ fun SavingsAccountScreen( Toast.makeText( context, context.resources.getString(R.string.feature_savings_savings_account_submitted_for_approval), - Toast.LENGTH_LONG + Toast.LENGTH_LONG, ).show() navigateBack() @@ -200,7 +215,7 @@ fun SavingsAccountScreen( @OptIn(ExperimentalMaterial3Api::class) @Composable -fun SavingsAccountContent( +private fun SavingsAccountContent( clientId: Int, groupId: Int, isGroupAccount: Boolean, @@ -208,23 +223,14 @@ fun SavingsAccountContent( productSavings: List, savingProductsTemplate: SavingProductsAndTemplate, onSavingsProductSelected: (Int) -> Unit, - createSavingsAccount: (savingsPayload: SavingsPayload) -> Unit + modifier: Modifier = Modifier, + createSavingsAccount: (savingsPayload: SavingsPayload) -> Unit, ) { - var selectedSavingsProduct by rememberSaveable { - mutableStateOf("") - } - var selectedFieldOfficer by rememberSaveable { - mutableStateOf("") - } - var overDraftAllowed by rememberSaveable { - mutableStateOf(false) - } - var enforceMinimumBalance by rememberSaveable { - mutableStateOf(false) - } - var externalId by rememberSaveable { - mutableStateOf("") - } + var selectedSavingsProduct by rememberSaveable { mutableStateOf("") } + var selectedFieldOfficer by rememberSaveable { mutableStateOf("") } + var overDraftAllowed by rememberSaveable { mutableStateOf(false) } + var enforceMinimumBalance by rememberSaveable { mutableStateOf(false) } + var externalId by rememberSaveable { mutableStateOf("") } var maximumOverdraftAmount by rememberSaveable { mutableStateOf("") } @@ -265,7 +271,7 @@ fun SavingsAccountContent( override fun isSelectableDate(utcTimeMillis: Long): Boolean { return utcTimeMillis >= System.currentTimeMillis() } - } + }, ) if (pickSubmitDate) { @@ -280,26 +286,25 @@ fun SavingsAccountContent( submittedOnDate = it } pickSubmitDate = false - } + }, ) { Text(stringResource(id = R.string.feature_savings_select_date)) } }, dismissButton = { TextButton( onClick = { pickSubmitDate = false - } + }, ) { Text(stringResource(id = R.string.feature_savings_cancel)) } - } - ) - { + }, + ) { DatePicker(state = datePickerState) } } Column( - modifier = Modifier + modifier = modifier .fillMaxSize() - .verticalScroll(scrollState) + .verticalScroll(scrollState), ) { Spacer(modifier = Modifier.height(16.dp)) @@ -314,11 +319,10 @@ fun SavingsAccountContent( selectedSavingsProductID = it onSavingsProductSelected.invoke(it) } - }, label = R.string.feature_savings_product, options = productSavings.map { it.name.toString() }, - readOnly = true + readOnly = true, ) Spacer(modifier = Modifier.height(16.dp)) @@ -336,7 +340,7 @@ fun SavingsAccountContent( }, label = R.string.feature_savings_field_officer, options = fieldOfficerOptions.map { it.displayName.toString() }, - readOnly = true + readOnly = true, ) Spacer(modifier = Modifier.height(16.dp)) @@ -345,29 +349,29 @@ fun SavingsAccountContent( value = externalId, onValueChange = { externalId = it }, label = stringResource(id = R.string.feature_savings_external_id), - error = null + error = null, ) Spacer(modifier = Modifier.height(16.dp)) MifosDatePickerTextField( value = SimpleDateFormat( - "dd MMMM yyyy", Locale.getDefault() + "dd MMMM yyyy", + Locale.getDefault(), ).format(submittedOnDate), - label = R.string.feature_savings_submitted_on + label = R.string.feature_savings_submitted_on, ) { pickSubmitDate = true } Spacer(modifier = Modifier.height(16.dp)) - MifosOutlinedTextField( value = nominalAnnualInterest, onValueChange = { nominalAnnualInterest = it }, label = stringResource(id = R.string.feature_savings_nominal), error = null, - keyboardType = KeyboardType.Number + keyboardType = KeyboardType.Number, ) Spacer(modifier = Modifier.height(16.dp)) @@ -377,7 +381,7 @@ fun SavingsAccountContent( onValueChange = { interestCalculatedUsing = it }, label = stringResource(id = R.string.feature_savings_interest_calc), error = null, - readOnly = true + readOnly = true, ) Spacer(modifier = Modifier.height(16.dp)) @@ -397,7 +401,7 @@ fun SavingsAccountContent( onValueChange = { interestPostingPeriod = it }, label = stringResource(id = R.string.feature_savings_interest_p_period), error = null, - readOnly = true + readOnly = true, ) Spacer(modifier = Modifier.height(16.dp)) @@ -407,21 +411,21 @@ fun SavingsAccountContent( onValueChange = { }, label = stringResource(id = R.string.feature_savings_days_in_year), error = null, - readOnly = true + readOnly = true, ) Spacer(modifier = Modifier.height(16.dp)) Row( modifier = Modifier.fillMaxWidth(), - verticalAlignment = Alignment.CenterVertically + verticalAlignment = Alignment.CenterVertically, ) { Checkbox( checked = enforceMinimumBalance, onCheckedChange = { enforceMinimumBalance = !enforceMinimumBalance }, colors = CheckboxDefaults.colors( - checkedColor = if (isSystemInDarkTheme()) BluePrimaryDark else BluePrimary - ) + checkedColor = if (isSystemInDarkTheme()) BluePrimaryDark else BluePrimary, + ), ) Text(text = stringResource(id = R.string.feature_savings_min_required_balance)) @@ -432,11 +436,11 @@ fun SavingsAccountContent( enter = slideInVertically { with(density) { -40.dp.roundToPx() } } + expandVertically( - expandFrom = Alignment.Top + expandFrom = Alignment.Top, ) + fadeIn( - initialAlpha = 0.3f + initialAlpha = 0.3f, ), - exit = slideOutVertically() + shrinkVertically() + fadeOut() + exit = slideOutVertically() + shrinkVertically() + fadeOut(), ) { Spacer(modifier = Modifier.height(16.dp)) @@ -445,7 +449,7 @@ fun SavingsAccountContent( onValueChange = { minimumRequiredBalance = it }, label = stringResource(id = R.string.feature_savings_min_required_balance), error = null, - keyboardType = KeyboardType.Number + keyboardType = KeyboardType.Number, ) } @@ -453,14 +457,14 @@ fun SavingsAccountContent( Row( modifier = Modifier.fillMaxWidth(), - verticalAlignment = Alignment.CenterVertically + verticalAlignment = Alignment.CenterVertically, ) { Checkbox( checked = overDraftAllowed, onCheckedChange = { overDraftAllowed = !overDraftAllowed }, colors = CheckboxDefaults.colors( - checkedColor = if (isSystemInDarkTheme()) BluePrimaryDark else BluePrimary - ) + checkedColor = if (isSystemInDarkTheme()) BluePrimaryDark else BluePrimary, + ), ) Text(text = stringResource(id = R.string.feature_savings_overdraft_allowed)) @@ -471,11 +475,11 @@ fun SavingsAccountContent( enter = slideInVertically { with(density) { -40.dp.roundToPx() } } + expandVertically( - expandFrom = Alignment.Top + expandFrom = Alignment.Top, ) + fadeIn( - initialAlpha = 0.3f + initialAlpha = 0.3f, ), - exit = slideOutVertically() + shrinkVertically() + fadeOut() + exit = slideOutVertically() + shrinkVertically() + fadeOut(), ) { Column { Spacer(modifier = Modifier.height(16.dp)) @@ -485,7 +489,7 @@ fun SavingsAccountContent( onValueChange = { maximumOverdraftAmount = it }, label = stringResource(id = R.string.feature_savings_maxoverdraft), error = null, - keyboardType = KeyboardType.Number + keyboardType = KeyboardType.Number, ) Spacer(modifier = Modifier.height(16.dp)) @@ -495,7 +499,7 @@ fun SavingsAccountContent( onValueChange = { nominalAnnualInterestOverdraft = it }, label = stringResource(id = R.string.feature_savings_nominal_overdraft), error = null, - keyboardType = KeyboardType.Number + keyboardType = KeyboardType.Number, ) Spacer(modifier = Modifier.height(16.dp)) @@ -505,7 +509,7 @@ fun SavingsAccountContent( onValueChange = { minimumOverdraftAmount = it }, label = stringResource(id = R.string.feature_savings_min_overdraft), error = null, - keyboardType = KeyboardType.Number + keyboardType = KeyboardType.Number, ) } } @@ -519,7 +523,7 @@ fun SavingsAccountContent( .padding(horizontal = 16.dp), contentPadding = PaddingValues(), colors = ButtonDefaults.buttonColors( - containerColor = if (isSystemInDarkTheme()) BluePrimaryDark else BluePrimary + containerColor = if (isSystemInDarkTheme()) BluePrimaryDark else BluePrimary, ), onClick = { if (Network.isOnline(context)) { @@ -528,7 +532,7 @@ fun SavingsAccountContent( savingsPayload.externalId = externalId savingsPayload.locale = "en" savingsPayload.submittedOnDate = SimpleDateFormat( - "dd MMMM yyyy", Locale.getDefault() + "dd MMMM yyyy", Locale.getDefault(), ).format(submittedOnDate) savingsPayload.dateFormat = "dd MMMM yyyy" if (isGroupAccount) { @@ -551,52 +555,52 @@ fun SavingsAccountContent( Toast.makeText( context, context.resources.getString(R.string.feature_savings_error_not_connected_internet), - Toast.LENGTH_SHORT + Toast.LENGTH_SHORT, ).show() } - } + }, ) { Text(text = stringResource(id = R.string.feature_savings_submit)) } } } - class SavingsAccountScreenPreviewProvider : PreviewParameterProvider { override val values: Sequence get() = sequenceOf( SavingAccountUiState.ShowProgress, - SavingAccountUiState.LoadAllSavings(SavingProductsAndTemplate( - mProductSavings = listOf( - ProductSavings( - id = 0, - name = "Product" - ) + SavingAccountUiState.LoadAllSavings( + SavingProductsAndTemplate( + mProductSavings = listOf( + ProductSavings( + id = 0, + name = "Product", + ), + ), + mSavingProductsTemplate = SavingProductsTemplate(), ), - mSavingProductsTemplate = SavingProductsTemplate() - )), + ), SavingAccountUiState.ShowFetchingErrorString("Failed to fetch"), SavingAccountUiState.ShowSavingsAccountCreatedSuccessfully(Savings()), - SavingAccountUiState.ShowFetchingError(R.string.feature_savings_failed_to_fetch_savings_template) + SavingAccountUiState.ShowFetchingError(R.string.feature_savings_failed_to_fetch_savings_template), ) } @Composable @Preview(showSystemUi = true) -fun PreviewSavingsAccountScreen( - @PreviewParameter(SavingsAccountScreenPreviewProvider::class) savingAccountUiState: SavingAccountUiState +private fun PreviewSavingsAccountScreen( + @PreviewParameter(SavingsAccountScreenPreviewProvider::class) savingAccountUiState: SavingAccountUiState, ) { SavingsAccountScreen( uiState = savingAccountUiState, savingProductsTemplate = SavingProductsTemplate(), - onSavingsProductSelected = { } , + onSavingsProductSelected = { }, navigateBack = { }, onRetry = { }, fetchTemplate = { }, isGroupAccount = true, clientId = 0, - groupId = 0 + groupId = 0, ) { - } -} \ No newline at end of file +} diff --git a/feature/savings/src/main/java/com/mifos/feature/savings/account_activate/SavingsAccountActivateScreen.kt b/feature/savings/src/main/java/com/mifos/feature/savings/savingsAccountActivate/SavingsAccountActivateScreen.kt similarity index 82% rename from feature/savings/src/main/java/com/mifos/feature/savings/account_activate/SavingsAccountActivateScreen.kt rename to feature/savings/src/main/java/com/mifos/feature/savings/savingsAccountActivate/SavingsAccountActivateScreen.kt index 42e8d360d90..7c634a4e48e 100644 --- a/feature/savings/src/main/java/com/mifos/feature/savings/account_activate/SavingsAccountActivateScreen.kt +++ b/feature/savings/src/main/java/com/mifos/feature/savings/savingsAccountActivate/SavingsAccountActivateScreen.kt @@ -1,4 +1,13 @@ -package com.mifos.feature.savings.account_activate +/* + * Copyright 2024 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/android-client/blob/master/LICENSE.md + */ +package com.mifos.feature.savings.savingsAccountActivate import android.widget.Toast import androidx.compose.foundation.isSystemInDarkTheme @@ -58,24 +67,25 @@ import java.util.Locale */ @Composable -fun SavingsAccountActivateScreen( - navigateBack: () -> Unit +internal fun SavingsAccountActivateScreen( + navigateBack: () -> Unit, + viewModel: SavingsAccountActivateViewModel = hiltViewModel(), ) { - val viewModel: SavingsAccountActivateViewModel = hiltViewModel() val uiState by viewModel.savingsAccountActivateUiState.collectAsStateWithLifecycle() val savingsAccountId by viewModel.savingsAccountId.collectAsStateWithLifecycle() SavingsAccountActivateScreen( uiState = uiState, navigateBack = navigateBack, - activateSavings = { viewModel.activateSavings(savingsAccountId, it) } + activateSavings = { viewModel.activateSavings(savingsAccountId, it) }, ) } @Composable -fun SavingsAccountActivateScreen( +internal fun SavingsAccountActivateScreen( uiState: SavingsAccountActivateUiState, navigateBack: () -> Unit, + modifier: Modifier = Modifier, activateSavings: (hashMap: HashMap) -> Unit, ) { val snackBarHostState = remember { @@ -84,20 +94,21 @@ fun SavingsAccountActivateScreen( val context = LocalContext.current MifosScaffold( + modifier = modifier, snackbarHostState = snackBarHostState, title = stringResource(id = R.string.feature_savings_activate_savings), onBackPressed = navigateBack, - icon = MifosIcons.arrowBack + icon = MifosIcons.arrowBack, ) { Box( modifier = Modifier .fillMaxSize() - .padding(it) + .padding(it), ) { when (uiState) { SavingsAccountActivateUiState.Initial -> { SavingsAccountActivateContent( - activateSavings = activateSavings + activateSavings = activateSavings, ) } @@ -105,7 +116,7 @@ fun SavingsAccountActivateScreen( MifosSweetError( message = uiState.message, isRetryEnabled = false, - onclick = {} + onclick = {}, ) } @@ -117,7 +128,7 @@ fun SavingsAccountActivateScreen( Toast.makeText( context, context.resources.getString(R.string.feature_savings_savings_account_activated), - Toast.LENGTH_LONG + Toast.LENGTH_LONG, ).show() navigateBack.invoke() @@ -129,7 +140,8 @@ fun SavingsAccountActivateScreen( @OptIn(ExperimentalMaterial3Api::class) @Composable -fun SavingsAccountActivateContent( +private fun SavingsAccountActivateContent( + modifier: Modifier = Modifier, activateSavings: (hashMap: HashMap) -> Unit, ) { val scrollstate = rememberScrollState() @@ -149,7 +161,7 @@ fun SavingsAccountActivateContent( override fun isSelectableDate(utcTimeMillis: Long): Boolean { return utcTimeMillis >= System.currentTimeMillis() } - } + }, ) if (showDatePickerDialog) { @@ -164,33 +176,32 @@ fun SavingsAccountActivateContent( approvalDate = it } showDatePickerDialog = false - } + }, ) { Text(stringResource(id = R.string.feature_savings_select_date)) } }, dismissButton = { TextButton( onClick = { showDatePickerDialog = false - } + }, ) { Text(stringResource(id = R.string.feature_savings_cancel)) } - } - ) - { + }, + ) { DatePicker(state = datePickerState) } } Column( - modifier = Modifier + modifier = modifier .fillMaxSize() - .verticalScroll(scrollstate) + .verticalScroll(scrollstate), ) { Spacer(modifier = Modifier.height(16.dp)) Text( style = MaterialTheme.typography.bodyLarge, text = stringResource(id = R.string.feature_savings_approved_on), - modifier = Modifier.padding(start = 16.dp) + modifier = Modifier.padding(start = 16.dp), ) Spacer(modifier = Modifier.height(16.dp)) @@ -198,8 +209,9 @@ fun SavingsAccountActivateContent( MifosDatePickerTextField( value = SimpleDateFormat( "dd-MMMM-yyyy", - Locale.getDefault() - ).format(approvalDate), label = R.string.feature_savings_approval_savings_date + Locale.getDefault(), + ).format(approvalDate), + label = R.string.feature_savings_approval_savings_date, ) { showDatePickerDialog = true } @@ -210,17 +222,18 @@ fun SavingsAccountActivateContent( value = approvalReason, onValueChange = { approvalReason = it }, label = stringResource(id = R.string.feature_savings_savings_approval_reason), - error = null + error = null, ) Spacer(modifier = Modifier.height(16.dp)) - Button(modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 16.dp) - .heightIn(46.dp), + Button( + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 16.dp) + .heightIn(46.dp), colors = ButtonDefaults.buttonColors( - containerColor = if (isSystemInDarkTheme()) BluePrimaryDark else BluePrimary + containerColor = if (isSystemInDarkTheme()) BluePrimaryDark else BluePrimary, ), onClick = { if (Network.isOnline(context)) { @@ -228,7 +241,7 @@ fun SavingsAccountActivateContent( hashMap["dateFormat"] = "dd MMMM yyyy" hashMap["activatedOnDate"] = SimpleDateFormat( "dd-MMMM-yyyy", - Locale.getDefault() + Locale.getDefault(), ).format(approvalDate) hashMap["locale"] = "en" @@ -237,10 +250,11 @@ fun SavingsAccountActivateContent( Toast.makeText( context, context.resources.getString(R.string.feature_savings_error_not_connected_internet), - Toast.LENGTH_SHORT + Toast.LENGTH_SHORT, ).show() } - }) { + }, + ) { Text(text = stringResource(id = R.string.feature_savings_save)) } } @@ -253,18 +267,19 @@ class SavingsAccountActivateScreenPreviewProvider : SavingsAccountActivateUiState.Initial, SavingsAccountActivateUiState.ShowProgressbar, SavingsAccountActivateUiState.ShowSavingAccountActivatedSuccessfully(GenericResponse()), - SavingsAccountActivateUiState.ShowError("Error") + SavingsAccountActivateUiState.ShowError("Error"), ) } @Composable @Preview(showSystemUi = true) -fun PreviewSavingsAccountActivateScreen( - @PreviewParameter(SavingsAccountActivateScreenPreviewProvider::class) savingsAccountActivateUiState: SavingsAccountActivateUiState +private fun PreviewSavingsAccountActivateScreen( + @PreviewParameter(SavingsAccountActivateScreenPreviewProvider::class) + savingsAccountActivateUiState: SavingsAccountActivateUiState, ) { SavingsAccountActivateScreen( uiState = savingsAccountActivateUiState, navigateBack = { }, - activateSavings = {} + activateSavings = {}, ) } diff --git a/feature/savings/src/main/java/com/mifos/feature/savings/account_activate/SavingsAccountActivateUiState.kt b/feature/savings/src/main/java/com/mifos/feature/savings/savingsAccountActivate/SavingsAccountActivateUiState.kt similarity index 55% rename from feature/savings/src/main/java/com/mifos/feature/savings/account_activate/SavingsAccountActivateUiState.kt rename to feature/savings/src/main/java/com/mifos/feature/savings/savingsAccountActivate/SavingsAccountActivateUiState.kt index c92e75d08dd..7e7f392ec87 100644 --- a/feature/savings/src/main/java/com/mifos/feature/savings/account_activate/SavingsAccountActivateUiState.kt +++ b/feature/savings/src/main/java/com/mifos/feature/savings/savingsAccountActivate/SavingsAccountActivateUiState.kt @@ -1,4 +1,13 @@ -package com.mifos.feature.savings.account_activate +/* + * Copyright 2024 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/android-client/blob/master/LICENSE.md + */ +package com.mifos.feature.savings.savingsAccountActivate import com.mifos.core.network.GenericResponse @@ -15,4 +24,4 @@ sealed class SavingsAccountActivateUiState { data class ShowSavingAccountActivatedSuccessfully(val genericResponse: GenericResponse) : SavingsAccountActivateUiState() -} \ No newline at end of file +} diff --git a/feature/savings/src/main/java/com/mifos/feature/savings/account_activate/SavingsAccountActivateViewModel.kt b/feature/savings/src/main/java/com/mifos/feature/savings/savingsAccountActivate/SavingsAccountActivateViewModel.kt similarity index 55% rename from feature/savings/src/main/java/com/mifos/feature/savings/account_activate/SavingsAccountActivateViewModel.kt rename to feature/savings/src/main/java/com/mifos/feature/savings/savingsAccountActivate/SavingsAccountActivateViewModel.kt index b9fc8e751da..80443d83259 100644 --- a/feature/savings/src/main/java/com/mifos/feature/savings/account_activate/SavingsAccountActivateViewModel.kt +++ b/feature/savings/src/main/java/com/mifos/feature/savings/savingsAccountActivate/SavingsAccountActivateViewModel.kt @@ -1,22 +1,26 @@ -package com.mifos.feature.savings.account_activate +/* + * Copyright 2024 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/android-client/blob/master/LICENSE.md + */ +package com.mifos.feature.savings.savingsAccountActivate import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.mifos.core.common.utils.Constants import com.mifos.core.common.utils.Resource -import com.mifos.core.data.repository.SavingsAccountActivateRepository import com.mifos.core.domain.use_cases.ActivateSavingsUseCase import com.mifos.core.network.GenericResponse -import com.mifos.core.objects.accounts.savings.Transaction_Table import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.launch -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers import javax.inject.Inject /** @@ -25,7 +29,7 @@ import javax.inject.Inject @HiltViewModel class SavingsAccountActivateViewModel @Inject constructor( private val activateSavingsUseCase: ActivateSavingsUseCase, - private val savedStateHandle: SavedStateHandle + private val savedStateHandle: SavedStateHandle, ) : ViewModel() { val savingsAccountId = savedStateHandle.getStateFlow(Constants.SAVINGS_ACCOUNT_ID, 0) @@ -36,22 +40,24 @@ class SavingsAccountActivateViewModel @Inject constructor( val savingsAccountActivateUiState: StateFlow get() = _savingsAccountActivateUiState - fun activateSavings(savingsAccountId: Int, request: HashMap) = viewModelScope.launch(Dispatchers.IO) { activateSavingsUseCase(savingsAccountId, request).collect { result -> when (result) { - is Resource.Error -> _savingsAccountActivateUiState.value = - SavingsAccountActivateUiState.ShowError(result.message.toString()) - - is Resource.Loading -> _savingsAccountActivateUiState.value = - SavingsAccountActivateUiState.ShowProgressbar - - is Resource.Success -> _savingsAccountActivateUiState.value = - SavingsAccountActivateUiState.ShowSavingAccountActivatedSuccessfully( - result.data ?: GenericResponse() - ) + is Resource.Error -> + _savingsAccountActivateUiState.value = + SavingsAccountActivateUiState.ShowError(result.message.toString()) + + is Resource.Loading -> + _savingsAccountActivateUiState.value = + SavingsAccountActivateUiState.ShowProgressbar + + is Resource.Success -> + _savingsAccountActivateUiState.value = + SavingsAccountActivateUiState.ShowSavingAccountActivatedSuccessfully( + result.data ?: GenericResponse(), + ) } } } -} \ No newline at end of file +} diff --git a/feature/savings/src/main/java/com/mifos/feature/savings/account_approval/SavingsAccountApprovalScreen.kt b/feature/savings/src/main/java/com/mifos/feature/savings/savingsAccountApproval/SavingsAccountApprovalScreen.kt similarity index 81% rename from feature/savings/src/main/java/com/mifos/feature/savings/account_approval/SavingsAccountApprovalScreen.kt rename to feature/savings/src/main/java/com/mifos/feature/savings/savingsAccountApproval/SavingsAccountApprovalScreen.kt index f579d5e75ec..ebc00897e58 100644 --- a/feature/savings/src/main/java/com/mifos/feature/savings/account_approval/SavingsAccountApprovalScreen.kt +++ b/feature/savings/src/main/java/com/mifos/feature/savings/savingsAccountApproval/SavingsAccountApprovalScreen.kt @@ -1,4 +1,13 @@ -package com.mifos.feature.savings.account_approval +/* + * Copyright 2024 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/android-client/blob/master/LICENSE.md + */ +package com.mifos.feature.savings.savingsAccountApproval import android.widget.Toast import androidx.compose.foundation.isSystemInDarkTheme @@ -59,24 +68,25 @@ import java.util.Locale */ @Composable -fun SavingsAccountApprovalScreen( - navigateBack: () -> Unit +internal fun SavingsAccountApprovalScreen( + navigateBack: () -> Unit, + viewModel: SavingsAccountApprovalViewModel = hiltViewModel(), ) { - val viewModel: SavingsAccountApprovalViewModel = hiltViewModel() val uiState by viewModel.savingsAccountApprovalUiState.collectAsStateWithLifecycle() val savingsAccountId by viewModel.savingsAccountId.collectAsStateWithLifecycle() SavingsAccountApprovalScreen( uiState = uiState, navigateBack = navigateBack, - approveLoan = { viewModel.approveSavingsApplication(savingsAccountId, it) } + approveLoan = { viewModel.approveSavingsApplication(savingsAccountId, it) }, ) } @Composable -fun SavingsAccountApprovalScreen( +internal fun SavingsAccountApprovalScreen( uiState: SavingsAccountApprovalUiState, navigateBack: () -> Unit, + modifier: Modifier = Modifier, approveLoan: (SavingsApproval) -> Unit, ) { val snackbarHostState = remember { @@ -85,15 +95,16 @@ fun SavingsAccountApprovalScreen( val context = LocalContext.current MifosScaffold( + modifier = modifier, snackbarHostState = snackbarHostState, title = stringResource(id = R.string.feature_savings_approve_savings), onBackPressed = navigateBack, - icon = MifosIcons.arrowBack + icon = MifosIcons.arrowBack, ) { Box( modifier = Modifier .fillMaxSize() - .padding(it) + .padding(it), ) { when (uiState) { SavingsAccountApprovalUiState.Initial -> { @@ -104,7 +115,7 @@ fun SavingsAccountApprovalScreen( MifosSweetError( message = uiState.message, isRetryEnabled = false, - onclick = {} + onclick = {}, ) } @@ -116,7 +127,7 @@ fun SavingsAccountApprovalScreen( Toast.makeText( context, stringResource(id = R.string.feature_savings_savings_approved), - Toast.LENGTH_LONG + Toast.LENGTH_LONG, ).show() navigateBack.invoke() } @@ -127,8 +138,9 @@ fun SavingsAccountApprovalScreen( @OptIn(ExperimentalMaterial3Api::class) @Composable -fun SavingsAccountApprovalContent( - approveLoan: (savingsApproval: SavingsApproval) -> Unit +private fun SavingsAccountApprovalContent( + approveLoan: (savingsApproval: SavingsApproval) -> Unit, + modifier: Modifier = Modifier, ) { val scrollState = rememberScrollState() var approvalDate by rememberSaveable { @@ -143,7 +155,7 @@ fun SavingsAccountApprovalContent( override fun isSelectableDate(utcTimeMillis: Long): Boolean { return utcTimeMillis >= System.currentTimeMillis() } - } + }, ) val context = LocalContext.current var showDatePickerDialog by rememberSaveable { @@ -161,41 +173,41 @@ fun SavingsAccountApprovalContent( approvalDate = it } showDatePickerDialog = false - } + }, ) { Text(stringResource(id = R.string.feature_savings_select_date)) } }, dismissButton = { TextButton( onClick = { showDatePickerDialog = false - } + }, ) { Text(stringResource(id = R.string.feature_savings_cancel)) } - } - ) - { + }, + ) { DatePicker(state = datePickerState) } } Column( - modifier = Modifier + modifier = modifier .verticalScroll(scrollState) - .fillMaxSize() + .fillMaxSize(), ) { Spacer(modifier = Modifier.height(16.dp)) Text( style = MaterialTheme.typography.bodyLarge, text = stringResource(id = R.string.feature_savings_approved_on), - modifier = Modifier.padding(start = 16.dp) + modifier = Modifier.padding(start = 16.dp), ) Spacer(modifier = Modifier.height(16.dp)) MifosDatePickerTextField( value = SimpleDateFormat("dd MMMM yyyy", Locale.getDefault()).format( - approvalDate - ), label = R.string.feature_savings_approval_savings_date + approvalDate, + ), + label = R.string.feature_savings_approval_savings_date, ) { showDatePickerDialog = true } @@ -206,36 +218,39 @@ fun SavingsAccountApprovalContent( value = reasonForApproval, onValueChange = { reasonForApproval = it }, label = stringResource(id = R.string.feature_savings_savings_approval_reason), - error = null + error = null, ) Spacer(modifier = Modifier.height(16.dp)) - Button(modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 16.dp) - .heightIn(44.dp), + Button( + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 16.dp) + .heightIn(44.dp), colors = ButtonDefaults.buttonColors( - containerColor = if (isSystemInDarkTheme()) BluePrimaryDark else BluePrimary - ), onClick = { + containerColor = if (isSystemInDarkTheme()) BluePrimaryDark else BluePrimary, + ), + onClick = { if (Network.isOnline(context)) { approveLoan.invoke( SavingsApproval( approvedOnDate = SimpleDateFormat( "yyyy-MM-dd", - Locale.getDefault() + Locale.getDefault(), ).format(approvalDate), - note = reasonForApproval - ) + note = reasonForApproval, + ), ) } else { Toast.makeText( context, context.resources.getString(R.string.feature_savings_error_not_connected_internet), - Toast.LENGTH_SHORT + Toast.LENGTH_SHORT, ).show() } - }) { + }, + ) { Text(text = stringResource(id = R.string.feature_savings_save)) } } @@ -249,18 +264,19 @@ class SavingsAccountApprovalScreenPreviewProvider : SavingsAccountApprovalUiState.Initial, SavingsAccountApprovalUiState.ShowProgressbar, SavingsAccountApprovalUiState.ShowSavingAccountApprovedSuccessfully(GenericResponse()), - SavingsAccountApprovalUiState.ShowError("Error") + SavingsAccountApprovalUiState.ShowError("Error"), ) } @Composable @Preview(showSystemUi = true) -fun PreviewSavingsAccountApprovalScreen( - @PreviewParameter(SavingsAccountApprovalScreenPreviewProvider::class) savingsAccountApprovalUiState: SavingsAccountApprovalUiState +private fun PreviewSavingsAccountApprovalScreen( + @PreviewParameter(SavingsAccountApprovalScreenPreviewProvider::class) + savingsAccountApprovalUiState: SavingsAccountApprovalUiState, ) { SavingsAccountApprovalScreen( uiState = savingsAccountApprovalUiState, - navigateBack = { }) { - + navigateBack = { }, + ) { } } diff --git a/feature/savings/src/main/java/com/mifos/feature/savings/account_approval/SavingsAccountApprovalUiState.kt b/feature/savings/src/main/java/com/mifos/feature/savings/savingsAccountApproval/SavingsAccountApprovalUiState.kt similarity index 55% rename from feature/savings/src/main/java/com/mifos/feature/savings/account_approval/SavingsAccountApprovalUiState.kt rename to feature/savings/src/main/java/com/mifos/feature/savings/savingsAccountApproval/SavingsAccountApprovalUiState.kt index 14d90363f5e..e22befa0f1d 100644 --- a/feature/savings/src/main/java/com/mifos/feature/savings/account_approval/SavingsAccountApprovalUiState.kt +++ b/feature/savings/src/main/java/com/mifos/feature/savings/savingsAccountApproval/SavingsAccountApprovalUiState.kt @@ -1,4 +1,13 @@ -package com.mifos.feature.savings.account_approval +/* + * Copyright 2024 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/android-client/blob/master/LICENSE.md + */ +package com.mifos.feature.savings.savingsAccountApproval import com.mifos.core.network.GenericResponse @@ -15,4 +24,4 @@ sealed class SavingsAccountApprovalUiState { data class ShowSavingAccountApprovedSuccessfully(val genericResponse: GenericResponse) : SavingsAccountApprovalUiState() -} \ No newline at end of file +} diff --git a/feature/savings/src/main/java/com/mifos/feature/savings/account_approval/SavingsAccountApprovalViewModel.kt b/feature/savings/src/main/java/com/mifos/feature/savings/savingsAccountApproval/SavingsAccountApprovalViewModel.kt similarity index 53% rename from feature/savings/src/main/java/com/mifos/feature/savings/account_approval/SavingsAccountApprovalViewModel.kt rename to feature/savings/src/main/java/com/mifos/feature/savings/savingsAccountApproval/SavingsAccountApprovalViewModel.kt index 0ff7cc60af3..573b36edcfe 100644 --- a/feature/savings/src/main/java/com/mifos/feature/savings/account_approval/SavingsAccountApprovalViewModel.kt +++ b/feature/savings/src/main/java/com/mifos/feature/savings/savingsAccountApproval/SavingsAccountApprovalViewModel.kt @@ -1,4 +1,13 @@ -package com.mifos.feature.savings.account_approval +/* + * Copyright 2024 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/android-client/blob/master/LICENSE.md + */ +package com.mifos.feature.savings.savingsAccountApproval import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel @@ -13,9 +22,6 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.launch -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers import javax.inject.Inject /** @@ -24,7 +30,7 @@ import javax.inject.Inject @HiltViewModel class SavingsAccountApprovalViewModel @Inject constructor( private val approveSavingsApplicationUseCase: ApproveSavingsApplicationUseCase, - savedStateHandle: SavedStateHandle + savedStateHandle: SavedStateHandle, ) : ViewModel() { val savingsAccountId = savedStateHandle.getStateFlow(key = Constants.SAVINGS_ACCOUNT_ID, initialValue = 0) @@ -34,24 +40,26 @@ class SavingsAccountApprovalViewModel @Inject constructor( val savingsAccountApprovalUiState: StateFlow get() = _savingsAccountApprovalUiState - fun approveSavingsApplication(accountId : Int, savingsApproval: SavingsApproval?) = + fun approveSavingsApplication(accountId: Int, savingsApproval: SavingsApproval?) = viewModelScope.launch(Dispatchers.IO) { approveSavingsApplicationUseCase(accountId, savingsApproval).collect { result -> when (result) { - is Resource.Error -> _savingsAccountApprovalUiState.value = - SavingsAccountApprovalUiState.ShowError( - result.message ?: "Something went wrong" - ) + is Resource.Error -> + _savingsAccountApprovalUiState.value = + SavingsAccountApprovalUiState.ShowError( + result.message ?: "Something went wrong", + ) - is Resource.Loading -> _savingsAccountApprovalUiState.value = - SavingsAccountApprovalUiState.ShowProgressbar + is Resource.Loading -> + _savingsAccountApprovalUiState.value = + SavingsAccountApprovalUiState.ShowProgressbar - is Resource.Success -> _savingsAccountApprovalUiState.value = - SavingsAccountApprovalUiState.ShowSavingAccountApprovedSuccessfully( - result.data ?: GenericResponse() - ) + is Resource.Success -> + _savingsAccountApprovalUiState.value = + SavingsAccountApprovalUiState.ShowSavingAccountApprovedSuccessfully( + result.data ?: GenericResponse(), + ) } } } - -} \ No newline at end of file +} diff --git a/feature/savings/src/main/java/com/mifos/feature/savings/account_summary/SavingsAccountSummaryScreen.kt b/feature/savings/src/main/java/com/mifos/feature/savings/savingsAccountSummary/SavingsAccountSummaryScreen.kt similarity index 85% rename from feature/savings/src/main/java/com/mifos/feature/savings/account_summary/SavingsAccountSummaryScreen.kt rename to feature/savings/src/main/java/com/mifos/feature/savings/savingsAccountSummary/SavingsAccountSummaryScreen.kt index 8dff29b8610..e586372a47b 100644 --- a/feature/savings/src/main/java/com/mifos/feature/savings/account_summary/SavingsAccountSummaryScreen.kt +++ b/feature/savings/src/main/java/com/mifos/feature/savings/savingsAccountSummary/SavingsAccountSummaryScreen.kt @@ -1,4 +1,13 @@ -package com.mifos.feature.savings.account_summary +/* + * Copyright 2024 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/android-client/blob/master/LICENSE.md + */ +package com.mifos.feature.savings.savingsAccountSummary import android.content.Context import androidx.compose.foundation.background @@ -66,7 +75,6 @@ import com.mifos.core.objects.accounts.savings.Status import com.mifos.core.objects.accounts.savings.Summary import com.mifos.core.objects.accounts.savings.Transaction import com.mifos.core.objects.accounts.savings.TransactionType -import com.mifos.core.objects.templates.savings.SavingsAccountTransactionTemplate_Table.accountId import com.mifos.core.ui.components.MifosEmptyUi import com.mifos.feature.savings.R @@ -75,19 +83,19 @@ import com.mifos.feature.savings.R */ @Composable -fun SavingsAccountSummaryScreen( +internal fun SavingsAccountSummaryScreen( navigateBack: () -> Unit, loadMoreSavingsAccountInfo: (accountNumber: Int) -> Unit, loadDocuments: (accountNumber: Int) -> Unit, - onDepositClick: (savingsAccountWithAssociations: SavingsAccountWithAssociations, savingsAccountType: DepositType?) -> Unit, - onWithdrawButtonClicked: (savingsAccountWithAssociations: SavingsAccountWithAssociations, savingsAccountType: DepositType?) -> Unit, - approveSavings: (savingsAccountType: DepositType?, savingsAccountNumber: Int) -> Unit, - activateSavings: (savingsAccountType: DepositType?, savingsAccountNumber: Int) -> Unit + onDepositClick: (savings: SavingsAccountWithAssociations, type: DepositType?) -> Unit, + onWithdrawButtonClicked: (savings: SavingsAccountWithAssociations, type: DepositType?) -> Unit, + approveSavings: (type: DepositType?, accountNumber: Int) -> Unit, + activateSavings: (type: DepositType?, accountNumber: Int) -> Unit, + viewmodel: SavingsAccountSummaryViewModel = hiltViewModel(), ) { - val viewmodel: SavingsAccountSummaryViewModel = hiltViewModel() val uiState by viewmodel.savingsAccountSummaryUiState.collectAsStateWithLifecycle() val accountId = viewmodel.savingsNavigationData.id - val savingsAccountType = viewmodel.savingsNavigationData.type + val savingsAccountType = viewmodel.savingsNavigationData.type LaunchedEffect(key1 = Unit) { viewmodel.loadSavingAccount(savingsAccountType?.endpoint, accountId) @@ -100,12 +108,12 @@ fun SavingsAccountSummaryScreen( loadMoreSavingsAccountInfo = { loadMoreSavingsAccountInfo.invoke(accountId) }, loadDocuments = { loadDocuments.invoke(accountId) }, onDepositButtonClicked = { - onDepositClick.invoke( it, savingsAccountType) + onDepositClick.invoke(it, savingsAccountType) }, onWithdrawButtonClicked = { onWithdrawButtonClicked.invoke( it, - savingsAccountType + savingsAccountType, ) }, approveSavings = { @@ -113,21 +121,22 @@ fun SavingsAccountSummaryScreen( }, activateSavings = { activateSavings.invoke(savingsAccountType, accountId) - } + }, ) } @Composable -fun SavingsAccountSummaryScreen( +internal fun SavingsAccountSummaryScreen( uiState: SavingsAccountSummaryUiState, navigateBack: () -> Unit, onRetry: () -> Unit, loadMoreSavingsAccountInfo: () -> Unit, loadDocuments: () -> Unit, - onDepositButtonClicked: (savingsAccountWithAssociations: SavingsAccountWithAssociations) -> Unit, - onWithdrawButtonClicked: (savingsAccountWithAssociations: SavingsAccountWithAssociations) -> Unit, + onDepositButtonClicked: (savings: SavingsAccountWithAssociations) -> Unit, + onWithdrawButtonClicked: (savings: SavingsAccountWithAssociations) -> Unit, approveSavings: () -> Unit, - activateSavings: () -> Unit + modifier: Modifier = Modifier, + activateSavings: () -> Unit, ) { val snackbarHostState = remember { SnackbarHostState() @@ -137,6 +146,7 @@ fun SavingsAccountSummaryScreen( } MifosScaffold( + modifier = modifier, snackbarHostState = snackbarHostState, onBackPressed = navigateBack, title = stringResource(id = R.string.feature_savings_savingsAccountSummary), @@ -159,11 +169,11 @@ fun SavingsAccountSummaryScreen( } } } - } + }, ) { Box( modifier = Modifier - .padding(it) + .padding(it), ) { when (uiState) { is SavingsAccountSummaryUiState.ShowFetchingError -> { @@ -182,7 +192,7 @@ fun SavingsAccountSummaryScreen( onDepositButtonClicked = onDepositButtonClicked, onWithdrawButtonClicked = onWithdrawButtonClicked, approveSavings = approveSavings, - activateSavings = activateSavings + activateSavings = activateSavings, ) } } @@ -191,12 +201,13 @@ fun SavingsAccountSummaryScreen( } @Composable -fun SavingsAccountSummaryContent( +private fun SavingsAccountSummaryContent( savingsAccountWithAssociations: SavingsAccountWithAssociations, onDepositButtonClicked: (savingsAccountWithAssociations: SavingsAccountWithAssociations) -> Unit, onWithdrawButtonClicked: (savingsAccountWithAssociations: SavingsAccountWithAssociations) -> Unit, approveSavings: () -> Unit, - activateSavings: () -> Unit + modifier: Modifier = Modifier, + activateSavings: () -> Unit, ) { val context = LocalContext.current val isSavingsButtonVisible by rememberSaveable { @@ -207,10 +218,10 @@ fun SavingsAccountSummaryContent( } Box( - modifier = Modifier.padding(horizontal = 24.dp) + modifier = modifier.padding(horizontal = 24.dp), ) { Column( - modifier = Modifier.fillMaxSize() + modifier = Modifier.fillMaxSize(), ) { Text( modifier = Modifier @@ -226,7 +237,7 @@ fun SavingsAccountSummaryContent( FarApartTextItem( title = savingsAccountWithAssociations.savingsProductName ?: stringResource(id = R.string.feature_savings_product_name), - value = savingsAccountWithAssociations.accountNo?.toString() ?: "" + value = savingsAccountWithAssociations.accountNo?.toString() ?: "", ) HorizontalDivider(modifier = Modifier.padding(top = 6.dp), color = DarkGray) @@ -234,30 +245,30 @@ fun SavingsAccountSummaryContent( FarApartTextItem( title = stringResource(id = R.string.feature_savings_account_balance), value = savingsAccountWithAssociations.summary?.accountBalance?.toString() - ?: "0.0" + ?: "0.0", ) FarApartTextItem( title = stringResource(id = R.string.feature_savings_total_deposits), value = savingsAccountWithAssociations.summary?.totalDeposits?.toString() - ?: "0.0" + ?: "0.0", ) FarApartTextItem( title = stringResource(id = R.string.feature_savings_total_withdrawals), value = savingsAccountWithAssociations.summary?.totalWithdrawals?.toString() - ?: "0.0" + ?: "0.0", ) FarApartTextItem( title = stringResource(id = R.string.feature_savings_interest_earned), value = savingsAccountWithAssociations.summary?.totalInterestEarned?.toString() - ?: "0.0" + ?: "0.0", ) HorizontalDivider( modifier = Modifier.padding(vertical = 8.dp), - color = DarkGray + color = DarkGray, ) if (savingsAccountWithAssociations.transactions.isEmpty()) { @@ -280,14 +291,14 @@ fun SavingsAccountSummaryContent( modifier = Modifier .align(Alignment.BottomStart) .background( - color = Color.White + color = Color.White, ), ) { Row( modifier = Modifier .fillMaxWidth() .padding(vertical = 8.dp), - horizontalArrangement = Arrangement.SpaceBetween + horizontalArrangement = Arrangement.SpaceBetween, ) { if (isWithdrawalAndDepositButtonVisible) { Button( @@ -298,7 +309,8 @@ fun SavingsAccountSummaryContent( colors = ButtonDefaults.buttonColors( containerColor = if (isSystemInDarkTheme()) BluePrimaryDark else BluePrimary, ), - onClick = { onWithdrawButtonClicked.invoke(savingsAccountWithAssociations) }) { + onClick = { onWithdrawButtonClicked.invoke(savingsAccountWithAssociations) }, + ) { Text(text = stringResource(id = R.string.feature_savings_withdrawal)) } @@ -310,12 +322,12 @@ fun SavingsAccountSummaryContent( colors = ButtonDefaults.buttonColors( containerColor = if (isSystemInDarkTheme()) BluePrimaryDark else BluePrimary, ), - onClick = { onDepositButtonClicked.invoke(savingsAccountWithAssociations) }) { + onClick = { onDepositButtonClicked.invoke(savingsAccountWithAssociations) }, + ) { Text(text = stringResource(id = R.string.feature_savings_make_deposit)) } } - if (isSavingsButtonVisible) { Button( modifier = Modifier @@ -335,16 +347,16 @@ fun SavingsAccountSummaryContent( } else -> { - { /** not reachable , view gone here **/ } + { } } - } + }, ) { Text( text = getSavingsButtonText( context = context, - status = savingsAccountWithAssociations.status - ) + status = savingsAccountWithAssociations.status, + ), ) } } @@ -354,8 +366,9 @@ fun SavingsAccountSummaryContent( } @Composable -fun TransactionItemRow( - transaction: Transaction +private fun TransactionItemRow( + transaction: Transaction, + modifier: Modifier = Modifier, ) { var showTransactionDetails by rememberSaveable { mutableStateOf(false) @@ -364,30 +377,30 @@ fun TransactionItemRow( if (showTransactionDetails) { SummaryDialogBox( onDismissCall = { showTransactionDetails = false }, - transaction = transaction + transaction = transaction, ) } Card( - modifier = Modifier + modifier = modifier .fillMaxWidth(), onClick = { showTransactionDetails = !showTransactionDetails }, colors = CardDefaults.cardColors( - containerColor = Color.White + containerColor = Color.White, ), - shape = RoundedCornerShape(0.dp) + shape = RoundedCornerShape(0.dp), ) { Column { Row( modifier = Modifier .fillMaxWidth() .padding(vertical = 16.dp), - verticalAlignment = Alignment.CenterVertically + verticalAlignment = Alignment.CenterVertically, ) { Text( text = DateHelper.getDateAsString(transaction.date as List), style = MaterialTheme.typography.bodyLarge, color = MaterialTheme.colorScheme.onBackground, - modifier = Modifier.weight(4f) + modifier = Modifier.weight(4f), ) Text( @@ -414,7 +427,7 @@ fun TransactionItemRow( else -> { Color.Black } - } + }, ) } HorizontalDivider(modifier = Modifier.fillMaxWidth()) @@ -423,65 +436,66 @@ fun TransactionItemRow( } @Composable -fun SummaryDialogBox( +private fun SummaryDialogBox( onDismissCall: () -> Unit, - transaction: Transaction + transaction: Transaction, ) { AlertDialog( onDismissRequest = { onDismissCall.invoke() }, confirmButton = { }, text = { Column( - modifier = Modifier.verticalScroll(rememberScrollState()) + modifier = Modifier.verticalScroll(rememberScrollState()), ) { DialogBoxRowItem( title = stringResource(id = R.string.feature_savings_transaction_id), - value = transaction.id?.toString() ?: "" + value = transaction.id?.toString() ?: "", ) Spacer(modifier = Modifier.height(4.dp)) DialogBoxRowItem( title = stringResource(id = R.string.feature_savings_date), - value = DateHelper.getDateAsString(transaction.date as List) + value = DateHelper.getDateAsString(transaction.date as List), ) Spacer(modifier = Modifier.height(4.dp)) DialogBoxRowItem( title = stringResource(id = R.string.feature_savings_transaction_type), - value = transaction.transactionType?.value ?: "" + value = transaction.transactionType?.value ?: "", ) Spacer(modifier = Modifier.height(4.dp)) DialogBoxRowItem( title = stringResource(id = R.string.feature_savings_running_balance), - value = transaction.runningBalance.toString() + value = transaction.runningBalance.toString(), ) Spacer(modifier = Modifier.height(4.dp)) DialogBoxRowItem( title = stringResource(id = R.string.feature_savings_saving_account_id), - value = transaction.accountId.toString() + value = transaction.accountId.toString(), ) Spacer(modifier = Modifier.height(4.dp)) DialogBoxRowItem( title = stringResource(id = R.string.feature_savings_account_number), - value = transaction.accountNo ?: "" + value = transaction.accountNo ?: "", ) Spacer(modifier = Modifier.height(4.dp)) DialogBoxRowItem( title = stringResource(id = R.string.feature_savings_currency), - value = transaction.currency?.name ?: "" + value = transaction.currency?.name ?: "", ) } - }) + }, + ) } @Composable private fun DialogBoxRowItem( title: String, - value: String + value: String, ) { Row( modifier = Modifier @@ -489,10 +503,10 @@ private fun DialogBoxRowItem( .border( width = 2.dp, color = BluePrimary.copy(alpha = .5f), - shape = RoundedCornerShape(0.dp) + shape = RoundedCornerShape(0.dp), ) .padding(horizontal = 8.dp, vertical = 16.dp), - verticalAlignment = Alignment.CenterVertically + verticalAlignment = Alignment.CenterVertically, ) { Text( @@ -509,7 +523,7 @@ private fun DialogBoxRowItem( style = MaterialTheme.typography.bodyMedium, text = value, color = Black, - textAlign = TextAlign.End + textAlign = TextAlign.End, ) } } @@ -520,7 +534,7 @@ private fun FarApartTextItem(title: String, value: String) { modifier = Modifier .fillMaxWidth() .padding(top = 6.dp), - horizontalArrangement = Arrangement.SpaceBetween + horizontalArrangement = Arrangement.SpaceBetween, ) { Text( style = MaterialTheme.typography.bodyLarge, @@ -536,8 +550,7 @@ private fun FarApartTextItem(title: String, value: String) { } } - -fun getSavingsButtonText(context: Context, status: Status?): String { +private fun getSavingsButtonText(context: Context, status: Status?): String { return when { status?.submittedAndPendingApproval == true -> { context.resources.getString(R.string.feature_savings_approve_savings) @@ -557,7 +570,7 @@ fun getSavingsButtonText(context: Context, status: Status?): String { } } -fun savingsButtonVisibilityStatus(status: Status?): Boolean { +private fun savingsButtonVisibilityStatus(status: Status?): Boolean { return when { status?.submittedAndPendingApproval == true -> { true @@ -577,7 +590,7 @@ fun savingsButtonVisibilityStatus(status: Status?): Boolean { } } -fun depositAndWithdrawButtonVisibility(status: Status?): Boolean { +private fun depositAndWithdrawButtonVisibility(status: Status?): Boolean { return when { status?.submittedAndPendingApproval == true -> { false @@ -606,7 +619,7 @@ class SavingsAccountSummaryScreenPreviewProvider : totalDeposits = 4332.333, accountBalance = 23232.333, totalWithdrawals = 3343.434, - totalInterestEarned = 234.34 + totalInterestEarned = 234.34, ) val transaction = Transaction( @@ -615,7 +628,7 @@ class SavingsAccountSummaryScreenPreviewProvider : ), date = listOf(2, 3, 2022), currency = Currency( - code = null + code = null, ), ) override val values: Sequence @@ -631,19 +644,19 @@ class SavingsAccountSummaryScreenPreviewProvider : transaction, transaction, transaction, - transaction + transaction, ), status = Status(), - summary = summary - ) + summary = summary, + ), ), ) } @Composable @Preview(showSystemUi = true) -fun PreviewSavingsAccountSummaryScreen( - @PreviewParameter(SavingsAccountSummaryScreenPreviewProvider::class) savingsAccountSummaryUiState: SavingsAccountSummaryUiState +private fun PreviewSavingsAccountSummaryScreen( + @PreviewParameter(SavingsAccountSummaryScreenPreviewProvider::class) savingsAccountSummaryUiState: SavingsAccountSummaryUiState, ) { SavingsAccountSummaryScreen( uiState = savingsAccountSummaryUiState, @@ -653,6 +666,7 @@ fun PreviewSavingsAccountSummaryScreen( loadDocuments = { }, onDepositButtonClicked = { _ -> }, onWithdrawButtonClicked = { _ -> }, - approveSavings = { }) { + approveSavings = { }, + ) { } } diff --git a/feature/savings/src/main/java/com/mifos/feature/savings/account_summary/SavingsAccountSummaryUiState.kt b/feature/savings/src/main/java/com/mifos/feature/savings/savingsAccountSummary/SavingsAccountSummaryUiState.kt similarity index 55% rename from feature/savings/src/main/java/com/mifos/feature/savings/account_summary/SavingsAccountSummaryUiState.kt rename to feature/savings/src/main/java/com/mifos/feature/savings/savingsAccountSummary/SavingsAccountSummaryUiState.kt index 2dac2c11c46..1812979b821 100644 --- a/feature/savings/src/main/java/com/mifos/feature/savings/account_summary/SavingsAccountSummaryUiState.kt +++ b/feature/savings/src/main/java/com/mifos/feature/savings/savingsAccountSummary/SavingsAccountSummaryUiState.kt @@ -1,4 +1,13 @@ -package com.mifos.feature.savings.account_summary +/* + * Copyright 2024 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/android-client/blob/master/LICENSE.md + */ +package com.mifos.feature.savings.savingsAccountSummary import com.mifos.core.objects.accounts.savings.SavingsAccountWithAssociations diff --git a/feature/savings/src/main/java/com/mifos/feature/savings/account_summary/SavingsAccountSummaryViewModel.kt b/feature/savings/src/main/java/com/mifos/feature/savings/savingsAccountSummary/SavingsAccountSummaryViewModel.kt similarity index 56% rename from feature/savings/src/main/java/com/mifos/feature/savings/account_summary/SavingsAccountSummaryViewModel.kt rename to feature/savings/src/main/java/com/mifos/feature/savings/savingsAccountSummary/SavingsAccountSummaryViewModel.kt index 8467ce9c1c3..4ce2399b33d 100644 --- a/feature/savings/src/main/java/com/mifos/feature/savings/account_summary/SavingsAccountSummaryViewModel.kt +++ b/feature/savings/src/main/java/com/mifos/feature/savings/savingsAccountSummary/SavingsAccountSummaryViewModel.kt @@ -1,4 +1,13 @@ -package com.mifos.feature.savings.account_summary +/* + * Copyright 2024 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/android-client/blob/master/LICENSE.md + */ +package com.mifos.feature.savings.savingsAccountSummary import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel @@ -23,7 +32,7 @@ import javax.inject.Inject @HiltViewModel class SavingsAccountSummaryViewModel @Inject constructor( private val getSavingsAccountUseCase: GetSavingsAccountUseCase, - savedStateHandle: SavedStateHandle + savedStateHandle: SavedStateHandle, ) : ViewModel() { private val arg = savedStateHandle.getStateFlow(key = "arg", initialValue = "") @@ -33,21 +42,23 @@ class SavingsAccountSummaryViewModel @Inject constructor( MutableStateFlow(SavingsAccountSummaryUiState.ShowProgressbar) val savingsAccountSummaryUiState: StateFlow get() = _savingsAccountSummaryUiState - - fun loadSavingAccount(type: String?, accountId : Int) = viewModelScope.launch(Dispatchers.IO) { + fun loadSavingAccount(type: String?, accountId: Int) = viewModelScope.launch(Dispatchers.IO) { getSavingsAccountUseCase(type, accountId, Constants.TRANSACTIONS).collect { result -> when (result) { - is Resource.Error -> _savingsAccountSummaryUiState.value = - SavingsAccountSummaryUiState.ShowFetchingError(R.string.feature_savings_failed_to_fetch_savingsaccount) + is Resource.Error -> + _savingsAccountSummaryUiState.value = + SavingsAccountSummaryUiState.ShowFetchingError(R.string.feature_savings_failed_to_fetch_savingsaccount) - is Resource.Loading -> _savingsAccountSummaryUiState.value = - SavingsAccountSummaryUiState.ShowProgressbar + is Resource.Loading -> + _savingsAccountSummaryUiState.value = + SavingsAccountSummaryUiState.ShowProgressbar - is Resource.Success -> _savingsAccountSummaryUiState.value = - SavingsAccountSummaryUiState.ShowSavingAccount( - result.data ?: SavingsAccountWithAssociations() - ) + is Resource.Success -> + _savingsAccountSummaryUiState.value = + SavingsAccountSummaryUiState.ShowSavingAccount( + result.data ?: SavingsAccountWithAssociations(), + ) } } } -} \ No newline at end of file +} diff --git a/feature/savings/src/main/java/com/mifos/feature/savings/account_transaction/SavingsAccountTransactionScreen.kt b/feature/savings/src/main/java/com/mifos/feature/savings/savingsAccountTransaction/SavingsAccountTransactionScreen.kt similarity index 80% rename from feature/savings/src/main/java/com/mifos/feature/savings/account_transaction/SavingsAccountTransactionScreen.kt rename to feature/savings/src/main/java/com/mifos/feature/savings/savingsAccountTransaction/SavingsAccountTransactionScreen.kt index 1b6bf9bc564..8bb54cd9dcf 100644 --- a/feature/savings/src/main/java/com/mifos/feature/savings/account_transaction/SavingsAccountTransactionScreen.kt +++ b/feature/savings/src/main/java/com/mifos/feature/savings/savingsAccountTransaction/SavingsAccountTransactionScreen.kt @@ -1,4 +1,13 @@ -package com.mifos.feature.savings.account_transaction +/* + * Copyright 2024 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/android-client/blob/master/LICENSE.md + */ +package com.mifos.feature.savings.savingsAccountTransaction import android.content.Context import android.util.Log @@ -50,7 +59,6 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.google.gson.Gson import com.mifos.core.common.utils.Constants import com.mifos.core.common.utils.Network -import com.mifos.core.datastore.PrefManager import com.mifos.core.designsystem.component.MifosCircularProgress import com.mifos.core.designsystem.component.MifosDatePickerTextField import com.mifos.core.designsystem.component.MifosOutlinedTextField @@ -74,10 +82,10 @@ import java.util.Locale */ @Composable -fun SavingsAccountTransactionScreen( - navigateBack: () -> Unit +internal fun SavingsAccountTransactionScreen( + navigateBack: () -> Unit, + viewmodel: SavingsAccountTransactionViewModel = hiltViewModel(), ) { - val viewmodel: SavingsAccountTransactionViewModel = hiltViewModel() val uiState by viewmodel.savingsAccountTransactionUiState.collectAsStateWithLifecycle() val savingsAccountNumber = viewmodel.savingsAccountNumber @@ -103,12 +111,12 @@ fun SavingsAccountTransactionScreen( onProcessTransaction = { viewmodel.processTransaction(it) }, - setUserOffline = { viewmodel.setUserOffline() } + setUserOffline = { viewmodel.setUserOffline() }, ) } @Composable -fun SavingsAccountTransactionScreen( +internal fun SavingsAccountTransactionScreen( clientName: String?, savingsAccountNumber: Int?, uiState: SavingsAccountTransactionUiState, @@ -116,28 +124,31 @@ fun SavingsAccountTransactionScreen( onRetry: () -> Unit, transactionType: String, loadSavingAccountTemplate: () -> Unit, - onProcessTransaction: (savingsAccountTransactionRequest: SavingsAccountTransactionRequest) -> Unit, - setUserOffline : () -> Unit, + onProcessTransaction: (request: SavingsAccountTransactionRequest) -> Unit, + modifier: Modifier = Modifier, + setUserOffline: () -> Unit, ) { val snackBarHostState = remember { SnackbarHostState() } val context = LocalContext.current val topbarTitle = if (transactionType == Constants.SAVINGS_ACCOUNT_TRANSACTION_DEPOSIT) { - stringResource(id = R.string.feature_savings_savingsAccount) + " " + stringResource(id = R.string.feature_savings_deposit) + stringResource(id = R.string.feature_savings_savingsAccount) + " " + + stringResource(id = R.string.feature_savings_deposit) } else { stringResource(id = R.string.feature_savings_savingsAccount) + " " + stringResource(id = R.string.feature_savings_withdrawal) } MifosScaffold( + modifier = modifier, snackbarHostState = snackBarHostState, title = topbarTitle, icon = MifosIcons.arrowBack, - onBackPressed = navigateBack + onBackPressed = navigateBack, ) { Box( modifier = Modifier .fillMaxSize() - .padding(it) + .padding(it), ) { when (uiState) { is SavingsAccountTransactionUiState.ShowError -> { @@ -157,7 +168,7 @@ fun SavingsAccountTransactionScreen( savingsAccountTransactionTemplate = uiState.savingsAccountTransactionTemplate, savingsAccountNumber = savingsAccountNumber, onProcessTransaction = onProcessTransaction, - setUserOffline = setUserOffline + setUserOffline = setUserOffline, ) } @@ -166,11 +177,12 @@ fun SavingsAccountTransactionScreen( } SavingsAccountTransactionUiState.ShowSavingAccountTransactionExistInDatabase -> { - AlertDialog(onDismissRequest = { }, + AlertDialog( + onDismissRequest = { }, title = { Text( style = MaterialTheme.typography.titleLarge, - text = stringResource(id = R.string.feature_savings_sync_previous_transaction) + text = stringResource(id = R.string.feature_savings_sync_previous_transaction), ) }, text = { Text(text = stringResource(id = R.string.feature_savings_dialog_message_sync_savingaccounttransaction)) }, @@ -178,7 +190,7 @@ fun SavingsAccountTransactionScreen( TextButton(onClick = { navigateBack() }) { Text(text = stringResource(id = R.string.feature_savings_dialog_action_ok)) } - } + }, ) } @@ -187,20 +199,22 @@ fun SavingsAccountTransactionScreen( Toast.makeText( context, context.resources.getString(R.string.feature_savings_transaction_saved_in_db), - Toast.LENGTH_SHORT + Toast.LENGTH_SHORT, ).show() } else { if (transactionType == Constants.SAVINGS_ACCOUNT_TRANSACTION_DEPOSIT) { Toast.makeText( context, - context.resources.getString(R.string.feature_savings_deposit_successful_transaction_ID) + uiState.savingsAccountTransactionResponse.resourceId, - Toast.LENGTH_SHORT + context.resources.getString(R.string.feature_savings_deposit_successful_transaction_ID) + + uiState.savingsAccountTransactionResponse.resourceId, + Toast.LENGTH_SHORT, ).show() } else if (transactionType == Constants.SAVINGS_ACCOUNT_TRANSACTION_WITHDRAWAL) { Toast.makeText( context, - context.resources.getString(R.string.feature_savings_withdrawal_successful_transaction_ID) + uiState.savingsAccountTransactionResponse.resourceId, - Toast.LENGTH_SHORT + context.resources.getString(R.string.feature_savings_withdrawal_successful_transaction_ID) + + uiState.savingsAccountTransactionResponse.resourceId, + Toast.LENGTH_SHORT, ).show() } } @@ -212,55 +226,48 @@ fun SavingsAccountTransactionScreen( @OptIn(ExperimentalMaterial3Api::class) @Composable -fun SavingsAccountTransactionContent( +private fun SavingsAccountTransactionContent( clientName: String?, savingsAccountNumber: Int?, navigateBack: () -> Unit, savingsAccountTransactionTemplate: SavingsAccountTransactionTemplate, onProcessTransaction: (savingsAccountTransactionRequest: SavingsAccountTransactionRequest) -> Unit, - setUserOffline: () -> Unit + modifier: Modifier = Modifier, + setUserOffline: () -> Unit, ) { - var amount by rememberSaveable { - mutableStateOf("") - } - var paymentType by rememberSaveable { - mutableStateOf("") - } - var paymentTypeId by rememberSaveable { - mutableStateOf(0) - } - - var transactionDate by rememberSaveable { - mutableLongStateOf(System.currentTimeMillis()) - } - var openDatepicker by rememberSaveable { - mutableStateOf(false) - } + var amount by rememberSaveable { mutableStateOf("") } + var paymentType by rememberSaveable { mutableStateOf("") } + var paymentTypeId by rememberSaveable { mutableStateOf(0) } + var transactionDate by rememberSaveable { mutableLongStateOf(System.currentTimeMillis()) } + var openDatepicker by rememberSaveable { mutableStateOf(false) } val datePickerState = rememberDatePickerState( initialSelectedDateMillis = transactionDate, selectableDates = object : SelectableDates { override fun isSelectableDate(utcTimeMillis: Long): Boolean { return utcTimeMillis >= System.currentTimeMillis() } - } + }, ) val context = LocalContext.current val scrollState = rememberScrollState() - var showReviewTransactionDialog by rememberSaveable { - mutableStateOf(false) - } + var showReviewTransactionDialog by rememberSaveable { mutableStateOf(false) } if (showReviewTransactionDialog) { - AlertDialog(onDismissRequest = { showReviewTransactionDialog = false }, + AlertDialog( + onDismissRequest = { showReviewTransactionDialog = false }, title = { - Text(text = stringResource(id = R.string.feature_savings_review_transaction_details), style = MaterialTheme.typography.titleLarge)}, + Text( + text = stringResource(id = R.string.feature_savings_review_transaction_details), + style = MaterialTheme.typography.titleLarge, + ) + }, text = { Column { Text( text = stringResource(id = R.string.feature_savings_transaction_date) + " : " + SimpleDateFormat( "dd MMMM yyyy", - Locale.getDefault() - ).format(transactionDate) + Locale.getDefault(), + ).format(transactionDate), ) Text(text = stringResource(id = R.string.feature_savings_payment_type) + " : " + paymentType) Text(text = stringResource(id = R.string.feature_savings_amount) + " : " + amount) @@ -276,7 +283,7 @@ fun SavingsAccountTransactionContent( savingsAccountTransactionRequest.dateFormat = "dd MM yyyy" savingsAccountTransactionRequest.transactionDate = SimpleDateFormat( "dd MMMM yyyy", - Locale.getDefault() + Locale.getDefault(), ).format(transactionDate) savingsAccountTransactionRequest.transactionAmount = amount savingsAccountTransactionRequest.paymentTypeId = paymentTypeId.toString() @@ -285,11 +292,12 @@ fun SavingsAccountTransactionContent( Gson().toJson(savingsAccountTransactionRequest) Log.i( context.resources.getString(R.string.feature_savings_transaction_body), - builtTransactionRequestAsJson + builtTransactionRequestAsJson, ) onProcessTransaction.invoke(savingsAccountTransactionRequest) - }) { + }, + ) { Text(text = stringResource(id = R.string.feature_savings_review_transaction)) } }, @@ -297,7 +305,7 @@ fun SavingsAccountTransactionContent( TextButton(onClick = { showReviewTransactionDialog = false }) { Text(text = stringResource(id = R.string.feature_savings_cancel)) } - } + }, ) } @@ -313,32 +321,31 @@ fun SavingsAccountTransactionContent( transactionDate = it } openDatepicker = false - } + }, ) { Text(stringResource(id = R.string.feature_savings_select_date)) } }, dismissButton = { TextButton( onClick = { openDatepicker = false - } + }, ) { Text(stringResource(id = R.string.feature_savings_cancel)) } - } - ) - { + }, + ) { DatePicker(state = datePickerState) } } Column( - modifier = Modifier + modifier = modifier .fillMaxSize() .padding(horizontal = 16.dp, vertical = 10.dp) - .verticalScroll(scrollState) + .verticalScroll(scrollState), ) { Text( style = MaterialTheme.typography.bodyLarge, color = MaterialTheme.colorScheme.onBackground, - text = clientName ?: "" + text = clientName ?: "", // TODO from old fragment // 1. Implement QuickContactBadge here @@ -348,7 +355,7 @@ fun SavingsAccountTransactionContent( FarApartTextItem( title = stringResource(id = R.string.feature_savings_account_number), - value = savingsAccountNumber?.toString() ?: "" + value = savingsAccountNumber?.toString() ?: "", ) Spacer(modifier = Modifier.height(16.dp)) @@ -360,9 +367,10 @@ fun SavingsAccountTransactionContent( MifosDatePickerTextField( value = SimpleDateFormat( "dd-MMMM-yyyy", - Locale.getDefault() - ).format(transactionDate), label = R.string.feature_savings_date, - modifier = Modifier.fillMaxWidth() + Locale.getDefault(), + ).format(transactionDate), + label = R.string.feature_savings_date, + modifier = Modifier.fillMaxWidth(), ) { openDatepicker = true } @@ -375,7 +383,7 @@ fun SavingsAccountTransactionContent( onValueChange = { amount = it }, label = stringResource(id = R.string.feature_savings_amount), error = null, - keyboardType = KeyboardType.Number + keyboardType = KeyboardType.Number, ) Spacer(modifier = Modifier.height(16.dp)) @@ -390,28 +398,29 @@ fun SavingsAccountTransactionContent( }, label = R.string.feature_savings_payment_type, options = savingsAccountTransactionTemplate.paymentTypeOptions.map { it.name }, - readOnly = true + readOnly = true, ) Spacer(modifier = Modifier.height(16.dp)) Row( modifier = Modifier.fillMaxSize(), - horizontalArrangement = Arrangement.SpaceBetween + horizontalArrangement = Arrangement.SpaceBetween, ) { Button( modifier = Modifier.heightIn(46.dp), colors = ButtonDefaults.buttonColors( - containerColor = if (isSystemInDarkTheme()) BluePrimaryDark else BluePrimary + containerColor = if (isSystemInDarkTheme()) BluePrimaryDark else BluePrimary, ), - onClick = { navigateBack.invoke() }) { + onClick = { navigateBack.invoke() }, + ) { Text(text = stringResource(id = R.string.feature_savings_cancel)) } Button( modifier = Modifier.heightIn(46.dp), colors = ButtonDefaults.buttonColors( - containerColor = if (isSystemInDarkTheme()) BluePrimaryDark else BluePrimary + containerColor = if (isSystemInDarkTheme()) BluePrimaryDark else BluePrimary, ), onClick = { if (isAmountValid(context, amount)) { @@ -423,28 +432,29 @@ fun SavingsAccountTransactionContent( Toast.makeText( context, context.resources.getString(R.string.feature_savings_error_not_connected_internet), - Toast.LENGTH_SHORT + Toast.LENGTH_SHORT, ).show() } } - } + }, ) { Text(text = stringResource(id = R.string.feature_savings_review_transaction)) } } - } } -fun isAmountValid( +private fun isAmountValid( context: Context, amount: String, ): Boolean { if (amount.isEmpty()) { Toast.makeText( context, - context.resources.getString(R.string.feature_savings_amount) + " " + context.resources.getString(R.string.feature_savings_message_field_required), - Toast.LENGTH_SHORT + context.resources.getString(R.string.feature_savings_amount) + " " + context.resources.getString( + R.string.feature_savings_message_field_required, + ), + Toast.LENGTH_SHORT, ).show() return false @@ -455,7 +465,7 @@ fun isAmountValid( Toast.makeText( context, context.resources.getString(R.string.feature_savings_error_amount_can_not_be_empty), - Toast.LENGTH_SHORT + Toast.LENGTH_SHORT, ).show() return false @@ -464,7 +474,7 @@ fun isAmountValid( Toast.makeText( context, context.resources.getString(R.string.feature_savings_error_invalid_amount), - Toast.LENGTH_SHORT + Toast.LENGTH_SHORT, ).show() return false @@ -479,7 +489,7 @@ private fun FarApartTextItem(title: String, value: String) { modifier = Modifier .fillMaxWidth() .padding(top = 6.dp), - horizontalArrangement = Arrangement.SpaceBetween + horizontalArrangement = Arrangement.SpaceBetween, ) { Text( style = MaterialTheme.typography.bodyLarge, @@ -502,23 +512,24 @@ class SavingsAccountTransactionScreenPreviewProvider : get() = sequenceOf( SavingsAccountTransactionUiState.ShowSavingAccountTemplate( SavingsAccountTransactionTemplate( - paymentTypeOptions = listOf() - ) + paymentTypeOptions = listOf(), + ), ), SavingsAccountTransactionUiState.ShowProgressbar, SavingsAccountTransactionUiState.ShowSavingAccountTransactionDoesNotExistInDatabase, SavingsAccountTransactionUiState.ShowSavingAccountTransactionExistInDatabase, SavingsAccountTransactionUiState.ShowError("Failed to fetch"), SavingsAccountTransactionUiState.ShowTransactionSuccessfullyDone( - SavingsAccountTransactionResponse() - ) + SavingsAccountTransactionResponse(), + ), ) } @Composable @Preview(showSystemUi = true) -fun PreviewSavingsAccountTransactionScreen( - @PreviewParameter(SavingsAccountTransactionScreenPreviewProvider::class) savingsAccountTransactionUiState: SavingsAccountTransactionUiState +private fun PreviewSavingsAccountTransactionScreen( + @PreviewParameter(SavingsAccountTransactionScreenPreviewProvider::class) + savingsAccountTransactionUiState: SavingsAccountTransactionUiState, ) { SavingsAccountTransactionScreen( clientName = "Jean Charles", @@ -529,7 +540,6 @@ fun PreviewSavingsAccountTransactionScreen( transactionType = "type", loadSavingAccountTemplate = { }, setUserOffline = {}, - onProcessTransaction = { } + onProcessTransaction = { }, ) } - diff --git a/feature/savings/src/main/java/com/mifos/feature/savings/account_transaction/SavingsAccountTransactionUiState.kt b/feature/savings/src/main/java/com/mifos/feature/savings/savingsAccountTransaction/SavingsAccountTransactionUiState.kt similarity index 71% rename from feature/savings/src/main/java/com/mifos/feature/savings/account_transaction/SavingsAccountTransactionUiState.kt rename to feature/savings/src/main/java/com/mifos/feature/savings/savingsAccountTransaction/SavingsAccountTransactionUiState.kt index 4d71fedf8b8..4c86a3a5abc 100644 --- a/feature/savings/src/main/java/com/mifos/feature/savings/account_transaction/SavingsAccountTransactionUiState.kt +++ b/feature/savings/src/main/java/com/mifos/feature/savings/savingsAccountTransaction/SavingsAccountTransactionUiState.kt @@ -1,4 +1,13 @@ -package com.mifos.feature.savings.account_transaction +/* + * Copyright 2024 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/android-client/blob/master/LICENSE.md + */ +package com.mifos.feature.savings.savingsAccountTransaction import com.mifos.core.objects.accounts.savings.SavingsAccountTransactionResponse import com.mifos.core.objects.templates.savings.SavingsAccountTransactionTemplate @@ -15,7 +24,6 @@ sealed class SavingsAccountTransactionUiState { data class ShowSavingAccountTemplate(val savingsAccountTransactionTemplate: SavingsAccountTransactionTemplate) : SavingsAccountTransactionUiState() - data class ShowTransactionSuccessfullyDone(val savingsAccountTransactionResponse: SavingsAccountTransactionResponse) : SavingsAccountTransactionUiState() diff --git a/feature/savings/src/main/java/com/mifos/feature/savings/account_transaction/SavingsAccountTransactionViewModel.kt b/feature/savings/src/main/java/com/mifos/feature/savings/savingsAccountTransaction/SavingsAccountTransactionViewModel.kt similarity index 63% rename from feature/savings/src/main/java/com/mifos/feature/savings/account_transaction/SavingsAccountTransactionViewModel.kt rename to feature/savings/src/main/java/com/mifos/feature/savings/savingsAccountTransaction/SavingsAccountTransactionViewModel.kt index d71c90c02a0..e93098a9da4 100644 --- a/feature/savings/src/main/java/com/mifos/feature/savings/account_transaction/SavingsAccountTransactionViewModel.kt +++ b/feature/savings/src/main/java/com/mifos/feature/savings/savingsAccountTransaction/SavingsAccountTransactionViewModel.kt @@ -1,4 +1,13 @@ -package com.mifos.feature.savings.account_transaction +/* + * Copyright 2024 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/android-client/blob/master/LICENSE.md + */ +package com.mifos.feature.savings.savingsAccountTransaction import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel @@ -6,27 +15,19 @@ import androidx.lifecycle.viewModelScope import com.google.gson.Gson import com.mifos.core.common.utils.Constants import com.mifos.core.common.utils.Resource -import com.mifos.core.data.repository.SavingsAccountTransactionRepository import com.mifos.core.datastore.PrefManager import com.mifos.core.domain.use_cases.GetSavingsAccountTransactionTemplateUseCase import com.mifos.core.domain.use_cases.GetSavingsAccountTransactionUseCase import com.mifos.core.domain.use_cases.ProcessTransactionUseCase -import com.mifos.core.objects.accounts.savings.DepositType import com.mifos.core.objects.accounts.savings.SavingsAccountTransactionRequest import com.mifos.core.objects.accounts.savings.SavingsAccountTransactionResponse -import com.mifos.core.objects.accounts.savings.SavingsSummaryData import com.mifos.core.objects.accounts.savings.SavingsTransactionData -import com.mifos.core.objects.client.Savings import com.mifos.core.objects.templates.savings.SavingsAccountTransactionTemplate import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers import javax.inject.Inject /** @@ -38,13 +39,13 @@ class SavingsAccountTransactionViewModel @Inject constructor( private val processTransactionUseCase: ProcessTransactionUseCase, private val getSavingsAccountTransactionUseCase: GetSavingsAccountTransactionUseCase, private val prefManager: PrefManager, - savedStateHandle: SavedStateHandle + savedStateHandle: SavedStateHandle, ) : ViewModel() { private val arg = savedStateHandle.getStateFlow(key = "arg", initialValue = "") private val savingsTransactionData: SavingsTransactionData = Gson().fromJson(arg.value, SavingsTransactionData::class.java) - val accountId = savingsTransactionData.savingsAccountWithAssociations.id + val accountId = savingsTransactionData.savingsAccountWithAssociations.id val savingsAccountNumber = savingsTransactionData.savingsAccountWithAssociations.accountNo val clientName = savingsTransactionData.savingsAccountWithAssociations.clientName val transactionType = savingsTransactionData.transactionType @@ -64,19 +65,22 @@ class SavingsAccountTransactionViewModel @Inject constructor( getSavingsAccountTransactionTemplateUseCase( savingsAccountType?.endpoint, it, - transactionType + transactionType, ).collect { result -> when (result) { - is Resource.Error -> _savingsAccountTransactionUiState.value = - SavingsAccountTransactionUiState.ShowError(result.message.toString()) - - is Resource.Loading -> _savingsAccountTransactionUiState.value = - SavingsAccountTransactionUiState.ShowProgressbar - - is Resource.Success -> _savingsAccountTransactionUiState.value = - SavingsAccountTransactionUiState.ShowSavingAccountTemplate( - result.data ?: SavingsAccountTransactionTemplate() - ) + is Resource.Error -> + _savingsAccountTransactionUiState.value = + SavingsAccountTransactionUiState.ShowError(result.message.toString()) + + is Resource.Loading -> + _savingsAccountTransactionUiState.value = + SavingsAccountTransactionUiState.ShowProgressbar + + is Resource.Success -> + _savingsAccountTransactionUiState.value = + SavingsAccountTransactionUiState.ShowSavingAccountTemplate( + result.data ?: SavingsAccountTransactionTemplate(), + ) } } } @@ -89,19 +93,22 @@ class SavingsAccountTransactionViewModel @Inject constructor( savingsAccountType?.endpoint, it, transactionType, - request + request, ).collect { result -> when (result) { - is Resource.Error -> _savingsAccountTransactionUiState.value = - SavingsAccountTransactionUiState.ShowError(result.message.toString()) - - is Resource.Loading -> _savingsAccountTransactionUiState.value = - SavingsAccountTransactionUiState.ShowProgressbar - - is Resource.Success -> _savingsAccountTransactionUiState.value = - SavingsAccountTransactionUiState.ShowTransactionSuccessfullyDone( - result.data ?: SavingsAccountTransactionResponse() - ) + is Resource.Error -> + _savingsAccountTransactionUiState.value = + SavingsAccountTransactionUiState.ShowError(result.message.toString()) + + is Resource.Loading -> + _savingsAccountTransactionUiState.value = + SavingsAccountTransactionUiState.ShowProgressbar + + is Resource.Success -> + _savingsAccountTransactionUiState.value = + SavingsAccountTransactionUiState.ShowTransactionSuccessfullyDone( + result.data ?: SavingsAccountTransactionResponse(), + ) } } } @@ -112,11 +119,13 @@ class SavingsAccountTransactionViewModel @Inject constructor( accountId?.let { getSavingsAccountTransactionUseCase(it).collect { result -> when (result) { - is Resource.Error -> _savingsAccountTransactionUiState.value = - SavingsAccountTransactionUiState.ShowError(result.message.toString()) + is Resource.Error -> + _savingsAccountTransactionUiState.value = + SavingsAccountTransactionUiState.ShowError(result.message.toString()) - is Resource.Loading -> _savingsAccountTransactionUiState.value = - SavingsAccountTransactionUiState.ShowProgressbar + is Resource.Loading -> + _savingsAccountTransactionUiState.value = + SavingsAccountTransactionUiState.ShowProgressbar is Resource.Success -> { if (result.data != null) { @@ -131,5 +140,4 @@ class SavingsAccountTransactionViewModel @Inject constructor( } } } - -} \ No newline at end of file +} diff --git a/feature/savings/src/main/res/values/feature_savings_strings.xml b/feature/savings/src/main/res/values/feature_savings_strings.xml index 3b5a52838ea..6c9555023c1 100644 --- a/feature/savings/src/main/res/values/feature_savings_strings.xml +++ b/feature/savings/src/main/res/values/feature_savings_strings.xml @@ -1,4 +1,13 @@ + More savings account info Savings Account Summary diff --git a/feature/savings/src/test/java/com/mifos/feature/savings/ExampleUnitTest.kt b/feature/savings/src/test/java/com/mifos/feature/savings/ExampleUnitTest.kt index e2948341bdd..342d86546b0 100644 --- a/feature/savings/src/test/java/com/mifos/feature/savings/ExampleUnitTest.kt +++ b/feature/savings/src/test/java/com/mifos/feature/savings/ExampleUnitTest.kt @@ -1,9 +1,17 @@ +/* + * Copyright 2024 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/android-client/blob/master/LICENSE.md + */ package com.mifos.feature.savings +import junit.framework.TestCase.assertEquals import org.junit.Test -import org.junit.Assert.* - /** * Example local unit test, which will execute on the development machine (host). * @@ -14,4 +22,4 @@ class ExampleUnitTest { fun addition_isCorrect() { assertEquals(4, 2 + 2) } -} \ No newline at end of file +} diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/SavingsAccountTransactionsListAdapter.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/SavingsAccountTransactionsListAdapter.kt deleted file mode 100644 index 49328bd489c..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/SavingsAccountTransactionsListAdapter.kt +++ /dev/null @@ -1,79 +0,0 @@ -/* - * This project is licensed under the open source MPL V2. - * See https://github.com/openMF/android-client/blob/master/LICENSE.md - */ -package com.mifos.mifosxdroid.adapters - -import android.content.Context -import android.graphics.Color -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.widget.BaseAdapter -import androidx.core.content.ContextCompat -import com.mifos.core.objects.accounts.savings.Transaction -import com.mifos.mifosxdroid.R -import com.mifos.mifosxdroid.databinding.RowSavingsTransactionItemBinding -import com.mifos.utils.DateHelper.getDateAsString - -/** - * Created by ishankhanna on 30/05/14. - */ -class SavingsAccountTransactionsListAdapter( - context: Context, - listOfTransactions: List -) : BaseAdapter() { - private val listOfTransactions: List - private val layoutInflater: LayoutInflater - private val mContext: Context - - init { - layoutInflater = LayoutInflater.from(context) - this.listOfTransactions = listOfTransactions - mContext = context - } - - override fun getCount(): Int { - return listOfTransactions.size - } - - override fun getItem(i: Int): Transaction { - return listOfTransactions[i] - } - - override fun getItemId(i: Int): Long { - return 0 - } - - override fun getView(i: Int, view: View?, viewGroup: ViewGroup): View { - val binding: RowSavingsTransactionItemBinding - val convertView: View - if (view == null) { - - binding = RowSavingsTransactionItemBinding.inflate(layoutInflater, viewGroup, false) - convertView = binding.root - convertView.tag = binding - } else { - binding = view.tag as RowSavingsTransactionItemBinding - convertView = view - } - binding.tvTransactionDate.text = - getDateAsString(listOfTransactions[i].date as List) - binding.tvTransactionType.text = listOfTransactions[i] - .transactionType?.value - val transactionAmount = listOfTransactions[i].currency?.displaySymbol + - mContext.resources.getString(R.string.space) + - listOfTransactions[i].amount - binding.tvTransactionAmount.text = transactionAmount - if (listOfTransactions[i].transactionType?.deposit == true) { - binding.tvTransactionAmount.setTextColor( - ContextCompat.getColor(mContext, R.color.savings_account_status_active) - ) - } else if (listOfTransactions[i].transactionType?.withdrawal == true) { - binding.tvTransactionAmount.setTextColor(Color.RED) - } else { - binding.tvTransactionAmount.setTextColor(Color.BLACK) - } - return convertView - } -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/SavingsAccountsListAdapter.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/SavingsAccountsListAdapter.kt deleted file mode 100644 index 1e11862d76a..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/SavingsAccountsListAdapter.kt +++ /dev/null @@ -1,88 +0,0 @@ -/* - * This project is licensed under the open source MPL V2. - * See https://github.com/openMF/android-client/blob/master/LICENSE.md - */ -package com.mifos.mifosxdroid.adapters - -import android.content.Context -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.widget.BaseAdapter -import androidx.core.content.ContextCompat -import com.mifos.core.objects.accounts.savings.SavingsAccount -import com.mifos.mifosxdroid.R -import com.mifos.mifosxdroid.databinding.RowAccountItemBinding -import java.text.DecimalFormat - -/** - * Created by ishankhanna on 23/05/14. - */ -class SavingsAccountsListAdapter(context: Context, savingsAccountList: List) : - BaseAdapter() { - var context: Context - private val savingsAccountList: List - private val layoutInflater: LayoutInflater - - init { - layoutInflater = LayoutInflater.from(context) - this.savingsAccountList = savingsAccountList - this.context = context - } - - override fun getCount(): Int { - return savingsAccountList.size - } - - override fun getItem(i: Int): SavingsAccount { - return savingsAccountList[i] - } - - override fun getItemId(i: Int): Long { - return 0 - } - - override fun getView(i: Int, view: View?, viewGroup: ViewGroup): View { - val binding: RowAccountItemBinding - val convertView: View - if (view == null) { - binding = RowAccountItemBinding.inflate(layoutInflater, viewGroup, false) - convertView = binding.root - convertView.tag = binding - } else { - binding = view.tag as RowAccountItemBinding - convertView = view - } - if (savingsAccountList[i].status?.active == true) { - binding.viewStatusIndicator.setBackgroundColor( - ContextCompat.getColor( - context, - R.color.savings_account_status_active - ) - ) - } else if (savingsAccountList[i].status?.approved == true) { - binding.viewStatusIndicator.setBackgroundColor( - ContextCompat.getColor(context, R.color.status_approved) - ) - } else if (savingsAccountList[i].status?.submittedAndPendingApproval == true) { - binding.viewStatusIndicator.setBackgroundColor( - ContextCompat.getColor( - context, - R.color.status_submitted_and_pending_approval - ) - ) - } else { - binding.viewStatusIndicator.setBackgroundColor( - ContextCompat.getColor(context, R.color.status_closed) - ) - } - val accountBalance = savingsAccountList[i].accountBalance - val decimalFormat = DecimalFormat("#.##") - decimalFormat.maximumFractionDigits = 2 - decimalFormat.maximumIntegerDigits = 10 - binding.tvAmount.text = - (if (accountBalance == null) "0.00" else decimalFormat.format(accountBalance)).toString() - binding.tvAccountNumber.text = savingsAccountList[i].accountNo - return convertView - } -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/components/Navigation.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/components/Navigation.kt index 754e9f3792f..397a7d3f0d3 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/components/Navigation.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/components/Navigation.kt @@ -115,13 +115,8 @@ fun Navigation( savingsNavGraph( navController = navController, onBackPressed = navController::popBackStack, - loadMoreSavingsAccountInfo = { navController.navigateToDataTable(Constants.DATA_TABLE_NAME_SAVINGS, it) }, - loadDocuments = { - navController.navigateToDocumentListScreen( - it, - Constants.ENTITY_TYPE_SAVINGS - ) - }, + loadMoreSavingsAccountInfo = navController::navigateToDataTable, + loadDocuments = navController::navigateToDocumentListScreen ) loanNavGraph( diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/savingaccountsummary/SavingsAccountSummaryFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/savingaccountsummary/SavingsAccountSummaryFragment.kt deleted file mode 100755 index 332162566c8..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/savingaccountsummary/SavingsAccountSummaryFragment.kt +++ /dev/null @@ -1,150 +0,0 @@ -/* - * This project is licensed under the open source MPL V2. - * See https://github.com/openMF/android-client/blob/master/LICENSE.md - */ -package com.mifos.mifosxdroid.online.savingaccountsummary - -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.compose.ui.platform.ComposeView -import androidx.compose.ui.platform.ViewCompositionStrategy -import androidx.fragment.app.viewModels -import androidx.navigation.findNavController -import androidx.navigation.fragment.findNavController -import androidx.navigation.fragment.navArgs -import com.mifos.core.common.utils.Constants -import com.mifos.core.objects.accounts.savings.DepositType -import com.mifos.core.objects.accounts.savings.SavingsAccountWithAssociations -import com.mifos.feature.savings.account_summary.SavingsAccountSummaryScreen -import com.mifos.feature.savings.account_summary.SavingsAccountSummaryViewModel -import com.mifos.mifosxdroid.core.MifosBaseFragment -import dagger.hilt.android.AndroidEntryPoint - -@AndroidEntryPoint -class SavingsAccountSummaryFragment : MifosBaseFragment() { - - private val viewModel: SavingsAccountSummaryViewModel by viewModels() - private val arg: SavingsAccountSummaryFragmentArgs by navArgs() - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) -// viewModel.accountId = arg.savingsAccountNumber - val v = arg.accountType - } - - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? - ): View { - return ComposeView(requireContext()).apply { - setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) - setContent { - SavingsAccountSummaryScreen( - navigateBack = { findNavController().popBackStack() }, - loadMoreSavingsAccountInfo = { loadSavingsDataTables(it) }, - loadDocuments = { loadDocuments(it) }, - onDepositClick = { savingsAccountWithAssociations, type -> - onDepositButtonClicked(savingsAccountWithAssociations, type) - }, - onWithdrawButtonClicked = { savingsAccountWithAssociations, type -> - onWithdrawalButtonClicked(savingsAccountWithAssociations, type) - }, - activateSavings = { type, accountNumber -> - activateSavings(type, accountNumber) - }, - approveSavings = { type, accountNumber -> - approveSavings(type, accountNumber) - } - ) - } - } - } - - override fun onResume() { - super.onResume() - toolbar?.visibility = View.GONE - } - - override fun onStop() { - super.onStop() - toolbar?.visibility = View.VISIBLE - } - - private fun loadDocuments(savingsAccountNumber: Int) { -// val action = -// SavingsAccountSummaryFragmentDirections.actionSavingsAccountSummaryFragmentToDocumentListFragment( -// savingsAccountNumber, -// Constants.ENTITY_TYPE_SAVINGS -// ) -// findNavController().navigate(action) - } - - private fun onDepositButtonClicked( - savingsAccountWithAssociations: SavingsAccountWithAssociations, - savingsAccountType: DepositType? - ) { - doTransaction( - savingsAccountWithAssociations, - Constants.SAVINGS_ACCOUNT_TRANSACTION_DEPOSIT, savingsAccountType - ) - } - - private fun onWithdrawalButtonClicked( - savingsAccountWithAssociations: SavingsAccountWithAssociations, - savingsAccountType: DepositType? - ) { - doTransaction( - savingsAccountWithAssociations, - Constants.SAVINGS_ACCOUNT_TRANSACTION_WITHDRAWAL, savingsAccountType - ) - } - - private fun approveSavings(savingsAccountType: DepositType?, savingsAccountNumber: Int) { - val action = savingsAccountType?.let { - SavingsAccountSummaryFragmentDirections.actionSavingsAccountSummaryFragmentToSavingsAccountApprovalFragment( - savingsAccountNumber, - it - ) - } - action?.let { findNavController().navigate(it) } - } - - private fun activateSavings(savingsAccountType: DepositType?, savingsAccountNumber: Int) { - val action = savingsAccountType?.let { - SavingsAccountSummaryFragmentDirections.actionSavingsAccountSummaryFragmentToSavingsAccountActivateFragment( - savingsAccountNumber, - it - ) - } - action?.let { findNavController().navigate(it) } - } - - private fun loadSavingsDataTables(savingsAccountNumber: Int) { -// val action = -// SavingsAccountSummaryFragmentDirections.actionSavingsAccountSummaryFragmentToDataTableFragment( -// Constants.DATA_TABLE_NAME_SAVINGS, -// savingsAccountNumber -// ) -// findNavController().navigate(action) - } - - private fun doTransaction( - savingsAccountWithAssociations: SavingsAccountWithAssociations?, - transactionType: String?, - accountType: DepositType? - ) { - val action = savingsAccountWithAssociations?.let { - transactionType?.let { it1 -> - accountType?.let { it2 -> - SavingsAccountSummaryFragmentDirections.actionSavingsAccountSummaryFragmentToSavingsAccountTransactionFragment( - it, it1, it2 - ) - } - } - } - action?.let { findNavController().navigate(it) } - } -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/savingaccounttransaction/SavingsAccountTransactionFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/savingaccounttransaction/SavingsAccountTransactionFragment.kt deleted file mode 100755 index b2d0cbd23f0..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/savingaccounttransaction/SavingsAccountTransactionFragment.kt +++ /dev/null @@ -1,59 +0,0 @@ -/* - * This project is licensed under the open source MPL V2. - * See https://github.com/openMF/android-client/blob/master/LICENSE.md - */ -package com.mifos.mifosxdroid.online.savingaccounttransaction - -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.compose.ui.platform.ComposeView -import androidx.compose.ui.platform.ViewCompositionStrategy -import androidx.fragment.app.viewModels -import androidx.navigation.fragment.findNavController -import androidx.navigation.fragment.navArgs -import com.mifos.feature.savings.account_transaction.SavingsAccountTransactionScreen -import com.mifos.mifosxdroid.core.MifosBaseFragment -import dagger.hilt.android.AndroidEntryPoint - -@AndroidEntryPoint -class SavingsAccountTransactionFragment : MifosBaseFragment() { - -// private val arg: SavingsAccountTransactionFragmentArgs by navArgs() - val viewModel: com.mifos.feature.savings.account_transaction.SavingsAccountTransactionViewModel by viewModels() - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) -// viewModel.accountId = arg.savingsAccountWithAssociations.id -// viewModel.transactionType = arg.transactionType -// viewModel.clientName = arg.savingsAccountWithAssociations.clientName -// viewModel.savingsAccountNumber = arg.savingsAccountWithAssociations.accountNo -// viewModel.savingsAccountType = arg.accountType - } - - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? - ): View { - return ComposeView(requireContext()).apply { - setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) - setContent { - SavingsAccountTransactionScreen { - findNavController().popBackStack() - } - } - } - } - - override fun onResume() { - super.onResume() - toolbar?.visibility = View.GONE - } - - override fun onStop() { - super.onStop() - toolbar?.visibility = View.VISIBLE - } -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/savingsaccount/SavingsAccountFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/savingsaccount/SavingsAccountFragment.kt deleted file mode 100755 index 9fcff05d500..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/savingsaccount/SavingsAccountFragment.kt +++ /dev/null @@ -1,64 +0,0 @@ -/* - * This project is licensed under the open source MPL V2. - * See https://github.com/openMF/android-client/blob/master/LICENSE.md - */ -package com.mifos.mifosxdroid.online.savingsaccount - -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.compose.ui.platform.ComposeView -import androidx.compose.ui.platform.ViewCompositionStrategy -import androidx.fragment.app.viewModels -import androidx.navigation.fragment.findNavController -import androidx.navigation.fragment.navArgs -import com.mifos.feature.savings.account.SavingAccountViewModel -import com.mifos.feature.savings.account.SavingsAccountScreen -import com.mifos.mifosxdroid.core.MifosBaseFragment -import dagger.hilt.android.AndroidEntryPoint - -/** - * Created by nellyk on 1/22/2016. - * - * - * Use this Dialog Fragment to Create and/or Update charges - */ -@AndroidEntryPoint -class SavingsAccountFragment : MifosBaseFragment() { - - private val arg: SavingsAccountFragmentArgs by navArgs() - val viewmodel : SavingAccountViewModel by viewModels() - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) -// viewmodel.clientId = arg.id -// viewmodel.groupId = arg.id -// viewmodel.isGroupAccount = arg.isGroupAccount - } - - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? - ): View { - return ComposeView(requireContext()).apply { - setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) - setContent { - SavingsAccountScreen { - findNavController().popBackStack() - } - } - } - } - - override fun onResume() { - super.onResume() - toolbar?.visibility = View.GONE - } - - override fun onStop() { - super.onStop() - toolbar?.visibility = View.VISIBLE - } -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/savingsaccountactivate/SavingsAccountActivateFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/savingsaccountactivate/SavingsAccountActivateFragment.kt deleted file mode 100644 index cecf568a528..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/savingsaccountactivate/SavingsAccountActivateFragment.kt +++ /dev/null @@ -1,59 +0,0 @@ -/* - * This project is licensed under the open source MPL V2. - * See https://github.com/openMF/android-client/blob/master/LICENSE.md - */ -package com.mifos.mifosxdroid.online.savingsaccountactivate - -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.compose.ui.platform.ComposeView -import androidx.compose.ui.platform.ViewCompositionStrategy -import androidx.fragment.app.viewModels -import androidx.navigation.findNavController -import androidx.navigation.fragment.navArgs -import com.mifos.feature.savings.account_activate.SavingsAccountActivateScreen -import com.mifos.feature.savings.account_activate.SavingsAccountActivateViewModel -import com.mifos.mifosxdroid.core.MifosBaseFragment -import dagger.hilt.android.AndroidEntryPoint - -/** - * Created by Tarun on 01/06/17. - */ -@AndroidEntryPoint -class SavingsAccountActivateFragment : MifosBaseFragment() { - - private val arg: SavingsAccountActivateFragmentArgs by navArgs() - private val viewmodel: SavingsAccountActivateViewModel by viewModels() - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) -// viewmodel.savingsAccountId = arg.savingsAccountNumber - } - - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? - ): View { - return ComposeView(requireContext()).apply { - setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) - setContent { - SavingsAccountActivateScreen( - navigateBack = { findNavController().popBackStack() } - ) - } - } - } - - override fun onResume() { - super.onResume() - toolbar?.visibility = View.GONE - } - - override fun onPause() { - super.onPause() - toolbar?.visibility = View.VISIBLE - } -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/savingsaccountapproval/SavingsAccountApprovalFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/savingsaccountapproval/SavingsAccountApprovalFragment.kt deleted file mode 100644 index 07ae6c4d9d9..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/savingsaccountapproval/SavingsAccountApprovalFragment.kt +++ /dev/null @@ -1,59 +0,0 @@ -/* - * This project is licensed under the open source MPL V2. - * See https://github.com/openMF/android-client/blob/master/LICENSE.md - */ -package com.mifos.mifosxdroid.online.savingsaccountapproval - -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.compose.ui.platform.ComposeView -import androidx.compose.ui.platform.ViewCompositionStrategy -import androidx.fragment.app.viewModels -import androidx.navigation.findNavController -import androidx.navigation.fragment.navArgs -import com.mifos.feature.savings.account_approval.SavingsAccountApprovalScreen -import com.mifos.feature.savings.account_approval.SavingsAccountApprovalViewModel -import com.mifos.mifosxdroid.core.MifosBaseFragment -import dagger.hilt.android.AndroidEntryPoint - -/** - * @author nellyk - */ -@AndroidEntryPoint -class SavingsAccountApprovalFragment : MifosBaseFragment(){ - -// private val arg: SavingsAccountApprovalFragmentArgs by navArgs() - private val viewmodel: SavingsAccountApprovalViewModel by viewModels() - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) -// viewmodel.savingsAccountId = arg.savingsAccountNumber - } - - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? - ): View { - return ComposeView(requireContext()).apply { - setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) - setContent { - SavingsAccountApprovalScreen( - navigateBack = { findNavController().popBackStack() } - ) - } - } - } - - override fun onResume() { - super.onResume() - toolbar?.visibility = View.GONE - } - - override fun onStop() { - super.onStop() - toolbar?.visibility = View.VISIBLE - } -} \ No newline at end of file diff --git a/mifosng-android/src/main/res/layout/dialog_fragment_approve_savings.xml b/mifosng-android/src/main/res/layout/dialog_fragment_approve_savings.xml deleted file mode 100644 index 953a1ff945d..00000000000 --- a/mifosng-android/src/main/res/layout/dialog_fragment_approve_savings.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - - - - - - - - -