Skip to content

Commit

Permalink
Fix: #2395 Added SDK Checks for Deprecated Parcelable and Serializabl…
Browse files Browse the repository at this point in the history
…e functions
  • Loading branch information
SekhGulamMainuddin committed Oct 15, 2023
1 parent 2c403ba commit aba69f7
Show file tree
Hide file tree
Showing 35 changed files with 440 additions and 253 deletions.
10 changes: 6 additions & 4 deletions app/src/main/java/org/mifos/mobile/ui/activities/HomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.content.Intent
import android.content.IntentFilter
import android.graphics.Bitmap
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.os.Handler
import android.util.Log
Expand Down Expand Up @@ -37,6 +38,7 @@ import org.mifos.mobile.ui.enums.ChargeType
import org.mifos.mobile.ui.fragments.*
import org.mifos.mobile.ui.getThemeAttributeColor
import org.mifos.mobile.utils.Constants
import org.mifos.mobile.utils.ParcelableAndSerializableUtils.getCheckedParcelable
import org.mifos.mobile.utils.TextDrawable
import org.mifos.mobile.utils.Toaster
import org.mifos.mobile.utils.UserDetailUiState
Expand Down Expand Up @@ -70,7 +72,7 @@ class HomeActivity :
private var isReceiverRegistered = false
var checkedItem = 0
private set
var doubleBackToExitPressedOnce = false
private var doubleBackToExitPressedOnce = false
public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityHomeBinding.inflate(layoutInflater)
Expand All @@ -92,7 +94,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 Expand Up @@ -307,7 +309,7 @@ class HomeActivity :
*
* @param client Contains details about the client
*/
fun showUserDetails(client: Client?) {
private fun showUserDetails(client: Client?) {
this.client = client
preferencesHelper?.clientName = client?.displayName
tvUsername?.text = client?.displayName
Expand All @@ -318,7 +320,7 @@ class HomeActivity :
*
* @param bitmap UserProfile Picture
*/
fun showUserImage(bitmap: Bitmap?) {
private fun showUserImage(bitmap: Bitmap?) {
if (bitmap != null) {
runOnUiThread {
userProfileBitmap = bitmap
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.mifos.mobile.ui.fragments

import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.os.Parcelable
import android.view.LayoutInflater
Expand Down Expand Up @@ -28,6 +29,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,24 +139,32 @@ 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()
)
?: listOf()

showLoanAccounts(loanAccountList)
}

Constants.SHARE_ACCOUNTS -> {
val shareAccountList: List<ShareAccount?> =
savedInstanceState.getParcelableArrayList(
savedInstanceState.getCheckedArrayListFromParcelable(
ShareAccount::class.java,
Constants.SHARE_ACCOUNTS,
) ?: listOf()
)
?: listOf()
showShareAccounts(shareAccountList)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,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,8 +53,12 @@ class AddGuarantorFragment : BaseFragment() {
if (arguments != null) {
loanId = arguments?.getLong(Constants.LOAN_ID)
guarantorState = requireArguments()
.getSerializable(Constants.GUARANTOR_STATE) as GuarantorState
payload = arguments?.getParcelable(Constants.PAYLOAD)
.getCheckedSerializable(
GuarantorState::class.java,
Constants.GUARANTOR_STATE
) as GuarantorState
payload =
arguments?.getCheckedParcelable(GuarantorPayload::class.java, Constants.PAYLOAD)
index = arguments?.getInt(Constants.INDEX)
}
}
Expand Down Expand Up @@ -83,22 +89,27 @@ class AddGuarantorFragment : BaseFragment() {
hideProgress()
showError(it.message)
}

is GuarantorUiState.ShowGuarantorApplication -> {
hideProgress()
showGuarantorApplication(it.template)
}

is GuarantorUiState.ShowGuarantorUpdation -> {
hideProgress()
showGuarantorUpdation(it.template)
}

is GuarantorUiState.SubmittedSuccessfully -> {
hideProgress()
submittedSuccessfully(it.message, it.payload)
}

is GuarantorUiState.GuarantorUpdatedSuccessfully -> {
hideProgress()
updatedSuccessfully(it.message)
}

else -> throw IllegalStateException("Undesired $it")
}
}
Expand All @@ -115,7 +126,7 @@ class AddGuarantorFragment : BaseFragment() {
viewModel.getGuarantorTemplate(guarantorState, loanId)
}

fun onSubmit() {
private fun onSubmit() {
with(binding) {
tilFirstName.isErrorEnabled = false
tilLastName.isErrorEnabled = false
Expand Down Expand Up @@ -199,12 +210,12 @@ class AddGuarantorFragment : BaseFragment() {
_binding = null
}

fun showGuarantorApplication(template: GuarantorTemplatePayload?) {
private fun showGuarantorApplication(template: GuarantorTemplatePayload?) {
this.template = template
setUpSpinner()
}

fun showGuarantorUpdation(template: GuarantorTemplatePayload?) {
private fun showGuarantorUpdation(template: GuarantorTemplatePayload?) {
this.template = template
setUpSpinner()
with(binding) {
Expand All @@ -231,13 +242,13 @@ class AddGuarantorFragment : BaseFragment() {
}
}

fun updatedSuccessfully(message: String?) {
private fun updatedSuccessfully(message: String?) {
Toast.makeText(context, message, Toast.LENGTH_SHORT).show()
publish(UpdateGuarantorEvent(guarantorApplicationPayload, index))
activity?.supportFragmentManager?.popBackStack()
}

fun submittedSuccessfully(message: String?, payload: GuarantorApplicationPayload?) {
private fun submittedSuccessfully(message: String?, payload: GuarantorApplicationPayload?) {
Toast.makeText(context, message, Toast.LENGTH_SHORT).show()
publish(AddGuarantorEvent(payload, index))
activity?.supportFragmentManager?.popBackStack()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,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 @@ -45,15 +47,24 @@ class BeneficiaryApplicationFragment : BaseFragment() {
setToolbarTitle(getString(R.string.add_beneficiary))
if (arguments != null) {
beneficiaryState = requireArguments()
.getSerializable(Constants.BENEFICIARY_STATE) as BeneficiaryState
.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 @@ -89,22 +100,27 @@ class BeneficiaryApplicationFragment : BaseFragment() {
hideProgress()
showError(getString(it.message))
}

is BeneficiaryUiState.SetVisibility -> {
hideProgress()
setVisibility(it.visibility)
}

is BeneficiaryUiState.ShowBeneficiaryTemplate -> {
hideProgress()
showBeneficiaryTemplate(it.beneficiaryTemplate)
}

is BeneficiaryUiState.CreatedSuccessfully -> {
hideProgress()
showBeneficiaryCreatedSuccessfully()
}

is BeneficiaryUiState.UpdatedSuccessfully -> {
hideProgress()
showBeneficiaryUpdatedSuccessfully()
}

else -> throw IllegalStateException("Undesired $it")
}
}
Expand All @@ -127,7 +143,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 All @@ -151,7 +172,7 @@ class BeneficiaryApplicationFragment : BaseFragment() {
*
* @param beneficiaryTemplate [BeneficiaryTemplate] fetched from server
*/
fun showBeneficiaryTemplate(beneficiaryTemplate: BeneficiaryTemplate?) {
private fun showBeneficiaryTemplate(beneficiaryTemplate: BeneficiaryTemplate?) {
this.beneficiaryTemplate = beneficiaryTemplate
for ((_, _, value) in beneficiaryTemplate?.accountTypeOptions!!) {
listAccountType.add(value)
Expand Down Expand Up @@ -280,7 +301,7 @@ class BeneficiaryApplicationFragment : BaseFragment() {
* Displays a {@link Snackbar} on successfully creation of
* Beneficiary and pops fragments in order to go back to [BeneficiaryListFragment]
*/
fun showBeneficiaryCreatedSuccessfully() {
private fun showBeneficiaryCreatedSuccessfully() {
Toaster.show(binding.tilTransferLimit, getString(R.string.beneficiary_created_successfully))
activity?.finish()
}
Expand All @@ -289,7 +310,7 @@ class BeneficiaryApplicationFragment : BaseFragment() {
* Displays a {@link Snackbar} on successfully updation of
* Beneficiary and pops fragments in order to go back to [BeneficiaryListFragment]
*/
fun showBeneficiaryUpdatedSuccessfully() {
private fun showBeneficiaryUpdatedSuccessfully() {
Toaster.show(binding.root, getString(R.string.beneficiary_updated_successfully))
activity?.supportFragmentManager?.popBackStack()
activity?.supportFragmentManager?.popBackStack()
Expand All @@ -316,7 +337,7 @@ class BeneficiaryApplicationFragment : BaseFragment() {
}
}

fun setVisibility(state: Int) {
private fun setVisibility(state: Int) {
binding.llApplicationBeneficiary.visibility = state
}

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.BeneficiaryState
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.BeneficiaryDetailViewModel

/**
Expand All @@ -34,7 +35,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 All @@ -61,10 +63,12 @@ class BeneficiaryDetailFragment : BaseFragment() {
hideProgress()
showError(getString(it.message))
}

is BeneficiaryUiState.DeletedSuccessfully -> {
hideProgress()
showBeneficiaryDeletedSuccessfully()
}

else -> throw IllegalStateException("Undesired $it")
}
}
Expand Down Expand Up @@ -122,7 +126,7 @@ class BeneficiaryDetailFragment : BaseFragment() {
* Shows a {@link Snackbar} on successfull deletion of a
* Beneficiary and then pops current fragment
*/
fun showBeneficiaryDeletedSuccessfully() {
private fun showBeneficiaryDeletedSuccessfully() {
Toaster.show(binding.root, getString(R.string.beneficiary_deleted_successfully))
activity?.supportFragmentManager?.popBackStack()
}
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.DividerItemDecoration
import org.mifos.mobile.utils.Network
import org.mifos.mobile.utils.ParcelableAndSerializableUtils.getCheckedArrayListFromParcelable
import org.mifos.mobile.viewModels.BeneficiaryListViewModel

/**
Expand Down Expand Up @@ -68,10 +69,12 @@ class BeneficiaryListFragment : BaseFragment(), OnRefreshListener {
hideProgress()
showError(getString(it.message))
}

is BeneficiaryUiState.ShowBeneficiaryList -> {
hideProgress()
showBeneficiaryList(it.beneficiaries)
}

else -> throw IllegalStateException("Undesired $it")
}
}
Expand Down Expand Up @@ -102,7 +105,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
Loading

0 comments on commit aba69f7

Please sign in to comment.