diff --git a/wallet/src/de/schildbach/wallet/ui/send/SendCoinsFragment.java b/wallet/src/de/schildbach/wallet/ui/send/SendCoinsFragment.java index 54eee4d915..02ae94a30e 100644 --- a/wallet/src/de/schildbach/wallet/ui/send/SendCoinsFragment.java +++ b/wallet/src/de/schildbach/wallet/ui/send/SendCoinsFragment.java @@ -296,8 +296,8 @@ private void handleClear() @Override public void changed() { - executeDryrun(); updateView(); + handler.post(dryrunRunnable); } @Override @@ -680,8 +680,8 @@ public void onResume() loaderManager.initLoader(ID_RATE_LOADER, null, rateLoaderCallbacks); loaderManager.initLoader(ID_RECEIVING_ADDRESS_LOADER, null, receivingAddressLoaderCallbacks); - executeDryrun(); updateView(); + handler.post(dryrunRunnable); } @Override @@ -1117,47 +1117,55 @@ private void handlePriority() { priority = !priority; - executeDryrun(); updateView(); + handler.post(dryrunRunnable); } private void handleEmpty() { final Coin available = wallet.getBalance(BalanceType.AVAILABLE); - amountCalculatorLink.setBtcAmount(available); - executeDryrun(); updateView(); + handler.post(dryrunRunnable); } - private void executeDryrun() + private Runnable dryrunRunnable = new Runnable() { - if (state != State.INPUT) - return; + @Override + public void run() + { + if (state == State.INPUT) + executeDryrun(); - dryrunTransaction = null; - dryrunException = null; + updateView(); + } - final Coin amount = amountCalculatorLink.getAmount(); - if (amount != null) + private void executeDryrun() { - try - { - final Address dummy = wallet.currentReceiveAddress(); // won't be used, tx is never committed - final SendRequest sendRequest = paymentIntent.mergeWithEditedValues(amount, dummy).toSendRequest(); - sendRequest.signInputs = false; - sendRequest.emptyWallet = paymentIntent.mayEditAmount() && amount.equals(wallet.getBalance(BalanceType.AVAILABLE)); - sendRequest.feePerKb = priority ? SendRequest.DEFAULT_FEE_PER_KB.multiply(10) : SendRequest.DEFAULT_FEE_PER_KB; - wallet.completeTx(sendRequest); - dryrunTransaction = sendRequest.tx; - } - catch (final Exception x) + dryrunTransaction = null; + dryrunException = null; + + final Coin amount = amountCalculatorLink.getAmount(); + if (amount != null) { - dryrunException = x; + try + { + final Address dummy = wallet.currentReceiveAddress(); // won't be used, tx is never committed + final SendRequest sendRequest = paymentIntent.mergeWithEditedValues(amount, dummy).toSendRequest(); + sendRequest.signInputs = false; + sendRequest.emptyWallet = paymentIntent.mayEditAmount() && amount.equals(wallet.getBalance(BalanceType.AVAILABLE)); + sendRequest.feePerKb = priority ? SendRequest.DEFAULT_FEE_PER_KB.multiply(10) : SendRequest.DEFAULT_FEE_PER_KB; + wallet.completeTx(sendRequest); + dryrunTransaction = sendRequest.tx; + } + catch (final Exception x) + { + dryrunException = x; + } } } - } + }; private void setState(final State state) { @@ -1474,8 +1482,8 @@ else if (paymentIntent.isHttpPaymentUrl()) directPaymentEnableView.setChecked(!Constants.BUG_OPENSSL_HEARTBLEED); requestFocusFirst(); - executeDryrun(); updateView(); + handler.post(dryrunRunnable); } if (paymentIntent.hasPaymentRequestUrl()) @@ -1519,8 +1527,8 @@ public void onPaymentIntent(final PaymentIntent paymentIntent) { // success updateStateFrom(paymentIntent); - executeDryrun(); updateView(); + handler.post(dryrunRunnable); } else {