taler-android

Android apps for GNU Taler (wallet, PoS, cashier)
Log | Files | Refs | README | LICENSE

commit 02c9b6a89448dd36c1cc9a924c851f67d3c34cbd
parent 761aa68df2fe364d9351085f3a3081a99e60068f
Author: Iván Ávalos <avalos@disroot.org>
Date:   Wed, 30 Apr 2025 20:28:01 +0200

[wallet] add "cancel" button to payment dialog

Diffstat:
Mwallet/src/main/java/net/taler/wallet/payment/PromptPaymentFragment.kt | 34+++++++++++++++++++---------------
Mwallet/src/main/java/net/taler/wallet/transactions/TransactionDetailFragment.kt | 18+++++++++++-------
Mwallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt | 7++++++-
Mwallet/src/main/res/layout-w550dp/payment_bottom_bar.xml | 14++++++++++++++
Mwallet/src/main/res/layout/payment_bottom_bar.xml | 18++++++++++++++++--
Mwallet/src/main/res/values/strings.xml | 1+
6 files changed, 67 insertions(+), 25 deletions(-)

diff --git a/wallet/src/main/java/net/taler/wallet/payment/PromptPaymentFragment.kt b/wallet/src/main/java/net/taler/wallet/payment/PromptPaymentFragment.kt @@ -76,21 +76,6 @@ class PromptPaymentFragment : Fragment(), ProductImageClickListener { } } - override fun onDestroy() { - super.onDestroy() - if (!requireActivity().isChangingConfigurations) { - val payStatus = paymentManager.payStatus.value as? PayStatus.Prepared ?: return - transactionManager.abortTransaction(payStatus.transactionId) { error -> - Log.e(TAG, "Error abortTransaction $error") - if (model.devMode.value == false) { - showError(error.userFacingMsg) - } else { - showError(error) - } - } - } - } - private fun setupInsets() { ViewCompat.setOnApplyWindowInsetsListener(ui.bottom.bottomLayout) { v, windowInsets -> val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()) @@ -126,8 +111,27 @@ class PromptPaymentFragment : Fragment(), ProductImageClickListener { currency = payStatus.contractTerms.amount.currency, ) ui.bottom.confirmButton.fadeOut() + ui.bottom.cancelButton.fadeOut() ui.bottom.confirmProgressBar.fadeIn() } + ui.bottom.cancelButton.isEnabled = true + ui.bottom.cancelButton.setOnClickListener { + transactionManager.abortTransaction( + payStatus.transactionId, + onSuccess = { + Snackbar.make(requireView(), getString(R.string.payment_aborted), LENGTH_LONG).show() + findNavController().popBackStack() + }, + onError = { error -> + Log.e(TAG, "Error abortTransaction $error") + if (model.devMode.value == false) { + showError(error.userFacingMsg) + } else { + showError(error) + } + } + ) + } } is PayStatus.InsufficientBalance -> { showLoading(false) diff --git a/wallet/src/main/java/net/taler/wallet/transactions/TransactionDetailFragment.kt b/wallet/src/main/java/net/taler/wallet/transactions/TransactionDetailFragment.kt @@ -129,14 +129,18 @@ abstract class TransactionDetailFragment : Fragment() { } private fun abortTransaction(t: Transaction) { - transactionManager.abortTransaction(t.transactionId) { - Log.e(TAG, "Error abortTransaction $it") - if (model.devMode.value == true) { - showError(it) - } else { - showError(it.userFacingMsg) + transactionManager.abortTransaction( + t.transactionId, + onSuccess = {}, + onError = { + Log.e(TAG, "Error abortTransaction $it") + if (model.devMode.value == true) { + showError(it) + } else { + showError(it.userFacingMsg) + } } - } + ) } private fun failTransaction(t: Transaction) { diff --git a/wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt b/wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt @@ -233,13 +233,18 @@ class TransactionManager( } } - fun abortTransaction(transactionId: String, onError: (it: TalerErrorInfo) -> Unit) = + fun abortTransaction( + transactionId: String, + onSuccess: () -> Unit, + onError: (it: TalerErrorInfo) -> Unit, + ) = scope.launch { api.request<Unit>("abortTransaction") { put("transactionId", transactionId) }.onError { onError(it) }.onSuccess { + onSuccess() loadTransactions() } } diff --git a/wallet/src/main/res/layout-w550dp/payment_bottom_bar.xml b/wallet/src/main/res/layout-w550dp/payment_bottom_bar.xml @@ -79,6 +79,20 @@ tools:visibility="visible" /> <Button + android:id="@+id/cancelButton" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_margin="8dp" + android:enabled="false" + style="@style/Widget.Material3.Button.OutlinedButton" + android:text="@string/payment_button_cancel" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toStartOf="@id/confirmButton" + app:layout_constraintHorizontal_bias="0.0" + app:layout_constraintStart_toStartOf="parent" + tools:enabled="true" /> + + <Button android:id="@+id/confirmButton" android:layout_width="wrap_content" android:layout_height="wrap_content" diff --git a/wallet/src/main/res/layout/payment_bottom_bar.xml b/wallet/src/main/res/layout/payment_bottom_bar.xml @@ -81,11 +81,25 @@ tools:visibility="visible" /> <Button + android:id="@+id/cancelButton" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_margin="8dp" + android:enabled="false" + style="@style/Widget.Material3.Button.OutlinedButton" + android:text="@string/payment_button_cancel" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toStartOf="@id/confirmButton" + app:layout_constraintHorizontal_bias="0.0" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/feeView" + tools:enabled="true" /> + + <Button android:id="@+id/confirmButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="8dp" - android:backgroundTint="@color/green" android:enabled="false" android:text="@string/payment_button_confirm" app:layout_constraintBottom_toBottomOf="parent" @@ -93,7 +107,7 @@ app:layout_constraintHorizontal_bias="1.0" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/feeView" - tools:enabled="true" /> + tools:enabled="true"/> <ProgressBar android:id="@+id/confirmProgressBar" diff --git a/wallet/src/main/res/values/strings.xml b/wallet/src/main/res/values/strings.xml @@ -194,6 +194,7 @@ GNU Taler is immune against many types of fraud, such as phishing of credit card <string name="payment_balance_insufficient_hint_merchant_deposit_insufficient">Merchant doesn\'t accept the wire method of the provider, this likely means it is misconfigured</string> <string name="payment_balance_insufficient_hint_wallet_balance_material_insufficient">Some of the coins needed for this purchase are currently unavailable</string> <string name="payment_balance_insufficient_max">Balance insufficient! Maximum is %1$s</string> + <string name="payment_button_cancel">Cancel</string> <string name="payment_button_confirm">Confirm payment</string> <string name="payment_confirmation_code">Confirmation code</string> <string name="payment_create_order">Create order</string>