use of org.bitcoinj.core.Address in project bitcoin-wallet by bitcoin-wallet.
the class WalletTransactionsFragment method onTransactionMenuClick.
@Override
public void onTransactionMenuClick(final View view, final Transaction tx) {
final boolean txSent = tx.getValue(wallet).signum() < 0;
final Address txAddress = txSent ? WalletUtils.getToAddressOfSent(tx, wallet) : WalletUtils.getWalletAddressOfReceived(tx, wallet);
final byte[] txSerialized = tx.unsafeBitcoinSerialize();
final boolean txRotation = tx.getPurpose() == Purpose.KEY_ROTATION;
final PopupMenu popupMenu = new PopupMenu(activity, view);
popupMenu.inflate(R.menu.wallet_transactions_context);
final MenuItem editAddressMenuItem = popupMenu.getMenu().findItem(R.id.wallet_transactions_context_edit_address);
if (!txRotation && txAddress != null) {
editAddressMenuItem.setVisible(true);
final boolean isAdd = AddressBookProvider.resolveLabel(activity, txAddress.toBase58()) == null;
final boolean isOwn = wallet.isPubKeyHashMine(txAddress.getHash160());
if (isOwn)
editAddressMenuItem.setTitle(isAdd ? R.string.edit_address_book_entry_dialog_title_add_receive : R.string.edit_address_book_entry_dialog_title_edit_receive);
else
editAddressMenuItem.setTitle(isAdd ? R.string.edit_address_book_entry_dialog_title_add : R.string.edit_address_book_entry_dialog_title_edit);
} else {
editAddressMenuItem.setVisible(false);
}
popupMenu.getMenu().findItem(R.id.wallet_transactions_context_show_qr).setVisible(!txRotation && txSerialized.length < SHOW_QR_THRESHOLD_BYTES);
popupMenu.getMenu().findItem(R.id.wallet_transactions_context_raise_fee).setVisible(RaiseFeeDialogFragment.feeCanLikelyBeRaised(wallet, tx));
popupMenu.getMenu().findItem(R.id.wallet_transactions_context_browse).setVisible(Constants.ENABLE_BROWSE);
popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(final MenuItem item) {
switch(item.getItemId()) {
case R.id.wallet_transactions_context_edit_address:
handleEditAddress(tx);
return true;
case R.id.wallet_transactions_context_show_qr:
handleShowQr();
return true;
case R.id.wallet_transactions_context_raise_fee:
RaiseFeeDialogFragment.show(getFragmentManager(), tx);
return true;
case R.id.wallet_transactions_context_report_issue:
handleReportIssue(tx);
return true;
case R.id.wallet_transactions_context_browse:
if (!txRotation) {
final String txHash = tx.getHashAsString();
final Uri blockExplorerUri = config.getBlockExplorer();
log.info("Viewing transaction {} on {}", txHash, blockExplorerUri);
startActivity(new Intent(Intent.ACTION_VIEW, Uri.withAppendedPath(blockExplorerUri, "tx/" + txHash)));
} else {
startActivity(new Intent(Intent.ACTION_VIEW, KEY_ROTATION_URI));
}
return true;
}
return false;
}
private void handleEditAddress(final Transaction tx) {
EditAddressBookEntryFragment.edit(getFragmentManager(), txAddress);
}
private void handleShowQr() {
final Bitmap qrCodeBitmap = Qr.bitmap(Qr.encodeCompressBinary(txSerialized));
BitmapFragment.show(getFragmentManager(), qrCodeBitmap);
}
private void handleReportIssue(final Transaction tx) {
final StringBuilder contextualData = new StringBuilder();
try {
contextualData.append(tx.getValue(wallet).toFriendlyString()).append(" total value");
} catch (final ScriptException x) {
contextualData.append(x.getMessage());
}
contextualData.append('\n');
if (tx.hasConfidence())
contextualData.append(" confidence: ").append(tx.getConfidence()).append('\n');
contextualData.append(tx.toString());
ReportIssueDialogFragment.show(getFragmentManager(), R.string.report_issue_dialog_title_transaction, R.string.report_issue_dialog_message_issue, Constants.REPORT_SUBJECT_ISSUE, contextualData.toString());
}
});
popupMenu.show();
}
Aggregations