diff --git a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/MarketCapitalization.java b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/MarketCapitalization.java index b3a56a4..c0584e2 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/MarketCapitalization.java +++ b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/MarketCapitalization.java @@ -44,6 +44,7 @@ import java.util.ArrayList; import java.util.List; import static com.herbron.moodl.MoodlBox.getColor; +import static com.herbron.moodl.MoodlBox.getIconDominantColor; import static java.lang.Math.abs; /** @@ -265,10 +266,8 @@ public class MarketCapitalization extends Fragment implements CryptocompareNotif MoodlBox.getBitmapFromURL(iconUrl, localCurrency.getSymbol(), getResources(), getActivity().getBaseContext(), new MoodlboxNotifierInterface() { @Override public void onBitmapDownloaded(Bitmap bitmapIcon) { - Palette.Builder builder = Palette.from(bitmapIcon); - coinmarketCapAPIManager.getTopCurrencies().get(index).setIcon(bitmapIcon); - coinmarketCapAPIManager.getTopCurrencies().get(index).setChartColor(builder.generate().getDominantColor(getColor(R.color.default_color, getActivity().getBaseContext()))); + coinmarketCapAPIManager.getTopCurrencies().get(index).setChartColor(getIconDominantColor(getContext(), bitmapIcon)); countIcons(); diff --git a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Overview.java b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Overview.java index c142429..9905a3e 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Overview.java +++ b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Overview.java @@ -30,6 +30,7 @@ import com.herbron.moodl.R; import java.util.List; import static com.herbron.moodl.MoodlBox.getDrawable; +import static com.herbron.moodl.MoodlBox.getIconDominantColor; /** * Created by Administrator on 27/05/2018. @@ -121,20 +122,6 @@ public class Overview extends Fragment implements CoinmarketcapNotifierInterface currencyLoader.execute(); } - private void updateChartColor(Currency currency) - { - if(currency.getIcon() != null) - { - Palette.Builder builder = Palette.from(currency.getIcon()); - - currency.setChartColor(builder.generate().getDominantColor(0)); - } - else - { - currency.setChartColor(12369084); - } - } - private void loadingIndicatorGenerator() { loadingFooter = LayoutInflater.from(getActivity().getBaseContext()).inflate(R.layout.listview_loading_indicator, null, false); @@ -198,7 +185,7 @@ public class Overview extends Fragment implements CoinmarketcapNotifierInterface @Override public void onBitmapDownloaded(Bitmap bitmap) { currency.setIcon(bitmap); - updateChartColor(currency); + currency.setChartColor(getIconDominantColor(getContext(), bitmap)); countIcons(currencies[0]); } }); @@ -216,7 +203,7 @@ public class Overview extends Fragment implements CoinmarketcapNotifierInterface icon = Bitmap.createScaledBitmap(icon, 50, 50, false); currency.setIcon(icon); - updateChartColor(currency); + currency.setChartColor(getIconDominantColor(getContext(), icon)); countIcons(currencies[0]); } } diff --git a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java index 9d5ab3f..fce352b 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java +++ b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java @@ -708,26 +708,6 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, super.onProgressUpdate(values); } - private void updateChartColor(Currency currency) - { - if(currency.getIcon() != null) - { - Palette.Builder builder = Palette.from(currency.getIcon()); - - currency.setChartColor(builder.generate().getDominantColor(getColor(R.color.default_color, getActivity().getBaseContext()))); - } - else - { - currency.setChartColor(getColor(R.color.default_color, getActivity().getBaseContext())); - } - } - - private void loadCurrency(Currency currency) - { - currency.setName(balanceManager.getCurrencyName(currency.getSymbol())); - currency.setId(balanceManager.getCurrencyId(currency.getSymbol())); - } - @Override protected Void doInBackground(Void... params) { @@ -744,7 +724,7 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, localCurrency.setTickerId(coinmarketCapAPIManager.getTickerIdForSymbol(localCurrency.getSymbol())); - updateChartColor(localCurrency); + localCurrency.setChartColor(getIconDominantColor(baseContext, localCurrency.getIcon())); loadCurrency(localCurrency); diff --git a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Watchlist.java b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Watchlist.java index 7368714..803043d 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Watchlist.java +++ b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Watchlist.java @@ -43,6 +43,7 @@ import java.util.List; import static com.herbron.moodl.MoodlBox.collapseW; import static com.herbron.moodl.MoodlBox.expandW; import static com.herbron.moodl.MoodlBox.getColor; +import static com.herbron.moodl.MoodlBox.getIconDominantColor; /** * Created by Tiji on 13/04/2018. @@ -380,20 +381,6 @@ public class Watchlist extends Fragment implements CryptocompareNotifierInterfac } } - private void updateChartColor(Currency currency) - { - if(currency.getIcon() != null) - { - Palette.Builder builder = Palette.from(currency.getIcon()); - - currency.setChartColor(builder.generate().getDominantColor(getColor(R.color.default_color, getActivity().getBaseContext()))); - } - else - { - currency.setChartColor(getColor(R.color.default_color, getActivity().getBaseContext())); - } - } - public int getCurrencyId(String symbol) { int id = 0; @@ -454,7 +441,7 @@ public class Watchlist extends Fragment implements CryptocompareNotifierInterfac @Override public void onBitmapDownloaded(Bitmap bitmapIcon) { currency.setIcon(bitmapIcon); - updateChartColor(currency); + currency.setChartColor(getIconDominantColor(getContext(), bitmapIcon)); countWatchlist(); } @@ -466,7 +453,7 @@ public class Watchlist extends Fragment implements CryptocompareNotifierInterfac icon = Bitmap.createScaledBitmap(icon, 50, 50, false); currency.setIcon(icon); - updateChartColor(currency); + currency.setChartColor(getIconDominantColor(getContext(), icon)); countWatchlist(); } } diff --git a/app/src/main/java/com/herbron/moodl/MoodlBox.java b/app/src/main/java/com/herbron/moodl/MoodlBox.java index ea6f231..87cbe61 100644 --- a/app/src/main/java/com/herbron/moodl/MoodlBox.java +++ b/app/src/main/java/com/herbron/moodl/MoodlBox.java @@ -6,6 +6,7 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.drawable.Drawable; import android.os.Build; +import android.support.v7.graphics.Palette; import android.support.v7.widget.CardView; import android.util.Log; import android.view.View; @@ -297,4 +298,18 @@ public class MoodlBox { return url; } + + public static int getIconDominantColor(Context context, Bitmap icon) + { + if(icon != null) + { + Palette.Builder builder = Palette.from(icon); + + return builder.generate().getDominantColor(getColor(R.color.default_color, context)); + } + else + { + return getColor(R.color.default_color, context); + } + } }