@Test public void onDraw_invalid_adapterPosition() { when(recyclerView.getChildAt(anyInt())).thenReturn(child); when(recyclerView.getChildCount()).thenReturn(3); when(recyclerView.getChildAdapterPosition(child)).thenReturn(-1); testAdapter.getItemDecoration().onDraw(canvas, recyclerView, state); verify(testAdapter, never()).drawDecoration(canvas, recyclerView, state, child, -1); }
@Override public void onDraw(@NonNull Canvas canvas, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { int childCount = parent.getChildCount(); for (int i = 0; i < childCount; i++) { View child = parent.getChildAt(i); int adapterPosition = parent.getChildAdapterPosition(child); if (adapterPosition < 0) { return; } adapter.drawDecoration(canvas, parent, state, child, adapterPosition); } }
DecorationDelegate extends RecyclerView.ItemDecoration { @Override public void onDraw(@NonNull Canvas canvas, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { int childCount = parent.getChildCount(); for (int i = 0; i < childCount; i++) { View child = parent.getChildAt(i); int adapterPosition = parent.getChildAdapterPosition(child); if (adapterPosition < 0) { return; } adapter.drawDecoration(canvas, parent, state, child, adapterPosition); } } }
DecorationDelegate extends RecyclerView.ItemDecoration { @Override public void onDraw(@NonNull Canvas canvas, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { int childCount = parent.getChildCount(); for (int i = 0; i < childCount; i++) { View child = parent.getChildAt(i); int adapterPosition = parent.getChildAdapterPosition(child); if (adapterPosition < 0) { return; } adapter.drawDecoration(canvas, parent, state, child, adapterPosition); } } DecorationDelegate(MultiViewAdapter adapter); }
DecorationDelegate extends RecyclerView.ItemDecoration { @Override public void onDraw(@NonNull Canvas canvas, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { int childCount = parent.getChildCount(); for (int i = 0; i < childCount; i++) { View child = parent.getChildAt(i); int adapterPosition = parent.getChildAdapterPosition(child); if (adapterPosition < 0) { return; } adapter.drawDecoration(canvas, parent, state, child, adapterPosition); } } DecorationDelegate(MultiViewAdapter adapter); @Override void onDraw(@NonNull Canvas canvas, @NonNull RecyclerView parent,
      @NonNull RecyclerView.State state); @Override void onDrawOver(@NonNull Canvas canvas, @NonNull RecyclerView parent,
      @NonNull RecyclerView.State state); @Override void getItemOffsets(@NonNull Rect outRect, @NonNull View view,
      @NonNull RecyclerView parent, @NonNull RecyclerView.State state); }
DecorationDelegate extends RecyclerView.ItemDecoration { @Override public void onDraw(@NonNull Canvas canvas, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { int childCount = parent.getChildCount(); for (int i = 0; i < childCount; i++) { View child = parent.getChildAt(i); int adapterPosition = parent.getChildAdapterPosition(child); if (adapterPosition < 0) { return; } adapter.drawDecoration(canvas, parent, state, child, adapterPosition); } } DecorationDelegate(MultiViewAdapter adapter); @Override void onDraw(@NonNull Canvas canvas, @NonNull RecyclerView parent,
      @NonNull RecyclerView.State state); @Override void onDrawOver(@NonNull Canvas canvas, @NonNull RecyclerView parent,
      @NonNull RecyclerView.State state); @Override void getItemOffsets(@NonNull Rect outRect, @NonNull View view,
      @NonNull RecyclerView parent, @NonNull RecyclerView.State state);  }