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"
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 {

View file

@ -37,7 +37,7 @@ import java.util.Objects;
public class CoinsInfoAdapter extends RecyclerView.Adapter<CoinsInfoAdapter.ViewHolder> {
private List<CoinsInfo> localDataSet;
private List<CoinsInfo> selectedUtxos;
private ArrayList<CoinsInfo> selectedUtxos;
private CoinsInfoAdapterListener listener = null;
/**
@ -49,17 +49,34 @@ public class CoinsInfoAdapter extends RecyclerView.Adapter<CoinsInfoAdapter.View
this.selectedUtxos = new ArrayList<>();
}
public void submitList(List<CoinsInfo> dataSet, List<CoinsInfo> selectedUtxos) {
public void submitList(List<CoinsInfo> dataSet) {
this.localDataSet = dataSet;
this.selectedUtxos = selectedUtxos;
notifyDataSetChanged();
}
public void updateSelectedUtxos(List<CoinsInfo> 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<CoinsInfo> 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<CoinsInfoAdapter.View
View view = LayoutInflater.from(viewGroup.getContext())
.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)
@Override
public void onBindViewHolder(ViewHolder viewHolder, final int 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)
@ -92,15 +109,11 @@ public class CoinsInfoAdapter extends RecyclerView.Adapter<CoinsInfoAdapter.View
* (custom ViewHolder).
*/
public static class ViewHolder extends RecyclerView.ViewHolder {
private CoinsInfoAdapterListener listener = null;
public ViewHolder(CoinsInfoAdapterListener listener, View view) {
public ViewHolder(View view) {
super(view);
this.listener = listener;
}
public void bind(CoinsInfo coinsInfo, List<CoinsInfo> selectedUtxos) {
boolean alreadyEditing = selectedUtxos.size() > 0;
public void bind(CoinsInfoAdapterListener listener, CoinsInfo coinsInfo, List<CoinsInfo> 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<CoinsInfoAdapter.View
break;
}
}
boolean alreadyEditing = selectedUtxos.size() > 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<CoinsInfoAdapter.View
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()));
if(alreadyEditing) {
itemView.setOnClickListener(view -> {
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));

View file

@ -30,16 +30,10 @@ import java.util.List;
public class UtxosFragment extends Fragment implements CoinsInfoAdapter.CoinsInfoAdapterListener, SendBottomSheetDialog.Listener {
private UtxosViewModel mViewModel;
private final ArrayList<CoinsInfo> 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<String> 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<String> 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);