< 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:47
Uncovered lines:1
Coverable lines:48
Total lines:133
Line coverage:97.9% (47 of 48)
Covered branches:0
Total branches:0

Metrics

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

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 UnityEngine;
 5using UnityEngine.UI;
 6
 7namespace DCL.Social.Friends
 8{
 9    public class SendFriendRequestHUDComponentView : BaseComponentView, ISendFriendRequestHUDView
 10    {
 11        [SerializeField] internal GameObject defaultContainer;
 12        [SerializeField] internal GameObject pendingToSendContainer;
 13        [SerializeField] internal GameObject failedContainer;
 14        [SerializeField] internal GameObject successContainer;
 15        [SerializeField] internal TMP_Text nameLabel;
 16        [SerializeField] internal TMP_Text pendingStateLabel;
 17        [SerializeField] internal TMP_Text successStateLabel;
 18        [SerializeField] internal Button[] cancelButtons;
 19        [SerializeField] internal Button sendButton;
 20        [SerializeField] internal Button retryButton;
 21        [SerializeField] internal TMP_InputField messageBodyInput;
 22        [SerializeField] internal ImageComponentView profileImage;
 23
 1124        private readonly Model model = new Model();
 25        private ILazyTextureObserver lastProfilePictureObserver;
 26
 27        public event Action<string> OnMessageBodyChanged;
 28        public event Action OnSend;
 29        public event Action OnCancel;
 30
 31        public static SendFriendRequestHUDComponentView Create() =>
 1032            Instantiate(
 33                Resources.Load<SendFriendRequestHUDComponentView>("FriendRequests/SendFriendRequestHUD"));
 34
 35        public override void Awake()
 36        {
 1037            base.Awake();
 38
 8039            foreach (var button in cancelButtons)
 3040                button.onClick.AddListener(() => OnCancel?.Invoke());
 41
 1042            messageBodyInput.onValueChanged.AddListener(s => OnMessageBodyChanged?.Invoke(s));
 1043            sendButton.onClick.AddListener(() => OnSend?.Invoke());
 1044            retryButton.onClick.AddListener(() => OnSend?.Invoke());
 1045        }
 46
 47        public override void Dispose()
 48        {
 2049            base.Dispose();
 2050            model.ProfilePictureObserver?.RemoveListener(profileImage.SetImage);
 651        }
 52
 53        public override void RefreshControl()
 54        {
 1355            defaultContainer.SetActive(model.State == Model.LayoutState.Default);
 1356            pendingToSendContainer.SetActive(model.State == Model.LayoutState.Pending);
 1357            failedContainer.SetActive(model.State == Model.LayoutState.Failed);
 1358            successContainer.SetActive(model.State == Model.LayoutState.Success);
 1359            nameLabel.text = model.Name;
 1360            pendingStateLabel.text = $"Sending friend request to {model.Name}";
 1361            successStateLabel.text = $"Friend request sent to {model.Name}";
 62
 63            // the load of the profile picture gets stuck if the same listener is registered many times
 1364            if (lastProfilePictureObserver != model.ProfilePictureObserver)
 65            {
 566                lastProfilePictureObserver?.RemoveListener(profileImage.SetImage);
 567                model.ProfilePictureObserver?.AddListener(profileImage.SetImage);
 568                lastProfilePictureObserver = model.ProfilePictureObserver;
 69            }
 1370        }
 71
 72        public void Close()
 73        {
 174            base.Hide(instant: true);
 175            gameObject.SetActive(false);
 176        }
 77
 78        public void Show()
 79        {
 180            gameObject.SetActive(true);
 181            base.Show(instant: true);
 182            model.State = Model.LayoutState.Default;
 183            RefreshControl();
 184        }
 85
 86        public void SetName(string name)
 87        {
 288            model.Name = name;
 289            RefreshControl();
 290        }
 91
 92        public void SetProfilePicture(ILazyTextureObserver textureObserver)
 93        {
 794            model.ProfilePictureObserver = textureObserver;
 795            RefreshControl();
 796        }
 97
 98        public void ShowPendingToSend()
 99        {
 1100            model.State = Model.LayoutState.Pending;
 1101            RefreshControl();
 1102        }
 103
 104        public void ShowSendSuccess()
 105        {
 1106            model.State = Model.LayoutState.Success;
 1107            RefreshControl();
 1108        }
 109
 110        public void ShowSendFailed()
 111        {
 1112            model.State = Model.LayoutState.Failed;
 1113            RefreshControl();
 1114        }
 115
 0116        public void ClearInputField() => messageBodyInput.text = "";
 117
 118        private class Model
 119        {
 120            public string Name;
 121            public LayoutState State;
 122            public ILazyTextureObserver ProfilePictureObserver;
 123
 124            public enum LayoutState
 125            {
 126                Default,
 127                Pending,
 128                Failed,
 129                Success
 130            }
 131        }
 132    }
 133}