]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/MainModel.java
specialized sub-classes of AccountListItem
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / MainModel.java
index 813e3a00b3ab54a49b480ccad5f9b5584d077cd5..845242bfee305290c724d27eb2f784bfea8d4a46 100644 (file)
@@ -290,8 +290,8 @@ public class MainModel extends ViewModel {
             ArrayList<LedgerAccount> list = new ArrayList<>();
             HashMap<String, LedgerAccount> map = new HashMap<>();
 
-            String sql = "SELECT a.name, a.expanded, a.amounts_expanded";
-            sql += " from accounts a WHERE a.profile = ?";
+            String sql = "SELECT a.name, a.expanded, a.amounts_expanded, a.id";
+            sql += " from accounts a WHERE a.profile_id = ?";
             sql += " ORDER BY a.name";
 
             SQLiteDatabase db = App.getDatabase();
@@ -302,6 +302,7 @@ public class MainModel extends ViewModel {
                     if (isInterrupted())
                         return;
 
+                    final long accId = cursor.getLong(3);
                     final String accName = cursor.getString(0);
 //                    debug("accounts",
 //                            String.format("Read account '%s' from DB [%s]", accName,
@@ -325,8 +326,8 @@ public class MainModel extends ViewModel {
                     acc.setHasSubAccounts(false);
 
                     try (Cursor c2 = db.rawQuery(
-                            "SELECT value, currency FROM account_values WHERE profile = ?" + " " +
-                            "AND account = ?", new String[]{String.valueOf(profileId), accName}))
+                            "SELECT value, currency FROM account_values WHERE account_id = ?",
+                            new String[]{String.valueOf(accId)}))
                     {
                         while (c2.moveToNext()) {
                             acc.addAmount(c2.getFloat(0), c2.getString(1));
@@ -362,7 +363,7 @@ public class MainModel extends ViewModel {
             Logger.debug("dFilter", "waiting for synchronized block");
             Logger.debug("dFilter", String.format(Locale.US,
                     "entered synchronized block (about to examine %d accounts)", list.size()));
-            newDisplayed.add(new AccountListItem());    // header
+            newDisplayed.add(new AccountListItem.Header());    // header
 
             int count = 0;
             for (LedgerAccount a : list) {
@@ -370,7 +371,7 @@ public class MainModel extends ViewModel {
                     return;
 
                 if (a.isVisible()) {
-                    newDisplayed.add(new AccountListItem(a));
+                    newDisplayed.add(new AccountListItem.Account(a));
                     count++;
                 }
             }