public override void RestoreUserActivityState(NSUserActivity activity)
        {
            base.RestoreUserActivityState (activity);
            Console.Write ("RestoreUserActivityState ");
            if ((activity.ActivityType == ActivityTypes.Detail)
                || (activity.ActivityType == ActivityTypes.Add))
            {
                Console.WriteLine ("NSUserActivity " + activity.ActivityType);
                if (activity.UserInfo == null || activity.UserInfo.Count == 0) {
                    // new todo
                    current = new Task();
                } else {
                    // load existing todo
                    var id = activity.UserInfo.ObjectForKey (ActivityKeys.Id).ToString ();
                    current = AppDelegate.Current.TaskMgr.GetTask (Convert.ToInt32 (id));
                }
            }
            if (activity.ActivityType == CSSearchableItem.ActionType) {
                Console.WriteLine ("CSSearchableItem.ActionType");
                var uid = activity.UserInfo [CoreSpotlight.CSSearchableItem.ActivityIdentifier];

                current = AppDelegate.Current.TaskMgr.GetTask (Convert.ToInt32 (uid.Description));

                Console.WriteLine ("eeeeeeee RestoreUserActivityState " + uid);
            }

            // CoreSpotlight index can get out-of-date, show 'empty' task if the requested id is invalid
            if (current == null) {
                current = new Task { Name = "(not found)" };
            }
        }
 public void DeleteTask(Task task)
 {
     Console.WriteLine("Delete "+task.Name);
     if (task.Id >= 0) {
         AppDelegate.Current.TaskMgr.DeleteTask (task.Id);
         SpotlightHelper.Delete (task);
     }
 }
		public void CreateTask () {
			// first, add the task to the underlying data
			var newId = tasks[tasks.Count - 1].Id + 1;
			var newTask = new Task(){Id=newId};
			tasks.Add (newTask);
			// then open the detail view to edit it
			var detail = Storyboard.InstantiateViewController("detail") as TaskDetailViewController;
			detail.SetTask (this, newTask);
			NavigationController.PushViewController (detail, true);

			// Could to this instead of the above, but need to create 'new Task()' in PrepareForSegue()
			//this.PerformSegue ("TaskSegue", this);
		}
 public static void Delete(Task t)
 {
     CSSearchableIndex.DefaultSearchableIndex.Delete (new string[] {t.Id.ToString()}, err => {
         if (err != null) {
             Console.WriteLine (err);
             Insights.Report(new Exception("CoreSpotlight Delete Failed"), new Dictionary <string, string> {
                 {"Message", err.ToString()}
             }, Xamarin.Insights.Severity.Error);
         } else {
             Console.WriteLine ("Deleted inividual item from CS index");
         }
     });
 }
        public static void Index(Task t)
        {
            var attributeSet = new CSSearchableItemAttributeSet (UTType.Text);
            attributeSet.Title = t.Name;
            attributeSet.ContentDescription = t.Notes;
            attributeSet.TextContent = t.Notes;

            var dataItem = new CSSearchableItem (t.Id.ToString(), Spotlight.SearchDomain, attributeSet);

            CSSearchableIndex.DefaultSearchableIndex.Index (new CSSearchableItem[] {dataItem}, err => {
                if (err != null) {
                    Console.WriteLine (err);
                    Insights.Report(new Exception("CoreSpotlight Index Failed"), new Dictionary <string, string> {
                        {"Message", err.ToString()}
                    }, Xamarin.Insights.Severity.Error);
                } else {
                    Console.WriteLine ("Indexed inividual item successfully");
                    Insights.Track("CoreSpotlight", new Dictionary<string, string> {
                        {"Type", "Indexed successfully"}
                    });
                }
            });
        }
		// this will be called before the view is displayed 
		public void SetTask (RootViewController d, Task task) {
			Delegate = d;
			currentTask = task;
		}
 public int SaveTask(Task item)
 {
     return repository.SaveTask(item);
 }
 public TodoCollectionSource(Task[] items)
 {
     tableItems = items.ToList();
 }
 public ContactHelper(Task todo)
 {
     current = todo;
 }
		public void DeleteTask (Task task) {
			Console.WriteLine("Delete "+task.Name);
			var oldTask = tasks.Find(t => t.Id == task.Id);
			tasks.Remove (oldTask);
			NavigationController.PopViewController(true);
		}
		public void SaveTask (Task task) {
			Console.WriteLine("Save "+task.Name);
			var oldTask = tasks.Find(t => t.Id == task.Id);
			oldTask = task;
			NavigationController.PopViewController(true);
		}
 // this will be called before the view is displayed
 public void SetTodo(Task todo)
 {
     current = todo;
 }
		public RootTableSource (Task[] items)
		{
			tableItems = items; 
		}
 public void SaveTask(Task task)
 {
     AppDelegate.Current.TaskMgr.SaveTask(task);
     SpotlightHelper.Index (task);
 }
 public int SaveTask(Task item)
 {
     return db.SaveItem<Task>(item);
 }