Skip to content

Commit 2a7fc4d

Browse files
Merge branch 'master' into develop
2 parents 72c1d84 + 2f84693 commit 2a7fc4d

File tree

5 files changed

+64
-16
lines changed

5 files changed

+64
-16
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ allprojects {
2424
**Step 2.** Add the dependency
2525
```
2626
dependencies {
27-
implementation 'com.github.Omega-R:OmegaRecyclerView:1.9.4@aar' // AndroidX
27+
implementation 'com.github.Omega-R:OmegaRecyclerView:1.9.5@aar' // AndroidX
2828
// or
2929
// implementation 'com.github.Omega-R:OmegaRecyclerView:1.8.2@aar' // Android Support
3030
}

app/src/main/res/layout/fragment_test.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
android:divider="@drawable/divider"
1313
android:dividerHeight="1dp"
1414
app:itemSpace="32dp"
15-
app:alphaDivider="0.5"
15+
app:dividerAlpha="0.5"
1616
app:dividerShow="middle"/>
1717
</FrameLayout>

omegarecyclerviewlibs/src/main/java/com/omega_r/libs/omegarecyclerview/OmegaRecyclerView.java

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ public class OmegaRecyclerView extends ExpandedRecyclerView implements SwipeMenu
6161
private List<View> mHeadersList = new ArrayList<>();
6262
private List<View> mFooterList = new ArrayList<>();
6363
private WeakHashMap<ViewGroup.LayoutParams, SectionState> mLayoutParamCache = new WeakHashMap<>();
64+
@Nullable
65+
private DividerItemDecoration mDividerItemDecoration;
6466
private int mItemSpace;
6567
private int mDividerSize;
6668

@@ -84,8 +86,8 @@ private void init(Context context, @Nullable AttributeSet attrs, int defStyleAtt
8486
initDefaultLayoutManager(attrs, defStyleAttr);
8587
if (attrs != null) {
8688
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.OmegaRecyclerView, defStyleAttr, 0);
87-
initDivider(a);
8889
initItemSpace(a);
90+
initDivider(a);
8991
initEmptyView(a);
9092
initPagination(a);
9193
initStickyMode(a);
@@ -127,31 +129,32 @@ public void initDivider(TypedArray a) {
127129
}
128130
}
129131

132+
130133
mDividerSize = (int) a.getDimension(R.styleable.OmegaRecyclerView_dividerHeight,
134+
131135
a.getDimension(R.styleable.OmegaRecyclerView_android_dividerHeight, -1));
132-
float alpha = a.getFloat(R.styleable.OmegaRecyclerView_alphaDivider, 1);
133-
int itemSpace = (int) a.getDimension(R.styleable.OmegaRecyclerView_itemSpace, 0);
136+
float alpha = a.getFloat(R.styleable.OmegaRecyclerView_dividerAlpha, 1);
134137

135-
DividerItemDecoration decoration = new DividerItemDecoration(
138+
mDividerItemDecoration = new DividerItemDecoration(
136139
dividerDrawable,
137140
mDividerSize,
138141
showDivider,
139-
itemSpace / 2,
142+
mItemSpace / 2,
140143
alpha
141144
);
142145

143146
int paddingStartDivider = a.getDimensionPixelSize(R.styleable.OmegaRecyclerView_dividerPaddingStart, 0);
144147
int paddingEndDivider = a.getDimensionPixelSize(R.styleable.OmegaRecyclerView_dividerPaddingEnd, 0);
145148

146-
decoration.setPaddingStart(paddingStartDivider);
147-
decoration.setPaddingEnd(paddingEndDivider);
149+
mDividerItemDecoration.setPaddingStart(paddingStartDivider);
150+
mDividerItemDecoration.setPaddingEnd(paddingEndDivider);
148151

149152
if (a.hasValue(R.styleable.OmegaRecyclerView_dividerPadding)) {
150153
int paddingDivider = a.getDimensionPixelSize(R.styleable.OmegaRecyclerView_dividerPadding, 0);
151-
decoration.setPadding(paddingDivider);
154+
mDividerItemDecoration.setPadding(paddingDivider);
152155
}
153156

154-
addItemDecoration(decoration);
157+
addItemDecoration(mDividerItemDecoration);
155158
}
156159
}
157160
}
@@ -424,12 +427,50 @@ public View transformTouchView(int touchPosition, View touchView) {
424427
}
425428

426429
public void setDividerAlpha(float dividerAlpha) {
430+
if (0 > dividerAlpha || dividerAlpha > 1) return;
431+
432+
if (mDividerItemDecoration != null) {
433+
mDividerItemDecoration.setDividerAlpha(dividerAlpha);
434+
}
435+
436+
boolean hasDividerDecoration = false;
437+
for (int i = 0; i < getItemDecorationCount(); i++) {
438+
RecyclerView.ItemDecoration itemDecoration = getItemDecorationAt(i);
439+
if (itemDecoration instanceof DividerItemDecoration) {
440+
hasDividerDecoration = true;
441+
invalidateItemDecorations();
442+
break;
443+
}
444+
}
445+
446+
if (!hasDividerDecoration && mDividerItemDecoration != null) {
447+
addItemDecoration(mDividerItemDecoration);
448+
}
449+
}
450+
451+
public void setDividerDrawable(@Nullable Drawable drawable) {
452+
if (mDividerItemDecoration != null && drawable != null) {
453+
mDividerItemDecoration.setDividerDrawable(drawable);
454+
}
455+
456+
boolean hasDividerDecoration = false;
427457
for (int i = 0; i < getItemDecorationCount(); i++) {
428458
RecyclerView.ItemDecoration itemDecoration = getItemDecorationAt(i);
429459
if (itemDecoration instanceof DividerItemDecoration) {
430-
((DividerItemDecoration) itemDecoration).setDividerAlpha(dividerAlpha);
460+
hasDividerDecoration = true;
461+
if (drawable == null) {
462+
removeItemDecoration(itemDecoration);
463+
break;
464+
} else {
465+
invalidateItemDecorations();
466+
break;
467+
}
431468
}
432469
}
470+
471+
if (drawable != null && !hasDividerDecoration) {
472+
addItemDecoration(mDividerItemDecoration);
473+
}
433474
}
434475

435476
public void setPaginationCallback(OnPageRequestListener callback) {

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,21 @@
1212
import com.omega_r.libs.omegarecyclerview.item_decoration.decoration_helpers.DividerDecorationHelper;
1313

1414
public class DividerItemDecoration extends BaseItemDecoration {
15-
private final int mOffset;
1615

16+
private final Rect mViewRect = new Rect();
17+
private final Rect mItemRect = new Rect();
18+
private final int mOriginalDividerSize;
19+
private final int mOffset;
1720
private float mDividerAlpha;
1821
private Drawable mDivider;
1922
private int mDividerSize;
2023
private int mPaddingStart;
2124
private int mPaddingEnd;
22-
private Rect mViewRect = new Rect();
23-
private Rect mItemRect = new Rect();
25+
2426

2527
public DividerItemDecoration(Drawable divider, int dividerSize, int showDivider, int offset, float dividerAlpha) {
2628
super(showDivider);
29+
mOriginalDividerSize = dividerSize;
2730
mDivider = divider;
2831
mDividerSize = dividerSize;
2932
mOffset = offset;
@@ -55,6 +58,10 @@ public void setDividerAlpha(float dividerAlpha) {
5558

5659
public void setDividerDrawable(@NonNull Drawable dividerDrawable) {
5760
mDivider = dividerDrawable;
61+
if (mOriginalDividerSize < 0) {
62+
mDividerSize = mOriginalDividerSize;
63+
updateSize();
64+
}
5865
}
5966

6067
private void updateSize() {

omegarecyclerviewlibs/src/main/res/values/attrs.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<flag name="middle" value="2" />
1717
<flag name="end" value="4" />
1818
</attr>
19-
<attr name="alphaDivider" format="float" />
19+
<attr name="dividerAlpha" format="float" />
2020
<attr name="emptyView" format="reference" />
2121
<attr name="paginationLayout" format="reference" />
2222
<attr name="paginationErrorLayout" format="reference" />

0 commit comments

Comments
 (0)