]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListAdapter.java
last update text also includes transaction count
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / transaction_list / TransactionListAdapter.java
index 6f13930ad286bc63593f0bf3c7aaac88736fc3c1..d9f4cf16a53a56a465926078af4964925d0d5fdf 100644 (file)
@@ -39,6 +39,7 @@ import androidx.recyclerview.widget.RecyclerView;
 
 import net.ktnx.mobileledger.App;
 import net.ktnx.mobileledger.R;
+import net.ktnx.mobileledger.model.Data;
 import net.ktnx.mobileledger.model.LedgerTransaction;
 import net.ktnx.mobileledger.model.LedgerTransactionAccount;
 import net.ktnx.mobileledger.model.TransactionListItem;
@@ -56,8 +57,8 @@ import java.util.Locale;
 import java.util.TimeZone;
 
 public class TransactionListAdapter extends RecyclerView.Adapter<TransactionRowHolder> {
-    private MainModel model;
-    private AsyncListDiffer<TransactionListItem> listDiffer;
+    private final MainModel model;
+    private final AsyncListDiffer<TransactionListItem> listDiffer;
     public TransactionListAdapter(MainModel model) {
         super();
         this.model = model;
@@ -76,6 +77,8 @@ public class TransactionListAdapter extends RecyclerView.Adapter<TransactionRowH
                         return oldItem.getTransaction()
                                       .getId() == newItem.getTransaction()
                                                          .getId();
+                    case HEADER:
+                        return true;    // there can be only one header
                     default:
                         throw new IllegalStateException(
                                 String.format(Locale.US, "Unexpected transaction item type %s",
@@ -92,6 +95,10 @@ public class TransactionListAdapter extends RecyclerView.Adapter<TransactionRowH
                     case TRANSACTION:
                         return oldItem.getTransaction()
                                       .equals(newItem.getTransaction());
+                    case HEADER:
+                        // headers don't differ in their contents. they observe the last update
+                        // date and react to its changes
+                        return true;
                     default:
                         throw new IllegalStateException(
                                 String.format(Locale.US, "Unexpected transaction item type %s",
@@ -112,10 +119,11 @@ public class TransactionListAdapter extends RecyclerView.Adapter<TransactionRowH
         if (item == null)
             return;
 
-        switch (item.getType()) {
+        final TransactionListItem.Type newType = item.getType();
+        holder.setType(newType);
+
+        switch (newType) {
             case TRANSACTION:
-                holder.vTransaction.setVisibility(View.VISIBLE);
-                holder.vDelimiter.setVisibility(View.GONE);
                 LedgerTransaction tr = item.getTransaction();
 
                 //        debug("transactions", String.format("Filling position %d with %d
@@ -137,8 +145,6 @@ public class TransactionListAdapter extends RecyclerView.Adapter<TransactionRowH
                 break;
             case DELIMITER:
                 SimpleDate date = item.getDate();
-                holder.vTransaction.setVisibility(View.GONE);
-                holder.vDelimiter.setVisibility(View.VISIBLE);
                 holder.tvDelimiterDate.setText(DateFormat.getDateInstance()
                                                          .format(date.toDate()));
                 if (item.isMonthShown()) {
@@ -159,9 +165,14 @@ public class TransactionListAdapter extends RecyclerView.Adapter<TransactionRowH
                     holder.vDelimiterThick.setVisibility(View.GONE);
                 }
                 break;
+            case HEADER:
+                holder.setLastUpdateText(Data.lastUpdateText.get());
+
+                break;
+            default:
+                throw new IllegalStateException("Unexpected value: " + newType);
         }
     }
-
     @NonNull
     @Override
     public TransactionRowHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
@@ -297,10 +308,10 @@ public class TransactionListAdapter extends RecyclerView.Adapter<TransactionRowH
     }
 
     private static class TransactionLoaderParams {
-        LedgerTransaction transaction;
-        TransactionRowHolder holder;
-        int position;
-        String boldAccountName;
+        final LedgerTransaction transaction;
+        final TransactionRowHolder holder;
+        final int position;
+        final String boldAccountName;
         TransactionLoaderParams(LedgerTransaction transaction, TransactionRowHolder holder,
                                 int position, String boldAccountName) {
             this.transaction = transaction;