use of com.samourai.wallet.api.Tx in project samourai-wallet-android by Samourai-Wallet.
the class BalanceActivity method onCreate.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_balance);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
if (SamouraiWallet.getInstance().isTestNet()) {
setTitle(getText(R.string.app_name) + ":" + "TestNet");
}
LayoutInflater inflator = BalanceActivity.this.getLayoutInflater();
tvBalanceBar = (LinearLayout) inflator.inflate(R.layout.balance_layout, null);
tvBalanceBar.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (isBTC) {
isBTC = false;
} else {
isBTC = true;
}
displayBalance();
txAdapter.notifyDataSetChanged();
return false;
}
});
tvBalanceAmount = (TextView) tvBalanceBar.findViewById(R.id.BalanceAmount);
tvBalanceUnits = (TextView) tvBalanceBar.findViewById(R.id.BalanceUnits);
ibQuickSend = (FloatingActionsMenu) findViewById(R.id.wallet_menu);
actionSend = (FloatingActionButton) findViewById(R.id.send);
actionSend.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(BalanceActivity.this, SendActivity.class);
intent.putExtra("via_menu", true);
startActivity(intent);
}
});
actionReceive = (FloatingActionButton) findViewById(R.id.receive);
actionReceive.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
try {
HD_Wallet hdw = HD_WalletFactory.getInstance(BalanceActivity.this).get();
if (hdw != null) {
Intent intent = new Intent(BalanceActivity.this, ReceiveActivity.class);
startActivity(intent);
}
} catch (IOException | MnemonicException.MnemonicLengthException e) {
;
}
}
});
actionBIP47 = (FloatingActionButton) findViewById(R.id.bip47);
actionBIP47.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(BalanceActivity.this, com.samourai.wallet.bip47.BIP47Activity.class);
startActivity(intent);
}
});
txs = new ArrayList<Tx>();
txStates = new HashMap<String, Boolean>();
txList = (ListView) findViewById(R.id.txList);
txAdapter = new TransactionAdapter();
txList.setAdapter(txAdapter);
txList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, final View view, int position, long id) {
if (position == 0) {
return;
}
long viewId = view.getId();
View v = (View) view.getParent();
final Tx tx = txs.get(position - 1);
ImageView ivTxStatus = (ImageView) v.findViewById(R.id.TransactionStatus);
TextView tvConfirmationCount = (TextView) v.findViewById(R.id.ConfirmationCount);
if (viewId == R.id.ConfirmationCount || viewId == R.id.TransactionStatus) {
if (txStates.containsKey(tx.getHash()) && txStates.get(tx.getHash()) == true) {
txStates.put(tx.getHash(), false);
displayTxStatus(false, tx.getConfirmations(), tvConfirmationCount, ivTxStatus);
} else {
txStates.put(tx.getHash(), true);
displayTxStatus(true, tx.getConfirmations(), tvConfirmationCount, ivTxStatus);
}
} else {
String message = getString(R.string.options_unconfirmed_tx);
// RBF
if (tx.getConfirmations() < 1 && tx.getAmount() < 0.0 && RBFUtil.getInstance().contains(tx.getHash())) {
AlertDialog.Builder builder = new AlertDialog.Builder(BalanceActivity.this);
builder.setTitle(R.string.app_name);
builder.setMessage(message);
builder.setCancelable(true);
builder.setPositiveButton(R.string.options_bump_fee, new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, int whichButton) {
if (rbfTask == null || rbfTask.getStatus().equals(AsyncTask.Status.FINISHED)) {
rbfTask = new RBFTask();
rbfTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, tx.getHash());
}
}
});
builder.setNegativeButton(R.string.options_block_explorer, new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, int whichButton) {
doExplorerView(tx.getHash());
}
});
AlertDialog alert = builder.create();
alert.show();
} else // CPFP receive
if (tx.getConfirmations() < 1 && tx.getAmount() >= 0.0) {
AlertDialog.Builder builder = new AlertDialog.Builder(BalanceActivity.this);
builder.setTitle(R.string.app_name);
builder.setMessage(message);
builder.setCancelable(true);
builder.setPositiveButton(R.string.options_bump_fee, new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, int whichButton) {
if (cpfpTask == null || cpfpTask.getStatus().equals(AsyncTask.Status.FINISHED)) {
cpfpTask = new CPFPTask();
cpfpTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, tx.getHash());
}
}
});
builder.setNegativeButton(R.string.options_block_explorer, new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, int whichButton) {
doExplorerView(tx.getHash());
}
});
AlertDialog alert = builder.create();
alert.show();
} else // CPFP spend
if (tx.getConfirmations() < 1 && tx.getAmount() < 0.0) {
AlertDialog.Builder builder = new AlertDialog.Builder(BalanceActivity.this);
builder.setTitle(R.string.app_name);
builder.setMessage(message);
builder.setCancelable(true);
builder.setPositiveButton(R.string.options_bump_fee, new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, int whichButton) {
if (cpfpTask == null || cpfpTask.getStatus().equals(AsyncTask.Status.FINISHED)) {
cpfpTask = new CPFPTask();
cpfpTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, tx.getHash());
}
}
});
builder.setNegativeButton(R.string.options_block_explorer, new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, int whichButton) {
doExplorerView(tx.getHash());
}
});
AlertDialog alert = builder.create();
alert.show();
} else {
doExplorerView(tx.getHash());
return;
}
}
}
});
swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swiperefresh);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
new Handler().post(new Runnable() {
@Override
public void run() {
refreshTx(false, true, true, false);
}
});
}
});
swipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_bright, android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light);
IntentFilter filter = new IntentFilter(ACTION_INTENT);
LocalBroadcastManager.getInstance(BalanceActivity.this).registerReceiver(receiver, filter);
// TorUtil.getInstance(BalanceActivity.this).setStatusFromBroadcast(false);
registerReceiver(torStatusReceiver, new IntentFilter(OrbotHelper.ACTION_STATUS));
boolean notifTx = false;
boolean fetch = false;
Bundle extras = getIntent().getExtras();
if (extras != null && extras.containsKey("notifTx")) {
notifTx = extras.getBoolean("notifTx");
}
if (extras != null && extras.containsKey("uri")) {
fetch = extras.getBoolean("fetch");
}
refreshTx(notifTx, fetch, false, true);
if (PrefsUtil.getInstance(BalanceActivity.this).getValue(PrefsUtil.PAYNYM_CLAIMED, false) == false && PrefsUtil.getInstance(BalanceActivity.this).getValue(PrefsUtil.PAYNYM_REFUSED, false) == false) {
doClaimPayNym();
}
if (!AppUtil.getInstance(BalanceActivity.this).isClipboardSeen()) {
doClipboardCheck();
}
}
use of com.samourai.wallet.api.Tx in project samourai-wallet-android by Samourai-Wallet.
the class PaynymTxListAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
Tx tx = txList.get(position);
SimpleDateFormat sdf = new SimpleDateFormat("MMM d, yyyy", Locale.US);
sdf.setTimeZone(TimeZone.getDefault());
holder.date.setText(sdf.format(tx.getTS() * 1000L));
holder.amount.setText(sdf.format(tx.getTS() * 1000L));
long _amount = 0L;
if (tx.getAmount() < 0.0) {
_amount = Math.abs((long) tx.getAmount());
} else {
_amount = (long) tx.getAmount();
}
if (tx.getAmount() < 0.0) {
holder.icon.setImageResource(R.drawable.out_going_tx_whtie_arrow);
holder.amount.setText(context.getString(R.string.you_sent).concat(" ").concat(this.getBTCDisplayAmount(_amount)).concat(" BTC"));
} else {
holder.icon.setImageResource(R.drawable.incoming_tx_green);
holder.amount.setText(context.getString(R.string.you_received).concat(" ").concat(this.getBTCDisplayAmount(_amount)).concat(" BTC"));
}
holder.amount.getRootView().setOnClickListener(view -> {
Intent txIntent = new Intent(context, TxDetailsActivity.class);
txIntent.putExtra("TX", tx.toJSON().toString());
context.startActivity(txIntent);
});
}
use of com.samourai.wallet.api.Tx in project samourai-wallet-android by Samourai-Wallet.
the class BalanceViewModel method loadOfflineData.
void loadOfflineData() {
try {
JSONObject response = PayloadUtil.getInstance(getApplication()).deserializeMultiAddr();
if (response != null) {
Disposable disposable = parseXPUB(new JSONObject(response.toString())).subscribeOn(Schedulers.computation()).observeOn(AndroidSchedulers.mainThread()).subscribe(boo -> {
List<Tx> txes = new ArrayList<Tx>();
for (String key : xpub_txs.keySet()) {
List<Tx> txs = xpub_txs.get(key);
txes.addAll(txs);
}
Collections.sort(txes, new APIFactory.TxMostRecentDateComparator());
txs.postValue(txes);
toggleSat.setValue(false);
balance.postValue(xpub_balance - BlockedUTXO.getInstance().getTotalValueBlocked0());
}, error -> {
txs.postValue(new ArrayList<>());
toggleSat.setValue(false);
balance.postValue(0L);
});
compositeDisposables.add(disposable);
}
// Log.i(TAG, "BalanceViewModel: ".concat(response));
} catch (IOException | JSONException e) {
e.printStackTrace();
txs.setValue(new ArrayList<>());
toggleSat.setValue(false);
balance.setValue(0L);
}
}
use of com.samourai.wallet.api.Tx in project samourai-wallet-android by Samourai-Wallet.
the class BalanceActivity method initViewModel.
private void initViewModel() {
TxAdapter adapter = new TxAdapter(getApplicationContext(), new ArrayList<>(), account);
adapter.setHasStableIds(true);
adapter.setClickListener((position, tx) -> txDetails(tx));
TxRecyclerView.setAdapter(adapter);
balanceViewModel.getBalance().observe(this, balance -> {
if (balance < 0) {
return;
}
if (balanceViewModel.getSatState().getValue() != null) {
setBalance(balance, balanceViewModel.getSatState().getValue());
} else {
setBalance(balance, false);
}
});
adapter.setTxes(balanceViewModel.getTxs().getValue());
setBalance(balanceViewModel.getBalance().getValue(), false);
balanceViewModel.getSatState().observe(this, state -> {
if (state == null) {
state = false;
}
setBalance(balanceViewModel.getBalance().getValue(), state);
adapter.toggleDisplayUnit(state);
});
balanceViewModel.getTxs().observe(this, new Observer<List<Tx>>() {
@Override
public void onChanged(@Nullable List<Tx> list) {
adapter.setTxes(list);
}
});
mCollapsingToolbar.setOnClickListener(view -> balanceViewModel.toggleSat());
}
use of com.samourai.wallet.api.Tx in project samourai-wallet-android by Samourai-Wallet.
the class TxDetailsActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tx);
setSupportActionBar(findViewById(R.id.toolbar));
if (getIntent().hasExtra("TX")) {
try {
JSONObject TxJsonObject = new JSONObject(getIntent().getStringExtra("TX"));
tx = new Tx(TxJsonObject);
} catch (JSONException e) {
e.printStackTrace();
}
}
payNymUsername = findViewById(R.id.tx_paynym_username);
btcUnit = findViewById(R.id.tx_unit);
amount = findViewById(R.id.tx_amount);
payNymAvatar = findViewById(R.id.img_paynym_avatar);
txId = findViewById(R.id.transaction_id);
txStatus = findViewById(R.id.tx_status);
txDate = findViewById(R.id.tx_date);
bottomButton = findViewById(R.id.btn_bottom_button);
Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
progressBar = findViewById(R.id.progressBar);
minerFee = findViewById(R.id.tx_miner_fee_paid);
minerFeeRate = findViewById(R.id.tx_miner_fee_rate);
amount.setOnClickListener(view -> toggleUnits());
btcUnit.setOnClickListener(view -> toggleUnits());
setTx();
bottomButton.setOnClickListener(view -> {
if (this.isBoostingAvailable()) {
this.doBoosting();
} else {
refundOrPayAgain();
}
});
txId.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) TxDetailsActivity.this.getSystemService(android.content.Context.CLIPBOARD_SERVICE);
android.content.ClipData clip;
clip = android.content.ClipData.newPlainText("tx id", ((TextView) view).getText());
if (clipboard != null) {
clipboard.setPrimaryClip(clip);
}
Toast.makeText(TxDetailsActivity.this, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
}).setNegativeButton(R.string.no, (dialog, whichButton) -> {
}).show();
});
}
Aggregations