Search in sources :

Example 16 with Entry

use of com.faltenreich.diaguard.shared.data.database.entity.Entry in project Diaguard by Faltenreich.

the class LogSwipeCallback method onSwiped.

@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
    Object item = adapter.getItem(viewHolder.getAdapterPosition());
    if (item instanceof LogEntryListItem) {
        LogEntryListItem listItem = (LogEntryListItem) item;
        Entry entry = listItem.getEntry();
        EntryDao.getInstance().delete(entry);
        Events.post(new EntryDeletedEvent(entry, listItem.getEntryTags(), listItem.getFoodEatenList()));
    }
}
Also used : Entry(com.faltenreich.diaguard.shared.data.database.entity.Entry) LogEntryListItem(com.faltenreich.diaguard.feature.log.entry.LogEntryListItem) EntryDeletedEvent(com.faltenreich.diaguard.shared.event.data.EntryDeletedEvent)

Example 17 with Entry

use of com.faltenreich.diaguard.shared.data.database.entity.Entry in project Diaguard by Faltenreich.

the class PdfTimeline method drawChart.

private Point drawChart(PdfPage page, Point position, List<BloodSugar> bloodSugars) throws Exception {
    chart.setColor(Color.transparent);
    chart.setPosition(position.getX(), position.getY());
    float[] coordinates = chart.drawOn(page);
    TextLine label = new TextLine(cache.getFontNormal());
    label.setColor(Color.gray);
    Line line = new Line();
    line.setColor(Color.gray);
    float chartWidth = chart.getWidth();
    float chartHeight = chart.getHeight();
    float chartStartX = 0;
    float chartEndX = chartStartX + chart.getWidth();
    float chartStartY = 0;
    float chartEndY = chartStartY + chartHeight;
    float contentStartX = getLabelWidth();
    float contentStartY = chartStartY + label.getHeight() + PADDING;
    float contentEndX = chartEndX;
    float contentEndY = chartEndY;
    float contentWidth = contentEndX - contentStartX;
    float contentHeight = contentEndY - contentStartY;
    int xStep = DateTimeConstants.MINUTES_PER_HOUR * HOUR_INTERVAL;
    float xMax = DateTimeConstants.MINUTES_PER_DAY;
    TextLine header = new TextLine(cache.getFontBold());
    header.setText(DateTimeUtils.toWeekDayAndDate(cache.getDateTime()));
    header.setPosition(chartStartX, chartStartY + header.getHeight());
    header.placeIn(chart);
    header.drawOn(page);
    // Labels for x axis
    int minutes = 0;
    while (minutes <= xMax) {
        float x = contentStartX + ((float) minutes / xMax) * contentWidth;
        label.setText(String.valueOf(minutes / 60));
        label.setPosition(x - label.getWidth() / 2, chartStartY + header.getHeight());
        label.placeIn(chart);
        label.drawOn(page);
        line.setStartPoint(x, chartStartY + header.getHeight() + 8);
        line.setEndPoint(x, contentEndY);
        line.placeIn(chart);
        line.drawOn(page);
        minutes += xStep;
    }
    if (showChartForBloodSugar) {
        float yMin = 40;
        float yMax = 210;
        for (BloodSugar bloodSugar : bloodSugars) {
            if (bloodSugar.getMgDl() > yMax) {
                yMax = bloodSugar.getMgDl();
            }
        }
        int yStep = (int) ((yMax - yMin) / 5);
        yStep = Math.round((yStep + 10) / 10) * 10;
        // Labels for y axis
        int labelValue = yStep;
        float labelY;
        while ((labelY = contentStartY + contentHeight - ((labelValue / yMax) * contentHeight)) >= contentStartY) {
            label.setText(PreferenceStore.getInstance().getMeasurementForUi(Category.BLOODSUGAR, labelValue));
            label.setPosition(chartStartX, labelY + (label.getHeight() / 4));
            label.placeIn(chart);
            label.drawOn(page);
            line.setStartPoint(chartStartX + label.getWidth() + PADDING, labelY);
            line.setEndPoint(contentEndX, labelY);
            line.placeIn(chart);
            line.drawOn(page);
            labelValue += yStep;
        }
        Point point = new Point();
        point.setFillShape(true);
        point.setRadius(POINT_RADIUS);
        for (BloodSugar bloodSugar : bloodSugars) {
            Entry entry = bloodSugar.getEntry();
            float minute = entry.getDate().getMinuteOfDay();
            float value = bloodSugar.getMgDl();
            float x = contentStartX + ((minute / xMax) * contentWidth);
            float y = contentStartY + (contentHeight - (value / yMax) * contentHeight);
            point.setPosition(x, y);
            int color = Color.black;
            if (cache.getConfig().highlightLimits()) {
                if (value > PreferenceStore.getInstance().getLimitHyperglycemia()) {
                    color = cache.getColorHyperglycemia();
                } else if (value < PreferenceStore.getInstance().getLimitHypoglycemia()) {
                    color = cache.getColorHypoglycemia();
                }
            }
            point.setColor(color);
            point.placeIn(chart);
            point.drawOn(page);
        }
    }
    return new Point(position.getX(), coordinates[1]);
}
Also used : Line(com.pdfjet.Line) TextLine(com.pdfjet.TextLine) Entry(com.faltenreich.diaguard.shared.data.database.entity.Entry) TextLine(com.pdfjet.TextLine) Point(com.pdfjet.Point) BloodSugar(com.faltenreich.diaguard.shared.data.database.entity.BloodSugar) Point(com.pdfjet.Point)

Example 18 with Entry

use of com.faltenreich.diaguard.shared.data.database.entity.Entry in project Diaguard by Faltenreich.

the class LogFetchDataTask method getListItems.

private List<LogListItem> getListItems(DateTime startDate, boolean scrollingDown) {
    List<LogListItem> listItems = new ArrayList<>();
    DateTime date = startDate;
    boolean loadMore = true;
    while (loadMore) {
        List<Entry> entries = EntryDao.getInstance().getEntriesOfDay(date);
        for (Entry entry : entries) {
            List<Measurement> measurements = EntryDao.getInstance().getMeasurements(entry);
            entry.setMeasurementCache(measurements);
        }
        if (entries.size() > 0) {
            LogEntryListItem firstListItemEntryOfDay = null;
            for (int entryIndex = 0; entryIndex < entries.size(); entryIndex++) {
                Entry entry = entries.get(entryIndex);
                List<EntryTag> entryTags = EntryTagDao.getInstance().getAll(entry);
                List<FoodEaten> foodEaten = new ArrayList<>();
                for (Measurement measurement : entry.getMeasurementCache()) {
                    if (measurement instanceof Meal) {
                        foodEaten.addAll(FoodEatenDao.getInstance().getAll((Meal) measurement));
                    }
                }
                LogEntryListItem listItemEntry = new LogEntryListItem(entry, entryTags, foodEaten);
                if (entryIndex == 0) {
                    firstListItemEntryOfDay = listItemEntry;
                }
                listItemEntry.setFirstListItemEntryOfDay(firstListItemEntryOfDay);
                listItems.add(scrollingDown ? listItems.size() : entryIndex, listItemEntry);
            }
        } else {
            listItems.add(scrollingDown ? listItems.size() : 0, new LogEmptyListItem(date));
        }
        boolean isFirstDayOfMonth = date.dayOfMonth().get() == 1;
        if (isFirstDayOfMonth) {
            listItems.add(scrollingDown ? listItems.size() - 1 : 0, new LogMonthListItem(date));
        }
        loadMore = listItems.size() < (EndlessAdapter.BULK_SIZE);
        date = scrollingDown ? date.plusDays(1) : date.minusDays(1);
    }
    return listItems;
}
Also used : Measurement(com.faltenreich.diaguard.shared.data.database.entity.Measurement) LogEmptyListItem(com.faltenreich.diaguard.feature.log.empty.LogEmptyListItem) EntryTag(com.faltenreich.diaguard.shared.data.database.entity.EntryTag) Meal(com.faltenreich.diaguard.shared.data.database.entity.Meal) ArrayList(java.util.ArrayList) FoodEaten(com.faltenreich.diaguard.shared.data.database.entity.FoodEaten) LogMonthListItem(com.faltenreich.diaguard.feature.log.month.LogMonthListItem) DateTime(org.joda.time.DateTime) Entry(com.faltenreich.diaguard.shared.data.database.entity.Entry) LogEntryListItem(com.faltenreich.diaguard.feature.log.entry.LogEntryListItem)

Example 19 with Entry

use of com.faltenreich.diaguard.shared.data.database.entity.Entry in project Diaguard by Faltenreich.

the class TestDataImport method importData.

@Override
public void importData() {
    for (int count = 0; count < DATA_COUNT; count++) {
        DateTime dateTime = DateTime.now().minusHours(count);
        Entry entry = new Entry();
        entry.setDate(dateTime);
        EntryDao.getInstance().createOrUpdate(entry);
        BloodSugar bloodSugar = new BloodSugar();
        bloodSugar.setMgDl(120);
        bloodSugar.setEntry(entry);
        MeasurementDao.getInstance(BloodSugar.class).createOrUpdate(bloodSugar);
        Log.d(TAG, "Created test data: " + (count + 1) + "/" + DATA_COUNT);
    }
}
Also used : Entry(com.faltenreich.diaguard.shared.data.database.entity.Entry) BloodSugar(com.faltenreich.diaguard.shared.data.database.entity.BloodSugar) DateTime(org.joda.time.DateTime)

Example 20 with Entry

use of com.faltenreich.diaguard.shared.data.database.entity.Entry 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)

Aggregations

Entry (com.faltenreich.diaguard.shared.data.database.entity.Entry)32 Measurement (com.faltenreich.diaguard.shared.data.database.entity.Measurement)17 ArrayList (java.util.ArrayList)15 Category (com.faltenreich.diaguard.shared.data.database.entity.Category)13 EntryTag (com.faltenreich.diaguard.shared.data.database.entity.EntryTag)10 FoodEaten (com.faltenreich.diaguard.shared.data.database.entity.FoodEaten)9 Tag (com.faltenreich.diaguard.shared.data.database.entity.Tag)8 DateTime (org.joda.time.DateTime)8 BloodSugar (com.faltenreich.diaguard.shared.data.database.entity.BloodSugar)7 Meal (com.faltenreich.diaguard.shared.data.database.entity.Meal)7 List (java.util.List)7 Nullable (androidx.annotation.Nullable)5 EntryAddedEvent (com.faltenreich.diaguard.shared.event.data.EntryAddedEvent)5 View (android.view.View)4 ImageView (android.widget.ImageView)4 Food (com.faltenreich.diaguard.shared.data.database.entity.Food)4 EntryDeletedEvent (com.faltenreich.diaguard.shared.event.data.EntryDeletedEvent)4 ChipView (com.faltenreich.diaguard.shared.view.chip.ChipView)4 Context (android.content.Context)3 LayoutInflater (android.view.LayoutInflater)3