Update icon code

This commit is contained in:
Tanguy Herbron 2018-05-26 01:26:23 +02:00
parent 241362fe8c
commit 4986091644
5 changed files with 70 additions and 72 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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();
}
}
});
}

View File

@ -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<CurrencyDataChart>) 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<String>() {
@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<CurrencyDataChart> dataChart);
void onSuccess(String price);

View File

@ -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;
}
}