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 android.widget.ViewFlipper;
import com.daimajia.swipe.SwipeLayout; import com.daimajia.swipe.SwipeLayout;
import com.db.chart.tooltip.Tooltip;
import com.github.mikephil.charting.charts.BarChart; import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.charts.LineChart; import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.data.BarData; import com.github.mikephil.charting.data.BarData;
@ -45,10 +44,8 @@ import com.nauk.coinfolio.R;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Locale;
/**Create a Parcelable**/ /**Create a Parcelable**/
@ -67,6 +64,8 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
private final static int MONTH = 3; private final static int MONTH = 3;
private final static int YEAR = 4; private final static int YEAR = 4;
private List<CurrencyDataChart> dataChartList; private List<CurrencyDataChart> dataChartList;
private LineChart lineChart;
private BarChart barChart;
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() { = new BottomNavigationView.OnNavigationItemSelectedListener() {
@ -122,6 +121,8 @@ 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.chartsLayout); chartLayout = findViewById(R.id.chartsLayout);
lineChart = findViewById(R.id.chartPriceView);
barChart = findViewById(R.id.chartVolumeView);
drawTransactionList(); drawTransactionList();
@ -129,6 +130,16 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
createCharts(DAY, 1); createCharts(DAY, 1);
setupActionBar();
BottomNavigationView navigation = findViewById(R.id.navigation_details);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
hasBeenModified = false;
}
private void setupActionBar()
{
setTitle(" " + currency.getName() + " | " + currency.getBalance()); setTitle(" " + currency.getName() + " | " + currency.getBalance());
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME |
ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_USE_LOGO); 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))); 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() private void initializeButtons()
@ -185,7 +192,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
} }
} }
chartEvent((Button) v); updateCharts((Button) v);
} }
private float convertDpToPx(float dp) private float convertDpToPx(float dp)
@ -193,7 +200,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
return dp * this.getResources().getDisplayMetrics().density; 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.chartPriceView).setVisibility(View.GONE);
findViewById(R.id.chartVolumeView).setVisibility(View.GONE); findViewById(R.id.chartVolumeView).setVisibility(View.GONE);
@ -344,8 +351,16 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
private void drawVolumeChart() 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.setDrawGridBackground(false);
barChart.setDrawBorders(false); barChart.setDrawBorders(false);
barChart.setDrawMarkers(true); barChart.setDrawMarkers(true);
@ -360,18 +375,42 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
barChart.getXAxis().setEnabled(false); barChart.getXAxis().setEnabled(false);
barChart.setViewPortOffsets(0, 0, 0, 0); barChart.setViewPortOffsets(0, 0, 0, 0);
barChart.setFitBars(true); barChart.setFitBars(true);
barChart.setData(generateVolumeChartSet());
barChart.invalidate();
findViewById(R.id.chartVolumeView).setVisibility(View.VISIBLE);
} }
private void drawPriceChart() private void drawPriceChart()
{ {
final LineChart lineChart = findViewById(R.id.chartPriceView); initializeLineChart(lineChart);
final BarChart barChart = findViewById(R.id.chartVolumeView);
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.setDrawGridBackground(false);
lineChart.setDrawBorders(false); lineChart.setDrawBorders(false);
lineChart.setDrawMarkers(true); lineChart.setDrawMarkers(true);
@ -385,61 +424,57 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
lineChart.getLegend().setEnabled(false); lineChart.getLegend().setEnabled(false);
lineChart.getXAxis().setEnabled(false); lineChart.getXAxis().setEnabled(false);
lineChart.setViewPortOffsets(0, 0, 0, 0); lineChart.setViewPortOffsets(0, 0, 0, 0);
}
lineChart.setData(generatePriceChartSet()); private void valueSelectedEvent(Entry e)
lineChart.getAxisLeft().setAxisMinValue(lineChart.getData().getYMin()); {
//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);
lineChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() { if(dataChartList.size() > 200)
@Override {
public void onValueSelected(Entry e, Highlight h) { date = getDate(dataChartList.get((int) Math.floor(dataChartList.size() / 200) * index).getTimestamp() * 1000);
//updateFluctuation(lineChart.getData().getDataSets().get(0).getEntryForIndex(0).getY(), e.getY()); }
int index = lineChart.getData().getDataSets().get(0).getEntryIndex(e); else
String date = null; {
barChart.highlightValue(barChart.getData().getDataSets().get(0).getEntryForIndex(index).getX(), 0, index); date = getDate(dataChartList.get(index).getTimestamp() * 1000);
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) displayDataIndicators();
{
date = getDate(dataChartList.get((int) Math.floor(dataChartList.size() / 200) * index).getTimestamp() * 1000);
}
else
{
date = getDate(dataChartList.get(index).getTimestamp() * 1000);
}
((TextView) findViewById(R.id.volumeHightlight)).setText("Volume : US$" + barChart.getData().getDataSets().get(0).getEntryForIndex(index).getY()); ((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.priceHightlight)).setText("Price : US$" + e.getY());
((TextView) findViewById(R.id.timestampHightlight)).setText("Date : " + date); ((TextView) findViewById(R.id.timestampHightlight)).setText("Date : " + date);
}
@Override }
public void onNothingSelected() {
} 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();
}
lineChart.setOnTouchListener(new View.OnTouchListener() { return false;
@Override }
public boolean onTouch(View view, 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);
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()); private void displayDataIndicators()
{
findViewById(R.id.volumeHightlight).setVisibility(View.VISIBLE);
findViewById(R.id.priceHightlight).setVisibility(View.VISIBLE);
findViewById(R.id.timestampHightlight).setVisibility(View.VISIBLE);
}
findViewById(R.id.chartPriceView).setVisibility(View.VISIBLE); private void hideDataIndicators()
findViewById(R.id.progressLayoutChart).setVisibility(View.GONE); {
findViewById(R.id.volumeHightlight).setVisibility(View.INVISIBLE);
findViewById(R.id.priceHightlight).setVisibility(View.INVISIBLE);
findViewById(R.id.timestampHightlight).setVisibility(View.INVISIBLE);
} }
private String getDate(long timeStamp){ private String getDate(long timeStamp){
@ -514,7 +549,6 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
Drawable fillDrawable = ContextCompat.getDrawable(this, R.drawable.linear_chart_gradient); Drawable fillDrawable = ContextCompat.getDrawable(this, R.drawable.linear_chart_gradient);
fillDrawable.setColorFilter(getColorWithAlpha(currency.getChartColor(), 0.5f), PorterDuff.Mode.SRC_ATOP); fillDrawable.setColorFilter(getColorWithAlpha(currency.getChartColor(), 0.5f), PorterDuff.Mode.SRC_ATOP);
//dataSet.setFillDrawable(fillDrawable);
return new LineData(dataSet); return new LineData(dataSet);
} }
@ -582,49 +616,53 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
amountTxtView.setText(transactionList.get(i).getAmount() + ""); amountTxtView.setText(transactionList.get(i).getAmount() + "");
SwipeLayout swipeLayout = view.findViewById(R.id.swipeLayout); setupSwipeView(view);
//set show mode.
swipeLayout.setShowMode(SwipeLayout.ShowMode.LayDown);
//add drag edge.(If the BottomView has 'layout_gravity' attribute, this line is unnecessary)
swipeLayout.addDrag(SwipeLayout.DragEdge.Left, view.findViewById(R.id.bottom_wrapper));
swipeLayout.addSwipeListener(new SwipeLayout.SwipeListener() {
@Override
public void onClose(SwipeLayout layout) {
//when the SurfaceView totally cover the BottomView.
}
@Override
public void onUpdate(SwipeLayout layout, int leftOffset, int topOffset) {
//you are swiping.
}
@Override
public void onStartOpen(SwipeLayout layout) {
}
@Override
public void onOpen(SwipeLayout layout) {
//when the BottomView totally show.
}
@Override
public void onStartClose(SwipeLayout layout) {
}
@Override
public void onHandRelease(SwipeLayout layout, float xvel, float yvel) {
//when user's hand released.
}
});
transactionLayout.addView(view); transactionLayout.addView(view);
} }
}
private void setupSwipeView(View view)
{
SwipeLayout swipeLayout = view.findViewById(R.id.swipeLayout);
//set show mode.
swipeLayout.setShowMode(SwipeLayout.ShowMode.LayDown);
//add drag edge.(If the BottomView has 'layout_gravity' attribute, this line is unnecessary)
swipeLayout.addDrag(SwipeLayout.DragEdge.Left, view.findViewById(R.id.bottom_wrapper));
swipeLayout.addSwipeListener(new SwipeLayout.SwipeListener() {
@Override
public void onClose(SwipeLayout layout) {
//when the SurfaceView totally cover the BottomView.
}
@Override
public void onUpdate(SwipeLayout layout, int leftOffset, int topOffset) {
//you are swiping.
}
@Override
public void onStartOpen(SwipeLayout layout) {
}
@Override
public void onOpen(SwipeLayout layout) {
//when the BottomView totally show.
}
@Override
public void onStartClose(SwipeLayout layout) {
}
@Override
public void onHandRelease(SwipeLayout layout, float xvel, float yvel) {
//when user's hand released.
}
});
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -9,13 +9,13 @@ import android.os.Parcelable;
public class CurrencyDataChart implements Parcelable { public class CurrencyDataChart implements Parcelable {
long timestamp; private long timestamp;
double close; private double close;
double high; private double high;
double low; private double low;
double open; private double open;
double volumeFrom; private double volumeFrom;
double volumeTo; private double volumeTo;
public CurrencyDataChart(long timestamp, double close, double high, double low, double open, double volumeFrom, 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) private void updateHistory(final String symbolCurrencyFrom, String symbolCyrrencyTo, final DataChartCallBack callBack, int timeUnit)
{ {
String requestUrl = null; String requestUrl = getRequestUrl(timeUnit, symbolCurrencyFrom, symbolCyrrencyTo);
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;
}
StringRequest stringRequest = new StringRequest(Request.Method.GET, requestUrl, StringRequest stringRequest = new StringRequest(Request.Method.GET, requestUrl,
new Response.Listener<String>() { new Response.Listener<String>() {
@ -76,6 +63,26 @@ public class CurrencyDataRetriever {
requestQueue.add(stringRequest); 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) private List<CurrencyDataChart> processHistoryResult(String response)
{ {
List<CurrencyDataChart> dataChart = new ArrayList<>(); List<CurrencyDataChart> dataChart = new ArrayList<>();
@ -99,15 +106,7 @@ public class CurrencyDataRetriever {
try { try {
JSONObject jsonObject = new JSONObject(tab[i]); JSONObject jsonObject = new JSONObject(tab[i]);
long timestamp = Long.parseLong(jsonObject.getString("time")); dataChart.add(parseJSON(jsonObject));
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));
} catch (JSONException e) { } catch (JSONException e) {
Log.d(context.getResources().getString(R.string.debug_volley), "API Request error: " + e + " index: " + i); Log.d(context.getResources().getString(R.string.debug_volley), "API Request error: " + e + " index: " + i);
@ -122,6 +121,19 @@ public class CurrencyDataRetriever {
return dataChart; 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) void updateHistory(String symbolCurrencyFrom, final DataChartCallBack callBack, int timeUnit)
{ {
if(symbolCurrencyFrom.equals("USD")) if(symbolCurrencyFrom.equals("USD"))

View File

@ -110,19 +110,16 @@ public class DatabaseManager extends SQLiteOpenHelper{
return currencyList; return currencyList;
} }
//public HashMap<Integer, Double> getCurrencyTransactions(String symbol)
public List<Transaction> getCurrencyTransactions(String symbol) public List<Transaction> getCurrencyTransactions(String symbol)
{ {
String searchQuerry = "SELECT * FROM " + TABLE_MANUAL_CURRENCIES + " WHERE symbol='" + symbol.toUpperCase() + "'"; String searchQuerry = "SELECT * FROM " + TABLE_MANUAL_CURRENCIES + " WHERE symbol='" + symbol.toUpperCase() + "'";
SQLiteDatabase db = this.getWritableDatabase(); SQLiteDatabase db = this.getWritableDatabase();
Cursor resultatList = db.rawQuery(searchQuerry, null); Cursor resultatList = db.rawQuery(searchQuerry, null);
//HashMap<Integer, Double> transactionList = new HashMap<>();
List<Transaction> transactionList = new ArrayList<>(); List<Transaction> transactionList = new ArrayList<>();
while(resultatList.moveToNext()) 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))); 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; private List<Currency> balance;
public BinanceManager(){}
public BinanceManager(String publicKey, String privateKey) public BinanceManager(String publicKey, String privateKey)
{ {
this.publicKey = publicKey; this.publicKey = publicKey;
@ -32,7 +30,6 @@ public class BinanceManager {
public void updateBalance(BinanceCallBack callBack) public void updateBalance(BinanceCallBack callBack)
{ {
Map<String, AssetBalance> accountBalanceCache;
BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance(publicKey, privateKey); BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance(publicKey, privateKey);
BinanceApiRestClient client = factory.newRestClient(); BinanceApiRestClient client = factory.newRestClient();

View File

@ -36,12 +36,6 @@ public class HitBtcManager {
private List<Currency> balance; private List<Currency> balance;
private android.content.Context context; 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) public HitBtcManager(android.content.Context context, String publicKey, String privateKey)
{ {
this.context = context; this.context = context;
@ -53,27 +47,9 @@ public class HitBtcManager {
public void updateBalance(final HitBtcCallBack callBack) public void updateBalance(final HitBtcCallBack callBack)
{ {
JsonArrayRequest arrayRequest = new JsonArrayRequest(Request.Method.GET, hitBalanceUrl, JsonArrayRequest arrayRequest = new JsonArrayRequest(Request.Method.GET, hitBalanceUrl
new Response.Listener<JSONArray>() { , getResponseListener(callBack), getErrorResponseListener(callBack))
@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());
}
}
) {
@Override @Override
public Map<String, String> getHeaders() throws AuthFailureError { public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<>(); Map<String, String> headers = new HashMap<>();
@ -89,6 +65,31 @@ public class HitBtcManager {
requestQueue.add(arrayRequest); 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) private void parseBalance(JSONArray response)
{ {
balance = new ArrayList<>(); balance = new ArrayList<>();

View File

@ -32,8 +32,6 @@ public class FingerprintDialogFragment extends DialogFragment{
View view = inflater.inflate(R.layout.fragment_fingerprint_scanner, container); 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() { view.findViewById(R.id.cancelButton).setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {

View File

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

View File

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

View File

@ -64,6 +64,64 @@ public class HomeLayoutGenerator {
} }
}); });
updateCardViewInfos(view, currency);
view.findViewById(R.id.errorTextView).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context.getApplicationContext(), CurrencyDetailsActivity.class);
intent.putExtra("currency", currency);
context.getApplicationContext().startActivity(intent);
}
});
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);
lineChart.setDrawGridBackground(false);
lineChart.setDrawBorders(false);
lineChart.setDrawMarkers(false);
lineChart.setDoubleTapToZoomEnabled(false);
lineChart.setPinchZoom(false);
lineChart.setScaleEnabled(false);
lineChart.setDragEnabled(false);
lineChart.getDescription().setEnabled(false);
lineChart.getAxisLeft().setEnabled(false);
lineChart.getAxisRight().setEnabled(false);
lineChart.getLegend().setEnabled(false);
lineChart.getXAxis().setEnabled(false);
lineChart.setViewPortOffsets(0, 0, 0, 0);
lineChart.setData(generateData(currency));
lineChart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context.getApplicationContext(), CurrencyDetailsActivity.class);
intent.putExtra("currency", currency);
context.getApplicationContext().startActivity(intent);
}
});
}
private void updateCardViewInfos(View view, Currency currency)
{
((ImageView) view.findViewById(R.id.currencyIcon)) ((ImageView) view.findViewById(R.id.currencyIcon))
.setImageBitmap(currency.getIcon()); .setImageBitmap(currency.getIcon());
((TextView) view.findViewById(R.id.currencyNameTextView)) ((TextView) view.findViewById(R.id.currencyNameTextView))
@ -83,57 +141,6 @@ public class HomeLayoutGenerator {
.setText(context.getResources().getString(R.string.currencyDollarParenthesisPlaceholder, numberConformer(currency.getDayFluctuation()))); .setText(context.getResources().getString(R.string.currencyDollarParenthesisPlaceholder, numberConformer(currency.getDayFluctuation())));
((ImageView) view.findViewById(R.id.detailsArrow)) ((ImageView) view.findViewById(R.id.detailsArrow))
.getDrawable().setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN)); .getDrawable().setColorFilter(new PorterDuffColorFilter(currency.getChartColor(), PorterDuff.Mode.SRC_IN));
view.findViewById(R.id.errorTextView).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context.getApplicationContext(), CurrencyDetailsActivity.class);
intent.putExtra("currency", currency);
context.getApplicationContext().startActivity(intent);
}
});
if(currency.getHistoryMinutes() != null)
{
LineChart lineChart = view.findViewById(R.id.LineChartView);
lineChart.setDrawGridBackground(false);
lineChart.setDrawBorders(false);
lineChart.setDrawMarkers(false);
lineChart.setDoubleTapToZoomEnabled(false);
lineChart.setPinchZoom(false);
lineChart.setScaleEnabled(false);
lineChart.setDragEnabled(false);
lineChart.getDescription().setEnabled(false);
lineChart.getAxisLeft().setEnabled(false);
lineChart.getAxisRight().setEnabled(false);
lineChart.getLegend().setEnabled(false);
lineChart.getXAxis().setEnabled(false);
lineChart.setViewPortOffsets(0, 0, 0, 0);
lineChart.setData(generateData(currency));
lineChart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context.getApplicationContext(), CurrencyDetailsActivity.class);
intent.putExtra("currency", currency);
context.getApplicationContext().startActivity(intent);
}
});
}
if(isExtended)
{
extendView(currency, view);
}
else
{
collapseView(view);
}
updateColor(view, currency);
return view;
} }
private void collapseView(View view) private void collapseView(View view)
@ -241,7 +248,9 @@ public class HomeLayoutGenerator {
int r = Color.red(color); int r = Color.red(color);
int g = Color.green(color); int g = Color.green(color);
int b = Color.blue(color); int b = Color.blue(color);
transColor = Color.argb(alpha, r, g, b); transColor = Color.argb(alpha, r, g, b);
return transColor ; return transColor ;
} }