/// <summary> /// Event for adding a contact from the contact book /// </summary> private void AddRecipientFromContactButton_TouchUpInside(object sender, EventArgs e) { _isComeFromContact = true; if (contactPickerView == null) { contactPickerView = new CNContactPickerViewController(); contactPickerView.DisplayedPropertyKeys = new NSString[] { CNContactKey.EmailAddresses }; contactPickerView.PredicateForEnablingContact = NSPredicate.FromFormat("emailAddresses.@count > 0"); contactPickerView.PredicateForSelectionOfContact = NSPredicate.FromFormat("emailAddresses.@count == 1"); var contactPickerDelegate = new ContactPickerDelegate(); contactPickerView.Delegate = contactPickerDelegate; contactPickerDelegate.SelectionCanceled += () => { }; contactPickerDelegate.ContactPropertySelected += (property) => { }; contactPickerDelegate.ContactsSelected += (CNContactPickerViewController picker, CNContact[] contacts) => { foreach (var contact in contacts) { if (App.Locator.Alert.LsRecipients.Any((arg) => arg.Email.ToLower() == contact.EmailAddresses[0].Value.ToString().Trim().ToLower())) { continue; } var recipient = new AlertRecipientDTO(); recipient.DisplayName = string.Format("{0} {1}", contact.GivenName, contact.FamilyName); recipient.Email = contact.EmailAddresses[0].Value.ToString().Trim(); AddRecipientToRecipientContainer(recipient); } }; } PresentViewController(contactPickerView, true, null); }
/// <summary> /// Create a contact container /// </summary> private void CreateContactContainerUI(AlertRecipientDTO contact) { if (App.Locator.AlertSOS.LsRecipients.Count == 0) { EmptyDataButton.Hidden = false; return; } else { EmptyDataButton.Hidden = true; } var customView = new UIView(); var sizeUI = (contact.Email.Length > contact.DisplayName.Length ? contact.Email.Length : contact.DisplayName.Length) * 7; var contactNameLable = new UILabel(); contactNameLable.Frame = new RectangleF(3f, 7f, sizeUI, 20f); contactNameLable.Text = contact.DisplayName; contactNameLable.Font = UIFont.FromName("Helvetica", 15f); contactNameLable.TextColor = UIColor.FromRGB(102, 102, 102); var emailLabel = new UILabel(); emailLabel.Frame = new RectangleF(3f, 30f, sizeUI, 20f); emailLabel.Text = contact.Email; emailLabel.Font = UIFont.FromName("Helvetica", 12f); emailLabel.TextColor = UIColor.FromRGB(153, 153, 153); var deleteButton = new UIButton(UIButtonType.RoundedRect); deleteButton.Frame = new RectangleF(sizeUI + 6f, 16f, 25f, 25f);; deleteButton.SetImage(UIImage.FromBundle("Trash"), UIControlState.Normal); deleteButton.Tag = _index; // Delete the content of ScrollView. deleteButton.TouchUpInside += (s, e) => { var index = (int)deleteButton.Tag; App.Locator.AlertSOS.LsRecipients.RemoveAt(index); UpdateScrollViewUI(); SaveButton.Enabled = true; }; customView.AddSubview(contactNameLable); customView.AddSubview(emailLabel); customView.AddSubview(deleteButton); customView.Frame = new RectangleF(_sizeFrame, 0f, sizeUI + 30f, 46f); _sizeFrame += (sizeUI + 30); ScrollViewContact.AddSubview(customView); ScrollViewContact.ContentSize = new CGSize(_sizeFrame, 46f); ScrollViewContact.SetNeedsDisplay(); _index++; }
/// <summary> /// Event for adding a contact from the popup when no data /// </summary> private void EmptyDataButton_TouchUpInside() { var alertView = AlertControllerHelper.ShowAlertToAddContact((displayNameTextField, emailTextField) => { if (App.Locator.Alert.LsRecipients.Any((arg) => arg.Email.ToLower() == emailTextField.Text.Trim().ToLower())) { return(false); } // adding contact in the contact container if (VerificationFields(emailTextField)) { var recipient = new AlertRecipientDTO(); recipient.DisplayName = displayNameTextField.Text; recipient.Email = emailTextField.Text.Trim(); AddRecipientToRecipientContainer(recipient); return(true); } return(false); }); PresentViewController(alertView, true, null); }
/// <summary> /// Method for Add and Update a contact to ScrollView /// </summary> private void AddRecipientToRecipientContainer(AlertRecipientDTO contact) { App.Locator.Alert.LsRecipients.Add(contact); CreateContactContainerUI(contact); }
/// <summary> /// Method for Add and Update a contact to ScrollView /// </summary> private void AddRecipientToRecipientContainer(AlertRecipientDTO contact) { App.Locator.AlertSOS.LsRecipients.Add(contact); UpdateScrollViewContentSize(); CreateContactContainerUI(contact); }