From 74b10c33fef1fb6920a2de210732cda72e8b4ea3 Mon Sep 17 00:00:00 2001 From: Mantas Varnagiris Date: Fri, 30 Jan 2015 19:49:57 +0000 Subject: [PATCH] Fixed exchange rates update --- CHANGELOG.md | 4 +++ .../java/com/code44/finance/api/Request.java | 2 ++ .../api/currencies/ExchangeRatesResponse.java | 35 ++++++------------- 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80219864..8aee0fc2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +###Version: 0.18.1 +- ```fix``` Fixed currency exchange rates update. +- ```fix``` Categories report shows tag amounts again. + ###Version: 0.18.0 - ```new``` New trends graph that is interactive. - ```new``` Updated settings page UI. diff --git a/financius/src/main/java/com/code44/finance/api/Request.java b/financius/src/main/java/com/code44/finance/api/Request.java index fd3617d2..5b8ade5e 100644 --- a/financius/src/main/java/com/code44/finance/api/Request.java +++ b/financius/src/main/java/com/code44/finance/api/Request.java @@ -2,6 +2,7 @@ import com.code44.finance.utils.EventBus; import com.code44.finance.utils.Logger; +import com.crashlytics.android.Crashlytics; import java.util.concurrent.Callable; @@ -22,6 +23,7 @@ protected Request(EventBus eventBus) { final T data = performRequest(); result = new Result<>(data, null); } catch (Exception error) { + Crashlytics.logException(error); logger.error("Request failed.", error); result = new Result<>(null, error); } diff --git a/financius/src/main/java/com/code44/finance/api/currencies/ExchangeRatesResponse.java b/financius/src/main/java/com/code44/finance/api/currencies/ExchangeRatesResponse.java index ffd87b5d..ce7554d4 100644 --- a/financius/src/main/java/com/code44/finance/api/currencies/ExchangeRatesResponse.java +++ b/financius/src/main/java/com/code44/finance/api/currencies/ExchangeRatesResponse.java @@ -1,44 +1,31 @@ package com.code44.finance.api.currencies; import com.code44.finance.data.model.ExchangeRate; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; import com.google.gson.annotations.SerializedName; import java.util.HashSet; -import java.util.List; import java.util.Set; public class ExchangeRatesResponse { @SerializedName("query") - private Query query; + private JsonObject query; public Set getExchangeRates() { final Set exchangeRates = new HashSet<>(); - for (Rate rate : query.results.rates) { + final JsonArray jsonArray = query.getAsJsonObject("results").getAsJsonArray("rate"); + for (int i = 0, size = jsonArray.size(); i < size; i++) { + final JsonObject jsonObject = jsonArray.get(i).getAsJsonObject(); + final String id = jsonObject.get("id").getAsString(); + final double rate = jsonObject.get("Rate").getAsDouble(); final ExchangeRate exchangeRate = new ExchangeRate(); - exchangeRate.setFromCode(rate.id.substring(0, 3)); - exchangeRate.setToCode(rate.id.substring(3)); - exchangeRate.setRate(rate.rate); + exchangeRate.setFromCode(id.substring(0, 3)); + exchangeRate.setToCode(id.substring(3)); + exchangeRate.setRate(rate); exchangeRates.add(exchangeRate); } return exchangeRates; } - - private static class Query { - @SerializedName("results") - private Results results; - } - - private static class Results { - @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") @SerializedName("rate") - private List rates; - } - - private static class Rate { - @SerializedName("id") - private String id; - - @SerializedName("Rate") - private double rate; - } }