Fix CoinMarketCap v2 API implementation

This commit is contained in:
Tanguy Herbron 2018-05-09 02:49:19 +02:00
parent 0927d6629c
commit 460eb1aa14
4 changed files with 32 additions and 14 deletions

View File

@ -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;

View File

@ -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

View File

@ -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();
}

View File

@ -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();