Code cleanup

This commit is contained in:
Tanguy Herbron 2018-04-04 14:12:23 +02:00
parent c83385080c
commit 6e0657e5db
16 changed files with 468 additions and 400 deletions

21
.idea/statistic.xml generated Normal file
View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Statistic">
<option name="fileTypes" value="class;svn-base;svn-work;Extra;gif;png;jpg;jpeg;bmp;tga;tiff;ear;war;zip;jar;iml;iws;ipr;bz2;gz;gitignore;gradle;md;pro;properties;" />
<option name="excludedDirectories">
<list>
<option value="$PROJECT_DIR$/build" />
<option value="$PROJECT_DIR$/export" />
<option value="$PROJECT_DIR$/gource" />
<option value="$PROJECT_DIR$/gradle" />
<option value="$PROJECT_DIR$/libs" />
<option value="$PROJECT_DIR$/.idea" />
<option value="$PROJECT_DIR$/.gradle" />
<option value="$PROJECT_DIR$/app/build" />
<option value="$PROJECT_DIR$/app/release" />
<option value="$PROJECT_DIR$/app/src/androidTest" />
<option value="$PROJECT_DIR$/app/src/test" />
</list>
</option>
</component>
</project>

View File

@ -26,7 +26,6 @@ import android.widget.TextView;
import android.widget.ViewFlipper;
import com.daimajia.swipe.SwipeLayout;
import com.db.chart.tooltip.Tooltip;
import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.data.BarData;
@ -45,10 +44,8 @@ import com.nauk.coinfolio.R;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
/**Create a Parcelable**/
@ -67,6 +64,8 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
private final static int MONTH = 3;
private final static int YEAR = 4;
private List<CurrencyDataChart> dataChartList;
private LineChart lineChart;
private BarChart barChart;
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {
@ -122,6 +121,8 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
viewFlipper = findViewById(R.id.vfCurrencyDetails);
transactionLayout = findViewById(R.id.listTransactions);
chartLayout = findViewById(R.id.chartsLayout);
lineChart = findViewById(R.id.chartPriceView);
barChart = findViewById(R.id.chartVolumeView);
drawTransactionList();
@ -129,6 +130,16 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
createCharts(DAY, 1);
setupActionBar();
BottomNavigationView navigation = findViewById(R.id.navigation_details);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
hasBeenModified = false;
}
private void setupActionBar()
{
setTitle(" " + currency.getName() + " | " + currency.getBalance());
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME |
ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_USE_LOGO);
@ -145,10 +156,6 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
getSupportActionBar().setIcon(new BitmapDrawable(Bitmap.createScaledBitmap(result, 120, 120, false)));
BottomNavigationView navigation = findViewById(R.id.navigation_details);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
hasBeenModified = false;
}
private void initializeButtons()
@ -185,7 +192,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
}
}
chartEvent((Button) v);
updateCharts((Button) v);
}
private float convertDpToPx(float dp)
@ -193,7 +200,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
return dp * this.getResources().getDisplayMetrics().density;
}
private void chartEvent(Button button)
private void updateCharts(Button button)
{
findViewById(R.id.chartPriceView).setVisibility(View.GONE);
findViewById(R.id.chartVolumeView).setVisibility(View.GONE);
@ -344,8 +351,16 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
private void drawVolumeChart()
{
final BarChart barChart = findViewById(R.id.chartVolumeView);
initializeBarChart(barChart);
barChart.setData(generateVolumeChartSet());
barChart.invalidate();
findViewById(R.id.chartVolumeView).setVisibility(View.VISIBLE);
}
private void initializeBarChart(BarChart barChart)
{
barChart.setDrawGridBackground(false);
barChart.setDrawBorders(false);
barChart.setDrawMarkers(true);
@ -360,18 +375,42 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
barChart.getXAxis().setEnabled(false);
barChart.setViewPortOffsets(0, 0, 0, 0);
barChart.setFitBars(true);
barChart.setData(generateVolumeChartSet());
barChart.invalidate();
findViewById(R.id.chartVolumeView).setVisibility(View.VISIBLE);
}
private void drawPriceChart()
{
final LineChart lineChart = findViewById(R.id.chartPriceView);
final BarChart barChart = findViewById(R.id.chartVolumeView);
initializeLineChart(lineChart);
lineChart.setData(generatePriceChartSet());
lineChart.getAxisLeft().setAxisMinValue(lineChart.getData().getYMin());
lineChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
@Override
public void onValueSelected(Entry e, Highlight h) {
valueSelectedEvent(e);
}
@Override
public void onNothingSelected() {
}
});
lineChart.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
return toucheEvent(motionEvent);
}
});
updateFluctuation(lineChart.getData().getDataSets().get(0).getEntryForIndex(0).getY(), lineChart.getData().getDataSets().get(0).getEntryForIndex(lineChart.getData().getDataSets().get(0).getEntryCount() - 1).getY());
findViewById(R.id.chartPriceView).setVisibility(View.VISIBLE);
findViewById(R.id.progressLayoutChart).setVisibility(View.GONE);
}
private void initializeLineChart(LineChart lineChart)
{
lineChart.setDrawGridBackground(false);
lineChart.setDrawBorders(false);
lineChart.setDrawMarkers(true);
@ -385,20 +424,14 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
lineChart.getLegend().setEnabled(false);
lineChart.getXAxis().setEnabled(false);
lineChart.setViewPortOffsets(0, 0, 0, 0);
}
lineChart.setData(generatePriceChartSet());
lineChart.getAxisLeft().setAxisMinValue(lineChart.getData().getYMin());
lineChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
@Override
public void onValueSelected(Entry e, Highlight h) {
private void valueSelectedEvent(Entry e)
{
//updateFluctuation(lineChart.getData().getDataSets().get(0).getEntryForIndex(0).getY(), e.getY());
int index = lineChart.getData().getDataSets().get(0).getEntryIndex(e);
String date = null;
barChart.highlightValue(barChart.getData().getDataSets().get(0).getEntryForIndex(index).getX(), 0, index);
findViewById(R.id.volumeHightlight).setVisibility(View.VISIBLE);
findViewById(R.id.priceHightlight).setVisibility(View.VISIBLE);
findViewById(R.id.timestampHightlight).setVisibility(View.VISIBLE);
if(dataChartList.size() > 200)
{
@ -409,38 +442,40 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
date = getDate(dataChartList.get(index).getTimestamp() * 1000);
}
displayDataIndicators();
((TextView) findViewById(R.id.volumeHightlight)).setText("Volume : US$" + barChart.getData().getDataSets().get(0).getEntryForIndex(index).getY());
((TextView) findViewById(R.id.priceHightlight)).setText("Price : US$" + e.getY());
((TextView) findViewById(R.id.timestampHightlight)).setText("Date : " + date);
}
@Override
public void onNothingSelected() {
}
});
lineChart.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
private boolean toucheEvent(MotionEvent motionEvent)
{
if(motionEvent.getAction() == MotionEvent.ACTION_UP)
{
lineChart.highlightValue(null);
updateFluctuation(lineChart.getData().getDataSets().get(0).getEntryForIndex(0).getY(), lineChart.getData().getDataSets().get(0).getEntryForIndex(lineChart.getData().getDataSets().get(0).getEntryCount() - 1).getY());
barChart.highlightValues(null);
hideDataIndicators();
}
return false;
}
private void displayDataIndicators()
{
findViewById(R.id.volumeHightlight).setVisibility(View.VISIBLE);
findViewById(R.id.priceHightlight).setVisibility(View.VISIBLE);
findViewById(R.id.timestampHightlight).setVisibility(View.VISIBLE);
}
private void hideDataIndicators()
{
findViewById(R.id.volumeHightlight).setVisibility(View.INVISIBLE);
findViewById(R.id.priceHightlight).setVisibility(View.INVISIBLE);
findViewById(R.id.timestampHightlight).setVisibility(View.INVISIBLE);
}
return false;
}
});
updateFluctuation(lineChart.getData().getDataSets().get(0).getEntryForIndex(0).getY(), lineChart.getData().getDataSets().get(0).getEntryForIndex(lineChart.getData().getDataSets().get(0).getEntryCount() - 1).getY());
findViewById(R.id.chartPriceView).setVisibility(View.VISIBLE);
findViewById(R.id.progressLayoutChart).setVisibility(View.GONE);
}
private String getDate(long timeStamp){
@ -514,7 +549,6 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
Drawable fillDrawable = ContextCompat.getDrawable(this, R.drawable.linear_chart_gradient);
fillDrawable.setColorFilter(getColorWithAlpha(currency.getChartColor(), 0.5f), PorterDuff.Mode.SRC_ATOP);
//dataSet.setFillDrawable(fillDrawable);
return new LineData(dataSet);
}
@ -582,6 +616,14 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
amountTxtView.setText(transactionList.get(i).getAmount() + "");
setupSwipeView(view);
transactionLayout.addView(view);
}
}
private void setupSwipeView(View view)
{
SwipeLayout swipeLayout = view.findViewById(R.id.swipeLayout);
//set show mode.
@ -621,10 +663,6 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
//when user's hand released.
}
});
transactionLayout.addView(view);
}
}
}

View File

@ -46,6 +46,11 @@ public class CurrencySelectionActivity extends AppCompatActivity implements Sear
setupList();
setupSearchView();
}
private void setupSearchView()
{
SearchView searchView = findViewById(R.id.search_bar);
searchView.setIconifiedByDefault(false);

View File

@ -6,8 +6,6 @@ import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Outline;
import android.graphics.Typeface;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
@ -23,11 +21,7 @@ import android.support.v7.app.AppCompatActivity;
import android.support.v7.graphics.Palette;
import android.support.v7.widget.Toolbar;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.text.style.StyleSpan;
import android.util.Log;
import android.view.DragEvent;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
@ -35,22 +29,17 @@ import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewOutlineProvider;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.ViewFlipper;
import com.github.mikephil.charting.animation.Easing;
import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.data.PieEntry;
import com.github.mikephil.charting.formatter.PercentFormatter;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.luseen.spacenavigation.SpaceItem;
import com.luseen.spacenavigation.SpaceNavigationView;
import com.luseen.spacenavigation.SpaceOnClickListener;
@ -61,8 +50,6 @@ import com.nauk.coinfolio.DataManagers.PreferencesManager;
import com.nauk.coinfolio.LayoutManagers.HomeLayoutGenerator;
import com.nauk.coinfolio.R;
import org.w3c.dom.Text;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
@ -74,7 +61,6 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Random;
//Use WilliamChart for charts https://github.com/diogobernardino/WilliamChart
@ -149,7 +135,7 @@ public class HomeActivity extends AppCompatActivity {
setContentView(R.layout.activity_currency_summary);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
generateSplash();
generateSplashScreen();
//Objects initialization
preferencesManager = new PreferencesManager(this);
@ -195,12 +181,6 @@ public class HomeActivity extends AppCompatActivity {
toolbarSubtitle.setText("US$0.00");
/*BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation_home);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
navigation.setSelectedItemId(R.id.navigation_view_list);
navigation.setFitsSystemWindows(true);
navigation.setItemBackgroundResource(R.color.colorAccent);*/
//Events setup
detailsButton.setOnClickListener(new View.OnClickListener() {
@Override
@ -304,6 +284,22 @@ public class HomeActivity extends AppCompatActivity {
spaceNavigationView.setSpaceOnClickListener(new SpaceOnClickListener() {
@Override
public void onCentreButtonClick() {
spaceNavigationCentreButtonEvent();
}
@Override
public void onItemClick(int itemIndex, String itemName) {
}
@Override
public void onItemReselected(int itemIndex, String itemName) {
spaceNavigationItemEvent(itemIndex);
}
});
}
private void spaceNavigationCentreButtonEvent()
{
//Toast.makeText(MainActivity.this,"onCentreButtonClick", Toast.LENGTH_SHORT).show();
((FloatingActionButton) findViewById(R.id.floatingAddButton)).show();
SpaceNavigationView nav = findViewById(R.id.space);
@ -323,8 +319,8 @@ public class HomeActivity extends AppCompatActivity {
viewFlipper.setDisplayedChild(1);
}
@Override
public void onItemClick(int itemIndex, String itemName) {
private void spaceNavigationItemEvent(int itemIndex)
{
((FloatingActionButton) findViewById(R.id.floatingAddButton)).hide();
((SpaceNavigationView) findViewById(R.id.space)).setCentreButtonIcon(R.drawable.ic_view_list_white_24dp);
@ -340,8 +336,6 @@ public class HomeActivity extends AppCompatActivity {
findViewById(R.id.switch_button).setVisibility(View.GONE);
viewFlipper.setDisplayedChild(itemIndex * 2);
if(itemIndex == 1)
@ -350,13 +344,6 @@ public class HomeActivity extends AppCompatActivity {
}
}
@Override
public void onItemReselected(int itemIndex, String itemName) {
//Toast.makeText(MainActivity.this, itemIndex + " " + itemName, Toast.LENGTH_SHORT).show();
}
});
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
@ -379,13 +366,24 @@ public class HomeActivity extends AppCompatActivity {
protected void onResume() {
super.onResume();
//addTestWatchlistCardview();
Intent intent = getIntent();
updateAll(intent.getBooleanExtra("update", false));
((SpaceNavigationView) findViewById(R.id.space)).changeCenterButtonIcon(R.drawable.ic_view_list_white_24dp);
}
private void addTestWatchlistCardview()
{
View view = LayoutInflater.from(this).inflate(R.layout.cardview_watchlist, null);
((TextView) view.findViewById(R.id.currencyFluctuationPercentageTextView)).setText("3%");
((TextView) view.findViewById(R.id.currencyFluctuationTextView)).setText("$3");
((TextView) view.findViewById(R.id.currencyNameTextView)).setText("TanguyCoin");
((TextView) view.findViewById(R.id.currencySymbolTextView)).setText("TGC");
((TextView) view.findViewById(R.id.currencyValueTextView)).setText("$100");
view.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
view.setOnClickListener(new View.OnClickListener() {
@Override
@ -394,14 +392,7 @@ public class HomeActivity extends AppCompatActivity {
}
});
//((LinearLayout) findViewById(R.id.linearLayoutWatchlist)).addView(view);
Intent intent = getIntent();
Log.d("coinfolio", "Updated ? " + intent.getBooleanExtra("update", false));
updateAll(intent.getBooleanExtra("update", false));
((SpaceNavigationView) findViewById(R.id.space)).changeCenterButtonIcon(R.drawable.ic_view_list_white_24dp);
((LinearLayout) findViewById(R.id.linearLayoutWatchlist)).addView(view);
}
@Override
@ -455,7 +446,6 @@ public class HomeActivity extends AppCompatActivity {
if(!currency.getSymbol().equals("USD") && ((currency.getBalance() * currency.getValue()) > 0.001 || currency.getHistoryMinutes() == null))
{
//currencyLayout.addView(layoutGenerator.getInfoLayout(currency));
currencyLayout.addView(layoutGenerator.getInfoLayout(currency, isDetailed));
}
}
@ -574,13 +564,10 @@ public class HomeActivity extends AppCompatActivity {
{
marketCapCounter = 0;
Log.d("coinfolio", "Start update market cap");
marketCapManager.updateTopCurrencies(new MarketCapManager.VolleyCallBack() {
@Override
public void onSuccess()
{
Log.d("coinfolio", "Top updated");
countCompletedMarketCapRequest();
}
});
@ -588,7 +575,6 @@ public class HomeActivity extends AppCompatActivity {
marketCapManager.updateMarketCap(new MarketCapManager.VolleyCallBack() {
@Override
public void onSuccess() {
Log.d("coinfolio", "Marketcap updated");
countCompletedMarketCapRequest();
}
});
@ -610,8 +596,6 @@ public class HomeActivity extends AppCompatActivity {
ArrayList<Integer> colors = new ArrayList<>();
PieChart pieChart = findViewById(R.id.marketCapPieChart);
float otherCurrenciesDominance = 0;
for(Iterator i = marketCapManager.getDominance().keySet().iterator(); i.hasNext(); )
@ -632,6 +616,15 @@ public class HomeActivity extends AppCompatActivity {
PieData data = new PieData(set);
data.setValueTextSize(10);
data.setValueFormatter(new PercentFormatter());
setupPieChart(data);
}
}
private void setupPieChart(PieData data)
{
PieChart pieChart = findViewById(R.id.marketCapPieChart);
pieChart.setData(data);
pieChart.setDrawSlicesUnderHole(false);
pieChart.setUsePercentValues(true);
@ -661,7 +654,7 @@ public class HomeActivity extends AppCompatActivity {
pieChart.getLegend().setEnabled(false);
pieChart.setCenterText(generateCenterSpannableText());
pieChart.invalidate(); // refresh
}
}
private void setupTextViewMarketCap()
@ -679,8 +672,8 @@ public class HomeActivity extends AppCompatActivity {
private SpannableString generateCenterSpannableText() {
SpannableString s = new SpannableString("Market Capitalization Dominance");
return s;
SpannableString spannableString = new SpannableString("Market Capitalization Dominance");
return spannableString;
}
private void countCoins(boolean isCoin, boolean isDetails)
@ -706,8 +699,6 @@ public class HomeActivity extends AppCompatActivity {
{
if(balanceManager.getTotalBalance().size() == 0)
{
Log.d("coinfolio", "Empty");
countIcons();
}
}
@ -732,7 +723,7 @@ public class HomeActivity extends AppCompatActivity {
}
}
private void generateSplash()
private void generateSplashScreen()
{
LinearLayout loadingLayout = new LinearLayout(this);
@ -825,49 +816,40 @@ public class HomeActivity extends AppCompatActivity {
super.onProgressUpdate(values);
}
@Override
protected Void doInBackground(Void... params)
private void updateChartColor(Currency currency)
{
final List<View> cardList = new ArrayList<>();
Looper.prepare();
balanceManager.sortCoins();
for(int i = 0; i < balanceManager.getTotalBalance().size(); i++)
if(currency.getIcon() != null)
{
final Currency localCurrency = balanceManager.getTotalBalance().get(i);
if(localCurrency.getIcon() != null)
{
Palette.Builder builder = Palette.from(localCurrency.getIcon());
localCurrency.setChartColor(builder.generate().getDominantColor(0));
Palette.Builder builder = Palette.from(currency.getIcon());
currency.setChartColor(builder.generate().getDominantColor(0));
}
else
{
localCurrency.setChartColor(12369084);
currency.setChartColor(12369084);
}
}
if(!localCurrency.getSymbol().equals("USD") && (localCurrency.getBalance() * localCurrency.getValue()) > 0.001)
private void loadCurrency(Currency currency, List<View> cardList)
{
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);
cardList.add(layoutGenerator.getInfoLayout(localCurrency, true));
}
if(!localCurrency.getSymbol().equals("USD") && localCurrency.getHistoryMinutes() == null)
if(!currency.getSymbol().equals("USD") && (currency.getBalance() * currency.getValue()) > 0.001)
{
cardList.add(layoutGenerator.getInfoLayout(localCurrency, true));
currency.setName(balanceManager.getCurrencyName(currency.getSymbol()));
currency.setId(balanceManager.getCurrencyId(currency.getSymbol()));
totalValue += currency.getValue() * currency.getBalance();
totalFluctuation += (currency.getValue() * currency.getBalance()) * (currency.getDayFluctuationPercentage() / 100);
cardList.add(layoutGenerator.getInfoLayout(currency, true));
}
balanceManager.getTotalBalance().set(i, localCurrency);
if(!currency.getSymbol().equals("USD") && currency.getHistoryMinutes() == null)
{
cardList.add(layoutGenerator.getInfoLayout(currency, true));
}
}
private void refreshCurrencyList(final List<View> cardList)
{
runOnUiThread(new Runnable() {
@Override
public void run() {
@ -882,9 +864,10 @@ public class HomeActivity extends AppCompatActivity {
adaptView();
}
});
}
toolbarLayout.setTitle("US$" + String.format("%.2f", totalValue));
private void updateFluctuation()
{
if(totalFluctuation > 0)
{
runOnUiThread(new Runnable() {
@ -903,7 +886,10 @@ public class HomeActivity extends AppCompatActivity {
}
});
}
}
private void updateTitle()
{
runOnUiThread(new Runnable() {
@Override
public void run() {
@ -918,6 +904,35 @@ public class HomeActivity extends AppCompatActivity {
}
}
});
}
@Override
protected Void doInBackground(Void... params)
{
final List<View> cardList = new ArrayList<>();
Looper.prepare();
balanceManager.sortCoins();
for(int i = 0; i < balanceManager.getTotalBalance().size(); i++)
{
final Currency localCurrency = balanceManager.getTotalBalance().get(i);
updateChartColor(localCurrency);
loadCurrency(localCurrency, cardList);
balanceManager.getTotalBalance().set(i, localCurrency);
}
refreshCurrencyList(cardList);
toolbarLayout.setTitle("US$" + String.format("%.2f", totalValue));
updateFluctuation();
updateTitle();
return null;
}
@ -1011,17 +1026,6 @@ public class HomeActivity extends AppCompatActivity {
updateMarketCap();
/*marketCapManager.updateTopCurrencies(new BalanceManager.VolleyCallBack() {
@Override
public void onSuccess() {
}
@Override
public void onError(String error) {
}});*/
return null;
}

View File

@ -49,9 +49,7 @@ public class RecordTransactionActivity extends AppCompatActivity {
databaseManager = new DatabaseManager(this);
validateButton = findViewById(R.id.validateButton);
amountTxtView = findViewById(R.id.currencyAmount);
purchasedDate = findViewById(R.id.purchaseDate);
purchasedDate.setText(sdf.format(calendar.getTime()));

View File

@ -280,7 +280,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
if(preferences.getBoolean("enable_fingerprint", false))
{
newFragment.setCancelable(false);
newFragment.show(getFragmentManager(), "dialog");

View File

@ -95,7 +95,6 @@ public class BalanceManager {
while(index < 11)
{
//currenciesDetails.add(index, coinInfosHashmap.keySet().iterator().next());
index++;
Log.d("coinfolio", "For " + index + " : " + coinIterator.next());

View File

@ -9,13 +9,13 @@ import android.os.Parcelable;
public class CurrencyDataChart implements Parcelable {
long timestamp;
double close;
double high;
double low;
double open;
double volumeFrom;
double volumeTo;
private long timestamp;
private double close;
private double high;
private double low;
private double open;
private double volumeFrom;
private double volumeTo;
public CurrencyDataChart(long timestamp, double close, double high, double low, double open, double volumeFrom, double volumeTo)
{

View File

@ -44,20 +44,7 @@ public class CurrencyDataRetriever {
private void updateHistory(final String symbolCurrencyFrom, String symbolCyrrencyTo, final DataChartCallBack callBack, int timeUnit)
{
String requestUrl = null;
switch (timeUnit)
{
case MINUTES:
requestUrl = minuteHistoryUrl + "?fsym=" + symbolCurrencyFrom + "&tsym=" + symbolCyrrencyTo + "&limit=1440";
break;
case HOURS:
requestUrl = hourHistoryUrl + "?fsym=" + symbolCurrencyFrom + "&tsym=" + symbolCyrrencyTo + "&limit=744";
break;
case DAYS:
requestUrl = dayHistoryUrl + "?fsym=" + symbolCurrencyFrom + "&tsym=" + symbolCyrrencyTo + "&limit=365";
break;
}
String requestUrl = getRequestUrl(timeUnit, symbolCurrencyFrom, symbolCyrrencyTo);
StringRequest stringRequest = new StringRequest(Request.Method.GET, requestUrl,
new Response.Listener<String>() {
@ -76,6 +63,26 @@ public class CurrencyDataRetriever {
requestQueue.add(stringRequest);
}
private String getRequestUrl(int timeUnit, String symbolCurrencyFrom, String symbolCyrrencyTo)
{
String requestUrl = null;
switch (timeUnit)
{
case MINUTES:
requestUrl = minuteHistoryUrl + "?fsym=" + symbolCurrencyFrom + "&tsym=" + symbolCyrrencyTo + "&limit=1440";
break;
case HOURS:
requestUrl = hourHistoryUrl + "?fsym=" + symbolCurrencyFrom + "&tsym=" + symbolCyrrencyTo + "&limit=744";
break;
case DAYS:
requestUrl = dayHistoryUrl + "?fsym=" + symbolCurrencyFrom + "&tsym=" + symbolCyrrencyTo + "&limit=365";
break;
}
return requestUrl;
}
private List<CurrencyDataChart> processHistoryResult(String response)
{
List<CurrencyDataChart> dataChart = new ArrayList<>();
@ -99,15 +106,7 @@ public class CurrencyDataRetriever {
try {
JSONObject jsonObject = new JSONObject(tab[i]);
long timestamp = Long.parseLong(jsonObject.getString("time"));
double close = Double.parseDouble(jsonObject.getString("close"));
double high = Double.parseDouble(jsonObject.getString("high"));
double low = Double.parseDouble(jsonObject.getString("low"));
double open = Double.parseDouble(jsonObject.getString("open"));
double volumeFrom = Double.parseDouble(jsonObject.getString("volumefrom"));
double volumeTo = Double.parseDouble(jsonObject.getString("volumeto"));
dataChart.add(new CurrencyDataChart(timestamp, close, high, low, open, volumeFrom, volumeTo));
dataChart.add(parseJSON(jsonObject));
} catch (JSONException e) {
Log.d(context.getResources().getString(R.string.debug_volley), "API Request error: " + e + " index: " + i);
@ -122,6 +121,19 @@ public class CurrencyDataRetriever {
return dataChart;
}
private CurrencyDataChart parseJSON(JSONObject jsonObject) throws JSONException {
long timestamp = Long.parseLong(jsonObject.getString("time"));
double close = Double.parseDouble(jsonObject.getString("close"));
double high = Double.parseDouble(jsonObject.getString("high"));
double low = Double.parseDouble(jsonObject.getString("low"));
double open = Double.parseDouble(jsonObject.getString("open"));
double volumeFrom = Double.parseDouble(jsonObject.getString("volumefrom"));
double volumeTo = Double.parseDouble(jsonObject.getString("volumeto"));
return new CurrencyDataChart(timestamp, close, high, low, open, volumeFrom, volumeTo);
}
void updateHistory(String symbolCurrencyFrom, final DataChartCallBack callBack, int timeUnit)
{
if(symbolCurrencyFrom.equals("USD"))

View File

@ -110,19 +110,16 @@ public class DatabaseManager extends SQLiteOpenHelper{
return currencyList;
}
//public HashMap<Integer, Double> getCurrencyTransactions(String symbol)
public List<Transaction> getCurrencyTransactions(String symbol)
{
String searchQuerry = "SELECT * FROM " + TABLE_MANUAL_CURRENCIES + " WHERE symbol='" + symbol.toUpperCase() + "'";
SQLiteDatabase db = this.getWritableDatabase();
Cursor resultatList = db.rawQuery(searchQuerry, null);
//HashMap<Integer, Double> transactionList = new HashMap<>();
List<Transaction> transactionList = new ArrayList<>();
while(resultatList.moveToNext())
{
//transactionList.put(resultatList.getInt(0), resultatList.getDouble(3));
transactionList.add(new Transaction(resultatList.getInt(0), resultatList.getString(1), resultatList.getDouble(3), resultatList.getLong(4)));
}

View File

@ -22,8 +22,6 @@ public class BinanceManager {
private List<Currency> balance;
public BinanceManager(){}
public BinanceManager(String publicKey, String privateKey)
{
this.publicKey = publicKey;
@ -32,7 +30,6 @@ public class BinanceManager {
public void updateBalance(BinanceCallBack callBack)
{
Map<String, AssetBalance> accountBalanceCache;
BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance(publicKey, privateKey);
BinanceApiRestClient client = factory.newRestClient();

View File

@ -36,12 +36,6 @@ public class HitBtcManager {
private List<Currency> balance;
private android.content.Context context;
public HitBtcManager(android.content.Context context)
{
this.context = context;
requestQueue = Volley.newRequestQueue(context);
}
public HitBtcManager(android.content.Context context, String publicKey, String privateKey)
{
this.context = context;
@ -53,27 +47,9 @@ public class HitBtcManager {
public void updateBalance(final HitBtcCallBack callBack)
{
JsonArrayRequest arrayRequest = new JsonArrayRequest(Request.Method.GET, hitBalanceUrl,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
if (response.length() > 0) {
parseBalance(response);
} else {
//No balance
}
callBack.onSuccess();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(context.getResources().getString(R.string.debug), "API Error : " + error);
callBack.onError(error.toString());
}
}
) {
JsonArrayRequest arrayRequest = new JsonArrayRequest(Request.Method.GET, hitBalanceUrl
, getResponseListener(callBack), getErrorResponseListener(callBack))
{
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<>();
@ -89,6 +65,31 @@ public class HitBtcManager {
requestQueue.add(arrayRequest);
}
private Response.Listener<JSONArray> getResponseListener(final HitBtcCallBack callBack)
{
return new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
if (response.length() > 0) {
parseBalance(response);
}
callBack.onSuccess();
}
};
}
private Response.ErrorListener getErrorResponseListener(final HitBtcCallBack callBack)
{
return new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(context.getResources().getString(R.string.debug), "API Error : " + error);
callBack.onError(error.toString());
}
};
}
private void parseBalance(JSONArray response)
{
balance = new ArrayList<>();

View File

@ -32,8 +32,6 @@ public class FingerprintDialogFragment extends DialogFragment{
View view = inflater.inflate(R.layout.fragment_fingerprint_scanner, container);
//getDialog().getWindow().setLayout(getResources().getDimensionPixelSize(R.dimen.fingerprint_dialog_width), getResources().getDimensionPixelSize(R.dimen.fingerprint_dialog_height));
view.findViewById(R.id.cancelButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

View File

@ -37,7 +37,6 @@ public class FingerprintHandler extends FingerprintManager.AuthenticationCallbac
@Override
public void onAuthenticationError(int errMsgId, CharSequence errString)
{
//Toast.makeText(context, "Authentification error\n" + errString, Toast.LENGTH_LONG).show();
if(dialogFragment.isVisible())
{
dialogFragment.wrongFingerprint("Error");
@ -56,7 +55,6 @@ public class FingerprintHandler extends FingerprintManager.AuthenticationCallbac
@Override
public void onAuthenticationFailed()
{
//Toast.makeText(context, "Authentification failed", Toast.LENGTH_LONG).show();
if(dialogFragment.isVisible())
{
dialogFragment.wrongFingerprint("Wrong fingerprint");
@ -75,8 +73,6 @@ public class FingerprintHandler extends FingerprintManager.AuthenticationCallbac
@Override
public void onAuthenticationHelp(int helpMsgIf, CharSequence helpString)
{
//Toast.makeText(context, "Authentification help\n" + helpString, Toast.LENGTH_LONG).show();
if(dialogFragment.isVisible())
{
dialogFragment.wrongFingerprint(helpString.toString());
@ -95,9 +91,6 @@ public class FingerprintHandler extends FingerprintManager.AuthenticationCallbac
@Override
public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result)
{
//Toast.makeText(context, "Success !", Toast.LENGTH_LONG).show();
//dialogFragment.dismiss();
dialogFragment.correctFingerprint();
new Handler().postDelayed(new Runnable() {
@Override

View File

@ -31,20 +31,25 @@ public class CurrencyAdapter extends ArrayAdapter<Currency> {
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
public View getView(int position, View convertView, ViewGroup parent)
{
Currency currency = getItem(position);
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.custom_currency_row, parent, false);
}
TextView currencyName = convertView.findViewById(R.id.currencyName);
TextView currencySymbol = convertView.findViewById(R.id.currencySymbol);
if (currencyName != null)
currencyName.setText(currency.getName());
if(currencySymbol != null)
{
currencySymbol.setText(currency.getSymbol());
}
// Now assign alternate color for rows
if (position % 2 == 0)
convertView.setBackgroundColor(context.getResources().getColor(R.color.listBackground2));
else
@ -74,7 +79,7 @@ public class CurrencyAdapter extends ArrayAdapter<Currency> {
int found = 0;
String temp = constraint.toString().toLowerCase();
while(i < tempCurrency.size() && found < 25)
while(i < tempCurrency.size() && found < 50)
{
Currency currency = tempCurrency.get(i);
if (currency.getName().toLowerCase().startsWith(temp)
@ -85,14 +90,6 @@ public class CurrencyAdapter extends ArrayAdapter<Currency> {
i++;
}
/*for (Currency currency : tempCurrency) {
if (currency.getName().toLowerCase().startsWith(temp)
|| currency.getSymbol().toLowerCase().startsWith(temp)) {
suggestions.add(currency);
}
}*/
FilterResults filterResults = new FilterResults();
filterResults.values = suggestions;
filterResults.count = suggestions.size();

View File

@ -64,25 +64,7 @@ public class HomeLayoutGenerator {
}
});
((ImageView) view.findViewById(R.id.currencyIcon))
.setImageBitmap(currency.getIcon());
((TextView) view.findViewById(R.id.currencyNameTextView))
.setText(currency.getName());
((TextView) view.findViewById(R.id.currencySymbolTextView))
.setText(context.getResources().getString(R.string.currencySymbolPlaceholder, currency.getSymbol()));
((TextView) view.findViewById(R.id.currencyOwnedTextView))
.setText(context.getResources().getString(R.string.currencyBalancePlaceholder, numberConformer(currency.getBalance()), currency.getSymbol()));
((TextView) view.findViewById(R.id.currencyValueOwnedTextView))
.setText(context.getResources().getString(R.string.currencyDollarParenthesisPlaceholder, numberConformer(currency.getValue() * currency.getBalance())));
((TextView) view.findViewById(R.id.currencyValueTextView))
.setText(context.getResources().getString(R.string.currencyDollarPlaceholder, numberConformer(currency.getValue())));
((TextView) view.findViewById(R.id.currencyFluctuationPercentageTextView))
.setText(context.getResources().getString(R.string.currencyPercentagePlaceholder, numberConformer(currency.getDayFluctuationPercentage())));
((TextView) view.findViewById(R.id.currencyFluctuationTextView))
.setText(context.getResources().getString(R.string.currencyDollarParenthesisPlaceholder, numberConformer(currency.getDayFluctuation())));
((ImageView) view.findViewById(R.id.detailsArrow))
.getDrawable().setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN));
updateCardViewInfos(view, currency);
view.findViewById(R.id.errorTextView).setOnClickListener(new View.OnClickListener() {
@Override
@ -93,7 +75,23 @@ public class HomeLayoutGenerator {
}
});
if(currency.getHistoryMinutes() != null)
setupLineChart(view, currency);
if(isExtended)
{
extendView(currency, view);
}
else
{
collapseView(view);
}
updateColor(view, currency);
return view;
}
private void setupLineChart(View view, final Currency currency)
{
LineChart lineChart = view.findViewById(R.id.LineChartView);
@ -122,18 +120,27 @@ public class HomeLayoutGenerator {
});
}
if(isExtended)
private void updateCardViewInfos(View view, Currency currency)
{
extendView(currency, view);
}
else
{
collapseView(view);
}
((ImageView) view.findViewById(R.id.currencyIcon))
.setImageBitmap(currency.getIcon());
((TextView) view.findViewById(R.id.currencyNameTextView))
.setText(currency.getName());
((TextView) view.findViewById(R.id.currencySymbolTextView))
.setText(context.getResources().getString(R.string.currencySymbolPlaceholder, currency.getSymbol()));
((TextView) view.findViewById(R.id.currencyOwnedTextView))
.setText(context.getResources().getString(R.string.currencyBalancePlaceholder, numberConformer(currency.getBalance()), currency.getSymbol()));
((TextView) view.findViewById(R.id.currencyValueOwnedTextView))
.setText(context.getResources().getString(R.string.currencyDollarParenthesisPlaceholder, numberConformer(currency.getValue() * currency.getBalance())));
updateColor(view, currency);
return view;
((TextView) view.findViewById(R.id.currencyValueTextView))
.setText(context.getResources().getString(R.string.currencyDollarPlaceholder, numberConformer(currency.getValue())));
((TextView) view.findViewById(R.id.currencyFluctuationPercentageTextView))
.setText(context.getResources().getString(R.string.currencyPercentagePlaceholder, numberConformer(currency.getDayFluctuationPercentage())));
((TextView) view.findViewById(R.id.currencyFluctuationTextView))
.setText(context.getResources().getString(R.string.currencyDollarParenthesisPlaceholder, numberConformer(currency.getDayFluctuation())));
((ImageView) view.findViewById(R.id.detailsArrow))
.getDrawable().setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN));
}
private void collapseView(View view)
@ -241,7 +248,9 @@ public class HomeLayoutGenerator {
int r = Color.red(color);
int g = Color.green(color);
int b = Color.blue(color);
transColor = Color.argb(alpha, r, g, b);
return transColor ;
}