Esempio n. 1
0
 public void BeginDispatchOnUIThread(Action action)
 {
     if (Ctrl != null)
     {
         Ctrl.BeginInvokeOnMainThread(() => action());
     }
 }
        private void StartOnAddContactAction(UINavigationController navigationController, User user)
        {
            AddressBook book = new AddressBook ();
            book.RequestPermission ().ContinueWith (task => {
                navigationController.BeginInvokeOnMainThread (delegate {
                    if (task.IsFaulted || task.IsCanceled || !task.Result)
                    {
                        ShowNoContactAccess ();
                    }

                    else
                    {
                        _canAccessAddress = true;
                        CheckForExistingAndContinue (navigationController, user, false);
                    }
                });

            },TaskScheduler.FromCurrentSynchronizationContext());
        }
        private void CheckForExistingAndContinue(UINavigationController navigationController, 
		                                          User user, bool mainThreadRequired)
        {
            KeyValuePair <string, string> namePair = GetFirstAndLastName (user);

            string firstName = namePair.Key;
            string lastName = namePair.Value;

            AddressBook book = new AddressBook ();

            foreach (Contact contact in book)
            {
                if (contact.FirstName == firstName &&
                    contact.LastName == lastName)
                {
                    if (!mainThreadRequired)
                        AskShouldAddDuplicateAndContinue (navigationController, user);
                    else
                    {
                        navigationController.BeginInvokeOnMainThread (delegate {
                            AskShouldAddDuplicateAndContinue (navigationController, user);
                        });
                    }
                    return;
                }
            }

            if (!mainThreadRequired)
                ShowAddContactController (navigationController, user);
            else
            {
                navigationController.BeginInvokeOnMainThread (delegate {
                    ShowAddContactController (navigationController, user);
                });
            }
        }