package cash.z.ecc.android.ui.history import android.view.LayoutInflater import android.view.ViewGroup import androidx.paging.PagedListAdapter import androidx.recyclerview.widget.DiffUtil import cash.z.ecc.android.R import cash.z.ecc.android.sdk.db.entity.ConfirmedTransaction class TransactionAdapter : PagedListAdapter>( object : DiffUtil.ItemCallback() { override fun areItemsTheSame( oldItem: T, newItem: T ) = oldItem.minedHeight == newItem.minedHeight && oldItem.noteId == newItem.noteId && // bugfix: distinguish between self-transactions so they don't overwrite each other in the UI // TODO confirm that this is working, as intended ((oldItem.raw == null && newItem.raw == null) || (oldItem.raw != null && newItem.raw != null && oldItem.raw!!.contentEquals(newItem.raw!!))) override fun areContentsTheSame( oldItem: T, newItem: T ) = oldItem == newItem } ) { init { setHasStableIds(true) } override fun onCreateViewHolder( parent: ViewGroup, viewType: Int ) = TransactionViewHolder( LayoutInflater.from(parent.context).inflate(R.layout.item_transaction, parent, false) ) override fun onBindViewHolder( holder: TransactionViewHolder, position: Int ) = holder.bindTo(getItem(position)) override fun getItemId(position: Int): Long { return getItem(position)?.id ?: -1 } }