From d2ae55187b5f9e8c1d8f22cb76593919dacc53a4 Mon Sep 17 00:00:00 2001 From: Richard Le Mesurier Date: Fri, 2 Mar 2018 10:02:17 +0200 Subject: [PATCH 1/2] Fix GLM vertical divider null view bug Given a grid where all rows are filled up to the end, the calculation for `rowCount` has been corrected by bringing back logic that was previously removed. Resolves: #31 --- .../grid/GridDividerItemDecoration.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/simpleitemdecoration/src/main/java/com/dgreenhalgh/android/simpleitemdecoration/grid/GridDividerItemDecoration.java b/simpleitemdecoration/src/main/java/com/dgreenhalgh/android/simpleitemdecoration/grid/GridDividerItemDecoration.java index f785d98..7cb3175 100644 --- a/simpleitemdecoration/src/main/java/com/dgreenhalgh/android/simpleitemdecoration/grid/GridDividerItemDecoration.java +++ b/simpleitemdecoration/src/main/java/com/dgreenhalgh/android/simpleitemdecoration/grid/GridDividerItemDecoration.java @@ -21,9 +21,9 @@ public class GridDividerItemDecoration extends RecyclerView.ItemDecoration { * * @param horizontalDivider A divider {@code Drawable} to be drawn on the * rows of the grid of the RecyclerView - * @param verticalDivider A divider {@code Drawable} to be drawn on the - * columns of the grid of the RecyclerView - * @param numColumns The number of columns in the grid of the RecyclerView + * @param verticalDivider A divider {@code Drawable} to be drawn on the + * columns of the grid of the RecyclerView + * @param numColumns The number of columns in the grid of the RecyclerView */ public GridDividerItemDecoration(Drawable horizontalDivider, Drawable verticalDivider, int numColumns) { mHorizontalDivider = horizontalDivider; @@ -36,7 +36,7 @@ public GridDividerItemDecoration(Drawable horizontalDivider, Drawable verticalDi * * @param canvas The {@link Canvas} onto which dividers will be drawn * @param parent The RecyclerView onto which dividers are being added - * @param state The current RecyclerView.State of the RecyclerView + * @param state The current RecyclerView.State of the RecyclerView */ @Override public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state) { @@ -50,9 +50,9 @@ public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state) * RecyclerView. * * @param outRect The {@link Rect} of offsets to be added around the child view - * @param view The child view to be decorated with an offset - * @param parent The RecyclerView onto which dividers are being added - * @param state The current RecyclerView.State of the RecyclerView + * @param view The child view to be decorated with an offset + * @param parent The RecyclerView onto which dividers are being added + * @param state The current RecyclerView.State of the RecyclerView */ @Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { @@ -111,7 +111,13 @@ private void drawHorizontalDividers(Canvas canvas, RecyclerView parent) { */ private void drawVerticalDividers(Canvas canvas, RecyclerView parent) { int childCount = parent.getChildCount(); + + // number of full rows int rowCount = childCount / mNumColumns; + if ((childCount % mNumColumns) == 0) { + rowCount--; + } + int rightmostChildIndex; for (int i = 1; i <= rowCount; i++) { if (i == rowCount) { From f610eebd86df1960f4cf3c47590cebaabd263c79 Mon Sep 17 00:00:00 2001 From: Richard Le Mesurier Date: Fri, 2 Mar 2018 10:13:51 +0200 Subject: [PATCH 2/2] Revert formatting changes --- .../grid/GridDividerItemDecoration.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/simpleitemdecoration/src/main/java/com/dgreenhalgh/android/simpleitemdecoration/grid/GridDividerItemDecoration.java b/simpleitemdecoration/src/main/java/com/dgreenhalgh/android/simpleitemdecoration/grid/GridDividerItemDecoration.java index 7cb3175..ab88b4d 100644 --- a/simpleitemdecoration/src/main/java/com/dgreenhalgh/android/simpleitemdecoration/grid/GridDividerItemDecoration.java +++ b/simpleitemdecoration/src/main/java/com/dgreenhalgh/android/simpleitemdecoration/grid/GridDividerItemDecoration.java @@ -21,9 +21,9 @@ public class GridDividerItemDecoration extends RecyclerView.ItemDecoration { * * @param horizontalDivider A divider {@code Drawable} to be drawn on the * rows of the grid of the RecyclerView - * @param verticalDivider A divider {@code Drawable} to be drawn on the - * columns of the grid of the RecyclerView - * @param numColumns The number of columns in the grid of the RecyclerView + * @param verticalDivider A divider {@code Drawable} to be drawn on the + * columns of the grid of the RecyclerView + * @param numColumns The number of columns in the grid of the RecyclerView */ public GridDividerItemDecoration(Drawable horizontalDivider, Drawable verticalDivider, int numColumns) { mHorizontalDivider = horizontalDivider; @@ -36,7 +36,7 @@ public GridDividerItemDecoration(Drawable horizontalDivider, Drawable verticalDi * * @param canvas The {@link Canvas} onto which dividers will be drawn * @param parent The RecyclerView onto which dividers are being added - * @param state The current RecyclerView.State of the RecyclerView + * @param state The current RecyclerView.State of the RecyclerView */ @Override public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state) { @@ -50,9 +50,9 @@ public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state) * RecyclerView. * * @param outRect The {@link Rect} of offsets to be added around the child view - * @param view The child view to be decorated with an offset - * @param parent The RecyclerView onto which dividers are being added - * @param state The current RecyclerView.State of the RecyclerView + * @param view The child view to be decorated with an offset + * @param parent The RecyclerView onto which dividers are being added + * @param state The current RecyclerView.State of the RecyclerView */ @Override public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {