Search in sources :

Example 1 with PdfNote

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());
    }
}
Also used : PdfExportConfig(com.faltenreich.diaguard.feature.export.job.pdf.meta.PdfExportConfig) Context(android.content.Context) Category(com.faltenreich.diaguard.shared.data.database.entity.Category) ArrayList(java.util.ArrayList) CategoryValueListItem(com.faltenreich.diaguard.feature.timeline.table.CategoryValueListItem) Point(com.pdfjet.Point) Entry(com.faltenreich.diaguard.shared.data.database.entity.Entry) CellBuilder(com.faltenreich.diaguard.feature.export.job.pdf.view.CellBuilder) ArrayList(java.util.ArrayList) List(java.util.List) Cell(com.pdfjet.Cell) PdfNote(com.faltenreich.diaguard.feature.export.job.pdf.meta.PdfNote)

Example 2 with PdfNote

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);
}
Also used : Measurement(com.faltenreich.diaguard.shared.data.database.entity.Measurement) Entry(com.faltenreich.diaguard.shared.data.database.entity.Entry) Category(com.faltenreich.diaguard.shared.data.database.entity.Category) ArrayList(java.util.ArrayList) BloodSugar(com.faltenreich.diaguard.shared.data.database.entity.BloodSugar) PdfNote(com.faltenreich.diaguard.feature.export.job.pdf.meta.PdfNote)

Example 3 with PdfNote

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;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) PdfNote(com.faltenreich.diaguard.feature.export.job.pdf.meta.PdfNote) Cell(com.pdfjet.Cell)

Aggregations

PdfNote (com.faltenreich.diaguard.feature.export.job.pdf.meta.PdfNote)3 ArrayList (java.util.ArrayList)3 Category (com.faltenreich.diaguard.shared.data.database.entity.Category)2 Entry (com.faltenreich.diaguard.shared.data.database.entity.Entry)2 Cell (com.pdfjet.Cell)2 List (java.util.List)2 Context (android.content.Context)1 PdfExportConfig (com.faltenreich.diaguard.feature.export.job.pdf.meta.PdfExportConfig)1 CellBuilder (com.faltenreich.diaguard.feature.export.job.pdf.view.CellBuilder)1 CategoryValueListItem (com.faltenreich.diaguard.feature.timeline.table.CategoryValueListItem)1 BloodSugar (com.faltenreich.diaguard.shared.data.database.entity.BloodSugar)1 Measurement (com.faltenreich.diaguard.shared.data.database.entity.Measurement)1 Point (com.pdfjet.Point)1