From 792ba00c0feeaf799b8c57a7a10ec1493a248aae Mon Sep 17 00:00:00 2001 From: pokkst Date: Mon, 10 Jul 2023 00:08:33 -0500 Subject: [PATCH] UTXO list clicking fixes, and freeze button UI fixes (0.4.4.3) --- app/build.gradle | 4 +- .../wallet/adapter/CoinsInfoAdapter.java | 74 +++++++++++-------- .../wallet/fragment/utxos/UtxosFragment.java | 34 ++++----- 3 files changed, 59 insertions(+), 53 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 9b6507f..e2d8122 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "net.mynero.wallet" minSdkVersion 21 targetSdkVersion 34 - versionCode 40402 - versionName "0.4.4.2 'Fluorine Fermi'" + versionCode 40403 + versionName "0.4.4.3 '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 e989853..59df127 100644 --- a/app/src/main/java/net/mynero/wallet/adapter/CoinsInfoAdapter.java +++ b/app/src/main/java/net/mynero/wallet/adapter/CoinsInfoAdapter.java @@ -37,7 +37,7 @@ import java.util.Objects; public class CoinsInfoAdapter extends RecyclerView.Adapter { private List localDataSet; - private List selectedUtxos; + private ArrayList selectedUtxos; private CoinsInfoAdapterListener listener = null; /** @@ -49,17 +49,34 @@ public class CoinsInfoAdapter extends RecyclerView.Adapter(); } - public void submitList(List dataSet, List selectedUtxos) { + public void submitList(List dataSet) { this.localDataSet = dataSet; - this.selectedUtxos = selectedUtxos; notifyDataSetChanged(); } - public void updateSelectedUtxos(List selectedUtxos) { - this.selectedUtxos = selectedUtxos; + public void deselectUtxo(CoinsInfo coinsInfo) { + this.selectedUtxos.remove(coinsInfo); notifyDataSetChanged(); } + public void selectUtxo(CoinsInfo coinsInfo) { + this.selectedUtxos.add(coinsInfo); + notifyDataSetChanged(); + } + + public boolean contains(CoinsInfo coinsInfo) { + return this.selectedUtxos.contains(coinsInfo); + } + + public void clear() { + this.selectedUtxos.clear(); + notifyDataSetChanged(); + } + + public List getSelectedUtxos() { + return selectedUtxos; + } + // Create new views (invoked by the layout manager) @Override public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { @@ -67,14 +84,14 @@ public class CoinsInfoAdapter extends RecyclerView.Adapter selectedUtxos) { - boolean alreadyEditing = selectedUtxos.size() > 0; + public void bind(CoinsInfoAdapterListener listener, CoinsInfo coinsInfo, List selectedUtxos) { boolean selected = false; for(CoinsInfo selectedUtxo : selectedUtxos) { if (Objects.equals(selectedUtxo.getKeyImage(), coinsInfo.getKeyImage())) { @@ -108,6 +121,8 @@ public class CoinsInfoAdapter extends RecyclerView.Adapter 0 || selected; + TextView pubKeyTextView = itemView.findViewById(R.id.utxo_pub_key_textview); TextView amountTextView = itemView.findViewById(R.id.utxo_amount_textview); TextView globalIdxTextView = itemView.findViewById(R.id.utxo_global_index_textview); @@ -119,24 +134,21 @@ public class CoinsInfoAdapter extends RecyclerView.Adapter { - boolean unlocked = coinsInfo.isUnlocked(); - if (unlocked) { - listener.onUtxoSelected(coinsInfo); - } - }); - itemView.setOnLongClickListener(null); - } else { - itemView.setOnLongClickListener(view -> { - boolean unlocked = coinsInfo.isUnlocked(); - if (unlocked) { - listener.onUtxoSelected(coinsInfo); - } - return unlocked; - }); - itemView.setOnClickListener(null); - } + itemView.setOnClickListener(view -> { + if(!alreadyEditing) return; + boolean unlocked = coinsInfo.isUnlocked(); + if (unlocked) { + listener.onUtxoSelected(coinsInfo); + } + }); + itemView.setOnLongClickListener(view -> { + if(alreadyEditing) return false; + boolean unlocked = coinsInfo.isUnlocked(); + if (unlocked) { + listener.onUtxoSelected(coinsInfo); + } + return unlocked; + }); if (selected) { itemView.setBackgroundColor(ContextCompat.getColor(itemView.getContext(), R.color.oled_colorSecondary)); diff --git a/app/src/main/java/net/mynero/wallet/fragment/utxos/UtxosFragment.java b/app/src/main/java/net/mynero/wallet/fragment/utxos/UtxosFragment.java index d356c42..c970496 100644 --- a/app/src/main/java/net/mynero/wallet/fragment/utxos/UtxosFragment.java +++ b/app/src/main/java/net/mynero/wallet/fragment/utxos/UtxosFragment.java @@ -30,16 +30,10 @@ import java.util.List; public class UtxosFragment extends Fragment implements CoinsInfoAdapter.CoinsInfoAdapterListener, SendBottomSheetDialog.Listener { private UtxosViewModel mViewModel; - private final ArrayList selectedUtxos = new ArrayList<>(); private final CoinsInfoAdapter adapter = new CoinsInfoAdapter(this); private Button sendUtxosButton; private Button churnUtxosButton; private Button freezeUtxosButton; - enum FreezeActionType { - FREEZE, - UNFREEZE, - TOGGLE_FREEZE - } @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @@ -65,10 +59,9 @@ public class UtxosFragment extends Fragment implements CoinsInfoAdapter.CoinsInf freezeUtxosButton.setOnClickListener(view1 -> { Toast.makeText(getContext(), "Toggling freeze status, please wait.", Toast.LENGTH_SHORT).show(); MoneroThreadPoolExecutor.MONERO_THREAD_POOL_EXECUTOR.execute(() -> { - UTXOService.getInstance().toggleFrozen(selectedUtxos); + UTXOService.getInstance().toggleFrozen(adapter.getSelectedUtxos()); getActivity().runOnUiThread(() -> { - selectedUtxos.clear(); - adapter.updateSelectedUtxos(new ArrayList<>()); + adapter.clear(); sendUtxosButton.setVisibility(View.GONE); churnUtxosButton.setVisibility(View.GONE); freezeUtxosButton.setVisibility(View.GONE); @@ -77,7 +70,7 @@ public class UtxosFragment extends Fragment implements CoinsInfoAdapter.CoinsInf }); sendUtxosButton.setOnClickListener(view1 -> { ArrayList selectedKeyImages = new ArrayList<>(); - for(CoinsInfo coinsInfo : selectedUtxos) { + for(CoinsInfo coinsInfo : adapter.getSelectedUtxos()) { selectedKeyImages.add(coinsInfo.getKeyImage()); } SendBottomSheetDialog sendDialog = new SendBottomSheetDialog(); @@ -87,7 +80,7 @@ public class UtxosFragment extends Fragment implements CoinsInfoAdapter.CoinsInf }); churnUtxosButton.setOnClickListener(view1 -> { ArrayList selectedKeyImages = new ArrayList<>(); - for(CoinsInfo coinsInfo : selectedUtxos) { + for(CoinsInfo coinsInfo : adapter.getSelectedUtxos()) { selectedKeyImages.add(coinsInfo.getKeyImage()); } SendBottomSheetDialog sendDialog = new SendBottomSheetDialog(); @@ -116,7 +109,7 @@ public class UtxosFragment extends Fragment implements CoinsInfoAdapter.CoinsInf if (filteredUtxos.isEmpty()) { utxosRecyclerView.setVisibility(View.GONE); } else { - adapter.submitList(filteredUtxos, selectedUtxos); + adapter.submitList(filteredUtxos); utxosRecyclerView.setVisibility(View.VISIBLE); } }); @@ -125,15 +118,15 @@ public class UtxosFragment extends Fragment implements CoinsInfoAdapter.CoinsInf @Override public void onUtxoSelected(CoinsInfo coinsInfo) { - boolean selected = selectedUtxos.contains(coinsInfo); + boolean selected = adapter.contains(coinsInfo); if (selected) { - selectedUtxos.remove(coinsInfo); + adapter.deselectUtxo(coinsInfo); } else { - selectedUtxos.add(coinsInfo); + adapter.selectUtxo(coinsInfo); } boolean frozenExists = false, unfrozenExists = false, bothExist = false; - for(CoinsInfo selectedUtxo : selectedUtxos) { + for(CoinsInfo selectedUtxo : adapter.getSelectedUtxos()) { if(selectedUtxo.isFrozen()) frozenExists = true; else { @@ -142,23 +135,24 @@ public class UtxosFragment extends Fragment implements CoinsInfoAdapter.CoinsInf } bothExist = frozenExists && unfrozenExists; - if (selectedUtxos.isEmpty()) { + if (adapter.getSelectedUtxos().isEmpty()) { sendUtxosButton.setVisibility(View.GONE); churnUtxosButton.setVisibility(View.GONE); freezeUtxosButton.setVisibility(View.GONE); + freezeUtxosButton.setBackgroundResource(R.drawable.button_bg_left); } else { if(frozenExists) { + freezeUtxosButton.setBackgroundResource(R.drawable.button_bg); sendUtxosButton.setVisibility(View.GONE); churnUtxosButton.setVisibility(View.GONE); } else { + freezeUtxosButton.setBackgroundResource(R.drawable.button_bg_left); sendUtxosButton.setVisibility(View.VISIBLE); churnUtxosButton.setVisibility(View.VISIBLE); } freezeUtxosButton.setVisibility(View.VISIBLE); } - adapter.updateSelectedUtxos(selectedUtxos); - if(bothExist) { freezeUtxosButton.setText(R.string.toggle_freeze); } else if(frozenExists) { @@ -170,7 +164,7 @@ public class UtxosFragment extends Fragment implements CoinsInfoAdapter.CoinsInf @Override public void onSentTransaction() { - selectedUtxos.clear(); + adapter.clear(); churnUtxosButton.setVisibility(View.GONE); sendUtxosButton.setVisibility(View.GONE); freezeUtxosButton.setVisibility(View.GONE);