Search in sources :

Example 6 with Cell

use of com.pdfjet.Cell in project Diaguard by Faltenreich.

the class PdfLog method getRow.

private List<Cell> getRow(PdfExportCache cache, String title, String subtitle, String description, int backgroundColor, int foregroundColor) {
    List<Cell> entryRow = new ArrayList<>();
    float width = cache.getPage().getWidth();
    Cell titleCell = new CellBuilder(new Cell(cache.getFontNormal())).setWidth(PdfLog.TIME_WIDTH).setText(title).setBackgroundColor(backgroundColor).setForegroundColor(Color.gray).build();
    entryRow.add(titleCell);
    Cell subtitleCell = new CellBuilder(new Cell(cache.getFontNormal())).setWidth(getLabelWidth()).setText(subtitle).setBackgroundColor(backgroundColor).setForegroundColor(Color.gray).build();
    entryRow.add(subtitleCell);
    Cell descriptionCell = new CellBuilder(new MultilineCell(cache.getFontNormal())).setWidth(width - titleCell.getWidth() - subtitleCell.getWidth()).setText(description).setBackgroundColor(backgroundColor).setForegroundColor(foregroundColor).build();
    entryRow.add(descriptionCell);
    return entryRow;
}
Also used : MultilineCell(com.faltenreich.diaguard.feature.export.job.pdf.view.MultilineCell) CellBuilder(com.faltenreich.diaguard.feature.export.job.pdf.view.CellBuilder) ArrayList(java.util.ArrayList) MultilineCell(com.faltenreich.diaguard.feature.export.job.pdf.view.MultilineCell) Cell(com.pdfjet.Cell)

Example 7 with Cell

use of com.pdfjet.Cell in project Diaguard by Faltenreich.

the class PdfLog method init.

private void init() {
    PdfExportConfig config = cache.getConfig();
    Context context = config.getContext();
    List<List<Cell>> data = new ArrayList<>();
    List<Cell> headerRow = new ArrayList<>();
    Cell headerCell = new CellBuilder(new Cell(cache.getFontBold())).setWidth(getLabelWidth()).setText(DateTimeUtils.toWeekDayAndDate(cache.getDateTime())).build();
    headerRow.add(headerCell);
    data.add(headerRow);
    for (Entry entry : entriesOfDay) {
        List<Measurement> measurements = EntryDao.getInstance().getMeasurements(entry, cache.getConfig().getCategories());
        entry.setMeasurementCache(measurements);
    }
    int rowIndex = 0;
    for (Entry entry : entriesOfDay) {
        int backgroundColor = rowIndex % 2 == 0 ? cache.getColorDivider() : Color.white;
        int oldSize = data.size();
        String time = entry.getDate().toString("HH:mm");
        for (Measurement measurement : entry.getMeasurementCache()) {
            Category category = measurement.getCategory();
            int textColor = Color.black;
            if (category == Category.BLOODSUGAR && config.highlightLimits()) {
                BloodSugar bloodSugar = (BloodSugar) measurement;
                float value = bloodSugar.getMgDl();
                if (value > PreferenceStore.getInstance().getLimitHyperglycemia()) {
                    textColor = cache.getColorHyperglycemia();
                } else if (value < PreferenceStore.getInstance().getLimitHypoglycemia()) {
                    textColor = cache.getColorHypoglycemia();
                }
            }
            String measurementText = measurement.print(context);
            if (category == Category.MEAL && config.exportFood()) {
                List<String> foodOfDay = new ArrayList<>();
                Meal meal = (Meal) MeasurementDao.getInstance(Meal.class).getMeasurement(entry);
                if (meal != null) {
                    for (FoodEaten foodEaten : FoodEatenDao.getInstance().getAll(meal)) {
                        String foodNote = foodEaten.print();
                        if (foodNote != null) {
                            foodOfDay.add(foodNote);
                        }
                    }
                }
                if (!foodOfDay.isEmpty()) {
                    String foodText = TextUtils.join(", ", foodOfDay);
                    measurementText = String.format("%s\n%s", measurementText, foodText);
                }
            }
            data.add(getRow(cache, data.size() == oldSize ? time : null, context.getString(category.getStringAcronymResId()), measurementText, backgroundColor, textColor));
        }
        if (config.exportTags()) {
            List<EntryTag> entryTags = EntryTagDao.getInstance().getAll(entry);
            if (!entryTags.isEmpty()) {
                List<String> tagNames = new ArrayList<>();
                for (EntryTag entryTag : entryTags) {
                    Tag tag = entryTag.getTag();
                    if (tag != null) {
                        String tagName = tag.getName();
                        if (!StringUtils.isBlank(tagName)) {
                            tagNames.add(tagName);
                        }
                    }
                }
                data.add(getRow(cache, data.size() == oldSize ? time : null, context.getString(R.string.tags), TextUtils.join(", ", tagNames), backgroundColor));
            }
        }
        if (config.exportNotes()) {
            if (!StringUtils.isBlank(entry.getNote())) {
                data.add(getRow(cache, data.size() == oldSize ? time : null, context.getString(R.string.note), entry.getNote(), backgroundColor));
            }
        }
        rowIndex++;
    }
    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) Measurement(com.faltenreich.diaguard.shared.data.database.entity.Measurement) Category(com.faltenreich.diaguard.shared.data.database.entity.Category) Meal(com.faltenreich.diaguard.shared.data.database.entity.Meal) EntryTag(com.faltenreich.diaguard.shared.data.database.entity.EntryTag) ArrayList(java.util.ArrayList) FoodEaten(com.faltenreich.diaguard.shared.data.database.entity.FoodEaten) BloodSugar(com.faltenreich.diaguard.shared.data.database.entity.BloodSugar) 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) Tag(com.faltenreich.diaguard.shared.data.database.entity.Tag) EntryTag(com.faltenreich.diaguard.shared.data.database.entity.EntryTag) MultilineCell(com.faltenreich.diaguard.feature.export.job.pdf.view.MultilineCell) Cell(com.pdfjet.Cell)

Aggregations

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