Search in sources :

Example 1 with Meal

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

the class MeasurementDao method delete.

@Override
public int delete(M object) {
    if (object.getCategory() == Category.MEAL) {
        Meal meal = (Meal) object;
        for (FoodEaten foodEaten : meal.getFoodEaten()) {
            meal.getFoodEatenCache().add(foodEaten);
            FoodEatenDao.getInstance().delete(foodEaten);
        }
    }
    return super.delete(object);
}
Also used : Meal(com.faltenreich.diaguard.shared.data.database.entity.Meal) FoodEaten(com.faltenreich.diaguard.shared.data.database.entity.FoodEaten)

Example 2 with Meal

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

the class MeasurementDao method getAvgMeasurement.

public Measurement getAvgMeasurement(Category category, Interval interval) {
    long daysBetween = interval.toDuration().getStandardDays() + 1;
    switch(category) {
        case BLOODSUGAR:
            BloodSugar bloodSugar = new BloodSugar();
            bloodSugar.setMgDl(function(SqlFunction.AVG, BloodSugar.Column.MGDL, interval));
            return bloodSugar;
        case INSULIN:
            Insulin insulin = new Insulin();
            insulin.setBolus(function(SqlFunction.SUM, Insulin.Column.BOLUS, interval) / daysBetween);
            insulin.setBasal(function(SqlFunction.SUM, Insulin.Column.BASAL, interval) / daysBetween);
            insulin.setCorrection(function(SqlFunction.SUM, Insulin.Column.CORRECTION, interval) / daysBetween);
            return insulin;
        case MEAL:
            Meal meal = new Meal();
            float avg = function(SqlFunction.SUM, Meal.Column.CARBOHYDRATES, interval) / daysBetween;
            float foodEatenSum = 0;
            List<FoodEaten> foodEatenList = FoodEatenDao.getInstance().getAll(interval);
            for (FoodEaten foodEaten : foodEatenList) {
                foodEatenSum += foodEaten.getCarbohydrates();
            }
            avg = avg + (foodEatenSum / daysBetween);
            meal.setCarbohydrates(avg);
            return meal;
        case ACTIVITY:
            Activity activity = new Activity();
            activity.setMinutes((int) (function(SqlFunction.SUM, Activity.Column.MINUTES, interval) / daysBetween));
            return activity;
        case HBA1C:
            HbA1c hbA1c = new HbA1c();
            hbA1c.setPercent(function(SqlFunction.AVG, HbA1c.Column.PERCENT, interval));
            return hbA1c;
        case WEIGHT:
            Weight weight = new Weight();
            weight.setKilogram(function(SqlFunction.AVG, Weight.Column.KILOGRAM, interval));
            return weight;
        case PULSE:
            Pulse pulse = new Pulse();
            pulse.setFrequency(function(SqlFunction.AVG, Pulse.Column.FREQUENCY, interval));
            return pulse;
        case PRESSURE:
            Pressure pressure = new Pressure();
            pressure.setSystolic(function(SqlFunction.AVG, Pressure.Column.SYSTOLIC, interval));
            pressure.setDiastolic(function(SqlFunction.AVG, Pressure.Column.DIASTOLIC, interval));
            return pressure;
        case OXYGEN_SATURATION:
            OxygenSaturation oxygenSaturation = new OxygenSaturation();
            oxygenSaturation.setPercent(function(SqlFunction.AVG, OxygenSaturation.Column.PERCENT, interval));
            return oxygenSaturation;
        default:
            return null;
    }
}
Also used : Meal(com.faltenreich.diaguard.shared.data.database.entity.Meal) Pulse(com.faltenreich.diaguard.shared.data.database.entity.Pulse) FoodEaten(com.faltenreich.diaguard.shared.data.database.entity.FoodEaten) Activity(com.faltenreich.diaguard.shared.data.database.entity.Activity) OxygenSaturation(com.faltenreich.diaguard.shared.data.database.entity.OxygenSaturation) BloodSugar(com.faltenreich.diaguard.shared.data.database.entity.BloodSugar) Insulin(com.faltenreich.diaguard.shared.data.database.entity.Insulin) Pressure(com.faltenreich.diaguard.shared.data.database.entity.Pressure) Weight(com.faltenreich.diaguard.shared.data.database.entity.Weight) HbA1c(com.faltenreich.diaguard.shared.data.database.entity.HbA1c)

Example 3 with Meal

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

the class EntryEditFragment method getFoodEaten.

private List<FoodEaten> getFoodEaten() {
    for (int index = 0; index < measurementContainer.getChildCount(); index++) {
        View view = measurementContainer.getChildAt(index);
        if (view instanceof MeasurementView) {
            MeasurementView<?> measurementView = ((MeasurementView<?>) view);
            Measurement measurement = measurementView.getMeasurement();
            if (measurement instanceof Meal) {
                List<FoodEaten> foodEatenList = new ArrayList<>();
                for (FoodEaten foodEaten : ((Meal) measurement).getFoodEatenCache()) {
                    if (foodEaten.isValid()) {
                        foodEatenList.add(foodEaten);
                    }
                }
                return foodEatenList;
            }
        }
    }
    return new ArrayList<>();
}
Also used : Measurement(com.faltenreich.diaguard.shared.data.database.entity.Measurement) MeasurementView(com.faltenreich.diaguard.feature.entry.edit.measurement.MeasurementView) Meal(com.faltenreich.diaguard.shared.data.database.entity.Meal) FoodEaten(com.faltenreich.diaguard.shared.data.database.entity.FoodEaten) ArrayList(java.util.ArrayList) MeasurementView(com.faltenreich.diaguard.feature.entry.edit.measurement.MeasurementView) NestedScrollView(androidx.core.widget.NestedScrollView) ImageView(android.widget.ImageView) View(android.view.View) ChipView(com.faltenreich.diaguard.shared.view.chip.ChipView) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Example 4 with Meal

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

the class MeasurementView method init.

private void init() {
    binding = ListItemMeasurementBinding.inflate(LayoutInflater.from(getContext()), this);
    View inputView;
    Category category = measurement.getCategory();
    switch(category) {
        case INSULIN:
            inputView = new InsulinInputView(getContext(), (Insulin) measurement);
            break;
        case MEAL:
            inputView = new MealInputView(getContext(), (Meal) measurement);
            break;
        case PRESSURE:
            inputView = new PressureInputView(getContext(), (Pressure) measurement);
            break;
        default:
            inputView = new GenericInputView<>(getContext(), category.toClass(), measurement);
    }
    // noinspection unchecked
    this.inputView = (MeasurementInputView<?, T>) inputView;
}
Also used : PressureInputView(com.faltenreich.diaguard.feature.entry.edit.input.PressureInputView) Category(com.faltenreich.diaguard.shared.data.database.entity.Category) InsulinInputView(com.faltenreich.diaguard.feature.entry.edit.input.InsulinInputView) Meal(com.faltenreich.diaguard.shared.data.database.entity.Meal) GenericInputView(com.faltenreich.diaguard.feature.entry.edit.input.GenericInputView) PressureInputView(com.faltenreich.diaguard.feature.entry.edit.input.PressureInputView) ImageView(android.widget.ImageView) InsulinInputView(com.faltenreich.diaguard.feature.entry.edit.input.InsulinInputView) View(android.view.View) CardView(androidx.cardview.widget.CardView) MeasurementInputView(com.faltenreich.diaguard.feature.entry.edit.input.MeasurementInputView) MealInputView(com.faltenreich.diaguard.feature.entry.edit.input.MealInputView) TextView(android.widget.TextView) Insulin(com.faltenreich.diaguard.shared.data.database.entity.Insulin) Pressure(com.faltenreich.diaguard.shared.data.database.entity.Pressure) MealInputView(com.faltenreich.diaguard.feature.entry.edit.input.MealInputView)

Example 5 with Meal

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

the class CalculatorFragment method storeValues.

private void storeValues(float mgDl, float carbohydrates, float bolus, float correction) {
    DateTime now = DateTime.now();
    Entry entry = new Entry();
    entry.setDate(now);
    EntryDao.getInstance().createOrUpdate(entry);
    BloodSugar bloodSugar = new BloodSugar();
    bloodSugar.setMgDl(mgDl);
    bloodSugar.setEntry(entry);
    MeasurementDao.getInstance(BloodSugar.class).createOrUpdate(bloodSugar);
    List<FoodEaten> foodEatenList = new ArrayList<>();
    if (carbohydrates > 0) {
        FoodInputView foodInputView = getBinding().foodInputView;
        foodEatenList.addAll(foodInputView.getFoodEatenList());
        meal.setCarbohydrates(foodInputView.getInputCarbohydrates());
        meal.setEntry(entry);
        MeasurementDao.getInstance(Meal.class).createOrUpdate(meal);
        for (FoodEaten foodEaten : foodEatenList) {
            if (foodEaten.getAmountInGrams() > 0) {
                foodEaten.setMeal(meal);
                FoodEatenDao.getInstance().createOrUpdate(foodEaten);
            }
        }
    }
    if (bolus > 0 || correction > 0) {
        Insulin insulin = new Insulin();
        insulin.setBolus(bolus);
        insulin.setCorrection(correction);
        insulin.setEntry(entry);
        MeasurementDao.getInstance(Insulin.class).createOrUpdate(insulin);
    }
    Events.post(new EntryAddedEvent(entry, null, foodEatenList));
    openEntry(entry);
    clearInput();
    update();
}
Also used : Entry(com.faltenreich.diaguard.shared.data.database.entity.Entry) FoodInputView(com.faltenreich.diaguard.feature.food.input.FoodInputView) Meal(com.faltenreich.diaguard.shared.data.database.entity.Meal) FoodEaten(com.faltenreich.diaguard.shared.data.database.entity.FoodEaten) ArrayList(java.util.ArrayList) EntryAddedEvent(com.faltenreich.diaguard.shared.event.data.EntryAddedEvent) BloodSugar(com.faltenreich.diaguard.shared.data.database.entity.BloodSugar) Insulin(com.faltenreich.diaguard.shared.data.database.entity.Insulin) DateTime(org.joda.time.DateTime)

Aggregations

Meal (com.faltenreich.diaguard.shared.data.database.entity.Meal)13 FoodEaten (com.faltenreich.diaguard.shared.data.database.entity.FoodEaten)11 ArrayList (java.util.ArrayList)8 Category (com.faltenreich.diaguard.shared.data.database.entity.Category)6 Entry (com.faltenreich.diaguard.shared.data.database.entity.Entry)6 Measurement (com.faltenreich.diaguard.shared.data.database.entity.Measurement)6 EntryTag (com.faltenreich.diaguard.shared.data.database.entity.EntryTag)5 Insulin (com.faltenreich.diaguard.shared.data.database.entity.Insulin)5 BloodSugar (com.faltenreich.diaguard.shared.data.database.entity.BloodSugar)4 Tag (com.faltenreich.diaguard.shared.data.database.entity.Tag)4 DateTime (org.joda.time.DateTime)4 View (android.view.View)3 Pressure (com.faltenreich.diaguard.shared.data.database.entity.Pressure)3 List (java.util.List)3 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 Nullable (androidx.annotation.Nullable)2 FoodInputView (com.faltenreich.diaguard.feature.food.input.FoodInputView)2 Food (com.faltenreich.diaguard.shared.data.database.entity.Food)2 AlertDialog (android.app.AlertDialog)1