Skip to content

Instantly share code, notes, and snippets.

@IanLeatherbury
Last active August 29, 2015 14:23
Show Gist options
  • Save IanLeatherbury/0be7361e971dd66088f9 to your computer and use it in GitHub Desktop.
Save IanLeatherbury/0be7361e971dd66088f9 to your computer and use it in GitHub Desktop.
Likes
private async void GetLikes()
{
var likes = FindViewById<TextView>(Resource.Id.likes);
if (thisPoll.Likes == 1)
if (thisPoll != null)
{
if (thisPoll.Likes == 1)
{
likes.Text = thisPoll.Likes + " Like";
}
else
{
likes.Text = thisPoll.Likes + " Likes";
}
}
else
{
likes.Text = "0 Likes";
}
}
async void IncrementLike()
{
JObject pollUpdate = new JObject();
pollUpdate.Add("id", pollId);
pollUpdate.Add("Likes", thisPoll.Likes + 1);
var updateLikes = await Client.GetTable<Poll>().UpdateAsync(pollUpdate);
var likes = FindViewById<TextView>(Resource.Id.likes);
likes.Text = (thisPoll.Likes).ToString() + " Likes";
}
async void DecrementLike()
{
JObject pollUpdate = new JObject();
pollUpdate.Add("id", pollId);
pollUpdate.Add("Likes", thisPoll.Likes - 1);
var updateLikes = await Client.GetTable<Poll>().UpdateAsync(pollUpdate);
var likes = FindViewById<TextView>(Resource.Id.likes);
likes.Text = (thisPoll.Likes).ToString() + " Likes";
}
//implement like button
likeButton = FindViewById<ToggleButton>(Resource.Id.like_button);
likeButton.Click += (o, e) => {
// Perform action on clicks
if (likeButton.Checked)
IncrementLike();
else
DecrementLike();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment