< Summary

Class:FriendsHUDComponentView
Assembly:FriendsHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/FriendsHUD/Scripts/FriendsHUDComponentView.cs
Covered lines:76
Uncovered lines:33
Coverable lines:109
Total lines:268
Line coverage:69.7% (76 of 109)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
add_OnFriendRequestApproved(...)0%110100%
remove_OnFriendRequestApproved(...)0%110100%
add_OnCancelConfirmation(...)0%110100%
remove_OnCancelConfirmation(...)0%110100%
add_OnRejectConfirmation(...)0%110100%
remove_OnRejectConfirmation(...)0%110100%
add_OnFriendRequestSent(...)0%110100%
remove_OnFriendRequestSent(...)0%110100%
add_OnWhisper(...)0%110100%
remove_OnWhisper(...)0%110100%
add_OnDeleteConfirmation(...)0%2100%
remove_OnDeleteConfirmation(...)0%110100%
add_OnRequireMoreFriends(...)0%110100%
remove_OnRequireMoreFriends(...)0%110100%
add_OnRequireMoreFriendRequests(...)0%110100%
remove_OnRequireMoreFriendRequests(...)0%110100%
add_OnSearchFriendsRequested(...)0%110100%
remove_OnSearchFriendsRequested(...)0%110100%
Create()0%110100%
Initialize(...)0%110100%
RefreshFriendsTab()0%110100%
Awake()0%110100%
HideLoadingSpinner()0%110100%
ShowLoadingSpinner()0%110100%
GetEntry(...)0%220100%
DisplayFriendUserNotFound()0%2100%
Show()0%110100%
Hide()0%110100%
Set(...)0%110100%
Remove(...)0%110100%
Set(...)0%110100%
IsActive()0%110100%
ShowRequestSendError(...)0%6200%
ShowRequestSendSuccess()0%2100%
ShowMoreFriendsToLoadHint(...)0%110100%
HideMoreFriendsToLoadHint()0%110100%
ShowMoreRequestsToLoadHint(...)0%110100%
HideMoreRequestsToLoadHint()0%110100%
ContainsFriend(...)0%110100%
ContainsFriendRequest(...)0%110100%
EnableSearchMode()0%2100%
DisableSearchMode()0%2100%
UpdateBlockStatus(...)0%2100%
ClearAll()0%110100%
RefreshControl()0%12300%
FocusTab(...)0%5.395075%
UpdateBlockStatus(...)0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/FriendsHUD/Scripts/FriendsHUDComponentView.cs

#LineLine coverage
 1using System;
 2using SocialFeaturesAnalytics;
 3using UnityEngine;
 4using UnityEngine.UI;
 5
 6public class FriendsHUDComponentView : BaseComponentView, IFriendsHUDComponentView
 7{
 8    private const int FRIENDS_LIST_TAB_INDEX = 0;
 9    private const int FRIENDS_REQUEST_TAB_INDEX = 1;
 10
 11    [SerializeField] internal GameObject loadingSpinner;
 12    [SerializeField] internal Button closeButton;
 13    [SerializeField] internal Button friendsTabFocusButton;
 14    [SerializeField] internal Button friendRequestsTabFocusButton;
 15    [SerializeField] internal FriendsTabComponentView friendsTab;
 16    [SerializeField] internal FriendRequestsTabComponentView friendRequestsTab;
 17    [SerializeField] private Model model;
 18
 19    public event Action<FriendRequestEntryModel> OnFriendRequestApproved
 20    {
 121        add => friendRequestsTab.OnFriendRequestApproved += value;
 122        remove => friendRequestsTab.OnFriendRequestApproved -= value;
 23    }
 24
 25    public event Action<FriendRequestEntryModel> OnCancelConfirmation
 26    {
 127        add => friendRequestsTab.OnCancelConfirmation += value;
 128        remove => friendRequestsTab.OnCancelConfirmation -= value;
 29    }
 30
 31    public event Action<FriendRequestEntryModel> OnRejectConfirmation
 32    {
 133        add => friendRequestsTab.OnRejectConfirmation += value;
 134        remove => friendRequestsTab.OnRejectConfirmation -= value;
 35    }
 36
 37    public event Action<string> OnFriendRequestSent
 38    {
 139        add => friendRequestsTab.OnFriendRequestSent += value;
 140        remove => friendRequestsTab.OnFriendRequestSent -= value;
 41    }
 42
 43    public event Action<FriendEntryModel> OnWhisper
 44    {
 145        add => friendsTab.OnWhisper += value;
 146        remove => friendsTab.OnWhisper -= value;
 47    }
 48
 49    public event Action<string> OnDeleteConfirmation
 50    {
 051        add => friendsTab.OnDeleteConfirmation += value;
 152        remove => friendsTab.OnDeleteConfirmation -= value;
 53    }
 54
 55    public event Action OnRequireMoreFriends
 56    {
 257        add => friendsTab.OnRequireMoreEntries += value;
 158        remove => friendsTab.OnRequireMoreEntries -= value;
 59    }
 60
 61    public event Action OnRequireMoreFriendRequests
 62    {
 263        add => friendRequestsTab.OnRequireMoreEntries += value;
 164        remove => friendRequestsTab.OnRequireMoreEntries -= value;
 65    }
 66
 67    public event Action<string> OnSearchFriendsRequested
 68    {
 169        add => friendsTab.OnSearchRequested += value;
 170        remove => friendsTab.OnSearchRequested -= value;
 71    }
 72
 73    public event Action OnFriendListDisplayed;
 74    public event Action OnRequestListDisplayed;
 75
 76    public event Action OnClose;
 77
 278    public RectTransform Transform => transform as RectTransform;
 79
 1580    public int FriendCount => friendsTab.Count;
 1481    public int FriendRequestCount => friendRequestsTab.Count;
 082    public int FriendRequestSentCount => friendRequestsTab.SentCount;
 083    public int FriendRequestReceivedCount => friendRequestsTab.ReceivedCount;
 184    public bool IsFriendListActive => friendsTab.gameObject.activeInHierarchy;
 085    public bool IsRequestListActive => friendRequestsTab.gameObject.activeInHierarchy;
 86
 87    public static FriendsHUDComponentView Create()
 88    {
 2389        var view = Instantiate(Resources.Load<GameObject>("SocialBarV1/FriendsHUD"))
 90            .GetComponent<FriendsHUDComponentView>();
 2391        return view;
 92    }
 93
 94    public void Initialize(IChatController chatController,
 95        IFriendsController friendsController,
 96        ISocialAnalytics socialAnalytics)
 97    {
 2398        friendsTab.Initialize(chatController, friendsController, socialAnalytics);
 2399    }
 100
 101    public void RefreshFriendsTab()
 102    {
 1103        friendsTab.RefreshControl();
 1104    }
 105
 106    public override void Awake()
 107    {
 23108        base.Awake();
 109
 23110        friendsTabFocusButton.onClick.AddListener(() => FocusTab(FRIENDS_LIST_TAB_INDEX));
 23111        friendRequestsTabFocusButton.onClick.AddListener(() => FocusTab(FRIENDS_REQUEST_TAB_INDEX));
 23112        closeButton.onClick.AddListener(() =>
 113        {
 0114            OnClose?.Invoke();
 0115            Hide();
 0116        });
 117
 23118        friendRequestsTab.Expand();
 23119    }
 120
 121    public void HideLoadingSpinner()
 122    {
 2123        loadingSpinner.SetActive(false);
 2124        model.isLoadingSpinnerActive = false;
 2125    }
 126
 127    public void ShowLoadingSpinner()
 128    {
 3129        loadingSpinner.SetActive(true);
 3130        model.isLoadingSpinnerActive = true;
 3131    }
 132
 133    public FriendEntryBase GetEntry(string userId)
 134    {
 14135        return (FriendEntryBase) friendsTab.Get(userId) ?? friendRequestsTab.Get(userId);
 136    }
 137
 0138    public void DisplayFriendUserNotFound() => friendRequestsTab.ShowUserNotFoundNotification();
 139
 140    public void Show()
 141    {
 2142        model.visible = true;
 2143        gameObject.SetActive(true);
 2144        AudioScriptableObjects.dialogOpen.Play(true);
 2145    }
 146
 147    public void Hide()
 148    {
 1149        model.visible = false;
 1150        gameObject.SetActive(false);
 1151        AudioScriptableObjects.dialogClose.Play(true);
 1152    }
 153
 154    public void Set(string userId, FriendEntryModel model)
 155    {
 7156        friendRequestsTab.Remove(userId);
 7157        friendsTab.Enqueue(userId, model);
 7158    }
 159
 160    public void Remove(string userId)
 161    {
 5162        friendRequestsTab.Remove(userId);
 5163        friendsTab.Remove(userId);
 5164    }
 165
 166    public void Set(string userId, FriendRequestEntryModel model)
 167    {
 6168        friendRequestsTab.Enqueue(userId, model);
 6169        friendsTab.Remove(userId);
 6170    }
 171
 3172    public bool IsActive() => gameObject.activeInHierarchy;
 173
 174    public void ShowRequestSendError(FriendRequestError error)
 175    {
 176        switch (error)
 177        {
 178            case FriendRequestError.AlreadyFriends:
 0179                friendRequestsTab.ShowAlreadyFriendsNotification();
 180                break;
 181        }
 0182    }
 183
 184    public void ShowRequestSendSuccess()
 185    {
 0186        friendRequestsTab.ShowRequestSuccessfullySentNotification();
 0187    }
 188
 2189    public void ShowMoreFriendsToLoadHint(int hiddenCount) => friendsTab.ShowMoreFriendsToLoadHint(hiddenCount);
 190
 1191    public void HideMoreFriendsToLoadHint() => friendsTab.HideMoreFriendsToLoadHint();
 192
 193    public void ShowMoreRequestsToLoadHint(int hiddenCount) =>
 2194        friendRequestsTab.ShowMoreEntriesToLoadHint(hiddenCount);
 195
 1196    public void HideMoreRequestsToLoadHint() => friendRequestsTab.HideMoreFriendsToLoadHint();
 197
 14198    public bool ContainsFriend(string userId) => friendsTab.Get(userId) != null;
 199
 14200    public bool ContainsFriendRequest(string userId) => friendRequestsTab.Get(userId) != null;
 201
 0202    public void EnableSearchMode() => friendsTab.EnableSearchMode();
 203
 0204    public void DisableSearchMode() => friendsTab.DisableSearchMode();
 205
 206    public void UpdateBlockStatus(string userId, bool blocked)
 207    {
 0208        UpdateBlockStatus(blocked, friendsTab.Get(userId));
 0209        UpdateBlockStatus(blocked, friendRequestsTab.Get(userId));
 0210    }
 211
 212    public void ClearAll()
 213    {
 1214        friendsTab.Clear();
 1215        friendRequestsTab.Clear();
 1216    }
 217
 218    public override void RefreshControl()
 219    {
 0220        if (model.isLoadingSpinnerActive)
 0221            ShowLoadingSpinner();
 222        else
 0223            HideLoadingSpinner();
 224
 0225        if (model.visible)
 0226            Show();
 227        else
 0228            Hide();
 229
 0230        FocusTab(model.focusedTabIndex);
 0231    }
 232
 233    internal void FocusTab(int index)
 234    {
 15235        model.focusedTabIndex = index;
 236
 15237        if (index == FRIENDS_LIST_TAB_INDEX)
 238        {
 8239            friendsTab.Show();
 8240            friendRequestsTab.Hide();
 8241            OnFriendListDisplayed?.Invoke();
 0242        }
 7243        else if (index == FRIENDS_REQUEST_TAB_INDEX)
 244        {
 7245            friendsTab.Hide();
 7246            friendRequestsTab.Show();
 7247            OnRequestListDisplayed?.Invoke();
 0248        }
 249        else
 0250            throw new IndexOutOfRangeException();
 251    }
 252
 253    private void UpdateBlockStatus(bool blocked, FriendEntryBase friendEntry)
 254    {
 0255        if (friendEntry == null) return;
 0256        var friendModel = friendEntry.Model;
 0257        friendModel.blocked = blocked;
 0258        friendEntry.RefreshControl();
 0259    }
 260
 261    [Serializable]
 262    private struct Model
 263    {
 264        public int focusedTabIndex;
 265        public bool isLoadingSpinnerActive;
 266        public bool visible;
 267    }
 268}

Methods/Properties

add_OnFriendRequestApproved(System.Action[FriendRequestEntryModel])
remove_OnFriendRequestApproved(System.Action[FriendRequestEntryModel])
add_OnCancelConfirmation(System.Action[FriendRequestEntryModel])
remove_OnCancelConfirmation(System.Action[FriendRequestEntryModel])
add_OnRejectConfirmation(System.Action[FriendRequestEntryModel])
remove_OnRejectConfirmation(System.Action[FriendRequestEntryModel])
add_OnFriendRequestSent(System.Action[String])
remove_OnFriendRequestSent(System.Action[String])
add_OnWhisper(System.Action[FriendEntryModel])
remove_OnWhisper(System.Action[FriendEntryModel])
add_OnDeleteConfirmation(System.Action[String])
remove_OnDeleteConfirmation(System.Action[String])
add_OnRequireMoreFriends(System.Action)
remove_OnRequireMoreFriends(System.Action)
add_OnRequireMoreFriendRequests(System.Action)
remove_OnRequireMoreFriendRequests(System.Action)
add_OnSearchFriendsRequested(System.Action[String])
remove_OnSearchFriendsRequested(System.Action[String])
Transform()
FriendCount()
FriendRequestCount()
FriendRequestSentCount()
FriendRequestReceivedCount()
IsFriendListActive()
IsRequestListActive()
Create()
Initialize(IChatController, IFriendsController, SocialFeaturesAnalytics.ISocialAnalytics)
RefreshFriendsTab()
Awake()
HideLoadingSpinner()
ShowLoadingSpinner()
GetEntry(System.String)
DisplayFriendUserNotFound()
Show()
Hide()
Set(System.String, FriendEntryModel)
Remove(System.String)
Set(System.String, FriendRequestEntryModel)
IsActive()
ShowRequestSendError(FriendRequestError)
ShowRequestSendSuccess()
ShowMoreFriendsToLoadHint(System.Int32)
HideMoreFriendsToLoadHint()
ShowMoreRequestsToLoadHint(System.Int32)
HideMoreRequestsToLoadHint()
ContainsFriend(System.String)
ContainsFriendRequest(System.String)
EnableSearchMode()
DisableSearchMode()
UpdateBlockStatus(System.String, System.Boolean)
ClearAll()
RefreshControl()
FocusTab(System.Int32)
UpdateBlockStatus(System.Boolean, FriendEntryBase)