@@ -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 ) {
0 commit comments