Skip to content

Commit

Permalink
Added setColoredDivider and setVerticalGap Kotlin extension funct…
Browse files Browse the repository at this point in the history
…ions on the `RecyclerView` class.
  • Loading branch information
adil-hussain-84 committed Apr 15, 2022
1 parent 4fc934f commit b666590
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ This library contains a mixture of small helper classes, functions and views use

## Views

* [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`.
* [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`.
* [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`.
* [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.
* [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.

Expand All @@ -50,6 +49,6 @@ repositories {
mavenCentral()
}
dependencies {
implementation 'com.tazkiyatech:android-utils:0.2.2'
implementation 'com.tazkiyatech:android-utils:0.2.3'
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.tazkiyatech.utils.views

import androidx.annotation.ColorInt
import androidx.recyclerview.widget.RecyclerView

/**
* Sets the colored divider that will be drawn between each item in the [RecyclerView].
*
* Note that this method calls into the [RecyclerView.addItemDecoration] method internally.
* This call will likely conflict with any other calls to [RecyclerView.addItemDecoration] that you make on the [RecyclerView].
*/
fun RecyclerView.setColoredDivider(@ColorInt dividerColor: Int,
dividerHeightPixels: Int,
dividerMarginLeftPixels: Int = 0,
dividerMarginRightPixels: Int = 0) {
val itemDecoration = RecyclerViewColoredDividerItemDecoration(
dividerColor, dividerHeightPixels, dividerMarginLeftPixels, dividerMarginRightPixels
)
addItemDecoration(itemDecoration)
}

/**
* Sets the vertical gap that will be drawn between each item in the [RecyclerView].
*
* Note that this method calls into the [RecyclerView.addItemDecoration] method internally.
* This call will likely conflict with any other calls to [RecyclerView.addItemDecoration] that you make on the [RecyclerView].
*/
fun RecyclerView.setVerticalGap(verticalGapInPixels: Int) {
addItemDecoration(RecyclerViewVerticalGapItemDecoration(verticalGapInPixels))
}

0 comments on commit b666590

Please sign in to comment.