From 394d5471e34b1f5e7e995b5b9347d95d36a4835b Mon Sep 17 00:00:00 2001 From: m2049r Date: Sun, 18 Apr 2021 19:16:52 +0200 Subject: [PATCH] show total incoming amount (#745) --- .../m2049r/xmrwallet/SubaddressFragment.java | 7 +++- .../com/m2049r/xmrwallet/data/Subaddress.java | 8 +++-- .../layout/SubaddressInfoAdapter.java | 9 +++++ .../com/m2049r/xmrwallet/model/Wallet.java | 11 +++++- app/src/main/res/layout/item_subaddress.xml | 35 ++++++++++++++----- 5 files changed, 57 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/m2049r/xmrwallet/SubaddressFragment.java b/app/src/main/java/com/m2049r/xmrwallet/SubaddressFragment.java index 45c0678a..9c83f5c8 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/SubaddressFragment.java +++ b/app/src/main/java/com/m2049r/xmrwallet/SubaddressFragment.java @@ -48,7 +48,7 @@ import lombok.RequiredArgsConstructor; import timber.log.Timber; public class SubaddressFragment extends Fragment implements SubaddressInfoAdapter.OnInteractionListener, - View.OnClickListener { + View.OnClickListener, OnBlockUpdateListener { static public final String KEY_MODE = "mode"; static public final String MODE_MANAGER = "manager"; @@ -169,6 +169,11 @@ public class SubaddressFragment extends Fragment implements SubaddressInfoAdapte adapter.setInfos(list); } + @Override + public void onBlockUpdate(Wallet wallet) { + loadList(); + } + @Override public void onClick(View v) { int id = v.getId(); diff --git a/app/src/main/java/com/m2049r/xmrwallet/data/Subaddress.java b/app/src/main/java/com/m2049r/xmrwallet/data/Subaddress.java index 6a79dfdb..582ce878 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/data/Subaddress.java +++ b/app/src/main/java/com/m2049r/xmrwallet/data/Subaddress.java @@ -18,12 +18,13 @@ package com.m2049r.xmrwallet.data; import java.util.regex.Pattern; -import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; import lombok.ToString; -@AllArgsConstructor +@RequiredArgsConstructor @ToString @EqualsAndHashCode public class Subaddress implements Comparable { @@ -35,6 +36,9 @@ public class Subaddress implements Comparable { final private String address; @Getter private final String label; + @Getter + @Setter + private long amount; @Override public int compareTo(Subaddress another) { // newer is < diff --git a/app/src/main/java/com/m2049r/xmrwallet/layout/SubaddressInfoAdapter.java b/app/src/main/java/com/m2049r/xmrwallet/layout/SubaddressInfoAdapter.java index 7edb2d59..6dab3490 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/layout/SubaddressInfoAdapter.java +++ b/app/src/main/java/com/m2049r/xmrwallet/layout/SubaddressInfoAdapter.java @@ -28,6 +28,7 @@ import androidx.recyclerview.widget.RecyclerView; import com.m2049r.xmrwallet.R; import com.m2049r.xmrwallet.data.Subaddress; +import com.m2049r.xmrwallet.util.Helper; import java.util.ArrayList; import java.util.Collections; @@ -110,12 +111,14 @@ public class SubaddressInfoAdapter extends RecyclerView.Adapter 0) + tvAmount.setText(context.getString(R.string.tx_list_amount_positive, + Helper.getDisplayAmount(amount, Helper.DISPLAY_DIGITS_INFO))); + else + tvAmount.setText(""); } @Override diff --git a/app/src/main/java/com/m2049r/xmrwallet/model/Wallet.java b/app/src/main/java/com/m2049r/xmrwallet/model/Wallet.java index 765ad731..103a50a3 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/model/Wallet.java +++ b/app/src/main/java/com/m2049r/xmrwallet/model/Wallet.java @@ -173,7 +173,16 @@ public class Wallet { } public Subaddress getSubaddressObject(int subAddressIndex) { - return getSubaddressObject(accountIndex, subAddressIndex); + Subaddress subaddress = getSubaddressObject(accountIndex, subAddressIndex); + long amount = 0; + for (TransactionInfo info : getHistory().getAll()) { + if ((info.addressIndex == subAddressIndex) + && (info.direction == TransactionInfo.Direction.Direction_In)) { + amount += info.amount; + } + } + subaddress.setAmount(amount); + return subaddress; } public native String getPath(); diff --git a/app/src/main/res/layout/item_subaddress.xml b/app/src/main/res/layout/item_subaddress.xml index 28374d1f..059f11dc 100644 --- a/app/src/main/res/layout/item_subaddress.xml +++ b/app/src/main/res/layout/item_subaddress.xml @@ -1,16 +1,16 @@ - + - - \ No newline at end of file + + + + +