Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/saran2020/DragRating
Easy to use Drag Rating with customisation with custom assets
https://github.com/saran2020/DragRating
dragging material-design rating-component rating-stars ratingbar stars
Last synced: 16 days ago
JSON representation
Easy to use Drag Rating with customisation with custom assets
- Host: GitHub
- URL: https://github.com/saran2020/DragRating
- Owner: saran2020
- Created: 2019-04-27T06:10:03.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-07-13T04:45:42.000Z (over 5 years ago)
- Last Synced: 2024-08-09T02:17:59.976Z (4 months ago)
- Topics: dragging, material-design, rating-component, rating-stars, ratingbar, stars
- Language: Kotlin
- Homepage:
- Size: 548 KB
- Stars: 23
- Watchers: 3
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- jimsghstars - saran2020/DragRating - Easy to use Drag Rating with customisation with custom assets (Kotlin)
README
# Drag Rating
Drag rating is a rating view inspired of Drag Review from Book My Show app. The purpose of this library is to create simple and easy to use Drag Rating Widget with support for custom assets.
![](assets/demo.gif)
Include this library by adding below line to the module level `build.gradle`
```Gradle
dependencies {
implementation 'com.github.saran2020:DragRating:2.1.0'
}
```**layout.xml**
```xml```
`initial_rating` - It's used to set the initial rating to the widget.
`max_rating` - It's used to set the maximum allowed rating. The number you provide here is the number of stars that will be drawn.
`rating_space` - It can be used to control the space between two star views.Current rating can be read using `getRating()` and to set the rating use method `setRating(3.5f)`.
To provide custom asset for the view, you need to set a `Map` with the multiplier for the asset and the asset like shown below.
Passing custom asset resource id
```kotlin
ratingView.setDrawableResourceAssetMap(
mapOf(
0f to R.drawable.ic_star_empty,
0.5f to R.drawable.ic_star_half,
1f to R.drawable.ic_star_full
)
)
```Passing asset as `Drawable` in kotlin
```kotlin
ratingView.setDrawableAssetMap(
mapOf(
0f to emptyRating,
0.5f to halfRating,
1f to fullRating
)
)
```
**NOTE: You should only provide the multiplier between 0 and 1. If the current rating is 1.5 it will automatically fill one star with the asset mapped to `1f` and one star with asset mapped to `0.5f`**Callback when user is dragging the `DragRatingView`
```kotlin
ratingView.callback = object : DragRatingView.RatingChangeCallback {
override fun onRatingChange(previous: Float, new: Float) {
Log.d(TAG, "previous rating = $previous new rating = $current")
}
}
```