From: Damyan Ivanov Date: Tue, 2 Apr 2019 21:36:33 +0000 (+0300) Subject: fix JSON account retrieval to supply the amounts to the new list X-Git-Tag: v0.9~20 X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=commitdiff_plain;h=025fe22c621f5977742198becce9cc4b9d9a018c;hp=608de71a076ac030abb61ace753c9357ea33064e fix JSON account retrieval to supply the amounts to the new list --- diff --git a/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java b/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java index 8a75996c..57a2739f 100644 --- a/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java +++ b/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java @@ -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); diff --git a/app/src/main/java/net/ktnx/mobileledger/json/ParsedBalance.java b/app/src/main/java/net/ktnx/mobileledger/json/ParsedBalance.java index 63a0e05c..a355bbdf 100644 --- a/app/src/main/java/net/ktnx/mobileledger/json/ParsedBalance.java +++ b/app/src/main/java/net/ktnx/mobileledger/json/ParsedBalance.java @@ -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;