use of com.faltenreich.diaguard.feature.log.empty.LogEmptyListItem in project Diaguard by Faltenreich.
the class LogFragment method addEntry.
private void addEntry(Entry entry, List<EntryTag> entryTags, List<FoodEaten> foodEatenList) {
if (entry != null) {
DateTime date = entry.getDate();
int position = listAdapter.getNextDateTimePosition(date);
if (position >= 0) {
// Remove any existing empty view
int previousPosition = position - 1;
LogListItem previousListItem = listAdapter.getItem(previousPosition);
if (previousListItem instanceof LogEmptyListItem && previousListItem.getDateTime().getDayOfYear() == date.getDayOfYear()) {
listAdapter.removeItem(previousPosition);
listAdapter.notifyItemRemoved(previousPosition);
position = previousPosition;
}
entry.setMeasurementCache(EntryDao.getInstance().getMeasurements(entry));
LogEntryListItem listItemEntry = new LogEntryListItem(entry, entryTags, foodEatenList);
listAdapter.addItem(position, listItemEntry);
listAdapter.notifyItemInserted(position);
updateHeaderSection(date);
}
}
}
use of com.faltenreich.diaguard.feature.log.empty.LogEmptyListItem 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;
}
use of com.faltenreich.diaguard.feature.log.empty.LogEmptyListItem in project Diaguard by Faltenreich.
the class LogFragment method removeEntry.
private void removeEntry(int position) {
DateTime dateTime = listAdapter.getItem(position).getDateTime();
listAdapter.removeItem(position);
// Add empty view if there is no entry available anymore for this day
boolean hasNoMoreEntries = listAdapter.getFirstListItemEntryOfDayPosition(dateTime) == -1;
if (hasNoMoreEntries) {
listAdapter.addItem(position, new LogEmptyListItem(dateTime));
listAdapter.notifyItemChanged(position);
} else {
listAdapter.notifyItemRemoved(position);
}
updateHeaderSection(dateTime);
}
Aggregations