Skip to content

Commit 81ecb2d

Browse files
committed
Add support GridLayoutManager in itemSpace
1 parent 8929028 commit 81ecb2d

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

omegarecyclerviewlibs/src/main/java/com/omega_r/libs/omegarecyclerview/item_decoration/SpaceItemDecoration.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ void getItemOffset(@NonNull Rect outRect, @NonNull RecyclerView parent,
2323
int countBeginEndPositions = getCountBeginEndPositions(parent);
2424
if (isShowBeginDivider() || countBeginEndPositions <= position) helper.setStart(outRect, space);
2525
if (isShowEndDivider() && position == itemCount - countBeginEndPositions) helper.setEnd(outRect, space);
26+
27+
if (position % countBeginEndPositions != 0 || isShowBeginDivider()) helper.setOtherStart(outRect, space);
28+
if (position / (countBeginEndPositions - 1) > 0 && isShowEndDivider()) helper.setOtherStart(outRect, space);
29+
30+
2631
}
2732

2833
private int getCountBeginEndPositions(RecyclerView recyclerView) {

omegarecyclerviewlibs/src/main/java/com/omega_r/libs/omegarecyclerview/item_decoration/decoration_helpers/DividerDecorationHelper.java

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ public static DividerDecorationHelper getHelper(int orientation, RecyclerView pa
4646

4747
public abstract int getEnd(Rect rect);
4848

49+
public abstract void setOtherStart(Rect rect, int start);
50+
51+
public abstract void setOtherEnd(Rect rect, int end);
52+
53+
public abstract int getOtherStart(Rect rect);
54+
55+
public abstract int getOtherEnd(Rect rect);
56+
4957
public int getOffset(int offset) {
5058
return offset;
5159
}
@@ -78,6 +86,26 @@ public int getEnd(Rect rect) {
7886
return rect.bottom;
7987
}
8088

89+
@Override
90+
public void setOtherStart(Rect rect, int start) {
91+
rect.left = start;
92+
}
93+
94+
@Override
95+
public void setOtherEnd(Rect rect, int end) {
96+
rect.right = end;
97+
}
98+
99+
@Override
100+
public int getOtherStart(Rect rect) {
101+
return rect.left;
102+
}
103+
104+
@Override
105+
public int getOtherEnd(Rect rect) {
106+
return rect.right;
107+
}
108+
81109
}
82110

83111
class ReverseVerticalDividerDecorationHelper extends DividerDecorationHelper {
@@ -106,6 +134,26 @@ public int getEnd(Rect rect) {
106134
return rect.top;
107135
}
108136

137+
@Override
138+
public void setOtherStart(Rect rect, int start) {
139+
rect.right = start;
140+
}
141+
142+
@Override
143+
public void setOtherEnd(Rect rect, int end) {
144+
rect.left = end;
145+
}
146+
147+
@Override
148+
public int getOtherStart(Rect rect) {
149+
return rect.right;
150+
}
151+
152+
@Override
153+
public int getOtherEnd(Rect rect) {
154+
return rect.left;
155+
}
156+
109157
@Override
110158
public int getOffset(int offset) {
111159
return -offset;
@@ -139,6 +187,26 @@ public int getEnd(Rect rect) {
139187
return rect.right;
140188
}
141189

190+
@Override
191+
public void setOtherStart(Rect rect, int start) {
192+
rect.top = start;
193+
}
194+
195+
@Override
196+
public void setOtherEnd(Rect rect, int end) {
197+
rect.bottom = end;
198+
}
199+
200+
@Override
201+
public int getOtherStart(Rect rect) {
202+
return rect.top;
203+
}
204+
205+
@Override
206+
public int getOtherEnd(Rect rect) {
207+
return rect.bottom;
208+
}
209+
142210
}
143211

144212
class ReverseHorizontalDividerDecorationHelper extends DividerDecorationHelper {
@@ -167,6 +235,26 @@ public int getEnd(Rect rect) {
167235
return rect.left;
168236
}
169237

238+
@Override
239+
public void setOtherStart(Rect rect, int start) {
240+
rect.bottom = start;
241+
}
242+
243+
@Override
244+
public void setOtherEnd(Rect rect, int end) {
245+
rect.top = end;
246+
}
247+
248+
@Override
249+
public int getOtherStart(Rect rect) {
250+
return rect.bottom;
251+
}
252+
253+
@Override
254+
public int getOtherEnd(Rect rect) {
255+
return rect.top;
256+
}
257+
170258
@Override
171259
public int getOffset(int offset) {
172260
return -offset;

0 commit comments

Comments
 (0)