private void OnListTasks(LazyResult <Tasks.v1.Data.Tasks> response)
        {
            Tasks.v1.Data.Tasks result = null;

            try {
                result = response.GetResult();
            } catch (Exception ex) {
                AppDelegate.FinishActivity();
                ReloadComplete();
                ShowError(ex);
                return;
            }

            BeginInvokeOnMainThread(() => {
                var section = Root.First();
                section.Clear();

                if (result.Items != null)
                {
                    section.AddAll(result.Items.Select(t =>
                                                       new StyledStringElement(t.Title, () => OnTap(t))
                    {
                        Accessory = (t.Status == "completed") ? UITableViewCellAccessory.Checkmark : UITableViewCellAccessory.None
                    }
                                                       ).Cast <Element>());
                }

                ReloadComplete();

                AppDelegate.FinishActivity();
            });
        }
        private void CreateItem(string text)
        {
            Task task = new Task {
                Title = text
            };

            AppDelegate.AddActivity();

            this.service.Tasks.Insert(task, this.list.Id).FetchAsync(lr => {
                AppDelegate.FinishActivity();

                Refresh();
            });
        }
        private void OnTap(Task task)
        {
            AppDelegate.AddActivity();

            bool completing = (task.Status != "completed");

            task.Status    = (completing) ? "completed" : "needsAction";
            task.Completed = (completing) ? XmlConvert.ToString(DateTime.Now, "yyyy-MM-ddTHH:mm:sszzzzzz") : null;

            this.service.Tasks.Update(task, this.list.Id, task.Id)
            .FetchAsync(lr => {
                Refresh();
                AppDelegate.FinishActivity();
            });
        }
        private void CreateList(string name)
        {
            if (String.IsNullOrWhiteSpace(name))
            {
                return;
            }

            AppDelegate.AddActivity();

            this.service.Tasklists.Insert(new TaskList {
                Title = name
            })
            .FetchAsync(lr => {
                TaskList result = lr.GetResult();

                AppDelegate.FinishActivity();

                BeginInvokeOnMainThread(() => {
                    var tasks = new TasksViewController(this.service, result);
                    NavigationController.PushViewController(tasks, animated: true);
                });
            });
        }
        private void OnTaskListResponse(LazyResult <TaskLists> response)
        {
            TaskLists lists = null;

            try {
                lists = response.GetResult();
            } catch (Exception ex) {
                BeginInvokeOnMainThread(ReloadComplete);
                AppDelegate.FinishActivity();
                ShowError(ex);
            }

            if (lists == null || lists.Items == null)
            {
                AppDelegate.FinishActivity();
                return;
            }

            Section section = new Section();

            section.AddAll(lists.Items.Select(l =>
                                              new StringElement(l.Title, () => {
                var tasks = new TasksViewController(this.service, l);
                NavigationController.PushViewController(tasks, true);
            })
                                              ).Cast <Element>());

            BeginInvokeOnMainThread(() => {
                Root.Clear();
                Root.Add(section);

                ReloadComplete();

                AppDelegate.FinishActivity();
            });
        }