I'm thinking about implementing a "liking" mechanism for a social network app (using Parse) whereby users select a value from a discrete slider beneath each post. The slide would range from 0-5 and reflect the post's value to users. An example of the slider is below:


enter image description here

Each "Post" ParseObject would have a column (Number) called "likeCount". This column should be updated for each "like". A change listener would wait for a user to release their finger from the slider and then store that value in the Post ParseObject, i.e. first by storing the user's objectId in a column (Array) that stores unique objectIds:

Sting currentUserObjectId = ParseUser.getCurrentUser().getObjectId();
postObject.addAllUnique("likedBy", Collections.singletonList(currentUserObjectId))

Updating the likeCount on the postObject would work as follows (using something like https://github.com/sonyckovoor/Discrete-Slider/blob/master/sample/src/main/java/in/sc9/samples/discreteslider/MainActivity.java):

public void onProgressChanged(DiscreteSlider seekBar, int value, boolean fromUser) {

 int likeCountInc = value;
 postObject.increment("likeCount", likeCountInc)


Lastly, I'd set the likeCount TextView in the post itself:

int likeCount_int = yeet.getInt("likeCount").size();
int likedByList_int = yeet.getList("likedBy").size();
int averageLikeValue_int = likeCount_int / likedByList_int;
String averageLikeValue_string = Integer.toString(averageLikeValue_int);

Would Integer division be a problem here? Is there a more effective implementation for this design?

  • \$\begingroup\$ I'm torn on this one, this really is more of an architecture question than a code review, isn't it? \$\endgroup\$ – Bobby Oct 29 '20 at 12:18
  • \$\begingroup\$ "Would Integer division be a problem here?" Integer division is always a problem unless explicitly wanted, because "99 / 100" will yield "0", which is most of the time not something one wants. \$\endgroup\$ – Bobby Oct 29 '20 at 12:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.