Skip to content

Commit

Permalink
Merge branch 'master' of personal_github:saran2020/DragRating
Browse files Browse the repository at this point in the history
  • Loading branch information
saran2020 committed Jun 5, 2019
2 parents 7b93228 + b67be72 commit 23819a4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ ratingView.setDrawableAssetMap(
Callback when user is dragging the `DragRatingView`
```kotlin
ratingView.callback = object : DragRatingView.RatingChangeCallback {
override fun onRatingChanged(previous: Float, new: Float) {
override fun onRatingChange(previous: Float, new: Float) {
Log.d(TAG, "previous rating = $previous new rating = $current")
}
}
Expand Down
22 changes: 12 additions & 10 deletions app/src/main/java/com/github/saran2020/app/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,27 @@ class MainActivity : AppCompatActivity() {
ratingTextView = findViewById(R.id.rating_text)

ratingView?.callback = object : DragRatingView.RatingChangeCallback {
override fun onRatingChanged(previous: Float, current: Float) {
override fun onRatingChange(previous: Float, current: Float) {
ratingTextView?.text = "$current"
}
}

ratingViewHeart = findViewById(R.id.slide_rating_heart)
ratingTextViewHeart = findViewById(R.id.rating_text_heart)

ratingViewHeart?.setDrawableResourceAssetMap(
mapOf(
0f to R.drawable.ic_empty_filled_heart,
0.5f to R.drawable.ic_half_filled_heart,
1f to R.drawable.ic_filled_heart
ratingViewHeart?.apply {
setDrawableResourceAssetMap(
mapOf(
0f to R.drawable.ic_empty_filled_heart,
0.5f to R.drawable.ic_half_filled_heart,
1f to R.drawable.ic_filled_heart
)
)
)

ratingViewHeart?.callback = object : DragRatingView.RatingChangeCallback {
override fun onRatingChanged(previous: Float, current: Float) {
ratingTextViewHeart?.text = "$current"
callback = object : DragRatingView.RatingChangeCallback {
override fun onRatingChange(previous: Float, current: Float) {
ratingTextViewHeart?.text = "$current"
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ open class DragRatingView @JvmOverloads constructor(
}

field = newRating
callback?.onRatingChanged(previousRating, field)
callback?.onRatingChange(previousRating, field)

Log.d("buggy_bug", "current rating $currentRating")
refreshRatingView()
Expand Down Expand Up @@ -283,6 +283,6 @@ open class DragRatingView @JvmOverloads constructor(
}

interface RatingChangeCallback {
fun onRatingChanged(previous: Float, current: Float)
fun onRatingChange(previous: Float, current: Float)
}
}

0 comments on commit 23819a4

Please sign in to comment.