diff --git a/app/src/main/java/rehanced/com/simpleetherwallet/activities/MainActivity.java b/app/src/main/java/rehanced/com/simpleetherwallet/activities/MainActivity.java index c0ba263..f12e46b 100644 --- a/app/src/main/java/rehanced/com/simpleetherwallet/activities/MainActivity.java +++ b/app/src/main/java/rehanced/com/simpleetherwallet/activities/MainActivity.java @@ -370,7 +370,7 @@ public void run() { public void run() { if (fragments != null) { if (fragments[0] != null) - ((FragmentPrice) fragments[0]).update(); + ((FragmentPrice) fragments[0]).update(true); if (fragments[1] != null) { ((FragmentWallets) fragments[1]).updateBalanceText(); ((FragmentWallets) fragments[1]).notifyDataSetChanged(); @@ -481,7 +481,7 @@ public void onUpdate(Response s) { public void run() { broadCastDataSetChanged(); if (fragments != null && fragments[0] != null) { - ((FragmentPrice) fragments[0]).update(); + ((FragmentPrice) fragments[0]).update(true); } } }); diff --git a/app/src/main/java/rehanced/com/simpleetherwallet/fragments/FragmentPrice.java b/app/src/main/java/rehanced/com/simpleetherwallet/fragments/FragmentPrice.java index a384593..0264c48 100644 --- a/app/src/main/java/rehanced/com/simpleetherwallet/fragments/FragmentPrice.java +++ b/app/src/main/java/rehanced/com/simpleetherwallet/fragments/FragmentPrice.java @@ -98,7 +98,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, @Override public void onClick(View view) { displayInUsd = !displayInUsd; - update(); + update(true); general(); if (ac != null && ac.getPreferences() != null) { @@ -145,7 +145,7 @@ public void onRefresh() { swipeLayout.setRefreshing(true); general(); - update(); + update(true); priceChart.setVisibility(View.INVISIBLE); return rootView; } @@ -153,11 +153,13 @@ public void onRefresh() { private void next() { displayType = (displayType + 1) % PERIOD.length; general(); + update(true); } private void previous() { displayType = displayType > 0 ? displayType - 1 : PERIOD.length - 1; general(); + update(true); } private void general() { @@ -169,13 +171,6 @@ private void general() { editor.putInt("displaytype_chart", displayType); editor.apply(); } - - //swipeLayout.setRefreshing(true); - try { - loadPriceData(TIMESTAMPS[displayType], PERIOD[displayType]); - } catch (IOException e) { - e.printStackTrace(); - } } private void loadPriceData(final long time, int period) throws IOException { @@ -203,7 +198,7 @@ public void onResponse(Call call, Response response) throws IOException { JSONObject o = data.getJSONObject(i); yVals.add(new Entry(o.getLong("date"), (float) Math.floor(o.getDouble("high") * exchangeRate * commas) / commas)); } - + if(ac == null) return; ac.runOnUiThread(new Runnable() { @Override public void run() { @@ -211,7 +206,7 @@ public void run() { onItemsLoadComplete(); if (isAdded()) { setupChart(priceChart, getData(yVals), getResources().getColor(R.color.colorPrimaryLittleDarker)); - update(); + update(false); } } }); @@ -309,19 +304,27 @@ public float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProv public void updateExchangeRates() { try { ExchangeCalculator.getInstance().updateExchangeRates(ac != null ? ac.getPreferences().getString("maincurrency", "USD") : "USD", ac); - update(); + update(true); onItemsLoadComplete(); } catch (IOException e) { e.printStackTrace(); } } - public void update() { + public void update(boolean updateChart) { if (price != null) price.setText(displayInUsd ? ExchangeCalculator.getInstance().displayUsdNicely(ExchangeCalculator.getInstance().getUSDPrice()) + " " + ExchangeCalculator.getInstance().getMainCurreny().getName() : ExchangeCalculator.getInstance().displayEthNicely(ExchangeCalculator.getInstance().getBTCPrice()) + " BTC" ); + + if(updateChart) { + try { + loadPriceData(TIMESTAMPS[displayType], PERIOD[displayType]); + } catch (IOException e) { + e.printStackTrace(); + } + } onItemsLoadComplete(); } diff --git a/app/src/main/java/rehanced/com/simpleetherwallet/network/EtherscanAPI.java b/app/src/main/java/rehanced/com/simpleetherwallet/network/EtherscanAPI.java index 264b686..9c020f2 100644 --- a/app/src/main/java/rehanced/com/simpleetherwallet/network/EtherscanAPI.java +++ b/app/src/main/java/rehanced/com/simpleetherwallet/network/EtherscanAPI.java @@ -161,7 +161,7 @@ public void getNonceForAddress(String address, Callback b) throws IOException { public void getPriceConversionRates(String currencyConversion, Callback b) throws IOException { - get("http://download.finance.yahoo.com/d/quotes.csv?s=" + currencyConversion + "=X&f=snl1", b); + get("https://api.fixer.io/latest?base=USD&symbols=" + currencyConversion, b); } diff --git a/app/src/main/java/rehanced/com/simpleetherwallet/utils/ExchangeCalculator.java b/app/src/main/java/rehanced/com/simpleetherwallet/utils/ExchangeCalculator.java index da8d5f3..f507eee 100644 --- a/app/src/main/java/rehanced/com/simpleetherwallet/utils/ExchangeCalculator.java +++ b/app/src/main/java/rehanced/com/simpleetherwallet/utils/ExchangeCalculator.java @@ -218,7 +218,7 @@ public void onResponse(Call call, final Response response) throws IOException { } private void convert(final String currency, final NetworkUpdateListener update) throws IOException { - EtherscanAPI.getInstance().getPriceConversionRates("USD" + currency, new Callback() { + EtherscanAPI.getInstance().getPriceConversionRates(currency, new Callback() { @Override public void onFailure(Call call, IOException e) { } diff --git a/app/src/main/java/rehanced/com/simpleetherwallet/utils/ResponseParser.java b/app/src/main/java/rehanced/com/simpleetherwallet/utils/ResponseParser.java index a5e4247..575265d 100644 --- a/app/src/main/java/rehanced/com/simpleetherwallet/utils/ResponseParser.java +++ b/app/src/main/java/rehanced/com/simpleetherwallet/utils/ResponseParser.java @@ -155,7 +155,9 @@ public static BigInteger parseGasPrice(String response) throws Exception { public static double parsePriceConversionRate(String response) { try { - return Double.parseDouble(response.split(",")[2]); + JSONObject jo = new JSONObject(response).getJSONObject("rates"); + String key = jo.keys().next(); + return jo.getDouble(key); } catch (Exception e) { return 1; }