Search in sources :

Example 6 with UTXOCoin

use of com.samourai.wallet.utxos.models.UTXOCoin in project samourai-wallet-android by Samourai-Wallet.

the class UTXOSActivity method clearSelection.

// Clears current Toolbar action mode
void clearSelection() {
    ArrayList<UTXOCoin> models = new ArrayList<>();
    for (UTXOCoin model : this.filteredUTXOs) {
        model.isSelected = false;
        models.add(model);
    }
    this.filteredUTXOs = new ArrayList<>();
    this.filteredUTXOs.addAll(models);
}
Also used : UTXOCoin(com.samourai.wallet.utxos.models.UTXOCoin) ArrayList(java.util.ArrayList)

Example 7 with UTXOCoin

use of com.samourai.wallet.utxos.models.UTXOCoin in project samourai-wallet-android by Samourai-Wallet.

the class UTXODetailsActivity method showMoreOptions.

private void showMoreOptions() {
    View dialogView = getLayoutInflater().inflate(R.layout.utxo_details_options_bottomsheet, null);
    BottomSheetDialog dialog = new BottomSheetDialog(this);
    dialog.setContentView(dialogView);
    dialog.show();
    TextView spendOption = dialog.findViewById(R.id.utxo_details_spending_status);
    if (isBlocked()) {
        if (spendOption != null)
            spendOption.setText(R.string.this_utxo_is_marked_as_blocked);
    } else {
        if (spendOption != null)
            spendOption.setText(R.string.this_utxo_is_marked_as_spendable);
    }
    dialog.findViewById(R.id.utxo_details_option_sign).setOnClickListener(view -> sign());
    dialog.findViewById(R.id.utxo_details_option_redeem).setOnClickListener(view -> redeem());
    dialog.findViewById(R.id.utxo_details_option_private_key).setOnClickListener(view -> viewPrivateKey());
    dialog.findViewById(R.id.utxo_details_option_status).setOnClickListener(view -> {
        setSpendStatus();
        dialog.dismiss();
    });
    dialog.findViewById(R.id.utxo_details_option_spend).setOnClickListener(view -> {
        dialog.dismiss();
        ArrayList<UTXOCoin> list = new ArrayList<>();
        list.add(utxoCoin);
        String id = UUID.randomUUID().toString();
        PreSelectUtil.getInstance().clear();
        PreSelectUtil.getInstance().add(id, list);
        if (utxoCoin.doNotSpend) {
            Snackbar.make(paynymLayout.getRootView(), R.string.utxo_is_marked_as_blocked, Snackbar.LENGTH_LONG).show();
            return;
        }
        if (id != null) {
            Intent intent = new Intent(getApplicationContext(), SendActivity.class);
            intent.putExtra("preselected", id);
            intent.putExtra("_account", account);
            startActivity(intent);
        }
    });
}
Also used : BottomSheetDialog(android.support.design.widget.BottomSheetDialog) UTXOCoin(com.samourai.wallet.utxos.models.UTXOCoin) ArrayList(java.util.ArrayList) TextView(android.widget.TextView) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView)

Example 8 with UTXOCoin

use of com.samourai.wallet.utxos.models.UTXOCoin in project samourai-wallet-android by Samourai-Wallet.

the class UTXODetailsActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_utxodetails);
    setSupportActionBar(findViewById(R.id.toolbar_utxo_activity));
    Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    addressTextView = findViewById(R.id.utxo_details_address);
    amountTextView = findViewById(R.id.utxo_details_amount);
    statusTextView = findViewById(R.id.utxo_details_spendable_status);
    hashTextView = findViewById(R.id.utxo_details_hash);
    addNote = findViewById(R.id.add_note_button);
    notesTextView = findViewById(R.id.utxo_details_note);
    deleteButton = findViewById(R.id.delete_note);
    paynymLayout = findViewById(R.id.utxo_details_paynym_container);
    paynymLayout.setVisibility(View.GONE);
    df.setMinimumIntegerDigits(1);
    df.setMinimumFractionDigits(8);
    df.setMaximumFractionDigits(8);
    if (getIntent().getExtras() != null && getIntent().getExtras().containsKey("hashIdx")) {
        hashIdx = getIntent().getExtras().getString("hashIdx");
    } else {
        finish();
    }
    if (getIntent().getExtras() != null && getIntent().getExtras().containsKey("_account")) {
        account = getIntent().getExtras().getInt("_account");
    } else {
        finish();
    }
    List<UTXO> utxos = new ArrayList<>();
    if (account == WhirlpoolMeta.getInstance(getApplicationContext()).getWhirlpoolPostmix()) {
        utxos.addAll(APIFactory.getInstance(getApplicationContext()).getUtxosPostMix(false));
    } else {
        utxos.addAll(APIFactory.getInstance(getApplicationContext()).getUtxos(false));
    }
    utxos.addAll(APIFactory.getInstance(getApplicationContext()).getUtxos(false));
    for (UTXO utxo : utxos) {
        for (MyTransactionOutPoint outpoint : utxo.getOutpoints()) {
            if (outpoint.getTxHash() != null) {
                String hashWithIdx = outpoint.getTxHash().toString().concat("-").concat(String.valueOf(outpoint.getTxOutputN()));
                if (hashWithIdx.equals(hashIdx)) {
                    idx = outpoint.getTxOutputN();
                    amount = outpoint.getValue().longValue();
                    hash = outpoint.getTxHash().toString();
                    addr = outpoint.getAddress();
                    utxoCoin = new UTXOCoin(outpoint, utxo);
                    if (BlockedUTXO.getInstance().contains(outpoint.getTxHash().toString(), outpoint.getTxOutputN())) {
                        utxoCoin.doNotSpend = true;
                    }
                    setUTXOState();
                }
            }
        }
    }
    deleteButton.setOnClickListener(view -> {
        if (UTXOUtil.getInstance().getNote(hash) != null) {
            UTXOUtil.getInstance().removeNote(hash);
        }
        setNoteState();
        saveWalletState();
    });
    addNote.setOnClickListener(view -> {
        View dialogView = getLayoutInflater().inflate(R.layout.bottom_sheet_note, null);
        BottomSheetDialog dialog = new BottomSheetDialog(this, R.style.bottom_sheet_note);
        dialog.setContentView(dialogView);
        dialog.show();
        Button submitButton = dialog.findViewById(R.id.submit_note);
        if (UTXOUtil.getInstance().getNote(hash) != null) {
            ((EditText) dialog.findViewById(R.id.utxo_details_note)).setText(UTXOUtil.getInstance().getNote(hash));
            submitButton.setText("Save");
        } else {
            submitButton.setText("Add");
        }
        dialog.findViewById(R.id.submit_note).setOnClickListener((View view1) -> {
            dialog.dismiss();
            addNote(((EditText) dialog.findViewById(R.id.utxo_details_note)).getText().toString());
        });
    });
    setNoteState();
    addressTextView.setOnClickListener((event) -> new AlertDialog.Builder(UTXODetailsActivity.this).setTitle(R.string.app_name).setMessage(R.string.receive_address_to_clipboard).setCancelable(false).setPositiveButton(R.string.yes, (dialog, whichButton) -> {
        android.content.ClipboardManager clipboard = (android.content.ClipboardManager) UTXODetailsActivity.this.getSystemService(android.content.Context.CLIPBOARD_SERVICE);
        android.content.ClipData clip = null;
        clip = android.content.ClipData.newPlainText("address", addr);
        clipboard.setPrimaryClip(clip);
        Toast.makeText(UTXODetailsActivity.this, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
    }).setNegativeButton(R.string.no, (dialog, whichButton) -> {
    }).show());
    hashTextView.setOnClickListener(view -> {
        new android.app.AlertDialog.Builder(this).setTitle(R.string.app_name).setMessage(R.string.txid_to_clipboard).setCancelable(false).setPositiveButton(R.string.yes, (dialog, whichButton) -> {
            android.content.ClipboardManager clipboard = (android.content.ClipboardManager) UTXODetailsActivity.this.getSystemService(android.content.Context.CLIPBOARD_SERVICE);
            android.content.ClipData clip;
            clip = android.content.ClipData.newPlainText("tx id", hash);
            if (clipboard != null) {
                clipboard.setPrimaryClip(clip);
            }
            Toast.makeText(UTXODetailsActivity.this, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
        }).setNegativeButton(R.string.no, (dialog, whichButton) -> {
        }).show();
    });
}
Also used : EditText(android.widget.EditText) AlertDialog(android.app.AlertDialog) LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) Completable(io.reactivex.Completable) Uri(android.net.Uri) ImageView(android.widget.ImageView) TransitionManager(android.transition.TransitionManager) WriterException(com.google.zxing.WriterException) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) WhirlpoolMeta(com.samourai.wallet.whirlpool.WhirlpoolMeta) Picasso(com.squareup.picasso.Picasso) MyTransactionOutPoint(com.samourai.wallet.send.MyTransactionOutPoint) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) View(android.view.View) Button(android.widget.Button) SendActivity(com.samourai.wallet.send.SendActivity) UTXO(com.samourai.wallet.send.UTXO) Schedulers(io.reactivex.schedulers.Schedulers) Log(android.util.Log) AccessFactory(com.samourai.wallet.access.AccessFactory) ActivityOptionsCompat(android.support.v4.app.ActivityOptionsCompat) WebUtil(com.samourai.wallet.bip47.paynym.WebUtil) UUID(java.util.UUID) AppCompatActivity(android.support.v7.app.AppCompatActivity) ViewGroup(android.view.ViewGroup) ECKey(org.bitcoinj.core.ECKey) AlertDialog(android.app.AlertDialog) Objects(java.util.Objects) Contents(com.google.zxing.client.android.Contents) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) TextView(android.widget.TextView) Address(org.bitcoinj.core.Address) BIP47Meta(com.samourai.wallet.bip47.BIP47Meta) Snackbar(android.support.design.widget.Snackbar) BarcodeFormat(com.google.zxing.BarcodeFormat) FormatsUtil(com.samourai.wallet.util.FormatsUtil) BottomSheetDialog(android.support.design.widget.BottomSheetDialog) BlockedUTXO(com.samourai.wallet.send.BlockedUTXO) Intent(android.content.Intent) PayloadUtil(com.samourai.wallet.payload.PayloadUtil) MnemonicException(org.bitcoinj.crypto.MnemonicException) MenuItem(android.view.MenuItem) Hex(org.bouncycastle.util.encoders.Hex) ArrayList(java.util.ArrayList) BIP47Add(com.samourai.wallet.bip47.BIP47Add) SamouraiWallet(com.samourai.wallet.SamouraiWallet) SendFactory(com.samourai.wallet.send.SendFactory) Toast(android.widget.Toast) Menu(android.view.Menu) Observable(io.reactivex.Observable) DecryptionException(com.samourai.wallet.crypto.DecryptionException) CharSequenceX(com.samourai.wallet.util.CharSequenceX) UTXOCoin(com.samourai.wallet.utxos.models.UTXOCoin) MessageSignUtil(com.samourai.wallet.util.MessageSignUtil) SegwitAddress(com.samourai.wallet.segwit.SegwitAddress) PayNymDetailsActivity(com.samourai.wallet.paynym.paynymDetails.PayNymDetailsActivity) DecimalFormat(java.text.DecimalFormat) IOException(java.io.IOException) R(com.samourai.wallet.R) QRCodeEncoder(com.google.zxing.client.android.encode.QRCodeEncoder) Bitmap(android.graphics.Bitmap) WhirlpoolMain(com.samourai.wallet.whirlpool.WhirlpoolMain) APIFactory(com.samourai.wallet.api.APIFactory) LogUtil(com.samourai.wallet.util.LogUtil) EditText(android.widget.EditText) ArrayList(java.util.ArrayList) MyTransactionOutPoint(com.samourai.wallet.send.MyTransactionOutPoint) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) UTXO(com.samourai.wallet.send.UTXO) BlockedUTXO(com.samourai.wallet.send.BlockedUTXO) BottomSheetDialog(android.support.design.widget.BottomSheetDialog) UTXOCoin(com.samourai.wallet.utxos.models.UTXOCoin) Button(android.widget.Button)

Example 9 with UTXOCoin

use of com.samourai.wallet.utxos.models.UTXOCoin in project samourai-wallet-android by Samourai-Wallet.

the class ChooseUTXOsFragment method applyFilters.

private void applyFilters(List<UTXOCoin> utxoCoins) {
    ArrayList<UTXOCoin> utxoCoinList = new ArrayList<>();
    /*------------------------------------------------*/
    ArrayList<UTXOCoin> unCycled = new ArrayList<>();
    // Add all received utxo's
    for (UTXOCoin model : utxoCoins) {
        if (model.account == 0 && model.path.startsWith("M/0/")) {
            if (!unCycled.contains(model)) {
                unCycled.add(model);
            }
        } else if (model.account == 0 && model.path.equals("")) {
            if (!unCycled.contains(model)) {
                unCycled.add(model);
            }
        }
    }
    Collections.sort(unCycled, (model, t1) -> Long.compare(t1.amount, model.amount));
    utxoCoinList.addAll(unCycled);
    /*------------------------------------------------*/
    // Change UTXO section
    ArrayList<UTXOCoin> changes = new ArrayList<>();
    // Add all change utxo's
    for (UTXOCoin model : utxoCoins) {
        if (model.account == WhirlpoolMeta.getInstance(getActivity()).getWhirlpoolPostmix() && model.path.startsWith("M/1/")) {
            if (!changes.contains(model)) {
                changes.add(model);
            }
        }
        if (model.account == 0 && model.path.startsWith("M/1/")) {
            if (!changes.contains(model)) {
                changes.add(model);
            }
        }
    }
    Collections.sort(changes, (model, t1) -> Long.compare(t1.amount, model.amount));
    utxoCoinList.addAll(changes);
    utxoAdapter.updateList(utxoCoinList);
    selectUTXOs();
}
Also used : UTXOCoin(com.samourai.wallet.utxos.models.UTXOCoin) ArrayList(java.util.ArrayList)

Example 10 with UTXOCoin

use of com.samourai.wallet.utxos.models.UTXOCoin in project samourai-wallet-android by Samourai-Wallet.

the class ChooseUTXOsFragment method selectUTXOs.

private void selectUTXOs() {
    if (preselectedUTXOs != null) {
        List<UTXOCoin> selectedList = new ArrayList<>();
        for (int i = 0; i < utxos.size(); i++) {
            for (int j = 0; j < preselectedUTXOs.size(); j++) {
                // Checking current utxo lists contains preselected UTXOs
                if (utxos.get(i).hash != null && utxos.get(i).hash.equals(preselectedUTXOs.get(j).hash) && utxos.get(i).idx == (preselectedUTXOs.get(j).idx)) {
                    utxos.get(i).isSelected = true;
                    int finalI = i;
                    utxoRecyclerView.post(() -> utxoAdapter.notifyItemChanged(finalI));
                    selectedList.add(utxos.get(i));
                }
            }
        }
        if (onUTXOSelectionListener != null)
            onUTXOSelectionListener.onSelect(selectedList);
        // Scroll to the selection position
        if (selectedList.size() != 0 && utxos.size() != 0 && utxos.indexOf(selectedList.get(selectedList.size() - 1)) != -1)
            utxoRecyclerView.smoothScrollToPosition(utxos.indexOf(selectedList.get(selectedList.size() - 1)));
    }
}
Also used : UTXOCoin(com.samourai.wallet.utxos.models.UTXOCoin) ArrayList(java.util.ArrayList) MyTransactionOutPoint(com.samourai.wallet.send.MyTransactionOutPoint)

Aggregations

UTXOCoin (com.samourai.wallet.utxos.models.UTXOCoin)20 ArrayList (java.util.ArrayList)16 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)7 Disposable (io.reactivex.disposables.Disposable)7 MyTransactionOutPoint (com.samourai.wallet.send.MyTransactionOutPoint)6 List (java.util.List)6 View (android.view.View)5 ImageView (android.widget.ImageView)5 TextView (android.widget.TextView)5 IOException (java.io.IOException)5 MnemonicException (org.bitcoinj.crypto.MnemonicException)5 AlertDialog (android.app.AlertDialog)4 Intent (android.content.Intent)4 Bundle (android.os.Bundle)4 AppCompatActivity (android.support.v7.app.AppCompatActivity)4 MenuItem (android.view.MenuItem)4 Toast (android.widget.Toast)4 R (com.samourai.wallet.R)4 UTXO (com.samourai.wallet.send.UTXO)4 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)4