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 82d65af..5c01765 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 @@ -8,6 +8,7 @@ import android.support.v4.view.GravityCompat; import android.support.v4.widget.DrawerLayout; import android.support.v4.widget.SwipeRefreshLayout; import android.text.SpannableString; +import android.util.Log; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; @@ -245,10 +246,19 @@ public class MarketCapitalization extends Fragment { if(marketCapCounter == 2) { + updateIcons(); refreshDisplayedData(); } } + private void updateIcons() + { + for(int i = 0; i < marketCapManager.getTopCurrencies().size(); i++) + { + Log.d("moodl", "> " + marketCapManager.getTopCurrencies().get(i).getSymbol()); + } + } + private void setupPieChart(PieData data) { CustomPieChart pieChart = view.findViewById(R.id.marketCapPieChart); diff --git a/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Summary.java b/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Summary.java index add357e..09878f9 100644 --- a/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Summary.java +++ b/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Summary.java @@ -615,13 +615,26 @@ public class Summary extends Fragment implements HideBalanceSwitch { { final Currency localCurrency = balanceManager.getTotalBalance().get(i); - MoodlBox.getBitmapFromURL(balanceManager.getIconUrl(localCurrency.getSymbol()), localCurrency.getSymbol(), getResources(), getContext(), new HomeActivity.IconCallBack() { - @Override - public void onSuccess(Bitmap bitmapIcon) { - localCurrency.setIcon(bitmapIcon); - countIcons(); - } - }); + String iconUrl = balanceManager.getIconUrl(localCurrency.getSymbol()); + + if(iconUrl != null) + { + MoodlBox.getBitmapFromURL(iconUrl, localCurrency.getSymbol(), getResources(), getContext(), new HomeActivity.IconCallBack() { + @Override + public void onSuccess(Bitmap bitmapIcon) { + localCurrency.setIcon(bitmapIcon); + countIcons(); + } + }); + } + else + { + Bitmap icon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher_moodl); + icon = Bitmap.createScaledBitmap(icon, 50, 50, false); + + localCurrency.setIcon(icon); + countIcons(); + } } return null; diff --git a/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Watchlist.java b/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Watchlist.java index 1ba86b9..e07e515 100644 --- a/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Watchlist.java +++ b/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Watchlist.java @@ -351,14 +351,28 @@ public class Watchlist extends Fragment { currency.updatePrice(getActivity(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { @Override public void onSuccess(final Currency sucessCurrency) { - MoodlBox.getBitmapFromURL(getIconUrl(sucessCurrency.getSymbol()), sucessCurrency.getSymbol(), getResources(), getContext(), new HomeActivity.IconCallBack() { - @Override - public void onSuccess(Bitmap bitmapIcon) { - sucessCurrency.setIcon(bitmapIcon); - updateChartColor(currency); - countWatchlist(); - } - }); + String iconUrl = getIconUrl(sucessCurrency.getSymbol()); + + if(iconUrl != null) + { + MoodlBox.getBitmapFromURL(iconUrl, sucessCurrency.getSymbol(), getResources(), getContext(), new HomeActivity.IconCallBack() { + @Override + public void onSuccess(Bitmap bitmapIcon) { + sucessCurrency.setIcon(bitmapIcon); + updateChartColor(currency); + countWatchlist(); + } + }); + } + else + { + Bitmap icon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher_moodl); + icon = Bitmap.createScaledBitmap(icon, 50, 50, false); + + sucessCurrency.setIcon(icon); + updateChartColor(currency); + countWatchlist(); + } } }); } diff --git a/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/CurrencyDataRetriever.java b/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/CurrencyDataRetriever.java index 442faa4..51e8980 100644 --- a/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/CurrencyDataRetriever.java +++ b/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/CurrencyDataRetriever.java @@ -136,7 +136,7 @@ public class CurrencyDataRetriever { return result; } - public void updateHistory(final String symbolCurrencyFrom, String symbolCyrrencyTo, final DataChartCallBack callBack, int timeUnit) + void updateHistory(final String symbolCurrencyFrom, String symbolCyrrencyTo, final DataChartCallBack callBack, int timeUnit) { String requestUrl = getRequestUrl(timeUnit, symbolCurrencyFrom, symbolCyrrencyTo); @@ -157,7 +157,7 @@ public class CurrencyDataRetriever { requestQueue.add(stringRequest); } - public void updatePrice(String symbolCurrencyFrom, String symbolCurrencyTo, final CurrencyCallBack callBack) + void updatePrice(String symbolCurrencyFrom, String symbolCurrencyTo, final CurrencyCallBack callBack) { if(symbolCurrencyFrom.equals("MIOTA")) { @@ -314,61 +314,6 @@ public class CurrencyDataRetriever { return new CurrencyDataChart(timestamp, close, high, low, open, volumeFrom, volumeTo); } - public void getPriceTimestamp(String symbolCurrencyFrom, final DataChartCallBack callBack, long timestamp) - { - getPriceTimestamp(symbolCurrencyFrom, "USD", callBack, timestamp); - } - - public void updateHistory(String symbolCurrencyFrom, final DataChartCallBack callBack, int timeUnit) - { - if(symbolCurrencyFrom.equals("USD")) - { - callBack.onSuccess((List) null); - } - else - { - updateHistory(symbolCurrencyFrom, "USD", callBack, timeUnit); - } - } - - public void updatePrice(String symbolCurrencyFrom, final CurrencyCallBack callBack) - { - if(symbolCurrencyFrom.equals("USD")) - { - callBack.onSuccess(null); - } - else - { - updatePrice(symbolCurrencyFrom, "USD", callBack); - } - } - - /*public void updateCryptocompareDetails(int id, final Currency.CurrencyCallBack callBack) - { - String requestUrl = getRequestUrl(timeUnit, symbolCurrencyFrom, symbolCyrrencyTo); - - StringRequest stringRequest = new StringRequest(Request.Method.GET, requestUrl, - new Response.Listener() { - @Override - public void onResponse(String response) { - callBack.onSuccess(); - } - }, - new Response.ErrorListener() { - @Override - public void onErrorResponse(VolleyError error) { - callBack.onSuccess(); - } - }); - - requestQueue.add(stringRequest); - }*/ - - public void updateCoinMarketCapDetails() - { - - } - public interface DataChartCallBack { void onSuccess(List dataChart); void onSuccess(String price); diff --git a/app/src/main/java/com/nauk/moodl/MoodlBox.java b/app/src/main/java/com/nauk/moodl/MoodlBox.java index a88bf7c..1df4ed6 100644 --- a/app/src/main/java/com/nauk/moodl/MoodlBox.java +++ b/app/src/main/java/com/nauk/moodl/MoodlBox.java @@ -12,6 +12,9 @@ import android.view.animation.Transformation; import com.nauk.moodl.Activities.HomeActivity; +import org.json.JSONException; +import org.json.JSONObject; + import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -237,4 +240,17 @@ public class MoodlBox { callBack.onSuccess(result); } + + public static String getIconUrl(String imageUrl) + { + String url; + + try { + url = "https://www.cryptocompare.com" + imageUrl + "?width=50"; + } catch (NullPointerException e) { + url = null; + } + + return url; + } }