Rework icon loading
- Icons are now downloaded after displaying the whole list
This commit is contained in:
parent
e6d69a01ce
commit
8ca63b5e85
@ -3,6 +3,7 @@ package com.herbron.moodl.Activities.HomeActivityFragments;
|
|||||||
import android.animation.ObjectAnimator;
|
import android.animation.ObjectAnimator;
|
||||||
import android.animation.ValueAnimator;
|
import android.animation.ValueAnimator;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
@ -61,6 +62,7 @@ import java.util.Random;
|
|||||||
|
|
||||||
import static com.herbron.moodl.MoodlBox.getColor;
|
import static com.herbron.moodl.MoodlBox.getColor;
|
||||||
import static com.herbron.moodl.MoodlBox.getDrawable;
|
import static com.herbron.moodl.MoodlBox.getDrawable;
|
||||||
|
import static com.herbron.moodl.MoodlBox.getIconDominantColor;
|
||||||
import static com.herbron.moodl.MoodlBox.numberConformer;
|
import static com.herbron.moodl.MoodlBox.numberConformer;
|
||||||
import static java.lang.Math.abs;
|
import static java.lang.Math.abs;
|
||||||
|
|
||||||
@ -206,41 +208,6 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
|
|||||||
layoutRefresherRunnable = new Runnable() {
|
layoutRefresherRunnable = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
final List<Currency> renderedCurrencies = new ArrayList<>();
|
|
||||||
|
|
||||||
if (balanceManager.getTotalBalance() != null)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < balanceManager.getTotalBalance().size(); i++) {
|
|
||||||
final Currency currency = balanceManager.getTotalBalance().get(i);
|
|
||||||
|
|
||||||
if ((Math.abs(currency.getBalance() * currency.getValue()) >= preferencesManager.getMinimumAmount())) {
|
|
||||||
//currencyView.add(layoutGenerator.getInfoLayout(currency, totalValue, preferencesManager.isBalanceHidden()));
|
|
||||||
renderedCurrencies.add(currency);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getActivity().runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
currencyLayout.removeAllViews();
|
|
||||||
|
|
||||||
for(int i = 0; i < renderedCurrencies.size(); i++)
|
|
||||||
{
|
|
||||||
//currencyLayout.addView(currencyView.get(i));
|
|
||||||
currencyLayout.addView(new CurrencyCardview(getActivity(), renderedCurrencies.get(i), getActivity(), preferencesManager.isBalanceHidden()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(loadingDialog.isShowing())
|
|
||||||
{
|
|
||||||
loadingDialog.dismiss();
|
|
||||||
}
|
|
||||||
|
|
||||||
updateTitle();
|
|
||||||
|
|
||||||
handler.removeCallbacks(updateRunnable);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -375,9 +342,44 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
|
|||||||
iconCounter = 0;
|
iconCounter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void adaptView()
|
private void adaptView(float totalValue, float totalFluctuation)
|
||||||
{
|
{
|
||||||
layoutRefresherRunnable.run();
|
this.totalValue = totalValue;
|
||||||
|
this.totalFluctuation = totalFluctuation;
|
||||||
|
final List<Currency> renderedCurrencies = new ArrayList<>();
|
||||||
|
|
||||||
|
if (balanceManager.getTotalBalance() != null)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < balanceManager.getTotalBalance().size(); i++) {
|
||||||
|
final Currency currency = balanceManager.getTotalBalance().get(i);
|
||||||
|
|
||||||
|
if ((Math.abs(currency.getBalance() * currency.getValue()) >= preferencesManager.getMinimumAmount())) {
|
||||||
|
//currencyView.add(layoutGenerator.getInfoLayout(currency, totalValue, preferencesManager.isBalanceHidden()));
|
||||||
|
renderedCurrencies.add(currency);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getActivity().runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
currencyLayout.removeAllViews();
|
||||||
|
|
||||||
|
for(int i = 0; i < renderedCurrencies.size(); i++)
|
||||||
|
{
|
||||||
|
currencyLayout.addView(new CurrencyCardview(getActivity(), renderedCurrencies.get(i), getActivity(), preferencesManager.isBalanceHidden()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(loadingDialog.isShowing())
|
||||||
|
{
|
||||||
|
loadingDialog.dismiss();
|
||||||
|
}
|
||||||
|
|
||||||
|
updateTitle();
|
||||||
|
|
||||||
|
handler.removeCallbacks(updateRunnable);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void countCoins(boolean isCoin, boolean isDetails, boolean isTickers)
|
private void countCoins(boolean isCoin, boolean isDetails, boolean isTickers)
|
||||||
@ -401,46 +403,22 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
|
|||||||
{
|
{
|
||||||
if(balanceManager.getTotalBalance().size() == 0)
|
if(balanceManager.getTotalBalance().size() == 0)
|
||||||
{
|
{
|
||||||
countIcons();
|
updateNoBalance();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(coinCounter >= balanceManager.getTotalBalance().size() && detailsChecker && tickersChecker)
|
if(coinCounter >= balanceManager.getTotalBalance().size() && detailsChecker && tickersChecker)
|
||||||
{
|
|
||||||
IconDownloader iconDownloader = new IconDownloader();
|
|
||||||
iconDownloader.execute();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void countIcons()
|
|
||||||
{
|
|
||||||
int offset = 0;
|
|
||||||
|
|
||||||
for(int i = 0; i < balanceManager.getTotalBalance().size(); i++)
|
|
||||||
{
|
|
||||||
if(balanceManager.getTotalBalance().get(i).getSymbol().equals("USD"))
|
|
||||||
{
|
|
||||||
offset++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
iconCounter++;
|
|
||||||
|
|
||||||
if(balanceManager.getTotalBalance() != null)
|
|
||||||
{
|
|
||||||
if(balanceManager.getTotalBalance().size() == 0)
|
|
||||||
{
|
|
||||||
updateNoBalance();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(iconCounter == balanceManager.getTotalBalance().size() - offset)
|
|
||||||
{
|
{
|
||||||
UiHeavyLoadCalculator uiHeavyLoadCalculator = new UiHeavyLoadCalculator();
|
UiHeavyLoadCalculator uiHeavyLoadCalculator = new UiHeavyLoadCalculator();
|
||||||
uiHeavyLoadCalculator.execute();
|
uiHeavyLoadCalculator.setOnUiEndListener(new UiHeavyLoadCalculator.OnUiEndListener() {
|
||||||
|
@Override
|
||||||
|
public void onEnd(float totalValue, float totalFluctuation) {
|
||||||
|
refreshLayout.setRefreshing(false);
|
||||||
|
|
||||||
|
adaptView(totalValue, totalFluctuation);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
uiHeavyLoadCalculator.execute(getActivity().getBaseContext(), balanceManager, coinmarketCapAPIManager);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -467,23 +445,11 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
|
|||||||
|
|
||||||
private void computeTotalValue()
|
private void computeTotalValue()
|
||||||
{
|
{
|
||||||
totalValue = 0;
|
|
||||||
totalFluctuation = 0;
|
|
||||||
|
|
||||||
for(int i = 0; i < currencyLayout.getChildCount(); i++)
|
for(int i = 0; i < currencyLayout.getChildCount(); i++)
|
||||||
{
|
{
|
||||||
if(currencyLayout.getChildAt(i) instanceof CurrencyCardview)
|
if(currencyLayout.getChildAt(i) instanceof CurrencyCardview)
|
||||||
{
|
{
|
||||||
totalValue += ((CurrencyCardview) currencyLayout.getChildAt(i)).getOwnedValue();
|
((CurrencyCardview) currencyLayout.getChildAt(i)).updateOwnedValues(totalValue, preferencesManager.isBalanceHidden());
|
||||||
totalFluctuation += ((CurrencyCardview) currencyLayout.getChildAt(i)).getFluctuation();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int i = 0; i < currencyLayout.getChildCount(); i++)
|
|
||||||
{
|
|
||||||
if(currencyLayout.getChildAt(i) instanceof CurrencyCardview)
|
|
||||||
{
|
|
||||||
((CurrencyCardview) currencyLayout.getChildAt(i)).updateCardViewInfos(totalValue, preferencesManager.isBalanceHidden());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -690,9 +656,22 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
|
|||||||
countCoins(false, false, true);
|
countCoins(false, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class UiHeavyLoadCalculator extends AsyncTask<Void, Integer, Void>
|
private static class UiHeavyLoadCalculator extends AsyncTask<Object, Integer, Void>
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private float totalValue = 0;
|
||||||
|
private float totalFluctuation = 0;
|
||||||
|
|
||||||
|
private BalanceManager balanceManager;
|
||||||
|
private CoinmarketCapAPIManager coinmarketCapAPIManager;
|
||||||
|
|
||||||
|
private OnUiEndListener onUiEndListener;
|
||||||
|
|
||||||
|
public void setOnUiEndListener(OnUiEndListener onUiEndListener)
|
||||||
|
{
|
||||||
|
this.onUiEndListener = onUiEndListener;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPreExecute()
|
protected void onPreExecute()
|
||||||
{
|
{
|
||||||
@ -709,13 +688,18 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... params)
|
protected Void doInBackground(Object... params)
|
||||||
{
|
{
|
||||||
if(Looper.myLooper() == null)
|
if(Looper.myLooper() == null)
|
||||||
{
|
{
|
||||||
Looper.prepare();
|
Looper.prepare();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Context baseContext = (Context) params[0];
|
||||||
|
|
||||||
|
balanceManager = (BalanceManager) params[1];
|
||||||
|
coinmarketCapAPIManager = (CoinmarketCapAPIManager) params[2];
|
||||||
|
|
||||||
balanceManager.sortCoins();
|
balanceManager.sortCoins();
|
||||||
|
|
||||||
for(int i = 0; i < balanceManager.getTotalBalance().size(); i++)
|
for(int i = 0; i < balanceManager.getTotalBalance().size(); i++)
|
||||||
@ -728,29 +712,30 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
|
|||||||
|
|
||||||
loadCurrency(localCurrency);
|
loadCurrency(localCurrency);
|
||||||
|
|
||||||
|
totalValue += localCurrency.getValue() * localCurrency.getBalance();
|
||||||
|
totalFluctuation += localCurrency.getValue() * localCurrency.getBalance() * (localCurrency.getDayFluctuationPercentage() / 100);
|
||||||
|
|
||||||
balanceManager.getTotalBalance().set(i, localCurrency);
|
balanceManager.getTotalBalance().set(i, localCurrency);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loadCurrency(Currency currency)
|
||||||
|
{
|
||||||
|
currency.setName(balanceManager.getCurrencyName(currency.getSymbol()));
|
||||||
|
currency.setId(balanceManager.getCurrencyId(currency.getSymbol()));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Void result)
|
protected void onPostExecute(Void result)
|
||||||
{
|
{
|
||||||
refreshLayout.setRefreshing(false);
|
onUiEndListener.onEnd(totalValue, totalFluctuation);
|
||||||
new AsyncTask<Void, Integer, Void>() {
|
}
|
||||||
|
|
||||||
@Override
|
public interface OnUiEndListener
|
||||||
protected Void doInBackground(Void... voids) {
|
|
||||||
if(Looper.myLooper() == null)
|
|
||||||
{
|
{
|
||||||
Looper.prepare();
|
void onEnd(float totalValue, float totalFluctuation);
|
||||||
}
|
|
||||||
|
|
||||||
adaptView();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}.execute();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -778,61 +763,6 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class IconDownloader extends AsyncTask<Void, Integer, Void>
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
protected void onPreExecute()
|
|
||||||
{
|
|
||||||
super.onPreExecute();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onProgressUpdate(Integer... values)
|
|
||||||
{
|
|
||||||
super.onProgressUpdate(values);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Void doInBackground(Void... params)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < balanceManager.getTotalBalance().size(); i++)
|
|
||||||
{
|
|
||||||
final Currency localCurrency = balanceManager.getTotalBalance().get(i);
|
|
||||||
|
|
||||||
String iconUrl = MoodlBox.getIconUrl(localCurrency.getSymbol(), balanceManager.getCryptocompareApiManager());
|
|
||||||
|
|
||||||
if(iconUrl != null)
|
|
||||||
{
|
|
||||||
MoodlBox.getBitmapFromURL(iconUrl, localCurrency.getSymbol(), getResources(), getActivity().getBaseContext(), new MoodlboxNotifierInterface() {
|
|
||||||
@Override
|
|
||||||
public void onBitmapDownloaded(Bitmap bitmapIcon) {
|
|
||||||
localCurrency.setIcon(bitmapIcon);
|
|
||||||
countIcons();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Drawable drawable = getDrawable(R.drawable.ic_panorama_fish_eye_24dp, getActivity().getBaseContext());
|
|
||||||
|
|
||||||
Bitmap icon = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
|
|
||||||
|
|
||||||
Canvas canvas = new Canvas(icon);
|
|
||||||
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
|
|
||||||
drawable.draw(canvas);
|
|
||||||
|
|
||||||
icon = Bitmap.createScaledBitmap(icon, 50, 50, false);
|
|
||||||
|
|
||||||
localCurrency.setIcon(icon);
|
|
||||||
countIcons();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private class DataUpdater extends AsyncTask<Void, Integer, Void>
|
private class DataUpdater extends AsyncTask<Void, Integer, Void>
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
@ -4,14 +4,19 @@ import android.app.Activity;
|
|||||||
import android.app.ActivityOptions;
|
import android.app.ActivityOptions;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
import android.graphics.PorterDuffColorFilter;
|
import android.graphics.PorterDuffColorFilter;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.support.v7.widget.CardView;
|
import android.support.v7.widget.CardView;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
@ -26,7 +31,9 @@ import com.github.mikephil.charting.data.LineDataSet;
|
|||||||
import com.herbron.moodl.Activities.CurrencyDetailsActivity;
|
import com.herbron.moodl.Activities.CurrencyDetailsActivity;
|
||||||
import com.herbron.moodl.CurrencyInfoUpdateNotifierInterface;
|
import com.herbron.moodl.CurrencyInfoUpdateNotifierInterface;
|
||||||
import com.herbron.moodl.DataManagers.DatabaseManager;
|
import com.herbron.moodl.DataManagers.DatabaseManager;
|
||||||
|
import com.herbron.moodl.DataManagers.InfoAPIManagers.CryptocompareApiManager;
|
||||||
import com.herbron.moodl.DataManagers.PreferencesManager;
|
import com.herbron.moodl.DataManagers.PreferencesManager;
|
||||||
|
import com.herbron.moodl.DataNotifiers.MoodlboxNotifierInterface;
|
||||||
import com.herbron.moodl.MoodlBox;
|
import com.herbron.moodl.MoodlBox;
|
||||||
import com.herbron.moodl.Utils.PlaceholderUtils;
|
import com.herbron.moodl.Utils.PlaceholderUtils;
|
||||||
import com.herbron.moodl.R;
|
import com.herbron.moodl.R;
|
||||||
@ -36,6 +43,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import static com.herbron.moodl.MoodlBox.collapseH;
|
import static com.herbron.moodl.MoodlBox.collapseH;
|
||||||
import static com.herbron.moodl.MoodlBox.expandH;
|
import static com.herbron.moodl.MoodlBox.expandH;
|
||||||
|
import static com.herbron.moodl.MoodlBox.getIconDominantColor;
|
||||||
import static com.herbron.moodl.MoodlBox.numberConformer;
|
import static com.herbron.moodl.MoodlBox.numberConformer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -46,6 +54,7 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
|
|||||||
|
|
||||||
private Currency currency;
|
private Currency currency;
|
||||||
private Activity parentActivity;
|
private Activity parentActivity;
|
||||||
|
private Context context;
|
||||||
|
|
||||||
private OnClickListener detailsClickListener = new OnClickListener() {
|
private OnClickListener detailsClickListener = new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -67,6 +76,7 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
|
|||||||
|
|
||||||
public CurrencyCardview(@NonNull Context context) {
|
public CurrencyCardview(@NonNull Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CurrencyCardview(@NonNull final Context context, final Currency currency, final Activity activity)
|
public CurrencyCardview(@NonNull final Context context, final Currency currency, final Activity activity)
|
||||||
@ -77,6 +87,7 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
|
|||||||
|
|
||||||
this.currency = currency;
|
this.currency = currency;
|
||||||
this.parentActivity = activity;
|
this.parentActivity = activity;
|
||||||
|
this.context = context;
|
||||||
|
|
||||||
LayoutInflater.from(context).inflate(R.layout.cardview_watchlist, this, true);
|
LayoutInflater.from(context).inflate(R.layout.cardview_watchlist, this, true);
|
||||||
|
|
||||||
@ -84,32 +95,9 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
|
|||||||
|
|
||||||
setupCardView();
|
setupCardView();
|
||||||
|
|
||||||
setOnClickListener(new View.OnClickListener() {
|
setOnClickListeners();
|
||||||
@Override
|
|
||||||
public void onClick(final View view) {
|
|
||||||
PreferencesManager preferencesManager = new PreferencesManager(context);
|
|
||||||
|
|
||||||
if (view.findViewById(R.id.collapsableLayout).getVisibility() == View.VISIBLE) {
|
updateCardviewInfos();
|
||||||
collapseH(view.findViewById(R.id.collapsableLayout));
|
|
||||||
} else {
|
|
||||||
view.findViewById(R.id.linearLayoutSubCharts).setVisibility(View.GONE);
|
|
||||||
view.findViewById(R.id.progressBarLinechartWatchlist).setVisibility(View.VISIBLE);
|
|
||||||
expandH(view.findViewById(R.id.collapsableLayout));
|
|
||||||
|
|
||||||
if (currency.getHistoryMinutes() == null) {
|
|
||||||
currency.updateHistoryMinutes(context, preferencesManager.getDefaultCurrency());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
expandH(view.findViewById(R.id.collapsableLayout));
|
|
||||||
view.findViewById(R.id.progressBarLinechartWatchlist).setVisibility(View.GONE);
|
|
||||||
view.findViewById(R.id.linearLayoutSubCharts).setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
updateCardViewInfos(currency);
|
|
||||||
|
|
||||||
findViewById(R.id.deleteCardWatchlist).setOnClickListener(new OnClickListener() {
|
findViewById(R.id.deleteCardWatchlist).setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -120,10 +108,9 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
findViewById(R.id.linearLayoutSubCharts).setOnClickListener(detailsClickListener);
|
updateColor();
|
||||||
findViewById(R.id.LineChartView).setOnClickListener(detailsClickListener);
|
|
||||||
|
|
||||||
updateColor(currency);
|
startIconUpdater();
|
||||||
}
|
}
|
||||||
|
|
||||||
public CurrencyCardview(@NonNull final Context context, final Currency currency, Activity activity, boolean isBalanceHidden)
|
public CurrencyCardview(@NonNull final Context context, final Currency currency, Activity activity, boolean isBalanceHidden)
|
||||||
@ -134,6 +121,7 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
|
|||||||
|
|
||||||
this.currency = currency;
|
this.currency = currency;
|
||||||
this.parentActivity = activity;
|
this.parentActivity = activity;
|
||||||
|
this.context = context;
|
||||||
|
|
||||||
LayoutInflater.from(context).inflate(R.layout.cardview_currency, this, true);
|
LayoutInflater.from(context).inflate(R.layout.cardview_currency, this, true);
|
||||||
|
|
||||||
@ -141,6 +129,68 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
|
|||||||
|
|
||||||
setupCardView();
|
setupCardView();
|
||||||
|
|
||||||
|
setOnClickListeners();
|
||||||
|
|
||||||
|
updateCardviewInfos();
|
||||||
|
|
||||||
|
updateColor();
|
||||||
|
|
||||||
|
startIconUpdater();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startIconUpdater()
|
||||||
|
{
|
||||||
|
IconDownloader iconDownloader = new IconDownloader();
|
||||||
|
iconDownloader.execute(context, currency);
|
||||||
|
iconDownloader.setOnBitmapDownloadedListener(new IconDownloader.OnBitmapDownloadedListener() {
|
||||||
|
@Override
|
||||||
|
public void onDownloaded(Bitmap icon) {
|
||||||
|
currency.setIcon(icon);
|
||||||
|
currency.setChartColor(getIconDominantColor(context, icon));
|
||||||
|
|
||||||
|
new Handler(Looper.getMainLooper()).post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
updateCurrencyColorRelatedLayouts();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateCurrencyColorRelatedLayouts()
|
||||||
|
{
|
||||||
|
((ImageView) findViewById(R.id.currencyIcon)).setImageBitmap(currency.getIcon());
|
||||||
|
|
||||||
|
Drawable arrowDrawable = ((ImageView) findViewById(R.id.detailsArrow)).getDrawable();
|
||||||
|
arrowDrawable.mutate();
|
||||||
|
arrowDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN));
|
||||||
|
arrowDrawable.invalidateSelf();
|
||||||
|
|
||||||
|
Drawable progressDrawable = ((ProgressBar) findViewById(R.id.progressBarLinechart)).getIndeterminateDrawable();
|
||||||
|
progressDrawable.mutate();
|
||||||
|
progressDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN));
|
||||||
|
progressDrawable.invalidateSelf();
|
||||||
|
|
||||||
|
if(findViewById(R.id.currencyPortfolioDominance) != null)
|
||||||
|
{
|
||||||
|
Drawable progressBarDrawable = ((ProgressBar) findViewById(R.id.currencyPortfolioDominance)).getProgressDrawable();
|
||||||
|
progressBarDrawable.mutate();
|
||||||
|
progressBarDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN));
|
||||||
|
progressBarDrawable.invalidateSelf();
|
||||||
|
}
|
||||||
|
|
||||||
|
LineChart lineChart = findViewById(R.id.LineChartView);
|
||||||
|
|
||||||
|
if(currency.getHistoryMinutes() != null)
|
||||||
|
{
|
||||||
|
lineChart.setData(generateData());
|
||||||
|
lineChart.invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setOnClickListeners()
|
||||||
|
{
|
||||||
setOnClickListener(new View.OnClickListener() {
|
setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(final View view) {
|
public void onClick(final View view) {
|
||||||
@ -150,7 +200,7 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
|
|||||||
collapseH(view.findViewById(R.id.collapsableLayout));
|
collapseH(view.findViewById(R.id.collapsableLayout));
|
||||||
} else {
|
} else {
|
||||||
view.findViewById(R.id.linearLayoutSubCharts).setVisibility(View.GONE);
|
view.findViewById(R.id.linearLayoutSubCharts).setVisibility(View.GONE);
|
||||||
view.findViewById(R.id.progressBarLinechartSummary).setVisibility(View.VISIBLE);
|
view.findViewById(R.id.progressBarLinechart).setVisibility(View.VISIBLE);
|
||||||
expandH(view.findViewById(R.id.collapsableLayout));
|
expandH(view.findViewById(R.id.collapsableLayout));
|
||||||
|
|
||||||
if (currency.getHistoryMinutes() == null) {
|
if (currency.getHistoryMinutes() == null) {
|
||||||
@ -159,7 +209,7 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
expandH(view.findViewById(R.id.collapsableLayout));
|
expandH(view.findViewById(R.id.collapsableLayout));
|
||||||
view.findViewById(R.id.progressBarLinechartSummary).setVisibility(View.GONE);
|
view.findViewById(R.id.progressBarLinechart).setVisibility(View.GONE);
|
||||||
view.findViewById(R.id.linearLayoutSubCharts).setVisibility(View.VISIBLE);
|
view.findViewById(R.id.linearLayoutSubCharts).setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -169,7 +219,6 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
|
|||||||
findViewById(R.id.linearLayoutSubCharts).setOnClickListener(detailsClickListener);
|
findViewById(R.id.linearLayoutSubCharts).setOnClickListener(detailsClickListener);
|
||||||
findViewById(R.id.LineChartView).setOnClickListener(detailsClickListener);
|
findViewById(R.id.LineChartView).setOnClickListener(detailsClickListener);
|
||||||
|
|
||||||
updateColor(currency);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Currency getCurrency()
|
public Currency getCurrency()
|
||||||
@ -210,81 +259,33 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
|
|||||||
lineChart.getLegend().setEnabled(false);
|
lineChart.getLegend().setEnabled(false);
|
||||||
lineChart.getXAxis().setEnabled(false);
|
lineChart.getXAxis().setEnabled(false);
|
||||||
lineChart.setViewPortOffsets(0, 0, 0, 0);
|
lineChart.setViewPortOffsets(0, 0, 0, 0);
|
||||||
lineChart.setData(generateData(currency));
|
lineChart.setData(generateData());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateCardViewInfos(Currency currency)
|
private void updateCardviewInfos()
|
||||||
{
|
{
|
||||||
((TextView) findViewById(R.id.currencyFluctuationTextView))
|
((TextView) findViewById(R.id.currencyFluctuationTextView))
|
||||||
.setText(PlaceholderUtils.getValueParenthesisString(numberConformer(currency.getDayFluctuation()), getContext()));
|
.setText(PlaceholderUtils.getValueParenthesisString(numberConformer(currency.getDayFluctuation()), getContext()));
|
||||||
((TextView) findViewById(R.id.currencyValueTextView))
|
((TextView) findViewById(R.id.currencyValueTextView))
|
||||||
.setText(PlaceholderUtils.getValueString(numberConformer(currency.getValue()), getContext()));
|
.setText(PlaceholderUtils.getValueString(numberConformer(currency.getValue()), getContext()));
|
||||||
|
|
||||||
((ImageView) findViewById(R.id.currencyIcon))
|
|
||||||
.setImageBitmap(currency.getIcon());
|
|
||||||
((TextView) findViewById(R.id.currencyNameTextView))
|
((TextView) findViewById(R.id.currencyNameTextView))
|
||||||
.setText(currency.getName());
|
.setText(currency.getName());
|
||||||
((TextView) findViewById(R.id.currencySymbolTextView))
|
((TextView) findViewById(R.id.currencySymbolTextView))
|
||||||
.setText(PlaceholderUtils.getSymbolString(currency.getSymbol(), getContext()));
|
.setText(PlaceholderUtils.getSymbolString(currency.getSymbol(), getContext()));
|
||||||
((TextView) findViewById(R.id.currencyFluctuationPercentageTextView))
|
((TextView) findViewById(R.id.currencyFluctuationPercentageTextView))
|
||||||
.setText(PlaceholderUtils.getPercentageString(numberConformer(currency.getDayFluctuationPercentage()), getContext()));
|
.setText(PlaceholderUtils.getPercentageString(numberConformer(currency.getDayFluctuationPercentage()), getContext()));
|
||||||
|
|
||||||
Drawable arrowDrawable = ((ImageView) findViewById(R.id.detailsArrow)).getDrawable();
|
|
||||||
|
|
||||||
if(arrowDrawable != null)
|
|
||||||
{
|
|
||||||
arrowDrawable.mutate();
|
|
||||||
arrowDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN));
|
|
||||||
arrowDrawable.invalidateSelf();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Drawable progressDrawable = ((ProgressBar) findViewById(R.id.progressBarLinechartWatchlist)).getIndeterminateDrawable();
|
public void updateOwnedValues(float totalValue, boolean isBalanceHidden)
|
||||||
|
|
||||||
if(progressDrawable != null)
|
|
||||||
{
|
|
||||||
progressDrawable.mutate();
|
|
||||||
progressDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN));
|
|
||||||
progressDrawable.invalidateSelf();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateCardViewInfos(float totalValue, boolean isBalanceHidden)
|
|
||||||
{
|
{
|
||||||
double value = currency.getValue() * currency.getBalance();
|
double value = currency.getValue() * currency.getBalance();
|
||||||
double percentage = value / totalValue * 100;
|
double percentage = value / totalValue * 100;
|
||||||
|
|
||||||
((TextView) findViewById(R.id.currencyValueOwnedTextView))
|
((TextView) findViewById(R.id.currencyValueOwnedTextView))
|
||||||
.setText(PlaceholderUtils.getValueParenthesisString(numberConformer(currency.getValue() * currency.getBalance()), getContext()));
|
.setText(PlaceholderUtils.getValueParenthesisString(numberConformer(currency.getValue() * currency.getBalance()), getContext()));
|
||||||
((TextView) findViewById(R.id.currencyFluctuationTextView))
|
|
||||||
.setText(PlaceholderUtils.getValueParenthesisString(numberConformer(currency.getDayFluctuation()), getContext()));
|
|
||||||
((TextView) findViewById(R.id.currencyValueTextView))
|
|
||||||
.setText(PlaceholderUtils.getValueString(numberConformer(currency.getValue()), getContext()));
|
|
||||||
|
|
||||||
((ImageView) findViewById(R.id.currencyIcon))
|
|
||||||
.setImageBitmap(currency.getIcon());
|
|
||||||
((TextView) findViewById(R.id.currencyNameTextView))
|
|
||||||
.setText(currency.getName());
|
|
||||||
((TextView) findViewById(R.id.currencySymbolTextView))
|
|
||||||
.setText(PlaceholderUtils.getSymbolString(currency.getSymbol(), getContext()));
|
|
||||||
((TextView) findViewById(R.id.currencyOwnedTextView))
|
((TextView) findViewById(R.id.currencyOwnedTextView))
|
||||||
.setText(PlaceholderUtils.getBalanceString(numberConformer(currency.getBalance()), currency.getSymbol(), getContext()));
|
.setText(PlaceholderUtils.getBalanceString(numberConformer(currency.getBalance()), currency.getSymbol(), getContext()));
|
||||||
((TextView) findViewById(R.id.currencyFluctuationPercentageTextView))
|
|
||||||
.setText(PlaceholderUtils.getPercentageString(numberConformer(currency.getDayFluctuationPercentage()), getContext()));
|
|
||||||
|
|
||||||
Drawable arrowDrawable = ((ImageView) findViewById(R.id.detailsArrow)).getDrawable();
|
|
||||||
arrowDrawable.mutate();
|
|
||||||
arrowDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN));
|
|
||||||
arrowDrawable.invalidateSelf();
|
|
||||||
|
|
||||||
Drawable progressDrawable = ((ProgressBar) findViewById(R.id.progressBarLinechartSummary)).getIndeterminateDrawable();
|
|
||||||
progressDrawable.mutate();
|
|
||||||
progressDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN));
|
|
||||||
progressDrawable.invalidateSelf();
|
|
||||||
|
|
||||||
Drawable progressBarDrawable = ((ProgressBar) findViewById(R.id.currencyPortfolioDominance)).getProgressDrawable();
|
|
||||||
progressBarDrawable.mutate();
|
|
||||||
progressBarDrawable.setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN));
|
|
||||||
progressBarDrawable.invalidateSelf();
|
|
||||||
|
|
||||||
((ProgressBar) findViewById(R.id.currencyPortfolioDominance)).setProgress((int) Math.round(percentage));
|
((ProgressBar) findViewById(R.id.currencyPortfolioDominance)).setProgress((int) Math.round(percentage));
|
||||||
((TextView) findViewById(R.id.percentageOwnedTextView)).setText(PlaceholderUtils.getPercentageString(numberConformer(percentage), getContext()));
|
((TextView) findViewById(R.id.percentageOwnedTextView)).setText(PlaceholderUtils.getPercentageString(numberConformer(percentage), getContext()));
|
||||||
@ -313,7 +314,7 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
|
|||||||
return getOwnedValue() * (currency.getDayFluctuationPercentage() / 100);
|
return getOwnedValue() * (currency.getDayFluctuationPercentage() / 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
private LineData generateData(Currency currency)
|
private LineData generateData()
|
||||||
{
|
{
|
||||||
LineDataSet dataSet;
|
LineDataSet dataSet;
|
||||||
List<CurrencyDataChart> dataChartList = currency.getHistoryMinutes();
|
List<CurrencyDataChart> dataChartList = currency.getHistoryMinutes();
|
||||||
@ -340,7 +341,7 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
|
|||||||
return new LineData(dataSet);
|
return new LineData(dataSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateColor(Currency currency)
|
private void updateColor()
|
||||||
{
|
{
|
||||||
if(currency.getDayFluctuationPercentage() >= 0)
|
if(currency.getDayFluctuationPercentage() >= 0)
|
||||||
{
|
{
|
||||||
@ -379,18 +380,9 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
|
|||||||
@Override
|
@Override
|
||||||
public void onHistoryDataUpdated() {
|
public void onHistoryDataUpdated() {
|
||||||
|
|
||||||
View progressWatchlistView = findViewById(R.id.progressBarLinechartWatchlist);
|
View progressView = findViewById(R.id.progressBarLinechart);
|
||||||
View progressSummaryView = findViewById(R.id.progressBarLinechartSummary);
|
|
||||||
|
|
||||||
if(progressWatchlistView != null)
|
progressView.setVisibility(View.GONE);
|
||||||
{
|
|
||||||
progressWatchlistView.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(progressSummaryView != null)
|
|
||||||
{
|
|
||||||
progressSummaryView.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
findViewById(R.id.linearLayoutSubCharts).setVisibility(View.VISIBLE);
|
findViewById(R.id.linearLayoutSubCharts).setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
@ -404,4 +396,46 @@ public class CurrencyCardview extends CardView implements CurrencyInfoUpdateNoti
|
|||||||
public void onPriceUpdated(Currency currency) {
|
public void onPriceUpdated(Currency currency) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class IconDownloader extends AsyncTask<Object, Integer, Void> implements MoodlboxNotifierInterface
|
||||||
|
{
|
||||||
|
private Bitmap icon = null;
|
||||||
|
private OnBitmapDownloadedListener onBitmapDownloadedListener;
|
||||||
|
|
||||||
|
public Bitmap getIcon()
|
||||||
|
{
|
||||||
|
return icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOnBitmapDownloadedListener(OnBitmapDownloadedListener onBitmapDownloadedListener) {
|
||||||
|
this.onBitmapDownloadedListener = onBitmapDownloadedListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Void doInBackground(Object... objects) {
|
||||||
|
Context context = (Context) objects[0];
|
||||||
|
Currency currency = (Currency) objects[1];
|
||||||
|
|
||||||
|
CryptocompareApiManager cryptocompareApiManager = CryptocompareApiManager.getInstance(context);
|
||||||
|
|
||||||
|
String iconUrl = MoodlBox.getIconUrl(currency.getSymbol(), cryptocompareApiManager);
|
||||||
|
|
||||||
|
if(iconUrl != null)
|
||||||
|
{
|
||||||
|
MoodlBox.getBitmapFromURL(iconUrl, currency.getSymbol(), context.getResources(), context, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBitmapDownloaded(Bitmap bitmap) {
|
||||||
|
icon = bitmap;
|
||||||
|
onBitmapDownloadedListener.onDownloaded(bitmap);
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface OnBitmapDownloadedListener {
|
||||||
|
void onDownloaded(Bitmap icon);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -165,7 +165,7 @@
|
|||||||
android:focusable="true">
|
android:focusable="true">
|
||||||
|
|
||||||
<ProgressBar
|
<ProgressBar
|
||||||
android:id="@+id/progressBarLinechartSummary"
|
android:id="@+id/progressBarLinechart"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
|
@ -177,7 +177,7 @@
|
|||||||
android:visibility="visible">
|
android:visibility="visible">
|
||||||
|
|
||||||
<ProgressBar
|
<ProgressBar
|
||||||
android:id="@+id/progressBarLinechartWatchlist"
|
android:id="@+id/progressBarLinechart"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
|
@ -166,7 +166,7 @@
|
|||||||
android:focusable="true">
|
android:focusable="true">
|
||||||
|
|
||||||
<ProgressBar
|
<ProgressBar
|
||||||
android:id="@+id/progressBarLinechartSummary"
|
android:id="@+id/progressBarLinechart"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
|
@ -180,7 +180,7 @@
|
|||||||
android:visibility="visible">
|
android:visibility="visible">
|
||||||
|
|
||||||
<ProgressBar
|
<ProgressBar
|
||||||
android:id="@+id/progressBarLinechartWatchlist"
|
android:id="@+id/progressBarLinechart"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
|
Loading…
Reference in New Issue
Block a user