From d2aaec536d9492fb5bbaacf64303722b3322cb15 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Wed, 9 May 2018 04:11:53 +0200 Subject: [PATCH] Add volume chart highlight synchronization | fix transactions order --- .../Activities/CurrencyDetailsActivity.java | 44 ++++++++++++++++--- .../moodl/DataManagers/DatabaseManager.java | 7 +-- 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/nauk/moodl/Activities/CurrencyDetailsActivity.java b/app/src/main/java/com/nauk/moodl/Activities/CurrencyDetailsActivity.java index c5f3185..a39b859 100644 --- a/app/src/main/java/com/nauk/moodl/Activities/CurrencyDetailsActivity.java +++ b/app/src/main/java/com/nauk/moodl/Activities/CurrencyDetailsActivity.java @@ -621,6 +621,26 @@ public class CurrencyDetailsActivity extends AppCompatActivity { barChart.getXAxis().setEnabled(false); barChart.setViewPortOffsets(0, 0, 0, 0); barChart.setFitBars(true); + barChart.setHighlightFullBarEnabled(true); + + barChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() { + @Override + public void onValueSelected(Entry e, Highlight h) { + barChartValueSelected(e); + } + + @Override + public void onNothingSelected() { + + } + }); + + barChart.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View view, MotionEvent motionEvent) { + return toucheEvent(motionEvent); + } + }); } private void drawPriceCandleStickChart() @@ -636,7 +656,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { lineChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() { @Override public void onValueSelected(Entry e, Highlight h) { - valueSelectedEvent(e); + lineChartValueSelected(e); } @Override @@ -683,16 +703,29 @@ public class CurrencyDetailsActivity extends AppCompatActivity { lineChart.setViewPortOffsets(0, 0, 0, 0); } - private void valueSelectedEvent(Entry e) + private void barChartValueSelected(Entry e) + { + int index = barChart.getData().getDataSets().get(0).getEntryIndex((BarEntry) e); + + lineChart.highlightValue(lineChart.getData().getDataSets().get(0).getEntryForIndex(index).getX(), lineChart.getData().getDataSets().get(0).getEntryForIndex(index).getY(), 0); + generatePlaceHoldersFromIndex(index); + } + + private void lineChartValueSelected(Entry e) { int index = lineChart.getData().getDataSets().get(0).getEntryIndex(e); + + barChart.highlightValue(barChart.getData().getDataSets().get(0).getEntryForIndex(index).getX(), 0, index); + generatePlaceHoldersFromIndex(index); + } + + private void generatePlaceHoldersFromIndex(int index) + { String date; String volumePlaceholder; String pricePlaceholder; String timestampPlaceholder; - barChart.highlightValue(barChart.getData().getDataSets().get(0).getEntryForIndex(index).getX(), 0, index); - if(dataChartList.size() > 200) { date = getDateFromTimestamp(dataChartList.get((int) Math.floor(dataChartList.size() / 200) * index).getTimestamp() * 1000); @@ -703,7 +736,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity { } volumePlaceholder = PlaceholderManager.getVolumeString(numberConformer(barChart.getData().getDataSets().get(0).getEntryForIndex(index).getY()), this); - pricePlaceholder = PlaceholderManager.getPriceString(numberConformer(e.getY()), this); + pricePlaceholder = PlaceholderManager.getPriceString(numberConformer((lineChart.getHighlighted())[0].getY()), this); timestampPlaceholder = PlaceholderManager.getTimestampString(date, this); ((TextView) findViewById(R.id.volumeHightlight)).setText(volumePlaceholder); @@ -712,7 +745,6 @@ public class CurrencyDetailsActivity extends AppCompatActivity { findViewById(R.id.priceHightlight).setVisibility(View.VISIBLE); ((TextView) findViewById(R.id.timestampHightlight)).setText(timestampPlaceholder); findViewById(R.id.timestampHightlight).setVisibility(View.VISIBLE); - } private boolean toucheEvent(MotionEvent motionEvent) diff --git a/app/src/main/java/com/nauk/moodl/DataManagers/DatabaseManager.java b/app/src/main/java/com/nauk/moodl/DataManagers/DatabaseManager.java index 43a70ee..ecea0bd 100644 --- a/app/src/main/java/com/nauk/moodl/DataManagers/DatabaseManager.java +++ b/app/src/main/java/com/nauk/moodl/DataManagers/DatabaseManager.java @@ -204,10 +204,11 @@ public class DatabaseManager extends SQLiteOpenHelper{ ArrayList transactionList = new ArrayList<>(); - while(resultatList.moveToNext()) - { + resultatList.moveToLast(); + + do { transactionList.add(new Transaction(resultatList.getInt(0), resultatList.getString(1), resultatList.getDouble(3), resultatList.getLong(4), resultatList.getLong(5), resultatList.getDouble(7))); - } + } while(resultatList.moveToPrevious()); resultatList.close();