gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-taler-android] branch master updated (ab77084 -> 6f45cd9)


From: gnunet
Subject: [taler-taler-android] branch master updated (ab77084 -> 6f45cd9)
Date: Thu, 05 Jan 2023 21:14:49 +0100

This is an automated email from the git hooks/post-receive script.

torsten-grote pushed a change to branch master
in repository taler-android.

    from ab77084  [wallet] Add share button to Peer-Pull (and adapt to new API)
     new 2c78d3c  [wallet] Some fixes for accepting a tip
     new 6f45cd9  [wallet] Show details of tip transaction

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../taler/wallet/tip/AlreadyAcceptedFragment.kt    |  7 +-
 .../java/net/taler/wallet/tip/PromptTipFragment.kt | 94 +++++++++++-----------
 .../main/java/net/taler/wallet/tip/TipManager.kt   | 34 ++------
 .../main/java/net/taler/wallet/tip/TipResponses.kt |  8 +-
 .../TransactionTipFragment.kt}                     | 62 +++++++++-----
 .../net/taler/wallet/transactions/Transactions.kt  |  5 +-
 wallet/src/main/res/layout/fragment_prompt_tip.xml |  2 +-
 wallet/src/main/res/navigation/nav_graph.xml       | 10 +++
 8 files changed, 113 insertions(+), 109 deletions(-)
 copy 
wallet/src/main/java/net/taler/wallet/{deposit/TransactionDepositComposable.kt 
=> transactions/TransactionTipFragment.kt} (61%)

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/java/net/taler/wallet/deposit/TransactionDepositComposable.kt 
b/wallet/src/main/java/net/taler/wallet/transactions/TransactionTipFragment.kt
similarity index 61%
copy from 
wallet/src/main/java/net/taler/wallet/deposit/TransactionDepositComposable.kt
copy to 
wallet/src/main/java/net/taler/wallet/transactions/TransactionTipFragment.kt
index 7c5c7a2..3f370c7 100644
--- 
a/wallet/src/main/java/net/taler/wallet/deposit/TransactionDepositComposable.kt
+++ 
b/wallet/src/main/java/net/taler/wallet/transactions/TransactionTipFragment.kt
@@ -14,8 +14,12 @@
  * GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
  */
 
-package net.taler.wallet.deposit
+package net.taler.wallet.transactions
 
+import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
 import androidx.compose.foundation.layout.Column
 import androidx.compose.foundation.layout.fillMaxWidth
 import androidx.compose.foundation.layout.padding
@@ -25,8 +29,9 @@ import androidx.compose.material.MaterialTheme
 import androidx.compose.material.Surface
 import androidx.compose.material.Text
 import androidx.compose.runtime.Composable
-import androidx.compose.ui.Alignment
+import androidx.compose.ui.Alignment.Companion.CenterHorizontally
 import androidx.compose.ui.Modifier
+import androidx.compose.ui.platform.ComposeView
 import androidx.compose.ui.platform.LocalContext
 import androidx.compose.ui.res.stringResource
 import androidx.compose.ui.tooling.preview.Preview
@@ -35,19 +40,34 @@ import net.taler.common.Amount
 import net.taler.common.Timestamp
 import net.taler.common.toAbsoluteTime
 import net.taler.wallet.R
-import net.taler.wallet.transactions.AmountType
-import net.taler.wallet.transactions.DeleteTransactionComposable
-import net.taler.wallet.transactions.TransactionAmountComposable
-import net.taler.wallet.transactions.TransactionDeposit
+import net.taler.wallet.compose.TalerSurface
+
+class TransactionTipFragment : TransactionDetailFragment() {
+
+    override fun onCreateView(
+        inflater: LayoutInflater,
+        container: ViewGroup?,
+        savedInstanceState: Bundle?,
+    ): View = ComposeView(requireContext()).apply {
+        setContent {
+            TalerSurface {
+                val t = transaction as? TransactionTip ?: error("No or wrong 
transaction")
+                TransactionTipComposable(t) {
+                    onDeleteButtonClicked(t)
+                }
+            }
+        }
+    }
+}
 
 @Composable
-fun TransactionDepositComposable(t: TransactionDeposit, onDelete: () -> Unit) {
+fun TransactionTipComposable(t: TransactionTip, onDelete: () -> Unit) {
     val scrollState = rememberScrollState()
     Column(
         modifier = Modifier
             .fillMaxWidth()
             .verticalScroll(scrollState),
-        horizontalAlignment = Alignment.CenterHorizontally,
+        horizontalAlignment = CenterHorizontally,
     ) {
         val context = LocalContext.current
         Text(
@@ -55,17 +75,18 @@ fun TransactionDepositComposable(t: TransactionDeposit, 
onDelete: () -> Unit) {
             text = t.timestamp.ms.toAbsoluteTime(context).toString(),
             style = MaterialTheme.typography.body1,
         )
+
         TransactionAmountComposable(
-            label = stringResource(id = R.string.transaction_paid),
+            label = stringResource(id = 
R.string.send_peer_payment_amount_received),
             amount = t.amountEffective,
-            amountType = AmountType.Negative,
+            amountType = AmountType.Positive,
         )
         TransactionAmountComposable(
-            label = stringResource(id = R.string.transaction_order_total),
+            label = stringResource(id = 
R.string.send_peer_payment_amount_sent),
             amount = t.amountRaw,
             amountType = AmountType.Neutral,
         )
-        val fee = t.amountEffective - t.amountRaw
+        val fee = t.amountRaw - t.amountEffective
         if (!fee.isZero()) {
             TransactionAmountComposable(
                 label = stringResource(id = R.string.withdraw_fees),
@@ -73,23 +94,26 @@ fun TransactionDepositComposable(t: TransactionDeposit, 
onDelete: () -> Unit) {
                 amountType = AmountType.Negative,
             )
         }
+        TransactionInfoComposable(
+            label = stringResource(id = R.string.tip_merchant_url),
+            info = t.merchantBaseUrl,
+        )
         DeleteTransactionComposable(onDelete)
     }
 }
 
 @Preview
 @Composable
-fun TransactionDepositComposablePreview() {
-    val t = TransactionDeposit(
+fun TransactionTipPreview() {
+    val t = TransactionTip(
         transactionId = "transactionId",
         timestamp = Timestamp.fromMillis(System.currentTimeMillis() - 360 * 60 
* 1000),
         pending = true,
-        depositGroupId = "fooBar",
-        amountRaw = Amount.fromDouble("TESTKUDOS", 42.1337),
-        amountEffective = Amount.fromDouble("TESTKUDOS", 42.23),
-        targetPaytoUri = "https://exchange.example.org/peer/pull/credit";,
+        merchantBaseUrl = "https://merchant.example.org/";,
+        amountRaw = Amount.fromDouble("TESTKUDOS", 42.23),
+        amountEffective = Amount.fromDouble("TESTKUDOS", 42.1337),
     )
     Surface {
-        TransactionDepositComposable(t) {}
+        TransactionTipComposable(t) {}
     }
 }
diff --git a/wallet/src/main/java/net/taler/wallet/transactions/Transactions.kt 
b/wallet/src/main/java/net/taler/wallet/transactions/Transactions.kt
index dcb524e..740aab6 100644
--- a/wallet/src/main/java/net/taler/wallet/transactions/Transactions.kt
+++ b/wallet/src/main/java/net/taler/wallet/transactions/Transactions.kt
@@ -212,14 +212,13 @@ class TransactionTip(
     override val transactionId: String,
     override val timestamp: Timestamp,
     override val pending: Boolean,
-    val frozen: Boolean,
     val merchantBaseUrl: String,
     override val error: TalerErrorInfo? = null,
     override val amountRaw: Amount,
     override val amountEffective: Amount,
 ) : Transaction() {
-    override val icon = R.drawable.transaction_tip_accepted // TODO different 
when declined
-    override val detailPageNav = 0
+    override val icon = R.drawable.transaction_tip_accepted
+    override val detailPageNav = R.id.action_nav_transactions_detail_tip
 
     @Transient
     override val amountType = AmountType.Positive
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"
diff --git a/wallet/src/main/res/navigation/nav_graph.xml 
b/wallet/src/main/res/navigation/nav_graph.xml
index f1d189f..ec5ec08 100644
--- a/wallet/src/main/res/navigation/nav_graph.xml
+++ b/wallet/src/main/res/navigation/nav_graph.xml
@@ -258,6 +258,12 @@
         android:label="@string/transactions_detail_title"
         tools:layout="@layout/fragment_transaction_withdrawal" />
 
+    <fragment
+        android:id="@+id/nav_transactions_detail_tip"
+        android:name="net.taler.wallet.transactions.TransactionTipFragment"
+        android:label="@string/transactions_detail_title"
+        tools:layout="@layout/fragment_transaction_withdrawal" />
+
     <fragment
         android:id="@+id/nav_transactions_detail_peer"
         android:name="net.taler.wallet.transactions.TransactionPeerFragment"
@@ -387,6 +393,10 @@
         android:id="@+id/action_nav_transactions_detail_deposit"
         app:destination="@id/nav_transactions_detail_deposit" />
 
+    <action
+        android:id="@+id/action_nav_transactions_detail_tip"
+        app:destination="@id/nav_transactions_detail_tip" />
+
     <action
         android:id="@+id/action_nav_payto_uri"
         app:destination="@id/nav_payto_uri" />

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]