@Test public void testShouldDecorateForRecyclerViewStateWithoutItems() { final RecyclerView mockRecyclerView = mock(RecyclerView.class); when(mockRecyclerView.getLayoutManager()).thenReturn(new LinearLayoutManager(context)); final RecyclerView.State mockRecyclerViewState = mock(RecyclerView.State.class); when(mockRecyclerViewState.getItemCount()).thenReturn(0); final RecyclerViewItemDecoration decoration = new TestDecoration(); assertThat(decoration.shouldDecorate(mockRecyclerView, mockRecyclerViewState), is(false)); verify(mockRecyclerView, times(1)).getLayoutManager(); verify(mockRecyclerViewState, times(1)).getItemCount(); }
protected boolean shouldDecorate(@NonNull final RecyclerView parent, @NonNull final RecyclerView.State state) { return parent.getLayoutManager() != null && state.getItemCount() > 0; }
RecyclerViewItemDecoration extends RecyclerView.ItemDecoration { protected boolean shouldDecorate(@NonNull final RecyclerView parent, @NonNull final RecyclerView.State state) { return parent.getLayoutManager() != null && state.getItemCount() > 0; } }
RecyclerViewItemDecoration extends RecyclerView.ItemDecoration { protected boolean shouldDecorate(@NonNull final RecyclerView parent, @NonNull final RecyclerView.State state) { return parent.getLayoutManager() != null && state.getItemCount() > 0; } RecyclerViewItemDecoration();  RecyclerViewItemDecoration(@Nullable final Context context);  RecyclerViewItemDecoration(@Nullable final Context context, @Nullable final AttributeSet attrs);  RecyclerViewItemDecoration(@Nullable final Context context, @Nullable final AttributeSet attrs, @AttrRes final int defStyleAttr);  RecyclerViewItemDecoration(@Nullable final Context context, @Nullable final AttributeSet attrs, @AttrRes final int defStyleAttr, @StyleRes final int defStyleRes); }
RecyclerViewItemDecoration extends RecyclerView.ItemDecoration { protected boolean shouldDecorate(@NonNull final RecyclerView parent, @NonNull final RecyclerView.State state) { return parent.getLayoutManager() != null && state.getItemCount() > 0; } RecyclerViewItemDecoration();  RecyclerViewItemDecoration(@Nullable final Context context);  RecyclerViewItemDecoration(@Nullable final Context context, @Nullable final AttributeSet attrs);  RecyclerViewItemDecoration(@Nullable final Context context, @Nullable final AttributeSet attrs, @AttrRes final int defStyleAttr);  RecyclerViewItemDecoration(@Nullable final Context context, @Nullable final AttributeSet attrs, @AttrRes final int defStyleAttr, @StyleRes final int defStyleRes); void setSkipFirst(final boolean skip); boolean skipsFirst(); void setSkipLast(final boolean skip); boolean skipsLast(); final void setPrecondition(@NonNull final Precondition precondition); @NonNull final Precondition getPrecondition(); }
RecyclerViewItemDecoration extends RecyclerView.ItemDecoration { protected boolean shouldDecorate(@NonNull final RecyclerView parent, @NonNull final RecyclerView.State state) { return parent.getLayoutManager() != null && state.getItemCount() > 0; } RecyclerViewItemDecoration();  RecyclerViewItemDecoration(@Nullable final Context context);  RecyclerViewItemDecoration(@Nullable final Context context, @Nullable final AttributeSet attrs);  RecyclerViewItemDecoration(@Nullable final Context context, @Nullable final AttributeSet attrs, @AttrRes final int defStyleAttr);  RecyclerViewItemDecoration(@Nullable final Context context, @Nullable final AttributeSet attrs, @AttrRes final int defStyleAttr, @StyleRes final int defStyleRes); void setSkipFirst(final boolean skip); boolean skipsFirst(); void setSkipLast(final boolean skip); boolean skipsLast(); final void setPrecondition(@NonNull final Precondition precondition); @NonNull final Precondition getPrecondition();  }