/** * Whether a section's contents are visually empty * * @return */ protected boolean isEmpty() { return children.isEmpty() || getItemCount(children) == 0; }
@Override public void addAll(@NonNull Collection<? extends Group> groups) { if (groups.isEmpty()) return; super.addAll(groups); int position = getItemCountWithoutFooter(); this.children.addAll(groups); notifyItemRangeInserted(position, getItemCount(groups)); refreshEmptyState(); }
private int getBodyItemCount() { return isPlaceholderVisible ? getPlaceholderItemCount() : getItemCount(children); }
@Override public void addAll(int position, @NonNull Collection<? extends Group> groups) { if (groups.isEmpty()) { return; } super.addAll(position, groups); this.children.addAll(position, groups); final int notifyPosition = getHeaderItemCount() + getItemCount(children.subList(0, position)); notifyItemRangeInserted(notifyPosition, getItemCount(groups)); refreshEmptyState(); }
@Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); if (!isAdded()) { return; } if (!hasMore) { return; } // The item count minus the footer int count = getMainSection().getItemCount() - 1; LinearLayoutManager layoutManager = getLayoutManager(); if (layoutManager != null) { if (layoutManager.findLastVisibleItemPosition() >= count) { showMore(); } } } };
@Override public void add(int position, @NonNull Group group) { super.add(position, group); children.add(position, group); final int notifyPosition = getHeaderItemCount() + getItemCount(children.subList(0, position)); notifyItemRangeInserted(notifyPosition, group.getItemCount()); refreshEmptyState(); }
final int oldBodyItemCount = getItemCount(oldBodyGroups); final int newBodyItemCount = getItemCount(newBodyGroups);
public void addAllWorksWithSets() { final Section testSection = new Section(); Set<Item> itemSet = new HashSet<>(); itemSet.add(new DummyItem()); itemSet.add(new DummyItem()); testSection.addAll(itemSet); Assert.assertEquals(2, testSection.getItemCount()); }
@Test public void footerCountIsSizeOfFooter() { Section section = new Section(); section.setFooter(footer); assertEquals(footerSize, section.getItemCount()); }
@Test public void footerCountIs0WhenThereIsNoFooter() { Section section = new Section(); section.removeFooter(); assertEquals(0, section.getItemCount()); }
@Test public void headerCountIsSizeOfHeader() { Section section = new Section(); section.setHeader(header); assertEquals(headerSize, section.getItemCount()); }
@Test public void headerCountIs0WhenThereIsNoHeader() { Section section = new Section(); section.removeHeader(); assertEquals(0, section.getItemCount()); }
@Test public void placeholderIsIncludedInItemCountIfBodyIsEmpty() { Section section = new Section(); section.setHeader(header); section.setFooter(footer); section.setPlaceholder(placeholder); assertEquals(headerSize + placeholderSize + footerSize, section.getItemCount()); }
@Test public void itemCountIsZeroWhenSetHideWhenEmptyTrue() { Section section = new Section(); section.setHeader(header); section.setPlaceholder(placeholder); section.setFooter(footer); section.setHideWhenEmpty(true); assertEquals(0, section.getItemCount()); }
@Test public void placeholderIsNotIncludedInItemCountIfBodyHasContent() { Section section = new Section(); section.setHeader(header); section.setFooter(footer); section.setPlaceholder(placeholder); section.add(new DummyItem()); assertEquals(headerSize + footerSize + 1, section.getItemCount()); }