< Summary

Class:PrivateChatWindowComponentView
Assembly:PrivateChatWindowHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/PrivateChatWindow/PrivateChatWindowComponentView.cs
Covered lines:55
Uncovered lines:19
Coverable lines:74
Total lines:201
Line coverage:74.3% (55 of 74)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
add_OnUnfriend(...)0%110100%
remove_OnUnfriend(...)0%110100%
add_OnFocused(...)0%110100%
remove_OnFocused(...)0%110100%
Create()0%110100%
Awake()0%110100%
Initialize(...)0%110100%
Dispose()0%4.254075%
ActivatePreview()0%9.666053.33%
DeactivatePreview()0%6.64045.45%
RefreshControl()0%110100%
Setup(...)0%110100%
Show()0%110100%
Hide()0%110100%
OnPointerDown(...)0%220100%
ShowOptions()0%2100%
HandleBlockFromContextMenu(...)0%6200%
SetAlpha()0%660100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/PrivateChatWindow/PrivateChatWindowComponentView.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using SocialBar.UserThumbnail;
 4using SocialFeaturesAnalytics;
 5using TMPro;
 6using UnityEngine;
 7using UnityEngine.EventSystems;
 8using UnityEngine.UI;
 9
 10public class PrivateChatWindowComponentView : BaseComponentView, IPrivateChatComponentView, IPointerDownHandler
 11{
 12    [SerializeField] internal Button backButton;
 13    [SerializeField] internal Button closeButton;
 14    [SerializeField] internal UserThumbnailComponentView userThumbnail;
 15    [SerializeField] internal TMP_Text userNameLabel;
 16    [SerializeField] internal PrivateChatHUDView chatView;
 17    [SerializeField] internal GameObject jumpInButtonContainer;
 18    [SerializeField] internal JumpInButton jumpInButton;
 19    [SerializeField] internal UserContextMenu userContextMenu;
 20    [SerializeField] internal RectTransform userContextMenuReferencePoint;
 21    [SerializeField] internal Button optionsButton;
 22    [SerializeField] private Model model;
 23    [SerializeField] internal CanvasGroup[] previewCanvasGroup;
 24    [SerializeField] private Vector2 previewModeSize;
 25
 26    private IFriendsController friendsController;
 27    private ISocialAnalytics socialAnalytics;
 28    private Coroutine alphaRoutine;
 29    private Vector2 originalSize;
 30
 31    public event Action OnPressBack;
 32    public event Action OnMinimize;
 33    public event Action OnClose;
 34    public event Action<string> OnUnfriend
 35    {
 136        add => userContextMenu.OnUnfriend += value;
 137        remove => userContextMenu.OnUnfriend -= value;
 38    }
 39    public event Action<bool> OnFocused
 40    {
 341        add => onFocused += value;
 142        remove => onFocused -= value;
 43    }
 44    public event Action OnClickOverWindow;
 45
 146    public IChatHUDComponentView ChatHUD => chatView;
 247    public bool IsActive => gameObject.activeInHierarchy;
 048    public RectTransform Transform => (RectTransform) transform;
 049    public bool IsFocused => isFocused;
 50
 51    public static PrivateChatWindowComponentView Create()
 52    {
 1253        return Instantiate(Resources.Load<PrivateChatWindowComponentView>("SocialBarV1/PrivateChatHUD"));
 54    }
 55
 56    public override void Awake()
 57    {
 1258        base.Awake();
 1259        originalSize = ((RectTransform) transform).sizeDelta;
 1360        backButton.onClick.AddListener(() => OnPressBack?.Invoke());
 1361        closeButton.onClick.AddListener(() => OnClose?.Invoke());
 1262        optionsButton.onClick.AddListener(ShowOptions);
 1263        userContextMenu.OnBlock += HandleBlockFromContextMenu;
 1264    }
 65
 66    public void Initialize(IFriendsController friendsController, ISocialAnalytics socialAnalytics)
 67    {
 168        this.friendsController = friendsController;
 169        this.socialAnalytics = socialAnalytics;
 170    }
 71
 72    public override void Dispose()
 73    {
 2474        if (!this) return;
 2475        if (!gameObject) return;
 76
 2477        if (userContextMenu != null)
 78        {
 2479            userContextMenu.OnBlock -= HandleBlockFromContextMenu;
 80        }
 81
 2482        base.Dispose();
 2483    }
 84
 85    public void ActivatePreview()
 86    {
 387        if (!this) return;
 188        if (!gameObject) return;
 89
 90        const float alphaTarget = 0f;
 91
 192        if (!gameObject.activeInHierarchy)
 93        {
 094            foreach (var group in previewCanvasGroup)
 095                group.alpha = alphaTarget;
 96
 097            return;
 98        }
 99
 1100        if (alphaRoutine != null)
 0101            StopCoroutine(alphaRoutine);
 102
 1103        alphaRoutine = StartCoroutine(SetAlpha(alphaTarget, 0.5f));
 1104        ((RectTransform) transform).sizeDelta = previewModeSize;
 1105    }
 106
 107    public void DeactivatePreview()
 108    {
 109        const float alphaTarget = 1f;
 110
 1111        if (!gameObject.activeInHierarchy)
 112        {
 0113            foreach (var group in previewCanvasGroup)
 0114                group.alpha = alphaTarget;
 115
 0116            return;
 117        }
 118
 1119        if (alphaRoutine != null)
 0120            StopCoroutine(alphaRoutine);
 121
 1122        alphaRoutine = StartCoroutine(SetAlpha(alphaTarget, 0.5f));
 1123        ((RectTransform) transform).sizeDelta = originalSize;
 1124    }
 125
 126    public override void RefreshControl()
 127    {
 2128        userThumbnail.Configure(new UserThumbnailComponentModel
 129        {
 130            faceUrl = model.faceSnapshotUrl,
 131            isBlocked = model.isUserBlocked,
 132            isOnline = model.isUserOnline
 133        });
 2134        userNameLabel.SetText(model.userName);
 2135        jumpInButtonContainer.SetActive(model.isUserOnline);
 2136    }
 137
 138    public void Setup(UserProfile profile, bool isOnline, bool isBlocked)
 139    {
 2140        model = new Model
 141        {
 142            userId = profile.userId,
 143            faceSnapshotUrl = profile.face256SnapshotURL,
 144            userName = profile.userName,
 145            isUserOnline = isOnline,
 146            isUserBlocked = isBlocked
 147        };
 2148        RefreshControl();
 149
 2150        jumpInButton.Initialize(friendsController, profile.userId, socialAnalytics);
 2151    }
 152
 2153    public void Show() => gameObject.SetActive(true);
 154
 2155    public void Hide() => gameObject.SetActive(false);
 156
 1157    public void OnPointerDown(PointerEventData eventData) => OnClickOverWindow?.Invoke();
 158
 159    private void ShowOptions()
 160    {
 0161        var contextMenuTransform = (RectTransform) userContextMenu.transform;
 0162        contextMenuTransform.pivot = userContextMenuReferencePoint.pivot;
 0163        contextMenuTransform.position = userContextMenuReferencePoint.position;
 0164        userContextMenu.Show(model.userId);
 0165    }
 166
 167    private void HandleBlockFromContextMenu(string userId, bool isBlocked)
 168    {
 0169        if (userId != model.userId) return;
 0170        model.isUserBlocked = isBlocked;
 0171        RefreshControl();
 0172    }
 173
 174    private IEnumerator SetAlpha(float target, float duration)
 175    {
 2176        var t = 0f;
 177
 219178        while (t < duration)
 179        {
 217180            t += Time.deltaTime;
 181
 3472182            foreach (var group in previewCanvasGroup)
 1519183                group.alpha = Mathf.Lerp(group.alpha, target, t / duration);
 184
 217185            yield return null;
 186        }
 187
 32188        foreach (var group in previewCanvasGroup)
 14189            group.alpha = target;
 2190    }
 191
 192    [Serializable]
 193    private struct Model
 194    {
 195        public string userId;
 196        public string userName;
 197        public string faceSnapshotUrl;
 198        public bool isUserBlocked;
 199        public bool isUserOnline;
 200    }
 201}