From 938f83316898492b0b585e0d1db79853a1c6a151 Mon Sep 17 00:00:00 2001 From: kmanikanta335 <118070186+kmanikanta335@users.noreply.github.com> Date: Sat, 11 Nov 2023 22:39:42 +0530 Subject: [PATCH] fix #1075: ui layout for loan application fragment fix #1075: ui layout for loan application fragment --- .../ui/fragments/LoanApplicationFragment.kt | 38 +++++++++++-------- .../layout/fragment_add_loan_application.xml | 4 +- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/org/mifos/mobile/ui/fragments/LoanApplicationFragment.kt b/app/src/main/java/org/mifos/mobile/ui/fragments/LoanApplicationFragment.kt index 9b616a401..0a8cfb0a2 100644 --- a/app/src/main/java/org/mifos/mobile/ui/fragments/LoanApplicationFragment.kt +++ b/app/src/main/java/org/mifos/mobile/ui/fragments/LoanApplicationFragment.kt @@ -10,6 +10,7 @@ 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 @@ -61,7 +62,7 @@ class LoanApplicationFragment : BaseFragment() { private var submittedDate: String? = null private var isDisbursementDate = false private var isLoanUpdatePurposesInitialization = true - + private var sweetUIErrorHandler: SweetUIErrorHandler? = null /** * Used when we want to apply for a Loan * @@ -114,6 +115,7 @@ class LoanApplicationFragment : BaseFragment() { savedInstanceState: Bundle?, ): View { _binding = FragmentAddLoanApplicationBinding.inflate(inflater, container, false) + sweetUIErrorHandler = SweetUIErrorHandler(activity, binding.root) showUserInterface() if (savedInstanceState == null) { loadLoanTemplate() @@ -197,7 +199,7 @@ class LoanApplicationFragment : BaseFragment() { setTvDisbursementOnDate() } - llError.ivStatus.setOnClickListener { + binding.layoutError.btnTryAgain.setOnClickListener { onRetry() } } @@ -322,11 +324,16 @@ class LoanApplicationFragment : BaseFragment() { * Retries to fetch [LoanTemplate] by calling `loadLoanTemplate()` */ private fun onRetry() { - binding.apply { - llError.root.visibility = View.GONE - llAddLoan.visibility = View.VISIBLE + if (Network.isConnected(context)) { + sweetUIErrorHandler?.hideSweetErrorLayoutUI( + binding.viewFlipper, + binding.layoutError.root, + ) + loadLoanTemplate() + } else { + Toaster.show(binding.viewFlipper, getString(R.string.internet_not_connected)) } - loadLoanTemplate() + } /** @@ -546,16 +553,17 @@ class LoanApplicationFragment : BaseFragment() { * @param message Error message that tells the user about the problem. */ fun showError(message: String?) { - with(binding) { - if (!Network.isConnected(activity)) { - llError.ivStatus.setImageResource(R.drawable.ic_error_black_24dp) - llError.tvStatus.text = getString(R.string.internet_not_connected) - llAddLoan.visibility = View.GONE - llError.root.visibility = View.VISIBLE - } else { - Toaster.show(root, message) - } + if (!Network.isConnected(context)) { + sweetUIErrorHandler?.showSweetNoInternetUI(binding.viewFlipper, binding.layoutError.root) + } else { + sweetUIErrorHandler?.showSweetErrorUI( + message, + binding.viewFlipper, + binding.layoutError.root, + ) + Toaster.show(binding.viewFlipper, message) } + hideProgress() } fun showProgress() { diff --git a/app/src/main/res/layout/fragment_add_loan_application.xml b/app/src/main/res/layout/fragment_add_loan_application.xml index a516de8eb..c776a06cd 100644 --- a/app/src/main/res/layout/fragment_add_loan_application.xml +++ b/app/src/main/res/layout/fragment_add_loan_application.xml @@ -181,8 +181,8 @@