Skip to content

Instantly share code, notes, and snippets.

@anshupitlia
Last active June 9, 2020 16:42
Show Gist options
  • Save anshupitlia/ac797d6d5712c70a7d0c88db56eb5b0b to your computer and use it in GitHub Desktop.
Save anshupitlia/ac797d6d5712c70a7d0c88db56eb5b0b to your computer and use it in GitHub Desktop.
Like Button update
public class LikeButton {
private Reactions selectedReaction;
public void setSelectedReaction(Reactions selectedReaction) {
this.selectedReaction = selectedReaction;
}
LikeButton() {
selectedReaction = Reactions.LIKE;
}
public void onClick() {
if (selectedReaction == Reactions.LIKE) {
System.out.println("Show Like emoji");
} if (selectedReaction == Reactions.LOVE) {
System.out.println("Show Love emoji");
} if (selectedReaction == Reactions.HAHA) {
System.out.println("Show Haha emoji");
}
}
public void onHover() {
System.out.println("Give reaction options");
}
}
public enum Reactions {
LIKE, LOVE, HAHA
}
public class Main {
public static void main(String[] args) {
LikeButton likeButton = new LikeButton();
likeButton.onHover(); //"Give reaction options
likeButton.setSelectedReaction(Reactions.HAHA);
likeButton.onClick(); //"Shows haha emoji
likeButton.setSelectedReaction(Reactions.LOVE);
likeButton.onClick(); //"Shows love emoji
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment