public TransactionListAdapter() {
super();
+ setHasStableIds(true);
+
listDiffer = new AsyncListDiffer<>(this, new DiffUtil.ItemCallback<TransactionListItem>() {
@Override
public boolean areItemsTheSame(@NonNull TransactionListItem oldItem,
@NonNull TransactionListItem newItem) {
switch (oldItem.getType()) {
case DELIMITER:
- // Delimiters items are "same" for same dates and the contents are the date
- return true;
+ return oldItem.isMonthShown() == newItem.isMonthShown();
case TRANSACTION:
return oldItem.getTransaction()
.equals(newItem.getTransaction()) &&
});
}
@Override
+ public long getItemId(int position) {
+ TransactionListItem item = listDiffer.getCurrentList()
+ .get(position);
+ switch (item.getType()) {
+ case HEADER:
+ return -1;
+ case TRANSACTION:
+ return item.getTransaction()
+ .getLedgerId();
+ case DELIMITER:
+ return -item.getDate()
+ .toDate()
+ .getTime();
+ default:
+ throw new IllegalStateException("Unexpected value: " + item.getType());
+ }
+ }
+ @Override
public int getItemViewType(int position) {
return listDiffer.getCurrentList()
.get(position)
switch (newType) {
case TRANSACTION:
- LedgerTransaction tr = item.getTransaction();
holder.asTransaction()
- .bind(tr, item.getBoldAccountName());
+ .bind(item, item.getBoldAccountName());
break;
case DELIMITER: