Detailed charts animations and tooltip for max values + bug fixing

Fix the major issues happening with data refreshing and optimizing data managment
Tooltip for detailed history in progress
This commit is contained in:
Tanguy Herbron 2018-02-04 03:01:46 +01:00
parent ba4655f64a
commit d220e661b4
11 changed files with 488 additions and 131 deletions

View File

@ -3,23 +3,32 @@ package com.nauk.coinfolio.Activities;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Intent; import android.content.Intent;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Rect;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView; import android.support.design.widget.BottomNavigationView;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.util.Log; import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.view.animation.BounceInterpolator;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.ListView; import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.ViewFlipper; import android.widget.ViewFlipper;
import com.daimajia.swipe.SwipeLayout; import com.daimajia.swipe.SwipeLayout;
import com.db.chart.animation.Animation;
import com.db.chart.model.LineSet; import com.db.chart.model.LineSet;
import com.db.chart.model.Point;
import com.db.chart.renderer.AxisRenderer; import com.db.chart.renderer.AxisRenderer;
import com.db.chart.tooltip.Tooltip;
import com.db.chart.util.Tools;
import com.db.chart.view.LineChartView; import com.db.chart.view.LineChartView;
import com.nauk.coinfolio.DataManagers.CurrencyData.Currency; import com.nauk.coinfolio.DataManagers.CurrencyData.Currency;
import com.nauk.coinfolio.DataManagers.CurrencyData.CurrencyDataChart; import com.nauk.coinfolio.DataManagers.CurrencyData.CurrencyDataChart;
@ -45,6 +54,10 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
private DatabaseManager databaseManager; private DatabaseManager databaseManager;
//private String symbol; //private String symbol;
private Currency currency; private Currency currency;
private boolean hasBeenModified;
private Tooltip tip;
private int indexMax;
private int indexMin;
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() { = new BottomNavigationView.OnNavigationItemSelectedListener() {
@ -66,6 +79,17 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
} }
}; };
@Override
public void onBackPressed()
{
Log.d(this.getResources().getString(R.string.debug), "Back pressed");
Intent intent = new Intent(this, HomeActivity.class);
intent.putExtra("update", hasBeenModified);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
finish();
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -80,23 +104,36 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
viewFlipper = findViewById(R.id.vfCurrencyDetails); viewFlipper = findViewById(R.id.vfCurrencyDetails);
transactionLayout = findViewById(R.id.listTransactions); transactionLayout = findViewById(R.id.listTransactions);
chartLayout = findViewById(R.id.chartLayout); chartLayout = findViewById(R.id.chartsLayout);
drawTransactionList(); drawTransactionList();
if(currency.getDayPriceHistory().size() > 0)
{
drawChart(); drawChart();
}
else
{
TextView errorTextView = new TextView(this);
errorTextView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 500));
errorTextView.setText("Not enough data");
errorTextView.setTag("chart_layout");
errorTextView.setGravity(Gravity.CENTER);
chartLayout.addView(errorTextView);
}
setTitle(currency.getName()); setTitle(currency.getName());
BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation); BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener); navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
Log.d("coinfolio", "Color received : " + currency.getChartColor()); hasBeenModified = false;
} }
private void drawChart() private void drawChart()
{ {
LineChartView chartView = new LineChartView(this); final LineChartView chartView = new LineChartView(this);
LineSet lineSet = new LineSet(); LineSet lineSet = new LineSet();
double valMin; double valMin;
double valMax; double valMax;
@ -105,8 +142,10 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
String hour; String hour;
String minute; String minute;
List<CurrencyDataChart> dataChartList = currency.getDayPriceHistory(); final List<CurrencyDataChart> dataChartList = currency.getDayPriceHistory();
indexMin = 0;
indexMax = 0;
valMin = dataChartList.get(0).getOpen(); valMin = dataChartList.get(0).getOpen();
valMax = dataChartList.get(0).getOpen(); valMax = dataChartList.get(0).getOpen();
@ -115,11 +154,13 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
if(valMax < dataChartList.get(i).getOpen()) if(valMax < dataChartList.get(i).getOpen())
{ {
valMax = dataChartList.get(i).getOpen(); valMax = dataChartList.get(i).getOpen();
indexMax = i;
} }
if(valMin > dataChartList.get(i).getOpen()) if(valMin > dataChartList.get(i).getOpen())
{ {
valMin = dataChartList.get(i).getOpen(); valMin = dataChartList.get(i).getOpen();
indexMin = i;
} }
} }
@ -130,7 +171,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
} }
chartView.setAxisBorderValues((float) valMin, (float) valMax); chartView.setAxisBorderValues((float) valMin, (float) valMax);
chartView.setYLabels(AxisRenderer.LabelPosition.OUTSIDE); chartView.setYLabels(AxisRenderer.LabelPosition.NONE);
chartView.setYAxis(false); chartView.setYAxis(false);
chartView.setXAxis(false); chartView.setXAxis(false);
@ -168,15 +209,48 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
lineSet.setFill(getColorWitchAlpha(currency.getChartColor(), 0.5f)); lineSet.setFill(getColorWitchAlpha(currency.getChartColor(), 0.5f));
lineSet.setColor(currency.getChartColor()); lineSet.setColor(currency.getChartColor());
chartView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 500)); final LinearLayout.LayoutParams chartParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 500);
chartParams.setMargins(0, 15, 0, 15);
chartView.setLayoutParams(chartParams);
tip = new Tooltip(this, R.layout.tooltip_layout, R.id.value);
RelativeLayout.LayoutParams tipParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
tip.setLayoutParams(tipParams);
tip.setVerticalAlignment(Tooltip.Alignment.BOTTOM_TOP);
tip.setDimensions((int) Tools.fromDpToPx(75), (int) Tools.fromDpToPx(25));
tip.setClickable(false);
/*tip.setVerticalAlignment(Tooltip.Alignment.CENTER);
tip.setHorizontalAlignment(Tooltip.Alignment.CENTER);
tip.setDimensions((int) Tools.fromDpToPx(4), (int) Tools.fromDpToPx(4));
tip.setClickable(false);*/
final Tooltip tip2 = tip;
chartView.addData(lineSet); chartView.addData(lineSet);
chartView.setFadingEdgeLength(15);
chartView.setLongClickable(true);
//tip.prepare(chartView.getEntriesArea(0).get(0), (float) dataChartList.get(0).getOpen());
chartView.setTooltips(tip);
chartView.setTooltips(tip2);
Runnable launchAction = new Runnable() {
@Override
public void run() {
tip.prepare(chartView.getEntriesArea(0).get((int) indexMin/10), (float) dataChartList.get(indexMin).getOpen());
tip2.prepare(chartView.getEntriesArea(0).get((int) indexMax/10), (float) dataChartList.get(indexMax).getOpen());
chartView.showTooltip(tip, true);
//chartView.showTooltip(tip2, true);
}
};
chartView.show(new Animation().fromAlpha(0).withEndAction(launchAction));
chartLayout.addView(chartView); chartLayout.addView(chartView);
Log.d("coinfolio", "Color : " + currency.getChartColor());
chartView.show();
} }
private int getColorWitchAlpha(int color, float ratio) private int getColorWitchAlpha(int color, float ratio)
@ -214,6 +288,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
databaseManager.deleteTransactionFromId(Integer.parseInt(view.getTag().toString())); databaseManager.deleteTransactionFromId(Integer.parseInt(view.getTag().toString()));
Log.d(CurrencyDetailsActivity.this.getResources().getString(R.string.debug), "Id : " + view.getTag()); Log.d(CurrencyDetailsActivity.this.getResources().getString(R.string.debug), "Id : " + view.getTag());
drawTransactionList(); drawTransactionList();
hasBeenModified = true;
} }
}); });

View File

@ -7,11 +7,14 @@ import android.graphics.BitmapFactory;
import android.graphics.drawable.Icon; import android.graphics.drawable.Icon;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.support.design.widget.CollapsingToolbarLayout; import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
import android.support.v4.widget.SwipeRefreshLayout; import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.graphics.Palette; import android.support.v7.graphics.Palette;
import android.support.v7.widget.CardView;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.util.Log; import android.util.Log;
import android.view.Gravity; import android.view.Gravity;
@ -21,6 +24,7 @@ import android.view.MenuItem;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.Window; import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.ArrayAdapter;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.ProgressBar; import android.widget.ProgressBar;
@ -38,6 +42,7 @@ import com.nauk.coinfolio.R;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.util.ArrayList;
import java.util.List; import java.util.List;
//Use WilliamChart for charts https://github.com/diogobernardino/WilliamChart //Use WilliamChart for charts https://github.com/diogobernardino/WilliamChart
@ -67,6 +72,8 @@ public class HomeActivity extends AppCompatActivity {
private PreferencesManager preferencesManager; private PreferencesManager preferencesManager;
private DatabaseManager databaseManager; private DatabaseManager databaseManager;
private long lastTimestamp; private long lastTimestamp;
private Handler handler;
private Runnable updateRunnable;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -126,7 +133,7 @@ public class HomeActivity extends AppCompatActivity {
new SwipeRefreshLayout.OnRefreshListener() { new SwipeRefreshLayout.OnRefreshListener() {
@Override @Override
public void onRefresh() { public void onRefresh() {
updateAll(); updateAll(false);
} }
} }
); );
@ -156,6 +163,41 @@ public class HomeActivity extends AppCompatActivity {
databaseManager = new DatabaseManager(this); databaseManager = new DatabaseManager(this);
handler = new Handler();
updateRunnable = new Runnable() {
@Override
public void run() {
if (refreshLayout.isRefreshing())
{
refreshLayout.setRefreshing(false);
Snackbar.make(findViewById(R.id.currencyListLayout), "Error while updating data", Snackbar.LENGTH_LONG)
.setAction("Update", new View.OnClickListener() {
@Override
public void onClick(View view) {
updateAll(true);
}
})
.show();
}
if (loadingDialog.isShowing())
{
loadingDialog.dismiss();
Snackbar.make(findViewById(R.id.currencyListLayout), "Error while updating data", Snackbar.LENGTH_LONG)
.setAction("Update", new View.OnClickListener() {
@Override
public void onClick(View view) {
updateAll(true);
}
})
.show();
}
}
};
updateViewButtonIcon(); updateViewButtonIcon();
lastTimestamp = 0; lastTimestamp = 0;
@ -165,12 +207,16 @@ public class HomeActivity extends AppCompatActivity {
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
if(System.currentTimeMillis()/1000 - lastTimestamp > 60) Intent intent = getIntent();
updateAll(intent.getBooleanExtra("update", false));
/*if(System.currentTimeMillis()/1000 - lastTimestamp > 60 || intent.getBooleanExtra("update", false))
{ {
lastTimestamp = System.currentTimeMillis()/1000; lastTimestamp = System.currentTimeMillis()/1000;
updateAll(); updateAll();
} }*/
} }
@Override @Override
@ -236,7 +282,7 @@ public class HomeActivity extends AppCompatActivity {
if(!currency.getSymbol().equals("USD") && ((currency.getBalance() * currency.getValue()) > 0.001 || currency.getDayPriceHistory() == null)) if(!currency.getSymbol().equals("USD") && ((currency.getBalance() * currency.getValue()) > 0.001 || currency.getDayPriceHistory() == null))
{ {
currencyLayout.addView(layoutGenerator.getInfoLayout(currency, currency.getChartColor())); currencyLayout.addView(layoutGenerator.getInfoLayout(currency));
} }
} }
} }
@ -246,13 +292,26 @@ public class HomeActivity extends AppCompatActivity {
private void updateAll() private void updateAll(boolean mustUpdate)
{ {
if(System.currentTimeMillis()/1000 - lastTimestamp > 60 || mustUpdate)
{
lastTimestamp = System.currentTimeMillis() / 1000;
resetCounter(); resetCounter();
balanceManager.updateExchangeKeys(); balanceManager.updateExchangeKeys();
DataUpdater updater = new DataUpdater(); DataUpdater updater = new DataUpdater();
updater.execute(); updater.execute();
refreshLayout.setRefreshing(true); refreshLayout.setRefreshing(true);
handler.postDelayed(updateRunnable, 10000);
}
else
{
if(refreshLayout.isRefreshing())
{
refreshLayout.setRefreshing(false);
}
}
} }
private void resetCounter() private void resetCounter()
@ -283,84 +342,16 @@ public class HomeActivity extends AppCompatActivity {
private void countIcons() private void countIcons()
{ {
float totalValue = 0;
float totalFluctuation = 0;
iconCounter++; iconCounter++;
if(iconCounter == balanceManager.getTotalBalance().size()) if(iconCounter == balanceManager.getTotalBalance().size() - 1)
{ {
if(balanceManager.getTotalBalance() != null) if(balanceManager.getTotalBalance() != null)
{ {
if(coinCounter == balanceManager.getTotalBalance().size() - 1 && iconChecker) if(coinCounter == balanceManager.getTotalBalance().size() - 1 && iconChecker)
{ {
refreshLayout.setRefreshing(false); UiHeavyLoadCalculator uiHeavyLoadCalculator = new UiHeavyLoadCalculator();
uiHeavyLoadCalculator.execute();
balanceManager.sortCoins();
currencyLayout.removeAllViews();
//layoutGenerator.setCurrencyList(balanceManager.getTotalBalance());
for(int i = 0; i < balanceManager.getTotalBalance().size(); i++)
{
if(balanceManager.getTotalBalance().get(i).getIcon() != null)
{
//balanceManager.getTotalBalance().get(i).setIcon(getBitmapFromURL(balanceManager.getIconUrl(balanceManager.getTotalBalance().get(i).getSymbol())));
Palette.Builder builder = Palette.from(balanceManager.getTotalBalance().get(i).getIcon());
balanceManager.getTotalBalance().get(i).setChartColor(builder.generate().getDominantColor(0));
//layoutGenerator.addCurrencyToList(currency);
//currencyLayout.addView(layoutGenerator.getInfoLayout(i));
}
else
{
//currency.setChartColor(12369084);
balanceManager.getTotalBalance().get(i).setChartColor(12369084);
//currencyLayout.addView(layoutGenerator.getInfoLayout(i));
}
if(!balanceManager.getTotalBalance().get(i).getSymbol().equals("USD") && (balanceManager.getTotalBalance().get(i).getBalance() * balanceManager.getTotalBalance().get(i).getValue()) > 0.001)
{
balanceManager.getTotalBalance().get(i).setName(balanceManager.getCurrencyName(balanceManager.getTotalBalance().get(i).getSymbol()));
totalValue += balanceManager.getTotalBalance().get(i).getValue() * balanceManager.getTotalBalance().get(i).getBalance();
totalFluctuation += (balanceManager.getTotalBalance().get(i).getValue() * balanceManager.getTotalBalance().get(i).getBalance()) * (balanceManager.getTotalBalance().get(i).getDayFluctuationPercentage() / 100);
//balanceManager.getTotalBalance().get(i).setIcon(getBitmapFromURL(balanceManager.getIconUrl(balanceManager.getTotalBalance().get(i).getSymbol())));
//currencyLayout.addView(layoutGenerator.getInfoLayout(i));
currencyLayout.addView(layoutGenerator.getInfoLayout(balanceManager.getTotalBalance().get(i), 0));
}
if(!balanceManager.getTotalBalance().get(i).getSymbol().equals("USD") && balanceManager.getTotalBalance().get(i).getDayPriceHistory() == null)
{
//balanceManager.getTotalBalance().get(i).setIcon(getBitmapFromURL(balanceManager.getIconUrl(balanceManager.getTotalBalance().get(i).getSymbol())));
//currencyLayout.addView(layoutGenerator.getInfoLayout(i));
currencyLayout.addView(layoutGenerator.getInfoLayout(balanceManager.getTotalBalance().get(i), 0));
}
}
adaptView();
toolbarLayout.setTitle("US$" + String.format("%.2f", totalValue));
if(totalFluctuation > 0)
{
toolbarSubtitle.setTextColor(getResources().getColor(R.color.increase));
}
else
{
toolbarSubtitle.setTextColor(getResources().getColor(R.color.decrease));
}
toolbarSubtitle.setText("US$" + String.format("%.2f", totalFluctuation));
if(loadingDialog.isShowing())
{
loadingDialog.dismiss();
}
} }
if(balanceManager.getTotalBalance().size() == 0) if(balanceManager.getTotalBalance().size() == 0)
@ -387,6 +378,31 @@ public class HomeActivity extends AppCompatActivity {
} }
} }
} }
else
{
if(balanceManager.getTotalBalance().size() == 0)
{
currencyLayout.removeAllViews();
refreshLayout.setRefreshing(false);
if(loadingDialog.isShowing())
{
loadingDialog.dismiss();
}
runOnUiThread(new Runnable() {
@Override
public void run() {
toolbarLayout.setTitle("US$0.00");
toolbarSubtitle.setText("US$0.00");
toolbarSubtitle.setTextColor(-1275068417);
}
});
}
}
} }
private void countCoins(boolean isCoin, boolean isDetails) private void countCoins(boolean isCoin, boolean isDetails)
@ -401,12 +417,16 @@ public class HomeActivity extends AppCompatActivity {
iconChecker = true; iconChecker = true;
} }
if(balanceManager.getTotalBalance() != null)
{
if(coinCounter == balanceManager.getTotalBalance().size()-1) if(coinCounter == balanceManager.getTotalBalance().size()-1)
{ {
for (int i = 0; i < balanceManager.getTotalBalance().size(); i++) for (int i = 0; i < balanceManager.getTotalBalance().size(); i++)
{ {
final int index = i; final int index = i;
if(balanceManager.getIconUrl(balanceManager.getTotalBalance().get(i).getSymbol()) != null)
{
getBitmapFromURL(balanceManager.getIconUrl(balanceManager.getTotalBalance().get(i).getSymbol()), new IconCallBack() { getBitmapFromURL(balanceManager.getIconUrl(balanceManager.getTotalBalance().get(i).getSymbol()), new IconCallBack() {
@Override @Override
public void onSuccess(Bitmap bitmapIcon) { public void onSuccess(Bitmap bitmapIcon) {
@ -417,6 +437,15 @@ public class HomeActivity extends AppCompatActivity {
} }
} }
} }
else
{
if(balanceManager.getTotalBalance().size() == 0)
{
countIcons();
}
}
}
}
private void updateViewButtonIcon() private void updateViewButtonIcon()
{ {
@ -460,6 +489,146 @@ public class HomeActivity extends AppCompatActivity {
loadingDialog.show(); loadingDialog.show();
} }
private class UiHeavyLoadCalculator extends AsyncTask<Void, Integer, Void>
{
private float totalValue;
private float totalFluctuation;
private float totalFluctuationPercentage;
@Override
protected void onPreExecute()
{
super.onPreExecute();
totalValue = 0;
totalFluctuation = 0;
totalFluctuationPercentage = 0;
}
@Override
protected void onProgressUpdate(Integer... values)
{
super.onProgressUpdate(values);
}
@Override
protected Void doInBackground(Void... params)
{
final List<CardView> cardList = new ArrayList<>();
Looper.prepare();
balanceManager.sortCoins();
//layoutGenerator.setCurrencyList(balanceManager.getTotalBalance());
for(int i = 0; i < balanceManager.getTotalBalance().size(); i++)
{
final Currency localCurrency = balanceManager.getTotalBalance().get(i);
if(localCurrency.getIcon() != null)
{
//balanceManager.getTotalBalance().get(i).setIcon(getBitmapFromURL(balanceManager.getIconUrl(balanceManager.getTotalBalance().get(i).getSymbol())));
Palette.Builder builder = Palette.from(localCurrency.getIcon());
localCurrency.setChartColor(builder.generate().getDominantColor(0));
//layoutGenerator.addCurrencyToList(currency);
//currencyLayout.addView(layoutGenerator.getInfoLayout(i));
}
else
{
//currency.setChartColor(12369084);
localCurrency.setChartColor(12369084);
//currencyLayout.addView(layoutGenerator.getInfoLayout(i));
}
if(!localCurrency.getSymbol().equals("USD") && (localCurrency.getBalance() * localCurrency.getValue()) > 0.001)
{
localCurrency.setName(balanceManager.getCurrencyName(localCurrency.getSymbol()));
localCurrency.setId(balanceManager.getCurrencyId(localCurrency.getSymbol()));
totalValue += localCurrency.getValue() * localCurrency.getBalance();
totalFluctuation += (localCurrency.getValue() * localCurrency.getBalance()) * (localCurrency.getDayFluctuationPercentage() / 100);
//balanceManager.getTotalBalance().get(i).setIcon(getBitmapFromURL(balanceManager.getIconUrl(balanceManager.getTotalBalance().get(i).getSymbol())));
//currencyLayout.addView(layoutGenerator.getInfoLayout(i));
cardList.add(layoutGenerator.getInfoLayout(localCurrency));
}
if(!localCurrency.getSymbol().equals("USD") && localCurrency.getDayPriceHistory() == null)
{
//balanceManager.getTotalBalance().get(i).setIcon(getBitmapFromURL(balanceManager.getIconUrl(balanceManager.getTotalBalance().get(i).getSymbol())));
//currencyLayout.addView(layoutGenerator.getInfoLayout(i));
cardList.add(layoutGenerator.getInfoLayout(localCurrency));
}
balanceManager.getTotalBalance().set(i, localCurrency);
}
runOnUiThread(new Runnable() {
@Override
public void run() {
refreshLayout.setRefreshing(false);
currencyLayout.removeAllViews();
for(int i = 0; i < cardList.size(); i++)
{
currencyLayout.addView(cardList.get(i));
}
adaptView();
}
});
toolbarLayout.setTitle("US$" + String.format("%.2f", totalValue));
if(totalFluctuation > 0)
{
runOnUiThread(new Runnable() {
@Override
public void run() {
toolbarSubtitle.setTextColor(getResources().getColor(R.color.increase));
}
});
}
else
{
runOnUiThread(new Runnable() {
@Override
public void run() {
toolbarSubtitle.setTextColor(getResources().getColor(R.color.decrease));
}
});
}
runOnUiThread(new Runnable() {
@Override
public void run() {
totalFluctuationPercentage = totalFluctuation / (totalValue - totalFluctuation) *100;
toolbarSubtitle.setText("US$" + String.format("%.2f", totalFluctuation) + " (" + String.format("%.2f", totalFluctuationPercentage) + "%)");
if(loadingDialog.isShowing())
{
loadingDialog.dismiss();
}
}
});
return null;
}
@Override
protected void onPostExecute(Void result)
{
handler.removeCallbacks(updateRunnable);
}
}
private class DataUpdater extends AsyncTask<Void, Integer, Void> private class DataUpdater extends AsyncTask<Void, Integer, Void>
{ {
@Override @Override
@ -490,12 +659,13 @@ public class HomeActivity extends AppCompatActivity {
balance.get(i).updateDayPriceHistory(getApplicationContext(), new Currency.CurrencyCallBack() { balance.get(i).updateDayPriceHistory(getApplicationContext(), new Currency.CurrencyCallBack() {
@Override @Override
public void onSuccess(Currency currency) { public void onSuccess(Currency currency) {
currency.updateName(getApplicationContext(), new Currency.CurrencyCallBack() { countCoins(true, false);
/*currency.updateName(getApplicationContext(), new Currency.CurrencyCallBack() {
@Override @Override
public void onSuccess(Currency currency) { public void onSuccess(Currency currency) {
countCoins(true, false); countCoins(true, false);
} }
}); });*/
} }
}); });
} }
@ -515,10 +685,10 @@ public class HomeActivity extends AppCompatActivity {
Snackbar.make(findViewById(R.id.currencyListLayout), "HitBTC synchronization error : Invalid keys", Snackbar.LENGTH_LONG) Snackbar.make(findViewById(R.id.currencyListLayout), "HitBTC synchronization error : Invalid keys", Snackbar.LENGTH_LONG)
.show(); .show();
refreshLayout.setRefreshing(false); refreshLayout.setRefreshing(false);
updateAll(); updateAll(true);
break; break;
default: default:
updateAll(); updateAll(true);
} }
//updateAll(); //updateAll();
} }

View File

@ -41,6 +41,7 @@ public class RecordTransactionActivity extends AppCompatActivity {
public void onClick(View view) { public void onClick(View view) {
databaseManager.addCurrencyToManualCurrency(symbol, Double.parseDouble(amountTxtView.getText().toString())); databaseManager.addCurrencyToManualCurrency(symbol, Double.parseDouble(amountTxtView.getText().toString()));
Intent intent = new Intent(RecordTransactionActivity.this, HomeActivity.class); Intent intent = new Intent(RecordTransactionActivity.this, HomeActivity.class);
intent.putExtra("update", true);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent); startActivity(intent);
finish(); finish();

View File

@ -48,6 +48,7 @@ public class BalanceManager {
private android.content.Context context; private android.content.Context context;
private Map<String, String> iconUrlList; private Map<String, String> iconUrlList;
private Map<String, String> coinList; private Map<String, String> coinList;
private Map<String, Integer> coinIdList;
private PreferencesManager preferenceManager; private PreferencesManager preferenceManager;
private DatabaseManager databaseManager; private DatabaseManager databaseManager;
@ -265,7 +266,16 @@ public class BalanceManager {
public String getIconUrl(String symbol) public String getIconUrl(String symbol)
{ {
return iconUrlList.get(symbol); String url;
try {
url = iconUrlList.get(symbol);
} catch (NullPointerException e) {
Log.d(context.getResources().getString(R.string.debug), symbol + " has no icon URL");
url = null;
}
return url;
} }
public String getCurrencyName(String symbol) public String getCurrencyName(String symbol)
@ -273,6 +283,11 @@ public class BalanceManager {
return coinList.get(symbol); return coinList.get(symbol);
} }
public int getCurrencyId(String symbol)
{
return coinIdList.get(symbol);
}
private void processDetailResult(String response, final IconCallBack callBack) private void processDetailResult(String response, final IconCallBack callBack)
{ {
response = response.substring(response.indexOf("\"Data\"") + 7, response.lastIndexOf("},\"Type\":100}")); response = response.substring(response.indexOf("\"Data\"") + 7, response.lastIndexOf("},\"Type\":100}"));
@ -280,6 +295,7 @@ public class BalanceManager {
iconUrlList = new HashMap<>(); iconUrlList = new HashMap<>();
coinList = new HashMap<>(); coinList = new HashMap<>();
coinIdList = new HashMap<>();
for(int i = 0; i < tab.length; i++) for(int i = 0; i < tab.length; i++)
{ {
@ -292,6 +308,8 @@ public class BalanceManager {
iconUrlList.put(jsonObject.getString("Symbol"), "https://www.cryptocompare.com" + jsonObject.getString("ImageUrl") + "?width=50"); iconUrlList.put(jsonObject.getString("Symbol"), "https://www.cryptocompare.com" + jsonObject.getString("ImageUrl") + "?width=50");
coinList.put(jsonObject.getString("Symbol"), jsonObject.getString("CoinName")); coinList.put(jsonObject.getString("Symbol"), jsonObject.getString("CoinName"));
coinIdList.put(jsonObject.getString("Symbol"), jsonObject.getInt("Id"));
} catch (JSONException e) { } catch (JSONException e) {
Log.d(context.getResources().getString(R.string.debug), "ImageUrl not found."); Log.d(context.getResources().getString(R.string.debug), "ImageUrl not found.");
} }

View File

@ -15,6 +15,7 @@ import static java.sql.Types.NULL;
public class Currency implements Parcelable { public class Currency implements Parcelable {
private int id;
private String name; private String name;
private String symbol; private String symbol;
private double value; private double value;
@ -26,6 +27,21 @@ public class Currency implements Parcelable {
private Bitmap icon; private Bitmap icon;
private int chartColor; private int chartColor;
public Currency(Currency currency)
{
this.id = currency.id;
this.name = currency.name;
this.symbol = currency.symbol;
this.value = currency.value;
this.balance = currency.balance;
this.dayFluctuationPercentage = currency.getDayFluctuationPercentage();
this.dayFluctuation = currency.getDayFluctuation();
this.dayPriceHistory = currency.dayPriceHistory;
this.dataRetriver = currency.getDataRetriver();
this.icon = currency.icon;
this.chartColor = currency.chartColor;
}
public Currency(String symbol, double balance) public Currency(String symbol, double balance)
{ {
this.symbol = symbol; this.symbol = symbol;
@ -88,6 +104,16 @@ public class Currency implements Parcelable {
}); });
} }
public void setId(int id)
{
this.id = id;
}
public int getId()
{
return id;
}
public void setChartColor(int chartColor) public void setChartColor(int chartColor)
{ {
this.chartColor = chartColor; this.chartColor = chartColor;
@ -190,6 +216,7 @@ public class Currency implements Parcelable {
@Override @Override
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(this.id);
dest.writeString(this.name); dest.writeString(this.name);
dest.writeString(this.symbol); dest.writeString(this.symbol);
dest.writeDouble(this.value); dest.writeDouble(this.value);
@ -202,6 +229,7 @@ public class Currency implements Parcelable {
} }
protected Currency(Parcel in) { protected Currency(Parcel in) {
this.id = in.readInt();
this.name = in.readString(); this.name = in.readString();
this.symbol = in.readString(); this.symbol = in.readString();
this.value = in.readDouble(); this.value = in.readDouble();

View File

@ -98,7 +98,7 @@ public class CurrencyDataRetriver {
new Response.ErrorListener() { new Response.ErrorListener() {
@Override @Override
public void onErrorResponse(VolleyError error) { public void onErrorResponse(VolleyError error) {
callBack.onSuccess(null);
} }
}); });

View File

@ -19,12 +19,11 @@ import com.nauk.coinfolio.R;
public class CurrencyAdapter extends ArrayAdapter<Currency> { public class CurrencyAdapter extends ArrayAdapter<Currency> {
private ArrayList<Currency> Currencys, tempCurrency, suggestions; private ArrayList<Currency> tempCurrency, suggestions;
private Context context; private Context context;
public CurrencyAdapter(Context context, ArrayList<Currency> objects) { public CurrencyAdapter(Context context, ArrayList<Currency> objects) {
super(context, android.R.layout.simple_list_item_1, objects); super(context, android.R.layout.simple_list_item_1, objects);
this.Currencys = objects;
this.tempCurrency = new ArrayList<Currency>(objects); this.tempCurrency = new ArrayList<Currency>(objects);
this.suggestions = new ArrayList<Currency>(objects); this.suggestions = new ArrayList<Currency>(objects);

View File

@ -49,7 +49,7 @@ public class HomeLayoutGenerator {
this.context = context; this.context = context;
} }
public CardView getInfoLayout(final Currency currency, int chartColor) public CardView getInfoLayout(final Currency currency)
//public CardView getInfoLayout(int index) //public CardView getInfoLayout(int index)
{ {
CardView mainCard = new CardView(context); CardView mainCard = new CardView(context);
@ -132,7 +132,7 @@ public class HomeLayoutGenerator {
mainLinear.addView(separatorLayout); mainLinear.addView(separatorLayout);
mainLinear.addView(generateChart(currency, chartLayout, chartColor)); mainLinear.addView(generateChart(currency, chartLayout));
mainLinear.setClickable(false); mainLinear.setClickable(false);
@ -180,13 +180,13 @@ public class HomeLayoutGenerator {
} }
}*/ }*/
private View generateChart(Currency currency, LinearLayout chartLayout, int chartColor) private View generateChart(Currency currency, LinearLayout chartLayout)
{ {
View toReturn; View toReturn;
if(currency.getDayPriceHistory() != null) if(currency.getDayPriceHistory() != null)
{ {
LineChartView lineChartView = chartGenerator(currency.getDayPriceHistory(), chartColor); LineChartView lineChartView = chartGenerator(currency.getDayPriceHistory(), currency.getChartColor());
chartLayout.setTag("chart_layout"); chartLayout.setTag("chart_layout");
chartLayout.addView(lineChartView); chartLayout.addView(lineChartView);
lineChartView.show(); lineChartView.show();

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="90"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="360">
<shape
android:innerRadiusRatio="3"
android:shape="ring"
android:thicknessRatio="7.0">
<gradient
android:centerColor="@color/colorAccent"
android:endColor="@color/colorAccent"
android:startColor="@color/colorAccent"
android:angle="0"
android:type="sweep"
android:useLevel="false" />
</shape>
</rotate>

View File

@ -12,31 +12,58 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginBottom="56dp"> android:layout_marginBottom="56dp">
<LinearLayout
android:id="@+id/chartsLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView <ScrollView
android:id="@+id/svCharts" android:id="@+id/svCharts"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/chartLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"/>
</ScrollView> </ScrollView>
<ScrollView
</LinearLayout>
<LinearLayout
android:id="@+id/infosLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleLarge"
android:layout_gravity="center"
android:background="@drawable/circular_progress_bar" />
<!--<ScrollView
android:id="@+id/svInfos" android:id="@+id/svInfos"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<TextView <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:gravity="center" android:orientation="vertical">
android:text="Infos"/>
</ScrollView> <ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleLarge"
android:layout_gravity="center"
android:background="@drawable/circular_progress_bar" />
</LinearLayout>
</ScrollView>-->
</LinearLayout>
<ScrollView <ScrollView
android:id="@+id/svTransactions" android:id="@+id/svTransactions"

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/rounded_corners"
android:gravity="center_horizontal">
<TextView
android:id="@+id/value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center"
android:textColor="#ffffff"
android:textSize="16sp"/>
</RelativeLayout>