From e87ff399d17216bf2d485567132f59eeed0865db Mon Sep 17 00:00:00 2001 From: pokkst Date: Mon, 19 Sep 2022 17:40:35 -0500 Subject: [PATCH] Disable send button when balance is 0 --- .../dialog/SendBottomSheetDialog.java | 64 +++++++++++-------- 1 file changed, 39 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/net/mynero/wallet/fragment/dialog/SendBottomSheetDialog.java b/app/src/main/java/net/mynero/wallet/fragment/dialog/SendBottomSheetDialog.java index 4c7b0e6..0f95f2e 100644 --- a/app/src/main/java/net/mynero/wallet/fragment/dialog/SendBottomSheetDialog.java +++ b/app/src/main/java/net/mynero/wallet/fragment/dialog/SendBottomSheetDialog.java @@ -19,6 +19,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.lifecycle.LiveData; import androidx.lifecycle.MutableLiveData; +import androidx.lifecycle.Observer; import com.google.android.material.bottomsheet.BottomSheetDialogFragment; import com.google.zxing.client.android.Intents; @@ -93,6 +94,44 @@ public class SendBottomSheetDialog extends BottomSheetDialogFragment { } } + bindObservers(); + bindListeners(); + } + + private void bindObservers() { + + BalanceService.getInstance().balance.observe(getViewLifecycleOwner(), balance -> { + createButton.setEnabled(balance != 0); + sendMaxButton.setEnabled(balance != 0); + }); + + sendingMax.observe(getViewLifecycleOwner(), sendingMax -> { + if (pendingTransaction.getValue() == null) { + if (sendingMax) { + amountEditText.setVisibility(View.INVISIBLE); + sendAllTextView.setVisibility(View.VISIBLE); + sendMaxButton.setText(getText(R.string.undo)); + } else { + amountEditText.setVisibility(View.VISIBLE); + sendAllTextView.setVisibility(View.GONE); + sendMaxButton.setText(getText(R.string.send_max)); + } + } + }); + + pendingTransaction.observe(getViewLifecycleOwner(), pendingTx -> { + showConfirmationLayout(pendingTx != null); + + if (pendingTx != null) { + String address = addressEditText.getText().toString(); + addressTextView.setText(getString(R.string.tx_address_text, address)); + amountTextView.setText(getString(R.string.tx_amount_text, Helper.getDisplayAmount(pendingTx.getAmount()))); + feeTextView.setText(getString(R.string.tx_fee_text, Helper.getDisplayAmount(pendingTx.getFee()))); + } + }); + } + + private void bindListeners() { pasteAddressImageButton.setOnClickListener(view1 -> { Context ctx = getContext(); if (ctx != null) { @@ -142,31 +181,6 @@ public class SendBottomSheetDialog extends BottomSheetDialogFragment { sendTx(pendingTx); } }); - - sendingMax.observe(getViewLifecycleOwner(), sendingMax -> { - if (pendingTransaction.getValue() == null) { - if (sendingMax) { - amountEditText.setVisibility(View.INVISIBLE); - sendAllTextView.setVisibility(View.VISIBLE); - sendMaxButton.setText(getText(R.string.undo)); - } else { - amountEditText.setVisibility(View.VISIBLE); - sendAllTextView.setVisibility(View.GONE); - sendMaxButton.setText(getText(R.string.send_max)); - } - } - }); - - pendingTransaction.observe(getViewLifecycleOwner(), pendingTx -> { - showConfirmationLayout(pendingTx != null); - - if (pendingTx != null) { - String address = addressEditText.getText().toString(); - addressTextView.setText(getString(R.string.tx_address_text, address)); - amountTextView.setText(getString(R.string.tx_amount_text, Helper.getDisplayAmount(pendingTx.getAmount()))); - feeTextView.setText(getString(R.string.tx_fee_text, Helper.getDisplayAmount(pendingTx.getFee()))); - } - }); } private void onScan() {