use of de.schildbach.wallet.ui.DialogBuilder in project bitcoin-wallet by bitcoin-wallet.
the class SendCoinsFragment method sendPayment.
private void sendPayment(final SendRequest sendRequest, final Coin finalAmount) {
final Wallet wallet = walletActivityViewModel.wallet.getValue();
new SendCoinsOfflineTask(wallet, backgroundHandler) {
@Override
protected void onSuccess(final Transaction transaction) {
viewModel.sentTransaction.setValue(transaction);
setState(SendCoinsViewModel.State.SENDING);
final Address refundAddress = viewModel.paymentIntent.standard == Standard.BIP70 ? wallet.freshAddress(KeyPurpose.REFUND) : null;
final Payment payment = PaymentProtocol.createPaymentMessage(Collections.singletonList(transaction), finalAmount, refundAddress, null, viewModel.paymentIntent.payeeData);
if (directPaymentEnableView.isChecked())
directPay(payment);
final ListenableFuture<Transaction> future = walletActivityViewModel.broadcastTransaction(transaction);
future.addListener(() -> {
// Auto-close the dialog after a short delay
if (config.getSendCoinsAutoclose())
handler.postDelayed(() -> activity.finish(), Constants.AUTOCLOSE_DELAY_MS);
}, Threading.THREAD_POOL);
final ComponentName callingActivity = activity.getCallingActivity();
if (callingActivity != null) {
log.info("returning result to calling activity: {}", callingActivity.flattenToString());
final Intent result = new Intent();
BitcoinIntegration.transactionHashToResult(result, transaction.getTxId().toString());
if (viewModel.paymentIntent.standard == Standard.BIP70)
BitcoinIntegration.paymentToResult(result, payment.toByteArray());
activity.setResult(Activity.RESULT_OK, result);
}
}
private void directPay(final Payment payment) {
final DirectPaymentTask.ResultCallback callback = new DirectPaymentTask.ResultCallback() {
@Override
public void onResult(final boolean ack) {
viewModel.directPaymentAck = ack;
if (viewModel.state == SendCoinsViewModel.State.SENDING)
setState(SendCoinsViewModel.State.SENT);
updateView();
}
@Override
public void onFail(final int messageResId, final Object... messageArgs) {
final DialogBuilder dialog = DialogBuilder.warn(activity, R.string.send_coins_fragment_direct_payment_failed_title, viewModel.paymentIntent.paymentUrl + "\n" + getString(messageResId, messageArgs) + "\n\n" + getString(R.string.send_coins_fragment_direct_payment_failed_msg));
dialog.setPositiveButton(R.string.button_retry, (d, which) -> directPay(payment));
dialog.setNegativeButton(R.string.button_dismiss, null);
dialog.show();
}
};
if (viewModel.paymentIntent.isHttpPaymentUrl()) {
new DirectPaymentTask.HttpPaymentTask(backgroundHandler, callback, viewModel.paymentIntent.paymentUrl, application.httpUserAgent()).send(payment);
} else if (viewModel.paymentIntent.isBluetoothPaymentUrl() && bluetoothAdapter != null && bluetoothAdapter.isEnabled()) {
new DirectPaymentTask.BluetoothPaymentTask(backgroundHandler, callback, bluetoothAdapter, Bluetooth.getBluetoothMac(viewModel.paymentIntent.paymentUrl)).send(payment);
}
}
@Override
protected void onInsufficientMoney(final Coin missing) {
setState(SendCoinsViewModel.State.INPUT);
final Coin estimated = wallet.getBalance(BalanceType.ESTIMATED);
final Coin available = wallet.getBalance(BalanceType.AVAILABLE);
final Coin pending = estimated.subtract(available);
final MonetaryFormat btcFormat = config.getFormat();
final StringBuilder msg = new StringBuilder();
msg.append(getString(R.string.send_coins_fragment_insufficient_money_msg1, btcFormat.format(missing)));
if (pending.signum() > 0)
msg.append("\n\n").append(getString(R.string.send_coins_fragment_pending, btcFormat.format(pending)));
if (viewModel.paymentIntent.mayEditAmount())
msg.append("\n\n").append(getString(R.string.send_coins_fragment_insufficient_money_msg2));
final DialogBuilder dialog = DialogBuilder.warn(activity, R.string.send_coins_fragment_insufficient_money_title, msg);
if (viewModel.paymentIntent.mayEditAmount()) {
dialog.setPositiveButton(R.string.send_coins_options_empty, (d, which) -> handleEmpty());
dialog.setNegativeButton(R.string.button_cancel, null);
} else {
dialog.setNeutralButton(R.string.button_dismiss, null);
}
dialog.show();
}
@Override
protected void onInvalidEncryptionKey() {
setState(SendCoinsViewModel.State.INPUT);
privateKeyBadPasswordView.setVisibility(View.VISIBLE);
privateKeyPasswordView.requestFocus();
}
@Override
protected void onEmptyWalletFailed() {
setState(SendCoinsViewModel.State.INPUT);
final DialogBuilder dialog = DialogBuilder.warn(activity, R.string.send_coins_fragment_empty_wallet_failed_title, R.string.send_coins_fragment_hint_empty_wallet_failed);
dialog.setNeutralButton(R.string.button_dismiss, null);
dialog.show();
}
@Override
protected void onFailure(Exception exception) {
setState(SendCoinsViewModel.State.FAILED);
final DialogBuilder dialog = DialogBuilder.warn(activity, R.string.send_coins_error_msg, exception.toString());
dialog.setNeutralButton(R.string.button_dismiss, null);
dialog.show();
}
}.sendCoinsOffline(// send asynchronously
sendRequest);
}
use of de.schildbach.wallet.ui.DialogBuilder in project bitcoin-wallet by bitcoin-wallet.
the class SendCoinsFragment method initStateFromBitcoinUri.
private void initStateFromBitcoinUri(final Uri bitcoinUri) {
final String input = bitcoinUri.toString();
new StringInputParser(input) {
@Override
protected void handlePaymentIntent(final PaymentIntent paymentIntent) {
updateStateFrom(paymentIntent);
}
@Override
protected void handlePrivateKey(final PrefixedChecksummedBytes key) {
throw new UnsupportedOperationException();
}
@Override
protected void handleDirectTransaction(final Transaction transaction) throws VerificationException {
throw new UnsupportedOperationException();
}
@Override
protected void error(final int messageResId, final Object... messageArgs) {
final DialogBuilder dialog = DialogBuilder.dialog(activity, 0, messageResId, messageArgs);
dialog.singleDismissButton(activityDismissListener);
dialog.show();
}
}.parse();
}
use of de.schildbach.wallet.ui.DialogBuilder in project bitcoin-wallet by bitcoin-wallet.
the class SendCoinsFragment method requestPaymentRequest.
private void requestPaymentRequest() {
final String paymentRequestHost;
if (!Bluetooth.isBluetoothUrl(viewModel.paymentIntent.paymentRequestUrl))
paymentRequestHost = Uri.parse(viewModel.paymentIntent.paymentRequestUrl).getHost();
else
paymentRequestHost = Bluetooth.decompressMac(Bluetooth.getBluetoothMac(viewModel.paymentIntent.paymentRequestUrl));
viewModel.progress.setValue(getString(R.string.send_coins_fragment_request_payment_request_progress, paymentRequestHost));
setState(SendCoinsViewModel.State.REQUEST_PAYMENT_REQUEST);
final RequestPaymentRequestTask.ResultCallback callback = new RequestPaymentRequestTask.ResultCallback() {
@Override
public void onPaymentIntent(final PaymentIntent paymentIntent) {
viewModel.progress.setValue(null);
if (viewModel.paymentIntent.isExtendedBy(paymentIntent)) {
// success
setState(SendCoinsViewModel.State.INPUT);
updateStateFrom(paymentIntent);
updateView();
handler.post(dryrunRunnable);
} else {
final List<String> reasons = new LinkedList<>();
if (!viewModel.paymentIntent.equalsAddress(paymentIntent))
reasons.add("address");
if (!viewModel.paymentIntent.equalsAmount(paymentIntent))
reasons.add("amount");
if (reasons.isEmpty())
reasons.add("unknown");
final DialogBuilder dialog = DialogBuilder.warn(activity, R.string.send_coins_fragment_request_payment_request_failed_title, R.string.send_coins_fragment_request_payment_request_failed_message, paymentRequestHost, Joiner.on(", ").join(reasons));
dialog.singleDismissButton((d, which) -> handleCancel());
dialog.show();
log.info("BIP72 trust check failed: {}", reasons);
}
}
@Override
public void onFail(final int messageResId, final Object... messageArgs) {
viewModel.progress.setValue(null);
final DialogBuilder dialog = DialogBuilder.warn(activity, R.string.send_coins_fragment_request_payment_request_failed_title, messageResId, messageArgs);
dialog.setPositiveButton(R.string.button_retry, (d, which) -> requestPaymentRequest());
dialog.setNegativeButton(R.string.button_dismiss, (d, which) -> {
if (!viewModel.paymentIntent.hasOutputs())
handleCancel();
else
setState(SendCoinsViewModel.State.INPUT);
});
dialog.show();
}
};
if (!Bluetooth.isBluetoothUrl(viewModel.paymentIntent.paymentRequestUrl))
new RequestPaymentRequestTask.HttpRequestTask(backgroundHandler, callback, application.httpUserAgent()).requestPaymentRequest(viewModel.paymentIntent.paymentRequestUrl);
else
new RequestPaymentRequestTask.BluetoothRequestTask(backgroundHandler, callback, bluetoothAdapter).requestPaymentRequest(viewModel.paymentIntent.paymentRequestUrl);
}
use of de.schildbach.wallet.ui.DialogBuilder in project bitcoin-wallet by bitcoin-wallet.
the class MaintenanceDialogFragment method onCreateDialog.
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
final View view = LayoutInflater.from(activity).inflate(R.layout.maintenance_dialog, null);
Coin value = Coin.ZERO;
Coin fee = Coin.ZERO;
for (final Transaction tx : determineMaintenanceTransactions()) {
value = value.add(tx.getValueSentFromMe(wallet));
fee = fee.add(tx.getFee());
}
final TextView messageView = view.findViewById(R.id.maintenance_dialog_message);
final MonetaryFormat format = application.getConfiguration().getFormat();
messageView.setText(getString(R.string.maintenance_dialog_message, format.format(value), format.format(fee)));
passwordGroup = view.findViewById(R.id.maintenance_dialog_password_group);
passwordView = view.findViewById(R.id.maintenance_dialog_password);
passwordView.setText(null);
badPasswordView = view.findViewById(R.id.maintenance_dialog_bad_password);
final DialogBuilder builder = DialogBuilder.custom(activity, R.string.maintenance_dialog_title, view);
// dummies, just to make buttons show
builder.setPositiveButton(R.string.maintenance_dialog_button_move, null);
builder.setNegativeButton(R.string.button_dismiss, null);
builder.setCancelable(false);
final AlertDialog dialog = builder.create();
dialog.setCanceledOnTouchOutside(false);
dialog.setOnShowListener(d -> {
positiveButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
negativeButton = dialog.getButton(DialogInterface.BUTTON_NEGATIVE);
positiveButton.setTypeface(Typeface.DEFAULT_BOLD);
positiveButton.setOnClickListener(v -> {
log.info("user decided to do maintenance");
handleGo();
});
negativeButton.setOnClickListener(v -> {
log.info("user decided to dismiss");
dismissAllowingStateLoss();
});
passwordView.addTextChangedListener(textWatcher);
MaintenanceDialogFragment.this.dialog = dialog;
updateView();
});
log.info("showing maintenance dialog");
return dialog;
}
use of de.schildbach.wallet.ui.DialogBuilder in project bitcoin-wallet by bitcoin-wallet.
the class RaiseFeeDialogFragment method onCreateDialog.
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
final View view = LayoutInflater.from(activity).inflate(R.layout.raise_fee_dialog, null);
messageView = view.findViewById(R.id.raise_fee_dialog_message);
passwordGroup = view.findViewById(R.id.raise_fee_dialog_password_group);
passwordView = view.findViewById(R.id.raise_fee_dialog_password);
passwordView.setText(null);
badPasswordView = view.findViewById(R.id.raise_fee_dialog_bad_password);
final DialogBuilder builder = DialogBuilder.custom(activity, R.string.raise_fee_dialog_title, view);
// dummies, just to make buttons show
builder.setPositiveButton(R.string.raise_fee_dialog_button_raise, null);
builder.setNegativeButton(R.string.button_dismiss, null);
builder.setCancelable(false);
final AlertDialog dialog = builder.create();
dialog.setCanceledOnTouchOutside(false);
dialog.setOnShowListener(d -> {
positiveButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
negativeButton = dialog.getButton(DialogInterface.BUTTON_NEGATIVE);
positiveButton.setTypeface(Typeface.DEFAULT_BOLD);
positiveButton.setOnClickListener(v -> handleGo());
negativeButton.setOnClickListener(v -> dismissAllowingStateLoss());
passwordView.addTextChangedListener(textWatcher);
RaiseFeeDialogFragment.this.dialog = dialog;
updateView();
});
log.info("showing raise fee dialog");
return dialog;
}
Aggregations