use of com.faltenreich.diaguard.feature.export.job.pdf.meta.PdfNote 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.export.job.pdf.meta.PdfNote in project Diaguard by Faltenreich.
the class PdfTimeline method fetchData.
private void fetchData() {
bloodSugars = new ArrayList<>();
pdfNotes = new ArrayList<>();
for (Entry entry : entriesOfDay) {
if (showChartForBloodSugar) {
List<Measurement> measurements = EntryDao.getInstance().getMeasurements(entry);
for (Measurement measurement : measurements) {
if (measurement instanceof BloodSugar) {
bloodSugars.add((BloodSugar) measurement);
}
}
}
PdfNote pdfNote = PdfNoteFactory.createNote(cache.getConfig(), entry);
if (pdfNote != null) {
pdfNotes.add(pdfNote);
}
}
List<Category> categories = new ArrayList<>();
for (Category category : cache.getConfig().getCategories()) {
if (category != Category.BLOODSUGAR) {
categories.add(category);
}
}
measurements = EntryDao.getInstance().getAverageDataTable(cache.getDateTime(), categories.toArray(new Category[0]), HOUR_INTERVAL);
}
use of com.faltenreich.diaguard.feature.export.job.pdf.meta.PdfNote in project Diaguard by Faltenreich.
the class CellFactory method createRowsForNotes.
public static List<List<Cell>> createRowsForNotes(PdfExportCache cache, List<PdfNote> pdfNotes, float labelWidth) {
List<List<Cell>> rows = new ArrayList<>();
for (PdfNote note : pdfNotes) {
boolean isFirst = pdfNotes.indexOf(note) == 0;
boolean isLast = pdfNotes.indexOf(note) == pdfNotes.size() - 1;
ArrayList<Cell> noteCells = new ArrayList<>();
Cell timeCell = new CellBuilder(new Cell(cache.getFontNormal())).setWidth(labelWidth).setText(Helper.getTimeFormat().print(note.getDateTime())).setForegroundColor(Color.gray).build();
if (isFirst) {
timeCell.setBorder(Border.TOP, true);
}
if (isLast) {
timeCell.setBorder(Border.BOTTOM, true);
}
noteCells.add(timeCell);
Cell noteCell = new CellBuilder(new MultilineCell(cache.getFontNormal())).setWidth(cache.getPage().getWidth() - labelWidth).setText(note.getNote()).setForegroundColor(Color.gray).build();
if (isFirst) {
noteCell.setBorder(Border.TOP, true);
}
if (isLast) {
noteCell.setBorder(Border.BOTTOM, true);
}
noteCells.add(noteCell);
rows.add(noteCells);
}
return rows;
}
Aggregations