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);
}
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);
}
});
}
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();
});
}
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();
}
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)));
}
}
Aggregations