use of com.faltenreich.diaguard.shared.data.database.entity.Entry in project Diaguard by Faltenreich.
the class AlarmUtils method getMessageForMeasurement.
private static String getMessageForMeasurement() {
Context context = DiaguardApplication.getContext();
Entry lastMeasurement = EntryDao.getInstance().getLatestWithMeasurement(BloodSugar.class);
String message = context.getString(R.string.alarm_desc_first);
if (lastMeasurement != null) {
// Calculate how long the last measurement has been ago
Interval interval = new Interval(lastMeasurement.getDate(), DateTime.now());
if (Minutes.minutesIn(interval).getMinutes() < 120) {
message = String.format(context.getString(R.string.alarm_desc), Integer.toString(Minutes.minutesIn(interval).getMinutes()) + " " + context.getString(R.string.minutes));
} else {
message = String.format(context.getString(R.string.alarm_desc), Integer.toString(Hours.hoursIn(interval).getHours()) + " " + context.getString(R.string.hours));
}
}
return message;
}
use of com.faltenreich.diaguard.shared.data.database.entity.Entry in project Diaguard by Faltenreich.
the class BaseFragment method onEvent.
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEvent(final EntryDeletedEvent event) {
if (getView() == null) {
return;
}
ViewUtils.showSnackbar(getView(), getString(R.string.entry_deleted), v -> {
Entry entry = event.context;
EntryDao.getInstance().createOrUpdate(entry);
for (Measurement measurement : entry.getMeasurementCache()) {
measurement.setEntry(entry);
// noinspection unchecked
MeasurementDao.getInstance(measurement.getClass()).createOrUpdate(measurement);
}
for (EntryTag entryTag : event.entryTags) {
entryTag.setEntry(entry);
EntryTagDao.getInstance().createOrUpdate(entryTag);
}
Events.post(new EntryAddedEvent(entry, event.entryTags, event.foodEatenList));
});
}
Aggregations