Search in sources :

Example 1 with PdfExportConfig

use of com.faltenreich.diaguard.feature.export.job.pdf.meta.PdfExportConfig in project Diaguard by Faltenreich.

the class ExportFragment method export.

private void export() {
    progressComponent.show(getContext());
    progressComponent.setMessage(getString(R.string.export_progress));
    DateTime dateStart = this.dateStart != null ? this.dateStart.withTimeAtStartOfDay() : null;
    DateTime dateEnd = this.dateEnd != null ? this.dateEnd.withTimeAtStartOfDay() : null;
    Category[] categories = categoryListAdapter.getSelectedCategories();
    PdfExportConfig config = new PdfExportConfig(getContext(), this, dateStart, dateEnd, categories, getStyle(), getBinding().headerCheckbox.isChecked(), getBinding().footerCheckbox.isChecked(), getBinding().noteCheckbox.isChecked(), getBinding().tagsCheckbox.isChecked(), getBinding().emptyDaysCheckbox.isChecked(), categoryListAdapter.exportFood(), categoryListAdapter.splitInsulin(), categoryListAdapter.highlightLimits());
    config.persistInSharedPreferences();
    FileType type = getFormat();
    switch(type) {
        case PDF:
            Export.exportPdf(config);
            break;
        case CSV:
            Export.exportCsv(getContext(), this, dateStart, dateEnd, categories);
            break;
    }
}
Also used : PdfExportConfig(com.faltenreich.diaguard.feature.export.job.pdf.meta.PdfExportConfig) Category(com.faltenreich.diaguard.shared.data.database.entity.Category) FileType(com.faltenreich.diaguard.feature.export.job.FileType) DateTime(org.joda.time.DateTime)

Example 2 with PdfExportConfig

use of com.faltenreich.diaguard.feature.export.job.pdf.meta.PdfExportConfig 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 3 with PdfExportConfig

use of com.faltenreich.diaguard.feature.export.job.pdf.meta.PdfExportConfig 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

PdfExportConfig (com.faltenreich.diaguard.feature.export.job.pdf.meta.PdfExportConfig)3 Category (com.faltenreich.diaguard.shared.data.database.entity.Category)3 Context (android.content.Context)2 CellBuilder (com.faltenreich.diaguard.feature.export.job.pdf.view.CellBuilder)2 Entry (com.faltenreich.diaguard.shared.data.database.entity.Entry)2 Cell (com.pdfjet.Cell)2 Point (com.pdfjet.Point)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 FileType (com.faltenreich.diaguard.feature.export.job.FileType)1 PdfNote (com.faltenreich.diaguard.feature.export.job.pdf.meta.PdfNote)1 MultilineCell (com.faltenreich.diaguard.feature.export.job.pdf.view.MultilineCell)1 CategoryValueListItem (com.faltenreich.diaguard.feature.timeline.table.CategoryValueListItem)1 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 DateTime (org.joda.time.DateTime)1