Search in sources :

Example 1 with TransactionItem

use of de.schildbach.wallet.ui.TransactionsAdapter.ListItem.TransactionItem in project bitcoin-wallet by bitcoin-wallet.

the class TransactionsAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position, final List<Object> payloads) {
    final boolean fullBind = payloads.isEmpty();
    final EnumSet<ChangeType> changes = EnumSet.noneOf(ChangeType.class);
    for (final Object payload : payloads) changes.addAll((EnumSet<ChangeType>) payload);
    final ListItem listItem = getItem(position);
    if (holder instanceof TransactionViewHolder) {
        final TransactionViewHolder transactionHolder = (TransactionViewHolder) holder;
        final ListItem.TransactionItem transactionItem = (ListItem.TransactionItem) listItem;
        final boolean isSelected = transactionItem.transactionId.equals(selectedTransactionId);
        if (fullBind) {
            final OnClickListener onClickListener = this.onClickListener;
            if (onClickListener != null)
                transactionHolder.itemView.setOnClickListener(v -> onClickListener.onTransactionClick(v, transactionItem.transactionId));
        }
        if (fullBind || changes.contains(ChangeType.SELECTION)) {
            transactionHolder.itemView.setSelected(isSelected);
            transactionHolder.contextBar.setVisibility(View.GONE);
            if (contextMenuCallback != null && isSelected) {
                final Menu menu = transactionHolder.contextBar.getMenu();
                menu.clear();
                contextMenuCallback.onInflateTransactionContextMenu(menuInflater, menu, transactionItem.transactionId);
                if (menu.hasVisibleItems()) {
                    transactionHolder.contextBar.setVisibility(View.VISIBLE);
                    transactionHolder.contextBar.setOnMenuItemClickListener(item -> contextMenuCallback.onClickTransactionContextMenuItem(item, transactionItem.transactionId));
                }
            }
        }
        if (fullBind || changes.contains(ChangeType.CONFIDENCE) || changes.contains(ChangeType.SELECTION))
            transactionHolder.bindConfidence(transactionItem, isSelected);
        if (fullBind || changes.contains(ChangeType.TIME) || changes.contains(ChangeType.SELECTION))
            transactionHolder.bindTime(transactionItem, isSelected);
        if (fullBind || changes.contains(ChangeType.ADDRESS) || changes.contains(ChangeType.SELECTION))
            transactionHolder.bindAddress(transactionItem, isSelected);
        if (fullBind || changes.contains(ChangeType.FEE) || changes.contains(ChangeType.SELECTION))
            transactionHolder.bindFee(transactionItem, isSelected);
        if (fullBind || changes.contains(ChangeType.VALUE))
            transactionHolder.bindValue(transactionItem);
        if (fullBind || changes.contains(ChangeType.FIAT))
            transactionHolder.bindFiat(transactionItem);
        if (fullBind || changes.contains(ChangeType.MESSAGE) || changes.contains(ChangeType.SELECTION))
            transactionHolder.bindMessage(transactionItem, isSelected);
    } else if (holder instanceof WarningViewHolder) {
        final WarningViewHolder warningHolder = (WarningViewHolder) holder;
        final ListItem.WarningItem warningItem = (ListItem.WarningItem) listItem;
        if (warningItem.type == WarningType.BACKUP) {
            if (getItemCount() == 2) /* 1 transaction, 1 warning */
            {
                warningHolder.message.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
                warningHolder.message.setText(Html.fromHtml(context.getString(R.string.wallet_transactions_row_warning_backup)));
            } else {
                warningHolder.message.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_warning_grey600_24dp, 0, 0, 0);
                warningHolder.message.setText(Html.fromHtml(context.getString(R.string.wallet_disclaimer_fragment_remind_backup)));
            }
        } else if (warningItem.type == WarningType.STORAGE_ENCRYPTION) {
            warningHolder.message.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
            warningHolder.message.setText(Html.fromHtml(context.getString(R.string.wallet_transactions_row_warning_storage_encryption)));
        } else if (warningItem.type == WarningType.CHAIN_FORKING) {
            warningHolder.message.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_warning_grey600_24dp, 0, 0, 0);
            warningHolder.message.setText(Html.fromHtml(context.getString(R.string.wallet_transactions_row_warning_chain_forking)));
        }
        if (onClickListener != null)
            warningHolder.itemView.setOnClickListener(v -> onClickListener.onWarningClick(v, warningItem.type));
    }
}
Also used : Typeface(android.graphics.Typeface) Context(android.content.Context) SpannedString(android.text.SpannedString) AddressBookEntry(de.schildbach.wallet.addressbook.AddressBookEntry) Spanned(android.text.Spanned) DateUtils(android.text.format.DateUtils) Transaction(org.bitcoinj.core.Transaction) TransactionConfidence(org.bitcoinj.core.TransactionConfidence) Coin(org.bitcoinj.core.Coin) Date(java.util.Date) Wallet(org.bitcoinj.wallet.Wallet) MainThread(androidx.annotation.MainThread) TransactionItem(de.schildbach.wallet.ui.TransactionsAdapter.ListItem.TransactionItem) ByteBuffer(java.nio.ByteBuffer) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) MenuInflater(android.view.MenuInflater) Toolbar(android.widget.Toolbar) Map(java.util.Map) Menu(android.view.Menu) View(android.view.View) R(de.schildbach.wallet.R) RecyclerView(androidx.recyclerview.widget.RecyclerView) Sha256Hash(org.bitcoinj.core.Sha256Hash) Constants(de.schildbach.wallet.Constants) EnumSet(java.util.EnumSet) ListAdapter(androidx.recyclerview.widget.ListAdapter) WalletUtils(de.schildbach.wallet.util.WalletUtils) ConfidenceType(org.bitcoinj.core.TransactionConfidence.ConfidenceType) Purpose(org.bitcoinj.core.Transaction.Purpose) ExchangeRate(org.bitcoinj.utils.ExchangeRate) LayoutInflater(android.view.LayoutInflater) DiffUtil(androidx.recyclerview.widget.DiffUtil) Fiat(org.bitcoinj.utils.Fiat) MonetaryFormat(org.bitcoinj.utils.MonetaryFormat) ViewGroup(android.view.ViewGroup) Color(android.graphics.Color) Objects(java.util.Objects) List(java.util.List) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) Html(android.text.Html) Address(org.bitcoinj.core.Address) DefaultCoinSelector(org.bitcoinj.wallet.DefaultCoinSelector) Formats(de.schildbach.wallet.util.Formats) ColorUtils(androidx.core.graphics.ColorUtils) TransactionItem(de.schildbach.wallet.ui.TransactionsAdapter.ListItem.TransactionItem) EnumSet(java.util.EnumSet) TransactionItem(de.schildbach.wallet.ui.TransactionsAdapter.ListItem.TransactionItem) Menu(android.view.Menu)

Aggregations

Context (android.content.Context)1 Color (android.graphics.Color)1 Typeface (android.graphics.Typeface)1 Html (android.text.Html)1 Spanned (android.text.Spanned)1 SpannedString (android.text.SpannedString)1 DateUtils (android.text.format.DateUtils)1 LayoutInflater (android.view.LayoutInflater)1 Menu (android.view.Menu)1 MenuInflater (android.view.MenuInflater)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 TextView (android.widget.TextView)1 Toolbar (android.widget.Toolbar)1 MainThread (androidx.annotation.MainThread)1 Nullable (androidx.annotation.Nullable)1 ColorUtils (androidx.core.graphics.ColorUtils)1 DiffUtil (androidx.recyclerview.widget.DiffUtil)1 ListAdapter (androidx.recyclerview.widget.ListAdapter)1