]> git.ktnx.net Git - mobile-ledger.git/commitdiff
fix JSON account retrieval to supply the amounts to the new list
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Tue, 2 Apr 2019 21:36:33 +0000 (00:36 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Tue, 2 Apr 2019 21:56:44 +0000 (00:56 +0300)
app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java
app/src/main/java/net/ktnx/mobileledger/json/ParsedBalance.java

index 8a75996cd2adf53c3aabe381964c0cd66f63e5d3..57a2739f70e066997907f6f1ed1935602b601540 100644 (file)
@@ -414,9 +414,26 @@ public class RetrieveTransactionsTask
                     else acc.removeAmounts();
 
                     profile.storeAccount(db, acc);
+                    String lastCurrency = null;
+                    float lastCurrencyAmount = 0;
                     for (ParsedBalance b : parsedAccount.getAibalance()) {
-                        profile.storeAccountValue(db, acc.getName(), b.getAcommodity(),
-                                b.getAquantity().asFloat());
+                        final String currency = b.getAcommodity();
+                        final float amount = b.getAquantity().asFloat();
+                        if (currency.equals(lastCurrency)) lastCurrencyAmount += amount;
+                        else {
+                            if (lastCurrency != null) {
+                                profile.storeAccountValue(db, acc.getName(), lastCurrency,
+                                        lastCurrencyAmount);
+                                acc.addAmount(lastCurrencyAmount, lastCurrency);
+                            }
+                            lastCurrency = currency;
+                            lastCurrencyAmount = amount;
+                        }
+                    }
+                    if (lastCurrency != null) {
+                        profile.storeAccountValue(db, acc.getName(), lastCurrency,
+                                lastCurrencyAmount);
+                        acc.addAmount(lastCurrencyAmount, lastCurrency);
                     }
 
                     if (acc.isVisible(accountList)) accountList.add(acc);
index 63a0e05c386bfd9ab1e3b47d8ba33e8f9e7df67a..a355bbdfda431d3487629e0b2119ac6a694bb141 100644 (file)
@@ -19,6 +19,8 @@ package net.ktnx.mobileledger.json;
 
 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 
+import androidx.annotation.NonNull;
+
 @JsonIgnoreProperties(ignoreUnknown = true)
 public class ParsedBalance {
     private ParsedQuantity aquantity;
@@ -32,8 +34,9 @@ public class ParsedBalance {
     public void setAquantity(ParsedQuantity aquantity) {
         this.aquantity = aquantity;
     }
+    @NonNull
     public String getAcommodity() {
-        return acommodity;
+        return (acommodity == null) ? "" : acommodity;
     }
     public void setAcommodity(String acommodity) {
         this.acommodity = acommodity;