use of com.faltenreich.diaguard.feature.timeline.chart.DayChartData in project Diaguard by Faltenreich.
the class TimelineDayFragment method invalidateData.
private void invalidateData() {
if (getContext() == null) {
return;
}
if (data.needsChartData()) {
Log.d(TAG, "Invalidating data for chart on " + data.getDay().toString());
DataLoader.getInstance().load(getContext(), new DataLoaderListener<DayChartData>() {
@Override
public DayChartData onShouldLoad(Context context) {
List<Measurement> values = new ArrayList<>();
List<Entry> entries = EntryDao.getInstance().getEntriesOfDay(data.getDay());
if (entries != null && entries.size() > 0) {
for (Entry entry : entries) {
// TODO: Improve performance by using transaction / bulk fetch
List<Measurement> measurements = EntryDao.getInstance().getMeasurements(entry, new Category[] { Category.BLOODSUGAR });
values.addAll(measurements);
}
}
return new DayChartData(context, PreferenceStore.getInstance().showDotsInTimeline(), PreferenceStore.getInstance().showLinesInTimeline(), values);
}
@Override
public void onDidLoad(DayChartData chartData) {
data.setChartData(chartData);
invalidateChart();
}
});
} else {
invalidateChart();
}
if (data.needsListData()) {
Log.d(TAG, "Invalidating data for list on " + data.getDay().toString());
DataLoader.getInstance().load(getContext(), new DataLoaderListener<List<CategoryValueListItem>>() {
@Override
public List<CategoryValueListItem> onShouldLoad(Context context) {
List<CategoryValueListItem> listItems = new ArrayList<>();
LinkedHashMap<Category, CategoryValueListItem[]> values = EntryDao.getInstance().getAverageDataTable(data.getDay(), categories, SKIP_EVERY_X_HOUR);
for (Map.Entry<Category, CategoryValueListItem[]> mapEntry : values.entrySet()) {
Collections.addAll(listItems, mapEntry.getValue());
}
return listItems;
}
@Override
public void onDidLoad(List<CategoryValueListItem> listData) {
data.setListData(listData);
invalidateList();
}
});
} else {
invalidateList();
}
}
use of com.faltenreich.diaguard.feature.timeline.chart.DayChartData in project Diaguard by Faltenreich.
the class TimelineDayFragment method invalidateChart.
private void invalidateChart() {
if (isAdded() && !data.needsChartData()) {
Log.d(TAG, "Invalidating view for chart on " + data.getDay().toString());
DayChartData chartData = data.getChartData();
chartView.setData(chartData);
chartView.getAxisLeft().setAxisMaximum(chartData.getYAxisMaximum());
// Workaround: Fixes invalidation within ViewPager
// https://github.com/PhilJay/MPAndroidChart/issues/1274
// FIXME: Leads to jumping chart view
chartView.invalidate();
}
}
Aggregations