Skip to content

Instantly share code, notes, and snippets.

@douglasiacovelli
Last active February 25, 2018 15:06
Show Gist options
  • Select an option

  • Save douglasiacovelli/e0c8d38df4470520bed265071d875f42 to your computer and use it in GitHub Desktop.

Select an option

Save douglasiacovelli/e0c8d38df4470520bed265071d875f42 to your computer and use it in GitHub Desktop.
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