1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-28 21:06:50 +01:00

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:
cpfeiffer 2016-10-03 23:34:05 +02:00
parent 6a5c3fb945
commit dee492bc4f
4 changed files with 20 additions and 9 deletions

View File

@ -85,7 +85,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
};
private boolean mChartDirty = true;
private AsyncTask refreshTask;
private XIndexLabelFormatter xIndexFormatter = new XIndexLabelFormatter();
protected XIndexLabelFormatter xIndexFormatter = new XIndexLabelFormatter();
public boolean isChartDirty() {
return mChartDirty;
@ -409,6 +409,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
Date date;
String dateStringFrom = "";
String dateStringTo = "";
ArrayList<String> xLabels = null;
LOG.info("" + getTitle() + ": number of samples:" + samples.size());
CombinedData combinedData;
@ -422,7 +423,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
SimpleDateFormat annotationDateFormat = new SimpleDateFormat("HH:mm");
int numEntries = samples.size();
ArrayList<String> xLabels = new ArrayList<>(numEntries);
xLabels = new ArrayList<>(numEntries);
List<BarEntry> activityEntries = new ArrayList<>(numEntries);
boolean hr = supportsHeartrate(gbDevice);
List<Entry> heartrateEntries = hr ? new ArrayList<Entry>(numEntries) : null;
@ -507,9 +508,6 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
xLabels.add(xLabel);
}
xIndexFormatter.setxLabels(xLabels);
// chart.getXAxis().setValues(xLabels);
BarDataSet activitySet = createActivitySet(activityEntries, colors, "Activity");
// create a data object with the datasets
// combinedData = new CombinedData(xLabels);
@ -533,7 +531,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
combinedData = new CombinedData();
}
return new DefaultChartsData(combinedData);
return new DefaultChartsData(combinedData, xLabels);
}
protected boolean isValidHeartRateValue(int value) {
@ -717,8 +715,9 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
public static class DefaultChartsData extends ChartsData {
private final CombinedData combinedData;
public DefaultChartsData(CombinedData combinedData) {
public DefaultChartsData(CombinedData combinedData, ArrayList<String> xLabels) {
this.combinedData = combinedData;
setxLabels(xLabels);
}
public CombinedData getCombinedData() {

View File

@ -119,6 +119,7 @@ public class ActivitySleepChartFragment extends AbstractChartFragment {
DefaultChartsData dcd = (DefaultChartsData) chartsData;
mChart.getLegend().setTextColor(LEGEND_TEXT_COLOR);
mChart.setData(null); // workaround for https://github.com/PhilJay/MPAndroidChart/issues/2317
xIndexFormatter.setxLabels(dcd.getXLabels());
mChart.setData(dcd.getCombinedData());
}

View File

@ -1,4 +1,15 @@
package nodomain.freeyourgadget.gadgetbridge.activities.charts;
import java.util.ArrayList;
public abstract class ChartsData {
private ArrayList<String> xLabels;
public void setxLabels(ArrayList<String> xLabels) {
this.xLabels = xLabels;
}
public ArrayList<String> getXLabels() {
return xLabels;
}
}

View File

@ -71,6 +71,7 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
mWeekStepsChart.setData(null); // workaround for https://github.com/PhilJay/MPAndroidChart/issues/2317
mWeekStepsChart.setData(mcd.getWeekBeforeStepsData().getCombinedData());
mWeekStepsChart.getLegend().setEnabled(false);
xIndexLabelFormatter.setxLabels(mcd.getWeekBeforeStepsData().getXLabels());
}
@Override
@ -97,7 +98,6 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
BarDataSet set = new BarDataSet(entries, "");
set.setColor(akActivity.color);
xIndexLabelFormatter.setxLabels(labels);
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);
@ -107,7 +107,7 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
CombinedData combinedData = new CombinedData();
combinedData.setData(barData);
return new DefaultChartsData(combinedData);
return new DefaultChartsData(combinedData, labels);
}