Skip to content

Commit b666590

Browse files
Added setColoredDivider and setVerticalGap Kotlin extension functions on the RecyclerView class.
1 parent 4fc934f commit b666590

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ This library contains a mixture of small helper classes, functions and views use
3636

3737
## Views
3838

39-
* [RecyclerViewColoredDividerItemDecoration](library/src/main/java/com/tazkiyatech/utils/views/RecyclerViewColoredDividerItemDecoration.java) – An extension of the `androidx.recyclerview.widget.RecyclerView.ItemDecoration` class that draws a colored divider between each item in a `RecyclerView`.
40-
* [RecyclerViewVerticalGapItemDecoration](library/src/main/java/com/tazkiyatech/utils/views/RecyclerViewVerticalGapItemDecoration.java) – An extension of the `androidx.recyclerview.widget.RecyclerView.ItemDecoration` class that draws a vertical gap between each item in a `RecyclerView`.
39+
* [RecyclerViewExtensions](library/src/main/java/com/tazkiyatech/utils/views/RecyclerViewExtensions.kt) – Provides Kotlin extension functions for drawing a colored divider or vertical gap between items in a `RecyclerView`.
4140
* [SimpleTouchListener](library/src/main/java/com/tazkiyatech/utils/views/SimpleTouchListener.java) – An implementation of the `android.view.View.OnTouchListener` interface that simply reports when a `android.view.View` is touched down and when the touch is subsequently released or canceled.
4241
* [SpinnerLookalikeView](library/src/main/java/com/tazkiyatech/utils/views/SpinnerLookalikeView.java) – An extension of the `android.widget.FrameLayout` class that looks like an `android.widget.Spinner` view.
4342

@@ -50,6 +49,6 @@ repositories {
5049
mavenCentral()
5150
}
5251
dependencies {
53-
implementation 'com.tazkiyatech:android-utils:0.2.2'
52+
implementation 'com.tazkiyatech:android-utils:0.2.3'
5453
}
5554
```
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.tazkiyatech.utils.views
2+
3+
import androidx.annotation.ColorInt
4+
import androidx.recyclerview.widget.RecyclerView
5+
6+
/**
7+
* Sets the colored divider that will be drawn between each item in the [RecyclerView].
8+
*
9+
* Note that this method calls into the [RecyclerView.addItemDecoration] method internally.
10+
* This call will likely conflict with any other calls to [RecyclerView.addItemDecoration] that you make on the [RecyclerView].
11+
*/
12+
fun RecyclerView.setColoredDivider(@ColorInt dividerColor: Int,
13+
dividerHeightPixels: Int,
14+
dividerMarginLeftPixels: Int = 0,
15+
dividerMarginRightPixels: Int = 0) {
16+
val itemDecoration = RecyclerViewColoredDividerItemDecoration(
17+
dividerColor, dividerHeightPixels, dividerMarginLeftPixels, dividerMarginRightPixels
18+
)
19+
addItemDecoration(itemDecoration)
20+
}
21+
22+
/**
23+
* Sets the vertical gap that will be drawn between each item in the [RecyclerView].
24+
*
25+
* Note that this method calls into the [RecyclerView.addItemDecoration] method internally.
26+
* This call will likely conflict with any other calls to [RecyclerView.addItemDecoration] that you make on the [RecyclerView].
27+
*/
28+
fun RecyclerView.setVerticalGap(verticalGapInPixels: Int) {
29+
addItemDecoration(RecyclerViewVerticalGapItemDecoration(verticalGapInPixels))
30+
}

0 commit comments

Comments
 (0)