use of com.faltenreich.diaguard.feature.timeline.table.CategoryValueListItem 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.table.CategoryValueListItem in project Diaguard by Faltenreich.
the class PdfTable method init.
private void init() {
PdfExportConfig config = cache.getConfig();
Context context = config.getContext();
List<List<Cell>> data = new ArrayList<>();
List<Cell> cells = new ArrayList<>();
Cell headerCell = new CellBuilder(new Cell(cache.getFontBold())).setWidth(getLabelWidth()).setText(DateTimeUtils.toWeekDayAndDate(cache.getDateTime())).build();
cells.add(headerCell);
float cellWidth = (cache.getPage().getWidth() - getLabelWidth()) / (DateTimeConstants.HOURS_PER_DAY / 2f);
for (int hour = 0; hour < DateTimeConstants.HOURS_PER_DAY; hour += PdfTable.HOURS_TO_SKIP) {
Cell hourCell = new CellBuilder(new Cell(cache.getFontNormal())).setWidth(cellWidth).setText(Integer.toString(hour)).setForegroundColor(Color.gray).setTextAlignment(Align.CENTER).build();
cells.add(hourCell);
}
data.add(cells);
LinkedHashMap<Category, CategoryValueListItem[]> values = EntryDao.getInstance().getAverageDataTable(cache.getDateTime(), config.getCategories(), HOURS_TO_SKIP);
int rowIndex = 0;
for (Category category : values.keySet()) {
CategoryValueListItem[] items = values.get(category);
if (items != null) {
String label = context.getString(category.getStringAcronymResId());
int backgroundColor = rowIndex % 2 == 0 ? cache.getColorDivider() : Color.white;
switch(category) {
case INSULIN:
if (config.splitInsulin()) {
data.add(createMeasurementRows(cache, items, cellWidth, 0, label + " " + context.getString(R.string.bolus), backgroundColor));
data.add(createMeasurementRows(cache, items, cellWidth, 1, label + " " + context.getString(R.string.correction), backgroundColor));
data.add(createMeasurementRows(cache, items, cellWidth, 2, label + " " + context.getString(R.string.basal), backgroundColor));
} else {
data.add(createMeasurementRows(cache, items, cellWidth, -1, label, backgroundColor));
}
break;
case PRESSURE:
data.add(createMeasurementRows(cache, items, cellWidth, 0, label + " " + context.getString(R.string.systolic_acronym), backgroundColor));
data.add(createMeasurementRows(cache, items, cellWidth, 1, label + " " + context.getString(R.string.diastolic_acronym), backgroundColor));
break;
default:
data.add(createMeasurementRows(cache, items, cellWidth, 0, label, backgroundColor));
break;
}
rowIndex++;
}
}
if (config.exportNotes() || config.exportTags() || config.exportFood()) {
List<PdfNote> pdfNotes = new ArrayList<>();
for (Entry entry : entriesOfDay) {
PdfNote pdfNote = PdfNoteFactory.createNote(config, entry);
if (pdfNote != null) {
pdfNotes.add(pdfNote);
}
}
data.addAll(CellFactory.createRowsForNotes(cache, pdfNotes, getLabelWidth()));
}
boolean hasData = data.size() > 1;
if (!hasData) {
data.add(CellFactory.createEmptyRow(cache));
}
try {
table.setData(data);
} catch (Exception exception) {
Log.e(TAG, exception.toString());
}
}
use of com.faltenreich.diaguard.feature.timeline.table.CategoryValueListItem in project Diaguard by Faltenreich.
the class PdfTable method createMeasurementRows.
private List<Cell> createMeasurementRows(PdfExportCache cache, CategoryValueListItem[] items, float cellWidth, int valueIndex, String label, int backgroundColor) {
List<Cell> cells = new ArrayList<>();
Cell labelCell = new CellBuilder(new Cell(cache.getFontNormal())).setWidth(getLabelWidth()).setText(label).setBackgroundColor(backgroundColor).setForegroundColor(Color.gray).build();
cells.add(labelCell);
for (CategoryValueListItem item : items) {
Category category = item.getCategory();
float value = 0;
switch(valueIndex) {
case -1:
value = item.getValueTotal();
break;
case 0:
value = item.getValueOne();
break;
case 1:
value = item.getValueTwo();
break;
case 2:
value = item.getValueThree();
break;
}
int textColor = Color.black;
if (category == Category.BLOODSUGAR && cache.getConfig().highlightLimits()) {
if (value > PreferenceStore.getInstance().getLimitHyperglycemia()) {
textColor = cache.getColorHyperglycemia();
} else if (value < PreferenceStore.getInstance().getLimitHypoglycemia()) {
textColor = cache.getColorHypoglycemia();
}
}
float customValue = PreferenceStore.getInstance().formatDefaultToCustomUnit(category, value);
String text = customValue > 0 ? FloatUtils.parseFloat(customValue) : "";
Cell measurementCell = new CellBuilder(new Cell(cache.getFontNormal())).setWidth(cellWidth).setText(text).setTextAlignment(Align.CENTER).setBackgroundColor(backgroundColor).setForegroundColor(textColor).build();
cells.add(measurementCell);
}
return cells;
}
use of com.faltenreich.diaguard.feature.timeline.table.CategoryValueListItem in project Diaguard by Faltenreich.
the class PdfTimeline method createRowForMeasurements.
private List<Cell> createRowForMeasurements(Category category, CategoryValueListItem[] values, int rowIndex, int valueIndex, String label) {
List<Cell> row = new ArrayList<>();
Cell titleCell = new Cell(cache.getFontNormal());
titleCell.setText(label);
titleCell.setWidth(getLabelWidth());
titleCell.setBgColor(rowIndex % 2 == 0 ? cache.getColorDivider() : Color.white);
titleCell.setFgColor(Color.gray);
titleCell.setPenColor(Color.gray);
row.add(titleCell);
for (CategoryValueListItem item : values) {
Cell valueCell = new Cell(cache.getFontNormal());
float value = 0;
switch(valueIndex) {
case -1:
value = item.getValueTotal();
break;
case 0:
value = item.getValueOne();
break;
case 1:
value = item.getValueTwo();
break;
case 2:
value = item.getValueThree();
break;
}
float customValue = PreferenceStore.getInstance().formatDefaultToCustomUnit(category, value);
String text = customValue > 0 ? FloatUtils.parseFloat(customValue) : "";
valueCell.setText(text);
valueCell.setWidth((cache.getPage().getWidth() - getLabelWidth()) / (DateTimeConstants.HOURS_PER_DAY / HOUR_INTERVAL));
valueCell.setBgColor(rowIndex % 2 == 0 ? cache.getColorDivider() : Color.white);
valueCell.setFgColor(Color.black);
valueCell.setPenColor(Color.gray);
valueCell.setTextAlignment(Align.CENTER);
row.add(valueCell);
}
return row;
}
use of com.faltenreich.diaguard.feature.timeline.table.CategoryValueListItem in project Diaguard by Faltenreich.
the class PdfTimeline method initTable.
private void initTable() {
List<List<Cell>> tableData = new ArrayList<>();
Context context = cache.getContext();
int rowIndex = 0;
for (Map.Entry<Category, CategoryValueListItem[]> entry : measurements.entrySet()) {
Category category = entry.getKey();
CategoryValueListItem[] values = entry.getValue();
String label = context.getString(category.getStringAcronymResId());
switch(category) {
case INSULIN:
if (cache.getConfig().splitInsulin()) {
tableData.add(createRowForMeasurements(category, values, rowIndex, 0, label + " " + context.getString(R.string.bolus)));
tableData.add(createRowForMeasurements(category, values, rowIndex, 1, label + " " + context.getString(R.string.correction)));
tableData.add(createRowForMeasurements(category, values, rowIndex, 2, label + " " + context.getString(R.string.basal)));
} else {
tableData.add(createRowForMeasurements(category, values, rowIndex, -1, label));
}
break;
case PRESSURE:
tableData.add(createRowForMeasurements(category, values, rowIndex, 0, label + " " + context.getString(R.string.systolic_acronym)));
tableData.add(createRowForMeasurements(category, values, rowIndex, 1, label + " " + context.getString(R.string.diastolic_acronym)));
break;
default:
tableData.add(createRowForMeasurements(category, values, rowIndex, -1, label));
}
rowIndex++;
}
tableData.addAll(CellFactory.createRowsForNotes(cache, pdfNotes, getLabelWidth()));
if (tableData.isEmpty() && !showChartForBloodSugar) {
tableData.add(CellFactory.createEmptyRow(cache));
}
try {
// Must be executed early to know the table's height
table.setData(tableData);
} catch (Exception exception) {
Log.e(TAG, exception.toString());
}
}
Aggregations