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.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentActivity;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
@ -204,24 +205,27 @@ public class SendBottomSheetDialog extends BottomSheetDialogFragment {
});
createButton.setOnClickListener(view1 -> {
boolean sendAll = sendingMax.getValue() != null ? sendingMax.getValue() : false;
String address = addressEditText.getText().toString().trim();
String amount = amountEditText.getText().toString().trim();
boolean validAddress = Wallet.isAddressValid(address);
if (validAddress && (!amount.isEmpty() || sendAll)) {
long amountRaw = Wallet.getAmountFromString(amount);
long balance = BalanceService.getInstance().getUnlockedBalanceRaw();
if ((amountRaw >= balance || amountRaw <= 0) && !sendAll) {
Toast.makeText(getActivity(), getString(R.string.send_amount_invalid), Toast.LENGTH_SHORT).show();
return;
FragmentActivity activity = getActivity();
if(activity != null) {
boolean sendAll = sendingMax.getValue() != null ? sendingMax.getValue() : false;
String address = addressEditText.getText().toString().trim();
String amount = amountEditText.getText().toString().trim();
boolean validAddress = Wallet.isAddressValid(address);
if (validAddress && (!amount.isEmpty() || sendAll)) {
long amountRaw = Wallet.getAmountFromString(amount);
long balance = BalanceService.getInstance().getUnlockedBalanceRaw();
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) {
((MoneroApplication)getActivity().getApplication()).getExecutor().execute(() -> {
boolean success = TxService.getInstance().sendTx(pendingTx);
Activity activity = getActivity();
if (activity != null) {
Activity activity = getActivity();
if (activity != null) {
((MoneroApplication) activity.getApplication()).getExecutor().execute(() -> {
boolean success = TxService.getInstance().sendTx(pendingTx);
activity.runOnUiThread(() -> {
if (success) {
Toast.makeText(getActivity(), getString(R.string.sent_tx), Toast.LENGTH_SHORT).show();
if(listener != null) {
Toast.makeText(activity, getString(R.string.sent_tx), Toast.LENGTH_SHORT).show();
if (listener != null) {
listener.onSentTransaction();
}
dismiss();
} else {
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) {
((MoneroApplication)getActivity().getApplication()).getExecutor().execute(() -> {
try {
PendingTransaction pendingTx = TxService.getInstance().createTx(address, amount, sendAll, feePriority, selectedUtxos);
if (pendingTx != null && pendingTx.getStatus() == PendingTransaction.Status.Status_Ok) {
_pendingTransaction.postValue(pendingTx);
} else {
Activity activity = getActivity();
if (activity != null) {
Activity activity = getActivity();
if (activity != null) {
((MoneroApplication)activity.getApplication()).getExecutor().execute(() -> {
try {
PendingTransaction pendingTx = TxService.getInstance().createTx(address, amount, sendAll, feePriority, selectedUtxos);
if (pendingTx != null && pendingTx.getStatus() == PendingTransaction.Status.Status_Ok) {
_pendingTransaction.postValue(pendingTx);
} else {
activity.runOnUiThread(() -> {
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) {
Activity activity = getActivity();
if (activity != null) {
} catch (Exception e) {
activity.runOnUiThread(() -> {
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) {

View File

@ -92,7 +92,7 @@ public class HomeFragment extends Fragment implements TransactionInfoAdapter.TxI
if (balanceService != null) {
balanceService.balanceInfo.observe(getViewLifecycleOwner(), balanceInfo -> {
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()) {
lockedBalanceTextView.setVisibility(View.INVISIBLE);

View File

@ -111,7 +111,7 @@ public class SendFragment extends Fragment {
}
private void init() {
addOutput();
addOutput(true);
}
private void bindListeners() {
@ -131,7 +131,7 @@ public class SendFragment extends Fragment {
sendMaxButton.setVisibility(View.GONE);
int outputCount = getDestCount();
if(outputCount < 8) {
addOutput();
addOutput(false);
} else {
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) {
int index = getDestCount();
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 -> {
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.remove_output_imagebutton).setOnClickListener(view -> {
int currentCount = getDestCount();
if(currentCount > 1) {
destList.removeView(entryView);
}
});
if(initial) {
removeOutputImageButton.setVisibility(View.INVISIBLE);
} else {
removeOutputImageButton.setOnClickListener(view -> {
int currentCount = getDestCount();
if (currentCount > 1) {
if (currentCount == 2) {
sendMaxButton.setVisibility(View.VISIBLE);
}
destList.removeView(entryView);
}
});
}
destList.addView(entryView);
}
}
@ -254,14 +261,14 @@ public class SendFragment extends Fragment {
private void unprepareMaxSend() {
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);
}
private void prepareOutputsForMaxSend() {
ConstraintLayout entryView = getDestView(0);
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) {

View File

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

View File

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

View File

@ -22,14 +22,13 @@
<!-- 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="send_amount_empty">Please enter an amount</string>
<string name="send_amount_invalid">Please enter a valid amount</string>
<string name="send_max">Max</string>
<string name="undo">Undo</string>
<string name="error_sending_tx">Error sending tx</string>
<string name="error_creating_tx">Error creating tx</string>
<string name="error_sending_tx">Error sending transaction</string>
<string name="error_creating_tx">Error creating: %1$s</string>
<string name="create_wallet">Create wallet</string>
<string name="invalid_mnemonic_code">Invalid mnemonic</string>
<string name="invalid_confirmed_password">Passwords do not match</string>