< Summary

Class:UsersAroundListHUDListElementView
Assembly:UsersAroundListHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/UsersAroundListHUD/UsersAroundListHUDListElementView.cs
Covered lines:37
Uncovered lines:40
Coverable lines:77
Total lines:182
Line coverage:48% (37 of 77)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
UsersAroundListHUDListElementView()0%110100%
Start()0%2100%
OnEnable()0%12300%
OnDisable()0%6200%
OnDestroy()0%6200%
SetUserProfile(...)0%3.213071.43%
SetMuted(...)0%110100%
SetRecording(...)0%6200%
SetBlocked(...)0%110100%
OnPoolRelease()0%440100%
OnPoolGet()0%22090%
SetupFriends(...)0%4.054085.71%
SetAvatarSnapshotImage(...)0%2100%
OnSoundButtonPressed()0%12300%
OnPointerEnter(...)0%2100%
OnPointerExit(...)0%2100%
OnFriendActionUpdate(...)0%6200%
SetupFriendship(...)0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/UsersAroundListHUD/UsersAroundListHUDListElementView.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using DCL;
 4using DCL.Components;
 5using DCL.Social.Friends;
 6using TMPro;
 7using UnityEngine;
 8using UnityEngine.UI;
 9using UnityEngine.EventSystems;
 10
 11internal class UsersAroundListHUDListElementView : MonoBehaviour, IPoolLifecycleHandler, IPointerEnterHandler, IPointerE
 12{
 113    private static readonly int talkingAnimation = Animator.StringToHash("Talking");
 14
 15    public event Action<string, bool> OnMuteUser;
 16    public event Action<Vector3, string> OnShowUserContexMenu;
 17
 18    [SerializeField] internal TextMeshProUGUI userName;
 19    [SerializeField] internal GameObject friendLabel;
 20    [SerializeField] internal RawImage avatarPreview;
 21    [SerializeField] internal GameObject blockedGO;
 22    [SerializeField] internal Button soundButton;
 23    [SerializeField] internal GameObject muteGO;
 24    [SerializeField] internal GameObject backgroundHover;
 25    [SerializeField] internal Button menuButton;
 26    [SerializeField] internal Transform contexMenuRefPosition;
 27    [SerializeField] internal Animator talkingAnimator;
 28
 29    private UserProfile profile;
 30    private bool isMuted = false;
 31    private bool isRecording = false;
 32
 33    private void Start()
 34    {
 035        soundButton.onClick.AddListener(OnSoundButtonPressed);
 036        menuButton.onClick.AddListener(() =>
 37        {
 038            if (profile)
 39            {
 040                OnShowUserContexMenu?.Invoke(contexMenuRefPosition.position, profile.userId);
 41            }
 042        });
 043    }
 44
 45    private void OnEnable()
 46    {
 047        if ( profile != null )
 048            profile.snapshotObserver.AddListener(SetAvatarSnapshotImage);
 49
 050        if ( talkingAnimator.isActiveAndEnabled )
 051            talkingAnimator.SetBool(talkingAnimation, isRecording);
 052    }
 53
 54    private void OnDisable()
 55    {
 056        if ( profile != null )
 057            profile.snapshotObserver.RemoveListener(SetAvatarSnapshotImage);
 058    }
 59
 60    private void OnDestroy()
 61    {
 062        if ( profile != null )
 063            profile.snapshotObserver.RemoveListener(SetAvatarSnapshotImage);
 064    }
 65
 66    public void SetUserProfile(UserProfile profile)
 67    {
 368        userName.text = profile.userName;
 69
 370        SetupFriends(profile.userId);
 71
 372        if (this.profile != null && isActiveAndEnabled)
 73        {
 074            this.profile.snapshotObserver.RemoveListener(SetAvatarSnapshotImage);
 075            profile.snapshotObserver.AddListener(SetAvatarSnapshotImage);
 76        }
 77
 378        this.profile = profile;
 379    }
 80
 81    public void SetMuted(bool isMuted)
 82    {
 383        this.isMuted = isMuted;
 384        muteGO.SetActive(isMuted);
 385    }
 86
 87    public void SetRecording(bool isRecording)
 88    {
 089        this.isRecording = isRecording;
 90
 091        if ( talkingAnimator.isActiveAndEnabled )
 092            talkingAnimator.SetBool(talkingAnimation, isRecording);
 093    }
 94
 695    public void SetBlocked(bool blocked) { blockedGO.SetActive(blocked); }
 96
 97    public void OnPoolRelease()
 98    {
 599        avatarPreview.texture = null;
 5100        userName.text = string.Empty;
 5101        isMuted = false;
 5102        isRecording = false;
 103
 5104        if (profile != null)
 105        {
 2106            profile.snapshotObserver?.RemoveListener(SetAvatarSnapshotImage);
 2107            profile = null;
 108        }
 109
 5110        if (FriendsController.i != null)
 111        {
 5112            FriendsController.i.OnUpdateFriendship -= OnFriendActionUpdate;
 113        }
 114
 5115        gameObject.SetActive(false);
 5116    }
 117
 118    public void OnPoolGet()
 119    {
 3120        muteGO.SetActive(false);
 121
 3122        if (talkingAnimator.isActiveAndEnabled)
 0123            talkingAnimator.SetBool(talkingAnimation, false);
 124
 3125        avatarPreview.texture = null;
 3126        userName.text = string.Empty;
 3127        backgroundHover.SetActive(false);
 3128        menuButton.gameObject.SetActive(false);
 3129        blockedGO.SetActive(false);
 3130        gameObject.SetActive(true);
 3131    }
 132
 133    void SetupFriends(string userId)
 134    {
 3135        if (FriendsController.i == null)
 136        {
 0137            return;
 138        }
 139
 3140        UserStatus status = FriendsController.i.GetUserStatus(userId);
 3141        SetupFriendship(status?.friendshipStatus ?? FriendshipStatus.NOT_FRIEND);
 142
 3143        FriendsController.i.OnUpdateFriendship -= OnFriendActionUpdate;
 3144        FriendsController.i.OnUpdateFriendship += OnFriendActionUpdate;
 3145    }
 146
 0147    void SetAvatarSnapshotImage(Texture2D texture) { avatarPreview.texture = texture; }
 148
 149    void OnSoundButtonPressed()
 150    {
 0151        if (profile == null)
 152        {
 0153            return;
 154        }
 155
 0156        OnMuteUser?.Invoke(profile.userId, !isMuted);
 0157    }
 158
 159    void IPointerEnterHandler.OnPointerEnter(PointerEventData eventData)
 160    {
 0161        backgroundHover.SetActive(true);
 0162        menuButton.gameObject.SetActive(true);
 0163    }
 164
 165    void IPointerExitHandler.OnPointerExit(PointerEventData eventData)
 166    {
 0167        backgroundHover.SetActive(false);
 0168        menuButton.gameObject.SetActive(false);
 0169    }
 170
 171    void OnFriendActionUpdate(string userId, FriendshipAction action)
 172    {
 0173        if (profile.userId != userId)
 174        {
 0175            return;
 176        }
 177
 0178        friendLabel.SetActive(action == FriendshipAction.APPROVED);
 0179    }
 180
 6181    void SetupFriendship(FriendshipStatus friendshipStatus) { friendLabel.SetActive(friendshipStatus == FriendshipStatus
 182}