From 44333e55f7e98c5bbb604355097c2b77ebb91c6d Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Thu, 17 May 2018 00:47:30 +0200 Subject: [PATCH] Some market capitalization details --- .../MarketCapitalization.java | 18 +++++++++++++++++- .../DataManagers/CurrencyData/Currency.java | 10 ++++++++++ .../moodl/DataManagers/MarketCapManager.java | 17 +++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) 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 8702ecb..2b5ab5e 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 @@ -16,10 +16,13 @@ import android.widget.ImageButton; import android.widget.TextView; import com.github.mikephil.charting.charts.PieChart; +import com.github.mikephil.charting.data.Entry; import com.github.mikephil.charting.data.PieData; import com.github.mikephil.charting.data.PieDataSet; import com.github.mikephil.charting.data.PieEntry; import com.github.mikephil.charting.formatter.PercentFormatter; +import com.github.mikephil.charting.highlight.Highlight; +import com.github.mikephil.charting.listener.OnChartValueSelectedListener; import com.nauk.moodl.Activities.SettingsActivity; import com.nauk.moodl.DataManagers.CurrencyData.Currency; import com.nauk.moodl.DataManagers.MarketCapManager; @@ -207,7 +210,7 @@ public class MarketCapitalization extends Fragment { for(int i = 0; i < topCurrencies.size(); i++) { - PieEntry pieEntry = 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(), topCurrencies.get(i).getSymbol()); if(pieEntry.getValue() < 3) { @@ -271,6 +274,19 @@ public class MarketCapitalization extends Fragment { } }); + pieChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() { + @Override + public void onValueSelected(Entry e, Highlight h) { + Currency currency = marketCapManager.getCurrencyFromSymbol((String) e.getData()); + Log.d("moodl", "> " + currency.getSymbol() + " " + currency.getMarketCapitalization() + " " + currency.getVolume24h()); + } + + @Override + public void onNothingSelected() { + + } + }); + pieChart.getDescription().setEnabled(false); pieChart.getLegend().setEnabled(false); pieChart.setCenterText(generateCenterSpannableText()); diff --git a/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/Currency.java b/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/Currency.java index bb3e4c6..afdd48a 100644 --- a/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/Currency.java +++ b/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/Currency.java @@ -40,6 +40,8 @@ public class Currency implements Parcelable { private String proofType; private int totalSupply; private double marketCapitalization; + + private double volume24h; private double dominance; private int rank; private String startDate; @@ -268,6 +270,14 @@ public class Currency implements Parcelable { this.chartColor = chartColor; } + public double getVolume24h() { + return volume24h; + } + + public void setVolume24h(double volume24h) { + this.volume24h = volume24h; + } + public int getChartColor() { return chartColor; diff --git a/app/src/main/java/com/nauk/moodl/DataManagers/MarketCapManager.java b/app/src/main/java/com/nauk/moodl/DataManagers/MarketCapManager.java index 84de97a..649a916 100644 --- a/app/src/main/java/com/nauk/moodl/DataManagers/MarketCapManager.java +++ b/app/src/main/java/com/nauk/moodl/DataManagers/MarketCapManager.java @@ -135,6 +135,7 @@ public class MarketCapManager { JSONObject quoteJsonObject = subCurrencyJsonObject.getJSONObject("quotes"); JSONObject symJsonObject = quoteJsonObject.getJSONObject(toSymbol); newCurrency.setMarketCapitalization(symJsonObject.getDouble("market_cap")); + newCurrency.setVolume24h(symJsonObject.getDouble("volume_24h")); topCurrencies.add(newCurrency); } @@ -144,6 +145,22 @@ public class MarketCapManager { } } + public Currency getCurrencyFromSymbol(String symbol) + { + Currency returnedCurrency = null; + int index = 0; + + do { + if(symbol.equals(topCurrencies.get(index).getSymbol())) + { + returnedCurrency = topCurrencies.get(index); + } + } while(index < topCurrencies.size() && returnedCurrency == null); + + + return returnedCurrency; + } + public long getMarketCap() { return marketCap;