UTXO list clicking fixes, and freeze button UI fixes (0.4.4.3)

This commit is contained in:
pokkst 2023-07-10 00:08:33 -05:00
parent a09e90e5d3
commit 792ba00c0f
No known key found for this signature in database
GPG key ID: 90C2ED85E67A50FF
3 changed files with 59 additions and 53 deletions

View file

@ -9,8 +9,8 @@ android {
applicationId "net.mynero.wallet" applicationId "net.mynero.wallet"
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 34 targetSdkVersion 34
versionCode 40402 versionCode 40403
versionName "0.4.4.2 'Fluorine Fermi'" versionName "0.4.4.3 'Fluorine Fermi'"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild { externalNativeBuild {
cmake { cmake {

View file

@ -37,7 +37,7 @@ import java.util.Objects;
public class CoinsInfoAdapter extends RecyclerView.Adapter<CoinsInfoAdapter.ViewHolder> { public class CoinsInfoAdapter extends RecyclerView.Adapter<CoinsInfoAdapter.ViewHolder> {
private List<CoinsInfo> localDataSet; private List<CoinsInfo> localDataSet;
private List<CoinsInfo> selectedUtxos; private ArrayList<CoinsInfo> selectedUtxos;
private CoinsInfoAdapterListener listener = null; private CoinsInfoAdapterListener listener = null;
/** /**
@ -49,17 +49,34 @@ public class CoinsInfoAdapter extends RecyclerView.Adapter<CoinsInfoAdapter.View
this.selectedUtxos = new ArrayList<>(); this.selectedUtxos = new ArrayList<>();
} }
public void submitList(List<CoinsInfo> dataSet, List<CoinsInfo> selectedUtxos) { public void submitList(List<CoinsInfo> dataSet) {
this.localDataSet = dataSet; this.localDataSet = dataSet;
this.selectedUtxos = selectedUtxos;
notifyDataSetChanged(); notifyDataSetChanged();
} }
public void updateSelectedUtxos(List<CoinsInfo> selectedUtxos) { public void deselectUtxo(CoinsInfo coinsInfo) {
this.selectedUtxos = selectedUtxos; this.selectedUtxos.remove(coinsInfo);
notifyDataSetChanged(); 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<CoinsInfo> getSelectedUtxos() {
return selectedUtxos;
}
// Create new views (invoked by the layout manager) // Create new views (invoked by the layout manager)
@Override @Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
@ -67,14 +84,14 @@ public class CoinsInfoAdapter extends RecyclerView.Adapter<CoinsInfoAdapter.View
View view = LayoutInflater.from(viewGroup.getContext()) View view = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.utxo_selection_item, viewGroup, false); .inflate(R.layout.utxo_selection_item, viewGroup, false);
return new ViewHolder(listener, view); return new ViewHolder(view);
} }
// Replace the contents of a view (invoked by the layout manager) // Replace the contents of a view (invoked by the layout manager)
@Override @Override
public void onBindViewHolder(ViewHolder viewHolder, final int position) { public void onBindViewHolder(ViewHolder viewHolder, final int position) {
CoinsInfo tx = localDataSet.get(position); CoinsInfo tx = localDataSet.get(position);
viewHolder.bind(tx, selectedUtxos); viewHolder.bind(listener, tx, selectedUtxos);
} }
// Return the size of your dataset (invoked by the layout manager) // Return the size of your dataset (invoked by the layout manager)
@ -92,15 +109,11 @@ public class CoinsInfoAdapter extends RecyclerView.Adapter<CoinsInfoAdapter.View
* (custom ViewHolder). * (custom ViewHolder).
*/ */
public static class ViewHolder extends RecyclerView.ViewHolder { public static class ViewHolder extends RecyclerView.ViewHolder {
private CoinsInfoAdapterListener listener = null; public ViewHolder(View view) {
public ViewHolder(CoinsInfoAdapterListener listener, View view) {
super(view); super(view);
this.listener = listener;
} }
public void bind(CoinsInfo coinsInfo, List<CoinsInfo> selectedUtxos) { public void bind(CoinsInfoAdapterListener listener, CoinsInfo coinsInfo, List<CoinsInfo> selectedUtxos) {
boolean alreadyEditing = selectedUtxos.size() > 0;
boolean selected = false; boolean selected = false;
for(CoinsInfo selectedUtxo : selectedUtxos) { for(CoinsInfo selectedUtxo : selectedUtxos) {
if (Objects.equals(selectedUtxo.getKeyImage(), coinsInfo.getKeyImage())) { if (Objects.equals(selectedUtxo.getKeyImage(), coinsInfo.getKeyImage())) {
@ -108,6 +121,8 @@ public class CoinsInfoAdapter extends RecyclerView.Adapter<CoinsInfoAdapter.View
break; break;
} }
} }
boolean alreadyEditing = selectedUtxos.size() > 0 || selected;
TextView pubKeyTextView = itemView.findViewById(R.id.utxo_pub_key_textview); TextView pubKeyTextView = itemView.findViewById(R.id.utxo_pub_key_textview);
TextView amountTextView = itemView.findViewById(R.id.utxo_amount_textview); TextView amountTextView = itemView.findViewById(R.id.utxo_amount_textview);
TextView globalIdxTextView = itemView.findViewById(R.id.utxo_global_index_textview); TextView globalIdxTextView = itemView.findViewById(R.id.utxo_global_index_textview);
@ -119,24 +134,21 @@ public class CoinsInfoAdapter extends RecyclerView.Adapter<CoinsInfoAdapter.View
globalIdxTextView.setText(itemView.getResources().getString(R.string.global_index_text, coinsInfo.getGlobalOutputIndex())); globalIdxTextView.setText(itemView.getResources().getString(R.string.global_index_text, coinsInfo.getGlobalOutputIndex()));
outpointTextView.setText(itemView.getResources().getString(R.string.outpoint_text, coinsInfo.getHash() + ":" + coinsInfo.getLocalOutputIndex())); outpointTextView.setText(itemView.getResources().getString(R.string.outpoint_text, coinsInfo.getHash() + ":" + coinsInfo.getLocalOutputIndex()));
if(alreadyEditing) { itemView.setOnClickListener(view -> {
itemView.setOnClickListener(view -> { if(!alreadyEditing) return;
boolean unlocked = coinsInfo.isUnlocked(); boolean unlocked = coinsInfo.isUnlocked();
if (unlocked) { if (unlocked) {
listener.onUtxoSelected(coinsInfo); listener.onUtxoSelected(coinsInfo);
} }
}); });
itemView.setOnLongClickListener(null); itemView.setOnLongClickListener(view -> {
} else { if(alreadyEditing) return false;
itemView.setOnLongClickListener(view -> { boolean unlocked = coinsInfo.isUnlocked();
boolean unlocked = coinsInfo.isUnlocked(); if (unlocked) {
if (unlocked) { listener.onUtxoSelected(coinsInfo);
listener.onUtxoSelected(coinsInfo); }
} return unlocked;
return unlocked; });
});
itemView.setOnClickListener(null);
}
if (selected) { if (selected) {
itemView.setBackgroundColor(ContextCompat.getColor(itemView.getContext(), R.color.oled_colorSecondary)); itemView.setBackgroundColor(ContextCompat.getColor(itemView.getContext(), R.color.oled_colorSecondary));

View file

@ -30,16 +30,10 @@ import java.util.List;
public class UtxosFragment extends Fragment implements CoinsInfoAdapter.CoinsInfoAdapterListener, SendBottomSheetDialog.Listener { public class UtxosFragment extends Fragment implements CoinsInfoAdapter.CoinsInfoAdapterListener, SendBottomSheetDialog.Listener {
private UtxosViewModel mViewModel; private UtxosViewModel mViewModel;
private final ArrayList<CoinsInfo> selectedUtxos = new ArrayList<>();
private final CoinsInfoAdapter adapter = new CoinsInfoAdapter(this); private final CoinsInfoAdapter adapter = new CoinsInfoAdapter(this);
private Button sendUtxosButton; private Button sendUtxosButton;
private Button churnUtxosButton; private Button churnUtxosButton;
private Button freezeUtxosButton; private Button freezeUtxosButton;
enum FreezeActionType {
FREEZE,
UNFREEZE,
TOGGLE_FREEZE
}
@Override @Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@ -65,10 +59,9 @@ public class UtxosFragment extends Fragment implements CoinsInfoAdapter.CoinsInf
freezeUtxosButton.setOnClickListener(view1 -> { freezeUtxosButton.setOnClickListener(view1 -> {
Toast.makeText(getContext(), "Toggling freeze status, please wait.", Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), "Toggling freeze status, please wait.", Toast.LENGTH_SHORT).show();
MoneroThreadPoolExecutor.MONERO_THREAD_POOL_EXECUTOR.execute(() -> { MoneroThreadPoolExecutor.MONERO_THREAD_POOL_EXECUTOR.execute(() -> {
UTXOService.getInstance().toggleFrozen(selectedUtxos); UTXOService.getInstance().toggleFrozen(adapter.getSelectedUtxos());
getActivity().runOnUiThread(() -> { getActivity().runOnUiThread(() -> {
selectedUtxos.clear(); adapter.clear();
adapter.updateSelectedUtxos(new ArrayList<>());
sendUtxosButton.setVisibility(View.GONE); sendUtxosButton.setVisibility(View.GONE);
churnUtxosButton.setVisibility(View.GONE); churnUtxosButton.setVisibility(View.GONE);
freezeUtxosButton.setVisibility(View.GONE); freezeUtxosButton.setVisibility(View.GONE);
@ -77,7 +70,7 @@ public class UtxosFragment extends Fragment implements CoinsInfoAdapter.CoinsInf
}); });
sendUtxosButton.setOnClickListener(view1 -> { sendUtxosButton.setOnClickListener(view1 -> {
ArrayList<String> selectedKeyImages = new ArrayList<>(); ArrayList<String> selectedKeyImages = new ArrayList<>();
for(CoinsInfo coinsInfo : selectedUtxos) { for(CoinsInfo coinsInfo : adapter.getSelectedUtxos()) {
selectedKeyImages.add(coinsInfo.getKeyImage()); selectedKeyImages.add(coinsInfo.getKeyImage());
} }
SendBottomSheetDialog sendDialog = new SendBottomSheetDialog(); SendBottomSheetDialog sendDialog = new SendBottomSheetDialog();
@ -87,7 +80,7 @@ public class UtxosFragment extends Fragment implements CoinsInfoAdapter.CoinsInf
}); });
churnUtxosButton.setOnClickListener(view1 -> { churnUtxosButton.setOnClickListener(view1 -> {
ArrayList<String> selectedKeyImages = new ArrayList<>(); ArrayList<String> selectedKeyImages = new ArrayList<>();
for(CoinsInfo coinsInfo : selectedUtxos) { for(CoinsInfo coinsInfo : adapter.getSelectedUtxos()) {
selectedKeyImages.add(coinsInfo.getKeyImage()); selectedKeyImages.add(coinsInfo.getKeyImage());
} }
SendBottomSheetDialog sendDialog = new SendBottomSheetDialog(); SendBottomSheetDialog sendDialog = new SendBottomSheetDialog();
@ -116,7 +109,7 @@ public class UtxosFragment extends Fragment implements CoinsInfoAdapter.CoinsInf
if (filteredUtxos.isEmpty()) { if (filteredUtxos.isEmpty()) {
utxosRecyclerView.setVisibility(View.GONE); utxosRecyclerView.setVisibility(View.GONE);
} else { } else {
adapter.submitList(filteredUtxos, selectedUtxos); adapter.submitList(filteredUtxos);
utxosRecyclerView.setVisibility(View.VISIBLE); utxosRecyclerView.setVisibility(View.VISIBLE);
} }
}); });
@ -125,15 +118,15 @@ public class UtxosFragment extends Fragment implements CoinsInfoAdapter.CoinsInf
@Override @Override
public void onUtxoSelected(CoinsInfo coinsInfo) { public void onUtxoSelected(CoinsInfo coinsInfo) {
boolean selected = selectedUtxos.contains(coinsInfo); boolean selected = adapter.contains(coinsInfo);
if (selected) { if (selected) {
selectedUtxos.remove(coinsInfo); adapter.deselectUtxo(coinsInfo);
} else { } else {
selectedUtxos.add(coinsInfo); adapter.selectUtxo(coinsInfo);
} }
boolean frozenExists = false, unfrozenExists = false, bothExist = false; boolean frozenExists = false, unfrozenExists = false, bothExist = false;
for(CoinsInfo selectedUtxo : selectedUtxos) { for(CoinsInfo selectedUtxo : adapter.getSelectedUtxos()) {
if(selectedUtxo.isFrozen()) if(selectedUtxo.isFrozen())
frozenExists = true; frozenExists = true;
else { else {
@ -142,23 +135,24 @@ public class UtxosFragment extends Fragment implements CoinsInfoAdapter.CoinsInf
} }
bothExist = frozenExists && unfrozenExists; bothExist = frozenExists && unfrozenExists;
if (selectedUtxos.isEmpty()) { if (adapter.getSelectedUtxos().isEmpty()) {
sendUtxosButton.setVisibility(View.GONE); sendUtxosButton.setVisibility(View.GONE);
churnUtxosButton.setVisibility(View.GONE); churnUtxosButton.setVisibility(View.GONE);
freezeUtxosButton.setVisibility(View.GONE); freezeUtxosButton.setVisibility(View.GONE);
freezeUtxosButton.setBackgroundResource(R.drawable.button_bg_left);
} else { } else {
if(frozenExists) { if(frozenExists) {
freezeUtxosButton.setBackgroundResource(R.drawable.button_bg);
sendUtxosButton.setVisibility(View.GONE); sendUtxosButton.setVisibility(View.GONE);
churnUtxosButton.setVisibility(View.GONE); churnUtxosButton.setVisibility(View.GONE);
} else { } else {
freezeUtxosButton.setBackgroundResource(R.drawable.button_bg_left);
sendUtxosButton.setVisibility(View.VISIBLE); sendUtxosButton.setVisibility(View.VISIBLE);
churnUtxosButton.setVisibility(View.VISIBLE); churnUtxosButton.setVisibility(View.VISIBLE);
} }
freezeUtxosButton.setVisibility(View.VISIBLE); freezeUtxosButton.setVisibility(View.VISIBLE);
} }
adapter.updateSelectedUtxos(selectedUtxos);
if(bothExist) { if(bothExist) {
freezeUtxosButton.setText(R.string.toggle_freeze); freezeUtxosButton.setText(R.string.toggle_freeze);
} else if(frozenExists) { } else if(frozenExists) {
@ -170,7 +164,7 @@ public class UtxosFragment extends Fragment implements CoinsInfoAdapter.CoinsInf
@Override @Override
public void onSentTransaction() { public void onSentTransaction() {
selectedUtxos.clear(); adapter.clear();
churnUtxosButton.setVisibility(View.GONE); churnUtxosButton.setVisibility(View.GONE);
sendUtxosButton.setVisibility(View.GONE); sendUtxosButton.setVisibility(View.GONE);
freezeUtxosButton.setVisibility(View.GONE); freezeUtxosButton.setVisibility(View.GONE);