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()));
}
}
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]);
}
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;
}
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);
}
}
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());
}
}
Aggregations