Search in sources :

Example 31 with Entry

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;
}
Also used : Context(android.content.Context) Entry(com.faltenreich.diaguard.shared.data.database.entity.Entry) Interval(org.joda.time.Interval)

Example 32 with Entry

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));
    });
}
Also used : Measurement(com.faltenreich.diaguard.shared.data.database.entity.Measurement) Entry(com.faltenreich.diaguard.shared.data.database.entity.Entry) EntryTag(com.faltenreich.diaguard.shared.data.database.entity.EntryTag) EntryAddedEvent(com.faltenreich.diaguard.shared.event.data.EntryAddedEvent) Subscribe(org.greenrobot.eventbus.Subscribe)

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