use of com.faltenreich.diaguard.shared.event.data.FoodSavedEvent in project Diaguard by Faltenreich.
the class FoodEditFragment method store.
private void store() {
if (isValid()) {
if (food == null) {
food = new Food();
}
food.setLanguageCode(Helper.getLanguageCode());
food.setName(getBinding().nameInput.getText());
food.setBrand(getBinding().brandInput.getText());
food.setIngredients(getBinding().ingredientsInput.getText());
// FIXME: 4-digit carbohydrates are stored as 1-digit with 3 decimal places
for (Map.Entry<Food.Nutrient, Float> entry : getBinding().nutrientInputLayout.getValues().entrySet()) {
Food.Nutrient nutrient = entry.getKey();
Float value = entry.getValue();
// Auto-fill carbohydrates for user
if (nutrient == Food.Nutrient.CARBOHYDRATES && value == null) {
value = 0f;
}
nutrient.setValue(food, value != null ? value : -1);
}
FoodDao.getInstance().createOrUpdate(food);
Events.post(new FoodSavedEvent(food));
finish();
}
}
use of com.faltenreich.diaguard.shared.event.data.FoodSavedEvent in project Diaguard by Faltenreich.
the class FoodSearchFragment method onEvent.
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEvent(final FoodDeletedEvent event) {
removeItem(event.context);
ViewUtils.showSnackbar(getView(), getString(R.string.food_deleted), v -> {
Food food = event.context;
food.setDeletedAt(null);
FoodDao.getInstance().createOrUpdate(food);
Events.post(new FoodSavedEvent(food));
});
}
Aggregations