< 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:56
Uncovered lines:3
Coverable lines:59
Total lines:133
Line coverage:94.9% (56 of 59)
Covered branches:0
Total branches:0

Metrics

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

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() =>
 1033            Instantiate(
 34                Resources.Load<SendFriendRequestHUDComponentView>("FriendRequests/SendFriendRequestHUD"));
 35
 36        public override void Awake()
 37        {
 1038            base.Awake();
 39
 6040            foreach (var button in cancelButtons)
 2041                button.onClick.AddListener(() => OnCancel?.Invoke());
 42
 1043            messageBodyInput.onValueChanged.AddListener(s =>
 44            {
 245                RefreshMessageBodyValidations(s);
 246                OnMessageBodyChanged?.Invoke(s);
 047            });
 1048            sendButton.onClick.AddListener(() => OnSend?.Invoke());
 49
 1050            messageBodyLengthOriginalColor = messageBodyLengthLabel.color;
 1051        }
 52
 53        public override void Dispose()
 54        {
 2055            base.Dispose();
 2056            model.ProfilePictureObserver?.RemoveListener(profileImage.SetImage);
 657        }
 58
 59        public override void RefreshControl()
 60        {
 1261            sendButton.gameObject.SetActive(model.State != SendFriendRequestHUDModel.LayoutState.Pending);
 1262            sendButton.interactable = model.State != SendFriendRequestHUDModel.LayoutState.Pending;
 63
 7264            foreach (Button cancelButton in cancelButtons)
 2465                cancelButton.interactable = model.State != SendFriendRequestHUDModel.LayoutState.Pending;
 66
 1267            nameLabel.text = model.Name;
 1268            successStateLabel.text = $"Friend request sent to {model.Name}";
 1269            messageBodyLengthLabel.text = $"{messageBodyInput.text.Length}/{messageBodyInput.characterLimit}";
 1270            RefreshMessageBodyValidations(messageBodyInput.text);
 71
 72            // the load of the profile picture gets stuck if the same listener is registered many times
 1273            if (lastProfilePictureObserver != model.ProfilePictureObserver)
 74            {
 575                lastProfilePictureObserver?.RemoveListener(profileImage.SetImage);
 576                model.ProfilePictureObserver?.AddListener(profileImage.SetImage);
 577                lastProfilePictureObserver = model.ProfilePictureObserver;
 78            }
 1279        }
 80
 081        public void Close() => base.Hide();
 82
 83        public override void Show(bool instant = false)
 84        {
 185            base.Show(instant);
 186            model.State = SendFriendRequestHUDModel.LayoutState.Default;
 187            showHideAnimatorForDefaultState.Show(true);
 188            pendingToSendContainer.SetActive(false);
 189            showHideAnimatorForSuccessState.Hide(true);
 190            RefreshControl();
 191        }
 92
 93        public void SetName(string name)
 94        {
 295            model.Name = name;
 296            RefreshControl();
 297        }
 98
 99        public void SetProfilePicture(ILazyTextureObserver textureObserver)
 100        {
 7101            model.ProfilePictureObserver = textureObserver;
 7102            RefreshControl();
 7103        }
 104
 105        public void ShowPendingToSend()
 106        {
 1107            model.State = SendFriendRequestHUDModel.LayoutState.Pending;
 1108            showHideAnimatorForDefaultState.Show(true);
 1109            pendingToSendContainer.SetActive(true);
 1110            showHideAnimatorForSuccessState.Hide(true);
 1111            RefreshControl();
 1112        }
 113
 114        public void ShowSendSuccess()
 115        {
 1116            model.State = SendFriendRequestHUDModel.LayoutState.Success;
 1117            showHideAnimatorForDefaultState.Hide(true);
 1118            pendingToSendContainer.SetActive(false);
 1119            showHideAnimatorForSuccessState.Show();
 1120            RefreshControl();
 1121        }
 122
 0123        public void ClearInputField() => messageBodyInput.text = "";
 124
 125        private void RefreshMessageBodyValidations(string message)
 126        {
 14127            messageBodyLengthLabel.text = $"{message.Length}/{messageBodyInput.characterLimit}";
 14128            messageBodyMaxLimitMark.gameObject.SetActive(message.Length >= messageBodyInput.characterLimit);
 14129            messageBodyMaxLimitMark.color = messageBodyMaxLimitMark.gameObject.activeSelf ? bodyMaxLimitColor : messageB
 14130            messageBodyLengthLabel.color = messageBodyMaxLimitMark.gameObject.activeSelf ? bodyMaxLimitColor : messageBo
 14131        }
 132    }
 133}