show total incoming amount (#745)

This commit is contained in:
m2049r 2021-04-18 19:16:52 +02:00 committed by GitHub
parent beb098adb3
commit 394d5471e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 57 additions and 13 deletions

View File

@ -48,7 +48,7 @@ import lombok.RequiredArgsConstructor;
import timber.log.Timber; import timber.log.Timber;
public class SubaddressFragment extends Fragment implements SubaddressInfoAdapter.OnInteractionListener, public class SubaddressFragment extends Fragment implements SubaddressInfoAdapter.OnInteractionListener,
View.OnClickListener { View.OnClickListener, OnBlockUpdateListener {
static public final String KEY_MODE = "mode"; static public final String KEY_MODE = "mode";
static public final String MODE_MANAGER = "manager"; static public final String MODE_MANAGER = "manager";
@ -169,6 +169,11 @@ public class SubaddressFragment extends Fragment implements SubaddressInfoAdapte
adapter.setInfos(list); adapter.setInfos(list);
} }
@Override
public void onBlockUpdate(Wallet wallet) {
loadList();
}
@Override @Override
public void onClick(View v) { public void onClick(View v) {
int id = v.getId(); int id = v.getId();

View File

@ -18,12 +18,13 @@ package com.m2049r.xmrwallet.data;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString; import lombok.ToString;
@AllArgsConstructor @RequiredArgsConstructor
@ToString @ToString
@EqualsAndHashCode @EqualsAndHashCode
public class Subaddress implements Comparable<Subaddress> { public class Subaddress implements Comparable<Subaddress> {
@ -35,6 +36,9 @@ public class Subaddress implements Comparable<Subaddress> {
final private String address; final private String address;
@Getter @Getter
private final String label; private final String label;
@Getter
@Setter
private long amount;
@Override @Override
public int compareTo(Subaddress another) { // newer is < public int compareTo(Subaddress another) { // newer is <

View File

@ -28,6 +28,7 @@ import androidx.recyclerview.widget.RecyclerView;
import com.m2049r.xmrwallet.R; import com.m2049r.xmrwallet.R;
import com.m2049r.xmrwallet.data.Subaddress; import com.m2049r.xmrwallet.data.Subaddress;
import com.m2049r.xmrwallet.util.Helper;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -110,12 +111,14 @@ public class SubaddressInfoAdapter extends RecyclerView.Adapter<SubaddressInfoAd
class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener { class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
final TextView tvName; final TextView tvName;
final TextView tvAddress; final TextView tvAddress;
final TextView tvAmount;
Subaddress item; Subaddress item;
ViewHolder(View itemView) { ViewHolder(View itemView) {
super(itemView); super(itemView);
tvName = itemView.findViewById(R.id.tvName); tvName = itemView.findViewById(R.id.tvName);
tvAddress = itemView.findViewById(R.id.tvAddress); tvAddress = itemView.findViewById(R.id.tvAddress);
tvAmount = itemView.findViewById(R.id.tx_amount);
itemView.setOnClickListener(this); itemView.setOnClickListener(this);
itemView.setOnLongClickListener(this); itemView.setOnLongClickListener(this);
} }
@ -129,6 +132,12 @@ public class SubaddressInfoAdapter extends RecyclerView.Adapter<SubaddressInfoAd
item.getAddressIndex(), item.getSquashedAddress()); item.getAddressIndex(), item.getSquashedAddress());
tvName.setText(label.isEmpty() ? address : label); tvName.setText(label.isEmpty() ? address : label);
tvAddress.setText(address); tvAddress.setText(address);
final long amount = item.getAmount();
if (amount > 0)
tvAmount.setText(context.getString(R.string.tx_list_amount_positive,
Helper.getDisplayAmount(amount, Helper.DISPLAY_DIGITS_INFO)));
else
tvAmount.setText("");
} }
@Override @Override

View File

@ -173,7 +173,16 @@ public class Wallet {
} }
public Subaddress getSubaddressObject(int subAddressIndex) { 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(); public native String getPath();

View File

@ -1,16 +1,16 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android" <com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
android:layout_margin="8dp"> android:layout_margin="8dp">
<LinearLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="fill_parent" android:layout_width="match_parent"
android:orientation="vertical" android:layout_height="match_parent"
android:padding="8dp" android:padding="8dp">
android:layout_height="wrap_content">
<TextView <TextView
android:id="@+id/tvName" android:id="@+id/tvName"
@ -19,14 +19,31 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingStart="8dp" android:paddingStart="8dp"
android:paddingEnd="8dp" android:paddingEnd="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="My First Subaddress" /> tools:text="My First Subaddress" />
<TextView <TextView
android:id="@+id/tvAddress" android:id="@+id/tvAddress"
style="@style/MoneroText.Small" style="@style/MoneroText.Small"
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_marginTop="4dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="4dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvName"
tools:text="#1: 8AioXCmK...aGivEa7C" /> tools:text="#1: 8AioXCmK...aGivEa7C" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView> <TextView
android:id="@+id/tx_amount"
style="@style/MoneroText.PosAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/tvAddress"
android:textColor="@color/tx_plus"
app:layout_constraintBottom_toBottomOf="@id/tvName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="+ 999.999999" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>