Skip to content

Commit

Permalink
refactor #2511: migrated savings account detail screen to compose
Browse files Browse the repository at this point in the history
  • Loading branch information
AvneetSingh2001 committed Feb 15, 2024
1 parent 4b19bbc commit 1a7dfd2
Show file tree
Hide file tree
Showing 40 changed files with 1,186 additions and 578 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import org.mifos.mobile.utils.UserDetailUiState
import org.mifos.mobile.utils.fcm.RegistrationIntentService
import org.mifos.mobile.ui.user_profile.UserDetailViewModel
import org.mifos.mobile.ui.user_profile.UserProfileActivity
import org.mifos.mobile.utils.ParcelableAndSerializableUtils.getCheckedParcelable
import javax.inject.Inject

/**
Expand Down Expand Up @@ -96,7 +97,7 @@ class HomeActivity :
viewModel.userImage
showUserImage(null)
} else {
client = savedInstanceState.getParcelable(Constants.USER_DETAILS)
client = savedInstanceState.getCheckedParcelable(Client::class.java, Constants.USER_DETAILS)
viewModel.setUserProfile(preferencesHelper?.userProfileImage)
showUserDetails(client)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.mifos.mobile.ui.activities

import android.os.Bundle
import android.view.View
import org.mifos.mobile.R
import org.mifos.mobile.databinding.ActivityContainerBinding
import org.mifos.mobile.ui.activities.base.BaseActivity
import org.mifos.mobile.ui.fragments.SavingAccountsDetailFragment
import org.mifos.mobile.ui.savings_account.SavingAccountsDetailFragment
import org.mifos.mobile.utils.Constants

/**
Expand Down Expand Up @@ -35,6 +36,18 @@ class SavingsAccountContainerActivity : BaseActivity() {
}
}

fun hideToolbar() {
binding.apply {
toolbar?.visibility = View.GONE
}
}

fun showToolbar() {
binding.apply {
toolbar?.visibility = View.VISIBLE
}
}

companion object {
var transferSuccess = false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import org.mifos.mobile.ui.adapters.SavingAccountsListAdapter
import org.mifos.mobile.ui.adapters.ShareAccountsListAdapter
import org.mifos.mobile.ui.fragments.base.BaseFragment
import org.mifos.mobile.utils.*
import org.mifos.mobile.utils.ParcelableAndSerializableUtils.getCheckedArrayListFromParcelable
import org.mifos.mobile.viewModels.AccountsViewModel
import java.util.*

Expand Down Expand Up @@ -137,22 +138,27 @@ class AccountsFragment : BaseFragment(), OnRefreshListener {
when (accountType) {
Constants.SAVINGS_ACCOUNTS -> {
val savingAccountList: List<SavingAccount?> =
savedInstanceState.getParcelableArrayList(Constants.SAVINGS_ACCOUNTS)
savedInstanceState.getCheckedArrayListFromParcelable(
SavingAccount::class.java,
Constants.SAVINGS_ACCOUNTS
)
?: listOf()
showSavingsAccounts(savingAccountList)
}

Constants.LOAN_ACCOUNTS -> {
val loanAccountList: List<LoanAccount?> =
savedInstanceState.getParcelableArrayList(
savedInstanceState.getCheckedArrayListFromParcelable(
LoanAccount::class.java,
Constants.LOAN_ACCOUNTS,
) ?: listOf()
showLoanAccounts(loanAccountList)
}

Constants.SHARE_ACCOUNTS -> {
val shareAccountList: List<ShareAccount?> =
savedInstanceState.getParcelableArrayList(
savedInstanceState.getCheckedArrayListFromParcelable(
ShareAccount::class.java,
Constants.SHARE_ACCOUNTS,
) ?: listOf()
showShareAccounts(shareAccountList)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import org.mifos.mobile.ui.enums.GuarantorState
import org.mifos.mobile.ui.fragments.base.BaseFragment
import org.mifos.mobile.utils.Constants
import org.mifos.mobile.utils.GuarantorUiState
import org.mifos.mobile.utils.ParcelableAndSerializableUtils.getCheckedParcelable
import org.mifos.mobile.utils.ParcelableAndSerializableUtils.getCheckedSerializable
import org.mifos.mobile.utils.RxBus.publish
import org.mifos.mobile.utils.RxEvent.AddGuarantorEvent
import org.mifos.mobile.utils.RxEvent.UpdateGuarantorEvent
Expand Down Expand Up @@ -51,16 +53,12 @@ class AddGuarantorFragment : BaseFragment() {
super.onCreate(savedInstanceState)
if (arguments != null) {
loanId = arguments?.getLong(Constants.LOAN_ID)
guarantorState = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
arguments?.getSerializable(Constants.GUARANTOR_STATE, GuarantorState::class.java)
} else {
arguments?.getSerializable(Constants.GUARANTOR_STATE) as GuarantorState?
}
payload = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
arguments?.getParcelable(Constants.PAYLOAD, GuarantorPayload::class.java)
} else {
arguments?.getParcelable(Constants.PAYLOAD) as GuarantorPayload?
}
guarantorState = requireArguments().getCheckedSerializable(
GuarantorState::class.java,
Constants.GUARANTOR_STATE
) as GuarantorState
payload =
arguments?.getCheckedParcelable(GuarantorPayload::class.java, Constants.PAYLOAD)
index = arguments?.getInt(Constants.INDEX)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import org.mifos.mobile.ui.fragments.base.BaseFragment
import org.mifos.mobile.utils.BeneficiaryUiState
import org.mifos.mobile.utils.Constants
import org.mifos.mobile.utils.Network
import org.mifos.mobile.utils.ParcelableAndSerializableUtils.getCheckedParcelable
import org.mifos.mobile.utils.ParcelableAndSerializableUtils.getCheckedSerializable
import org.mifos.mobile.utils.Toaster
import org.mifos.mobile.viewModels.BeneficiaryApplicationViewModel

Expand All @@ -47,16 +49,24 @@ class BeneficiaryApplicationFragment : BaseFragment() {
super.onCreate(savedInstanceState)
setToolbarTitle(getString(R.string.add_beneficiary))
if (arguments != null) {
beneficiaryState = requireArguments()
.getSerializable(Constants.BENEFICIARY_STATE) as BeneficiaryState
beneficiaryState = requireArguments().getCheckedSerializable(
BeneficiaryState::class.java,
Constants.BENEFICIARY_STATE
) as BeneficiaryState
when (beneficiaryState) {
BeneficiaryState.UPDATE -> {
beneficiary = arguments?.getParcelable(Constants.BENEFICIARY)
beneficiary = arguments?.getCheckedParcelable(
Beneficiary::class.java,
Constants.BENEFICIARY
)
setToolbarTitle(getString(R.string.update_beneficiary))
}

BeneficiaryState.CREATE_QR -> {
beneficiary = arguments?.getParcelable(Constants.BENEFICIARY)
beneficiary = arguments?.getCheckedParcelable(
Beneficiary::class.java,
Constants.BENEFICIARY
)
setToolbarTitle(getString(R.string.add_beneficiary))
}

Expand Down Expand Up @@ -140,7 +150,12 @@ class BeneficiaryApplicationFragment : BaseFragment() {
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
if (savedInstanceState != null) {
showBeneficiaryTemplate(savedInstanceState.getParcelable<Parcelable>(Constants.TEMPLATE) as BeneficiaryTemplate)
showBeneficiaryTemplate(
savedInstanceState.getCheckedParcelable(
BeneficiaryTemplate::class.java,
Constants.TEMPLATE
)
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.mifos.mobile.utils.BeneficiaryUiState
import org.mifos.mobile.utils.Constants
import org.mifos.mobile.utils.CurrencyUtil
import org.mifos.mobile.utils.MaterialDialog
import org.mifos.mobile.utils.ParcelableAndSerializableUtils.getCheckedParcelable
import org.mifos.mobile.utils.Toaster
import org.mifos.mobile.viewModels.BeneficiaryDetailViewModel

Expand All @@ -42,7 +43,8 @@ class BeneficiaryDetailFragment : BaseFragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (arguments != null) {
beneficiary = arguments?.getParcelable(Constants.BENEFICIARY)
beneficiary =
arguments?.getCheckedParcelable(Beneficiary::class.java, Constants.BENEFICIARY)
}
setHasOptionsMenu(true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import org.mifos.mobile.utils.BeneficiaryUiState
import org.mifos.mobile.utils.Constants
import org.mifos.mobile.utils.DividerItemDecoration
import org.mifos.mobile.utils.Network
import org.mifos.mobile.utils.ParcelableAndSerializableUtils.getCheckedArrayListFromParcelable
import org.mifos.mobile.viewModels.BeneficiaryListViewModel

/**
Expand Down Expand Up @@ -114,7 +115,10 @@ class BeneficiaryListFragment : BaseFragment(), OnRefreshListener {
super.onActivityCreated(savedInstanceState)
if (savedInstanceState != null) {
val beneficiaries: List<Beneficiary?> =
savedInstanceState.getParcelableArrayList(Constants.BENEFICIARY) ?: listOf()
savedInstanceState.getCheckedArrayListFromParcelable(
Beneficiary::class.java,
Constants.BENEFICIARY
) ?: listOf()
showBeneficiaryList(beneficiaries)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import org.mifos.mobile.ui.adapters.ViewPagerAdapter
import org.mifos.mobile.ui.enums.AccountType
import org.mifos.mobile.ui.fragments.base.BaseFragment
import org.mifos.mobile.utils.Constants
import org.mifos.mobile.utils.ParcelableAndSerializableUtils.getCheckedSerializable
import org.mifos.mobile.utils.StatusUtils
import org.mifos.mobile.viewModels.AccountsViewModel
import javax.inject.Inject
Expand All @@ -56,7 +57,10 @@ class ClientAccountsFragment : BaseFragment() {
super.onCreate(savedInstanceState)
setHasOptionsMenu(true)
if (arguments != null) {
accountType = arguments?.getSerializable(Constants.ACCOUNT_TYPE) as AccountType
accountType = arguments?.getCheckedSerializable(
AccountType::class.java,
Constants.ACCOUNT_TYPE
) as AccountType
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ import kotlinx.coroutines.launch
import org.mifos.mobile.R
import org.mifos.mobile.databinding.FragmentClientChargeBinding
import org.mifos.mobile.models.Charge
import org.mifos.mobile.ui.activities.SavingsAccountContainerActivity
import org.mifos.mobile.ui.adapters.ClientChargeAdapter
import org.mifos.mobile.ui.enums.ChargeType
import org.mifos.mobile.ui.fragments.base.BaseFragment
import org.mifos.mobile.utils.ClientChargeUiState
import org.mifos.mobile.utils.Constants
import org.mifos.mobile.utils.Network
import org.mifos.mobile.utils.ParcelableAndSerializableUtils.getCheckedArrayListFromParcelable
import org.mifos.mobile.utils.ParcelableAndSerializableUtils.getCheckedSerializable
import org.mifos.mobile.utils.Toaster
import org.mifos.mobile.viewModels.ClientChargeViewModel

Expand All @@ -46,9 +49,13 @@ class ClientChargeFragment : BaseFragment() {
private var sweetUIErrorHandler: SweetUIErrorHandler? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
(activity as? SavingsAccountContainerActivity)?.showToolbar()
if (arguments != null) {
id = arguments?.getLong(Constants.CLIENT_ID)
chargeType = arguments?.getSerializable(Constants.CHARGE_TYPE) as ChargeType
chargeType = arguments?.getCheckedSerializable(
ChargeType::class.java,
Constants.CHARGE_TYPE
) as ChargeType
}
}

Expand Down Expand Up @@ -121,8 +128,10 @@ class ClientChargeFragment : BaseFragment() {
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
if (savedInstanceState != null) {
val charges: List<Charge?> =
savedInstanceState.getParcelableArrayList(Constants.CHARGES) ?: listOf()
val charges: List<Charge?> = savedInstanceState.getCheckedArrayListFromParcelable(
Charge::class.java,
Constants.CHARGES
) ?: listOf()
showClientCharges(charges)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.mifos.mobile.ui.activities.base.BaseActivity
import org.mifos.mobile.ui.enums.GuarantorState
import org.mifos.mobile.ui.fragments.base.BaseFragment
import org.mifos.mobile.utils.*
import org.mifos.mobile.utils.ParcelableAndSerializableUtils.getCheckedParcelable
import org.mifos.mobile.utils.RxBus.listen
import org.mifos.mobile.utils.RxBus.publish
import org.mifos.mobile.utils.RxEvent.DeleteGuarantorEvent
Expand Down Expand Up @@ -44,7 +45,7 @@ class GuarantorDetailFragment : BaseFragment() {
super.onCreate(savedInstanceState)
if (arguments != null) {
loanId = arguments?.getLong(Constants.LOAN_ID)
payload = arguments?.getParcelable(Constants.GUARANTOR_DETAILS)
payload = arguments?.getCheckedParcelable(GuarantorPayload::class.java, Constants.GUARANTOR_DETAILS)
index = arguments?.getInt(Constants.INDEX)
guarantorId = payload?.id
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.mifos.mobile.models.accounts.loan.LoanWithAssociations
import org.mifos.mobile.ui.fragments.base.BaseFragment
import org.mifos.mobile.utils.Constants
import org.mifos.mobile.utils.CurrencyUtil
import org.mifos.mobile.utils.ParcelableAndSerializableUtils.getCheckedParcelable

/*
~This project is licensed under the open source MPL V2.
Expand All @@ -26,7 +27,7 @@ class LoanAccountSummaryFragment : BaseFragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (arguments != null) {
loanWithAssociations = arguments?.getParcelable(Constants.LOAN_ACCOUNT)
loanWithAssociations = arguments?.getCheckedParcelable(LoanWithAssociations::class.java, Constants.LOAN_ACCOUNT)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.mifos.mobile.ui.fragments.base.BaseFragment
import org.mifos.mobile.utils.Constants
import org.mifos.mobile.utils.LoanUiState
import org.mifos.mobile.utils.Network
import org.mifos.mobile.utils.ParcelableAndSerializableUtils.getCheckedParcelable
import org.mifos.mobile.viewModels.LoanAccountTransactionViewModel
import javax.inject.Inject

Expand Down Expand Up @@ -78,8 +79,12 @@ class LoanAccountTransactionFragment : BaseFragment() {
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
if (savedInstanceState != null) {
showLoanTransactions(savedInstanceState.getParcelable<Parcelable>(Constants.LOAN_ACCOUNT) as LoanWithAssociations)
}
showLoanTransactions(
savedInstanceState.getCheckedParcelable(
LoanWithAssociations::class.java,
Constants.LOAN_ACCOUNT
)
) }
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ 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.LoanUiState
import org.mifos.mobile.utils.ParcelableAndSerializableUtils.getCheckedParcelable
import org.mifos.mobile.utils.Toaster
import org.mifos.mobile.viewModels.LoanAccountWithdrawViewModel

Expand All @@ -36,7 +37,7 @@ class LoanAccountWithdrawFragment : BaseFragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (arguments != null) {
loanWithAssociations = arguments?.getParcelable(Constants.LOAN_ACCOUNT)
loanWithAssociations = arguments?.getCheckedParcelable(LoanWithAssociations::class.java, Constants.LOAN_ACCOUNT)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.mifos.mobile.ui.enums.ChargeType
import org.mifos.mobile.ui.enums.LoanState
import org.mifos.mobile.ui.fragments.base.BaseFragment
import org.mifos.mobile.utils.*
import org.mifos.mobile.utils.ParcelableAndSerializableUtils.getCheckedParcelable
import org.mifos.mobile.viewModels.LoanAccountsDetailViewModel
import javax.inject.Inject

Expand Down Expand Up @@ -78,7 +79,7 @@ class LoanAccountsDetailFragment : BaseFragment() {
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
if (savedInstanceState != null) {
showLoanAccountsDetail(savedInstanceState.getParcelable<Parcelable>(Constants.LOAN_ACCOUNT) as LoanWithAssociations)
showLoanAccountsDetail(savedInstanceState.getCheckedParcelable(LoanWithAssociations::class.java, Constants.LOAN_ACCOUNT))
}
}

Expand Down
Loading

0 comments on commit 1a7dfd2

Please sign in to comment.