Synchronize cursor for detail activity
This commit is contained in:
parent
9ff13165c6
commit
0cc6da7cdd
@ -5,7 +5,9 @@ import android.graphics.Bitmap;
|
|||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
|
import android.graphics.PorterDuff;
|
||||||
import android.graphics.drawable.BitmapDrawable;
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.design.widget.BottomNavigationView;
|
import android.support.design.widget.BottomNavigationView;
|
||||||
@ -41,8 +43,10 @@ import com.nauk.coinfolio.DataManagers.CurrencyData.Transaction;
|
|||||||
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.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
@ -344,6 +348,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
|
|||||||
private void drawPriceChart(int timeUnit, int amout)
|
private void drawPriceChart(int timeUnit, int amout)
|
||||||
{
|
{
|
||||||
final LineChart lineChart = findViewById(R.id.chartPriceView);
|
final LineChart lineChart = findViewById(R.id.chartPriceView);
|
||||||
|
final BarChart barChart = findViewById(R.id.chartVolumeView);
|
||||||
|
|
||||||
lineChart.setDrawGridBackground(false);
|
lineChart.setDrawGridBackground(false);
|
||||||
lineChart.setDrawBorders(false);
|
lineChart.setDrawBorders(false);
|
||||||
@ -366,6 +371,9 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
|
|||||||
@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);
|
||||||
|
barChart.highlightValue(barChart.getData().getDataSets().get(0).getEntryForIndex(index).getX(), 0, index);
|
||||||
|
//((TextView) findViewById(R.id.timestampHightlight)).setText(getDate());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -379,10 +387,9 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
|
|||||||
public boolean onTouch(View view, MotionEvent motionEvent) {
|
public boolean onTouch(View view, MotionEvent motionEvent) {
|
||||||
if(motionEvent.getAction() == MotionEvent.ACTION_UP)
|
if(motionEvent.getAction() == MotionEvent.ACTION_UP)
|
||||||
{
|
{
|
||||||
//lineChart.highlightValue(lineChart.getData().getDataSetCount()-1, 0);
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -394,6 +401,18 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
|
|||||||
findViewById(R.id.progressLayoutChart).setVisibility(View.GONE);
|
findViewById(R.id.progressLayoutChart).setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getDate(long timeStamp){
|
||||||
|
|
||||||
|
try{
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
|
||||||
|
Date netDate = (new Date(timeStamp));
|
||||||
|
return sdf.format(netDate);
|
||||||
|
}
|
||||||
|
catch(Exception ex){
|
||||||
|
return "xx";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private BarData generateVolumeChartSet(int timeUnit, int amount)
|
private BarData generateVolumeChartSet(int timeUnit, int amount)
|
||||||
{
|
{
|
||||||
BarDataSet dataSet;
|
BarDataSet dataSet;
|
||||||
@ -437,13 +456,16 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
int offset = (int) Math.floor(dataChartList.size() / 50);
|
int offset = (int) Math.floor(dataChartList.size() / 200);
|
||||||
|
|
||||||
int loopNumber = 0;
|
if(offset < 1)
|
||||||
for(int i = 0; i < dataChartList.size(); i += offset)
|
|
||||||
{
|
{
|
||||||
values.add(new BarEntry(loopNumber, (float) dataChartList.get(i).getVolumeTo()));
|
offset = 1;
|
||||||
loopNumber++;
|
}
|
||||||
|
|
||||||
|
for(int i = 0, j = 0; i < dataChartList.size(); i += offset, j++)
|
||||||
|
{
|
||||||
|
values.add(new BarEntry(j, (float) dataChartList.get(i).getVolumeFrom()));
|
||||||
}
|
}
|
||||||
|
|
||||||
dataSet = new BarDataSet(values, "Volume");
|
dataSet = new BarDataSet(values, "Volume");
|
||||||
@ -527,8 +549,8 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < dataChartList.size(); i++)
|
/*for(int i = 0; i < dataChartList.size(); i++)
|
||||||
{
|
{*/
|
||||||
/*if(counter == offset)
|
/*if(counter == offset)
|
||||||
{
|
{
|
||||||
calendar.setTimeInMillis(dataChartList.get(i).getTimestamp()*1000);
|
calendar.setTimeInMillis(dataChartList.get(i).getTimestamp()*1000);
|
||||||
@ -650,7 +672,19 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
|
|||||||
counter++;
|
counter++;
|
||||||
lineSet.addPoint("", (float) dataChartList.get(i).getOpen());
|
lineSet.addPoint("", (float) dataChartList.get(i).getOpen());
|
||||||
}*/
|
}*/
|
||||||
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 = new LineDataSet(values, "History");
|
||||||
@ -667,6 +701,10 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
|
|||||||
dataSet.setDrawHorizontalHighlightIndicator(false);
|
dataSet.setDrawHorizontalHighlightIndicator(false);
|
||||||
dataSet.setHighLightColor(currency.getChartColor());
|
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);
|
return new LineData(dataSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,6 +43,11 @@ public class CurrencyDataChart implements Parcelable {
|
|||||||
return volumeTo;
|
return volumeTo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public double getVolumeFrom()
|
||||||
|
{
|
||||||
|
return volumeFrom;
|
||||||
|
}
|
||||||
|
|
||||||
public long getTimestamp()
|
public long getTimestamp()
|
||||||
{
|
{
|
||||||
return timestamp;
|
return timestamp;
|
||||||
|
10
app/src/main/res/drawable/linear_chart_gradient.xml
Normal file
10
app/src/main/res/drawable/linear_chart_gradient.xml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<gradient
|
||||||
|
android:angle="90"
|
||||||
|
android:type="linear"
|
||||||
|
android:startColor="#00ff0000"
|
||||||
|
android:centerColor="#00ff0000"
|
||||||
|
android:endColor="#ffffffff"
|
||||||
|
android:centerY="1%" />
|
||||||
|
</shape>
|
@ -42,6 +42,34 @@
|
|||||||
android:layout_height="250dp"
|
android:layout_height="250dp"
|
||||||
android:layout_marginTop="15dp" />
|
android:layout_marginTop="15dp" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/timestampHightlight"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:visibility="invisible"
|
||||||
|
android:layout_weight="0.33"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/priceHightlight"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:visibility="invisible"
|
||||||
|
android:layout_weight="0.33" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/volumeHightlight"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:visibility="invisible"
|
||||||
|
android:layout_weight="0.33"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<com.github.mikephil.charting.charts.BarChart
|
<com.github.mikephil.charting.charts.BarChart
|
||||||
android:id="@+id/chartVolumeView"
|
android:id="@+id/chartVolumeView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -81,8 +81,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical">
|
||||||
android:gravity="center_vertical">
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/marketCapTextView"
|
android:id="@+id/marketCapTextView"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user