HeaderSpanSizeLookup extends GridLayoutManager.SpanSizeLookup { @Override public int getSpanSize(int position) { boolean isHeaderOrFooter = adapter.isHeaderPosition(position) || adapter.isFooterPosition(position); return isHeaderOrFooter ? layoutManager.getSpanCount() : 1; } HeaderSpanSizeLookup(HeaderRecyclerViewAdapter adapter, GridLayoutManager layoutManager); @Override int getSpanSize(int position);  }
@Test public void shouldReturnHeaderSpanSizeIfTheAdapterHasNoConfiguredAHeaderAndThePositionIsZero() { HeaderSpanSizeLookup headerSpanSizeLookup = new HeaderSpanSizeLookupBuilder().withAdapter( new HeaderRecyclerViewAdapterBuilder().withItems(givenSomeItems()).build()) .withGridLayoutManager(new GridLayoutManagerBuilder().withSpanCount(THREE_ROWS).build()) .build(); assertEquals(1, headerSpanSizeLookup.getSpanSize(POSITION_ZERO)); }
@Test public void shouldReturnFooterSpanSizeIfTheAdapterHasNoConfiguredAFooterAndThePositionIsTheLast() { HeaderSpanSizeLookup headerSpanSizeLookup = new HeaderSpanSizeLookupBuilder().withAdapter( new HeaderRecyclerViewAdapterBuilder().withItems(givenSomeItems()).build()) .withGridLayoutManager(new GridLayoutManagerBuilder().withSpanCount(THREE_ROWS).build()) .build(); assertEquals(1, headerSpanSizeLookup.getSpanSize(POSITION_ONE)); }
@Test public void shouldReturnSpanCountIfThePositionIsZeroAndTheAdapterHasAHeaderConfigured() { HeaderSpanSizeLookup headerSpanSizeLookup = new HeaderSpanSizeLookupBuilder().withAdapter( new HeaderRecyclerViewAdapterBuilder().withHeader(givenAHeader()).build()) .withGridLayoutManager(new GridLayoutManagerBuilder().withSpanCount(THREE_ROWS).build()) .build(); assertEquals(3, headerSpanSizeLookup.getSpanSize(POSITION_ZERO)); }
@Test public void shouldReturnHeaderSpanSizeIfThePositionIsZeroAndHasHeaderAndItemsConfigured() { HeaderSpanSizeLookup headerSpanSizeLookup = new HeaderSpanSizeLookupBuilder().withAdapter( new HeaderRecyclerViewAdapterBuilder().withHeader(givenAHeader()) .withItems(givenSomeItems()) .build()) .withGridLayoutManager(new GridLayoutManagerBuilder().withSpanCount(THREE_ROWS).build()) .build(); assertEquals(3, headerSpanSizeLookup.getSpanSize(POSITION_ZERO)); }
@Test public void shouldReturnHeaderSpanSizeIfThePositionIsOneAndHasHeaderAndItemsConfigured() { HeaderSpanSizeLookup headerSpanSizeLookup = new HeaderSpanSizeLookupBuilder().withAdapter( new HeaderRecyclerViewAdapterBuilder().withHeader(givenAHeader()) .withItems(givenSomeItems()) .build()) .withGridLayoutManager(new GridLayoutManagerBuilder().withSpanCount(THREE_ROWS).build()) .build(); assertEquals(1, headerSpanSizeLookup.getSpanSize(POSITION_ONE)); }