Search in sources :

Example 6 with DialogBuilder

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;
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) OnClickListener(android.content.DialogInterface.OnClickListener) DialogBuilder(de.schildbach.wallet.ui.DialogBuilder) View(android.view.View) OnShowListener(android.content.DialogInterface.OnShowListener) OnCancelListener(android.content.DialogInterface.OnCancelListener)

Example 7 with DialogBuilder

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;
}
Also used : AlertDialog(android.app.AlertDialog) ShowPasswordCheckListener(de.schildbach.wallet.ui.ShowPasswordCheckListener) DialogBuilder(de.schildbach.wallet.ui.DialogBuilder) View(android.view.View) TextView(android.widget.TextView)

Example 8 with DialogBuilder

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);
    }
}
Also used : Coin(org.bitcoinj.core.Coin) SendRequest(org.bitcoinj.wallet.SendRequest) MonetaryFormat(org.bitcoinj.utils.MonetaryFormat) Wallet(org.bitcoinj.wallet.Wallet) PaymentIntent(de.schildbach.wallet.data.PaymentIntent) DialogBuilder(de.schildbach.wallet.ui.DialogBuilder)

Example 9 with DialogBuilder

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);
    }
}
Also used : Transaction(org.bitcoinj.core.Transaction) StringInputParser(de.schildbach.wallet.ui.InputParser.StringInputParser) VerificationException(org.bitcoinj.core.VerificationException) PaymentIntent(de.schildbach.wallet.data.PaymentIntent) DialogBuilder(de.schildbach.wallet.ui.DialogBuilder)

Example 10 with DialogBuilder

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);
        }
    }
}
Also used : MonetarySpannable(de.schildbach.wallet.util.MonetarySpannable) Bundle(android.os.Bundle) DumpedPrivateKey(org.bitcoinj.core.DumpedPrivateKey) Transaction(org.bitcoinj.core.Transaction) PackageManager(android.content.pm.PackageManager) Coin(org.bitcoinj.core.Coin) WalletTransaction(org.bitcoinj.wallet.WalletTransaction) LoggerFactory(org.slf4j.LoggerFactory) ScanActivity(de.schildbach.wallet.ui.scan.ScanActivity) AbstractWalletActivityViewModel(de.schildbach.wallet.ui.AbstractWalletActivityViewModel) Process(android.os.Process) NetworkParameters(org.bitcoinj.core.NetworkParameters) PrefixedChecksummedBytes(org.bitcoinj.core.PrefixedChecksummedBytes) SendRequest(org.bitcoinj.wallet.SendRequest) Handler(android.os.Handler) Map(java.util.Map) Fragment(androidx.fragment.app.Fragment) View(android.view.View) Button(android.widget.Button) R(de.schildbach.wallet.R) Configuration(de.schildbach.wallet.Configuration) Constants(de.schildbach.wallet.Constants) PaymentIntent(de.schildbach.wallet.data.PaymentIntent) BalanceType(org.bitcoinj.wallet.Wallet.BalanceType) ConfidenceType(org.bitcoinj.core.TransactionConfidence.ConfidenceType) Set(java.util.Set) ComparisonChain(com.google.common.collect.ComparisonChain) ViewGroup(android.view.ViewGroup) Preconditions.checkState(androidx.core.util.Preconditions.checkState) ECKey(org.bitcoinj.core.ECKey) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) TransactionsAdapter(de.schildbach.wallet.ui.TransactionsAdapter) TransactionOutput(org.bitcoinj.core.TransactionOutput) UTXO(org.bitcoinj.core.UTXO) Context(android.content.Context) TransactionConfidence(org.bitcoinj.core.TransactionConfidence) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Wallet(org.bitcoinj.wallet.Wallet) Intent(android.content.Intent) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) MenuItem(android.view.MenuItem) AnimationUtils(android.view.animation.AnimationUtils) ProgressDialogFragment(de.schildbach.wallet.ui.ProgressDialogFragment) SpannableStringBuilder(android.text.SpannableStringBuilder) VerificationException(org.bitcoinj.core.VerificationException) MenuInflater(android.view.MenuInflater) Menu(android.view.Menu) DialogEvent(de.schildbach.wallet.ui.DialogEvent) Sha256Hash(org.bitcoinj.core.Sha256Hash) BIP38PrivateKey(org.bitcoinj.crypto.BIP38PrivateKey) FragmentManager(androidx.fragment.app.FragmentManager) TransactionOutPoint(org.bitcoinj.core.TransactionOutPoint) Logger(org.slf4j.Logger) ViewModelProvider(androidx.lifecycle.ViewModelProvider) LayoutInflater(android.view.LayoutInflater) MonetaryFormat(org.bitcoinj.utils.MonetaryFormat) Threading(org.bitcoinj.utils.Threading) AbstractWalletActivity(de.schildbach.wallet.ui.AbstractWalletActivity) DialogBuilder(de.schildbach.wallet.ui.DialogBuilder) HandlerThread(android.os.HandlerThread) TransactionInput(org.bitcoinj.core.TransactionInput) StringInputParser(de.schildbach.wallet.ui.InputParser.StringInputParser) WalletApplication(de.schildbach.wallet.WalletApplication) Comparator(java.util.Comparator) Activity(android.app.Activity) EditText(android.widget.EditText) MonetaryFormat(org.bitcoinj.utils.MonetaryFormat) PrefixedChecksummedBytes(org.bitcoinj.core.PrefixedChecksummedBytes) ProgressDialogFragment(de.schildbach.wallet.ui.ProgressDialogFragment) Handler(android.os.Handler) PaymentIntent(de.schildbach.wallet.data.PaymentIntent) Intent(android.content.Intent) MonetarySpannable(de.schildbach.wallet.util.MonetarySpannable) TransactionOutPoint(org.bitcoinj.core.TransactionOutPoint) ConfidenceType(org.bitcoinj.core.TransactionConfidence.ConfidenceType) DialogEvent(de.schildbach.wallet.ui.DialogEvent) HandlerThread(android.os.HandlerThread) AbstractWalletActivityViewModel(de.schildbach.wallet.ui.AbstractWalletActivityViewModel) DialogBuilder(de.schildbach.wallet.ui.DialogBuilder) TransactionConfidence(org.bitcoinj.core.TransactionConfidence) SpannableStringBuilder(android.text.SpannableStringBuilder) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Aggregations

DialogBuilder (de.schildbach.wallet.ui.DialogBuilder)20 DialogInterface (android.content.DialogInterface)8 View (android.view.View)8 OnClickListener (android.content.DialogInterface.OnClickListener)7 PaymentIntent (de.schildbach.wallet.data.PaymentIntent)7 TextView (android.widget.TextView)6 AlertDialog (android.app.AlertDialog)5 Transaction (org.bitcoinj.core.Transaction)5 StringInputParser (de.schildbach.wallet.ui.InputParser.StringInputParser)4 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 Coin (org.bitcoinj.core.Coin)4 VerificationException (org.bitcoinj.core.VerificationException)4 MonetaryFormat (org.bitcoinj.utils.MonetaryFormat)4 Wallet (org.bitcoinj.wallet.Wallet)4 FileInputStream (java.io.FileInputStream)3 Activity (android.app.Activity)2 Context (android.content.Context)2 Intent (android.content.Intent)2 PackageManager (android.content.pm.PackageManager)2