Layout tweaks and fixes

This commit is contained in:
pokkst 2023-02-02 12:18:33 -06:00
parent 8daa08bd6b
commit eee3536a99
No known key found for this signature in database
GPG key ID: 90C2ED85E67A50FF
6 changed files with 75 additions and 66 deletions

View file

@ -17,6 +17,7 @@ import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts; import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentActivity;
import androidx.lifecycle.LiveData; import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.MutableLiveData;
@ -204,24 +205,27 @@ public class SendBottomSheetDialog extends BottomSheetDialogFragment {
}); });
createButton.setOnClickListener(view1 -> { createButton.setOnClickListener(view1 -> {
boolean sendAll = sendingMax.getValue() != null ? sendingMax.getValue() : false; FragmentActivity activity = getActivity();
String address = addressEditText.getText().toString().trim(); if(activity != null) {
String amount = amountEditText.getText().toString().trim(); boolean sendAll = sendingMax.getValue() != null ? sendingMax.getValue() : false;
boolean validAddress = Wallet.isAddressValid(address); String address = addressEditText.getText().toString().trim();
if (validAddress && (!amount.isEmpty() || sendAll)) { String amount = amountEditText.getText().toString().trim();
long amountRaw = Wallet.getAmountFromString(amount); boolean validAddress = Wallet.isAddressValid(address);
long balance = BalanceService.getInstance().getUnlockedBalanceRaw(); if (validAddress && (!amount.isEmpty() || sendAll)) {
if ((amountRaw >= balance || amountRaw <= 0) && !sendAll) { long amountRaw = Wallet.getAmountFromString(amount);
Toast.makeText(getActivity(), getString(R.string.send_amount_invalid), Toast.LENGTH_SHORT).show(); long balance = BalanceService.getInstance().getUnlockedBalanceRaw();
return; if ((amountRaw >= balance || amountRaw <= 0) && !sendAll) {
Toast.makeText(activity, getString(R.string.send_amount_invalid), Toast.LENGTH_SHORT).show();
return;
}
Toast.makeText(activity, getString(R.string.creating_tx), Toast.LENGTH_SHORT).show();
createButton.setEnabled(false);
createTx(address, amount, sendAll, priority);
} else if (!validAddress) {
Toast.makeText(activity, getString(R.string.send_address_invalid), Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(activity, getString(R.string.send_amount_empty), Toast.LENGTH_SHORT).show();
} }
Toast.makeText(getActivity(), getString(R.string.creating_tx), Toast.LENGTH_SHORT).show();
createButton.setEnabled(false);
createTx(address, amount, sendAll, priority);
} else if (!validAddress) {
Toast.makeText(getActivity(), getString(R.string.send_address_invalid), Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getActivity(), getString(R.string.send_amount_empty), Toast.LENGTH_SHORT).show();
} }
}); });
@ -247,51 +251,50 @@ public class SendBottomSheetDialog extends BottomSheetDialogFragment {
} }
private void sendTx(PendingTransaction pendingTx) { private void sendTx(PendingTransaction pendingTx) {
((MoneroApplication)getActivity().getApplication()).getExecutor().execute(() -> { Activity activity = getActivity();
boolean success = TxService.getInstance().sendTx(pendingTx); if (activity != null) {
Activity activity = getActivity(); ((MoneroApplication) activity.getApplication()).getExecutor().execute(() -> {
if (activity != null) { boolean success = TxService.getInstance().sendTx(pendingTx);
activity.runOnUiThread(() -> { activity.runOnUiThread(() -> {
if (success) { if (success) {
Toast.makeText(getActivity(), getString(R.string.sent_tx), Toast.LENGTH_SHORT).show(); Toast.makeText(activity, getString(R.string.sent_tx), Toast.LENGTH_SHORT).show();
if(listener != null) { if (listener != null) {
listener.onSentTransaction(); listener.onSentTransaction();
} }
dismiss(); dismiss();
} else { } else {
sendButton.setEnabled(true); sendButton.setEnabled(true);
Toast.makeText(getActivity(), getString(R.string.error_sending_tx), Toast.LENGTH_SHORT).show(); Toast.makeText(activity, getString(R.string.error_sending_tx), Toast.LENGTH_SHORT).show();
} }
}); });
} });
}); }
} }
private void createTx(String address, String amount, boolean sendAll, PendingTransaction.Priority feePriority) { private void createTx(String address, String amount, boolean sendAll, PendingTransaction.Priority feePriority) {
((MoneroApplication)getActivity().getApplication()).getExecutor().execute(() -> { Activity activity = getActivity();
try { if (activity != null) {
PendingTransaction pendingTx = TxService.getInstance().createTx(address, amount, sendAll, feePriority, selectedUtxos); ((MoneroApplication)activity.getApplication()).getExecutor().execute(() -> {
if (pendingTx != null && pendingTx.getStatus() == PendingTransaction.Status.Status_Ok) { try {
_pendingTransaction.postValue(pendingTx); PendingTransaction pendingTx = TxService.getInstance().createTx(address, amount, sendAll, feePriority, selectedUtxos);
} else { if (pendingTx != null && pendingTx.getStatus() == PendingTransaction.Status.Status_Ok) {
Activity activity = getActivity(); _pendingTransaction.postValue(pendingTx);
if (activity != null) { } else {
activity.runOnUiThread(() -> { activity.runOnUiThread(() -> {
createButton.setEnabled(true); createButton.setEnabled(true);
Toast.makeText(getActivity(), getString(R.string.error_creating_tx), Toast.LENGTH_SHORT).show(); if(pendingTx != null) {
Toast.makeText(activity, getString(R.string.error_creating_tx, pendingTx.getErrorString()), Toast.LENGTH_SHORT).show();
}
}); });
} }
} } catch (Exception e) {
} catch (Exception e) {
Activity activity = getActivity();
if (activity != null) {
activity.runOnUiThread(() -> { activity.runOnUiThread(() -> {
createButton.setEnabled(true); createButton.setEnabled(true);
Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show(); Toast.makeText(activity, e.getMessage(), Toast.LENGTH_SHORT).show();
}); });
} }
} });
}); }
} }
private void showConfirmationLayout(boolean show) { private void showConfirmationLayout(boolean show) {

View file

@ -92,7 +92,7 @@ public class HomeFragment extends Fragment implements TransactionInfoAdapter.TxI
if (balanceService != null) { if (balanceService != null) {
balanceService.balanceInfo.observe(getViewLifecycleOwner(), balanceInfo -> { balanceService.balanceInfo.observe(getViewLifecycleOwner(), balanceInfo -> {
if(balanceInfo != null) { if(balanceInfo != null) {
unlockedBalanceTextView.setText(getString(R.string.wallet_balance_text, balanceInfo.getUnlockedDisplay())); unlockedBalanceTextView.setText(balanceInfo.getUnlockedDisplay());
if (balanceInfo.getLockedDisplay().equals(Constants.STREET_MODE_BALANCE) || balanceInfo.isLockedBalanceZero()) { if (balanceInfo.getLockedDisplay().equals(Constants.STREET_MODE_BALANCE) || balanceInfo.isLockedBalanceZero()) {
lockedBalanceTextView.setVisibility(View.INVISIBLE); lockedBalanceTextView.setVisibility(View.INVISIBLE);

View file

@ -111,7 +111,7 @@ public class SendFragment extends Fragment {
} }
private void init() { private void init() {
addOutput(); addOutput(true);
} }
private void bindListeners() { private void bindListeners() {
@ -131,7 +131,7 @@ public class SendFragment extends Fragment {
sendMaxButton.setVisibility(View.GONE); sendMaxButton.setVisibility(View.GONE);
int outputCount = getDestCount(); int outputCount = getDestCount();
if(outputCount < 8) { if(outputCount < 8) {
addOutput(); addOutput(false);
} else { } else {
Toast.makeText(getActivity(), getString(R.string.max_outputs_allowed), Toast.LENGTH_SHORT).show(); Toast.makeText(getActivity(), getString(R.string.max_outputs_allowed), Toast.LENGTH_SHORT).show();
} }
@ -214,11 +214,11 @@ public class SendFragment extends Fragment {
}); });
} }
private void addOutput() { private void addOutput(boolean initial) {
if (inflater != null) { if (inflater != null) {
int index = getDestCount(); int index = getDestCount();
ConstraintLayout entryView = (ConstraintLayout)inflater.inflate(R.layout.transaction_output_item, null); 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_address_imagebutton).setOnClickListener(view1 -> { entryView.findViewById(R.id.paste_address_imagebutton).setOnClickListener(view1 -> {
Context ctx = getContext(); Context ctx = getContext();
@ -230,12 +230,19 @@ public class SendFragment extends Fragment {
} }
}); });
entryView.findViewById(R.id.scan_address_imagebutton).setOnClickListener(view -> onScan(index)); entryView.findViewById(R.id.scan_address_imagebutton).setOnClickListener(view -> onScan(index));
entryView.findViewById(R.id.remove_output_imagebutton).setOnClickListener(view -> { if(initial) {
int currentCount = getDestCount(); removeOutputImageButton.setVisibility(View.INVISIBLE);
if(currentCount > 1) { } else {
destList.removeView(entryView); removeOutputImageButton.setOnClickListener(view -> {
} int currentCount = getDestCount();
}); if (currentCount > 1) {
if (currentCount == 2) {
sendMaxButton.setVisibility(View.VISIBLE);
}
destList.removeView(entryView);
}
});
}
destList.addView(entryView); destList.addView(entryView);
} }
} }
@ -254,14 +261,14 @@ public class SendFragment extends Fragment {
private void unprepareMaxSend() { private void unprepareMaxSend() {
ConstraintLayout entryView = getDestView(0); ConstraintLayout entryView = getDestView(0);
entryView.findViewById(R.id.sending_all_textview).setVisibility(View.GONE); entryView.findViewById(R.id.sending_all_textview).setVisibility(View.INVISIBLE);
entryView.findViewById(R.id.amount_edittext).setVisibility(View.VISIBLE); entryView.findViewById(R.id.amount_edittext).setVisibility(View.VISIBLE);
} }
private void prepareOutputsForMaxSend() { private void prepareOutputsForMaxSend() {
ConstraintLayout entryView = getDestView(0); ConstraintLayout entryView = getDestView(0);
entryView.findViewById(R.id.sending_all_textview).setVisibility(View.VISIBLE); entryView.findViewById(R.id.sending_all_textview).setVisibility(View.VISIBLE);
entryView.findViewById(R.id.amount_edittext).setVisibility(View.GONE); entryView.findViewById(R.id.amount_edittext).setVisibility(View.INVISIBLE);
} }
private void showConfirmationLayout(boolean show) { private void showConfirmationLayout(boolean show) {

View file

@ -24,13 +24,12 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="24dp" android:layout_marginStart="24dp"
android:layout_marginTop="24dp" android:layout_marginTop="24dp"
android:layout_marginEnd="24dp" android:textSize="32sp"
android:textSize="24sp"
android:textStyle="bold" android:textStyle="bold"
app:layout_constraintEnd_toStartOf="@id/settings_imageview" app:layout_constraintEnd_toStartOf="@id/settings_imageview"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
tools:text="100.000000000000 XMR" /> tools:text="100.000000000000" />
<TextView <TextView
android:id="@+id/balance_locked_textview" android:id="@+id/balance_locked_textview"
@ -40,7 +39,7 @@
android:layout_marginEnd="24dp" android:layout_marginEnd="24dp"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/settings_imageview" app:layout_constraintTop_toBottomOf="@id/balance_unlocked_textview"
tools:text="+ 100.000000000000 confirming" /> tools:text="+ 100.000000000000 confirming" />
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
@ -122,7 +121,7 @@
android:background="@drawable/button_bg_left" android:background="@drawable/button_bg_left"
android:text="@string/receive" android:text="@string/receive"
android:layout_marginEnd="1dp" android:layout_marginEnd="1dp"
android:layout_marginBottom="16dp" android:layout_marginBottom="24dp"
android:layout_marginStart="24dp" android:layout_marginStart="24dp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/send_button" app:layout_constraintEnd_toStartOf="@id/send_button"
@ -135,7 +134,7 @@
android:background="@drawable/button_bg_right" android:background="@drawable/button_bg_right"
android:text="@string/send" android:text="@string/send"
android:layout_marginStart="1dp" android:layout_marginStart="1dp"
android:layout_marginBottom="16dp" android:layout_marginBottom="24dp"
android:layout_marginEnd="24dp" android:layout_marginEnd="24dp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
@ -147,8 +146,8 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="24dp" android:layout_marginEnd="24dp"
android:minWidth="24dp" android:minWidth="48dp"
android:minHeight="24dp" android:minHeight="48dp"
android:padding="8dp" android:padding="8dp"
android:src="@drawable/ic_settings" android:src="@drawable/ic_settings"
app:layout_constraintBottom_toBottomOf="@id/balance_unlocked_textview" app:layout_constraintBottom_toBottomOf="@id/balance_unlocked_textview"

View file

@ -143,6 +143,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:paddingBottom="128dp"
android:clickable="false" android:clickable="false"
android:clipToPadding="false" android:clipToPadding="false"
android:orientation="vertical" android:orientation="vertical"

View file

@ -22,14 +22,13 @@
<!-- Strings used for fragments for navigation --> <!-- Strings used for fragments for navigation -->
<string name="wallet_balance_text">%1$s XMR</string>
<string name="wallet_locked_balance_text">+ %1$s confirming</string> <string name="wallet_locked_balance_text">+ %1$s confirming</string>
<string name="send_amount_empty">Please enter an amount</string> <string name="send_amount_empty">Please enter an amount</string>
<string name="send_amount_invalid">Please enter a valid amount</string> <string name="send_amount_invalid">Please enter a valid amount</string>
<string name="send_max">Max</string> <string name="send_max">Max</string>
<string name="undo">Undo</string> <string name="undo">Undo</string>
<string name="error_sending_tx">Error sending tx</string> <string name="error_sending_tx">Error sending transaction</string>
<string name="error_creating_tx">Error creating tx</string> <string name="error_creating_tx">Error creating: %1$s</string>
<string name="create_wallet">Create wallet</string> <string name="create_wallet">Create wallet</string>
<string name="invalid_mnemonic_code">Invalid mnemonic</string> <string name="invalid_mnemonic_code">Invalid mnemonic</string>
<string name="invalid_confirmed_password">Passwords do not match</string> <string name="invalid_confirmed_password">Passwords do not match</string>