use of com.faltenreich.diaguard.feature.food.networking.dto.ProductDto in project Diaguard by Faltenreich.
the class FoodDao method createOrUpdate.
public List<Food> createOrUpdate(@NonNull SearchResponseDto dto) {
String languageCode = Helper.getLanguageCode();
List<Food> foodList = new ArrayList<>();
Collections.reverse(dto.products);
for (ProductDto productDto : dto.products) {
// Workaround: API returns products in other languages even though defined otherwise through GET parameters
boolean isSameLanguage = languageCode.equals(productDto.languageCode);
if (isSameLanguage && productDto.isValid()) {
Food food = parseFromDto(productDto);
if (food != null) {
foodList.add(0, food);
}
}
}
FoodDao.getInstance().bulkCreateOrUpdate(foodList);
return foodList;
}
Aggregations