]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/model/AccountListItem.java
adopt Room for displaying account lists
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / model / AccountListItem.java
index a96a9a3e2f75c4e9da6bc300e760e47879a860a9..dfd3d982011a105191f5e801bea2fcc5e276c4d6 100644 (file)
 package net.ktnx.mobileledger.model;
 
 import androidx.annotation.NonNull;
+import androidx.lifecycle.LiveData;
 
 import org.jetbrains.annotations.NotNull;
 
-public class AccountListItem {
+public abstract class AccountListItem {
     private AccountListItem() {}
+    public abstract boolean sameContent(AccountListItem other);
     @NonNull
     public Type getType() {
         if (this instanceof Account)
@@ -46,10 +48,30 @@ public class AccountListItem {
         public Account(@NotNull LedgerAccount account) {
             this.account = account;
         }
+        @Override
+        public boolean sameContent(AccountListItem other) {
+            if (!(other instanceof Account))
+                return false;
+            return ((Account) other).account.hasSubAccounts() == account.hasSubAccounts() &&
+                   ((Account) other).account.amountsExpanded() == account.amountsExpanded() &&
+                   ((Account) other).account.isExpanded() == account.isExpanded() &&
+                   ((Account) other).account.getLevel() == account.getLevel() &&
+                   ((Account) other).account.getAmountsString()
+                                            .equals(account.getAmountsString());
+        }
     }
 
     public static class Header extends AccountListItem {
-        public Header() {
+        private final LiveData<String> text;
+        public Header(@NonNull LiveData<String> text) {
+            this.text = text;
+        }
+        public LiveData<String> getText() {
+            return text;
+        }
+        @Override
+        public boolean sameContent(AccountListItem other) {
+            return true;
         }
     }
 }