]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryAdapter.java
migrate to surrogate IDs for all database objects
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / account_summary / AccountSummaryAdapter.java
index c6c909152de2b6cb575d4130e58bd6688aee63a9..20b72915b9224158cfb11d07d0caa3c5c71b4afa 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2020 Damyan Ivanov.
+ * Copyright © 2021 Damyan Ivanov.
  * This file is part of MoLe.
  * MoLe is free software: you can distribute it and/or modify it
  * under the term of the GNU General Public License as published by
@@ -19,8 +19,6 @@ package net.ktnx.mobileledger.ui.account_summary;
 
 import android.content.Context;
 import android.content.res.Resources;
-import android.text.TextUtils;
-import android.text.format.DateUtils;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -43,6 +41,7 @@ import net.ktnx.mobileledger.model.MobileLedgerProfile;
 import net.ktnx.mobileledger.ui.MainModel;
 import net.ktnx.mobileledger.ui.activity.MainActivity;
 import net.ktnx.mobileledger.utils.Locker;
+import net.ktnx.mobileledger.utils.Misc;
 
 import org.jetbrains.annotations.NotNull;
 
@@ -72,9 +71,9 @@ public class AccountSummaryAdapter
                 if (oldType != newType)
                     return false;
 
-                return TextUtils.equals(oldItem.getAccount()
-                                               .getName(), newItem.getAccount()
-                                                                  .getName());
+                return Misc.equalStrings(oldItem.getAccount()
+                                                .getName(), newItem.getAccount()
+                                                                   .getName());
             }
             @Override
             public boolean areContentsTheSame(@NotNull AccountListItem oldItem,
@@ -170,7 +169,7 @@ public class AccountSummaryAdapter
             model.updateDisplayedAccounts();
 
             DbOpQueue.add("update accounts set expanded=? where name=? and profile=?",
-                    new Object[]{mAccount.isExpanded(), mAccount.getName(), profile.getUuid()
+                    new Object[]{mAccount.isExpanded(), mAccount.getName(), profile.getId()
                     });
 
         }
@@ -193,7 +192,7 @@ public class AccountSummaryAdapter
                 return;
 
             DbOpQueue.add("update accounts set amounts_expanded=? where name=? and profile=?",
-                    new Object[]{mAccount.amountsExpanded(), mAccount.getName(), profile.getUuid()
+                    new Object[]{mAccount.amountsExpanded(), mAccount.getName(), profile.getId()
                     });
 
         }
@@ -257,32 +256,29 @@ public class AccountSummaryAdapter
 
                     break;
                 case HEADER:
-                    setLastUpdateText(Data.lastUpdate.get());
+                    setLastUpdateText(Data.lastAccountsUpdateText.get());
                     break;
                 default:
                     throw new IllegalStateException("Unexpected value: " + newType);
             }
 
         }
-        void setLastUpdateText(long lastUpdate) {
-            final int formatFlags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR |
-                                    DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_NUMERIC_DATE;
-            tvLastUpdate.setText((lastUpdate == 0) ? "----" : DateUtils.formatDateTime(
-                    tvLastUpdate.getContext(), lastUpdate, formatFlags));
+        void setLastUpdateText(String text) {
+            tvLastUpdate.setText(text);
         }
         private void initLastUpdateObserver() {
             if (lastUpdateObserver != null)
                 return;
 
-            lastUpdateObserver = (o, arg) -> setLastUpdateText(Data.lastUpdate.get());
+            lastUpdateObserver = (o, arg) -> setLastUpdateText(Data.lastAccountsUpdateText.get());
 
-            Data.lastUpdate.addObserver(lastUpdateObserver);
+            Data.lastAccountsUpdateText.addObserver(lastUpdateObserver);
         }
         private void dropLastUpdateObserver() {
             if (lastUpdateObserver == null)
                 return;
 
-            Data.lastUpdate.deleteObserver(lastUpdateObserver);
+            Data.lastAccountsUpdateText.deleteObserver(lastUpdateObserver);
             lastUpdateObserver = null;
         }
         private void setType(AccountListItem.Type newType) {