use of com.faltenreich.diaguard.feature.log.month.LogMonthListItem in project Diaguard by Faltenreich.
the class LogFetchDataTask method getListItems.
private List<LogListItem> getListItems(DateTime startDate, boolean scrollingDown) {
List<LogListItem> listItems = new ArrayList<>();
DateTime date = startDate;
boolean loadMore = true;
while (loadMore) {
List<Entry> entries = EntryDao.getInstance().getEntriesOfDay(date);
for (Entry entry : entries) {
List<Measurement> measurements = EntryDao.getInstance().getMeasurements(entry);
entry.setMeasurementCache(measurements);
}
if (entries.size() > 0) {
LogEntryListItem firstListItemEntryOfDay = null;
for (int entryIndex = 0; entryIndex < entries.size(); entryIndex++) {
Entry entry = entries.get(entryIndex);
List<EntryTag> entryTags = EntryTagDao.getInstance().getAll(entry);
List<FoodEaten> foodEaten = new ArrayList<>();
for (Measurement measurement : entry.getMeasurementCache()) {
if (measurement instanceof Meal) {
foodEaten.addAll(FoodEatenDao.getInstance().getAll((Meal) measurement));
}
}
LogEntryListItem listItemEntry = new LogEntryListItem(entry, entryTags, foodEaten);
if (entryIndex == 0) {
firstListItemEntryOfDay = listItemEntry;
}
listItemEntry.setFirstListItemEntryOfDay(firstListItemEntryOfDay);
listItems.add(scrollingDown ? listItems.size() : entryIndex, listItemEntry);
}
} else {
listItems.add(scrollingDown ? listItems.size() : 0, new LogEmptyListItem(date));
}
boolean isFirstDayOfMonth = date.dayOfMonth().get() == 1;
if (isFirstDayOfMonth) {
listItems.add(scrollingDown ? listItems.size() - 1 : 0, new LogMonthListItem(date));
}
loadMore = listItems.size() < (EndlessAdapter.BULK_SIZE);
date = scrollingDown ? date.plusDays(1) : date.minusDays(1);
}
return listItems;
}
Aggregations