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