Fixes regarding xlabels -- must set them at the correct point in time
(otherwise we get ArrayIndexOutOfBoundsException when the chart refreshes and the wrong xLabels, potentially with fewer entries are used)
This commit is contained in:
parent
6a5c3fb945
commit
dee492bc4f
|
@ -85,7 +85,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
||||||
};
|
};
|
||||||
private boolean mChartDirty = true;
|
private boolean mChartDirty = true;
|
||||||
private AsyncTask refreshTask;
|
private AsyncTask refreshTask;
|
||||||
private XIndexLabelFormatter xIndexFormatter = new XIndexLabelFormatter();
|
protected XIndexLabelFormatter xIndexFormatter = new XIndexLabelFormatter();
|
||||||
|
|
||||||
public boolean isChartDirty() {
|
public boolean isChartDirty() {
|
||||||
return mChartDirty;
|
return mChartDirty;
|
||||||
|
@ -409,6 +409,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
||||||
Date date;
|
Date date;
|
||||||
String dateStringFrom = "";
|
String dateStringFrom = "";
|
||||||
String dateStringTo = "";
|
String dateStringTo = "";
|
||||||
|
ArrayList<String> xLabels = null;
|
||||||
|
|
||||||
LOG.info("" + getTitle() + ": number of samples:" + samples.size());
|
LOG.info("" + getTitle() + ": number of samples:" + samples.size());
|
||||||
CombinedData combinedData;
|
CombinedData combinedData;
|
||||||
|
@ -422,7 +423,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
||||||
SimpleDateFormat annotationDateFormat = new SimpleDateFormat("HH:mm");
|
SimpleDateFormat annotationDateFormat = new SimpleDateFormat("HH:mm");
|
||||||
|
|
||||||
int numEntries = samples.size();
|
int numEntries = samples.size();
|
||||||
ArrayList<String> xLabels = new ArrayList<>(numEntries);
|
xLabels = new ArrayList<>(numEntries);
|
||||||
List<BarEntry> activityEntries = new ArrayList<>(numEntries);
|
List<BarEntry> activityEntries = new ArrayList<>(numEntries);
|
||||||
boolean hr = supportsHeartrate(gbDevice);
|
boolean hr = supportsHeartrate(gbDevice);
|
||||||
List<Entry> heartrateEntries = hr ? new ArrayList<Entry>(numEntries) : null;
|
List<Entry> heartrateEntries = hr ? new ArrayList<Entry>(numEntries) : null;
|
||||||
|
@ -507,9 +508,6 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
||||||
xLabels.add(xLabel);
|
xLabels.add(xLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
xIndexFormatter.setxLabels(xLabels);
|
|
||||||
// chart.getXAxis().setValues(xLabels);
|
|
||||||
|
|
||||||
BarDataSet activitySet = createActivitySet(activityEntries, colors, "Activity");
|
BarDataSet activitySet = createActivitySet(activityEntries, colors, "Activity");
|
||||||
// create a data object with the datasets
|
// create a data object with the datasets
|
||||||
// combinedData = new CombinedData(xLabels);
|
// combinedData = new CombinedData(xLabels);
|
||||||
|
@ -533,7 +531,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
||||||
combinedData = new CombinedData();
|
combinedData = new CombinedData();
|
||||||
}
|
}
|
||||||
|
|
||||||
return new DefaultChartsData(combinedData);
|
return new DefaultChartsData(combinedData, xLabels);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isValidHeartRateValue(int value) {
|
protected boolean isValidHeartRateValue(int value) {
|
||||||
|
@ -717,8 +715,9 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
||||||
public static class DefaultChartsData extends ChartsData {
|
public static class DefaultChartsData extends ChartsData {
|
||||||
private final CombinedData combinedData;
|
private final CombinedData combinedData;
|
||||||
|
|
||||||
public DefaultChartsData(CombinedData combinedData) {
|
public DefaultChartsData(CombinedData combinedData, ArrayList<String> xLabels) {
|
||||||
this.combinedData = combinedData;
|
this.combinedData = combinedData;
|
||||||
|
setxLabels(xLabels);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CombinedData getCombinedData() {
|
public CombinedData getCombinedData() {
|
||||||
|
|
|
@ -119,6 +119,7 @@ public class ActivitySleepChartFragment extends AbstractChartFragment {
|
||||||
DefaultChartsData dcd = (DefaultChartsData) chartsData;
|
DefaultChartsData dcd = (DefaultChartsData) chartsData;
|
||||||
mChart.getLegend().setTextColor(LEGEND_TEXT_COLOR);
|
mChart.getLegend().setTextColor(LEGEND_TEXT_COLOR);
|
||||||
mChart.setData(null); // workaround for https://github.com/PhilJay/MPAndroidChart/issues/2317
|
mChart.setData(null); // workaround for https://github.com/PhilJay/MPAndroidChart/issues/2317
|
||||||
|
xIndexFormatter.setxLabels(dcd.getXLabels());
|
||||||
mChart.setData(dcd.getCombinedData());
|
mChart.setData(dcd.getCombinedData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,15 @@
|
||||||
package nodomain.freeyourgadget.gadgetbridge.activities.charts;
|
package nodomain.freeyourgadget.gadgetbridge.activities.charts;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public abstract class ChartsData {
|
public abstract class ChartsData {
|
||||||
|
private ArrayList<String> xLabels;
|
||||||
|
|
||||||
|
public void setxLabels(ArrayList<String> xLabels) {
|
||||||
|
this.xLabels = xLabels;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<String> getXLabels() {
|
||||||
|
return xLabels;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,6 +71,7 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
|
||||||
mWeekStepsChart.setData(null); // workaround for https://github.com/PhilJay/MPAndroidChart/issues/2317
|
mWeekStepsChart.setData(null); // workaround for https://github.com/PhilJay/MPAndroidChart/issues/2317
|
||||||
mWeekStepsChart.setData(mcd.getWeekBeforeStepsData().getCombinedData());
|
mWeekStepsChart.setData(mcd.getWeekBeforeStepsData().getCombinedData());
|
||||||
mWeekStepsChart.getLegend().setEnabled(false);
|
mWeekStepsChart.getLegend().setEnabled(false);
|
||||||
|
xIndexLabelFormatter.setxLabels(mcd.getWeekBeforeStepsData().getXLabels());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -97,7 +98,6 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
|
||||||
BarDataSet set = new BarDataSet(entries, "");
|
BarDataSet set = new BarDataSet(entries, "");
|
||||||
set.setColor(akActivity.color);
|
set.setColor(akActivity.color);
|
||||||
|
|
||||||
xIndexLabelFormatter.setxLabels(labels);
|
|
||||||
BarData barData = new BarData(set);
|
BarData barData = new BarData(set);
|
||||||
barData.setValueTextColor(Color.GRAY); //prevent tearing other graph elements with the black text. Another approach would be to hide the values cmpletely with data.setDrawValues(false);
|
barData.setValueTextColor(Color.GRAY); //prevent tearing other graph elements with the black text. Another approach would be to hide the values cmpletely with data.setDrawValues(false);
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
|
||||||
|
|
||||||
CombinedData combinedData = new CombinedData();
|
CombinedData combinedData = new CombinedData();
|
||||||
combinedData.setData(barData);
|
combinedData.setData(barData);
|
||||||
return new DefaultChartsData(combinedData);
|
return new DefaultChartsData(combinedData, labels);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue