From 238f59ad71b6c9dfef50d15af398a351aa11408a Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Sun, 24 May 2020 00:08:14 +0100 Subject: [PATCH] display correct label and amount for tip unlocks in tx history --- .../browser/adapter/RewardListAdapter.java | 4 +++ .../adapter/TransactionListAdapter.java | 6 +++- .../io/lbry/browser/model/Transaction.java | 31 ++++++++++++++++--- .../tasks/wallet/WalletBalanceTask.java | 2 +- .../res/layout/card_wallet_send_credits.xml | 3 +- .../main/res/layout/list_item_transaction.xml | 14 ++++++++- 6 files changed, 51 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/lbry/browser/adapter/RewardListAdapter.java b/app/src/main/java/io/lbry/browser/adapter/RewardListAdapter.java index f3895452..76dd89ab 100644 --- a/app/src/main/java/io/lbry/browser/adapter/RewardListAdapter.java +++ b/app/src/main/java/io/lbry/browser/adapter/RewardListAdapter.java @@ -168,6 +168,10 @@ public class RewardListAdapter extends RecyclerView.Adapter 0 ? View.VISIBLE : View.GONE); + vh.dateView.setText(item.getConfirmations() > 0 ? TX_LIST_DATE_FORMAT.format(item.getTxDate()) : null); + vh.pendingView.setVisibility(item.getConfirmations() == 0 ? View.VISIBLE : View.GONE); vh.infoFeeContainer.setVisibility(!Helper.isNullOrEmpty(item.getClaim()) || Math.abs(item.getFee().doubleValue()) > 0 ? View.VISIBLE : View.GONE); @@ -111,6 +113,7 @@ public class TransactionListAdapter extends RecyclerView.Adapter infos = new ArrayList<>(); try { if (jsonObject.has("abandon_info")) { JSONArray array = jsonObject.getJSONArray("abandon_info"); if (array.length() > 0) { - info = TransactionInfo.fromJSONObject(array.getJSONObject(0)); - descStringId = R.string.abandon; - transaction.setAbandonInfo(info); + if (array.length() == 1) { + info = TransactionInfo.fromJSONObject(array.getJSONObject(0)); + descStringId = info.getBalanceDelta().doubleValue() == info.getAmount().doubleValue() ? R.string.unlock : R.string.abandon; + transaction.setAbandonInfo(info); + } else { + // multiple abandon infos (txo_spend unlock tip) + descStringId = R.string.unlock; + for (int i = 0; i < array.length(); i++) { + infos.add(TransactionInfo.fromJSONObject(array.getJSONObject(i))); + } + } } } if (info == null && jsonObject.has("claim_info")) { @@ -94,8 +105,18 @@ public class Transaction { // pass } - if (transaction.getValue().doubleValue() == 0 && info != null && info.getBalanceDelta().doubleValue() != 0) { - transaction.setValue(info.getBalanceDelta()); + + + if (transaction.getValue().doubleValue() == 0) { + if (info != null && info.getBalanceDelta().doubleValue() != 0) { + transaction.setValue(info.getBalanceDelta()); + } else if (infos.size() > 0) { + BigDecimal total = new BigDecimal(0); + for (TransactionInfo txInfo : infos) { + total = total.add(txInfo.getAmount()); + } + transaction.setValue(total); + } } if (descStringId == -1) { diff --git a/app/src/main/java/io/lbry/browser/tasks/wallet/WalletBalanceTask.java b/app/src/main/java/io/lbry/browser/tasks/wallet/WalletBalanceTask.java index 53eb94e8..cad56be2 100644 --- a/app/src/main/java/io/lbry/browser/tasks/wallet/WalletBalanceTask.java +++ b/app/src/main/java/io/lbry/browser/tasks/wallet/WalletBalanceTask.java @@ -20,7 +20,7 @@ public class WalletBalanceTask extends AsyncTask { } protected WalletBalance doInBackground(Void... params) { - WalletBalance balance = new WalletBalance(); + WalletBalance balance; try { JSONObject json = (JSONObject) Lbry.genericApiCall(Lbry.METHOD_WALLET_BALANCE); balance = WalletBalance.fromJSONObject(json); diff --git a/app/src/main/res/layout/card_wallet_send_credits.xml b/app/src/main/res/layout/card_wallet_send_credits.xml index 17c15c1e..f4a4c966 100644 --- a/app/src/main/res/layout/card_wallet_send_credits.xml +++ b/app/src/main/res/layout/card_wallet_send_credits.xml @@ -28,7 +28,8 @@ android:fontFamily="@font/inter" android:textSize="14sp" android:layout_width="match_parent" - android:layout_height="wrap_content" /> + android:layout_height="wrap_content" + android:imeOptions="actionNext" /> + android:textFontWeight="300" + android:visibility="gone" /> + \ No newline at end of file