gnunet-svn
[Top][All Lists]
Advanced

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

[taler-taler-android] 10/13: [wallet] show a pending badge next to balan


From: gnunet
Subject: [taler-taler-android] 10/13: [wallet] show a pending badge next to balances with pending transactions
Date: Mon, 18 May 2020 14:47:27 +0200

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

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

commit ebaffcdfabd2d33e1754321f0c08d7ca5bd1570a
Author: Torsten Grote <address@hidden>
AuthorDate: Fri May 15 13:28:45 2020 -0300

    [wallet] show a pending badge next to balances with pending transactions
---
 .../src/main/java/net/taler/wallet/MainFragment.kt |  1 +
 .../main/java/net/taler/wallet/MainViewModel.kt    |  6 ++---
 .../net/taler/wallet/balances/BalanceAdapter.kt    | 10 +++++---
 .../net/taler/wallet/balances/BalancesFragment.kt  |  1 -
 .../wallet/transactions/TransactionManager.kt      |  8 ++++++
 wallet/src/main/res/drawable/badge.xml             | 26 +++++++++++++++++++
 wallet/src/main/res/layout/list_item_balance.xml   | 30 +++++++++++++++-------
 7 files changed, 66 insertions(+), 16 deletions(-)

diff --git a/wallet/src/main/java/net/taler/wallet/MainFragment.kt 
b/wallet/src/main/java/net/taler/wallet/MainFragment.kt
index 328d7a2..26c5a90 100644
--- a/wallet/src/main/java/net/taler/wallet/MainFragment.kt
+++ b/wallet/src/main/java/net/taler/wallet/MainFragment.kt
@@ -28,6 +28,7 @@ import kotlinx.android.synthetic.main.fragment_main.*
 import net.taler.common.EventObserver
 import net.taler.wallet.CurrencyMode.MULTI
 import net.taler.wallet.CurrencyMode.SINGLE
+import net.taler.wallet.balances.BalanceItem
 import net.taler.wallet.balances.BalancesFragment
 import net.taler.wallet.transactions.TransactionsFragment
 
diff --git a/wallet/src/main/java/net/taler/wallet/MainViewModel.kt 
b/wallet/src/main/java/net/taler/wallet/MainViewModel.kt
index 6a1d6aa..75cab67 100644
--- a/wallet/src/main/java/net/taler/wallet/MainViewModel.kt
+++ b/wallet/src/main/java/net/taler/wallet/MainViewModel.kt
@@ -32,6 +32,7 @@ import net.taler.common.Event
 import net.taler.common.assertUiThread
 import net.taler.common.toEvent
 import net.taler.wallet.backend.WalletBackendApi
+import net.taler.wallet.balances.BalanceItem
 import net.taler.wallet.history.DevHistoryManager
 import net.taler.wallet.payment.PaymentManager
 import net.taler.wallet.pending.PendingOperationsManager
@@ -48,8 +49,6 @@ private val transactionNotifications = listOf(
     "withdraw-group-finished"
 )
 
-data class BalanceItem(val available: Amount, val pendingIncoming: Amount)
-
 class MainViewModel(val app: Application) : AndroidViewModel(app) {
 
     private val mBalances = MutableLiveData<Map<String, BalanceItem>>()
@@ -127,7 +126,8 @@ class MainViewModel(val app: Application) : 
AndroidViewModel(app) {
                 val jsonAmountIncoming = byCurrency.getJSONObject(currency)
                     .getJSONObject("pendingIncoming")
                 val amountIncoming = Amount.fromJsonObject(jsonAmountIncoming)
-                balanceMap[currency] = BalanceItem(amount, amountIncoming)
+                val hasPending = transactionManager.hasPending(currency)
+                balanceMap[currency] = BalanceItem(amount, amountIncoming, 
hasPending)
             }
             mBalances.postValue(balanceMap)
             showProgressBar.postValue(false)
diff --git a/wallet/src/main/java/net/taler/wallet/balances/BalanceAdapter.kt 
b/wallet/src/main/java/net/taler/wallet/balances/BalanceAdapter.kt
index 0ccfeb2..be50364 100644
--- a/wallet/src/main/java/net/taler/wallet/balances/BalanceAdapter.kt
+++ b/wallet/src/main/java/net/taler/wallet/balances/BalanceAdapter.kt
@@ -24,10 +24,12 @@ import android.view.ViewGroup
 import android.widget.TextView
 import androidx.recyclerview.widget.RecyclerView
 import androidx.recyclerview.widget.RecyclerView.Adapter
-import net.taler.wallet.BalanceItem
+import net.taler.common.Amount
 import net.taler.wallet.R
 import net.taler.wallet.balances.BalanceAdapter.BalanceViewHolder
 
+data class BalanceItem(val available: Amount, val pendingIncoming: Amount, val 
hasPending: Boolean)
+
 class BalanceAdapter(private val listener: BalanceClickListener) : 
Adapter<BalanceViewHolder>() {
 
     private var items = emptyList<BalanceItem>()
@@ -55,10 +57,11 @@ class BalanceAdapter(private val listener: 
BalanceClickListener) : Adapter<Balan
     }
 
     inner class BalanceViewHolder(private val v: View) : 
RecyclerView.ViewHolder(v) {
-        private val currencyView: TextView = 
v.findViewById(R.id.balance_currency)
-        private val amountView: TextView = v.findViewById(R.id.balance_amount)
+        private val currencyView: TextView = 
v.findViewById(R.id.balanceCurrencyView)
+        private val amountView: TextView = 
v.findViewById(R.id.balanceAmountView)
         private val balanceInboundAmount: TextView = 
v.findViewById(R.id.balanceInboundAmount)
         private val balanceInboundLabel: TextView = 
v.findViewById(R.id.balanceInboundLabel)
+        private val pendingView: TextView = v.findViewById(R.id.pendingView)
 
         fun bind(item: BalanceItem) {
             v.setOnClickListener { 
listener.onBalanceClick(item.available.currency) }
@@ -75,6 +78,7 @@ class BalanceAdapter(private val listener: 
BalanceClickListener) : Adapter<Balan
                 balanceInboundAmount.text =
                     v.context.getString(R.string.amount_positive, 
amountIncoming)
             }
+            pendingView.visibility = if (item.hasPending) VISIBLE else GONE
         }
     }
 
diff --git a/wallet/src/main/java/net/taler/wallet/balances/BalancesFragment.kt 
b/wallet/src/main/java/net/taler/wallet/balances/BalancesFragment.kt
index ab4077a..22dd992 100644
--- a/wallet/src/main/java/net/taler/wallet/balances/BalancesFragment.kt
+++ b/wallet/src/main/java/net/taler/wallet/balances/BalancesFragment.kt
@@ -31,7 +31,6 @@ import androidx.recyclerview.widget.DividerItemDecoration
 import androidx.recyclerview.widget.LinearLayoutManager.VERTICAL
 import kotlinx.android.synthetic.main.fragment_balances.*
 import net.taler.common.fadeIn
-import net.taler.wallet.BalanceItem
 import net.taler.wallet.MainViewModel
 import net.taler.wallet.R
 
diff --git 
a/wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt 
b/wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt
index f830aa1..5b8e577 100644
--- a/wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt
+++ b/wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt
@@ -89,4 +89,12 @@ class TransactionManager(
         liveData.postValue(TransactionsResult.Success(transactions))
     }
 
+    @UiThread
+    fun hasPending(currency: String): Boolean {
+        val result = mTransactions[currency]?.value ?: return false
+        return if (result is TransactionsResult.Success) {
+            result.transactions.any { it.pending }
+        } else false
+    }
+
 }
diff --git a/wallet/src/main/res/drawable/badge.xml 
b/wallet/src/main/res/drawable/badge.xml
new file mode 100644
index 0000000..0b06ce5
--- /dev/null
+++ b/wallet/src/main/res/drawable/badge.xml
@@ -0,0 +1,26 @@
+<!--
+  ~ This file is part of GNU Taler
+  ~ (C) 2020 Taler Systems S.A.
+  ~
+  ~ GNU Taler is free software; you can redistribute it and/or modify it under 
the
+  ~ terms of the GNU General Public License as published by the Free Software
+  ~ Foundation; either version 3, or (at your option) any later version.
+  ~
+  ~ GNU Taler is distributed in the hope that it will be useful, but WITHOUT 
ANY
+  ~ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
FOR
+  ~ A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+  ~
+  ~ You should have received a copy of the GNU General Public License along 
with
+  ~ GNU Taler; see the file COPYING.  If not, see 
<http://www.gnu.org/licenses/>
+  -->
+
+<shape xmlns:android="http://schemas.android.com/apk/res/android";
+    android:shape="rectangle">
+    <solid android:color="?android:textColorSecondary" />
+    <corners android:radius="8dp" />
+    <padding
+        android:bottom="2dp"
+        android:left="8dp"
+        android:right="8dp"
+        android:top="2dp" />
+</shape>
\ No newline at end of file
diff --git a/wallet/src/main/res/layout/list_item_balance.xml 
b/wallet/src/main/res/layout/list_item_balance.xml
index a9e15df..475e7d6 100644
--- a/wallet/src/main/res/layout/list_item_balance.xml
+++ b/wallet/src/main/res/layout/list_item_balance.xml
@@ -23,12 +23,12 @@
     android:padding="16dp">
 
     <TextView
-        android:id="@+id/balance_amount"
+        android:id="@+id/balanceAmountView"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_marginEnd="8dp"
         android:textSize="40sp"
-        app:layout_constraintEnd_toStartOf="@+id/balance_currency"
+        app:layout_constraintEnd_toStartOf="@+id/balanceCurrencyView"
         app:layout_constraintHorizontal_bias="0.0"
         app:layout_constraintHorizontal_chainStyle="packed"
         app:layout_constraintStart_toStartOf="parent"
@@ -36,15 +36,16 @@
         tools:text="100.50" />
 
     <TextView
-        android:id="@+id/balance_currency"
+        android:id="@+id/balanceCurrencyView"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
+        android:layout_marginEnd="8dp"
         android:textSize="20sp"
-        app:layout_constraintBottom_toBottomOf="@+id/balance_amount"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintHorizontal_bias="0.5"
-        app:layout_constraintStart_toEndOf="@+id/balance_amount"
-        app:layout_constraintTop_toTopOf="@+id/balance_amount"
+        app:layout_constrainedWidth="true"
+        app:layout_constraintBottom_toBottomOf="@+id/balanceAmountView"
+        app:layout_constraintEnd_toStartOf="@+id/pendingView"
+        app:layout_constraintStart_toEndOf="@+id/balanceAmountView"
+        app:layout_constraintTop_toTopOf="@+id/balanceAmountView"
         tools:text="TESTKUDOS" />
 
     <TextView
@@ -58,7 +59,7 @@
         app:layout_constraintHorizontal_bias="0.0"
         app:layout_constraintHorizontal_chainStyle="packed"
         app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toBottomOf="@+id/balance_amount"
+        app:layout_constraintTop_toBottomOf="@+id/balanceAmountView"
         tools:text="+10 TESTKUDOS"
         tools:visibility="visible" />
 
@@ -75,4 +76,15 @@
         app:layout_constraintTop_toTopOf="@+id/balanceInboundAmount"
         tools:visibility="visible" />
 
+    <TextView
+        android:id="@+id/pendingView"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:background="@drawable/badge"
+        android:text="@string/transaction_pending"
+        android:textColor="?android:textColorPrimaryInverse"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintTop_toTopOf="parent" />
+
 </androidx.constraintlayout.widget.ConstraintLayout>

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

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