Search in sources :

Example 6 with Entry

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

the class EntryEditFragment method showTimePicker.

private void showTimePicker() {
    Entry entry = viewModel.getEntry();
    TimePickerFragment.newInstance(entry.getDate(), (view, hourOfDay, minute) -> {
        DateTime dateTime = viewModel.getEntry().getDate().withHourOfDay(hourOfDay).withMinuteOfHour(minute);
        viewModel.getEntry().setDate(dateTime);
        invalidateDateTime();
    }).show(getChildFragmentManager());
}
Also used : MeasurementView(com.faltenreich.diaguard.feature.entry.edit.measurement.MeasurementView) LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) FoodSearchEvent(com.faltenreich.diaguard.shared.event.ui.FoodSearchEvent) NestedScrollView(androidx.core.widget.NestedScrollView) NonNull(androidx.annotation.NonNull) EntryTagDao(com.faltenreich.diaguard.shared.data.database.dao.EntryTagDao) ImageView(android.widget.ImageView) FoodSearchFragment(com.faltenreich.diaguard.feature.food.search.FoodSearchFragment) Tag(com.faltenreich.diaguard.shared.data.database.entity.Tag) Measurement(com.faltenreich.diaguard.shared.data.database.entity.Measurement) Food(com.faltenreich.diaguard.shared.data.database.entity.Food) Handler(android.os.Handler) View(android.view.View) Button(android.widget.Button) Log(android.util.Log) FoodEaten(com.faltenreich.diaguard.shared.data.database.entity.FoodEaten) CategoryComparatorFactory(com.faltenreich.diaguard.feature.category.CategoryComparatorFactory) BaseFragment(com.faltenreich.diaguard.shared.view.fragment.BaseFragment) EntryDao(com.faltenreich.diaguard.shared.data.database.dao.EntryDao) FragmentEntryEditBinding(com.faltenreich.diaguard.databinding.FragmentEntryEditBinding) TimePickerFragment(com.faltenreich.diaguard.feature.datetime.TimePickerFragment) ChipView(com.faltenreich.diaguard.shared.view.chip.ChipView) ThreadMode(org.greenrobot.eventbus.ThreadMode) NumberPickerDialog(com.faltenreich.diaguard.shared.view.picker.NumberPickerDialog) ViewGroup(android.view.ViewGroup) AlertDialog(android.app.AlertDialog) R(com.faltenreich.diaguard.R) StringUtils(com.faltenreich.diaguard.shared.data.primitive.StringUtils) List(java.util.List) Nullable(androidx.annotation.Nullable) EditorInfo(android.view.inputmethod.EditorInfo) AlarmUtils(com.faltenreich.diaguard.feature.alarm.AlarmUtils) MainButton(com.faltenreich.diaguard.feature.navigation.MainButton) LocalTime(org.joda.time.LocalTime) ChipGroup(com.google.android.material.chip.ChipGroup) TagDao(com.faltenreich.diaguard.shared.data.database.dao.TagDao) Meal(com.faltenreich.diaguard.shared.data.database.entity.Meal) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) Helper(com.faltenreich.diaguard.shared.Helper) EntryDeletedEvent(com.faltenreich.diaguard.shared.event.data.EntryDeletedEvent) EntryAddedEvent(com.faltenreich.diaguard.shared.event.data.EntryAddedEvent) ToolbarDescribing(com.faltenreich.diaguard.feature.navigation.ToolbarDescribing) Events(com.faltenreich.diaguard.shared.event.Events) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) Category(com.faltenreich.diaguard.shared.data.database.entity.Category) Menu(android.view.Menu) TagAutoCompleteAdapter(com.faltenreich.diaguard.feature.tag.TagAutoCompleteAdapter) DatePickerFragment(com.faltenreich.diaguard.feature.datetime.DatePickerFragment) TagListFragment(com.faltenreich.diaguard.feature.tag.TagListFragment) EntryTag(com.faltenreich.diaguard.shared.data.database.entity.EntryTag) ViewUtils(com.faltenreich.diaguard.shared.view.ViewUtils) LayoutInflater(android.view.LayoutInflater) ObjectFactory(com.faltenreich.diaguard.shared.data.reflect.ObjectFactory) DateTime(org.joda.time.DateTime) MeasurementFloatingActionMenu(com.faltenreich.diaguard.feature.entry.edit.measurement.MeasurementFloatingActionMenu) Entry(com.faltenreich.diaguard.shared.data.database.entity.Entry) MainButtonProperties(com.faltenreich.diaguard.feature.navigation.MainButtonProperties) AutoCompleteTextView(android.widget.AutoCompleteTextView) Subscribe(org.greenrobot.eventbus.Subscribe) MeasurementDao(com.faltenreich.diaguard.shared.data.database.dao.MeasurementDao) EntryUpdatedEvent(com.faltenreich.diaguard.shared.event.data.EntryUpdatedEvent) ToolbarProperties(com.faltenreich.diaguard.feature.navigation.ToolbarProperties) EditTextUtils(com.faltenreich.diaguard.shared.view.edittext.EditTextUtils) CategoryListFragment(com.faltenreich.diaguard.feature.category.CategoryListFragment) Collections(java.util.Collections) EditText(android.widget.EditText) DateTimeConstants(org.joda.time.DateTimeConstants) Entry(com.faltenreich.diaguard.shared.data.database.entity.Entry) DateTime(org.joda.time.DateTime)

Example 7 with Entry

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

the class EntryEditFragment method showDatePicker.

private void showDatePicker() {
    Entry entry = viewModel.getEntry();
    DatePickerFragment.newInstance(entry.getDate(), dateTime -> {
        if (dateTime != null) {
            LocalTime time = viewModel.getEntry().getDate() != null ? viewModel.getEntry().getDate().toLocalTime() : LocalTime.now();
            dateTime = dateTime.withTime(time);
            viewModel.getEntry().setDate(dateTime);
            invalidateDateTime();
        }
    }).show(getChildFragmentManager());
}
Also used : MeasurementView(com.faltenreich.diaguard.feature.entry.edit.measurement.MeasurementView) LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) FoodSearchEvent(com.faltenreich.diaguard.shared.event.ui.FoodSearchEvent) NestedScrollView(androidx.core.widget.NestedScrollView) NonNull(androidx.annotation.NonNull) EntryTagDao(com.faltenreich.diaguard.shared.data.database.dao.EntryTagDao) ImageView(android.widget.ImageView) FoodSearchFragment(com.faltenreich.diaguard.feature.food.search.FoodSearchFragment) Tag(com.faltenreich.diaguard.shared.data.database.entity.Tag) Measurement(com.faltenreich.diaguard.shared.data.database.entity.Measurement) Food(com.faltenreich.diaguard.shared.data.database.entity.Food) Handler(android.os.Handler) View(android.view.View) Button(android.widget.Button) Log(android.util.Log) FoodEaten(com.faltenreich.diaguard.shared.data.database.entity.FoodEaten) CategoryComparatorFactory(com.faltenreich.diaguard.feature.category.CategoryComparatorFactory) BaseFragment(com.faltenreich.diaguard.shared.view.fragment.BaseFragment) EntryDao(com.faltenreich.diaguard.shared.data.database.dao.EntryDao) FragmentEntryEditBinding(com.faltenreich.diaguard.databinding.FragmentEntryEditBinding) TimePickerFragment(com.faltenreich.diaguard.feature.datetime.TimePickerFragment) ChipView(com.faltenreich.diaguard.shared.view.chip.ChipView) ThreadMode(org.greenrobot.eventbus.ThreadMode) NumberPickerDialog(com.faltenreich.diaguard.shared.view.picker.NumberPickerDialog) ViewGroup(android.view.ViewGroup) AlertDialog(android.app.AlertDialog) R(com.faltenreich.diaguard.R) StringUtils(com.faltenreich.diaguard.shared.data.primitive.StringUtils) List(java.util.List) Nullable(androidx.annotation.Nullable) EditorInfo(android.view.inputmethod.EditorInfo) AlarmUtils(com.faltenreich.diaguard.feature.alarm.AlarmUtils) MainButton(com.faltenreich.diaguard.feature.navigation.MainButton) LocalTime(org.joda.time.LocalTime) ChipGroup(com.google.android.material.chip.ChipGroup) TagDao(com.faltenreich.diaguard.shared.data.database.dao.TagDao) Meal(com.faltenreich.diaguard.shared.data.database.entity.Meal) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) Helper(com.faltenreich.diaguard.shared.Helper) EntryDeletedEvent(com.faltenreich.diaguard.shared.event.data.EntryDeletedEvent) EntryAddedEvent(com.faltenreich.diaguard.shared.event.data.EntryAddedEvent) ToolbarDescribing(com.faltenreich.diaguard.feature.navigation.ToolbarDescribing) Events(com.faltenreich.diaguard.shared.event.Events) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) Category(com.faltenreich.diaguard.shared.data.database.entity.Category) Menu(android.view.Menu) TagAutoCompleteAdapter(com.faltenreich.diaguard.feature.tag.TagAutoCompleteAdapter) DatePickerFragment(com.faltenreich.diaguard.feature.datetime.DatePickerFragment) TagListFragment(com.faltenreich.diaguard.feature.tag.TagListFragment) EntryTag(com.faltenreich.diaguard.shared.data.database.entity.EntryTag) ViewUtils(com.faltenreich.diaguard.shared.view.ViewUtils) LayoutInflater(android.view.LayoutInflater) ObjectFactory(com.faltenreich.diaguard.shared.data.reflect.ObjectFactory) DateTime(org.joda.time.DateTime) MeasurementFloatingActionMenu(com.faltenreich.diaguard.feature.entry.edit.measurement.MeasurementFloatingActionMenu) Entry(com.faltenreich.diaguard.shared.data.database.entity.Entry) MainButtonProperties(com.faltenreich.diaguard.feature.navigation.MainButtonProperties) AutoCompleteTextView(android.widget.AutoCompleteTextView) Subscribe(org.greenrobot.eventbus.Subscribe) MeasurementDao(com.faltenreich.diaguard.shared.data.database.dao.MeasurementDao) EntryUpdatedEvent(com.faltenreich.diaguard.shared.event.data.EntryUpdatedEvent) ToolbarProperties(com.faltenreich.diaguard.feature.navigation.ToolbarProperties) EditTextUtils(com.faltenreich.diaguard.shared.view.edittext.EditTextUtils) CategoryListFragment(com.faltenreich.diaguard.feature.category.CategoryListFragment) Collections(java.util.Collections) EditText(android.widget.EditText) DateTimeConstants(org.joda.time.DateTimeConstants) Entry(com.faltenreich.diaguard.shared.data.database.entity.Entry) LocalTime(org.joda.time.LocalTime)

Example 8 with Entry

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

the class EntryEditFragment method deleteEntry.

private void deleteEntry() {
    Entry entry = viewModel.getEntry();
    if (entry != null) {
        EntryDao.getInstance().delete(entry);
        finish();
        Events.unregister(this);
        Events.post(new EntryDeletedEvent(entry, viewModel.getEntryTags(), getFoodEaten()));
    }
}
Also used : Entry(com.faltenreich.diaguard.shared.data.database.entity.Entry) EntryDeletedEvent(com.faltenreich.diaguard.shared.event.data.EntryDeletedEvent)

Example 9 with Entry

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

the class EntryEditViewModel method createEntry.

private void createEntry() {
    entry = new Entry();
    entry.setDate(dateTime);
    if (category != null) {
        Measurement measurement = ObjectFactory.createFromClass(category.toClass());
        measurement.setEntry(entry);
        entry.getMeasurementCache().add(measurement);
    }
}
Also used : Measurement(com.faltenreich.diaguard.shared.data.database.entity.Measurement) Entry(com.faltenreich.diaguard.shared.data.database.entity.Entry)

Example 10 with Entry

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

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