From ec8d6b81f53b65615e562732693d52e704167ad0 Mon Sep 17 00:00:00 2001 From: Avneet Singh Date: Fri, 5 Jul 2024 08:51:35 +0530 Subject: [PATCH] refactor: transfer process module (#2644) --- app/build.gradle.kts | 1 + .../TransferProcessComposeFragment.kt | 2 + .../TransferProcessFragment.kt | 231 ------------------ feature/registration/build.gradle.kts | 2 - feature/transfer-process/.gitignore | 1 + feature/transfer-process/build.gradle.kts | 20 ++ feature/transfer-process/consumer-rules.pro | 0 feature/transfer-process/proguard-rules.pro | 21 ++ .../process/ExampleInstrumentedTest.kt | 24 ++ .../src/main/AndroidManifest.xml | 4 + .../process}/TransferProcessScreen.kt | 3 +- .../process}/TransferProcessViewModel.kt | 2 +- .../src/main/res/values/strings.xml | 12 + .../transfer/process/ExampleUnitTest.kt | 17 ++ settings.gradle.kts | 1 + 15 files changed, 105 insertions(+), 236 deletions(-) delete mode 100644 app/src/main/java/org/mifos/mobile/ui/transfer_process/TransferProcessFragment.kt create mode 100644 feature/transfer-process/.gitignore create mode 100644 feature/transfer-process/build.gradle.kts create mode 100644 feature/transfer-process/consumer-rules.pro create mode 100644 feature/transfer-process/proguard-rules.pro create mode 100644 feature/transfer-process/src/androidTest/java/org/mifos/mobile/feature/transfer/process/ExampleInstrumentedTest.kt create mode 100644 feature/transfer-process/src/main/AndroidManifest.xml rename {app/src/main/java/org/mifos/mobile/ui/transfer_process => feature/transfer-process/src/main/java/org/mifos/mobile/feature/transfer/process}/TransferProcessScreen.kt (99%) rename {app/src/main/java/org/mifos/mobile/ui/transfer_process => feature/transfer-process/src/main/java/org/mifos/mobile/feature/transfer/process}/TransferProcessViewModel.kt (98%) create mode 100644 feature/transfer-process/src/main/res/values/strings.xml create mode 100644 feature/transfer-process/src/test/java/org/mifos/mobile/feature/transfer/process/ExampleUnitTest.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 7e9d9cd92..247294d2a 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -83,6 +83,7 @@ dependencies { implementation(projects.feature.guarantor) implementation(projects.feature.savings) implementation(projects.feature.qr) + implementation(projects.feature.transferProcess) diff --git a/app/src/main/java/org/mifos/mobile/ui/transfer_process/TransferProcessComposeFragment.kt b/app/src/main/java/org/mifos/mobile/ui/transfer_process/TransferProcessComposeFragment.kt index 686ee9cd5..4913431d6 100644 --- a/app/src/main/java/org/mifos/mobile/ui/transfer_process/TransferProcessComposeFragment.kt +++ b/app/src/main/java/org/mifos/mobile/ui/transfer_process/TransferProcessComposeFragment.kt @@ -14,6 +14,8 @@ import org.mifos.mobile.core.common.Constants import org.mifos.mobile.core.model.entity.payload.TransferPayload import org.mifos.mobile.core.common.utils.ParcelableAndSerializableUtils.getCheckedParcelable import org.mifos.mobile.core.common.utils.ParcelableAndSerializableUtils.getCheckedSerializable +import org.mifos.mobile.feature.transfer.process.TransferProcessScreen +import org.mifos.mobile.feature.transfer.process.TransferProcessViewModel /** * Created by dilpreet on 1/7/17. diff --git a/app/src/main/java/org/mifos/mobile/ui/transfer_process/TransferProcessFragment.kt b/app/src/main/java/org/mifos/mobile/ui/transfer_process/TransferProcessFragment.kt deleted file mode 100644 index 02b381cb4..000000000 --- a/app/src/main/java/org/mifos/mobile/ui/transfer_process/TransferProcessFragment.kt +++ /dev/null @@ -1,231 +0,0 @@ -package org.mifos.mobile.ui.transfer_process - -/* -import android.graphics.drawable.Animatable -//import android.os.Bundle -//import android.view.LayoutInflater -//import android.view.View -//import android.view.ViewGroup -//import androidx.fragment.app.viewModels -//import androidx.lifecycle.Lifecycle -//import androidx.lifecycle.lifecycleScope -//import androidx.lifecycle.repeatOnLifecycle -import dagger.hilt.android.AndroidEntryPoint -import org.mifos.mobile.databinding.FragmentTransferProcessBinding -import kotlinx.coroutines.launch -import org.mifos.mobile.R -import org.mifos.mobile.databinding.FragmentTransferProcessBinding -import org.mifos.mobile.models.payload.TransferPayload -import org.mifos.mobile.models.templates.account.AccountOption -import org.mifos.mobile.ui.activities.SavingsAccountContainerActivity -import org.mifos.mobile.ui.enums.TransferType -import org.mifos.mobile.ui.fragments.base.BaseFragment -import org.mifos.mobile.core.common.Constants -import org.mifos.mobile.core.common.utils.CurrencyUtil -import org.mifos.mobile.core.common.utils.DateHelper -import org.mifos.mobile.utils.MFErrorParser -import org.mifos.mobile.core.common.Network -import org.mifos.mobile.core.common.utils.ParcelableAndSerializableUtils.getCheckedParcelable -import org.mifos.mobile.core.common.utils.ParcelableAndSerializableUtils.getCheckedSerializable -import org.mifos.mobile.utils.Toaster -import org.mifos.mobile.utils.TransferUiState -import org.mifos.mobile.utils.getTodayFormatted -import org.mifos.mobile.viewModels.TransferProcessViewModel - -/** - * Created by dilpreet on 1/7/17. - */ -@AndroidEntryPoint -class TransferProcessFragment : BaseFragment() { - - private var _binding: FragmentTransferProcessBinding? = null - private val binding get() = _binding!! - - private val viewModel: TransferProcessViewModel by viewModels() - - private var toAccountOption: AccountOption? = null - private var fromAccountOption: AccountOption? = null - - private var payload: TransferPayload? = null - private var transferType: TransferType? = null - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - if (activity != null) { - payload = arguments?.getParcelable(Constants.PAYLOAD) - payload = - arguments?.getCheckedParcelable( - TransferPayload::class.java, - Constants.PAYLOAD - ) - transferType = arguments?.getCheckedSerializable( - TransferType::class.java, - Constants.TRANSFER_TYPE - ) as TransferType } - } - - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle?, - ): View { - _binding = FragmentTransferProcessBinding.inflate(inflater, container, false) - setToolbarTitle(getString(R.string.transfer)) - with(binding) { - tvAmount.text = CurrencyUtil.formatCurrency(activity, payload?.transferAmount) - tvPayFrom.text = payload?.fromAccountNumber.toString() - tvPayTo.text = payload?.toAccountNumber.toString() - tvDate.text = payload?.transferDate - tvRemark.text = payload?.transferDescription - } - - return binding.root - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - - viewLifecycleOwner.lifecycleScope.launch { - repeatOnLifecycle(Lifecycle.State.STARTED) { - viewModel.transferUiState.collect { - when (it) { - is TransferUiState.Loading -> showProgress() - - is TransferUiState.TransferSuccess -> { - hideProgress() - showTransferredSuccessfully() - } - - is TransferUiState.Error -> { - hideProgress() - showError(MFErrorParser.errorMessage(it.errorMessage)) - } - - TransferUiState.Initial -> {} - } - } - } - } - - with(binding) { - btnStartTransfer.setOnClickListener { - startTransfer() - } - btnCancelTransfer.setOnClickListener { - cancelTransferProcess() - } - btnClose.setOnClickListener { - closeClicked() - } - } - } - - /** - * Initiates a transfer depending upon `transferType` - */ - private fun startTransfer() { - if (!Network.isConnected(activity)) { - Toaster.show(binding.root, getString(R.string.internet_not_connected)) - return - } - viewModel.makeTransfer( - fromAccountOption?.officeId, - fromAccountOption?.clientId, - fromAccountOption?.accountType?.id, - fromAccountOption?.accountId, - toAccountOption?.officeId, - toAccountOption?.clientId, - toAccountOption?.accountType?.id, - toAccountOption?.accountId, - DateHelper.getSpecificFormat( - DateHelper.FORMAT_dd_MMMM_yyyy, - getTodayFormatted(), - ), - binding.tvAmount.text.toString().toDouble(), - binding.tvRemark.text.toString(), - "dd MMMM yyyy", - "en", - fromAccountOption?.accountNo, - toAccountOption?.accountNo, - transferType - ) - - } - - /** - * Cancels the Transfer and pops fragment - */ - fun cancelTransferProcess() { - Toaster.cancelTransfer( - binding.root, - getString(R.string.cancel_transfer), - getString(R.string.yes), - View.OnClickListener { - activity?.supportFragmentManager?.popBackStack() - activity?.supportFragmentManager?.popBackStack() - }, - ) - } - - /** - * Closes the transfer fragment - */ - private fun closeClicked() { - activity?.supportFragmentManager?.popBackStack() - activity?.supportFragmentManager?.popBackStack() - } - - /** - * Shows a {@link Snackbar} on succesfull transfer of money - */ - private fun showTransferredSuccessfully() { - Toaster.show(binding.root, getString(R.string.transferred_successfully)) - binding.ivSuccess.visibility = View.VISIBLE - (binding.ivSuccess.drawable as Animatable).start() - binding.btnClose.visibility = View.VISIBLE - binding.llTransfer.visibility = View.GONE - SavingsAccountContainerActivity.transferSuccess = true - } - - /** - * It is called whenever any error occurs while executing a request - * - * @param msg Error message that tells the user about the problem. - */ - fun showError(msg: String?) { - Toaster.show(binding.root, msg) - } - - fun showProgress() { - showMifosProgressDialog(getString(R.string.please_wait)) - } - - fun hideProgress() { - hideMifosProgressDialog() - } - - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } - - companion object { - /** - * Used for TPT Transfer and own Account Transfer.

- * Use `type` as TransferType.TPT for TPT and TransferType.SELF for self Account Transfer - * - * @param payload Transfer Information - * @param type enum of [TransferType] - * @return Instance of [TransferProcessFragment] - */ - fun newInstance(payload: TransferPayload?, type: TransferType?): TransferProcessFragment { - val fragment = TransferProcessFragment() - val args = Bundle() - args.putParcelable(Constants.PAYLOAD, payload) - args.putSerializable(Constants.TRANSFER_TYPE, type) - fragment.arguments = args - return fragment - } - } -} - - */ diff --git a/feature/registration/build.gradle.kts b/feature/registration/build.gradle.kts index e0d853980..060fd034e 100644 --- a/feature/registration/build.gradle.kts +++ b/feature/registration/build.gradle.kts @@ -1,6 +1,4 @@ plugins { - alias(libs.plugins.android.library) - alias(libs.plugins.kotlin.android) alias(libs.plugins.mifos.android.feature) alias(libs.plugins.mifos.android.library.compose) } diff --git a/feature/transfer-process/.gitignore b/feature/transfer-process/.gitignore new file mode 100644 index 000000000..42afabfd2 --- /dev/null +++ b/feature/transfer-process/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/feature/transfer-process/build.gradle.kts b/feature/transfer-process/build.gradle.kts new file mode 100644 index 000000000..889046ade --- /dev/null +++ b/feature/transfer-process/build.gradle.kts @@ -0,0 +1,20 @@ +plugins { + alias(libs.plugins.mifos.android.feature) + alias(libs.plugins.mifos.android.library.compose) +} + + +android { + namespace = "org.mifos.mobile.feature.transfer.process" +} + +dependencies { + implementation(projects.ui) + implementation(projects.core.common) + implementation(projects.core.model) + implementation(projects.core.data) + + testImplementation(libs.junit) + androidTestImplementation(libs.androidx.test.ext.junit) + androidTestImplementation(libs.espresso.core) +} \ No newline at end of file diff --git a/feature/transfer-process/consumer-rules.pro b/feature/transfer-process/consumer-rules.pro new file mode 100644 index 000000000..e69de29bb diff --git a/feature/transfer-process/proguard-rules.pro b/feature/transfer-process/proguard-rules.pro new file mode 100644 index 000000000..481bb4348 --- /dev/null +++ b/feature/transfer-process/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/feature/transfer-process/src/androidTest/java/org/mifos/mobile/feature/transfer/process/ExampleInstrumentedTest.kt b/feature/transfer-process/src/androidTest/java/org/mifos/mobile/feature/transfer/process/ExampleInstrumentedTest.kt new file mode 100644 index 000000000..27b19e399 --- /dev/null +++ b/feature/transfer-process/src/androidTest/java/org/mifos/mobile/feature/transfer/process/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package org.mifos.mobile.feature.transfer.process + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("org.mifos.mobile.feature.transfer.process.test", appContext.packageName) + } +} \ No newline at end of file diff --git a/feature/transfer-process/src/main/AndroidManifest.xml b/feature/transfer-process/src/main/AndroidManifest.xml new file mode 100644 index 000000000..a5918e68a --- /dev/null +++ b/feature/transfer-process/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/app/src/main/java/org/mifos/mobile/ui/transfer_process/TransferProcessScreen.kt b/feature/transfer-process/src/main/java/org/mifos/mobile/feature/transfer/process/TransferProcessScreen.kt similarity index 99% rename from app/src/main/java/org/mifos/mobile/ui/transfer_process/TransferProcessScreen.kt rename to feature/transfer-process/src/main/java/org/mifos/mobile/feature/transfer/process/TransferProcessScreen.kt index 24cbad54b..b22e1abe4 100644 --- a/app/src/main/java/org/mifos/mobile/ui/transfer_process/TransferProcessScreen.kt +++ b/feature/transfer-process/src/main/java/org/mifos/mobile/feature/transfer/process/TransferProcessScreen.kt @@ -1,4 +1,4 @@ -package org.mifos.mobile.ui.transfer_process +package org.mifos.mobile.feature.transfer.process import android.widget.Toast import androidx.compose.foundation.BorderStroke @@ -34,7 +34,6 @@ import androidx.compose.ui.tooling.preview.PreviewParameterProvider import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle -import org.mifos.mobile.R import org.mifos.mobile.core.ui.component.MFScaffold import org.mifos.mobile.core.ui.component.MifosErrorComponent import org.mifos.mobile.core.ui.component.MifosProgressIndicatorOverlay diff --git a/app/src/main/java/org/mifos/mobile/ui/transfer_process/TransferProcessViewModel.kt b/feature/transfer-process/src/main/java/org/mifos/mobile/feature/transfer/process/TransferProcessViewModel.kt similarity index 98% rename from app/src/main/java/org/mifos/mobile/ui/transfer_process/TransferProcessViewModel.kt rename to feature/transfer-process/src/main/java/org/mifos/mobile/feature/transfer/process/TransferProcessViewModel.kt index 6b648e8b4..c50579e34 100644 --- a/app/src/main/java/org/mifos/mobile/ui/transfer_process/TransferProcessViewModel.kt +++ b/feature/transfer-process/src/main/java/org/mifos/mobile/feature/transfer/process/TransferProcessViewModel.kt @@ -1,4 +1,4 @@ -package org.mifos.mobile.ui.transfer_process +package org.mifos.mobile.feature.transfer.process import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope diff --git a/feature/transfer-process/src/main/res/values/strings.xml b/feature/transfer-process/src/main/res/values/strings.xml new file mode 100644 index 000000000..2b5ca4856 --- /dev/null +++ b/feature/transfer-process/src/main/res/values/strings.xml @@ -0,0 +1,12 @@ + + + Transfer + Transferred Successfully + Amount + Transfer from Savings + Pay To + Pay From + Date + Cancel + Remark + \ No newline at end of file diff --git a/feature/transfer-process/src/test/java/org/mifos/mobile/feature/transfer/process/ExampleUnitTest.kt b/feature/transfer-process/src/test/java/org/mifos/mobile/feature/transfer/process/ExampleUnitTest.kt new file mode 100644 index 000000000..e0bb4aa78 --- /dev/null +++ b/feature/transfer-process/src/test/java/org/mifos/mobile/feature/transfer/process/ExampleUnitTest.kt @@ -0,0 +1,17 @@ +package org.mifos.mobile.feature.transfer.process + +import org.junit.Test + +import org.junit.Assert.* + +/** + * Example local unit test, which will execute on the development machine (host). + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +class ExampleUnitTest { + @Test + fun addition_isCorrect() { + assertEquals(4, 2 + 2) + } +} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 88c25f0c1..025e9d601 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -34,3 +34,4 @@ include(":feature:beneficiary") include(":feature:registration") include(":feature:savings") include(":feature:qr") +include(":feature:transfer-process")