Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,25 @@ public final void setData(@Nullable Collection<DataObject> items,
@NonNull Comparator<Section> comparator) {
final SectionedItems<DataObject> sectionedItems = new SectionedItems<>(sectionEvaluator, items, comparator);
mapOfSections = sectionedItems.getSections();
insertNewItems(sectionedItems);
insertNewItems(sectionedItems.getItems());
}

private void insertNewItems(SectionedItems<DataObject> sectionedItems) {
public final void addData(@Nullable Collection<DataObject> items,
@NonNull SectionEvaluator<DataObject> sectionEvaluator) {
addData(items, sectionEvaluator, Comparators.ASCENDING_COMPARATOR);
}

public final void addData(@Nullable Collection<DataObject> items,
@NonNull SectionEvaluator<DataObject> sectionEvaluator,
@NonNull Comparator<Section> comparator) {
final SectionedItems<DataObject> sectionedItems = new SectionedItems<>(sectionEvaluator, items, comparator);
mapOfSections = sectionedItems.getSections();
final List<ListItem> newListItems = sectionedItems.getItems();
newListItems.addAll(sectionedItemList);
insertNewItems(newListItems);
}

private void insertNewItems(List<ListItem> newListItems) {
if (sectionedItemList.isEmpty()) {
sectionedItemList = newListItems;
notifyDataSetChanged();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ public class DynamicRecyclerViewAdapterTest {
private static final String FIRST_ITEM_SECTION_TITLE = new TestSectionEvaluator().evaluate(FIRST_ITEM);
private final static String SECOND_ITEM = "secondItem";
private static final String SECOND_ITEM_SECTION_TITLE = new TestSectionEvaluator().evaluate(SECOND_ITEM);
private final static String THIRD_ITEM = "thirdItem";
private final static String FOURTH_ITEM = "fourthItem";
private List<String> testItems = Arrays.asList(FIRST_ITEM, SECOND_ITEM);
private List<String> moreTestItems = Arrays.asList(THIRD_ITEM, FOURTH_ITEM);

@Captor ArgumentCaptor<String> titleCaptor;
@Captor ArgumentCaptor<Collection<DataCellItem>> dataItemsCaptor;
Expand All @@ -52,6 +55,13 @@ public void shouldGetCorrectItemCount() {
assertThat(dynamicRecyclerViewAdapter.getItemCount()).isEqualTo(4);
}

@Test
public void shouldGetCorrectItemCountAfterAdding() {
// when
dynamicRecyclerViewAdapter.addData(moreTestItems, new TestSectionEvaluator());
assertThat(dynamicRecyclerViewAdapter.getItemCount()).isEqualTo(7);
}

@Test
public void shouldProvideCorrectViewTypeForHeadersAndNonHeader() {
assertThat(dynamicRecyclerViewAdapter.getItemViewType(0)).isEqualTo(DynamicRecyclerViewAdapter.TITLE_TYPE);
Expand Down