sujithkanna / SmileyRating

SmileyRating is a simple rating bar for android. It displays animated smileys as rating icon.
Apache License 2.0
1.07k stars 183 forks source link

Range discordance between getRating and setSelectedSmile #43

Closed shining-cat closed 4 years ago

shining-cat commented 6 years ago

values returned by getRating() range from 1 to 5, with 0 for none selected but values expected by setSelectedSmile range from 0 to 5 with -1 for non selected

This makes it hazardous to store and display values through the scale : if you store as int userSatisfaction the value from the level variable inside the onRatingSelected of a SmileRating.OnRatingSelectedListener and later you want to display a scale with the same value, you have to set it like : SmileRating.setSelectedSmile(userSatisfaction -1); to adapt the range offset... this is quite unintuitive

This is not an issue per se but I spent quite some time thinking the #22 was not really fixed when in fact I was setting my SmileRating to level 5, which does not exist...

Anyway, many thanks for your great work!

MuhammadFaisalIchal commented 6 years ago

Hello @shining-cat Are you intended to post the rating value (i.e 1-5) somewhere else? If so, then we have same cases

shining-cat commented 6 years ago

hello @MuhammadFaisalIchal indeed I store the rating value i get in a room database, but I allow the user to edit them, so I need to be able to set the rating bar to the stored value. It took me some time to understant where my problem was comming from, but removing 1 from the value stored seems to be the workaround for now.

MuhammadFaisalIchal commented 6 years ago

hmm, interesting. by the way, what programming language do you use?

I'm in that case too, but now I'm in the phase of inserting each of these 5 smileys into a database using as you said 1-5 value. Currently, I'm using PHP and Mysql as the database, but I'm confused of how to pass the value from Android -> API -> PHP script -> Database.

The problem is, I know how to insert data like (form, number, etc), because it passes String data type into API then into Database. But this smileys is integer data typed. And I've spent a lot of time searching how to pass this value.

Do you have any idea if you don't mind, please?? :( Much appreciate any helps, thank you

shining-cat commented 6 years ago

Hello, I'm using Java on Android. I have bnot worked yet with an API as the one you mention, but I have worked on PHP and MySql. The thing is PHP is not natively a strongly typed language, but inserting ints in Mysql poses no problem since casting is handle by the DB. When getting data from the DB, my guess is you will have to handle casting and checking for errors on the Java side. Maybe the API you rely on has the capability to do that for you. I am probably not the right person to discuss your case, which I have no experience with, and this place hardly seems the right place to do so, since your current difficulty hardly has anything to do with this library. I would suggest to turn yourself to forums like stackOverflow, where, if you do not find your answer, you could submit your question to the highly supportive community there, and demultiply your chance of finding someone to help you :) all the best

MuhammadFaisalIchal commented 6 years ago

Yes, you're right, the error is in Java, which is let's say I don't know how to convert it.

Anyway, thanks a lot! ^_^