From c09fa8ca6fb1030a807555c26b9a2123f96047a8 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Sat, 26 May 2018 18:51:42 +0200 Subject: [PATCH] Add dynamic color generation to marketp cap activity --- .../MarketCapitalization.java | 31 ++++--------------- .../CurrencyData/CurrencyCardview.java | 6 ++-- .../main/java/com/nauk/moodl/MoodlBox.java | 1 - 3 files changed, 9 insertions(+), 29 deletions(-) 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 1d5d22c..82e838a 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 @@ -10,6 +10,7 @@ import android.os.Bundle; import android.support.v4.view.GravityCompat; import android.support.v4.widget.DrawerLayout; import android.support.v4.widget.SwipeRefreshLayout; +import android.support.v7.graphics.Palette; import android.text.SpannableString; import android.util.Log; import android.view.LayoutInflater; @@ -69,8 +70,6 @@ public class MarketCapitalization extends Fragment { { view = inflater.inflate(R.layout.fragment_marketcap_homeactivity, container, false); - setupDominantCurrenciesColors(); - preferencesManager = new PreferencesManager(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) { if(System.currentTimeMillis() / 1000 - lastTimestamp > 60 || mustUpdate) @@ -246,7 +224,7 @@ public class MarketCapitalization extends Fragment { entries.add(pieEntry); 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")); @@ -266,7 +244,6 @@ public class MarketCapitalization extends Fragment { if(isTopCurrenciesUpdated && isMarketpCapUpdated && isDetailsUpdated) { updateIcons(); - //refreshDisplayedData(); } } @@ -294,7 +271,11 @@ public class MarketCapitalization extends Fragment { MoodlBox.getBitmapFromURL(iconUrl, localCurrency.getSymbol(), getResources(), getContext(), new HomeActivity.IconCallBack() { @Override public void onSuccess(Bitmap bitmapIcon) { + Palette.Builder builder = Palette.from(bitmapIcon); + marketCapManager.getTopCurrencies().get(index).setIcon(bitmapIcon); + marketCapManager.getTopCurrencies().get(index).setChartColor(builder.generate().getDominantColor(0)); + countIcons(); } }); diff --git a/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/CurrencyCardview.java b/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/CurrencyCardview.java index f92a5f8..6e48e3f 100644 --- a/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/CurrencyCardview.java +++ b/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/CurrencyCardview.java @@ -76,7 +76,7 @@ public class CurrencyCardview extends CardView { public void onSuccess(Currency currency) { if(currency.getHistoryMinutes() != null) { - setupLineChart(view, currency); + setupLineChart(currency); view.findViewById(R.id.progressBarLinechartWatchlist).setVisibility(View.GONE); view.findViewById(R.id.linearLayoutSubLayout).setVisibility(View.VISIBLE); } @@ -157,7 +157,7 @@ public class CurrencyCardview extends CardView { public void onSuccess(Currency currency) { if(currency.getHistoryMinutes() != null) { - setupLineChart(view, currency); + setupLineChart(currency); view.findViewById(R.id.progressBarLinechartSummary).setVisibility(View.GONE); view.findViewById(R.id.linearLayoutSubLayout).setVisibility(View.VISIBLE); } @@ -208,7 +208,7 @@ public class CurrencyCardview extends CardView { 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); diff --git a/app/src/main/java/com/nauk/moodl/MoodlBox.java b/app/src/main/java/com/nauk/moodl/MoodlBox.java index 1ff034c..ab86531 100644 --- a/app/src/main/java/com/nauk/moodl/MoodlBox.java +++ b/app/src/main/java/com/nauk/moodl/MoodlBox.java @@ -27,7 +27,6 @@ import java.util.Date; import java.util.Locale; import static java.lang.Math.abs; -import static java.lang.Math.subtractExact; /** * Created by Guitoune on 30/04/2018.