use of de.schildbach.wallet.ui.DialogBuilder in project bitcoin-wallet by bitcoin-wallet.
the class RestoreWalletFromExternalDialogFragment method onCreateDialog.
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
final View view = LayoutInflater.from(activity).inflate(R.layout.restore_wallet_from_external_dialog, null);
passwordView = (EditText) view.findViewById(R.id.import_keys_from_content_dialog_password);
showView = (CheckBox) view.findViewById(R.id.import_keys_from_content_dialog_show);
replaceWarningView = view.findViewById(R.id.restore_wallet_from_content_dialog_replace_warning);
final DialogBuilder builder = new DialogBuilder(activity);
builder.setTitle(R.string.import_keys_dialog_title);
builder.setView(view);
builder.setPositiveButton(R.string.import_keys_dialog_button_import, new OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int which) {
final String password = passwordView.getText().toString().trim();
// get rid of it asap
passwordView.setText(null);
handleRestore(password);
}
});
builder.setNegativeButton(R.string.button_cancel, new OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int which) {
// get rid of it asap
passwordView.setText(null);
activity.finish();
}
});
builder.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(final DialogInterface dialog) {
// get rid of it asap
passwordView.setText(null);
activity.finish();
}
});
final AlertDialog dialog = builder.create();
dialog.setOnShowListener(new OnShowListener() {
@Override
public void onShow(final DialogInterface d) {
final ImportDialogButtonEnablerListener dialogButtonEnabler = new ImportDialogButtonEnablerListener(passwordView, dialog) {
@Override
protected boolean hasFile() {
return true;
}
};
passwordView.addTextChangedListener(dialogButtonEnabler);
RestoreWalletFromExternalDialogFragment.this.dialog = dialog;
updateView();
}
});
return dialog;
}
use of de.schildbach.wallet.ui.DialogBuilder in project bitcoin-wallet by bitcoin-wallet.
the class RestoreWalletDialogFragment method onCreateDialog.
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
final View view = LayoutInflater.from(activity).inflate(R.layout.restore_wallet_dialog, null);
messageView = view.findViewById(R.id.restore_wallet_dialog_message);
passwordView = view.findViewById(R.id.restore_wallet_dialog_password);
showView = view.findViewById(R.id.restore_wallet_dialog_show);
replaceWarningView = view.findViewById(R.id.restore_wallet_dialog_replace_warning);
final DialogBuilder builder = DialogBuilder.custom(activity, R.string.import_keys_dialog_title, view);
builder.setPositiveButton(R.string.import_keys_dialog_button_import, (dialog, which) -> {
final String password = passwordView.getText().toString().trim();
// get rid of it asap
passwordView.setText(null);
handleRestore(password);
});
builder.setNegativeButton(R.string.button_cancel, (dialog, which) -> {
// get rid of it asap
passwordView.setText(null);
maybeFinishActivity();
});
builder.setOnCancelListener(dialog -> {
// get rid of it asap
passwordView.setText(null);
maybeFinishActivity();
});
final AlertDialog dialog = builder.create();
dialog.setOnShowListener(d -> {
final ImportDialogButtonEnablerListener dialogButtonEnabler = new ImportDialogButtonEnablerListener(passwordView, dialog) {
@Override
protected boolean hasFile() {
return true;
}
};
passwordView.addTextChangedListener(dialogButtonEnabler);
showView.setOnCheckedChangeListener(new ShowPasswordCheckListener(passwordView));
viewModel.balance.observe(RestoreWalletDialogFragment.this, balance -> {
final boolean hasCoins = balance.signum() > 0;
replaceWarningView.setVisibility(hasCoins ? View.VISIBLE : View.GONE);
});
});
return dialog;
}
use of de.schildbach.wallet.ui.DialogBuilder in project bitcoin-wallet by bitcoin-wallet.
the class SendCoinsFragment method signAndSendPayment.
private void signAndSendPayment(final KeyParameter encryptionKey) {
setState(SendCoinsViewModel.State.SIGNING);
// final payment intent
final PaymentIntent finalPaymentIntent = viewModel.paymentIntent.mergeWithEditedValues(amountCalculatorLink.getAmount(), viewModel.validatedAddress != null ? viewModel.validatedAddress.address : null);
final Coin finalAmount = finalPaymentIntent.getAmount();
// prepare send request
final Map<FeeCategory, Coin> fees = viewModel.dynamicFees.getValue();
final Wallet wallet = walletActivityViewModel.wallet.getValue();
final SendRequest sendRequest = finalPaymentIntent.toSendRequest();
sendRequest.emptyWallet = viewModel.paymentIntent.mayEditAmount() && finalAmount.equals(wallet.getBalance(BalanceType.AVAILABLE));
sendRequest.feePerKb = fees.get(viewModel.feeCategory);
sendRequest.memo = viewModel.paymentIntent.memo;
sendRequest.exchangeRate = amountCalculatorLink.getExchangeRate();
sendRequest.aesKey = encryptionKey;
final Coin fee = viewModel.dryrunTransaction.getFee();
if (fee.isGreaterThan(finalAmount)) {
setState(SendCoinsViewModel.State.INPUT);
final MonetaryFormat btcFormat = config.getFormat();
final DialogBuilder dialog = DialogBuilder.warn(activity, R.string.send_coins_fragment_significant_fee_title, R.string.send_coins_fragment_significant_fee_message, btcFormat.format(fee), btcFormat.format(finalAmount));
dialog.setPositiveButton(R.string.send_coins_fragment_button_send, (d, which) -> sendPayment(sendRequest, finalAmount));
dialog.setNegativeButton(R.string.button_cancel, null);
dialog.show();
} else {
sendPayment(sendRequest, finalAmount);
}
}
use of de.schildbach.wallet.ui.DialogBuilder in project bitcoin-wallet by bitcoin-wallet.
the class SendCoinsFragment method onActivityResultResumed.
private void onActivityResultResumed(final int requestCode, final int resultCode, final Intent intent) {
if (requestCode == REQUEST_CODE_SCAN) {
if (resultCode == Activity.RESULT_OK) {
final String input = intent.getStringExtra(ScanActivity.INTENT_EXTRA_RESULT);
new StringInputParser(input) {
@Override
protected void handlePaymentIntent(final PaymentIntent paymentIntent) {
setState(null);
updateStateFrom(paymentIntent);
}
@Override
protected void handleDirectTransaction(final Transaction transaction) throws VerificationException {
cannotClassify(input);
}
@Override
protected void error(final int messageResId, final Object... messageArgs) {
final DialogBuilder dialog = DialogBuilder.dialog(activity, R.string.button_scan, messageResId, messageArgs);
dialog.singleDismissButton(null);
dialog.show();
}
}.parse();
}
} else if (requestCode == REQUEST_CODE_ENABLE_BLUETOOTH_FOR_PAYMENT_REQUEST) {
if (viewModel.paymentIntent.isBluetoothPaymentRequestUrl())
requestPaymentRequest();
} else if (requestCode == REQUEST_CODE_ENABLE_BLUETOOTH_FOR_DIRECT_PAYMENT) {
if (viewModel.paymentIntent.isBluetoothPaymentUrl())
directPaymentEnableView.setChecked(resultCode == Activity.RESULT_OK);
}
}
use of de.schildbach.wallet.ui.DialogBuilder in project bitcoin-wallet by bitcoin-wallet.
the class SweepWalletFragment method onCreate.
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.fragmentManager = getChildFragmentManager();
setHasOptionsMenu(true);
if (!Constants.ENABLE_SWEEP_WALLET)
throw new IllegalStateException("ENABLE_SWEEP_WALLET is disabled");
walletActivityViewModel = new ViewModelProvider(activity).get(AbstractWalletActivityViewModel.class);
walletActivityViewModel.wallet.observe(this, wallet -> updateView());
viewModel = new ViewModelProvider(this).get(SweepWalletViewModel.class);
viewModel.getDynamicFees().observe(this, dynamicFees -> updateView());
viewModel.progress.observe(this, new ProgressDialogFragment.Observer(fragmentManager));
viewModel.privateKeyToSweep.observe(this, privateKeyToSweep -> updateView());
viewModel.walletToSweep.observe(this, walletToSweep -> {
if (walletToSweep != null) {
balanceView.setVisibility(View.VISIBLE);
final MonetaryFormat btcFormat = config.getFormat();
final MonetarySpannable balanceSpannable = new MonetarySpannable(btcFormat, walletToSweep.getBalance(BalanceType.ESTIMATED));
balanceSpannable.applyMarkup(null, null);
final SpannableStringBuilder balance = new SpannableStringBuilder(balanceSpannable);
balance.insert(0, ": ");
balance.insert(0, getString(R.string.sweep_wallet_fragment_balance));
balanceView.setText(balance);
} else {
balanceView.setVisibility(View.GONE);
}
updateView();
});
viewModel.sentTransaction.observe(this, transaction -> {
if (viewModel.state == SweepWalletViewModel.State.SENDING) {
final TransactionConfidence confidence = transaction.getConfidence();
final ConfidenceType confidenceType = confidence.getConfidenceType();
final int numBroadcastPeers = confidence.numBroadcastPeers();
if (confidenceType == ConfidenceType.DEAD)
setState(SweepWalletViewModel.State.FAILED);
else if (numBroadcastPeers > 1 || confidenceType == ConfidenceType.BUILDING)
setState(SweepWalletViewModel.State.SENT);
}
updateView();
});
viewModel.showDialog.observe(this, new DialogEvent.Observer(activity));
viewModel.showDialogWithRetryRequestBalance.observe(this, new DialogEvent.Observer(activity) {
@Override
protected void onBuildButtons(final DialogBuilder dialog) {
dialog.setPositiveButton(R.string.button_retry, (d, which) -> requestWalletBalance());
dialog.setNegativeButton(R.string.button_dismiss, null);
}
});
backgroundThread = new HandlerThread("backgroundThread", Process.THREAD_PRIORITY_BACKGROUND);
backgroundThread.start();
backgroundHandler = new Handler(backgroundThread.getLooper());
if (savedInstanceState == null) {
final Intent intent = activity.getIntent();
if (intent.hasExtra(SweepWalletActivity.INTENT_EXTRA_KEY)) {
final PrefixedChecksummedBytes privateKeyToSweep = (PrefixedChecksummedBytes) intent.getSerializableExtra(SweepWalletActivity.INTENT_EXTRA_KEY);
viewModel.privateKeyToSweep.setValue(privateKeyToSweep);
// delay until fragment is resumed
handler.post(maybeDecodeKeyRunnable);
}
}
}
Aggregations