UI and performance improvements

- Add cache loading for icons
- Rework Market capitalization activity UI
This commit is contained in:
Tanguy Herbron 2018-05-25 21:16:55 +02:00
parent b46e9cbe3f
commit 241362fe8c
5 changed files with 116 additions and 89 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -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">
<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="0dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:orientation="vertical">
android:orientation="horizontal"
android:baselineAligned="false">
<TextView
android:layout_width="wrap_content"
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/textViewSymbol"/>
android:layout_weight="0.5"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Market capitalization"
android:textStyle="bold"/>
<TextView
android:id="@+id/textViewMarketCap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Market capitalization"
android:textStyle="bold"/>
android:layout_weight="0.5"
android:orientation="vertical">
<TextView
android:id="@+id/textViewMarketCap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="24h volume"
android:textStyle="bold"/>
</LinearLayout>
<TextView
android:id="@+id/textViewVolume"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="24h volume"
android:textStyle="bold"/>
<TextView
android:id="@+id/textViewVolume"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>