From 3545b0ded67c3ee99eb9c7a503aa414583d95cef Mon Sep 17 00:00:00 2001 From: pokkst Date: Mon, 10 Jul 2023 02:25:28 -0500 Subject: [PATCH] Finally fixed the fucking bug (0.4.4.4) --- app/build.gradle | 4 +- .../wallet/adapter/CoinsInfoAdapter.java | 88 ++++++++++++------- .../wallet/fragment/utxos/UtxosFragment.java | 12 +-- .../mynero/wallet/service/UTXOService.java | 5 +- 4 files changed, 69 insertions(+), 40 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index e2d8122..db62f06 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "net.mynero.wallet" minSdkVersion 21 targetSdkVersion 34 - versionCode 40403 - versionName "0.4.4.3 'Fluorine Fermi'" + versionCode 40404 + versionName "0.4.4.4 'Fluorine Fermi'" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" externalNativeBuild { cmake { diff --git a/app/src/main/java/net/mynero/wallet/adapter/CoinsInfoAdapter.java b/app/src/main/java/net/mynero/wallet/adapter/CoinsInfoAdapter.java index 2b7cbf0..caf0db3 100644 --- a/app/src/main/java/net/mynero/wallet/adapter/CoinsInfoAdapter.java +++ b/app/src/main/java/net/mynero/wallet/adapter/CoinsInfoAdapter.java @@ -21,6 +21,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.TextView; +import androidx.annotation.NonNull; import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.RecyclerView; @@ -32,14 +33,16 @@ import net.mynero.wallet.util.Constants; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Objects; public class CoinsInfoAdapter extends RecyclerView.Adapter { - private List localDataSet; - private final ArrayList selectedUtxos; + private List localDataSet; // + private final HashMap selectedUtxos; // private CoinsInfoAdapterListener listener = null; + private boolean editing = false; /** * Initialize the dataset of the Adapter. @@ -47,34 +50,41 @@ public class CoinsInfoAdapter extends RecyclerView.Adapter(); - this.selectedUtxos = new ArrayList<>(); + this.selectedUtxos = new HashMap<>(); } - public void submitList(List dataSet) { - this.localDataSet = dataSet; + public void submitList(HashMap dataSet) { + this.localDataSet = new ArrayList<>(dataSet.values()); notifyDataSetChanged(); } public void deselectUtxo(CoinsInfo coinsInfo) { - this.selectedUtxos.remove(coinsInfo); + this.selectedUtxos.remove(coinsInfo.getPubKey()); + + if(this.selectedUtxos.size() == 0) { + editing = false; + } + notifyDataSetChanged(); } public void selectUtxo(CoinsInfo coinsInfo) { - this.selectedUtxos.add(coinsInfo); + editing = true; + this.selectedUtxos.put(coinsInfo.getPubKey(), coinsInfo); notifyDataSetChanged(); } public boolean contains(CoinsInfo coinsInfo) { - return this.selectedUtxos.contains(coinsInfo); + return selectedUtxos.containsKey(coinsInfo.getPubKey()); } public void clear() { this.selectedUtxos.clear(); + editing = false; notifyDataSetChanged(); } - public List getSelectedUtxos() { + public HashMap getSelectedUtxos() { return selectedUtxos; } @@ -85,14 +95,14 @@ public class CoinsInfoAdapter extends RecyclerView.Adapter selectedUtxos) { - boolean selected = false; - for(CoinsInfo selectedUtxo : selectedUtxos) { - if (Objects.equals(selectedUtxo.getKeyImage(), coinsInfo.getKeyImage())) { - selected = true; - break; - } - } + public void bind(boolean editing, CoinsInfo coinsInfo, HashMap selectedUtxos) { + this.editing = editing; + this.coinsInfo = coinsInfo; + boolean selected = selectedUtxos.containsKey(coinsInfo.getPubKey()); TextView pubKeyTextView = itemView.findViewById(R.id.utxo_pub_key_textview); TextView amountTextView = itemView.findViewById(R.id.utxo_amount_textview); @@ -133,15 +146,6 @@ public class CoinsInfoAdapter extends RecyclerView.Adapter { - boolean unlocked = coinsInfo.isUnlocked(); - if (unlocked) { - listener.onUtxoSelected(coinsInfo); - } - return unlocked; - }); - if (selected) { itemView.setBackgroundColor(ContextCompat.getColor(itemView.getContext(), R.color.oled_colorSecondary)); } else if(coinsInfo.isFrozen()) { @@ -152,6 +156,30 @@ public class CoinsInfoAdapter extends RecyclerView.Adapter { ArrayList selectedKeyImages = new ArrayList<>(); - for(CoinsInfo coinsInfo : adapter.getSelectedUtxos()) { + for(CoinsInfo coinsInfo : adapter.getSelectedUtxos().values()) { selectedKeyImages.add(coinsInfo.getKeyImage()); } SendBottomSheetDialog sendDialog = new SendBottomSheetDialog(); @@ -80,7 +81,7 @@ public class UtxosFragment extends Fragment implements CoinsInfoAdapter.CoinsInf }); churnUtxosButton.setOnClickListener(view1 -> { ArrayList selectedKeyImages = new ArrayList<>(); - for(CoinsInfo coinsInfo : adapter.getSelectedUtxos()) { + for(CoinsInfo coinsInfo : adapter.getSelectedUtxos().values()) { selectedKeyImages.add(coinsInfo.getKeyImage()); } SendBottomSheetDialog sendDialog = new SendBottomSheetDialog(); @@ -99,13 +100,12 @@ public class UtxosFragment extends Fragment implements CoinsInfoAdapter.CoinsInf utxosRecyclerView.setAdapter(adapter); if (utxoService != null) { utxoService.utxos.observe(getViewLifecycleOwner(), utxos -> { - ArrayList filteredUtxos = new ArrayList<>(); + HashMap filteredUtxos = new HashMap<>(); for (CoinsInfo coinsInfo : utxos) { if (!coinsInfo.isSpent()) { - filteredUtxos.add(coinsInfo); + filteredUtxos.put(coinsInfo.getPubKey(), coinsInfo); } } - Collections.sort(filteredUtxos); if (filteredUtxos.isEmpty()) { utxosRecyclerView.setVisibility(View.GONE); } else { @@ -126,7 +126,7 @@ public class UtxosFragment extends Fragment implements CoinsInfoAdapter.CoinsInf } boolean frozenExists = false, unfrozenExists = false, bothExist = false; - for(CoinsInfo selectedUtxo : adapter.getSelectedUtxos()) { + for(CoinsInfo selectedUtxo : adapter.getSelectedUtxos().values()) { if(selectedUtxo.isFrozen()) frozenExists = true; else { diff --git a/app/src/main/java/net/mynero/wallet/service/UTXOService.java b/app/src/main/java/net/mynero/wallet/service/UTXOService.java index a19fe9f..786ebb7 100644 --- a/app/src/main/java/net/mynero/wallet/service/UTXOService.java +++ b/app/src/main/java/net/mynero/wallet/service/UTXOService.java @@ -13,6 +13,7 @@ import net.mynero.wallet.model.WalletManager; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; public class UTXOService extends ServiceBase { @@ -37,9 +38,9 @@ public class UTXOService extends ServiceBase { return WalletManager.getInstance().getWallet().getCoins().getAll(); } - public void toggleFrozen(List selectedCoins) { + public void toggleFrozen(HashMap selectedCoins) { Coins coins = WalletManager.getInstance().getWallet().getCoins(); - for(CoinsInfo coin : selectedCoins) { + for(CoinsInfo coin : selectedCoins.values()) { coins.setFrozen(coin.getPubKey(), !coin.isFrozen()); } refreshUtxos();