/* Rename the Selected Task for the Logged in User to the Given Title, Cancelling on Blank. */ private async void TryRename(SlideItem.SlideItem item) { var title = Interaction.InputBox( "To what title would you like to rename this task? " + "Leave it blank to cancel renaming the task." ); if (!string.IsNullOrEmpty(title)) { using (var client = new HttpClient()) { try { HttpResponseMessage response = await client.GetAsync( BaseApiUrl + $"task/update/{ LoginToken }/{ item.Tag }/" + $"{ title }/" + $"{ item.Controls[ "btnLeft" ].Tag }"); if (response.IsSuccessStatusCode) { var reply = XDocument.Parse(await response.Content.ReadAsStringAsync()); if (reply.Descendants("success").Any()) { item.Controls["btnMain"].Text = title; } } } catch { } } } }
/* Delete the Selected Task from the List for the Logged in User. Confirm on 2-second Hold. */ private async void TryDelete(SlideItem.SlideItem item) { var frm = new frmDelete(2, "your task"); Hide(); if (frm.ShowDialog(this) == DialogResult.Yes) { Show(); using (var client = new HttpClient()) { try { HttpResponseMessage response = await client.GetAsync( BaseApiUrl + $"task/delete/{ LoginToken }/{ item.Tag }"); if (response.IsSuccessStatusCode) { var reply = XDocument.Parse(await response.Content.ReadAsStringAsync()); if (reply.Descendants("success").Any()) { flowLayoutPanel.Controls.Remove(item); } } } catch { } } } else { Show(); } }
/* Toggle the Selected Task for the Logged in User from Done to Not Done, or Vice Versa. */ private async void TryToggle(SlideItem.SlideItem item) { using (var client = new HttpClient()) { var done = (bool)item.Controls["btnLeft"].Tag; try { HttpResponseMessage response = await client.GetAsync( BaseApiUrl + $"task/update/{ LoginToken }/{ item.Tag }/" + $"{ item.Controls[ "btnMain" ].Text }/" + $"{ ! done }"); if (response.IsSuccessStatusCode) { var reply = XDocument.Parse(await response.Content.ReadAsStringAsync()); if (reply.Descendants("success").Any()) { item.Controls["btnLeft"].Tag = done = !done; item.Controls["btnMain"].Font = new Font( item.Controls["btnMain"].Font , done ? FontStyle.Strikeout : FontStyle.Regular); } } } catch { } } }
/* Implementation Methods */ /* Get the Lists for the Logged in User. */ private async void TryGetLists() { using (var client = new HttpClient()) { try { HttpResponseMessage response = await client.GetAsync( BaseApiUrl + $"user/lists/{ LoginToken }"); if (response.IsSuccessStatusCode) { var reply = XDocument.Parse(await response.Content.ReadAsStringAsync()); if (reply.Descendants("success").Any()) { foreach (XElement list in reply.Descendants("list")) { var item = new SlideItem.SlideItem( "Rename", "Delete" , WebUtility.UrlDecode(list.Element("title").Value) ); item.Tag = list.Element("id").Value; item.Click += Item_Click; item.SlideLeft += Item_SlideLeft; item.SlideRight += Item_SlideRight; flowLayoutPanel.Controls.Add(item); } } } } catch { } } }
/* View all the Tasks for the Selected List of the Logged in User. */ private void ViewTasks(SlideItem.SlideItem item) { var view = new frmTasks( LoginToken, BaseApiUrl , (string)item.Tag, item.Controls["btnMain"].Text); Hide(); view.ShowDialog(this); Show(); }
/* Implementation Methods. */ /* Get the Tasks for the Selected List of the Logged in User. */ private async void TryGetTasks() { using (var client = new HttpClient()) { try { HttpResponseMessage response = await client.GetAsync( BaseApiUrl + $"list/tasks/{ LoginToken }/{ ListID }"); if (response.IsSuccessStatusCode) { var reply = XDocument.Parse(await response.Content.ReadAsStringAsync()); if (reply.Descendants("success").Any()) { foreach (XElement task in reply.Descendants("task")) { var item = new SlideItem.SlideItem( "Toggle", "Delete" , WebUtility.UrlDecode(task.Element("title").Value) ); item.Tag = task.Element("id").Value; item.Click += Item_Click; item.SlideLeft += Item_SlideLeft; item.SlideRight += Item_SlideRight; item.Controls["btnLeft"].Tag = bool.Parse(task.Element("done").Value); if (bool.Parse(task.Element("done").Value)) { item.Controls["btnMain"].Font = new Font( item.Controls["btnMain"].Font, FontStyle.Strikeout); } flowLayoutPanel.Controls.Add(item); } } } } catch { } } }
/* Add a Task to the List for the Logged in User. Cancel Task Addition on Blank. */ private async void TryAdd() { var title = Interaction.InputBox( "What title would you like for this task? " + "Leave it blank to cancel adding the task." ); if (!string.IsNullOrEmpty(title)) { using (var client = new HttpClient()) { try { HttpResponseMessage response = await client.GetAsync( BaseApiUrl + $"task/add/{ LoginToken }/{ ListID }/{ title }/false"); if (response.IsSuccessStatusCode) { var reply = XDocument.Parse(await response.Content.ReadAsStringAsync()); if (reply.Descendants("success").Any()) { var item = new SlideItem.SlideItem("Toggle", "Delete", title); item.Tag = reply.Descendants("taskid").FirstOrDefault().Value; item.Click += Item_Click; item.SlideLeft += Item_SlideLeft; item.SlideRight += Item_SlideRight; item.Controls["btnLeft"].Tag = false; flowLayoutPanel.Controls.Add(item); } } } catch { } } } }
private void Item_Click(object sender, EventArgs e) { SlideItem.SlideItem item = (SlideItem.SlideItem)sender; TryRename(item); }
private void Item_SlideRight(object sender, EventArgs e) { SlideItem.SlideItem item = (SlideItem.SlideItem)sender; TryToggle(item); }
private void Item_SlideLeft(object sender, EventArgs e) { SlideItem.SlideItem item = (SlideItem.SlideItem)sender; TryDelete(item); }
private void Item_Click(object sender, EventArgs e) { SlideItem.SlideItem item = (SlideItem.SlideItem)sender; ViewTasks(item); }