Details switch, first lines

This commit is contained in:
Tanguy Herbron 2018-03-16 00:20:54 +01:00
parent da984671f8
commit d6189731f8
3 changed files with 277 additions and 15 deletions

View File

@ -2,7 +2,6 @@ package com.nauk.coinfolio.Activities;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
@ -19,26 +18,24 @@ import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.ViewFlipper;
import com.daimajia.swipe.SwipeLayout;
import com.db.chart.animation.Animation;
import com.db.chart.model.LineSet;
import com.db.chart.renderer.AxisRenderer;
import com.db.chart.tooltip.Tooltip;
import com.db.chart.view.LineChartView;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.nauk.coinfolio.DataManagers.CurrencyData.Currency;
import com.nauk.coinfolio.DataManagers.CurrencyData.CurrencyDataChart;
import com.nauk.coinfolio.DataManagers.CurrencyData.Transaction;
import com.nauk.coinfolio.DataManagers.DatabaseManager;
import com.nauk.coinfolio.R;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
@ -296,7 +293,245 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
}
}
private void drawChart(int timeUnit, int amount)
private void drawChart(int timeUnit, int amout)
{
LineChart lineChart = findViewById(R.id.chartView);
lineChart.setDrawGridBackground(false);
lineChart.setDrawBorders(false);
lineChart.setDrawMarkers(false);
lineChart.setDoubleTapToZoomEnabled(true);
lineChart.setPinchZoom(true);
lineChart.setScaleEnabled(false);
lineChart.setDragEnabled(true);
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(generateChartSet(timeUnit, amout));
updateFluctuation(lineChart.getData());
findViewById(R.id.chartView).setVisibility(View.VISIBLE);
findViewById(R.id.progressLayoutChart).setVisibility(View.GONE);
}
private LineData generateChartSet(int timeUnit, int amount)
{
LineDataSet dataSet;
List<CurrencyDataChart> dataChartList = new ArrayList<>();
ArrayList<Entry> values = new ArrayList<>();
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());
}*/
values.add(new Entry(i, (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(false);
return new LineData(dataSet);
}
/*private void drawChart(int timeUnit, int amount)
{
final LineChartView chartView = findViewById(R.id.chartView);
LineSet lineSet = generateChartSet(timeUnit, amount);
@ -338,7 +573,7 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
//chartView.show(new Animation().fromAlpha(0).withEndAction(launchAction));
chartView.show(new Animation().fromAlpha(0));
}
}*/
private void updateFluctuation(LineSet lineSet)
{
@ -365,7 +600,34 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
((TextView) findViewById(R.id.txtViewPercentage)).setText(percentageFluctuation + "%");
}
private LineSet generateChartSet(int timeUnit, int amount)
private void updateFluctuation(LineData lineData)
{
//float fluctuation = lineSet.getEntry(lineSet.size() - 1).getValue() - lineSet.getEntry(0).getValue();
float fluctuation = lineData.getDataSetByIndex(lineData.getDataSetCount() - 1).getEntryCount();
//float percentageFluctuation = (float) (fluctuation / lineSet.getEntry(0).getValue() * 100);
ArrayList<Entry> values = new ArrayList<Entry>(lineData.);
/*dayFluctuation = historyMinutes.get(historyMinutes.size() - 1).getOpen() - historyMinutes.get(0).getOpen();
dayFluctuationPercentage = (float) (dayFluctuation / historyMinutes.get(0).getOpen() * 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("$" + lineSet.getEntry(0).getValue());
((TextView) findViewById(R.id.txtViewPriceNow)).setText("$" + lineSet.getEntry(lineSet.size() - 1).getValue());
((TextView) findViewById(R.id.txtViewPercentage)).setText(percentageFluctuation + "%");*/
}
/*private LineSet generateChartSet(int timeUnit, int amount)
{
List<CurrencyDataChart> dataChartList = new ArrayList<>();
LineSet lineSet = new LineSet();
@ -560,13 +822,13 @@ public class CurrencyDetailsActivity extends AppCompatActivity {
lineSet.setSmooth(true);
lineSet.setThickness(3);
lineSet.setFill(getColorWitchAlpha(currency.getChartColor(), 0.5f));
lineSet.setFill(getColorWithAlpha(currency.getChartColor(), 0.5f));
lineSet.setColor(currency.getChartColor());
return lineSet;
}
}*/
private int getColorWitchAlpha(int color, float ratio)
private int getColorWithAlpha(int color, float ratio)
{
int transColor;
int alpha = Math.round(Color.alpha(color) * ratio);

View File

@ -5,6 +5,7 @@ import android.content.Intent;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
@ -94,7 +95,6 @@ public class HomeLayoutGenerator {
if(currency.getHistoryMinutes() != null)
{
List<Double> borders = getAxisBorders(currency);
LineChart lineChart = view.findViewById(R.id.LineChartView);
lineChart.setDrawGridBackground(false);

View File

@ -36,7 +36,7 @@
</LinearLayout>
<com.db.chart.view.LineChartView
<com.github.mikephil.charting.charts.LineChart
android:id="@+id/chartView"
android:layout_width="match_parent"
android:layout_height="300dp"