From 9cd8a75dc623904f34e39ebb436c8953b90a3c5b Mon Sep 17 00:00:00 2001 From: m2049r Date: Sat, 7 Aug 2021 11:17:13 +0200 Subject: [PATCH] confirmations indicator (#775) --- .../com/m2049r/xmrwallet/WalletFragment.java | 12 +++-- .../layout/TransactionInfoAdapter.java | 39 ++++++++++++++- .../xmrwallet/service/WalletService.java | 35 ++++++-------- app/src/main/res/layout/item_transaction.xml | 47 +++++++++++++++---- build.gradle | 2 +- 5 files changed, 100 insertions(+), 35 deletions(-) diff --git a/app/src/main/java/com/m2049r/xmrwallet/WalletFragment.java b/app/src/main/java/com/m2049r/xmrwallet/WalletFragment.java index 3bd60ec..c1e53cd 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/WalletFragment.java +++ b/app/src/main/java/com/m2049r/xmrwallet/WalletFragment.java @@ -58,7 +58,6 @@ import java.text.NumberFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Objects; import timber.log.Timber; @@ -128,7 +127,7 @@ public class WalletFragment extends Fragment currencies.add(Helper.BASE_CRYPTO); if (Helper.SHOW_EXCHANGERATES) currencies.addAll(Arrays.asList(getResources().getStringArray(R.array.currency))); - ArrayAdapter spinnerAdapter = new ArrayAdapter<>(Objects.requireNonNull(getContext()), R.layout.item_spinner_balance, currencies); + ArrayAdapter spinnerAdapter = new ArrayAdapter<>(requireContext(), R.layout.item_spinner_balance, currencies); spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sCurrency.setAdapter(spinnerAdapter); @@ -346,13 +345,18 @@ public class WalletFragment extends Fragment // if account index has changed scroll to top? private int accountIndex = 0; - public void onRefreshed(final Wallet wallet, final boolean full) { + public void onRefreshed(final Wallet wallet, boolean full) { Timber.d("onRefreshed(%b)", full); + if (adapter.needsTransactionUpdateOnNewBlock()) { + wallet.getHistory().refresh(); + full = true; + } if (full) { List list = new ArrayList<>(); final long streetHeight = activityCallback.getStreetModeHeight(); Timber.d("StreetHeight=%d", streetHeight); + wallet.getHistory().refresh(); for (TransactionInfo info : wallet.getHistory().getAll()) { Timber.d("TxHeight=%d, Label=%s", info.blockheight, info.subaddressLabel); if ((info.isPending || (info.blockheight >= streetHeight)) @@ -561,7 +565,7 @@ public class WalletFragment extends Fragment //TODO figure out why gunther disappears on return from send although he is still set if (enable) { if (streetGunther == null) - streetGunther = ContextCompat.getDrawable(Objects.requireNonNull(getContext()), R.drawable.ic_gunther_streetmode); + streetGunther = ContextCompat.getDrawable(requireContext(), R.drawable.ic_gunther_streetmode); ivStreetGunther.setImageDrawable(streetGunther); } else ivStreetGunther.setImageDrawable(null); diff --git a/app/src/main/java/com/m2049r/xmrwallet/layout/TransactionInfoAdapter.java b/app/src/main/java/com/m2049r/xmrwallet/layout/TransactionInfoAdapter.java index cb21a92..835c3a1 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/layout/TransactionInfoAdapter.java +++ b/app/src/main/java/com/m2049r/xmrwallet/layout/TransactionInfoAdapter.java @@ -30,6 +30,7 @@ import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.DiffUtil; import androidx.recyclerview.widget.RecyclerView; +import com.google.android.material.progressindicator.CircularProgressIndicator; import com.m2049r.xmrwallet.R; import com.m2049r.xmrwallet.data.Crypto; import com.m2049r.xmrwallet.data.UserNotes; @@ -48,7 +49,9 @@ import java.util.TimeZone; import timber.log.Timber; public class TransactionInfoAdapter extends RecyclerView.Adapter { - private final SimpleDateFormat DATETIME_FORMATTER = new SimpleDateFormat("yyyy-MM-dd HH:mm"); + private final static int MAX_CONFIRMATIONS = 10; + + private final static SimpleDateFormat DATETIME_FORMATTER = new SimpleDateFormat("yyyy-MM-dd HH:mm"); private final int outboundColour; private final int inboundColour; @@ -77,6 +80,10 @@ public class TransactionInfoAdapter extends RecyclerView.Adapter 0) && (infoItems.get(0).confirmations < MAX_CONFIRMATIONS); + } + private static class TransactionInfoDiff extends DiffCallback { public TransactionInfoDiff(List oldList, List newList) { @@ -95,6 +102,7 @@ public class TransactionInfoAdapter extends RecyclerView.Adapter lastTxCount) { - // update the transaction list only if we have more than before - lastTxCount = txCount; - fullRefresh = true; - } + Timber.d("newBlock() @ %d with observer %s", height, observer); + if (observer != null) { + boolean fullRefresh = false; + updateDaemonState(wallet, wallet.isSynchronized() ? height : 0); + if (!wallet.isSynchronized()) { + updated = true; + // we want to see our transactions as they come in + wallet.getHistory().refresh(); + int txCount = wallet.getHistory().getCount(); + if (txCount > lastTxCount) { + // update the transaction list only if we have more than before + lastTxCount = txCount; + fullRefresh = true; } - if (observer != null) - observer.onRefreshed(wallet, fullRefresh); } + if (observer != null) + observer.onRefreshed(wallet, fullRefresh); } } diff --git a/app/src/main/res/layout/item_transaction.xml b/app/src/main/res/layout/item_transaction.xml index 00d66df..c9e55d7 100644 --- a/app/src/main/res/layout/item_transaction.xml +++ b/app/src/main/res/layout/item_transaction.xml @@ -1,5 +1,6 @@ - + + + + + + + + diff --git a/build.gradle b/build.gradle index c22dc87..4406443 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:4.2.0' + classpath 'com.android.tools.build:gradle:4.2.2' } }