From 025fe22c621f5977742198becce9cc4b9d9a018c Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Wed, 3 Apr 2019 00:36:33 +0300 Subject: [PATCH] fix JSON account retrieval to supply the amounts to the new list --- .../async/RetrieveTransactionsTask.java | 21 +++++++++++++++++-- .../ktnx/mobileledger/json/ParsedBalance.java | 5 ++++- 2 files changed, 23 insertions(+), 3 deletions(-) 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; -- 2.39.5