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 b78e53e..82d65af 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 @@ -1,7 +1,6 @@ package com.nauk.moodl.Activities.HomeActivityFragments; import android.annotation.SuppressLint; -import android.content.Intent; import android.graphics.Color; import android.support.v4.app.Fragment; import android.os.Bundle; @@ -9,16 +8,13 @@ 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; import android.view.ViewGroup; import android.widget.ImageButton; import android.widget.TextView; -import android.widget.Toast; -import com.github.mikephil.charting.charts.PieChart; import com.github.mikephil.charting.data.Entry; import com.github.mikephil.charting.data.PieData; import com.github.mikephil.charting.data.PieDataSet; @@ -26,19 +22,17 @@ import com.github.mikephil.charting.data.PieEntry; import com.github.mikephil.charting.formatter.PercentFormatter; import com.github.mikephil.charting.highlight.Highlight; import com.github.mikephil.charting.listener.OnChartValueSelectedListener; -import com.nauk.moodl.Activities.SettingsActivity; import com.nauk.moodl.DataManagers.CurrencyData.Currency; import com.nauk.moodl.DataManagers.MarketCapManager; import com.nauk.moodl.DataManagers.PreferencesManager; import com.nauk.moodl.LayoutManagers.CustomPieChart; -import com.nauk.moodl.LayoutManagers.CustomViewPager; +import com.nauk.moodl.MoodlBox; import com.nauk.moodl.PlaceholderManager; import com.nauk.moodl.R; import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import java.util.Locale; import static com.nauk.moodl.MoodlBox.numberConformer; import static java.lang.Math.abs; @@ -294,15 +288,19 @@ public class MarketCapitalization extends Fragment { public void run() { if(e.getData() != null) { + view.findViewById(R.id.layoutMarketDetails).setVisibility(View.VISIBLE); Currency currency = marketCapManager.getCurrencyFromSymbol((String) e.getData()); - //view.findViewById(R.id.layoutMarketDetails).setVisibility(); + ((TextView) view.findViewById(R.id.textViewMarketCap)) - .setText(PlaceholderManager.getValueString(String.valueOf(currency.getMarketCapitalization()), getContext())); + .setText(PlaceholderManager.getValueString(MoodlBox.numberConformer(currency.getMarketCapitalization()), getContext())); ((TextView) view.findViewById(R.id.textViewVolume)) - .setText(PlaceholderManager.getValueString(String.valueOf(currency.getVolume24h()), getContext())); - ((TextView) view.findViewById(R.id.textViewSymbol)) - .setText(currency.getName()); - + .setText(PlaceholderManager.getValueString(MoodlBox.numberConformer(currency.getVolume24h()), getContext())); + ((TextView) view.findViewById(R.id.textViewNameSymbol)) + .setText(currency.getName() + " (" + currency.getSymbol() + ")"); + } + else + { + view.findViewById(R.id.layoutMarketDetails).setVisibility(View.GONE); } } }); @@ -310,6 +308,7 @@ public class MarketCapitalization extends Fragment { @Override public void onNothingSelected() { + view.findViewById(R.id.layoutMarketDetails).setVisibility(View.GONE); } }); 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 ccdbcd8..add357e 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 @@ -35,6 +35,7 @@ import com.nauk.moodl.DataManagers.CurrencyData.CurrencyCardview; import com.nauk.moodl.DataManagers.CurrencyData.CurrencyTickerList; import com.nauk.moodl.DataManagers.PreferencesManager; import com.nauk.moodl.HideBalanceSwitch; +import com.nauk.moodl.MoodlBox; import com.nauk.moodl.PlaceholderManager; import com.nauk.moodl.R; @@ -569,27 +570,6 @@ public class Summary extends Fragment implements HideBalanceSwitch { } } - private void getBitmapFromURL(String src, HomeActivity.IconCallBack callBack) { - Bitmap result; - - try { - java.net.URL url = new java.net.URL(src); - HttpURLConnection connection = (HttpURLConnection) url - .openConnection(); - connection.setDoInput(true); - connection.connect(); - InputStream input = connection.getInputStream(); - result = BitmapFactory.decodeStream(input); - } catch (IOException e) { - Log.d("moodl", "Error while downloading icon"); - result = BitmapFactory.decodeResource(this.getResources(), - R.mipmap.ic_launcher_moodl); - result = Bitmap.createScaledBitmap(result, 50, 50, false); - } - - callBack.onSuccess(result); - } - private void displayBalance(boolean hideBalance) { updateTitle(); @@ -635,7 +615,7 @@ public class Summary extends Fragment implements HideBalanceSwitch { { final Currency localCurrency = balanceManager.getTotalBalance().get(i); - getBitmapFromURL(balanceManager.getIconUrl(localCurrency.getSymbol()), new HomeActivity.IconCallBack() { + MoodlBox.getBitmapFromURL(balanceManager.getIconUrl(localCurrency.getSymbol()), localCurrency.getSymbol(), getResources(), getContext(), new HomeActivity.IconCallBack() { @Override public void onSuccess(Bitmap bitmapIcon) { localCurrency.setIcon(bitmapIcon); 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 8a109e1..1ba86b9 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 @@ -30,6 +30,7 @@ import com.nauk.moodl.DataManagers.CurrencyData.CurrencyDetailsList; import com.nauk.moodl.DataManagers.CurrencyData.CurrencyTickerList; import com.nauk.moodl.DataManagers.PreferencesManager; import com.nauk.moodl.DataManagers.WatchlistManager; +import com.nauk.moodl.MoodlBox; import com.nauk.moodl.R; import org.json.JSONException; @@ -305,27 +306,6 @@ public class Watchlist extends Fragment { return url; } - private void getBitmapFromURL(String src, HomeActivity.IconCallBack callBack) { - Bitmap result; - - try { - java.net.URL url = new java.net.URL(src); - HttpURLConnection connection = (HttpURLConnection) url - .openConnection(); - connection.setDoInput(true); - connection.connect(); - InputStream input = connection.getInputStream(); - result = BitmapFactory.decodeStream(input); - } catch (IOException e) { - e.printStackTrace(); - result = BitmapFactory.decodeResource(this.getResources(), - R.mipmap.ic_launcher_moodl); - result = Bitmap.createScaledBitmap(result, 50, 50, false); - } - - callBack.onSuccess(result); - } - private void updateChartColor(Currency currency) { if(currency.getIcon() != null) @@ -371,7 +351,7 @@ public class Watchlist extends Fragment { currency.updatePrice(getActivity(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() { @Override public void onSuccess(final Currency sucessCurrency) { - getBitmapFromURL(getIconUrl(sucessCurrency.getSymbol()), new HomeActivity.IconCallBack() { + MoodlBox.getBitmapFromURL(getIconUrl(sucessCurrency.getSymbol()), sucessCurrency.getSymbol(), getResources(), getContext(), new HomeActivity.IconCallBack() { @Override public void onSuccess(Bitmap bitmapIcon) { sucessCurrency.setIcon(bitmapIcon); diff --git a/app/src/main/java/com/nauk/moodl/MoodlBox.java b/app/src/main/java/com/nauk/moodl/MoodlBox.java index 2dca48c..a88bf7c 100644 --- a/app/src/main/java/com/nauk/moodl/MoodlBox.java +++ b/app/src/main/java/com/nauk/moodl/MoodlBox.java @@ -1,15 +1,29 @@ package com.nauk.moodl; +import android.content.Context; +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; import android.support.v7.widget.CardView; +import android.util.Log; import android.view.View; import android.view.animation.Animation; import android.view.animation.Transformation; +import com.nauk.moodl.Activities.HomeActivity; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.HttpURLConnection; import java.text.SimpleDateFormat; 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. @@ -188,4 +202,39 @@ public class MoodlBox { return "xx"; } } + + public static void getBitmapFromURL(String src, String symbol, Resources resources, Context context, HomeActivity.IconCallBack callBack) { + + String filepath = context.getCacheDir() + "/" + symbol + ".png"; + Bitmap result; + + BitmapFactory.Options options = new BitmapFactory.Options(); + options.inPreferredConfig = Bitmap.Config.ARGB_8888; + + result = BitmapFactory.decodeFile(filepath, options); + + if(result == null) + { + try { + java.net.URL url = new java.net.URL(src); + HttpURLConnection connection = (HttpURLConnection) url + .openConnection(); + connection.setDoInput(true); + connection.connect(); + InputStream input = connection.getInputStream(); + result = BitmapFactory.decodeStream(input); + + FileOutputStream out = new FileOutputStream(filepath); + result.compress(Bitmap.CompressFormat.PNG, 100, out); + + } catch (IOException e) { + Log.d("moodl", "Error while downloading " + symbol + " icon"); + result = BitmapFactory.decodeResource(resources, + R.mipmap.ic_launcher_moodl); + result = Bitmap.createScaledBitmap(result, 50, 50, false); + } + } + + callBack.onSuccess(result); + } } diff --git a/app/src/main/res/layout/fragment_marketcap_homeactivity.xml b/app/src/main/res/layout/fragment_marketcap_homeactivity.xml index 788592e..c1bc94f 100644 --- a/app/src/main/res/layout/fragment_marketcap_homeactivity.xml +++ b/app/src/main/res/layout/fragment_marketcap_homeactivity.xml @@ -109,48 +109,67 @@ android:id="@+id/layoutMarketDetails" android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="horizontal"> + android:orientation="vertical" + android:layout_margin="10dp" + android:visibility="gone"> + + + + + android:orientation="horizontal" + android:baselineAligned="false"> - + android:layout_weight="0.5" + android:orientation="vertical"> - + + + + + + + android:layout_weight="0.5" + android:orientation="vertical"> - + - + - - - - - +