]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListAdapter.java
running totals when filtering transactions by account
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / transaction_list / TransactionListAdapter.java
index 599a9f8c8024e39e020a63485be749e1f5e0f27d..0c0ff6a7e3163f1d2ed82eeaff47c56b0a883702 100644 (file)
@@ -41,6 +41,8 @@ public class TransactionListAdapter extends RecyclerView.Adapter<TransactionRowH
     public TransactionListAdapter() {
         super();
 
+        setHasStableIds(true);
+
         listDiffer = new AsyncListDiffer<>(this, new DiffUtil.ItemCallback<TransactionListItem>() {
             @Override
             public boolean areItemsTheSame(@NonNull TransactionListItem oldItem,
@@ -68,8 +70,7 @@ public class TransactionListAdapter extends RecyclerView.Adapter<TransactionRowH
                                               @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()) &&
@@ -89,6 +90,24 @@ public class TransactionListAdapter extends RecyclerView.Adapter<TransactionRowH
         });
     }
     @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)
@@ -110,9 +129,8 @@ public class TransactionListAdapter extends RecyclerView.Adapter<TransactionRowH
 
         switch (newType) {
             case TRANSACTION:
-                LedgerTransaction tr = item.getTransaction();
                 holder.asTransaction()
-                      .bind(tr, item.getBoldAccountName());
+                      .bind(item, item.getBoldAccountName());
 
                 break;
             case DELIMITER: