Several improvements

- Add time/date pickers
- Add time for manual transactions recording
- Add time for manual transactions listing
- Add volume hightlight with price highlight
- Cleaning up of CurrencyDetailsActivity code
This commit is contained in:
Tanguy Herbron 2018-04-04 01:16:10 +02:00
parent 0cc6da7cdd
commit c83385080c
9 changed files with 328 additions and 498 deletions

View File

@ -42,6 +42,7 @@ dependencies {
implementation 'org.apache.commons:commons-lang3:3.6' implementation 'org.apache.commons:commons-lang3:3.6'
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3' implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
implementation 'com.mattprecious.swirl:swirl:1.1.0' implementation 'com.mattprecious.swirl:swirl:1.1.0'
implementation 'com.wdullaer:materialdatetimepicker:3.5.2'
//implementation 'com.github.lecho:hellocharts-library:1.5.8@aar' //implementation 'com.github.lecho:hellocharts-library:1.5.8@aar'
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1' androidTestImplementation 'com.android.support.test:runner:1.0.1'

View File

@ -61,14 +61,12 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
//private String symbol; //private String symbol;
private Currency currency; private Currency currency;
private boolean hasBeenModified; private boolean hasBeenModified;
private Tooltip tip;
private int indexMax;
private int indexMin;
private final static int HOUR = 0; private final static int HOUR = 0;
private final static int DAY = 1; private final static int DAY = 1;
private final static int WEEK = 2; private final static int WEEK = 2;
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 BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() { = new BottomNavigationView.OnNavigationItemSelectedListener() {
@ -103,7 +101,6 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home: case android.R.id.home:
NavUtils.navigateUpFromSameTask(this); NavUtils.navigateUpFromSameTask(this);
return true; return true;
@ -118,7 +115,6 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
Intent intent = getIntent(); Intent intent = getIntent();
//symbol = intent.getStringExtra("symbol");
currency = intent.getParcelableExtra("currency"); currency = intent.getParcelableExtra("currency");
databaseManager = new DatabaseManager(this); databaseManager = new DatabaseManager(this);
@ -131,23 +127,9 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
initializeButtons(); initializeButtons();
if(currency.getHistoryMinutes().size() > 0) createCharts(DAY, 1);
{
drawPriceChart(DAY, 1);
drawVolumeChart(DAY, 1);
}
else
{
/*TextView errorTextView = new TextView(this);
errorTextView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 750));
errorTextView.setText("Not enough data");
errorTextView.setTag("chart_layout");
errorTextView.setGravity(Gravity.CENTER);
chartLayout.addView(errorTextView, 0);*/ setTitle(" " + currency.getName() + " | " + currency.getBalance());
}
setTitle(" " + currency.getName());
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);
@ -222,16 +204,13 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
switch (interval) switch (interval)
{ {
case "1h": case "1h":
drawPriceChart(HOUR, 1); createCharts(HOUR, 1);
drawVolumeChart(HOUR, 1);
break; break;
case "3h": case "3h":
drawPriceChart(HOUR, 3); createCharts(HOUR, 3);
drawVolumeChart(HOUR, 3);
break; break;
case "1d": case "1d":
drawPriceChart(DAY, 1); createCharts(DAY, 1);
drawVolumeChart(DAY, 1);
break; break;
case "3d": case "3d":
currency.updateHistoryHours(this, new Currency.CurrencyCallBack() { currency.updateHistoryHours(this, new Currency.CurrencyCallBack() {
@ -240,8 +219,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
drawPriceChart(CurrencyDetailsActivity.DAY, 3); createCharts(CurrencyDetailsActivity.DAY, 3);
drawVolumeChart(CurrencyDetailsActivity.DAY, 3);
} }
}); });
} }
@ -254,8 +232,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
drawPriceChart(CurrencyDetailsActivity.WEEK, 1); createCharts(CurrencyDetailsActivity.WEEK, 11);
drawVolumeChart(CurrencyDetailsActivity.WEEK, 1);
} }
}); });
} }
@ -268,8 +245,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
drawPriceChart(CurrencyDetailsActivity.MONTH, 1); createCharts(CurrencyDetailsActivity.MONTH, 1);
drawVolumeChart(CurrencyDetailsActivity.MONTH, 1);
} }
}); });
} }
@ -282,8 +258,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
drawPriceChart(CurrencyDetailsActivity.MONTH, 3); createCharts(CurrencyDetailsActivity.MONTH, 3);
drawVolumeChart(CurrencyDetailsActivity.MONTH, 3);
} }
}); });
} }
@ -296,8 +271,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
drawPriceChart(CurrencyDetailsActivity.MONTH, 6); createCharts(CurrencyDetailsActivity.MONTH, 6);
drawVolumeChart(CurrencyDetailsActivity.MONTH, 6);
} }
}); });
} }
@ -310,8 +284,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
drawPriceChart(CurrencyDetailsActivity.YEAR, 1); createCharts(CurrencyDetailsActivity.YEAR, 1);
drawVolumeChart(CurrencyDetailsActivity.YEAR, 1);
} }
}); });
} }
@ -320,7 +293,56 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
} }
} }
private void drawVolumeChart(int timeUnit, int amout) private void createCharts(int timeUnit, int amount)
{
updateChartsData(timeUnit, amount);
drawPriceChart();
drawVolumeChart();
}
private void updateChartsData(int timeUnit, int amount)
{
dataChartList = new ArrayList<>();
switch (timeUnit)
{
case HOUR:
dataChartList = currency.getHistoryMinutes().subList(currency.getHistoryMinutes().size()-(60*amount), currency.getHistoryMinutes().size());
break;
case DAY:
if(amount == 1)
{
dataChartList = currency.getHistoryMinutes();
}
else
{
dataChartList = currency.getHistoryHours().subList(currency.getHistoryHours().size()-(24*amount), currency.getHistoryHours().size());
}
break;
case WEEK:
dataChartList = currency.getHistoryHours().subList(currency.getHistoryHours().size()-168, currency.getHistoryHours().size());
break;
case MONTH:
switch (amount)
{
case 1:
dataChartList = currency.getHistoryHours();
break;
case 3:
dataChartList = currency.getHistoryDays().subList(currency.getHistoryDays().size()-93, currency.getHistoryDays().size());
break;
case 6:
dataChartList = currency.getHistoryDays().subList(currency.getHistoryDays().size()-186, currency.getHistoryDays().size());
break;
}
break;
case YEAR:
dataChartList = currency.getHistoryDays();
break;
}
}
private void drawVolumeChart()
{ {
final BarChart barChart = findViewById(R.id.chartVolumeView); final BarChart barChart = findViewById(R.id.chartVolumeView);
@ -339,13 +361,13 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
barChart.setViewPortOffsets(0, 0, 0, 0); barChart.setViewPortOffsets(0, 0, 0, 0);
barChart.setFitBars(true); barChart.setFitBars(true);
barChart.setData(generateVolumeChartSet(timeUnit, amout)); barChart.setData(generateVolumeChartSet());
barChart.invalidate(); barChart.invalidate();
findViewById(R.id.chartVolumeView).setVisibility(View.VISIBLE); findViewById(R.id.chartVolumeView).setVisibility(View.VISIBLE);
} }
private void drawPriceChart(int timeUnit, int amout) private void drawPriceChart()
{ {
final LineChart lineChart = findViewById(R.id.chartPriceView); final LineChart lineChart = findViewById(R.id.chartPriceView);
final BarChart barChart = findViewById(R.id.chartVolumeView); final BarChart barChart = findViewById(R.id.chartVolumeView);
@ -364,16 +386,32 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
lineChart.getXAxis().setEnabled(false); lineChart.getXAxis().setEnabled(false);
lineChart.setViewPortOffsets(0, 0, 0, 0); lineChart.setViewPortOffsets(0, 0, 0, 0);
lineChart.setData(generatePriceChartSet(timeUnit, amout)); lineChart.setData(generatePriceChartSet());
lineChart.getAxisLeft().setAxisMinValue(lineChart.getData().getYMin()); lineChart.getAxisLeft().setAxisMinValue(lineChart.getData().getYMin());
lineChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() { lineChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
@Override @Override
public void onValueSelected(Entry e, Highlight h) { public void onValueSelected(Entry e, Highlight h) {
updateFluctuation(lineChart.getData().getDataSets().get(0).getEntryForIndex(0).getY(), e.getY()); //updateFluctuation(lineChart.getData().getDataSets().get(0).getEntryForIndex(0).getY(), e.getY());
int index = lineChart.getData().getDataSets().get(0).getEntryIndex(e); int index = lineChart.getData().getDataSets().get(0).getEntryIndex(e);
String date = null;
barChart.highlightValue(barChart.getData().getDataSets().get(0).getEntryForIndex(index).getX(), 0, index); barChart.highlightValue(barChart.getData().getDataSets().get(0).getEntryForIndex(index).getX(), 0, index);
//((TextView) findViewById(R.id.timestampHightlight)).setText(getDate()); 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)
{
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.priceHightlight)).setText("Price : US$" + e.getY());
((TextView) findViewById(R.id.timestampHightlight)).setText("Date : " + date);
} }
@Override @Override
@ -390,6 +428,9 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
lineChart.highlightValue(null); 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()); 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); 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; return false;
} }
@ -404,7 +445,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
private String getDate(long timeStamp){ private String getDate(long timeStamp){
try{ try{
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); SimpleDateFormat sdf = new SimpleDateFormat(" HH:mm dd/MM/yyyy");
Date netDate = (new Date(timeStamp)); Date netDate = (new Date(timeStamp));
return sdf.format(netDate); return sdf.format(netDate);
} }
@ -413,49 +454,11 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
} }
} }
private BarData generateVolumeChartSet(int timeUnit, int amount) private BarData generateVolumeChartSet()
{ {
BarDataSet dataSet; BarDataSet dataSet;
List<CurrencyDataChart> dataChartList = new ArrayList<>();
ArrayList<BarEntry> values = new ArrayList<>(); ArrayList<BarEntry> values = new ArrayList<>();
switch (timeUnit)
{
case HOUR:
dataChartList = currency.getHistoryMinutes().subList(currency.getHistoryMinutes().size()-(60*amount), currency.getHistoryMinutes().size());
break;
case DAY:
if(amount == 1)
{
dataChartList = currency.getHistoryMinutes();
}
else
{
dataChartList = currency.getHistoryHours().subList(currency.getHistoryHours().size()-(24*amount), currency.getHistoryHours().size());
}
break;
case WEEK:
dataChartList = currency.getHistoryHours().subList(currency.getHistoryHours().size()-168, currency.getHistoryHours().size());
break;
case MONTH:
switch (amount)
{
case 1:
dataChartList = currency.getHistoryHours();
break;
case 3:
dataChartList = currency.getHistoryDays().subList(currency.getHistoryDays().size()-93, currency.getHistoryDays().size());
break;
case 6:
dataChartList = currency.getHistoryDays().subList(currency.getHistoryDays().size()-186, currency.getHistoryDays().size());
break;
}
break;
case YEAR:
dataChartList = currency.getHistoryDays();
break;
}
int offset = (int) Math.floor(dataChartList.size() / 200); int offset = (int) Math.floor(dataChartList.size() / 200);
if(offset < 1) if(offset < 1)
@ -465,7 +468,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
for(int i = 0, j = 0; i < dataChartList.size(); i += offset, j++) for(int i = 0, j = 0; i < dataChartList.size(); i += offset, j++)
{ {
values.add(new BarEntry(j, (float) dataChartList.get(i).getVolumeFrom())); values.add(new BarEntry(j, (float) dataChartList.get(i).getVolumeTo()));
} }
dataSet = new BarDataSet(values, "Volume"); dataSet = new BarDataSet(values, "Volume");
@ -478,77 +481,153 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
return new BarData(dataSet); return new BarData(dataSet);
} }
private LineData generatePriceChartSet(int timeUnit, int amount) private LineData generatePriceChartSet()
{ {
LineDataSet dataSet; LineDataSet dataSet;
List<CurrencyDataChart> dataChartList = new ArrayList<>();
ArrayList<Entry> values = new ArrayList<>(); ArrayList<Entry> values = new ArrayList<>();
int counter = 0; int offsetRange = (int) Math.floor(dataChartList.size() / 200);
Calendar calendar = Calendar.getInstance(Locale.FRANCE);
String hour;
String minute;
String dayName = "";
String dayNumber;
String monthName = "";
String monthNumber;
int offset = 10;
int pointFormat = HOUR;
switch (timeUnit) if(offsetRange < 1)
{ {
case HOUR: offsetRange = 1;
dataChartList = currency.getHistoryMinutes().subList(currency.getHistoryMinutes().size()-(60*amount), currency.getHistoryMinutes().size()); }
offset = 10 * amount;
pointFormat = HOUR; for(int i = 0, j = 0; i < dataChartList.size(); i += offsetRange, j++)
break;
case DAY:
if(amount == 1)
{ {
dataChartList = currency.getHistoryMinutes(); values.add(new Entry(j, (float) dataChartList.get(i).getOpen()));
offset = 10 * 24; }
pointFormat = HOUR;
dataSet = new LineDataSet(values, "History");
dataSet.setDrawIcons(false);
dataSet.setColor(currency.getChartColor());
dataSet.setLineWidth(1);
dataSet.setDrawFilled(true);
dataSet.setFillColor(getColorWithAlpha(currency.getChartColor(), 0.5f));
dataSet.setFormLineWidth(1);
dataSet.setFormSize(15);
dataSet.setDrawCircles(false);
dataSet.setDrawValues(false);
dataSet.setHighlightEnabled(true);
dataSet.setDrawHorizontalHighlightIndicator(false);
dataSet.setHighLightColor(currency.getChartColor());
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);
}
private void updateFluctuation(float start, float end)
{
float fluctuation = end - start;
float percentageFluctuation = (float) (fluctuation / start * 100);
if(percentageFluctuation < 0)
{
((TextView) findViewById(R.id.txtViewPercentage)).setTextColor(getResources().getColor(R.color.red));
} }
else else
{ {
dataChartList = currency.getHistoryHours().subList(currency.getHistoryHours().size()-(24*amount), currency.getHistoryHours().size()); ((TextView) findViewById(R.id.txtViewPercentage)).setTextColor(getResources().getColor(R.color.green));
offset = 24;
pointFormat = DAY;
}
break;
case WEEK:
dataChartList = currency.getHistoryHours().subList(currency.getHistoryHours().size()-168, currency.getHistoryHours().size());
offset = 28;
pointFormat = DAY;
break;
case MONTH:
switch (amount)
{
case 1:
dataChartList = currency.getHistoryHours();
Log.d("coinfolio", "1 month");
offset = 124;
pointFormat = MONTH;
break;
case 3:
dataChartList = currency.getHistoryDays().subList(currency.getHistoryDays().size()-93, currency.getHistoryDays().size());
offset = 15;
pointFormat = MONTH;
break;
case 6:
dataChartList = currency.getHistoryDays().subList(currency.getHistoryDays().size()-186, currency.getHistoryDays().size());
offset = 31;
pointFormat = MONTH;
break;
}
break;
case YEAR:
dataChartList = currency.getHistoryDays();
offset = 30;
pointFormat = YEAR;
break;
} }
((TextView) findViewById(R.id.txtViewPriceStart)).setText("$" + start);
((TextView) findViewById(R.id.txtViewPriceNow)).setText("$" + end);
((TextView) findViewById(R.id.txtViewPercentage)).setText(percentageFluctuation + "%");
}
private int getColorWithAlpha(int color, float ratio)
{
int transColor;
int alpha = Math.round(Color.alpha(color) * ratio);
int r = Color.red(color);
int g = Color.green(color);
int b = Color.blue(color);
transColor = Color.argb(alpha, r, g, b);
return transColor;
}
private void drawTransactionList()
{
transactionLayout.removeAllViews();
List<Transaction> transactionList = databaseManager.getCurrencyTransactions(currency.getSymbol());
for(int i = 0; i < transactionList.size(); i++)
{
View view = LayoutInflater.from(this).inflate(R.layout.custom_transaction_row, null);
TextView amountTxtView = view.findViewById(R.id.amountPurchased);
TextView valueTxtView = view.findViewById(R.id.puchasedValue);
TextView dateTxtView = view.findViewById(R.id.purchaseDate);
Log.d("coinfolio", "Timestamp " + transactionList.get(i).getTimestamp());
dateTxtView.setText(getDate(transactionList.get(i).getTimestamp()));
LinearLayout deleteLayout = view.findViewById(R.id.deleteTransactionLayout);
deleteLayout.setTag(transactionList.get(i).getTransactionId());
deleteLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
databaseManager.deleteTransactionFromId(Integer.parseInt(view.getTag().toString()));
drawTransactionList();
hasBeenModified = true;
}
});
amountTxtView.setText(transactionList.get(i).getAmount() + "");
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.
}
});
transactionLayout.addView(view);
}
}
}
/*for(int i = 0; i < dataChartList.size(); i++) /*for(int i = 0; i < dataChartList.size(); i++)
{*/ {*/
/*if(counter == offset) /*if(counter == offset)
@ -674,343 +753,3 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
}*/ }*/
/*values.add(new Entry(i, (float) dataChartList.get(i).getOpen())); /*values.add(new Entry(i, (float) dataChartList.get(i).getOpen()));
}*/ }*/
int offsetRange = (int) Math.floor(dataChartList.size() / 200);
if(offsetRange < 1)
{
offsetRange = 1;
}
for(int i = 0, j = 0; i < dataChartList.size(); i += offsetRange, j++)
{
values.add(new Entry(j, (float) dataChartList.get(i).getOpen()));
}
dataSet = new LineDataSet(values, "History");
dataSet.setDrawIcons(false);
dataSet.setColor(currency.getChartColor());
dataSet.setLineWidth(1);
dataSet.setDrawFilled(true);
dataSet.setFillColor(getColorWithAlpha(currency.getChartColor(), 0.5f));
dataSet.setFormLineWidth(1);
dataSet.setFormSize(15);
dataSet.setDrawCircles(false);
dataSet.setDrawValues(false);
dataSet.setHighlightEnabled(true);
dataSet.setDrawHorizontalHighlightIndicator(false);
dataSet.setHighLightColor(currency.getChartColor());
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);
}
private void updateFluctuation(float start, float end)
{
float fluctuation = end - start;
float percentageFluctuation = (float) (fluctuation / start * 100);
if(percentageFluctuation < 0)
{
((TextView) findViewById(R.id.txtViewPercentage)).setTextColor(getResources().getColor(R.color.red));
}
else
{
((TextView) findViewById(R.id.txtViewPercentage)).setTextColor(getResources().getColor(R.color.green));
}
((TextView) findViewById(R.id.txtViewPriceStart)).setText("$" + start);
((TextView) findViewById(R.id.txtViewPriceNow)).setText("$" + end);
((TextView) findViewById(R.id.txtViewPercentage)).setText(percentageFluctuation + "%");
}
/*private LineSet generatePriceChartSet(int timeUnit, int amount)
{
List<CurrencyDataChart> dataChartList = new ArrayList<>();
LineSet lineSet = new LineSet();
int counter = 0;
Calendar calendar = Calendar.getInstance(Locale.FRANCE);
String hour;
String minute;
String dayName = "";
String dayNumber;
String monthName = "";
String monthNumber;
int offset = 10;
int pointFormat = HOUR;
switch (timeUnit)
{
case HOUR:
dataChartList = currency.getHistoryMinutes().subList(currency.getHistoryMinutes().size()-(60*amount), currency.getHistoryMinutes().size());
offset = 10 * amount;
pointFormat = HOUR;
break;
case DAY:
if(amount == 1)
{
dataChartList = currency.getHistoryMinutes();
offset = 10 * 24;
pointFormat = HOUR;
}
else
{
dataChartList = currency.getHistoryHours().subList(currency.getHistoryHours().size()-(24*amount), currency.getHistoryHours().size());
offset = 24;
pointFormat = DAY;
}
break;
case WEEK:
dataChartList = currency.getHistoryHours().subList(currency.getHistoryHours().size()-168, currency.getHistoryHours().size());
offset = 28;
pointFormat = DAY;
break;
case MONTH:
switch (amount)
{
case 1:
dataChartList = currency.getHistoryHours();
offset = 124;
pointFormat = MONTH;
break;
case 3:
dataChartList = currency.getHistoryDays().subList(currency.getHistoryDays().size()-93, currency.getHistoryDays().size());
offset = 15;
pointFormat = MONTH;
break;
case 6:
dataChartList = currency.getHistoryDays().subList(currency.getHistoryDays().size()-186, currency.getHistoryDays().size());
offset = 31;
pointFormat = MONTH;
break;
}
break;
case YEAR:
dataChartList = currency.getHistoryDays();
offset = 30;
pointFormat = YEAR;
break;
}
for(int i = 0; i < dataChartList.size(); i++)
{
if(counter == offset)
{
calendar.setTimeInMillis(dataChartList.get(i).getTimestamp()*1000);
switch (pointFormat)
{
case HOUR:
hour = String.valueOf(calendar.get(Calendar.HOUR_OF_DAY));
minute = String.valueOf(calendar.get(Calendar.MINUTE));
if(hour.length() < 2)
{
hour = "0" + hour;
}
if(minute.length() < 2)
{
minute = "0" + minute;
}
lineSet.addPoint(hour + ":" + minute, (float) dataChartList.get(i).getOpen());
break;
case DAY:
int dayIndex = calendar.get(Calendar.DAY_OF_WEEK)+1;
switch (dayIndex)
{
case Calendar.MONDAY:
dayName = "Mon";
break;
case Calendar.TUESDAY:
dayName = "Tue";
break;
case Calendar.WEDNESDAY:
dayName = "Wed";
break;
case Calendar.THURSDAY:
dayName = "Thu";
break;
case Calendar.FRIDAY:
dayName = "Fri";
break;
case Calendar.SATURDAY:
dayName = "Sat";
break;
case Calendar.SUNDAY:
dayName = "Sun";
break;
}
lineSet.addPoint(dayName, (float) dataChartList.get(i).getOpen());
break;
case MONTH:
dayNumber = String.valueOf(calendar.get(Calendar.DAY_OF_MONTH)+1);
monthNumber = String.valueOf(calendar.get(Calendar.MONTH)+1);
if(dayNumber.length() < 2)
{
dayNumber = '0' + dayNumber;
}
if(monthNumber.length() < 2)
{
monthNumber = '0' + monthNumber;
}
lineSet.addPoint(dayNumber + "/" + monthNumber, (float) dataChartList.get(i).getOpen());
break;
case YEAR:
int mb = calendar.get(Calendar.MONTH);
switch (mb)
{
case Calendar.JANUARY:
monthName = "Jan";
break;
case Calendar.FEBRUARY:
monthName = "Feb";
break;
case Calendar.MARCH:
monthName = "Mar";
break;
case Calendar.APRIL:
monthName = "Apr";
break;
case Calendar.MAY:
monthName = "May";
break;
case Calendar.JUNE:
monthName = "Jun";
break;
case Calendar.JULY:
monthName = "Jul";
break;
case Calendar.AUGUST:
monthName = "Aug";
break;
case Calendar.SEPTEMBER:
monthName = "Sep";
break;
case Calendar.OCTOBER:
monthName = "Oct";
break;
case Calendar.NOVEMBER:
monthName = "Nov";
break;
case Calendar.DECEMBER:
monthName = "Dec";
break;
}
lineSet.addPoint(monthName, (float) dataChartList.get(i).getOpen());
break;
}
counter = 0;
}
else
{
counter++;
lineSet.addPoint("", (float) dataChartList.get(i).getOpen());
}
}
lineSet.setSmooth(true);
lineSet.setThickness(3);
lineSet.setFill(getColorWithAlpha(currency.getChartColor(), 0.5f));
lineSet.setColor(currency.getChartColor());
return lineSet;
}*/
private int getColorWithAlpha(int color, float ratio)
{
int transColor;
int alpha = Math.round(Color.alpha(color) * ratio);
int r = Color.red(color);
int g = Color.green(color);
int b = Color.blue(color);
transColor = Color.argb(alpha, r, g, b);
return transColor;
}
private void drawTransactionList()
{
transactionLayout.removeAllViews();
List<Transaction> transactionList = databaseManager.getCurrencyTransactions(currency.getSymbol());
for(int i = 0; i < transactionList.size(); i++)
{
View view = LayoutInflater.from(this).inflate(R.layout.custom_transaction_row, null);
TextView amountTxtView = view.findViewById(R.id.amountPurchased);
TextView valueTxtView = view.findViewById(R.id.puchasedValue);
TextView dateTxtView = view.findViewById(R.id.purchaseDate);
LinearLayout deleteLayout = view.findViewById(R.id.deleteTransactionLayout);
deleteLayout.setTag(transactionList.get(i).getTransactionId());
deleteLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
databaseManager.deleteTransactionFromId(Integer.parseInt(view.getTag().toString()));
drawTransactionList();
hasBeenModified = true;
}
});
amountTxtView.setText(transactionList.get(i).getAmount() + "");
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.
}
});
transactionLayout.addView(view);
}
}
}

View File

@ -398,6 +398,8 @@ public class HomeActivity extends AppCompatActivity {
Intent intent = getIntent(); Intent intent = getIntent();
Log.d("coinfolio", "Updated ? " + intent.getBooleanExtra("update", false));
updateAll(intent.getBooleanExtra("update", false)); updateAll(intent.getBooleanExtra("update", false));
((SpaceNavigationView) findViewById(R.id.space)).changeCenterButtonIcon(R.drawable.ic_view_list_white_24dp); ((SpaceNavigationView) findViewById(R.id.space)).changeCenterButtonIcon(R.drawable.ic_view_list_white_24dp);
} }

View File

@ -1,23 +1,35 @@
package com.nauk.coinfolio.Activities; package com.nauk.coinfolio.Activities;
import android.app.DatePickerDialog;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import android.widget.TimePicker;
import com.nauk.coinfolio.DataManagers.DatabaseManager; import com.nauk.coinfolio.DataManagers.DatabaseManager;
import com.nauk.coinfolio.R; import com.nauk.coinfolio.R;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class RecordTransactionActivity extends AppCompatActivity { public class RecordTransactionActivity extends AppCompatActivity {
private String coin; private String coin;
private String symbol; private String symbol;
private TextView symbolTxtView; private TextView symbolTxtView;
private TextView amountTxtView; private EditText amountTxtView;
private TextView purchasedDate;
private Button validateButton; private Button validateButton;
private DatabaseManager databaseManager; private DatabaseManager databaseManager;
private Calendar calendar;
private SimpleDateFormat sdf;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -30,16 +42,31 @@ public class RecordTransactionActivity extends AppCompatActivity {
setTitle("Add " + coin + " transaction"); setTitle("Add " + coin + " transaction");
sdf = new SimpleDateFormat(" HH:mm dd/MM/yyyy");
calendar = Calendar.getInstance();
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.setText(sdf.format(calendar.getTime()));
purchasedDate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
createDatePicker();
}
});
validateButton.setOnClickListener(new View.OnClickListener() { validateButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
databaseManager.addCurrencyToManualCurrency(symbol, Double.parseDouble(amountTxtView.getText().toString())); databaseManager.addCurrencyToManualCurrency(symbol, Double.parseDouble(amountTxtView.getText().toString()), calendar.getTime());
Intent intent = new Intent(RecordTransactionActivity.this, HomeActivity.class); Intent intent = new Intent(RecordTransactionActivity.this, HomeActivity.class);
intent.putExtra("update", true); intent.putExtra("update", true);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
@ -48,4 +75,42 @@ public class RecordTransactionActivity extends AppCompatActivity {
} }
}); });
} }
private void createDatePicker()
{
new android.app.DatePickerDialog(
RecordTransactionActivity.this,
new android.app.DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month);
calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
purchasedDate.setText(sdf.format(calendar.getTime()));
createTimePicker();
}
},
calendar.get(Calendar.YEAR),
calendar.get(Calendar.MONTH),
calendar.get(Calendar.DAY_OF_MONTH)
).show();
}
private void createTimePicker()
{
new android.app.TimePickerDialog(
RecordTransactionActivity.this,
new android.app.TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hour, int minute) {
calendar.set(Calendar.HOUR_OF_DAY, hour);
calendar.set(Calendar.MINUTE, minute);
purchasedDate.setText(sdf.format(calendar.getTime()));
}
},
calendar.get(Calendar.HOUR_OF_DAY),
calendar.get(Calendar.MINUTE),
true
).show();
}
} }

View File

@ -9,14 +9,16 @@ public class Transaction {
private int transactionId; private int transactionId;
private String symbol; private String symbol;
private double amount; private double amount;
private long timestamp;
private double purchasedPrice; private double purchasedPrice;
private boolean isMined; private boolean isMined;
public Transaction(int transactionId, String symbol, double amount) public Transaction(int transactionId, String symbol, double amount, long timestamp)
{ {
this.transactionId = transactionId; this.transactionId = transactionId;
this.symbol = symbol; this.symbol = symbol;
this.amount = amount; this.amount = amount;
this.timestamp = timestamp;
} }
public int getTransactionId() { public int getTransactionId() {
@ -39,6 +41,11 @@ public class Transaction {
return amount; return amount;
} }
public long getTimestamp()
{
return timestamp;
}
public void setAmount(double amount) { public void setAmount(double amount) {
this.amount = amount; this.amount = amount;
} }

View File

@ -10,6 +10,7 @@ import com.nauk.coinfolio.DataManagers.CurrencyData.Currency;
import com.nauk.coinfolio.DataManagers.CurrencyData.Transaction; import com.nauk.coinfolio.DataManagers.CurrencyData.Transaction;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**
@ -51,7 +52,7 @@ public class DatabaseManager extends SQLiteOpenHelper{
+ KEY_CURRENCY_SYMBOL + " VARCHAR(4)," + KEY_CURRENCY_SYMBOL + " VARCHAR(4),"
+ KEY_CURRENCY_NAME + " VARCHAR(45)," + KEY_CURRENCY_NAME + " VARCHAR(45),"
+ KEY_CURRENCY_BALANCE + " TEXT," + KEY_CURRENCY_BALANCE + " TEXT,"
+ KEY_CURRENCY_DATE + " DATE," + KEY_CURRENCY_DATE + " TEXT,"
+ KEY_CURRENCY_PURCHASED_PRICE + " TEXT," + KEY_CURRENCY_PURCHASED_PRICE + " TEXT,"
+ KEY_CURRENCY_IS_MINED + " INTEGER" + KEY_CURRENCY_IS_MINED + " INTEGER"
+ ");"); + ");");
@ -75,14 +76,14 @@ public class DatabaseManager extends SQLiteOpenHelper{
onCreate(db); onCreate(db);
} }
public void addCurrencyToManualCurrency(String symbol, double balance) public void addCurrencyToManualCurrency(String symbol, double balance, Date date)
{ {
SQLiteDatabase db = this.getWritableDatabase(); SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put(KEY_CURRENCY_SYMBOL, symbol); values.put(KEY_CURRENCY_SYMBOL, symbol);
values.put(KEY_CURRENCY_BALANCE, balance); values.put(KEY_CURRENCY_BALANCE, balance);
//values.put(KEY_CURRENCY_DATE, getDate()); values.put(KEY_CURRENCY_DATE, date.getTime());
//values.put(KEY_CURRENCY_PURCHASED_PRICE, something); //values.put(KEY_CURRENCY_PURCHASED_PRICE, something);
db.insert(TABLE_MANUAL_CURRENCIES, null, values); db.insert(TABLE_MANUAL_CURRENCIES, null, values);
@ -122,7 +123,7 @@ public class DatabaseManager extends SQLiteOpenHelper{
while(resultatList.moveToNext()) while(resultatList.moveToNext())
{ {
//transactionList.put(resultatList.getInt(0), resultatList.getDouble(3)); //transactionList.put(resultatList.getInt(0), resultatList.getDouble(3));
transactionList.add(new Transaction(resultatList.getInt(0), resultatList.getString(1), resultatList.getDouble(3))); transactionList.add(new Transaction(resultatList.getInt(0), resultatList.getString(1), resultatList.getDouble(3), resultatList.getLong(4)));
} }
resultatList.close(); resultatList.close();

View File

@ -56,6 +56,11 @@ public class BinanceManager {
} }
} }
public void getTrades()
{
}
public void setPublicKey(String publicKey) public void setPublicKey(String publicKey)
{ {
this.publicKey = publicKey; this.publicKey = publicKey;

View File

@ -22,7 +22,16 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/activity_add_amount"/> android:hint="@string/activity_add_amount"/>
<TextView
android:id="@+id/purchaseDate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/activity_purchased_date"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp" />
<EditText <EditText
android:id="@+id/purchasePrice"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/activity_purchased_price"/> android:hint="@string/activity_purchased_price"/>

View File

@ -120,6 +120,7 @@
<!--Add transaction activity--> <!--Add transaction activity-->
<string name="activity_add_amount">Amount</string> <string name="activity_add_amount">Amount</string>
<string name="activity_purchased_price">Purchased price</string> <string name="activity_purchased_price">Purchased price</string>
<string name="activity_purchased_date">Purchased date</string>
<string name="title_activity_currency_details">CurrencyDetailsActivity</string> <string name="title_activity_currency_details">CurrencyDetailsActivity</string>
<string name="title_history">History charts</string> <string name="title_history">History charts</string>
<string name="title_watchlist">Watchlist</string> <string name="title_watchlist">Watchlist</string>