diff options
author | Torsten Grote <t@grobox.de> | 2023-01-05 17:03:34 -0300 |
---|---|---|
committer | Torsten Grote <t@grobox.de> | 2023-01-05 17:04:02 -0300 |
commit | 2c78d3c9ac6d2b7749af4c46f424766ede0a7a1b (patch) | |
tree | 1f473f9e072468bc45862b400d8ef4e91d9c5955 /wallet | |
parent | ab77084575b76f9cbd517ff5817a2a5655133136 (diff) | |
download | taler-android-2c78d3c9ac6d2b7749af4c46f424766ede0a7a1b.tar.gz taler-android-2c78d3c9ac6d2b7749af4c46f424766ede0a7a1b.tar.bz2 taler-android-2c78d3c9ac6d2b7749af4c46f424766ede0a7a1b.zip |
[wallet] Some fixes for accepting a tip
Diffstat (limited to 'wallet')
5 files changed, 58 insertions, 87 deletions
diff --git a/wallet/src/main/java/net/taler/wallet/tip/AlreadyAcceptedFragment.kt b/wallet/src/main/java/net/taler/wallet/tip/AlreadyAcceptedFragment.kt index d76b6a1..637a2da 100644 --- a/wallet/src/main/java/net/taler/wallet/tip/AlreadyAcceptedFragment.kt +++ b/wallet/src/main/java/net/taler/wallet/tip/AlreadyAcceptedFragment.kt @@ -33,9 +33,10 @@ class AlreadyAcceptedFragment : Fragment() { private lateinit var ui: FragmentAlreadyAcceptedBinding override fun onCreateView( - inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle? - ): View? { + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle?, + ): View { ui = FragmentAlreadyAcceptedBinding.inflate(inflater, container, false) return ui.root } diff --git a/wallet/src/main/java/net/taler/wallet/tip/PromptTipFragment.kt b/wallet/src/main/java/net/taler/wallet/tip/PromptTipFragment.kt index 6a96d1d..b0f5a35 100644 --- a/wallet/src/main/java/net/taler/wallet/tip/PromptTipFragment.kt +++ b/wallet/src/main/java/net/taler/wallet/tip/PromptTipFragment.kt @@ -44,11 +44,11 @@ class PromptTipFragment : Fragment() { private lateinit var ui: FragmentPromptTipBinding override fun onCreateView( - inflater: LayoutInflater, container: ViewGroup?, + inflater: LayoutInflater, + container: ViewGroup?, savedInstanceState: Bundle?, ): View { ui = FragmentPromptTipBinding.inflate(inflater, container, false) - ui.introView.fadeIn() return ui.root } @@ -73,55 +73,53 @@ class PromptTipFragment : Fragment() { } } - private fun onPaymentStatusChanged(payStatus: TipStatus?) { - when (payStatus) { - null -> {} - is TipStatus.Prepared -> { - showLoading(false) - showContent( - amountRaw = payStatus.tipAmountRaw, - amountEffective = payStatus.tipAmountEffective, - exchange = payStatus.exchangeBaseUrl, - merchant = payStatus.merchantBaseUrl + private fun onPaymentStatusChanged(payStatus: TipStatus) = when (payStatus) { + is TipStatus.Prepared -> { + showLoading(false) + showContent( + amountRaw = payStatus.tipAmountRaw, + amountEffective = payStatus.tipAmountEffective, + exchange = payStatus.exchangeBaseUrl, + merchant = payStatus.merchantBaseUrl + ) + ui.confirmWithdrawButton.isEnabled = true + ui.confirmWithdrawButton.setOnClickListener { + tipManager.confirmTip( + payStatus.walletTipId, + payStatus.tipAmountRaw.currency ) - //showOrder(payStatus.contractTerms, payStatus.amountRaw, fees) - ui.confirmWithdrawButton.isEnabled = true - ui.confirmWithdrawButton.setOnClickListener { - model.showProgressBar.value = true - tipManager.confirmTip( - payStatus.walletTipId, - payStatus.tipAmountRaw.currency - ) - ui.confirmWithdrawButton.fadeOut() - ui.progressBar.fadeIn() - } - } - is TipStatus.AlreadyAccepted -> { - showLoading(false) - tipManager.resetTipStatus() - findNavController().navigate(R.id.action_promptTip_to_alreadyAccepted) - } - is TipStatus.Success -> { - showLoading(false) - tipManager.resetTipStatus() - findNavController().navigate(R.id.action_promptTip_to_nav_main) - model.showTransactions(payStatus.currency) - Snackbar.make(requireView(), R.string.tip_received, LENGTH_LONG).show() - } - is TipStatus.Error -> { - showLoading(false) - ui.introView.text = getString(R.string.payment_error, payStatus.error) - ui.introView.fadeIn() - } - is TipStatus.None -> { - // No payment active. - showLoading(false) - } - is TipStatus.Loading -> { - // Wait until loaded ... - showLoading(true) } } + is TipStatus.Accepting -> { + model.showProgressBar.value = true + ui.confirmProgressBar.fadeIn() + ui.confirmWithdrawButton.fadeOut() + } + is TipStatus.AlreadyAccepted -> { + showLoading(false) + tipManager.resetTipStatus() + findNavController().navigate(R.id.action_promptTip_to_alreadyAccepted) + } + is TipStatus.Success -> { + showLoading(false) + tipManager.resetTipStatus() + findNavController().navigate(R.id.action_promptTip_to_nav_main) + model.showTransactions(payStatus.currency) + Snackbar.make(requireView(), R.string.tip_received, LENGTH_LONG).show() + } + is TipStatus.Error -> { + showLoading(false) + ui.introView.text = getString(R.string.payment_error, payStatus.error) + ui.introView.fadeIn() + } + is TipStatus.None -> { + // No tip active + showLoading(false) + } + is TipStatus.Loading -> { + // Wait until loaded ... + showLoading(true) + } } private fun showContent( diff --git a/wallet/src/main/java/net/taler/wallet/tip/TipManager.kt b/wallet/src/main/java/net/taler/wallet/tip/TipManager.kt index 855feb0..5548687 100644 --- a/wallet/src/main/java/net/taler/wallet/tip/TipManager.kt +++ b/wallet/src/main/java/net/taler/wallet/tip/TipManager.kt @@ -25,10 +25,10 @@ import kotlinx.coroutines.launch import net.taler.common.Amount import net.taler.common.Timestamp import net.taler.wallet.TAG -import net.taler.wallet.backend.WalletBackendApi import net.taler.wallet.backend.TalerErrorInfo -import net.taler.wallet.tip.PrepareTipResponse.TipPossibleResponse +import net.taler.wallet.backend.WalletBackendApi import net.taler.wallet.tip.PrepareTipResponse.AlreadyAcceptedResponse +import net.taler.wallet.tip.PrepareTipResponse.TipPossibleResponse sealed class TipStatus { object None : TipStatus() @@ -41,12 +41,12 @@ sealed class TipStatus { val tipAmountRaw: Amount, val tipAmountEffective: Amount, ) : TipStatus() - + object Accepting : TipStatus() data class AlreadyAccepted( val walletTipId: String, ) : TipStatus() - // TODO bring user to fulfilment URI + // TODO bring user to fulfilment URI (not yet in wallet API) data class Error(val error: String) : TipStatus() data class Success(val currency: String) : TipStatus() } @@ -77,6 +77,7 @@ class TipManager( } fun confirmTip(tipId: String, currency: String) = scope.launch { + mTipStatus.value = TipStatus.Accepting api.request("acceptTip", ConfirmTipResult.serializer()) { put("walletTipId", tipId) }.onError { @@ -86,31 +87,6 @@ class TipManager( } } -/* - @UiThread - fun abortTip() { - val ps = tipStatus.value - if (ps is TipStatus.Prepared) { - abortProposal(ps.walletTipId) - } - resetTipStatus() - } -*/ - -/* - internal fun abortProposal(proposalId: String) = scope.launch { - Log.i(TAG, "aborting proposal") - api.request<Unit>("abortProposal") { - put("proposalId", proposalId) - }.onError { - Log.e(TAG, "received error response to abortProposal") - handleError("abortProposal", it) - }.onSuccess { - mTipStatus.postValue(TipStatus.None) - } - } -*/ - @UiThread fun resetTipStatus() { mTipStatus.value = TipStatus.None diff --git a/wallet/src/main/java/net/taler/wallet/tip/TipResponses.kt b/wallet/src/main/java/net/taler/wallet/tip/TipResponses.kt index aa2da15..b0f6273 100644 --- a/wallet/src/main/java/net/taler/wallet/tip/TipResponses.kt +++ b/wallet/src/main/java/net/taler/wallet/tip/TipResponses.kt @@ -21,9 +21,7 @@ import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlinx.serialization.json.JsonClassDiscriminator import net.taler.common.Amount -import net.taler.common.ContractTerms import net.taler.common.Timestamp -import net.taler.wallet.backend.TalerErrorInfo @OptIn(ExperimentalSerializationApi::class) @Serializable @@ -46,7 +44,7 @@ sealed class PrepareTipResponse { exchangeBaseUrl = exchangeBaseUrl, expirationTimestamp = expirationTimestamp, tipAmountEffective = tipAmountEffective, - tipAmountRaw = tipAmountRaw + tipAmountRaw = tipAmountRaw, ) } @@ -58,6 +56,4 @@ sealed class PrepareTipResponse { } @Serializable -class ConfirmTipResult { - -} +class ConfirmTipResult diff --git a/wallet/src/main/res/layout/fragment_prompt_tip.xml b/wallet/src/main/res/layout/fragment_prompt_tip.xml index d96ef60..941274f 100644 --- a/wallet/src/main/res/layout/fragment_prompt_tip.xml +++ b/wallet/src/main/res/layout/fragment_prompt_tip.xml @@ -147,8 +147,8 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="16dp" - android:layout_marginBottom="8dp" android:layout_marginEnd="8dp" + android:layout_marginBottom="8dp" android:gravity="center" android:textSize="24sp" android:visibility="invisible" |