Last active
February 25, 2018 15:06
-
-
Save douglasiacovelli/e0c8d38df4470520bed265071d875f42 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun onClickLikeButton() { | |
| if (viewModel.liked) { | |
| removeLike() | |
| } else { | |
| addLike() | |
| } | |
| } | |
| private fun showError(errorMessage: String) { | |
| Toast.makeToast(activity, errorMessage, LENGTH_LONG).show() | |
| } | |
| private fun addLike() { | |
| viewModel.addLikeLocally() | |
| apiService.addLike.enqueue({ response -> | |
| viewModel.count = response.count | |
| }, { failure -> | |
| showError("Ops an error occurred") | |
| viewModel.removeLikeLocally() | |
| }) | |
| } | |
| private removeLike() { | |
| viewModel.removeLikeLocally() | |
| apiService.removeLike.enqueue({ response -> | |
| viewModel.count = response.count | |
| }, { failure -> | |
| showError("Ops an error occurred") | |
| viewModel.addLikeLocally() | |
| }) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment