From 460eb1aa14448c29dec8f0cd0bafddff0beef5c6 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Wed, 9 May 2018 02:49:19 +0200 Subject: [PATCH] Fix CoinMarketCap v2 API implementation --- .../Activities/CurrencyDetailsActivity.java | 1 + .../MarketCapitalization.java | 18 +++++++++++------- .../CurrencyData/CurrencyDataRetriever.java | 10 ++++++---- .../CurrencyData/CurrencyTickerList.java | 17 ++++++++++++++--- 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/nauk/moodl/Activities/CurrencyDetailsActivity.java b/app/src/main/java/com/nauk/moodl/Activities/CurrencyDetailsActivity.java index 079618b..1e26997 100644 --- a/app/src/main/java/com/nauk/moodl/Activities/CurrencyDetailsActivity.java +++ b/app/src/main/java/com/nauk/moodl/Activities/CurrencyDetailsActivity.java @@ -20,6 +20,7 @@ import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.CardView; import android.text.Html; import android.text.method.LinkMovementMethod; +import android.util.Log; import android.view.LayoutInflater; import android.view.MenuItem; import android.view.MotionEvent; diff --git a/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/MarketCapitalization.java b/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/MarketCapitalization.java index 70ea048..bfa138f 100644 --- a/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/MarketCapitalization.java +++ b/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/MarketCapitalization.java @@ -206,8 +206,14 @@ public class MarketCapitalization extends Fragment { for(int i = 0; i < topCurrencies.size(); i++) { - Log.d("moodl", "Dominance : " + topCurrencies.get(i).getSymbol() + " " + topCurrencies.get(i).getDominance(marketCapManager.getMarketCap())); - entries.add(new PieEntry(topCurrencies.get(i).getDominance(marketCapManager.getMarketCap()), topCurrencies.get(i).getSymbol())); + PieEntry pieEntry = new PieEntry(topCurrencies.get(i).getDominance(marketCapManager.getMarketCap()), topCurrencies.get(i).getSymbol()); + + if(pieEntry.getValue() < 3) + { + pieEntry.setLabel(""); + } + + entries.add(pieEntry); topCurrenciesDominance += topCurrencies.get(i).getDominance(marketCapManager.getMarketCap()); colors.add(dominantCurrenciesColors.get(topCurrencies.get(i).getSymbol())); } @@ -218,8 +224,7 @@ public class MarketCapitalization extends Fragment { PieDataSet set = new PieDataSet(entries, "Market Cap Dominance"); set.setColors(colors); set.setSliceSpace(1); - set.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE); - set.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE); + set.setDrawValues(false); return set; } @@ -241,10 +246,9 @@ public class MarketCapitalization extends Fragment { pieChart.setData(data); pieChart.setDrawSlicesUnderHole(false); - pieChart.setUsePercentValues(true); + pieChart.setUsePercentValues(false); pieChart.setTouchEnabled(true); - - pieChart.setEntryLabelColor(Color.parseColor("#FF000000")); + pieChart.setEntryLabelColor(Color.WHITE); pieChart.setOnTouchListener(new View.OnTouchListener() { @Override diff --git a/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/CurrencyDataRetriever.java b/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/CurrencyDataRetriever.java index ce67a8c..09085ab 100644 --- a/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/CurrencyDataRetriever.java +++ b/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/CurrencyDataRetriever.java @@ -70,13 +70,15 @@ public class CurrencyDataRetriever { { Currency currency = new Currency(); - response = response.substring(1, response.length()-1); - try { JSONObject jsonObject = new JSONObject(response); + JSONObject currencyJsonObject = jsonObject.getJSONObject("data"); + JSONObject quotesJsonObject = currencyJsonObject.getJSONObject("quotes"); + JSONObject valuesJsonObject = quotesJsonObject.getJSONObject(toSymbol); + + currency.setMarketCapitalization(valuesJsonObject.getDouble("market_cap")); + currency.setRank(currencyJsonObject.getInt("rank")); - currency.setMarketCapitalization(jsonObject.getDouble("market_cap_" + toSymbol.toLowerCase())); - currency.setRank(jsonObject.getInt("rank")); } catch (JSONException e) { e.printStackTrace(); } diff --git a/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/CurrencyTickerList.java b/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/CurrencyTickerList.java index f8cf5a4..6f22777 100644 --- a/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/CurrencyTickerList.java +++ b/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/CurrencyTickerList.java @@ -63,12 +63,12 @@ public class CurrencyTickerList { int tickerId = 0; int i = 0; - while(!currencyTickerList.get(i).equals(symbol) && currencyTickerList.size() < i) + while(!currencyTickerList.get(i).getSymbol().equals(symbol) && currencyTickerList.size() > i+1) { i++; } - if(currencyTickerList.get(i).equals(symbol)) + if(currencyTickerList.get(i).getSymbol().equals(symbol)) { tickerId = currencyTickerList.get(i).getTickerId(); } @@ -85,7 +85,18 @@ public class CurrencyTickerList { for(int i = 0; i < dataJsonArray.length(); i++) { JSONObject currencyJsonObject = dataJsonArray.getJSONObject(i); - currencyTickerList.add(new Currency(currencyJsonObject.getString("name"), currencyJsonObject.getString("symbol"), currencyJsonObject.getInt("id"))); + switch (currencyJsonObject.getString("symbol")) + { + case "MIOTA": + currencyTickerList.add(new Currency(currencyJsonObject.getString("name"), "IOT", currencyJsonObject.getInt("id"))); + break; + case "NANO": + currencyTickerList.add(new Currency(currencyJsonObject.getString("name"), "XRB", currencyJsonObject.getInt("id"))); + break; + default: + currencyTickerList.add(new Currency(currencyJsonObject.getString("name"), currencyJsonObject.getString("symbol"), currencyJsonObject.getInt("id"))); + break; + } } } catch (JSONException e) { e.printStackTrace();