Skip to content

Commit

Permalink
Fixed exchange rates update
Browse files Browse the repository at this point in the history
  • Loading branch information
mvarnagiris committed Jan 30, 2015
1 parent 445a5cd commit 74b10c3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 24 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 2 additions & 0 deletions financius/src/main/java/com/code44/finance/api/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ExchangeRate> getExchangeRates() {
final Set<ExchangeRate> 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<Rate> rates;
}

private static class Rate {
@SerializedName("id")
private String id;

@SerializedName("Rate")
private double rate;
}
}

0 comments on commit 74b10c3

Please sign in to comment.