use of com.faltenreich.diaguard.shared.data.database.entity.Food 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));
});
}
use of com.faltenreich.diaguard.shared.data.database.entity.Food in project Diaguard by Faltenreich.
the class FoodSearchViewHolder method onBind.
@Override
protected void onBind(FoodSearchListItem item) {
Food food = item.getFood();
getBinding().nameLabel.setText(food.getName());
getBinding().brandLabel.setText(food.getBrand());
getBinding().brandLabel.setVisibility(StringUtils.isBlank(food.getBrand()) ? View.GONE : View.VISIBLE);
getBinding().valueLabel.setText(food.getValueForUi());
getBinding().recentIndicator.setVisibility(item.getFoodEaten() != null ? View.VISIBLE : View.GONE);
}
use of com.faltenreich.diaguard.shared.data.database.entity.Food in project Diaguard by Faltenreich.
the class MigrateSodiumTask method doInBackground.
@Override
protected Void doInBackground(Void... voids) {
List<Food> foodList = FoodDao.getInstance().getAllCommon();
for (Food food : foodList) {
Float sodium = food.getSodium();
food.setSodium(sodium != null && sodium > 0 ? sodium / 1000 : null);
}
FoodDao.getInstance().bulkCreateOrUpdate(foodList);
Log.i(TAG, String.format("Fixed sodium of %d common food items", foodList.size()));
return null;
}
use of com.faltenreich.diaguard.shared.data.database.entity.Food in project Diaguard by Faltenreich.
the class FoodInputViewHolder method onBind.
@SuppressLint("RestrictedApi")
@Override
protected void onBind(FoodEaten item) {
Food food = item.getFood();
getBinding().nameLabel.setText(food.getName());
getBinding().valueLabel.setText(String.format("%s %s", food.getValueForUi(), PreferenceStore.getInstance().getLabelForMealPer100g(getContext())));
getBinding().deleteButton.setContentDescription(String.format(getContext().getString(R.string.remove_placeholder), food.getName()));
boolean isSet = item.isValid();
String text = isSet ? String.format("%s %s", FloatUtils.parseFloat(item.getAmountInGrams()), getContext().getString(R.string.grams_milliliters_acronym)) : getContext().getString(R.string.amount);
int backgroundColor = isSet ? ColorUtils.getBackgroundTertiary(getContext()) : ColorUtils.getPrimaryColor(getContext());
int textColor = isSet ? ColorUtils.getTextColorPrimary(getContext()) : Color.WHITE;
AppCompatButton amountButton = getBinding().amountButton;
amountButton.setText(text);
amountButton.setSupportBackgroundTintList(ColorStateList.valueOf(backgroundColor));
amountButton.setTextColor(textColor);
}
use of com.faltenreich.diaguard.shared.data.database.entity.Food in project Diaguard by Faltenreich.
the class FoodDao method search.
public List<Food> search(String query, long page, boolean showCustomFood, boolean showCommonFood, boolean showBrandedFood) {
if (!showCustomFood && !showCommonFood && !showBrandedFood) {
return new ArrayList<>();
}
try {
QueryBuilder<Food, Long> queryBuilder = getQueryBuilder().orderByRaw(String.format("%s COLLATE NOCASE", Food.Column.NAME)).orderBy(Food.Column.UPDATED_AT, false).offset(page * BaseDao.PAGE_SIZE).limit(BaseDao.PAGE_SIZE);
Where<Food, Long> where = queryBuilder.where();
where.isNull(Food.Column.DELETED_AT);
if (query != null && query.length() > 0) {
where.and();
where.like(Food.Column.NAME, new SelectArg("%" + query + "%"));
}
int whereTypeCount = 0;
if (showCustomFood) {
where.isNull(Food.Column.LABELS);
where.isNull(Food.Column.SERVER_ID);
where.and(2);
whereTypeCount++;
}
if (showCommonFood) {
where.isNotNull(Food.Column.LABELS);
where.isNull(Food.Column.SERVER_ID);
where.and(2);
whereTypeCount++;
}
if (showBrandedFood) {
where.isNotNull(Food.Column.SERVER_ID);
whereTypeCount++;
}
where.or(whereTypeCount);
where.and(2);
return where.query();
} catch (SQLException exception) {
Log.e(TAG, exception.toString());
return new ArrayList<>();
}
}
Aggregations