/// <summary> /// Deletes all the UI fields and rebuilds them based on _contact. /// Any unsaved changes on the fields will be lost. Call UpdateContactFromFields() /// before calling Refresh() if changes needed to be saved. /// </summary> private void Refresh() { DestroyListItems(); _nameField.Text = _contact.Name; _nameField.enabled = IsEditing; float yOffset = 0.01f; const float xOffset = -0.25f; const float yOffsetInc = -0.03f; for (int i = 0; i < _contact.PhoneNumberList.Count; ++i) { MLContactsTaggedAttribute phoneNumber = _contact.PhoneNumberList.Items[i]; GameObject itemGO = Instantiate(_attributeItem.gameObject, transform); itemGO.transform.localPosition = new Vector3(xOffset, yOffset, 0); yOffset += yOffsetInc; ContactAttributeItem item = itemGO.GetComponent <ContactAttributeItem>(); item.ContactPage = this; item.Attribute = phoneNumber; item.ListIndex = i; item.DeleteCommand = RemovePhoneNumber; _phoneNumberGOList.Add(itemGO); } _addPhoneButton.gameObject.SetActive(IsEditing); _addPhoneButton.transform.localPosition = new Vector3(xOffset, yOffset, 0); if (IsEditing) { yOffset += 2 * yOffsetInc; } else if (_contact.PhoneNumberList.Count > 0) { yOffset += yOffsetInc; } for (int i = 0; i < _contact.EmailAddressList.Count; ++i) { MLContactsTaggedAttribute emailAddress = _contact.EmailAddressList.Items[i]; GameObject itemGO = Instantiate(_attributeItem.gameObject, transform); itemGO.transform.localPosition = new Vector3(xOffset, yOffset, 0); yOffset += yOffsetInc; ContactAttributeItem item = itemGO.GetComponent <ContactAttributeItem>(); item.ContactPage = this; item.Attribute = emailAddress; item.ListIndex = i; item.DeleteCommand = RemoveEmailAddress; item.enabled = IsEditing; _emailAddressGOList.Add(itemGO); } _addEmailButton.gameObject.SetActive(IsEditing); _addEmailButton.transform.localPosition = new Vector3(xOffset, yOffset, 0); }
/// <summary> /// Handler when the user wants to add a new email address. /// </summary> private void HandleAddEmail() { UpdateContactFromFields(); MLContactsTaggedAttribute attr = new MLContactsTaggedAttribute(); attr.Tag = "<i>Tag</i>"; attr.Value = "<i>E-mail</i>"; _contact.EmailAddressList.Items.Add(attr); Refresh(); }
/// <summary> /// Handler when the user wants to add a new phone number. /// </summary> private void HandleAddPhone() { UpdateContactFromFields(); MLContactsTaggedAttribute attr = new MLContactsTaggedAttribute(); attr.Tag = "<i>Tag</i>"; attr.Value = "<i>Number</i>"; _contact.PhoneNumberList.Items.Add(attr); Refresh(); }