Add dynamic color generation to marketp cap activity
This commit is contained in:
parent
9218d54261
commit
c09fa8ca6f
@ -10,6 +10,7 @@ import android.os.Bundle;
|
|||||||
import android.support.v4.view.GravityCompat;
|
import android.support.v4.view.GravityCompat;
|
||||||
import android.support.v4.widget.DrawerLayout;
|
import android.support.v4.widget.DrawerLayout;
|
||||||
import android.support.v4.widget.SwipeRefreshLayout;
|
import android.support.v4.widget.SwipeRefreshLayout;
|
||||||
|
import android.support.v7.graphics.Palette;
|
||||||
import android.text.SpannableString;
|
import android.text.SpannableString;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@ -69,8 +70,6 @@ public class MarketCapitalization extends Fragment {
|
|||||||
{
|
{
|
||||||
view = inflater.inflate(R.layout.fragment_marketcap_homeactivity, container, false);
|
view = inflater.inflate(R.layout.fragment_marketcap_homeactivity, container, false);
|
||||||
|
|
||||||
setupDominantCurrenciesColors();
|
|
||||||
|
|
||||||
preferencesManager = new PreferencesManager(getContext());
|
preferencesManager = new PreferencesManager(getContext());
|
||||||
marketCapManager = new MarketCapManager(getContext());
|
marketCapManager = new MarketCapManager(getContext());
|
||||||
|
|
||||||
@ -147,27 +146,6 @@ public class MarketCapitalization extends Fragment {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupDominantCurrenciesColors()
|
|
||||||
{
|
|
||||||
dominantCurrenciesColors = new HashMap<>();
|
|
||||||
|
|
||||||
dominantCurrenciesColors.put("BTC", -489456);
|
|
||||||
dominantCurrenciesColors.put("ETH", -13619152);
|
|
||||||
dominantCurrenciesColors.put("XRP", -16744256);
|
|
||||||
dominantCurrenciesColors.put("BCH", -1011696);
|
|
||||||
dominantCurrenciesColors.put("LTC", -4671304);
|
|
||||||
dominantCurrenciesColors.put("EOS", -1513240);
|
|
||||||
dominantCurrenciesColors.put("ADA", -16773080);
|
|
||||||
dominantCurrenciesColors.put("XLM", -11509656);
|
|
||||||
dominantCurrenciesColors.put("MIOTA", -1513240);
|
|
||||||
dominantCurrenciesColors.put("NEO", -9390048);
|
|
||||||
dominantCurrenciesColors.put("XMR", -499712);
|
|
||||||
dominantCurrenciesColors.put("DASH", -15175496);
|
|
||||||
dominantCurrenciesColors.put("XEM", -7829368);
|
|
||||||
dominantCurrenciesColors.put("TRX", -7829360);
|
|
||||||
dominantCurrenciesColors.put("ETC", -10448784);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateMarketCap(boolean mustUpdate)
|
private void updateMarketCap(boolean mustUpdate)
|
||||||
{
|
{
|
||||||
if(System.currentTimeMillis() / 1000 - lastTimestamp > 60 || mustUpdate)
|
if(System.currentTimeMillis() / 1000 - lastTimestamp > 60 || mustUpdate)
|
||||||
@ -246,7 +224,7 @@ public class MarketCapitalization extends Fragment {
|
|||||||
|
|
||||||
entries.add(pieEntry);
|
entries.add(pieEntry);
|
||||||
topCurrenciesDominance += topCurrencies.get(i).getDominance(marketCapManager.getMarketCap());
|
topCurrenciesDominance += topCurrencies.get(i).getDominance(marketCapManager.getMarketCap());
|
||||||
colors.add(dominantCurrenciesColors.get(topCurrencies.get(i).getSymbol()));
|
colors.add(topCurrencies.get(i).getChartColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
entries.add(new PieEntry(100-topCurrenciesDominance, "Others", "others"));
|
entries.add(new PieEntry(100-topCurrenciesDominance, "Others", "others"));
|
||||||
@ -266,7 +244,6 @@ public class MarketCapitalization extends Fragment {
|
|||||||
if(isTopCurrenciesUpdated && isMarketpCapUpdated && isDetailsUpdated)
|
if(isTopCurrenciesUpdated && isMarketpCapUpdated && isDetailsUpdated)
|
||||||
{
|
{
|
||||||
updateIcons();
|
updateIcons();
|
||||||
//refreshDisplayedData();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -294,7 +271,11 @@ public class MarketCapitalization extends Fragment {
|
|||||||
MoodlBox.getBitmapFromURL(iconUrl, localCurrency.getSymbol(), getResources(), getContext(), new HomeActivity.IconCallBack() {
|
MoodlBox.getBitmapFromURL(iconUrl, localCurrency.getSymbol(), getResources(), getContext(), new HomeActivity.IconCallBack() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(Bitmap bitmapIcon) {
|
public void onSuccess(Bitmap bitmapIcon) {
|
||||||
|
Palette.Builder builder = Palette.from(bitmapIcon);
|
||||||
|
|
||||||
marketCapManager.getTopCurrencies().get(index).setIcon(bitmapIcon);
|
marketCapManager.getTopCurrencies().get(index).setIcon(bitmapIcon);
|
||||||
|
marketCapManager.getTopCurrencies().get(index).setChartColor(builder.generate().getDominantColor(0));
|
||||||
|
|
||||||
countIcons();
|
countIcons();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -76,7 +76,7 @@ public class CurrencyCardview extends CardView {
|
|||||||
public void onSuccess(Currency currency) {
|
public void onSuccess(Currency currency) {
|
||||||
if(currency.getHistoryMinutes() != null)
|
if(currency.getHistoryMinutes() != null)
|
||||||
{
|
{
|
||||||
setupLineChart(view, currency);
|
setupLineChart(currency);
|
||||||
view.findViewById(R.id.progressBarLinechartWatchlist).setVisibility(View.GONE);
|
view.findViewById(R.id.progressBarLinechartWatchlist).setVisibility(View.GONE);
|
||||||
view.findViewById(R.id.linearLayoutSubLayout).setVisibility(View.VISIBLE);
|
view.findViewById(R.id.linearLayoutSubLayout).setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
@ -157,7 +157,7 @@ public class CurrencyCardview extends CardView {
|
|||||||
public void onSuccess(Currency currency) {
|
public void onSuccess(Currency currency) {
|
||||||
if(currency.getHistoryMinutes() != null)
|
if(currency.getHistoryMinutes() != null)
|
||||||
{
|
{
|
||||||
setupLineChart(view, currency);
|
setupLineChart(currency);
|
||||||
view.findViewById(R.id.progressBarLinechartSummary).setVisibility(View.GONE);
|
view.findViewById(R.id.progressBarLinechartSummary).setVisibility(View.GONE);
|
||||||
view.findViewById(R.id.linearLayoutSubLayout).setVisibility(View.VISIBLE);
|
view.findViewById(R.id.linearLayoutSubLayout).setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
@ -208,7 +208,7 @@ public class CurrencyCardview extends CardView {
|
|||||||
setCardBackgroundColor(context.getColor(R.color.white));
|
setCardBackgroundColor(context.getColor(R.color.white));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupLineChart(View view, final Currency currency)
|
private void setupLineChart(final Currency currency)
|
||||||
{
|
{
|
||||||
LineChart lineChart = findViewById(R.id.LineChartView);
|
LineChart lineChart = findViewById(R.id.LineChartView);
|
||||||
|
|
||||||
|
@ -27,7 +27,6 @@ import java.util.Date;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import static java.lang.Math.abs;
|
import static java.lang.Math.abs;
|
||||||
import static java.lang.Math.subtractExact;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Guitoune on 30/04/2018.
|
* Created by Guitoune on 30/04/2018.
|
||||||
|
Loading…
Reference in New Issue
Block a user