@@ -59,6 +59,8 @@ public class OmegaRecyclerView extends ExpandedRecyclerView implements SwipeMenu
5959 private List <View > mHeadersList = new ArrayList <>();
6060 private List <View > mFooterList = new ArrayList <>();
6161 private WeakHashMap <ViewGroup .LayoutParams , SectionState > mLayoutParamCache = new WeakHashMap <>();
62+ @ Nullable
63+ private DividerItemDecoration mDividerItemDecoration ;
6264 private int mItemSpace ;
6365
6466 public OmegaRecyclerView (Context context ) {
@@ -81,8 +83,8 @@ private void init(Context context, @Nullable AttributeSet attrs, int defStyleAtt
8183 initDefaultLayoutManager (attrs , defStyleAttr );
8284 if (attrs != null ) {
8385 TypedArray a = context .obtainStyledAttributes (attrs , R .styleable .OmegaRecyclerView , defStyleAttr , 0 );
84- initDivider (a );
8586 initItemSpace (a );
87+ initDivider (a );
8688 initEmptyView (a );
8789 initPagination (a );
8890 a .recycle ();
@@ -123,31 +125,30 @@ public void initDivider(TypedArray a) {
123125 }
124126 }
125127
126- float dividerHeight = a .getDimension (R .styleable .OmegaRecyclerView_dividerHeight ,
128+ int dividerHeight = ( int ) a .getDimension (R .styleable .OmegaRecyclerView_dividerHeight ,
127129 a .getDimension (R .styleable .OmegaRecyclerView_android_dividerHeight , -1 ));
128- float alpha = a .getFloat (R .styleable .OmegaRecyclerView_alphaDivider , 1 );
129- int itemSpace = (int ) a .getDimension (R .styleable .OmegaRecyclerView_itemSpace , 0 );
130+ float alpha = a .getFloat (R .styleable .OmegaRecyclerView_dividerAlpha , 1 );
130131
131- DividerItemDecoration decoration = new DividerItemDecoration (
132+ mDividerItemDecoration = new DividerItemDecoration (
132133 dividerDrawable ,
133- ( int ) dividerHeight ,
134+ dividerHeight ,
134135 showDivider ,
135- itemSpace / 2 ,
136+ mItemSpace / 2 ,
136137 alpha
137138 );
138139
139140 int paddingStartDivider = a .getDimensionPixelSize (R .styleable .OmegaRecyclerView_dividerPaddingStart , 0 );
140141 int paddingEndDivider = a .getDimensionPixelSize (R .styleable .OmegaRecyclerView_dividerPaddingEnd , 0 );
141142
142- decoration .setPaddingStart (paddingStartDivider );
143- decoration .setPaddingEnd (paddingEndDivider );
143+ mDividerItemDecoration .setPaddingStart (paddingStartDivider );
144+ mDividerItemDecoration .setPaddingEnd (paddingEndDivider );
144145
145146 if (a .hasValue (R .styleable .OmegaRecyclerView_dividerPadding )) {
146147 int paddingDivider = a .getDimensionPixelSize (R .styleable .OmegaRecyclerView_dividerPadding , 0 );
147- decoration .setPadding (paddingDivider );
148+ mDividerItemDecoration .setPadding (paddingDivider );
148149 }
149150
150- addItemDecoration (decoration );
151+ addItemDecoration (mDividerItemDecoration );
151152 }
152153 }
153154 }
@@ -416,12 +417,50 @@ public View transformTouchView(int touchPosition, View touchView) {
416417 }
417418
418419 public void setDividerAlpha (float dividerAlpha ) {
420+ if (0 > dividerAlpha || dividerAlpha > 1 ) return ;
421+
422+ if (mDividerItemDecoration != null ) {
423+ mDividerItemDecoration .setDividerAlpha (dividerAlpha );
424+ }
425+
426+ boolean hasDividerDecoration = false ;
427+ for (int i = 0 ; i < getItemDecorationCount (); i ++) {
428+ RecyclerView .ItemDecoration itemDecoration = getItemDecorationAt (i );
429+ if (itemDecoration instanceof DividerItemDecoration ) {
430+ hasDividerDecoration = true ;
431+ invalidateItemDecorations ();
432+ break ;
433+ }
434+ }
435+
436+ if (!hasDividerDecoration && mDividerItemDecoration != null ) {
437+ addItemDecoration (mDividerItemDecoration );
438+ }
439+ }
440+
441+ public void setDividerDrawable (@ Nullable Drawable drawable ) {
442+ if (mDividerItemDecoration != null && drawable != null ) {
443+ mDividerItemDecoration .setDividerDrawable (drawable );
444+ }
445+
446+ boolean hasDividerDecoration = false ;
419447 for (int i = 0 ; i < getItemDecorationCount (); i ++) {
420448 RecyclerView .ItemDecoration itemDecoration = getItemDecorationAt (i );
421449 if (itemDecoration instanceof DividerItemDecoration ) {
422- ((DividerItemDecoration ) itemDecoration ).setDividerAlpha (dividerAlpha );
450+ hasDividerDecoration = true ;
451+ if (drawable == null ) {
452+ removeItemDecoration (itemDecoration );
453+ break ;
454+ } else {
455+ invalidateItemDecorations ();
456+ break ;
457+ }
423458 }
424459 }
460+
461+ if (drawable != null && !hasDividerDecoration ) {
462+ addItemDecoration (mDividerItemDecoration );
463+ }
425464 }
426465
427466 public void setPaginationCallback (OnPageRequestListener callback ) {
0 commit comments