FlyingPumba / SimpleRatingBar

Open source project which features a simple yet powerful RatingBar alternative to Android's default
Apache License 2.0
1.03k stars 142 forks source link

OnTouchListener is executing multiple times #8

Closed zouzoux closed 8 years ago

zouzoux commented 8 years ago

I am using a Recycler View where I have some posts you can rate them, I can't use onRatingbarChangeListener because another user might change the rating.... but when I use onTouchListener it executes too many times and also when I try to scroll down sometimes it takes time to display the average rating of the post, the animation is slow, is there somewhere we can chat like skype so we work on fixing it... Thank you!

FlyingPumba commented 8 years ago

Hi @zouzoux, I'm not sure this is a real bug. The reasons are: 1.onTouchListener is supposed to be called multiple times, that's how you get each of the MotionEvents actioned on the view. From what you wrote, it seems you are not using it for it's original purpose.

  1. I don't understand why you can't use OnRatingBarChangeListener. What do you mean by another user?
  2. In the sample application there are 5 rating bars using animation at the same time. In my phone (Motorola G) the animations were smooth, but perhaps its different in other phones. Or perhaps your ReyclerViewAdapter fails to properly recycle the view holders.

This said, if you find any part of the code in the SimpleRatingBar that can be optimized for better performance you can:

  1. Suggest the improvement by opening a new issue.
  2. Or much better, open a pull request with the changes :)
zouzoux commented 8 years ago

When I rate a post , the rating is sent to parse server database but the thing is when I only tap once onTouchListener keep executing and sending the same rating over and over again what I mean by another user is that someone else using another phone can rate the same post and change the average rating which will execute onRatingBarChangeListener and so a rating will be send from me even tough I did not rate anything....

FlyingPumba commented 8 years ago

Ok, I think I understand now. But anyway, you shouldn't be using onTouchListener, it's not meant for that. What you are missing is the fact that when the method onRatingChanged of your listener is called the third parameter is a boolean which indicates:

zouzoux commented 8 years ago

It seems that the problem happens also with onRatingChanged because as soon as I tap once to rate the post, it keep on sending the same rating on and on. Note that I used the same code with the original star rating and it was working but I want to use your Rating bar because it's simply awesome...

FlyingPumba commented 8 years ago

@zouzoux can you post some minimal code so I can replicate your problem ? Are you using version 0.1.0 ? I have added to the sample app an example of usage of onRatingChanged, and it's working just fine (no duplicated calling).

FlyingPumba commented 8 years ago

Closing this issue due to inactivity. I also answered the same question in SO: link.