< Summary

Class:DCL.Social.Friends.SendFriendRequestHUDComponentView
Assembly:FriendRequestHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/FriendRequestHUD/SendFriendRequestHUDComponentView.cs
Covered lines:0
Uncovered lines:59
Coverable lines:59
Total lines:133
Line coverage:0% (0 of 59)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:12
Method coverage:0% (0 of 12)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Create()0%2100%
Awake()0%6200%
Dispose()0%6200%
RefreshControl()0%30500%
Close()0%2100%
Show(...)0%2100%
SetName(...)0%2100%
SetProfilePicture(...)0%2100%
ShowPendingToSend()0%2100%
ShowSendSuccess()0%2100%
ClearInputField()0%2100%
RefreshMessageBodyValidations(...)0%30500%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/FriendRequestHUD/SendFriendRequestHUDComponentView.cs

#LineLine coverage
 1using DCL.Helpers;
 2using System;
 3using TMPro;
 4using UIComponents.Scripts.Components;
 5using UnityEngine;
 6using UnityEngine.UI;
 7
 8namespace DCL.Social.Friends
 9{
 10    public class SendFriendRequestHUDComponentView : BaseComponentView<SendFriendRequestHUDModel>, ISendFriendRequestHUD
 11    {
 12        [SerializeField] internal ShowHideAnimator showHideAnimatorForDefaultState;
 13        [SerializeField] internal GameObject pendingToSendContainer;
 14        [SerializeField] internal ShowHideAnimator showHideAnimatorForSuccessState;
 15        [SerializeField] internal TMP_Text nameLabel;
 16        [SerializeField] internal TMP_Text successStateLabel;
 17        [SerializeField] internal Button[] cancelButtons;
 18        [SerializeField] internal Button sendButton;
 19        [SerializeField] internal TMP_InputField messageBodyInput;
 20        [SerializeField] internal TMP_Text messageBodyLengthLabel;
 21        [SerializeField] internal Image messageBodyMaxLimitMark;
 22        [SerializeField] internal ImageComponentView profileImage;
 23        [SerializeField] internal Color bodyMaxLimitColor;
 24
 25        private ILazyTextureObserver lastProfilePictureObserver;
 26        private Color messageBodyLengthOriginalColor;
 27
 28        public event Action<string> OnMessageBodyChanged;
 29        public event Action OnSend;
 30        public event Action OnCancel;
 31
 32        public static SendFriendRequestHUDComponentView Create() =>
 033            Instantiate(
 34                Resources.Load<SendFriendRequestHUDComponentView>("FriendRequests/SendFriendRequestHUD"));
 35
 36        public override void Awake()
 37        {
 038            base.Awake();
 39
 040            foreach (var button in cancelButtons)
 041                button.onClick.AddListener(() => OnCancel?.Invoke());
 42
 043            messageBodyInput.onValueChanged.AddListener(s =>
 44            {
 045                RefreshMessageBodyValidations(s);
 046                OnMessageBodyChanged?.Invoke(s);
 047            });
 048            sendButton.onClick.AddListener(() => OnSend?.Invoke());
 49
 050            messageBodyLengthOriginalColor = messageBodyLengthLabel.color;
 051        }
 52
 53        public override void Dispose()
 54        {
 055            base.Dispose();
 056            model.ProfilePictureObserver?.RemoveListener(profileImage.SetImage);
 057        }
 58
 59        public override void RefreshControl()
 60        {
 061            sendButton.gameObject.SetActive(model.State != SendFriendRequestHUDModel.LayoutState.Pending);
 062            sendButton.interactable = model.State != SendFriendRequestHUDModel.LayoutState.Pending;
 63
 064            foreach (Button cancelButton in cancelButtons)
 065                cancelButton.interactable = model.State != SendFriendRequestHUDModel.LayoutState.Pending;
 66
 067            nameLabel.text = model.Name;
 068            successStateLabel.text = $"Friend request sent to {model.Name}";
 069            messageBodyLengthLabel.text = $"{messageBodyInput.text.Length}/{messageBodyInput.characterLimit}";
 070            RefreshMessageBodyValidations(messageBodyInput.text);
 71
 72            // the load of the profile picture gets stuck if the same listener is registered many times
 073            if (lastProfilePictureObserver != model.ProfilePictureObserver)
 74            {
 075                lastProfilePictureObserver?.RemoveListener(profileImage.SetImage);
 076                model.ProfilePictureObserver?.AddListener(profileImage.SetImage);
 077                lastProfilePictureObserver = model.ProfilePictureObserver;
 78            }
 079        }
 80
 081        public void Close() => base.Hide();
 82
 83        public override void Show(bool instant = false)
 84        {
 085            base.Show(instant);
 086            model.State = SendFriendRequestHUDModel.LayoutState.Default;
 087            showHideAnimatorForDefaultState.Show(true);
 088            pendingToSendContainer.SetActive(false);
 089            showHideAnimatorForSuccessState.Hide(true);
 090            RefreshControl();
 091        }
 92
 93        public void SetName(string name)
 94        {
 095            model.Name = name;
 096            RefreshControl();
 097        }
 98
 99        public void SetProfilePicture(ILazyTextureObserver textureObserver)
 100        {
 0101            model.ProfilePictureObserver = textureObserver;
 0102            RefreshControl();
 0103        }
 104
 105        public void ShowPendingToSend()
 106        {
 0107            model.State = SendFriendRequestHUDModel.LayoutState.Pending;
 0108            showHideAnimatorForDefaultState.Show(true);
 0109            pendingToSendContainer.SetActive(true);
 0110            showHideAnimatorForSuccessState.Hide(true);
 0111            RefreshControl();
 0112        }
 113
 114        public void ShowSendSuccess()
 115        {
 0116            model.State = SendFriendRequestHUDModel.LayoutState.Success;
 0117            showHideAnimatorForDefaultState.Hide(true);
 0118            pendingToSendContainer.SetActive(false);
 0119            showHideAnimatorForSuccessState.Show();
 0120            RefreshControl();
 0121        }
 122
 0123        public void ClearInputField() => messageBodyInput.text = "";
 124
 125        private void RefreshMessageBodyValidations(string message)
 126        {
 0127            messageBodyLengthLabel.text = $"{message.Length}/{messageBodyInput.characterLimit}";
 0128            messageBodyMaxLimitMark.gameObject.SetActive(message.Length >= messageBodyInput.characterLimit);
 0129            messageBodyMaxLimitMark.color = messageBodyMaxLimitMark.gameObject.activeSelf ? bodyMaxLimitColor : messageB
 0130            messageBodyLengthLabel.color = messageBodyMaxLimitMark.gameObject.activeSelf ? bodyMaxLimitColor : messageBo
 0131        }
 132    }
 133}