diff --git a/common/src/main/java/org/dash/wallet/common/ui/enter_amount/EnterAmountFragment.kt b/common/src/main/java/org/dash/wallet/common/ui/enter_amount/EnterAmountFragment.kt index 53ccc082eb..66c8c27a87 100644 --- a/common/src/main/java/org/dash/wallet/common/ui/enter_amount/EnterAmountFragment.kt +++ b/common/src/main/java/org/dash/wallet/common/ui/enter_amount/EnterAmountFragment.kt @@ -34,6 +34,7 @@ import androidx.core.view.isVisible import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels import androidx.lifecycle.lifecycleScope +import androidx.lifecycle.withStarted import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.launch import org.dash.wallet.common.money.Coin @@ -173,6 +174,7 @@ class EnterAmountFragment : Fragment(R.layout.fragment_enter_amount) { binding.keyboardView.onKeyboardActionListener = keyboardActionListener binding.continueBtn.setOnClickListener { + if (binding.continueProgress.isVisible) return@setOnClickListener val dashAmount = binding.amountView.dashAmount val fiatAmount = binding.amountView.fiatAmount viewModel.onContinueEvent.value = Pair(dashAmount, fiatAmount) @@ -189,6 +191,7 @@ class EnterAmountFragment : Fragment(R.layout.fragment_enter_amount) { } viewModel.canContinue.observe(viewLifecycleOwner) { canContinue -> + if (continueLoading) return@observe binding.continueBtn.isEnabled = if (!didAuthorize && requirePinForBalance && !viewModel.blockContinue) { viewModel.amount.value?.isPositive == true } else { @@ -214,6 +217,29 @@ class EnterAmountFragment : Fragment(R.layout.fragment_enter_amount) { } } + /** + * Show a progress circle on the continue button and DISABLE it — for + * hosts whose action runs asynchronously after the tap. The disabled + * state is sticky: [canContinue] emissions cannot re-enable the button + * while loading (that observer would otherwise flip it back on within + * milliseconds). + */ + fun setContinueLoading(loading: Boolean) { + continueLoading = loading + viewLifecycleOwner.lifecycleScope.launch { + viewLifecycleOwner.lifecycle.withStarted { + binding.continueProgress.isVisible = loading + binding.continueBtn.text = if (loading) "" else getString(R.string.button_continue) + // isEnabled alone gives the app's standard disabled look: the + // button theme already maps it to `disabledBackgroundColor`. + binding.continueBtn.isEnabled = !loading + } + } + } + + /** True while [setContinueLoading] holds the button in its busy state. */ + private var continueLoading = false + fun applyMaxAmount() { lifecycleScope.launchWhenStarted { onMaxAmountButtonClick() diff --git a/common/src/main/res/layout/fragment_enter_amount.xml b/common/src/main/res/layout/fragment_enter_amount.xml index 1c7d8f1fa9..d8a22daf2a 100644 --- a/common/src/main/res/layout/fragment_enter_amount.xml +++ b/common/src/main/res/layout/fragment_enter_amount.xml @@ -128,14 +128,28 @@ android:layout_marginBottom="@dimen/enter_amount_keyboard_spacing" app:nk_decSeparatorEnabled="true" /> -