< Summary

Class:DCL.MyAccount.MyProfileComponentView
Assembly:MyAccountHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/MyAccountHUD/MyProfileComponentView.cs
Covered lines:0
Uncovered lines:182
Coverable lines:182
Total lines:385
Line coverage:0% (0 of 182)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:25
Method coverage:0% (0 of 25)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%2100%
Show(...)0%6200%
Hide(...)0%6200%
OnPointerClick(...)0%6200%
Dispose()0%2100%
RefreshControl()0%2100%
SetClaimedNameMode(...)0%12300%
SetCurrentName(...)0%6200%
SetClaimNameBannerActive(...)0%2100%
SetClaimedNameModeAsInput(...)0%1321100%
SetClaimedNameDropdownOptions(...)0%12300%
SetAboutDescription(...)0%2100%
SetAboutEnabled(...)0%12300%
SetLoadingActive(...)0%2100%
SetNonValidNameWarningActive(...)0%2100%
SetLinks(...)0%6200%
ClearLinkInput()0%2100%
EnableOrDisableAddLinksOption(...)0%2100%
SetLinksEnabled(...)0%12300%
SetAdditionalInfoOptions(...)0%2100%
SetAdditionalInfoValues(...)0%2100%
SetAdditionalInfoEnabled(...)0%12300%
RefreshContentLayout()0%2100%
UpdateNameCharLimit(...)0%2100%
UpdateAboutCharLimit(...)0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/MyAccountHUD/MyProfileComponentView.cs

#LineLine coverage
 1using DCL.Helpers;
 2using System;
 3using System.Collections.Generic;
 4using TMPro;
 5using UIComponents.CollapsableSortedList;
 6using UIComponents.Scripts.Components;
 7using UnityEngine;
 8using UnityEngine.EventSystems;
 9using UnityEngine.UI;
 10
 11namespace DCL.MyAccount
 12{
 13    public class MyProfileComponentView : BaseComponentView<MyProfileModel>, IMyProfileComponentView, IPointerClickHandl
 14    {
 15        private const float DISABLED_SECTION_ALPHA = 0.7f;
 16        private const string ABOUT_READ_ONLY_CONTAINER_NAME = "AboutReadOnlyContainer";
 17
 18        [Header("General")]
 19        [SerializeField] internal GameObject mainContainer;
 20        [SerializeField] internal GameObject loadingContainer;
 21        [SerializeField] internal RectTransform contentTransform;
 22        [SerializeField] internal GameObject scrollBar;
 23
 24        [Header("Header")]
 25        [SerializeField] internal RectTransform headerContainerTransform;
 26        [SerializeField] internal CollapsableListToggleButton disclaimerButton;
 27
 28        [Header("Names")]
 29        [SerializeField] internal RectTransform namesContainerTransform;
 30        [SerializeField] internal GameObject nameTypeSelectorContainer;
 31        [SerializeField] internal GameObject nonClaimedNameModeContainer;
 32        [SerializeField] internal TMP_InputField nonClaimedNameInputField;
 33        [SerializeField] internal GameObject nonClaimedNameEditionLogo;
 34        [SerializeField] internal TMP_Text nonClaimedNameAddressHashtag;
 35        [SerializeField] internal GameObject claimNameBanner;
 36        [SerializeField] internal Button claimNameButton;
 37        [SerializeField] internal GameObject claimedNameModeContainer;
 38        [SerializeField] internal DropdownComponentView claimedNameDropdown;
 39        [SerializeField] internal Button claimedNameGoToNonClaimedNameButton;
 40        [SerializeField] internal TMP_Text claimedNameGoToNonClaimedNameButtonText;
 41        [SerializeField] internal GameObject claimedNameGoToNonClaimedNameSelectionMark;
 42        [SerializeField] internal GameObject claimedNameInputContainer;
 43        [SerializeField] internal TMP_InputField claimedNameInputField;
 44        [SerializeField] internal GameObject claimedNameEditionLogo;
 45        [SerializeField] internal TMP_Text claimedNameAddressHashtag;
 46        [SerializeField] internal Button claimedNameBackToClaimedNamesListButton;
 47        [SerializeField] internal TMP_Text claimedNameBackToClaimedNamesListButtonText;
 48        [SerializeField] internal GameObject claimedNameBackToClaimedNamesListSelectionMark;
 49        [SerializeField] internal Button claimedNameUniqueNameButton;
 50        [SerializeField] internal GameObject nameValidationsContainer;
 51        [SerializeField] internal TMP_Text nameCharCounter;
 52        [SerializeField] internal GameObject nonValidNameWarning;
 53
 54        [Header("About")]
 55        [SerializeField] internal TMP_InputField aboutInputText;
 56        [SerializeField] internal TMP_Text aboutCharCounter;
 57        [SerializeField] internal CanvasGroup aboutCanvasGroup;
 58        [SerializeField] internal GameObject editableAboutContainer;
 59        [SerializeField] internal GameObject readOnlyAboutContainer;
 60        [SerializeField] internal TMP_Text readOnlyAboutInputText;
 61
 62        [Header("Links")]
 63        [SerializeField] internal RectTransform linksContainerTransform;
 64        [SerializeField] internal MyProfileLinkListComponentView linkListView;
 65        [SerializeField] internal CanvasGroup linksCanvasGroup;
 66
 67        [Header("Additional Info")]
 68        [SerializeField] internal RectTransform additionalInfoContainerTransform;
 69        [SerializeField] internal MyProfileAdditionalInfoListComponentView additionalInfoList;
 70        [SerializeField] internal CanvasGroup additionalInfoCanvasGroup;
 71
 72        public event Action<string> OnCurrentNameEdited;
 73        public event Action<string, bool> OnCurrentNameSubmitted;
 74        public event Action OnGoFromClaimedToNonClaimNameClicked;
 75        public event Action OnClaimNameClicked;
 76        public event Action<string> OnAboutDescriptionSubmitted;
 77        public event Action<(string title, string url)> OnLinkAdded;
 78        public event Action<(string title, string url)> OnLinkRemoved;
 79
 80        public override void Awake()
 81        {
 082            base.Awake();
 83
 084            UpdateNameCharLimit(0, nonClaimedNameInputField.characterLimit);
 085            UpdateAboutCharLimit(0, aboutInputText.characterLimit);
 86
 087            nonClaimedNameInputField.onValueChanged.AddListener(newName =>
 88            {
 089                UpdateNameCharLimit(newName.Length, nonClaimedNameInputField.characterLimit);
 090                OnCurrentNameEdited?.Invoke(newName);
 091            });
 092            nonClaimedNameInputField.onSelect.AddListener(_ =>
 93            {
 094                nonClaimedNameEditionLogo.SetActive(false);
 095                nonClaimedNameAddressHashtag.gameObject.SetActive(true);
 096            });
 097            nonClaimedNameInputField.onDeselect.AddListener(newName =>
 98            {
 099                nonClaimedNameEditionLogo.SetActive(true);
 0100                nonClaimedNameAddressHashtag.gameObject.SetActive(false);
 0101                OnCurrentNameSubmitted?.Invoke(newName, false);
 0102            });
 0103            nonClaimedNameInputField.onSubmit.AddListener(newName => OnCurrentNameSubmitted?.Invoke(newName, false));
 0104            claimedNameInputField.onValueChanged.AddListener(newName =>
 105            {
 0106                UpdateNameCharLimit(newName.Length, claimedNameInputField.characterLimit);
 0107                OnCurrentNameEdited?.Invoke(newName);
 0108            });
 0109            claimedNameInputField.onSelect.AddListener(_ =>
 110            {
 0111                claimedNameEditionLogo.SetActive(false);
 0112                claimedNameAddressHashtag.gameObject.SetActive(true);
 0113            });
 0114            claimedNameInputField.onDeselect.AddListener(newName =>
 115            {
 0116                claimedNameEditionLogo.SetActive(true);
 0117                claimedNameAddressHashtag.gameObject.SetActive(false);
 0118                OnCurrentNameSubmitted?.Invoke(newName, false);
 0119            });
 0120            claimedNameInputField.onSubmit.AddListener(newName => OnCurrentNameSubmitted?.Invoke(newName, false));
 0121            claimedNameDropdown.OnOptionSelectionChanged += (isOn, optionId, _) =>
 122            {
 0123                if (!isOn) return;
 0124                OnCurrentNameSubmitted?.Invoke(optionId, true);
 0125            };
 0126            claimNameButton.onClick.AddListener(() => OnClaimNameClicked?.Invoke());
 0127            claimedNameGoToNonClaimedNameButton.onClick.AddListener(() =>
 128            {
 0129                Utils.ForceRebuildLayoutImmediate(namesContainerTransform);
 0130                OnGoFromClaimedToNonClaimNameClicked?.Invoke();
 0131            });
 0132            claimedNameBackToClaimedNamesListButton.onClick.AddListener(() =>
 133            {
 0134                Utils.ForceRebuildLayoutImmediate(namesContainerTransform);
 0135                SetClaimedNameModeAsInput(false);
 0136            });
 0137            claimedNameUniqueNameButton.onClick.AddListener(() => OnClaimNameClicked?.Invoke());
 138
 0139            aboutInputText.onValueChanged.AddListener(newDesc => UpdateAboutCharLimit(newDesc.Length, aboutInputText.cha
 0140            aboutInputText.onDeselect.AddListener(newDesc =>
 141            {
 0142                readOnlyAboutInputText.text = newDesc;
 0143                readOnlyAboutContainer.SetActive(true);
 0144                editableAboutContainer.SetActive(false);
 0145                OnAboutDescriptionSubmitted?.Invoke(newDesc);
 0146            });
 0147            aboutInputText.onSubmit.AddListener(newDesc => OnAboutDescriptionSubmitted?.Invoke(newDesc));
 148
 0149            linkListView.OnAddedNew += tuple =>
 150            {
 0151                OnLinkAdded?.Invoke((tuple.title, tuple.url));
 0152                Utils.ForceRebuildLayoutImmediate(linksContainerTransform);
 0153            };
 0154            linkListView.OnRemoved += tuple =>
 155            {
 0156                OnLinkRemoved?.Invoke((tuple.title, tuple.url));
 0157                Utils.ForceRebuildLayoutImmediate(linksContainerTransform);
 0158            };
 159
 0160            disclaimerButton.OnToggled += _ => Utils.ForceRebuildLayoutImmediate(headerContainerTransform);
 0161            additionalInfoList.OnAdditionalFieldAdded += () => Utils.ForceRebuildLayoutImmediate(additionalInfoContainer
 0162            additionalInfoList.OnAdditionalFieldRemoved += () => Utils.ForceRebuildLayoutImmediate(additionalInfoContain
 0163        }
 164
 165        public override void Show(bool instant = false)
 166        {
 0167            gameObject.SetActive(true);
 168
 0169            if (scrollBar != null)
 0170                scrollBar.SetActive(true);
 0171        }
 172
 173        public override void Hide(bool instant = false)
 174        {
 0175            gameObject.SetActive(false);
 176
 0177            if (scrollBar != null)
 0178                scrollBar.SetActive(false);
 0179        }
 180
 181        public void OnPointerClick(PointerEventData eventData)
 182        {
 0183            if (eventData.pointerCurrentRaycast.gameObject.name != ABOUT_READ_ONLY_CONTAINER_NAME)
 0184                return;
 185
 0186            readOnlyAboutContainer.SetActive(false);
 0187            editableAboutContainer.SetActive(true);
 0188            aboutInputText.Select();
 0189        }
 190
 191        public override void Dispose()
 192        {
 0193            nonClaimedNameInputField.onValueChanged.RemoveAllListeners();
 0194            nonClaimedNameInputField.onSelect.RemoveAllListeners();
 0195            nonClaimedNameInputField.onDeselect.RemoveAllListeners();
 0196            nonClaimedNameInputField.onSubmit.RemoveAllListeners();
 0197            claimedNameInputField.onSelect.RemoveAllListeners();
 0198            claimedNameInputField.onDeselect.RemoveAllListeners();
 0199            claimedNameInputField.onSubmit.RemoveAllListeners();
 0200            claimNameButton.onClick.RemoveAllListeners();
 0201            claimedNameGoToNonClaimedNameButton.onClick.RemoveAllListeners();
 0202            claimedNameBackToClaimedNamesListButton.onClick.RemoveAllListeners();
 0203            claimedNameUniqueNameButton.onClick.RemoveAllListeners();
 204
 0205            base.Dispose();
 0206        }
 207
 208        public override void RefreshControl()
 209        {
 0210            SetClaimedNameMode(model.IsClaimedMode);
 0211            SetCurrentName(model.MainName, model.NonClaimedHashtag);
 0212            SetClaimNameBannerActive(model.ShowClaimBanner);
 0213            SetClaimedNameModeAsInput(model.ShowInputForClaimedMode);
 0214            SetClaimedNameDropdownOptions(model.loadedClaimedNames);
 0215            SetAboutDescription(model.AboutDescription);
 0216        }
 217
 218        public void SetClaimedNameMode(bool isClaimed)
 219        {
 0220            model.IsClaimedMode = isClaimed;
 0221            nameTypeSelectorContainer.SetActive(isClaimed);
 0222            nonClaimedNameModeContainer.SetActive(!isClaimed);
 0223            claimedNameModeContainer.SetActive(isClaimed);
 0224            nameValidationsContainer.SetActive(!isClaimed || model.ShowInputForClaimedMode);
 0225        }
 226
 227        public void SetCurrentName(string newName, string nonClaimedHashtag)
 228        {
 0229            model.MainName = newName;
 0230            model.NonClaimedHashtag = nonClaimedHashtag;
 231
 0232            if (model.IsClaimedMode)
 233            {
 0234                claimedNameDropdown.SelectOption(newName, false);
 0235                claimedNameDropdown.SetTitle(newName);
 236            }
 237
 0238            claimedNameInputField.text = newName;
 0239            claimedNameAddressHashtag.text = $"#{nonClaimedHashtag}";
 0240            nonClaimedNameInputField.text = newName;
 0241            nonClaimedNameAddressHashtag.text = $"#{nonClaimedHashtag}";
 0242        }
 243
 244        public void SetClaimNameBannerActive(bool isActive)
 245        {
 0246            model.ShowClaimBanner = isActive;
 0247            claimNameBanner.SetActive(!model.IsClaimedMode && isActive);
 0248        }
 249
 250        public void SetClaimedNameModeAsInput(bool isInput, bool cleanInputField = false)
 251        {
 0252            model.ShowInputForClaimedMode = isInput;
 0253            claimedNameInputContainer.SetActive(isInput);
 0254            claimedNameDropdown.gameObject.SetActive(!isInput);
 0255            nameValidationsContainer.SetActive(isInput);
 0256            nameValidationsContainer.SetActive(!model.IsClaimedMode || isInput);
 257
 0258            claimedNameGoToNonClaimedNameSelectionMark.SetActive(isInput);
 0259            claimedNameBackToClaimedNamesListSelectionMark.SetActive(!isInput);
 0260            claimedNameGoToNonClaimedNameButtonText.fontStyle = isInput ? FontStyles.Bold : FontStyles.Normal;
 0261            claimedNameBackToClaimedNamesListButtonText.fontStyle = isInput ? FontStyles.Normal : FontStyles.Bold;
 262
 0263            if (cleanInputField)
 0264                claimedNameInputField.text = string.Empty;
 265
 0266            if (isInput)
 267            {
 0268                if (cleanInputField)
 0269                    claimedNameInputField.Select();
 270
 0271                return;
 272            }
 273
 0274            if (model.loadedClaimedNames.Contains(model.MainName))
 275            {
 0276                claimedNameDropdown.SelectOption(model.MainName, false);
 0277                claimedNameDropdown.SetTitle(model.MainName);
 278            }
 279            else
 280            {
 0281                claimedNameDropdown.SelectOption(
 282                    model.loadedClaimedNames.Count == 0 ? string.Empty : model.loadedClaimedNames[0],
 283                    model.loadedClaimedNames.Count != 0);
 0284                claimedNameDropdown.SetTitle(model.loadedClaimedNames.Count == 0 ? string.Empty : model.loadedClaimedNam
 285            }
 0286        }
 287
 288        public void SetClaimedNameDropdownOptions(List<string> claimedNamesList)
 289        {
 0290            model.loadedClaimedNames.Clear();
 0291            model.loadedClaimedNames.AddRange(claimedNamesList);
 292
 0293            List<ToggleComponentModel> collectionsToAdd = new ();
 294
 0295            foreach (string claimedName in claimedNamesList)
 296            {
 0297                ToggleComponentModel newCollectionModel = new ToggleComponentModel
 298                {
 299                    id = claimedName,
 300                    text = claimedName,
 301                    isOn = false,
 302                    isTextActive = true,
 303                    changeTextColorOnSelect = true,
 304                };
 305
 0306                collectionsToAdd.Add(newCollectionModel);
 307            }
 308
 0309            if (collectionsToAdd.Count > 0)
 0310                claimedNameDropdown.SetTitle(collectionsToAdd[0].text);
 311
 0312            claimedNameDropdown.SetOptions(collectionsToAdd);
 0313        }
 314
 315        public void SetAboutDescription(string newDesc)
 316        {
 0317            model.AboutDescription = newDesc;
 0318            aboutInputText.text = newDesc;
 0319            readOnlyAboutInputText.text = newDesc;
 0320        }
 321
 322        public void SetAboutEnabled(bool isEnabled)
 323        {
 0324            aboutCanvasGroup.alpha = isEnabled ? 1f : DISABLED_SECTION_ALPHA;
 0325            aboutCanvasGroup.interactable = isEnabled;
 0326            aboutCanvasGroup.blocksRaycasts = isEnabled;
 0327        }
 328
 329        public void SetLoadingActive(bool isActive)
 330        {
 0331            loadingContainer.SetActive(isActive);
 0332            mainContainer.SetActive(!isActive);
 0333        }
 334
 335        public void SetNonValidNameWarningActive(bool isActive) =>
 0336            nonValidNameWarning.SetActive(isActive);
 337
 338        public void SetLinks(List<UserProfileModel.Link> links)
 339        {
 0340            linkListView.Clear();
 341
 0342            foreach (UserProfileModel.Link link in links)
 0343                linkListView.Add(link.title, link.url);
 0344        }
 345
 346        public void ClearLinkInput() =>
 0347            linkListView.ClearInput();
 348
 349        public void EnableOrDisableAddLinksOption(bool isEnabled) =>
 0350            linkListView.EnableOrDisableAddNewLinkOption(isEnabled);
 351
 352        public void SetLinksEnabled(bool isEnabled)
 353        {
 0354            linksCanvasGroup.alpha = isEnabled ? 1f : DISABLED_SECTION_ALPHA;
 0355            linksCanvasGroup.interactable = isEnabled;
 0356            linksCanvasGroup.blocksRaycasts = isEnabled;
 0357        }
 358
 359        public void SetAdditionalInfoOptions(AdditionalInfoOptionsModel additionalInfoOptionsModel)
 360        {
 0361            additionalInfoList.SetOptions(additionalInfoOptionsModel);
 0362        }
 363
 364        public void SetAdditionalInfoValues(Dictionary<string, (string title, string value)> values)
 365        {
 0366            additionalInfoList.SetValues(values);
 0367        }
 368
 369        public void SetAdditionalInfoEnabled(bool isEnabled)
 370        {
 0371            additionalInfoCanvasGroup.alpha = isEnabled ? 1f : DISABLED_SECTION_ALPHA;
 0372            additionalInfoCanvasGroup.interactable = isEnabled;
 0373            additionalInfoCanvasGroup.blocksRaycasts = isEnabled;
 0374        }
 375
 376        public void RefreshContentLayout() =>
 0377            Utils.ForceRebuildLayoutImmediate(contentTransform);
 378
 379        private void UpdateNameCharLimit(int currentLenght, int maxLength) =>
 0380            nameCharCounter.text = $"{currentLenght}/{maxLength}";
 381
 382        private void UpdateAboutCharLimit(int currentLenght, int maxLength) =>
 0383            aboutCharCounter.text = $"{currentLenght}/{maxLength}";
 384    }
 385}