Search in sources :

Example 1 with Block

use of org.bitcoinj.core.Block in project bitcoin-wallet by bitcoin-wallet.

the class BlockListAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final BlockViewHolder holder, final int position) {
    final StoredBlock storedBlock = getItem(position);
    final Block header = storedBlock.getHeader();
    holder.miningRewardAdjustmentView.setVisibility(isMiningRewardHalvingPoint(storedBlock) ? View.VISIBLE : View.GONE);
    holder.miningDifficultyAdjustmentView.setVisibility(isDifficultyTransitionPoint(storedBlock) ? View.VISIBLE : View.GONE);
    final int height = storedBlock.getHeight();
    holder.heightView.setText(Integer.toString(height));
    final long timeMs = header.getTimeSeconds() * DateUtils.SECOND_IN_MILLIS;
    if (timeMs < System.currentTimeMillis() - DateUtils.MINUTE_IN_MILLIS)
        holder.timeView.setText(DateUtils.getRelativeDateTimeString(context, timeMs, DateUtils.MINUTE_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, 0));
    else
        holder.timeView.setText(R.string.block_row_now);
    holder.hashView.setText(WalletUtils.formatHash(null, header.getHashAsString(), 8, 0, ' '));
    final int transactionChildCount = holder.transactionsViewGroup.getChildCount() - ROW_BASE_CHILD_COUNT;
    int iTransactionView = 0;
    final Sha256Hash blockHash = header.getHash();
    for (final Transaction tx : transactions) {
        if (tx.getAppearsInHashes().containsKey(blockHash)) {
            final View view;
            if (iTransactionView < transactionChildCount) {
                view = holder.transactionsViewGroup.getChildAt(ROW_INSERT_INDEX + iTransactionView);
            } else {
                view = inflater.inflate(R.layout.block_row_transaction, null);
                holder.transactionsViewGroup.addView(view, ROW_INSERT_INDEX + iTransactionView);
            }
            bindView(view, tx);
            iTransactionView++;
        }
    }
    final int leftoverTransactionViews = transactionChildCount - iTransactionView;
    if (leftoverTransactionViews > 0)
        holder.transactionsViewGroup.removeViews(ROW_INSERT_INDEX + iTransactionView, leftoverTransactionViews);
    if (onClickListener != null) {
        holder.menuView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(final View v) {
                onClickListener.onBlockMenuClick(v, storedBlock);
            }
        });
    }
}
Also used : StoredBlock(org.bitcoinj.core.StoredBlock) Transaction(org.bitcoinj.core.Transaction) Sha256Hash(org.bitcoinj.core.Sha256Hash) Block(org.bitcoinj.core.Block) StoredBlock(org.bitcoinj.core.StoredBlock) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 TextView (android.widget.TextView)1 Block (org.bitcoinj.core.Block)1 Sha256Hash (org.bitcoinj.core.Sha256Hash)1 StoredBlock (org.bitcoinj.core.StoredBlock)1 Transaction (org.bitcoinj.core.Transaction)1