< Summary

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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
MyAccountSectionHUDComponentView()0%2100%
Awake()0%2100%
Dispose()0%2100%
RefreshControl()0%2100%
SetAsFullScreenMenuMode(...)0%12300%
<ShowAccountSettingsUpdatedToast()0%20400%
ShowAccountSettingsUpdatedToast()0%2100%
SetSectionsMenuActive(...)0%2100%
OpenSection(...)0%12300%
SetMyProfileButtonStatus(...)0%12300%
SetEmailNotificationsButtonStatus(...)0%12300%
SetBlockedListButtonStatus(...)0%12300%
DeselectButtons()0%6200%

File(s)

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

#LineLine coverage
 1using Cysharp.Threading.Tasks;
 2using DCL.Tasks;
 3using System;
 4using System.Threading;
 5using UnityEngine;
 6using UnityEngine.EventSystems;
 7using UnityEngine.UI;
 8
 9namespace DCL.MyAccount
 10{
 11    public class MyAccountSectionHUDComponentView : BaseComponentView, IMyAccountSectionHUDComponentView
 12    {
 13        private const float COPY_TOAST_VISIBLE_TIME = 3;
 14
 15        [SerializeField] internal GameObject sectionsMenu;
 16        [SerializeField] internal MyProfileComponentView myProfileComponentView;
 17        [SerializeField] internal EmailNotificationsComponentView emailNotificationsComponentView;
 18        [SerializeField] internal BlockedListComponentView blockedListComponentView;
 19        [SerializeField] internal ShowHideAnimator accountSettingsUpdatedToast;
 20
 21        [Header("Sections Menu Configuration")]
 22        [SerializeField] internal Button myProfileButton;
 23        [SerializeField] internal GameObject myProfileButtonDeselected;
 24        [SerializeField] internal Image myProfileButtonDeselectedImage;
 25        [SerializeField] internal GameObject myProfileButtonSelected;
 26        [SerializeField] internal Image myProfileButtonSelectedImage;
 27        [SerializeField] internal Button emailNotificationsButton;
 28        [SerializeField] internal GameObject emailNotificationsButtonDeselected;
 29        [SerializeField] internal Image emailNotificationsButtonDeselectedImage;
 30        [SerializeField] internal GameObject emailNotificationsButtonSelected;
 31        [SerializeField] internal Image emailNotificationsButtonSelectedImage;
 32
 33        [SerializeField] internal Button blockedListButton;
 34        [SerializeField] internal GameObject blockedListButtonDeselected;
 35        [SerializeField] internal Image blockedListButtonDeselectedImage;
 36        [SerializeField] internal GameObject blockedListButtonSelected;
 37        [SerializeField] internal Image blockedListButtonSelectedImage;
 38
 039        public IMyProfileComponentView CurrentMyProfileView => myProfileComponentView;
 040        public IEmailNotificationsComponentView CurrentEmailNotificationsView => emailNotificationsComponentView;
 041        public IBlockedListComponentView CurrentBlockedListComponentView => blockedListComponentView;
 42
 43        private Transform thisTransform;
 044        private CancellationTokenSource showAccountSettingsCancellationToken = new ();
 45
 46        public override void Awake()
 47        {
 048            base.Awake();
 49
 050            thisTransform = transform;
 51
 052            myProfileButton.onClick.AddListener(() => OpenSection(MyAccountSection.MyProfile));
 053            emailNotificationsButton.onClick.AddListener(() => OpenSection(MyAccountSection.EmailNotifications));
 054            blockedListButton.onClick.AddListener(() => OpenSection(MyAccountSection.BlockedList));
 55
 056            OpenSection(MyAccountSection.MyProfile);
 057        }
 58
 59        public override void Dispose()
 60        {
 061            base.Dispose();
 62
 063            showAccountSettingsCancellationToken.SafeCancelAndDispose();
 064            myProfileButton.onClick.RemoveAllListeners();
 065            emailNotificationsButton.onClick.RemoveAllListeners();
 066        }
 67
 068        public override void RefreshControl() { }
 69
 70        public void SetAsFullScreenMenuMode(Transform parentTransform)
 71        {
 072            if (parentTransform == null)
 073                return;
 74
 075            thisTransform.SetParent(parentTransform);
 076            thisTransform.localScale = Vector3.one;
 77
 078            RectTransform rectTransform = thisTransform as RectTransform;
 079            if (rectTransform == null) return;
 080            rectTransform.anchorMin = Vector2.zero;
 081            rectTransform.anchorMax = Vector2.one;
 082            rectTransform.pivot = new Vector2(0.5f, 0.5f);
 083            rectTransform.localPosition = Vector2.zero;
 084            rectTransform.offsetMax = Vector2.zero;
 085            rectTransform.offsetMin = Vector2.zero;
 086        }
 87
 88        public void ShowAccountSettingsUpdatedToast()
 89        {
 90            async UniTaskVoid ShowAccountSettingsUpdatedToastAsync(CancellationToken cancellationToken)
 91            {
 092                cancellationToken.ThrowIfCancellationRequested();
 93
 094                if (!accountSettingsUpdatedToast.gameObject.activeSelf)
 095                    accountSettingsUpdatedToast.gameObject.SetActive(true);
 96
 097                accountSettingsUpdatedToast.Show();
 098                await UniTask.Delay(TimeSpan.FromSeconds(COPY_TOAST_VISIBLE_TIME), cancellationToken: cancellationToken)
 099                accountSettingsUpdatedToast.Hide();
 0100            }
 101
 0102            showAccountSettingsCancellationToken = showAccountSettingsCancellationToken.SafeRestart();
 0103            ShowAccountSettingsUpdatedToastAsync(showAccountSettingsCancellationToken.Token).Forget();
 0104        }
 105
 106        public void SetSectionsMenuActive(bool isActive) =>
 0107            sectionsMenu.SetActive(isActive);
 108
 109        private void OpenSection(MyAccountSection section)
 110        {
 0111            DeselectButtons();
 112
 113            switch (section)
 114            {
 115                default:
 116                case MyAccountSection.MyProfile:
 0117                    SetMyProfileButtonStatus(true);
 0118                    SetEmailNotificationsButtonStatus(false);
 0119                    SetBlockedListButtonStatus(false);
 0120                    myProfileComponentView.Show();
 0121                    emailNotificationsComponentView.Hide();
 0122                    blockedListComponentView.Hide();
 0123                    break;
 124                case MyAccountSection.EmailNotifications:
 0125                    SetMyProfileButtonStatus(false);
 0126                    SetEmailNotificationsButtonStatus(true);
 0127                    SetBlockedListButtonStatus(false);
 0128                    myProfileComponentView.Hide();
 0129                    emailNotificationsComponentView.Show();
 0130                    blockedListComponentView.Hide();
 0131                    break;
 132                case MyAccountSection.BlockedList:
 0133                    SetMyProfileButtonStatus(false);
 0134                    SetEmailNotificationsButtonStatus(false);
 0135                    SetBlockedListButtonStatus(true);
 0136                    myProfileComponentView.Hide();
 0137                    emailNotificationsComponentView.Hide();
 0138                    blockedListComponentView.Show();
 139                    break;
 140            }
 141
 0142            DataStore.i.myAccount.openSection.Set(section.ToString());
 0143        }
 144
 145        private void SetMyProfileButtonStatus(bool isSelected)
 146        {
 0147            myProfileButton.targetGraphic = isSelected ? myProfileButtonSelectedImage : myProfileButtonDeselectedImage;
 0148            myProfileButtonDeselected.SetActive(!isSelected);
 0149            myProfileButtonSelected.SetActive(isSelected);
 0150        }
 151
 152        private void SetEmailNotificationsButtonStatus(bool isSelected)
 153        {
 0154            emailNotificationsButton.targetGraphic = isSelected ? emailNotificationsButtonSelectedImage : emailNotificat
 0155            emailNotificationsButtonDeselected.SetActive(!isSelected);
 0156            emailNotificationsButtonSelected.SetActive(isSelected);
 0157        }
 158
 159        private void SetBlockedListButtonStatus(bool isSelected)
 160        {
 0161            blockedListButton.targetGraphic = isSelected ? blockedListButtonSelectedImage : blockedListButtonDeselectedI
 0162            blockedListButtonDeselected.SetActive(!isSelected);
 0163            blockedListButtonSelected.SetActive(isSelected);
 0164        }
 165
 166        private static void DeselectButtons()
 167        {
 0168            if (EventSystem.current == null)
 0169                return;
 170
 0171            EventSystem.current.SetSelectedGameObject(null);
 0172        }
 173    }
 174}