UI and performance improvements
- Add cache loading for icons - Rework Market capitalization activity UI
This commit is contained in:
parent
b46e9cbe3f
commit
241362fe8c
@ -1,7 +1,6 @@
|
|||||||
package com.nauk.moodl.Activities.HomeActivityFragments;
|
package com.nauk.moodl.Activities.HomeActivityFragments;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Intent;
|
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.os.Bundle;
|
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.DrawerLayout;
|
||||||
import android.support.v4.widget.SwipeRefreshLayout;
|
import android.support.v4.widget.SwipeRefreshLayout;
|
||||||
import android.text.SpannableString;
|
import android.text.SpannableString;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.TextView;
|
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.Entry;
|
||||||
import com.github.mikephil.charting.data.PieData;
|
import com.github.mikephil.charting.data.PieData;
|
||||||
import com.github.mikephil.charting.data.PieDataSet;
|
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.formatter.PercentFormatter;
|
||||||
import com.github.mikephil.charting.highlight.Highlight;
|
import com.github.mikephil.charting.highlight.Highlight;
|
||||||
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
|
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.CurrencyData.Currency;
|
||||||
import com.nauk.moodl.DataManagers.MarketCapManager;
|
import com.nauk.moodl.DataManagers.MarketCapManager;
|
||||||
import com.nauk.moodl.DataManagers.PreferencesManager;
|
import com.nauk.moodl.DataManagers.PreferencesManager;
|
||||||
import com.nauk.moodl.LayoutManagers.CustomPieChart;
|
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.PlaceholderManager;
|
||||||
import com.nauk.moodl.R;
|
import com.nauk.moodl.R;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import static com.nauk.moodl.MoodlBox.numberConformer;
|
import static com.nauk.moodl.MoodlBox.numberConformer;
|
||||||
import static java.lang.Math.abs;
|
import static java.lang.Math.abs;
|
||||||
@ -294,15 +288,19 @@ public class MarketCapitalization extends Fragment {
|
|||||||
public void run() {
|
public void run() {
|
||||||
if(e.getData() != null)
|
if(e.getData() != null)
|
||||||
{
|
{
|
||||||
|
view.findViewById(R.id.layoutMarketDetails).setVisibility(View.VISIBLE);
|
||||||
Currency currency = marketCapManager.getCurrencyFromSymbol((String) e.getData());
|
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()));
|
|
||||||
((TextView) view.findViewById(R.id.textViewVolume))
|
|
||||||
.setText(PlaceholderManager.getValueString(String.valueOf(currency.getVolume24h()), getContext()));
|
|
||||||
((TextView) view.findViewById(R.id.textViewSymbol))
|
|
||||||
.setText(currency.getName());
|
|
||||||
|
|
||||||
|
((TextView) view.findViewById(R.id.textViewMarketCap))
|
||||||
|
.setText(PlaceholderManager.getValueString(MoodlBox.numberConformer(currency.getMarketCapitalization()), getContext()));
|
||||||
|
((TextView) view.findViewById(R.id.textViewVolume))
|
||||||
|
.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
|
@Override
|
||||||
public void onNothingSelected() {
|
public void onNothingSelected() {
|
||||||
|
view.findViewById(R.id.layoutMarketDetails).setVisibility(View.GONE);
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -35,6 +35,7 @@ import com.nauk.moodl.DataManagers.CurrencyData.CurrencyCardview;
|
|||||||
import com.nauk.moodl.DataManagers.CurrencyData.CurrencyTickerList;
|
import com.nauk.moodl.DataManagers.CurrencyData.CurrencyTickerList;
|
||||||
import com.nauk.moodl.DataManagers.PreferencesManager;
|
import com.nauk.moodl.DataManagers.PreferencesManager;
|
||||||
import com.nauk.moodl.HideBalanceSwitch;
|
import com.nauk.moodl.HideBalanceSwitch;
|
||||||
|
import com.nauk.moodl.MoodlBox;
|
||||||
import com.nauk.moodl.PlaceholderManager;
|
import com.nauk.moodl.PlaceholderManager;
|
||||||
import com.nauk.moodl.R;
|
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)
|
private void displayBalance(boolean hideBalance)
|
||||||
{
|
{
|
||||||
updateTitle();
|
updateTitle();
|
||||||
@ -635,7 +615,7 @@ public class Summary extends Fragment implements HideBalanceSwitch {
|
|||||||
{
|
{
|
||||||
final Currency localCurrency = balanceManager.getTotalBalance().get(i);
|
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
|
@Override
|
||||||
public void onSuccess(Bitmap bitmapIcon) {
|
public void onSuccess(Bitmap bitmapIcon) {
|
||||||
localCurrency.setIcon(bitmapIcon);
|
localCurrency.setIcon(bitmapIcon);
|
||||||
|
@ -30,6 +30,7 @@ import com.nauk.moodl.DataManagers.CurrencyData.CurrencyDetailsList;
|
|||||||
import com.nauk.moodl.DataManagers.CurrencyData.CurrencyTickerList;
|
import com.nauk.moodl.DataManagers.CurrencyData.CurrencyTickerList;
|
||||||
import com.nauk.moodl.DataManagers.PreferencesManager;
|
import com.nauk.moodl.DataManagers.PreferencesManager;
|
||||||
import com.nauk.moodl.DataManagers.WatchlistManager;
|
import com.nauk.moodl.DataManagers.WatchlistManager;
|
||||||
|
import com.nauk.moodl.MoodlBox;
|
||||||
import com.nauk.moodl.R;
|
import com.nauk.moodl.R;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
@ -305,27 +306,6 @@ public class Watchlist extends Fragment {
|
|||||||
return url;
|
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)
|
private void updateChartColor(Currency currency)
|
||||||
{
|
{
|
||||||
if(currency.getIcon() != null)
|
if(currency.getIcon() != null)
|
||||||
@ -371,7 +351,7 @@ public class Watchlist extends Fragment {
|
|||||||
currency.updatePrice(getActivity(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() {
|
currency.updatePrice(getActivity(), preferencesManager.getDefaultCurrency(), new Currency.CurrencyCallBack() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(final Currency sucessCurrency) {
|
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
|
@Override
|
||||||
public void onSuccess(Bitmap bitmapIcon) {
|
public void onSuccess(Bitmap bitmapIcon) {
|
||||||
sucessCurrency.setIcon(bitmapIcon);
|
sucessCurrency.setIcon(bitmapIcon);
|
||||||
|
@ -1,15 +1,29 @@
|
|||||||
package com.nauk.moodl;
|
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.support.v7.widget.CardView;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.animation.Animation;
|
import android.view.animation.Animation;
|
||||||
import android.view.animation.Transformation;
|
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.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import static java.lang.Math.abs;
|
import static java.lang.Math.abs;
|
||||||
|
import static java.lang.Math.subtractExact;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Guitoune on 30/04/2018.
|
* Created by Guitoune on 30/04/2018.
|
||||||
@ -188,4 +202,39 @@ public class MoodlBox {
|
|||||||
return "xx";
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,29 @@
|
|||||||
android:id="@+id/layoutMarketDetails"
|
android:id="@+id/layoutMarketDetails"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal">
|
android:orientation="vertical"
|
||||||
|
android:layout_margin="10dp"
|
||||||
|
android:visibility="gone">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/textViewNameSymbol"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:textSize="20sp"/>
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="@dimen/separationLineSize"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_margin="10dp"
|
||||||
|
android:background="@color/separationColor" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:baselineAligned="false">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
@ -117,11 +139,6 @@
|
|||||||
android:layout_weight="0.5"
|
android:layout_weight="0.5"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:id="@+id/textViewSymbol"/>
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@ -159,5 +176,7 @@
|
|||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
</android.support.v4.widget.SwipeRefreshLayout>
|
</android.support.v4.widget.SwipeRefreshLayout>
|
||||||
</android.support.constraint.ConstraintLayout>
|
</android.support.constraint.ConstraintLayout>
|
Loading…
Reference in New Issue
Block a user