From 69c62ee713811e63727c42db804fac9b31304585 Mon Sep 17 00:00:00 2001 From: pokkst Date: Sat, 11 Feb 2023 09:19:49 -0600 Subject: [PATCH] Transaction output item now has two paste buttons, one for amount and one for address --- .../wallet/fragment/send/SendFragment.java | 30 +++++++++++++--- .../res/layout/transaction_output_item.xml | 36 +++++++++++++------ app/src/main/res/values/strings.xml | 1 + 3 files changed, 51 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/net/mynero/wallet/fragment/send/SendFragment.java b/app/src/main/java/net/mynero/wallet/fragment/send/SendFragment.java index 78acb02..41e53be 100644 --- a/app/src/main/java/net/mynero/wallet/fragment/send/SendFragment.java +++ b/app/src/main/java/net/mynero/wallet/fragment/send/SendFragment.java @@ -64,7 +64,7 @@ public class SendFragment extends Fragment { private final ActivityResultLauncher qrCodeLauncher = registerForActivityResult(new ScanContract(), result -> { if (result.getContents() != null) { if(currentEntryIndex != -1) { - pasteAddress(getDestView(currentEntryIndex), result.getContents()); + pasteAddress(getDestView(currentEntryIndex), result.getContents(), false); currentEntryIndex = -1; } } @@ -221,12 +221,21 @@ public class SendFragment extends Fragment { ConstraintLayout entryView = (ConstraintLayout)inflater.inflate(R.layout.transaction_output_item, null); ImageButton removeOutputImageButton = entryView.findViewById(R.id.remove_output_imagebutton); + entryView.findViewById(R.id.paste_amount_imagebutton).setOnClickListener(view1 -> { + Context ctx = getContext(); + if (ctx != null) { + String clipboard = Helper.getClipBoardText(ctx); + if (clipboard != null) { + pasteAddress(entryView, clipboard, true); + } + } + }); entryView.findViewById(R.id.paste_address_imagebutton).setOnClickListener(view1 -> { Context ctx = getContext(); if (ctx != null) { String clipboard = Helper.getClipBoardText(ctx); if (clipboard != null) { - pasteAddress(entryView, clipboard); + pasteAddress(entryView, clipboard, false); } } }); @@ -312,8 +321,8 @@ public class SendFragment extends Fragment { } } - private void pasteAddress(ConstraintLayout entryView, String address) { - UriData uriData = UriData.parse(address); + private void pasteAddress(ConstraintLayout entryView, String clipboard, boolean pastingAmount) { + UriData uriData = UriData.parse(clipboard); if (uriData != null) { EditText addressField = entryView.findViewById(R.id.address_edittext); addressField.setText(uriData.getAddress()); @@ -323,7 +332,18 @@ public class SendFragment extends Fragment { amountField.setText(uriData.getAmount()); } } else { - Toast.makeText(getActivity(), getString(R.string.send_address_invalid), Toast.LENGTH_SHORT).show(); + if(pastingAmount) { + try { + Double.parseDouble(clipboard); + sendMaxButton.setEnabled(false); + EditText amountField = entryView.findViewById(R.id.amount_edittext); + amountField.setText(clipboard); + } catch (Exception e) { + Toast.makeText(getActivity(), getString(R.string.send_amount_invalid), Toast.LENGTH_SHORT).show(); + } + } else { + Toast.makeText(getActivity(), getString(R.string.send_address_invalid), Toast.LENGTH_SHORT).show(); + } } } diff --git a/app/src/main/res/layout/transaction_output_item.xml b/app/src/main/res/layout/transaction_output_item.xml index ff9975b..0a3ac91 100644 --- a/app/src/main/res/layout/transaction_output_item.xml +++ b/app/src/main/res/layout/transaction_output_item.xml @@ -17,7 +17,7 @@ android:inputType="numberDecimal" app:layout_constraintTop_toTopOf="parent" app:layout_constraintBottom_toTopOf="@id/address_edittext" - app:layout_constraintEnd_toStartOf="@id/paste_address_imagebutton" + app:layout_constraintEnd_toStartOf="@id/paste_amount_imagebutton" app:layout_constraintStart_toStartOf="parent" tools:visibility="visible" /> @@ -54,17 +54,31 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginTop="8dp" - android:layout_marginEnd="24dp" android:layout_marginBottom="4dp" android:background="@drawable/edittext_bg" android:layout_marginStart="8dp" android:ellipsize="middle" android:hint="@string/address" android:singleLine="true" - app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintEnd_toStartOf="@id/paste_address_imagebutton" app:layout_constraintStart_toEndOf="@id/to_address_label_textview" app:layout_constraintTop_toBottomOf="@id/amount_edittext" tools:visibility="visible" /> + - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 073b75c..a811692 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -5,6 +5,7 @@ Incorrect password! Not a valid address + Not a valid amount failed - %1$s