diff --git a/app/src/main/java/org/mifos/mobile/ui/activities/HomeActivity.kt b/app/src/main/java/org/mifos/mobile/ui/activities/HomeActivity.kt
index 31e6b3393..8b7e9874c 100644
--- a/app/src/main/java/org/mifos/mobile/ui/activities/HomeActivity.kt
+++ b/app/src/main/java/org/mifos/mobile/ui/activities/HomeActivity.kt
@@ -42,6 +42,7 @@ import org.mifos.mobile.ui.login.LoginActivity
import org.mifos.mobile.ui.third_party_transfer.ThirdPartyTransferComposeFragment
import org.mifos.mobile.ui.notification.NotificationFragment
import org.mifos.mobile.ui.recent_transactions.RecentTransactionsComposeFragment
+import org.mifos.mobile.ui.transfer_process.TransferProcessComposeFragment
import org.mifos.mobile.utils.Constants
import org.mifos.mobile.utils.TextDrawable
import org.mifos.mobile.utils.Toaster
@@ -386,8 +387,7 @@ class HomeActivity :
doubleBackToExitPressedOnce = true
Toaster.show(findViewById(android.R.id.content), getString(R.string.exit_message))
Handler().postDelayed({ doubleBackToExitPressedOnce = false }, 2000)
- } else if (fragment is TransferProcessFragment) {
- fragment.cancelTransferProcess()
+ } else if (fragment is TransferProcessComposeFragment) {
}
if (stackCount() != 0) {
diff --git a/app/src/main/java/org/mifos/mobile/ui/savings_make_transfer/SavingsMakeTransferComposeFragment.kt b/app/src/main/java/org/mifos/mobile/ui/savings_make_transfer/SavingsMakeTransferComposeFragment.kt
index cf735fddd..410fe3092 100644
--- a/app/src/main/java/org/mifos/mobile/ui/savings_make_transfer/SavingsMakeTransferComposeFragment.kt
+++ b/app/src/main/java/org/mifos/mobile/ui/savings_make_transfer/SavingsMakeTransferComposeFragment.kt
@@ -16,8 +16,8 @@ import org.mifos.mobile.core.ui.component.mifosComposeView
import org.mifos.mobile.models.payload.TransferPayload
import org.mifos.mobile.ui.activities.base.BaseActivity
import org.mifos.mobile.ui.enums.TransferType
-import org.mifos.mobile.ui.fragments.TransferProcessFragment
import org.mifos.mobile.ui.fragments.base.BaseFragment
+import org.mifos.mobile.ui.transfer_process.TransferProcessComposeFragment
import org.mifos.mobile.utils.Constants
import org.mifos.mobile.utils.DateHelper
import org.mifos.mobile.utils.getTodayFormatted
@@ -71,7 +71,7 @@ class SavingsMakeTransferComposeFragment : BaseFragment() {
}
(activity as BaseActivity?)?.replaceFragment(
- TransferProcessFragment.newInstance(transferPayload, TransferType.SELF),
+ TransferProcessComposeFragment.newInstance(transferPayload, TransferType.SELF),
true,
R.id.container,
)
diff --git a/app/src/main/java/org/mifos/mobile/ui/savings_make_transfer/SavingsMakeTransferFragment.kt b/app/src/main/java/org/mifos/mobile/ui/savings_make_transfer/SavingsMakeTransferFragment.kt
index dcd1e3ab3..51be6d7ac 100644
--- a/app/src/main/java/org/mifos/mobile/ui/savings_make_transfer/SavingsMakeTransferFragment.kt
+++ b/app/src/main/java/org/mifos/mobile/ui/savings_make_transfer/SavingsMakeTransferFragment.kt
@@ -1,464 +1,432 @@
package org.mifos.mobile.ui.savings_make_transfer
-import android.os.Bundle
-import android.view.LayoutInflater
-import android.view.Menu
-import android.view.MenuInflater
-import android.view.MenuItem
-import android.view.View
-import android.view.ViewGroup
-import android.widget.EditText
-import android.widget.Spinner
-import androidx.fragment.app.viewModels
-import androidx.lifecycle.Lifecycle
-import androidx.lifecycle.lifecycleScope
-import androidx.lifecycle.repeatOnLifecycle
-import com.github.therajanmaurya.sweeterror.SweetUIErrorHandler
import dagger.hilt.android.AndroidEntryPoint
-import kotlinx.coroutines.launch
-import org.mifos.mobile.R
-import org.mifos.mobile.databinding.FragmentSavingsMakeTransferBinding
-import org.mifos.mobile.models.payload.TransferPayload
-import org.mifos.mobile.models.templates.account.AccountOption
-import org.mifos.mobile.models.templates.account.AccountOptionsTemplate
-import org.mifos.mobile.ui.activities.base.BaseActivity
-import org.mifos.mobile.ui.adapters.AccountsSpinnerAdapter
-import org.mifos.mobile.ui.enums.TransferType
-import org.mifos.mobile.ui.fragments.TransferProcessFragment
import org.mifos.mobile.ui.fragments.base.BaseFragment
-import org.mifos.mobile.utils.Constants
-import org.mifos.mobile.utils.DateHelper
-import org.mifos.mobile.utils.Network
-import org.mifos.mobile.utils.ParcelableAndSerializableUtils.getCheckedParcelable
-import org.mifos.mobile.utils.SavingsAccountUiState
-import org.mifos.mobile.utils.Toaster
-import org.mifos.mobile.utils.Utils
-import org.mifos.mobile.utils.getTodayFormatted
/**
* Created by Rajan Maurya on 10/03/17.
*/
@AndroidEntryPoint
class SavingsMakeTransferFragment : BaseFragment() {
-
- private var _binding: FragmentSavingsMakeTransferBinding? = null
- private val binding get() = _binding!!
- private val viewModel: SavingsMakeTransferViewModel by viewModels()
- private var transferPayload: TransferPayload? = null
- private var transferDate: String? = null
- private var toAccountOption: AccountOption? = null
- private var fromAccountOption: AccountOption? = null
- private var accountOptionsTemplate: AccountOptionsTemplate? = null
- private var transferType: String? = null
- private var payTo: String? = null
- private var payFrom: String? = null
- private var accountId: Long? = 0
- private var outStandingBalance: Double? = 0.0
- private var isLoanRepayment = false
- private var sweetUIErrorHandler: SweetUIErrorHandler? = null
-
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- (activity as? BaseActivity)?.showToolbar()
- if (arguments != null) {
- accountId = arguments?.getLong(Constants.ACCOUNT_ID)
- transferType = arguments?.getString(Constants.TRANSFER_TYPE)
- if (arguments?.getBoolean(Constants.LOAN_REPAYMENT, false) == true) {
- isLoanRepayment = true
- outStandingBalance = arguments?.getDouble(Constants.OUTSTANDING_BALANCE)
- }
- }
- setHasOptionsMenu(true)
- }
-
- override fun onCreateView(
- inflater: LayoutInflater,
- container: ViewGroup?,
- savedInstanceState: Bundle?,
- ): View {
- _binding = FragmentSavingsMakeTransferBinding.inflate(inflater, container, false)
- setToolbarTitle(getString(R.string.transfer))
- sweetUIErrorHandler = SweetUIErrorHandler(activity, binding.root)
- showUserInterface()
- if (savedInstanceState == null) {
- //viewModel.loanAccountTransferTemplate()
- }
- return binding.root
- }
-
- override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
- super.onViewCreated(view, savedInstanceState)
-
- with(binding) {
- btnCancelTransfer.setOnClickListener {
- cancelTransfer()
- }
-
- btnReviewTransfer.setOnClickListener {
- reviewTransfer()
- }
-
- btnPayFrom.setOnClickListener {
- payFromSelected()
- }
-
- btnPayTo.setOnClickListener {
- payToSelected()
- }
-
- btnAmount.setOnClickListener {
- amountSet()
- }
-
- layoutError.btnTryAgain.setOnClickListener {
- onRetry()
- }
- }
-
-// viewLifecycleOwner.lifecycleScope.launch {
-// repeatOnLifecycle(Lifecycle.State.STARTED) {
-// viewModel.savingsMakeTransferUiState.collect { state ->
-// when (state) {
-// SavingsAccountUiState.Loading -> showProgress()
-//
-// is SavingsAccountUiState.ErrorMessage -> {
-// hideProgress()
-// showError(context?.getString(R.string.error_fetching_account_transfer_template))
-// }
-//
-// is SavingsAccountUiState.ShowSavingsAccountTemplate -> {
-// hideProgress()
-// showSavingsAccountTemplate(state.accountOptionsTemplate)
-// }
-//
-// is SavingsAccountUiState.Initial -> {}
-//
-// else -> throw IllegalStateException("Unexpected state : $state")
-// }
-// }
+//
+// private var _binding: FragmentSavingsMakeTransferBinding? = null
+// private val binding get() = _binding!!
+// private val viewModel: SavingsMakeTransferViewModel by viewModels()
+// private var transferPayload: TransferPayload? = null
+// private var transferDate: String? = null
+// private var toAccountOption: AccountOption? = null
+// private var fromAccountOption: AccountOption? = null
+// private var accountOptionsTemplate: AccountOptionsTemplate? = null
+// private var transferType: String? = null
+// private var payTo: String? = null
+// private var payFrom: String? = null
+// private var accountId: Long? = 0
+// private var outStandingBalance: Double? = 0.0
+// private var isLoanRepayment = false
+// private var sweetUIErrorHandler: SweetUIErrorHandler? = null
+//
+// override fun onCreate(savedInstanceState: Bundle?) {
+// super.onCreate(savedInstanceState)
+// (activity as? BaseActivity)?.showToolbar()
+// if (arguments != null) {
+// accountId = arguments?.getLong(Constants.ACCOUNT_ID)
+// transferType = arguments?.getString(Constants.TRANSFER_TYPE)
+// if (arguments?.getBoolean(Constants.LOAN_REPAYMENT, false) == true) {
+// isLoanRepayment = true
+// outStandingBalance = arguments?.getDouble(Constants.OUTSTANDING_BALANCE)
// }
// }
- }
-
- override fun onSaveInstanceState(outState: Bundle) {
- super.onSaveInstanceState(outState)
- outState.putParcelable(Constants.TEMPLATE, accountOptionsTemplate)
- }
-
- override fun onActivityCreated(savedInstanceState: Bundle?) {
- super.onActivityCreated(savedInstanceState)
- if (savedInstanceState != null) {
- showSavingsAccountTemplate(
- savedInstanceState.getCheckedParcelable(
- AccountOptionsTemplate::class.java,
- Constants.TEMPLATE
- )
- ) }
- }
-
- /**
- * Checks validation of `etRemark` and then opens [TransferProcessFragment] for
- * initiating the transfer
- */
- private fun reviewTransfer() {
- if (binding.etRemark.text.toString().trim { it <= ' ' } == "") {
- showToaster(getString(R.string.remark_is_mandatory))
- return
- }
- transferPayload = TransferPayload()
- transferPayload?.fromAccountId = fromAccountOption?.accountId
- transferPayload?.fromClientId = fromAccountOption?.clientId
- transferPayload?.fromAccountType = fromAccountOption?.accountType?.id
- transferPayload?.fromOfficeId = fromAccountOption?.officeId
- transferPayload?.toOfficeId = toAccountOption?.officeId
- transferPayload?.toAccountId = toAccountOption?.accountId
- transferPayload?.toClientId = toAccountOption?.clientId
- transferPayload?.toAccountType = toAccountOption?.accountType?.id
- transferPayload?.transferDate = transferDate
- transferPayload?.transferAmount = binding.amountField.text.toString().toDouble()
- transferPayload?.transferDescription = binding.etRemark.text.toString()
- transferPayload?.fromAccountNumber = fromAccountOption?.accountNo
- transferPayload?.toAccountNumber = toAccountOption?.accountNo
- (activity as BaseActivity?)?.replaceFragment(
- TransferProcessFragment.newInstance(
- transferPayload,
- TransferType.SELF,
- ),
- true,
- R.id.container,
- )
- }
-
- /**
- * Cancels the transfer by popping current Fragment
- */
- private fun cancelTransfer() {
- activity?.supportFragmentManager?.popBackStack()
- }
-
- private fun onRetry() {
- if (Network.isConnected(context)) {
- sweetUIErrorHandler?.hideSweetErrorLayoutUI(
- binding.llMakeTransfer,
- binding.layoutError.root,
- )
- //viewModel.loanAccountTransferTemplate()
- } else {
- Toaster.show(binding.root, getString(R.string.internet_not_connected))
- }
- }
-
- /**
- * Setting up basic components
- */
- fun showUserInterface() {
- binding.processOne.setCurrentActive()
- binding.payFromField.setOnItemClickListener { _, _, position, _ ->
- toAccountOption = accountOptionsTemplate?.toAccountOptions?.get(position)
- payTo = toAccountOption?.accountNo
- println("paytofield item selected payTo:$payTo")
- updateDetails()
- }
- binding.payToField.setOnItemClickListener { _, _, position, _ ->
- fromAccountOption = accountOptionsTemplate?.fromAccountOptions?.get(position)
- payFrom = fromAccountOption?.accountNo
- println("payfrom item selected payFrom:$payFrom")
- updateDetails()
- }
- transferDate = DateHelper.getSpecificFormat(
- DateHelper.FORMAT_dd_MMMM_yyyy,
- getTodayFormatted(),
- )
- if (isLoanRepayment) {
- binding.amountField.setText(outStandingBalance.toString())
- binding.amountFieldWrapper.isFocusable = false
- }
- }
-
- private fun updateDetails() {
-// when (transferType) {
-// Constants.TRANSFER_PAY_TO -> {
-// setToolbarTitle(getString(R.string.deposit))
-// toAccountOption =
-// viewModel.searchAccount(accountOptionsTemplate?.toAccountOptions, accountId)
-// binding.payToFieldWrapper.isEnabled = false
-// binding.processOne.setCurrentCompleted()
+// setHasOptionsMenu(true)
+// }
+//
+// override fun onCreateView(
+// inflater: LayoutInflater,
+// container: ViewGroup?,
+// savedInstanceState: Bundle?,
+// ): View {
+// _binding = FragmentSavingsMakeTransferBinding.inflate(inflater, container, false)
+// setToolbarTitle(getString(R.string.transfer))
+// sweetUIErrorHandler = SweetUIErrorHandler(activity, binding.root)
+// showUserInterface()
+// if (savedInstanceState == null) {
+// //viewModel.loanAccountTransferTemplate()
+// }
+// return binding.root
+// }
+//
+// override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+// super.onViewCreated(view, savedInstanceState)
+//
+// with(binding) {
+// btnCancelTransfer.setOnClickListener {
+// cancelTransfer()
+// }
+//
+// btnReviewTransfer.setOnClickListener {
+// reviewTransfer()
+// }
+//
+// btnPayFrom.setOnClickListener {
+// payFromSelected()
// }
//
-// Constants.TRANSFER_PAY_FROM -> {
-// setToolbarTitle(getString(R.string.transfer))
-// fromAccountOption =
-// viewModel.searchAccount(accountOptionsTemplate?.fromAccountOptions, accountId)
-// binding.payFromFieldWrapper.isEnabled = false
-// binding.payFromFieldWrapper.visibility = View.VISIBLE
-// binding.processTwo.setCurrentCompleted()
+// btnPayTo.setOnClickListener {
+// payToSelected()
+// }
+//
+// btnAmount.setOnClickListener {
+// amountSet()
+// }
+//
+// layoutError.btnTryAgain.setOnClickListener {
+// onRetry()
// }
// }
- }
-
- /**
- * Provides with `accountOptionsTemplate` fetched from server which is used to update
- * `listPayFrom` and `listPayTo`
- *
- * @param accountOptionsTemplate Template for account transfer
- */
- private fun showSavingsAccountTemplate(accountOptionsTemplate: AccountOptionsTemplate?) {
- this.accountOptionsTemplate = accountOptionsTemplate
-// binding.payToField.setAdapter(
-// AccountsSpinnerAdapter(
-// requireContext(),
-// viewModel.getAccountNumbers(
-// accountOptionsTemplate?.toAccountOptions,
-// false,
-// context?.getString(R.string.account_type_loan)
-// ),
+//
+//// viewLifecycleOwner.lifecycleScope.launch {
+//// repeatOnLifecycle(Lifecycle.State.STARTED) {
+//// viewModel.savingsMakeTransferUiState.collect { state ->
+//// when (state) {
+//// SavingsAccountUiState.Loading -> showProgress()
+////
+//// is SavingsAccountUiState.ErrorMessage -> {
+//// hideProgress()
+//// showError(context?.getString(R.string.error_fetching_account_transfer_template))
+//// }
+////
+//// is SavingsAccountUiState.ShowSavingsAccountTemplate -> {
+//// hideProgress()
+//// showSavingsAccountTemplate(state.accountOptionsTemplate)
+//// }
+////
+//// is SavingsAccountUiState.Initial -> {}
+////
+//// else -> throw IllegalStateException("Unexpected state : $state")
+//// }
+//// }
+//// }
+//// }
+// }
+//
+// override fun onSaveInstanceState(outState: Bundle) {
+// super.onSaveInstanceState(outState)
+// outState.putParcelable(Constants.TEMPLATE, accountOptionsTemplate)
+// }
+//
+// override fun onActivityCreated(savedInstanceState: Bundle?) {
+// super.onActivityCreated(savedInstanceState)
+// if (savedInstanceState != null) {
+// showSavingsAccountTemplate(
+// savedInstanceState.getCheckedParcelable(
+// AccountOptionsTemplate::class.java,
+// Constants.TEMPLATE
+// )
+// ) }
+// }
+//
+// /**
+// * Checks validation of `etRemark` and then opens [TransferProcessComposeFragment] for
+// * initiating the transfer
+// */
+// private fun reviewTransfer() {
+// if (binding.etRemark.text.toString().trim { it <= ' ' } == "") {
+// showToaster(getString(R.string.remark_is_mandatory))
+// return
+// }
+// transferPayload = TransferPayload()
+// transferPayload?.fromAccountId = fromAccountOption?.accountId
+// transferPayload?.fromClientId = fromAccountOption?.clientId
+// transferPayload?.fromAccountType = fromAccountOption?.accountType?.id
+// transferPayload?.fromOfficeId = fromAccountOption?.officeId
+// transferPayload?.toOfficeId = toAccountOption?.officeId
+// transferPayload?.toAccountId = toAccountOption?.accountId
+// transferPayload?.toClientId = toAccountOption?.clientId
+// transferPayload?.toAccountType = toAccountOption?.accountType?.id
+// transferPayload?.transferDate = transferDate
+// transferPayload?.transferAmount = binding.amountField.text.toString().toDouble()
+// transferPayload?.transferDescription = binding.etRemark.text.toString()
+// transferPayload?.fromAccountNumber = fromAccountOption?.accountNo
+// transferPayload?.toAccountNumber = toAccountOption?.accountNo
+// (activity as BaseActivity?)?.replaceFragment(
+// TransferProcessComposeFragment.newInstance(
+// transferPayload,
+// TransferType.SELF,
// ),
+// true,
+// R.id.container,
// )
-// binding.payFromField.setAdapter(
-// AccountsSpinnerAdapter(
-// requireContext(),
-// viewModel.getAccountNumbers(
-// accountOptionsTemplate?.toAccountOptions,
-// true,
-// context?.getString(R.string.account_type_loan)
-// ),
-// ),
+// }
+//
+// /**
+// * Cancels the transfer by popping current Fragment
+// */
+// private fun cancelTransfer() {
+// activity?.supportFragmentManager?.popBackStack()
+// }
+//
+// private fun onRetry() {
+// if (Network.isConnected(context)) {
+// sweetUIErrorHandler?.hideSweetErrorLayoutUI(
+// binding.llMakeTransfer,
+// binding.layoutError.root,
+// )
+// //viewModel.loanAccountTransferTemplate()
+// } else {
+// Toaster.show(binding.root, getString(R.string.internet_not_connected))
+// }
+// }
+//
+// /**
+// * Setting up basic components
+// */
+// fun showUserInterface() {
+// binding.processOne.setCurrentActive()
+// binding.payFromField.setOnItemClickListener { _, _, position, _ ->
+// toAccountOption = accountOptionsTemplate?.toAccountOptions?.get(position)
+// payTo = toAccountOption?.accountNo
+// println("paytofield item selected payTo:$payTo")
+// updateDetails()
+// }
+// binding.payToField.setOnItemClickListener { _, _, position, _ ->
+// fromAccountOption = accountOptionsTemplate?.fromAccountOptions?.get(position)
+// payFrom = fromAccountOption?.accountNo
+// println("payfrom item selected payFrom:$payFrom")
+// updateDetails()
+// }
+// transferDate = DateHelper.getSpecificFormat(
+// DateHelper.FORMAT_dd_MMMM_yyyy,
+// getTodayFormatted(),
// )
- }
-
- /**
- * Shows a {@link Snackbar} with `message`
- *f
- * @param message String to be shown
- */
- private fun showToaster(message: String?) {
- Toaster.show(binding.root, message)
- }
-
- /**
- * It is called whenever any error occurs while executing a request
- *
- * @param message Error message that tells the user about the problem.
- */
- fun showError(message: String?) {
- if (!Network.isConnected(context)) {
- sweetUIErrorHandler?.showSweetNoInternetUI(
- binding.llMakeTransfer,
- binding.layoutError.root,
- )
- } else {
- sweetUIErrorHandler?.showSweetErrorUI(
- message,
- binding.llMakeTransfer,
- binding.layoutError.root,
- )
- Toaster.show(binding.root, message)
- }
- }
-
- fun showProgress() {
- binding.llMakeTransfer.visibility = View.GONE
- showProgressBar()
- }
-
- fun hideProgress() {
- binding.llMakeTransfer.visibility = View.VISIBLE
- hideProgressBar()
- }
-
- /**
- * Callback for `spPayFrom` and `spPayTo`
- */
-
- /**
- * Disables `spPayTo` [Spinner] and sets `pvOne` to completed and make
- * `pvTwo` active
- */
- private fun payToSelected() {
- with(binding) {
- processOne.setCurrentCompleted()
- processTwo.setCurrentActive()
- btnPayTo.visibility = View.GONE
- btnPayFrom.visibility = View.VISIBLE
- payFromFieldWrapper.visibility = View.VISIBLE
- payToFieldWrapper.isEnabled = false
- }
- }
-
- /**
- * Checks validation of `spPayTo` [Spinner].
- * Disables `spPayFrom` [Spinner] and sets `pvTwo` to completed and make
- * `pvThree` active
- */
- private fun payFromSelected() {
- if (payTo == payFrom) {
- showToaster(getString(R.string.error_same_account_transfer))
- return
- }
- with(binding) {
- processTwo.setCurrentCompleted()
- processThree.setCurrentActive()
- btnPayFrom.visibility = View.GONE
- amountFieldWrapper.visibility = View.VISIBLE
- btnAmount.visibility = View.VISIBLE
- payFromFieldWrapper.isEnabled = false
- }
- }
-
- /**
- * Checks validation of `etAmount` [EditText].
- * Disables `etAmount` and sets `pvThree` to completed and make
- * `pvFour` active
- */
- private fun amountSet() {
- if (binding.amountField.text.toString() == "") {
- showToaster(getString(R.string.enter_amount))
- return
- }
- if (binding.amountField.text.toString() == ".") {
- showToaster(getString(R.string.invalid_amount))
- return
- }
- if (binding.amountField.text.toString().toDouble() == 0.0) {
- showToaster(getString(R.string.amount_greater_than_zero))
- return
- }
- with(binding) {
- processThree.setCurrentCompleted()
- processFour.setCurrentActive()
- btnAmount.visibility = View.GONE
- tvEnterRemark.visibility = View.GONE
- etRemark.visibility = View.VISIBLE
- llReview.visibility = View.VISIBLE
- amountFieldWrapper.isEnabled = false
- }
- }
-
- override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
- super.onCreateOptionsMenu(menu, inflater)
- inflater.inflate(R.menu.menu_transfer, menu)
- Utils.setToolbarIconColor(activity, menu, R.color.white)
- }
-
- override fun onOptionsItemSelected(item: MenuItem): Boolean {
- if (item.itemId == R.id.menu_refresh_transfer) {
- val transaction = fragmentManager?.beginTransaction()
- val currFragment = activity?.supportFragmentManager
- ?.findFragmentById(R.id.container)
- if (currFragment != null) {
- transaction?.detach(currFragment)
- transaction?.attach(currFragment)
- }
- transaction?.commit()
- }
- return super.onOptionsItemSelected(item)
- }
-
- override fun onDestroyView() {
- super.onDestroyView()
- hideProgress()
- hideMifosProgressDialog()
- _binding = null
- }
-
- companion object {
- /**
- * Provides an instance of [SavingsMakeTransferFragment], use `transferType` as
- * `Constants.TRANSFER_PAY_TO` when we want to deposit and
- * `Constants.TRANSFER_PAY_FROM` when we want to make a transfer
- *
- * @param accountId Saving account Id
- * @param transferType Type of transfer i.e. `Constants.TRANSFER_PAY_TO` or
- * `Constants.TRANSFER_PAY_FROM`
- * @return Instance of [SavingsMakeTransferFragment]
- */
- fun newInstance(accountId: Long?, transferType: String?): SavingsMakeTransferFragment {
- val transferFragment = SavingsMakeTransferFragment()
- val args = Bundle()
- if (accountId != null) args.putLong(Constants.ACCOUNT_ID, accountId)
- args.putString(Constants.TRANSFER_TYPE, transferType)
- transferFragment.arguments = args
- return transferFragment
- }
-
- fun newInstance(
- accountId: Long?,
- outstandingBalance: Double?,
- transferType: String?,
- ): SavingsMakeTransferFragment {
- val transferFragment = SavingsMakeTransferFragment()
- val args = Bundle()
- if (accountId != null) args.putLong(Constants.ACCOUNT_ID, accountId)
- args.putString(Constants.TRANSFER_TYPE, transferType)
- if (outstandingBalance != null) {
- args.putDouble(
- Constants.OUTSTANDING_BALANCE,
- outstandingBalance,
- )
- }
- args.putBoolean(Constants.LOAN_REPAYMENT, true)
- transferFragment.arguments = args
- return transferFragment
- }
- }
+// if (isLoanRepayment) {
+// binding.amountField.setText(outStandingBalance.toString())
+// binding.amountFieldWrapper.isFocusable = false
+// }
+// }
+//
+// private fun updateDetails() {
+//// when (transferType) {
+//// Constants.TRANSFER_PAY_TO -> {
+//// setToolbarTitle(getString(R.string.deposit))
+//// toAccountOption =
+//// viewModel.searchAccount(accountOptionsTemplate?.toAccountOptions, accountId)
+//// binding.payToFieldWrapper.isEnabled = false
+//// binding.processOne.setCurrentCompleted()
+//// }
+////
+//// Constants.TRANSFER_PAY_FROM -> {
+//// setToolbarTitle(getString(R.string.transfer))
+//// fromAccountOption =
+//// viewModel.searchAccount(accountOptionsTemplate?.fromAccountOptions, accountId)
+//// binding.payFromFieldWrapper.isEnabled = false
+//// binding.payFromFieldWrapper.visibility = View.VISIBLE
+//// binding.processTwo.setCurrentCompleted()
+//// }
+//// }
+// }
+//
+// /**
+// * Provides with `accountOptionsTemplate` fetched from server which is used to update
+// * `listPayFrom` and `listPayTo`
+// *
+// * @param accountOptionsTemplate Template for account transfer
+// */
+// private fun showSavingsAccountTemplate(accountOptionsTemplate: AccountOptionsTemplate?) {
+// this.accountOptionsTemplate = accountOptionsTemplate
+//// binding.payToField.setAdapter(
+//// AccountsSpinnerAdapter(
+//// requireContext(),
+//// viewModel.getAccountNumbers(
+//// accountOptionsTemplate?.toAccountOptions,
+//// false,
+//// context?.getString(R.string.account_type_loan)
+//// ),
+//// ),
+//// )
+//// binding.payFromField.setAdapter(
+//// AccountsSpinnerAdapter(
+//// requireContext(),
+//// viewModel.getAccountNumbers(
+//// accountOptionsTemplate?.toAccountOptions,
+//// true,
+//// context?.getString(R.string.account_type_loan)
+//// ),
+//// ),
+//// )
+// }
+//
+// /**
+// * Shows a {@link Snackbar} with `message`
+// *f
+// * @param message String to be shown
+// */
+// private fun showToaster(message: String?) {
+// Toaster.show(binding.root, message)
+// }
+//
+// /**
+// * It is called whenever any error occurs while executing a request
+// *
+// * @param message Error message that tells the user about the problem.
+// */
+// fun showError(message: String?) {
+// if (!Network.isConnected(context)) {
+// sweetUIErrorHandler?.showSweetNoInternetUI(
+// binding.llMakeTransfer,
+// binding.layoutError.root,
+// )
+// } else {
+// sweetUIErrorHandler?.showSweetErrorUI(
+// message,
+// binding.llMakeTransfer,
+// binding.layoutError.root,
+// )
+// Toaster.show(binding.root, message)
+// }
+// }
+//
+// fun showProgress() {
+// binding.llMakeTransfer.visibility = View.GONE
+// showProgressBar()
+// }
+//
+// fun hideProgress() {
+// binding.llMakeTransfer.visibility = View.VISIBLE
+// hideProgressBar()
+// }
+//
+// /**
+// * Callback for `spPayFrom` and `spPayTo`
+// */
+//
+// /**
+// * Disables `spPayTo` [Spinner] and sets `pvOne` to completed and make
+// * `pvTwo` active
+// */
+// private fun payToSelected() {
+// with(binding) {
+// processOne.setCurrentCompleted()
+// processTwo.setCurrentActive()
+// btnPayTo.visibility = View.GONE
+// btnPayFrom.visibility = View.VISIBLE
+// payFromFieldWrapper.visibility = View.VISIBLE
+// payToFieldWrapper.isEnabled = false
+// }
+// }
+//
+// /**
+// * Checks validation of `spPayTo` [Spinner].
+// * Disables `spPayFrom` [Spinner] and sets `pvTwo` to completed and make
+// * `pvThree` active
+// */
+// private fun payFromSelected() {
+// if (payTo == payFrom) {
+// showToaster(getString(R.string.error_same_account_transfer))
+// return
+// }
+// with(binding) {
+// processTwo.setCurrentCompleted()
+// processThree.setCurrentActive()
+// btnPayFrom.visibility = View.GONE
+// amountFieldWrapper.visibility = View.VISIBLE
+// btnAmount.visibility = View.VISIBLE
+// payFromFieldWrapper.isEnabled = false
+// }
+// }
+//
+// /**
+// * Checks validation of `etAmount` [EditText].
+// * Disables `etAmount` and sets `pvThree` to completed and make
+// * `pvFour` active
+// */
+// private fun amountSet() {
+// if (binding.amountField.text.toString() == "") {
+// showToaster(getString(R.string.enter_amount))
+// return
+// }
+// if (binding.amountField.text.toString() == ".") {
+// showToaster(getString(R.string.invalid_amount))
+// return
+// }
+// if (binding.amountField.text.toString().toDouble() == 0.0) {
+// showToaster(getString(R.string.amount_greater_than_zero))
+// return
+// }
+// with(binding) {
+// processThree.setCurrentCompleted()
+// processFour.setCurrentActive()
+// btnAmount.visibility = View.GONE
+// tvEnterRemark.visibility = View.GONE
+// etRemark.visibility = View.VISIBLE
+// llReview.visibility = View.VISIBLE
+// amountFieldWrapper.isEnabled = false
+// }
+// }
+//
+// override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
+// super.onCreateOptionsMenu(menu, inflater)
+// inflater.inflate(R.menu.menu_transfer, menu)
+// Utils.setToolbarIconColor(activity, menu, R.color.white)
+// }
+//
+// override fun onOptionsItemSelected(item: MenuItem): Boolean {
+// if (item.itemId == R.id.menu_refresh_transfer) {
+// val transaction = fragmentManager?.beginTransaction()
+// val currFragment = activity?.supportFragmentManager
+// ?.findFragmentById(R.id.container)
+// if (currFragment != null) {
+// transaction?.detach(currFragment)
+// transaction?.attach(currFragment)
+// }
+// transaction?.commit()
+// }
+// return super.onOptionsItemSelected(item)
+// }
+//
+// override fun onDestroyView() {
+// super.onDestroyView()
+// hideProgress()
+// hideMifosProgressDialog()
+// _binding = null
+// }
+//
+// companion object {
+// /**
+// * Provides an instance of [SavingsMakeTransferFragment], use `transferType` as
+// * `Constants.TRANSFER_PAY_TO` when we want to deposit and
+// * `Constants.TRANSFER_PAY_FROM` when we want to make a transfer
+// *
+// * @param accountId Saving account Id
+// * @param transferType Type of transfer i.e. `Constants.TRANSFER_PAY_TO` or
+// * `Constants.TRANSFER_PAY_FROM`
+// * @return Instance of [SavingsMakeTransferFragment]
+// */
+// fun newInstance(accountId: Long?, transferType: String?): SavingsMakeTransferFragment {
+// val transferFragment = SavingsMakeTransferFragment()
+// val args = Bundle()
+// if (accountId != null) args.putLong(Constants.ACCOUNT_ID, accountId)
+// args.putString(Constants.TRANSFER_TYPE, transferType)
+// transferFragment.arguments = args
+// return transferFragment
+// }
+//
+// fun newInstance(
+// accountId: Long?,
+// outstandingBalance: Double?,
+// transferType: String?,
+// ): SavingsMakeTransferFragment {
+// val transferFragment = SavingsMakeTransferFragment()
+// val args = Bundle()
+// if (accountId != null) args.putLong(Constants.ACCOUNT_ID, accountId)
+// args.putString(Constants.TRANSFER_TYPE, transferType)
+// if (outstandingBalance != null) {
+// args.putDouble(
+// Constants.OUTSTANDING_BALANCE,
+// outstandingBalance,
+// )
+// }
+// args.putBoolean(Constants.LOAN_REPAYMENT, true)
+// transferFragment.arguments = args
+// return transferFragment
+// }
+// }
}
diff --git a/app/src/main/java/org/mifos/mobile/ui/third_party_transfer/ThirdPartyTransferFragment.kt b/app/src/main/java/org/mifos/mobile/ui/third_party_transfer/ThirdPartyTransferFragment.kt
index 4ac611c86..c5083de2f 100644
--- a/app/src/main/java/org/mifos/mobile/ui/third_party_transfer/ThirdPartyTransferFragment.kt
+++ b/app/src/main/java/org/mifos/mobile/ui/third_party_transfer/ThirdPartyTransferFragment.kt
@@ -36,6 +36,7 @@ import org.mifos.mobile.ui.beneficiary.presentation.BeneficiaryAddOptionsFragmen
import org.mifos.mobile.ui.enums.TransferType
import org.mifos.mobile.ui.fragments.TransferProcessFragment
import org.mifos.mobile.ui.fragments.base.BaseFragment
+import org.mifos.mobile.ui.transfer_process.TransferProcessComposeFragment
import org.mifos.mobile.utils.Constants
import org.mifos.mobile.utils.DateHelper
import org.mifos.mobile.utils.Network
@@ -207,7 +208,7 @@ class ThirdPartyTransferFragment : BaseFragment(), OnItemSelectedListener {
}
/**
- * Checks validation of `etRemark` and then opens [TransferProcessFragment] for
+ * Checks validation of `etRemark` and then opens [TransferProcessComposeFragment] for
* initiating the transfer
*/
private fun reviewTransfer() {
@@ -244,7 +245,7 @@ class ThirdPartyTransferFragment : BaseFragment(), OnItemSelectedListener {
transferPayload.fromAccountNumber = fromAccountOption?.accountNo
transferPayload.toAccountNumber = beneficiaryAccountOption?.accountNo
(activity as BaseActivity?)?.replaceFragment(
- TransferProcessFragment.newInstance(
+ TransferProcessComposeFragment.newInstance(
transferPayload,
TransferType.TPT,
),
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
new file mode 100644
index 000000000..5e0ae6d8c
--- /dev/null
+++ b/app/src/main/java/org/mifos/mobile/ui/transfer_process/TransferProcessComposeFragment.kt
@@ -0,0 +1,76 @@
+package org.mifos.mobile.ui.transfer_process
+
+import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import androidx.fragment.app.viewModels
+import dagger.hilt.android.AndroidEntryPoint
+import org.mifos.mobile.core.ui.component.mifosComposeView
+import org.mifos.mobile.models.payload.TransferPayload
+import org.mifos.mobile.ui.activities.base.BaseActivity
+import org.mifos.mobile.ui.enums.TransferType
+import org.mifos.mobile.ui.fragments.base.BaseFragment
+import org.mifos.mobile.utils.Constants
+import org.mifos.mobile.utils.ParcelableAndSerializableUtils.getCheckedParcelable
+import org.mifos.mobile.utils.ParcelableAndSerializableUtils.getCheckedSerializable
+
+/**
+ * Created by dilpreet on 1/7/17.
+ */
+@AndroidEntryPoint
+class TransferProcessComposeFragment : BaseFragment() {
+
+ private val viewModel: TransferProcessViewModel by viewModels()
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ if (activity != null) {
+ arguments?.getCheckedParcelable(TransferPayload::class.java, Constants.PAYLOAD)?.let {
+ viewModel.setContent(it)
+ }
+ (arguments?.getCheckedSerializable(TransferType::class.java, Constants.TRANSFER_TYPE) as TransferType).let {
+ viewModel.setTransferType(it)
+ }
+ }
+ }
+
+ override fun onResume() {
+ super.onResume()
+ (activity as? BaseActivity)?.hideToolbar()
+ }
+
+ override fun onCreateView(
+ inflater: LayoutInflater,
+ container: ViewGroup?,
+ savedInstanceState: Bundle?,
+ ): View {
+ return mifosComposeView(requireContext()) {
+ TransferProcessScreen(
+ navigateBack = { activity?.supportFragmentManager?.popBackStack() },
+ )
+ }
+ }
+
+ 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 [TransferProcessComposeFragment]
+ */
+ fun newInstance(
+ payload: TransferPayload?,
+ type: TransferType?
+ ): TransferProcessComposeFragment {
+ val fragment = TransferProcessComposeFragment()
+ val args = Bundle()
+ args.putParcelable(Constants.PAYLOAD, payload)
+ args.putSerializable(Constants.TRANSFER_TYPE, type)
+ fragment.arguments = args
+ return fragment
+ }
+ }
+}
diff --git a/app/src/main/java/org/mifos/mobile/ui/fragments/TransferProcessFragment.kt b/app/src/main/java/org/mifos/mobile/ui/transfer_process/TransferProcessFragment.kt
similarity index 94%
rename from app/src/main/java/org/mifos/mobile/ui/fragments/TransferProcessFragment.kt
rename to app/src/main/java/org/mifos/mobile/ui/transfer_process/TransferProcessFragment.kt
index 0d1b5fd81..a18f3854c 100644
--- a/app/src/main/java/org/mifos/mobile/ui/fragments/TransferProcessFragment.kt
+++ b/app/src/main/java/org/mifos/mobile/ui/transfer_process/TransferProcessFragment.kt
@@ -1,15 +1,17 @@
-package org.mifos.mobile.ui.fragments
+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 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
@@ -138,7 +140,7 @@ class TransferProcessFragment : BaseFragment() {
DateHelper.FORMAT_dd_MMMM_yyyy,
getTodayFormatted(),
),
- binding.tvAmount.text.toString().replace(",", "").toDoubleOrNull(),
+ binding.tvAmount.text.toString().toDouble(),
binding.tvRemark.text.toString(),
"dd MMMM yyyy",
"en",
@@ -225,3 +227,5 @@ class TransferProcessFragment : BaseFragment() {
}
}
}
+
+ */
diff --git a/app/src/main/java/org/mifos/mobile/ui/transfer_process/TransferProcessScreen.kt b/app/src/main/java/org/mifos/mobile/ui/transfer_process/TransferProcessScreen.kt
new file mode 100644
index 000000000..e3aa3be3b
--- /dev/null
+++ b/app/src/main/java/org/mifos/mobile/ui/transfer_process/TransferProcessScreen.kt
@@ -0,0 +1,254 @@
+package org.mifos.mobile.ui.transfer_process
+
+import android.widget.Toast
+import androidx.compose.foundation.BorderStroke
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.Spacer
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.height
+import androidx.compose.foundation.layout.padding
+import androidx.compose.material3.Button
+import androidx.compose.material3.ButtonDefaults
+import androidx.compose.material3.Card
+import androidx.compose.material3.CardDefaults
+import androidx.compose.material3.HorizontalDivider
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.getValue
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.platform.LocalContext
+import androidx.compose.ui.res.stringResource
+import androidx.compose.ui.text.font.FontWeight
+import androidx.compose.ui.tooling.preview.Preview
+import androidx.compose.ui.tooling.preview.PreviewParameter
+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
+import org.mifos.mobile.core.ui.theme.MifosMobileTheme
+import org.mifos.mobile.models.payload.TransferPayload
+import org.mifos.mobile.utils.Network
+
+
+@Composable
+fun TransferProcessScreen(
+ viewModel: TransferProcessViewModel = hiltViewModel(),
+ navigateBack: () -> Unit
+) {
+ val uiState by viewModel.transferUiState.collectAsStateWithLifecycle()
+ val payload by viewModel.transferPayload.collectAsStateWithLifecycle()
+
+ TransferProcessScreen(
+ uiState = uiState,
+ transfer = { viewModel.makeTransfer() },
+ payload = payload,
+ navigateBack = navigateBack,
+ )
+}
+
+@Composable
+fun TransferProcessScreen(
+ uiState: TransferProcessUiState,
+ payload: TransferPayload?,
+ transfer: () -> Unit,
+ navigateBack: () -> Unit,
+) {
+ val context = LocalContext.current
+
+ MFScaffold(
+ topBarTitleResId = R.string.transfer,
+ navigateBack = navigateBack,
+ scaffoldContent = { paddingValues ->
+ Box(modifier= Modifier
+ .padding(paddingValues)
+ .fillMaxSize()) {
+
+ TransferProcessContent(payload = payload, transfer = transfer, cancelClicked = navigateBack)
+
+ when (uiState) {
+ is TransferProcessUiState.Loading -> {
+ MifosProgressIndicatorOverlay()
+ }
+
+ is TransferProcessUiState.Success -> {
+ Toast.makeText(context, R.string.transferred_successfully, Toast.LENGTH_SHORT).show()
+ navigateBack()
+ }
+
+ is TransferProcessUiState.Error -> {
+ MifosErrorComponent(isNetworkConnected = Network.isConnected(context),)
+ }
+
+ is TransferProcessUiState.Initial -> Unit
+ }
+ }
+ }
+ )
+}
+
+@Composable
+fun TransferProcessContent(
+ payload: TransferPayload?,
+ transfer: () -> Unit,
+ cancelClicked: () -> Unit
+) {
+ Card(
+ modifier = Modifier
+ .fillMaxWidth()
+ .padding(16.dp),
+ colors = CardDefaults.cardColors(
+ containerColor = MaterialTheme.colorScheme.background
+ ),
+ border = BorderStroke(1.dp, Color.LightGray)
+ ) {
+ Column(
+ modifier = Modifier
+ .fillMaxWidth()
+ .padding(14.dp)
+ ) {
+ Column(
+ modifier = Modifier
+ .fillMaxWidth()
+ .padding(bottom = 12.dp),
+ horizontalAlignment = Alignment.CenterHorizontally
+ ) {
+ Text(
+ text = stringResource(id = R.string.amount),
+ color = MaterialTheme.colorScheme.primary
+ )
+
+ Text(text = payload?.transferAmount.toString())
+ }
+
+ Text(
+ text = stringResource(id = R.string.transfer_from_savings),
+ fontWeight = FontWeight(500),
+ color = Color.Gray
+ )
+
+ Text(
+ text = stringResource(id = R.string.pay_to),
+ modifier = Modifier.padding(top = 8.dp),
+ color = MaterialTheme.colorScheme.primary
+ )
+
+ Text(
+ text = payload?.fromAccountNumber.toString(),
+ modifier = Modifier.padding(top = 4.dp, bottom = 2.dp)
+ )
+
+ HorizontalDivider()
+
+ Text(
+ text = stringResource(id = R.string.pay_from),
+ modifier = Modifier.padding(top = 8.dp),
+ color = MaterialTheme.colorScheme.primary
+ )
+
+ Text(
+ text = payload?.fromAccountNumber.toString(),
+ modifier = Modifier.padding(top = 4.dp, bottom = 2.dp)
+ )
+
+ HorizontalDivider()
+
+ Text(
+ text = stringResource(id = R.string.date),
+ modifier = Modifier.padding(top = 8.dp),
+ color = MaterialTheme.colorScheme.primary
+ )
+
+ Text(
+ text = payload?.transferDate.toString(),
+ modifier = Modifier.padding(top = 4.dp, bottom = 2.dp)
+ )
+
+ HorizontalDivider()
+
+ Text(
+ text = stringResource(id = R.string.remark),
+ modifier = Modifier.padding(top = 8.dp),
+ color = MaterialTheme.colorScheme.primary
+ )
+
+ Text(
+ text = payload?.transferDescription.toString(),
+ modifier = Modifier.padding(top = 4.dp, bottom = 2.dp)
+ )
+
+ HorizontalDivider()
+
+ Spacer(modifier = Modifier.height(24.dp))
+
+ Row(
+ modifier = Modifier.fillMaxWidth(),
+ horizontalArrangement = Arrangement.End
+ ) {
+ Row(
+ horizontalArrangement = Arrangement.spacedBy(30.dp),
+ ) {
+ Button(
+ onClick = { cancelClicked() },
+ colors = ButtonDefaults.buttonColors(
+ containerColor = Color.Transparent,
+ contentColor = MaterialTheme.colorScheme.primary
+ )
+ ) {
+ Text(text = stringResource(id = R.string.cancel))
+ }
+ Button(
+ onClick = {
+ transfer()
+ }
+ ) {
+ Text(text = stringResource(id = R.string.transfer))
+ }
+ }
+ }
+ }
+ }
+}
+
+
+class UiStatesParameterProvider : PreviewParameterProvider {
+ override val values: Sequence
+ get() = sequenceOf(
+ TransferProcessUiState.Initial,
+ TransferProcessUiState.Loading,
+ TransferProcessUiState.Error(null),
+ TransferProcessUiState.Success
+ )
+}
+
+@Preview(showSystemUi = true)
+@Composable
+fun TransferProcessScreenPreview(
+ @PreviewParameter(UiStatesParameterProvider::class) transferUiState: TransferProcessUiState
+) {
+ MifosMobileTheme {
+ TransferProcessScreen(
+ uiState = transferUiState,
+ payload = TransferPayload(
+ transferAmount = 100.0,
+ fromAccountNumber = "1234567890",
+ toAccountNumber = "0987654321",
+ transferDate = "2021-09-01",
+ transferDescription = "Transfer Description"
+ ),
+ transfer = {},
+ navigateBack = {},
+ )
+ }
+}
+
diff --git a/app/src/main/java/org/mifos/mobile/ui/transfer_process/TransferProcessViewModel.kt b/app/src/main/java/org/mifos/mobile/ui/transfer_process/TransferProcessViewModel.kt
new file mode 100644
index 000000000..51a659bca
--- /dev/null
+++ b/app/src/main/java/org/mifos/mobile/ui/transfer_process/TransferProcessViewModel.kt
@@ -0,0 +1,72 @@
+package org.mifos.mobile.ui.transfer_process
+
+import androidx.lifecycle.ViewModel
+import androidx.lifecycle.viewModelScope
+import dagger.hilt.android.lifecycle.HiltViewModel
+import kotlinx.coroutines.flow.MutableStateFlow
+import kotlinx.coroutines.flow.StateFlow
+import kotlinx.coroutines.flow.catch
+import kotlinx.coroutines.launch
+import org.mifos.mobile.models.payload.TransferPayload
+import org.mifos.mobile.repositories.TransferRepository
+import org.mifos.mobile.ui.enums.TransferType
+import javax.inject.Inject
+
+@HiltViewModel
+class TransferProcessViewModel @Inject constructor(private val transferRepositoryImp: TransferRepository) :
+ ViewModel() {
+
+ private val _transferUiState = MutableStateFlow(TransferProcessUiState.Initial)
+ val transferUiState: StateFlow get() = _transferUiState
+
+ private var _transferPayload: MutableStateFlow = MutableStateFlow(null)
+ val transferPayload: StateFlow get() = _transferPayload
+
+ private var _transferType: MutableStateFlow = MutableStateFlow(null)
+ val transferType: StateFlow get() = _transferType
+
+ fun makeTransfer() {
+ transferPayload.value?.let { payload ->
+ viewModelScope.launch {
+ _transferUiState.value = TransferProcessUiState.Loading
+ transferRepositoryImp.makeTransfer(
+ fromOfficeId = payload.fromOfficeId,
+ fromClientId = payload.fromClientId,
+ fromAccountType = payload.fromAccountType,
+ fromAccountId = payload.fromAccountId,
+ toOfficeId = payload.toOfficeId,
+ toClientId = payload.toClientId,
+ toAccountType = payload.toAccountType,
+ toAccountId = payload.toAccountId,
+ transferDate = payload.transferDate,
+ transferAmount = payload.transferAmount,
+ transferDescription = payload.transferDescription,
+ dateFormat = payload.dateFormat,
+ locale = payload.locale,
+ fromAccountNumber = payload.fromAccountNumber,
+ toAccountNumber = payload.toAccountNumber,
+ transferType = transferType.value
+ ).catch { e ->
+ _transferUiState.value = TransferProcessUiState.Error(e.message)
+ }.collect {
+ _transferUiState.value = TransferProcessUiState.Success
+ }
+ }
+ }
+ }
+
+ fun setContent(payload: TransferPayload) {
+ _transferPayload.value = payload
+ }
+
+ fun setTransferType(transferType: TransferType) {
+ _transferType.value = transferType
+ }
+}
+
+sealed class TransferProcessUiState {
+ data object Initial : TransferProcessUiState()
+ data object Loading : TransferProcessUiState()
+ data object Success : TransferProcessUiState()
+ data class Error(val errorMessage: String?) : TransferProcessUiState()
+}
diff --git a/app/src/main/java/org/mifos/mobile/utils/TransferUiState.kt b/app/src/main/java/org/mifos/mobile/utils/TransferUiState.kt
index cc49abe2d..12dd07a9d 100644
--- a/app/src/main/java/org/mifos/mobile/utils/TransferUiState.kt
+++ b/app/src/main/java/org/mifos/mobile/utils/TransferUiState.kt
@@ -1,9 +1,2 @@
package org.mifos.mobile.utils
-sealed class TransferUiState {
- object Initial : TransferUiState()
- object Loading : TransferUiState()
- object TransferSuccess : TransferUiState()
- data class Error(val errorMessage: Throwable) : TransferUiState()
-}
-
diff --git a/app/src/main/java/org/mifos/mobile/viewModels/TransferProcessViewModel.kt b/app/src/main/java/org/mifos/mobile/viewModels/TransferProcessViewModel.kt
index 8bf0cdb94..d315324bf 100644
--- a/app/src/main/java/org/mifos/mobile/viewModels/TransferProcessViewModel.kt
+++ b/app/src/main/java/org/mifos/mobile/viewModels/TransferProcessViewModel.kt
@@ -1,66 +1,66 @@
-package org.mifos.mobile.viewModels
-
-import androidx.lifecycle.ViewModel
-import androidx.lifecycle.viewModelScope
-import dagger.hilt.android.lifecycle.HiltViewModel
-import kotlinx.coroutines.flow.MutableStateFlow
-import kotlinx.coroutines.flow.StateFlow
-import kotlinx.coroutines.flow.catch
-import kotlinx.coroutines.launch
-import org.mifos.mobile.repositories.TransferRepository
-import org.mifos.mobile.ui.enums.TransferType
-import org.mifos.mobile.utils.TransferUiState
-import javax.inject.Inject
-
-@HiltViewModel
-class TransferProcessViewModel @Inject constructor(private val transferRepositoryImp: TransferRepository) :
- ViewModel() {
-
- private val _transferUiState = MutableStateFlow(TransferUiState.Initial)
- val transferUiState: StateFlow get() = _transferUiState
-
- fun makeTransfer(
- fromOfficeId: Int?,
- fromClientId: Long?,
- fromAccountType: Int?,
- fromAccountId: Int?,
- toOfficeId: Int?,
- toClientId: Long?,
- toAccountType: Int?,
- toAccountId: Int?,
- transferDate: String?,
- transferAmount: Double?,
- transferDescription: String?,
- dateFormat: String = "dd MMMM yyyy",
- locale: String = "en",
- fromAccountNumber: String?,
- toAccountNumber: String?,
- transferType: TransferType?
- ) {
- viewModelScope.launch {
- _transferUiState.value = TransferUiState.Loading
- transferRepositoryImp.makeTransfer(
- fromOfficeId,
- fromClientId,
- fromAccountType,
- fromAccountId,
- toOfficeId,
- toClientId,
- toAccountType,
- toAccountId,
- transferDate,
- transferAmount,
- transferDescription,
- dateFormat,
- locale,
- fromAccountNumber,
- toAccountNumber,
- transferType
- ).catch { e ->
- _transferUiState.value = TransferUiState.Error(e)
- }.collect {
- _transferUiState.value = TransferUiState.TransferSuccess
- }
- }
- }
-}
\ No newline at end of file
+//package org.mifos.mobile.viewModels
+//
+//import androidx.lifecycle.ViewModel
+//import androidx.lifecycle.viewModelScope
+//import dagger.hilt.android.lifecycle.HiltViewModel
+//import kotlinx.coroutines.flow.MutableStateFlow
+//import kotlinx.coroutines.flow.StateFlow
+//import kotlinx.coroutines.flow.catch
+//import kotlinx.coroutines.launch
+//import org.mifos.mobile.repositories.TransferRepository
+//import org.mifos.mobile.ui.enums.TransferType
+//import org.mifos.mobile.utils.TransferUiState
+//import javax.inject.Inject
+//
+//@HiltViewModel
+//class TransferProcessViewModel @Inject constructor(private val transferRepositoryImp: TransferRepository) :
+// ViewModel() {
+//
+// private val _transferUiState = MutableStateFlow(TransferUiState.Initial)
+// val transferUiState: StateFlow get() = _transferUiState
+//
+// fun makeTransfer(
+// fromOfficeId: Int?,
+// fromClientId: Long?,
+// fromAccountType: Int?,
+// fromAccountId: Int?,
+// toOfficeId: Int?,
+// toClientId: Long?,
+// toAccountType: Int?,
+// toAccountId: Int?,
+// transferDate: String?,
+// transferAmount: Double?,
+// transferDescription: String?,
+// dateFormat: String = "dd MMMM yyyy",
+// locale: String = "en",
+// fromAccountNumber: String?,
+// toAccountNumber: String?,
+// transferType: TransferType?
+// ) {
+// viewModelScope.launch {
+// _transferUiState.value = TransferUiState.Loading
+// transferRepositoryImp.makeTransfer(
+// fromOfficeId,
+// fromClientId,
+// fromAccountType,
+// fromAccountId,
+// toOfficeId,
+// toClientId,
+// toAccountType,
+// toAccountId,
+// transferDate,
+// transferAmount,
+// transferDescription,
+// dateFormat,
+// locale,
+// fromAccountNumber,
+// toAccountNumber,
+// transferType
+// ).catch { e ->
+// _transferUiState.value = TransferUiState.Error(e)
+// }.collect {
+// _transferUiState.value = TransferUiState.TransferSuccess
+// }
+// }
+// }
+//}
\ No newline at end of file
diff --git a/app/src/test/java/org/mifos/mobile/viewModels/TransferProcessViewModelTest.kt b/app/src/test/java/org/mifos/mobile/viewModels/TransferProcessViewModelTest.kt
index c64cb7f0b..e7ab8a19e 100644
--- a/app/src/test/java/org/mifos/mobile/viewModels/TransferProcessViewModelTest.kt
+++ b/app/src/test/java/org/mifos/mobile/viewModels/TransferProcessViewModelTest.kt
@@ -17,6 +17,7 @@ import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
+import org.mifos.mobile.models.payload.TransferPayload
import org.mifos.mobile.repositories.TransferRepositoryImp
import org.mifos.mobile.ui.enums.TransferType
import org.mifos.mobile.util.RxSchedulersOverrideRule
@@ -26,6 +27,7 @@ import org.mockito.Mockito
import org.mockito.MockitoAnnotations
import org.mockito.junit.MockitoJUnitRunner
import retrofit2.Response
+import org.mifos.mobile.ui.transfer_process.TransferProcessViewModel
@RunWith(MockitoJUnitRunner::class)
class TransferProcessViewModelTest {
@@ -63,11 +65,12 @@ class TransferProcessViewModelTest {
).thenReturn(flowOf(responseBody))
viewModel.transferUiState.test {
viewModel.makeTransfer(
- 1, 2, 3,
- 4, 5, 6, 7,
- 8, "06 July 2023 ", 100.0, "Transfer",
- "dd MMMM yyyy", "en", "0000001", "0000002",
- TransferType.SELF
+ TransferPayload(
+ 1, 2, 3,
+ 4, 5, 6, 7,
+ 8, "06 July 2023 ", 100.0, "Transfer",
+ "dd MMMM yyyy", "en", "0000001", "0000002"
+ )
)
assertEquals(TransferUiState.Initial, awaitItem())
assertEquals(TransferUiState.TransferSuccess, awaitItem())
@@ -92,11 +95,12 @@ class TransferProcessViewModelTest {
viewModel.transferUiState.test {
viewModel.makeTransfer(
- 1, 2, 3,
- 4, 5, 6, 7,
- 8, "06 July 2023 ", 100.0, "Transfer",
- "dd MMMM yyyy", "en", "0000001", "0000002",
- TransferType.SELF
+ TransferPayload(
+ 1, 2, 3,
+ 4, 5, 6, 7,
+ 8, "06 July 2023 ", 100.0, "Transfer",
+ "dd MMMM yyyy", "en", "0000001", "0000002"
+ )
)
assertEquals(TransferUiState.Initial, awaitItem())
assertEquals(TransferUiState.Error(error), awaitItem())