| | 1 | | using System; |
| | 2 | | using TMPro; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.EventSystems; |
| | 5 | |
|
| | 6 | | namespace DCL.MyAccount |
| | 7 | | { |
| | 8 | | public class EmailNotificationsComponentView : BaseComponentView, IEmailNotificationsComponentView, IPointerClickHan |
| | 9 | | { |
| | 10 | | [SerializeField] internal GameObject mainContainer; |
| | 11 | | [SerializeField] internal GameObject loadingContainer; |
| | 12 | | [SerializeField] internal TMP_InputField emailInputField; |
| | 13 | | [SerializeField] internal GameObject emailEditionLogoContainer; |
| | 14 | | [SerializeField] internal GameObject emailEditionLogo; |
| | 15 | | [SerializeField] internal GameObject emailEditionLoadingSpinner; |
| | 16 | | [SerializeField] internal GameObject emailInputFieldInvalid; |
| | 17 | | [SerializeField] internal GameObject emailInputFieldEditing; |
| | 18 | | [SerializeField] internal GameObject emailInputInvalidLabel; |
| | 19 | | [SerializeField] internal GameObject pendingStatusWarning; |
| | 20 | | [SerializeField] internal TMP_Text pendingStatusWarningText; |
| | 21 | | [SerializeField] internal Sprite deleteEmailSprite; |
| | 22 | | [SerializeField] internal Sprite updateEmailSprite; |
| | 23 | |
|
| | 24 | | public event Action<string> OnEmailEdited; |
| | 25 | | public event Action<string> OnEmailSubmitted; |
| | 26 | | public event Action OnReSendConfirmationEmailClicked; |
| | 27 | |
|
| 0 | 28 | | public Sprite deleteEmailLogo => deleteEmailSprite; |
| 0 | 29 | | public Sprite updateEmailLogo => updateEmailSprite; |
| | 30 | |
|
| | 31 | | public override void Awake() |
| | 32 | | { |
| 0 | 33 | | base.Awake(); |
| | 34 | |
|
| 0 | 35 | | emailInputField.onValueChanged.AddListener(OnEmailTextChanged); |
| 0 | 36 | | emailInputField.onSelect.AddListener(_ => |
| | 37 | | { |
| 0 | 38 | | emailEditionLogo.SetActive(false); |
| 0 | 39 | | emailInputFieldEditing.SetActive(true); |
| 0 | 40 | | }); |
| 0 | 41 | | emailInputField.onDeselect.AddListener(OnEmailTextSubmitted); |
| 0 | 42 | | emailInputField.onSubmit.AddListener(OnEmailTextSubmitted); |
| 0 | 43 | | } |
| | 44 | |
|
| 0 | 45 | | public override void RefreshControl() { } |
| | 46 | |
|
| | 47 | | public void SetLoadingActive(bool isActive) |
| | 48 | | { |
| 0 | 49 | | loadingContainer.SetActive(isActive); |
| 0 | 50 | | mainContainer.SetActive(!isActive); |
| 0 | 51 | | } |
| | 52 | |
|
| | 53 | | public void SetEmail(string email) => |
| 0 | 54 | | emailInputField.text = email; |
| | 55 | |
|
| | 56 | | public void SetStatusAsPending(bool isPending) => |
| 0 | 57 | | pendingStatusWarning.SetActive(isPending); |
| | 58 | |
|
| | 59 | | public void SetEmailFormValid(bool isValid) |
| | 60 | | { |
| 0 | 61 | | emailInputFieldInvalid.SetActive(!isValid); |
| 0 | 62 | | emailInputInvalidLabel.SetActive(!isValid); |
| 0 | 63 | | } |
| | 64 | |
|
| | 65 | | public void ResetForm() |
| | 66 | | { |
| 0 | 67 | | emailEditionLogo.SetActive(true); |
| 0 | 68 | | emailInputFieldEditing.SetActive(false); |
| 0 | 69 | | emailInputFieldInvalid.SetActive(false); |
| 0 | 70 | | emailInputInvalidLabel.SetActive(false); |
| 0 | 71 | | SetStatusAsPending(false); |
| 0 | 72 | | } |
| | 73 | |
|
| | 74 | | public void SetEmailInputInteractable(bool isInteractable) => |
| 0 | 75 | | emailInputField.interactable = isInteractable; |
| | 76 | |
|
| | 77 | | public void SetEmailUpdateLoadingActive(bool isActive) |
| | 78 | | { |
| 0 | 79 | | emailEditionLogoContainer.SetActive(!isActive); |
| 0 | 80 | | emailEditionLoadingSpinner.SetActive(isActive); |
| 0 | 81 | | } |
| | 82 | |
|
| | 83 | | public override void Show(bool instant = false) => |
| 0 | 84 | | gameObject.SetActive(true); |
| | 85 | |
|
| | 86 | | public override void Hide(bool instant = false) => |
| 0 | 87 | | gameObject.SetActive(false); |
| | 88 | |
|
| | 89 | | public void OnPointerClick(PointerEventData eventData) |
| | 90 | | { |
| 0 | 91 | | int linkIndex = TMP_TextUtilities.FindIntersectingLink(pendingStatusWarningText, Input.mousePosition, null); |
| 0 | 92 | | if (linkIndex == -1) |
| 0 | 93 | | return; |
| | 94 | |
|
| 0 | 95 | | TMP_LinkInfo linkInfo = pendingStatusWarningText.textInfo.linkInfo[linkIndex]; |
| 0 | 96 | | if (linkInfo.GetLinkID() == "reSendConfirmationEmail") |
| 0 | 97 | | OnReSendConfirmationEmailClicked?.Invoke(); |
| 0 | 98 | | } |
| | 99 | |
|
| | 100 | | public override void Dispose() |
| | 101 | | { |
| 0 | 102 | | emailInputField.onValueChanged.RemoveAllListeners(); |
| 0 | 103 | | emailInputField.onDeselect.RemoveAllListeners(); |
| 0 | 104 | | emailInputField.onSubmit.RemoveAllListeners(); |
| | 105 | |
|
| 0 | 106 | | base.Dispose(); |
| 0 | 107 | | } |
| | 108 | |
|
| | 109 | | private void OnEmailTextChanged(string newName) |
| | 110 | | { |
| 0 | 111 | | OnEmailEdited?.Invoke(newName); |
| 0 | 112 | | } |
| | 113 | |
|
| | 114 | | private void OnEmailTextSubmitted(string newName) |
| | 115 | | { |
| 0 | 116 | | emailEditionLogo.SetActive(true); |
| 0 | 117 | | emailInputFieldEditing.SetActive(false); |
| 0 | 118 | | OnEmailSubmitted?.Invoke(newName); |
| 0 | 119 | | } |
| | 120 | | } |
| | 121 | | } |