Git Product home page Git Product logo

dragrating's Introduction

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.

Include this library by adding below line to the module level build.gradle

dependencies {
    implementation 'com.github.saran2020:DragRating:2.1.0'
}

layout.xml

<com.github.saran2020.dragrating.DragRatingView
    android:id="@+id/slide_rating"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:initial_rating="2.5"
    app:rating_space="8dp"
    app:max_rating="5" />

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

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

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

ratingView.callback = object : DragRatingView.RatingChangeCallback {
    override fun onRatingChange(previous: Float, new: Float) {
        Log.d(TAG, "previous rating = $previous new rating = $current")
    }
}

dragrating's People

Contributors

saran2020 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

dragrating's Issues

Unable to slide to Rating below 0.5

I am trying to slide the rating below 0.5 I'm unable to move the rating to 0.

I feel letting the user rate 0 is a basic requirement and is mandatory for the lot of situations which needs to be allowed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.