< 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:31
Coverable lines:107
Total lines:269
Line coverage:71% (76 of 107)
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.025090%
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 DCl.Social.Friends;
 3using SocialFeaturesAnalytics;
 4using UnityEngine;
 5using UnityEngine.UI;
 6
 7public class FriendsHUDComponentView : BaseComponentView, IFriendsHUDComponentView
 8{
 9    private const int FRIENDS_LIST_TAB_INDEX = 0;
 10    private const int FRIENDS_REQUEST_TAB_INDEX = 1;
 11
 12    [SerializeField] internal GameObject loadingSpinner;
 13    [SerializeField] internal Button closeButton;
 14    [SerializeField] internal Button friendsTabFocusButton;
 15    [SerializeField] internal Button friendRequestsTabFocusButton;
 16    [SerializeField] internal FriendsTabComponentView friendsTab;
 17    [SerializeField] internal FriendRequestsTabComponentView friendRequestsTab;
 18    [SerializeField] private Model model;
 19
 20    public event Action<FriendRequestEntryModel> OnFriendRequestApproved
 21    {
 122        add => friendRequestsTab.OnFriendRequestApproved += value;
 123        remove => friendRequestsTab.OnFriendRequestApproved -= value;
 24    }
 25
 26    public event Action<FriendRequestEntryModel> OnCancelConfirmation
 27    {
 128        add => friendRequestsTab.OnCancelConfirmation += value;
 129        remove => friendRequestsTab.OnCancelConfirmation -= value;
 30    }
 31
 32    public event Action<FriendRequestEntryModel> OnRejectConfirmation
 33    {
 134        add => friendRequestsTab.OnRejectConfirmation += value;
 135        remove => friendRequestsTab.OnRejectConfirmation -= value;
 36    }
 37
 38    public event Action<string> OnFriendRequestSent
 39    {
 140        add => friendRequestsTab.OnFriendRequestSent += value;
 141        remove => friendRequestsTab.OnFriendRequestSent -= value;
 42    }
 43
 44    public event Action<FriendEntryModel> OnWhisper
 45    {
 146        add => friendsTab.OnWhisper += value;
 147        remove => friendsTab.OnWhisper -= value;
 48    }
 49
 50    public event Action<string> OnDeleteConfirmation
 51    {
 052        add => friendsTab.OnDeleteConfirmation += value;
 153        remove => friendsTab.OnDeleteConfirmation -= value;
 54    }
 55
 56    public event Action OnRequireMoreFriends
 57    {
 258        add => friendsTab.OnRequireMoreEntries += value;
 159        remove => friendsTab.OnRequireMoreEntries -= value;
 60    }
 61
 62    public event Action OnRequireMoreFriendRequests
 63    {
 264        add => friendRequestsTab.OnRequireMoreEntries += value;
 165        remove => friendRequestsTab.OnRequireMoreEntries -= value;
 66    }
 67
 68    public event Action<string> OnSearchFriendsRequested
 69    {
 170        add => friendsTab.OnSearchRequested += value;
 171        remove => friendsTab.OnSearchRequested -= value;
 72    }
 73
 74    public event Action OnFriendListDisplayed;
 75    public event Action OnRequestListDisplayed;
 76
 77    public event Action OnClose;
 78
 279    public RectTransform Transform => transform as RectTransform;
 80
 1581    public int FriendCount => friendsTab.Count;
 1482    public int FriendRequestCount => friendRequestsTab.Count;
 083    public int FriendRequestSentCount => friendRequestsTab.SentCount;
 084    public int FriendRequestReceivedCount => friendRequestsTab.ReceivedCount;
 185    public bool IsFriendListActive => friendsTab.gameObject.activeInHierarchy;
 086    public bool IsRequestListActive => friendRequestsTab.gameObject.activeInHierarchy;
 87
 88    public static FriendsHUDComponentView Create()
 89    {
 2390        var view = Instantiate(Resources.Load<GameObject>("SocialBarV1/FriendsHUD"))
 91            .GetComponent<FriendsHUDComponentView>();
 2392        return view;
 93    }
 94
 95    public void Initialize(IChatController chatController,
 96        IFriendsController friendsController,
 97        ISocialAnalytics socialAnalytics)
 98    {
 2399        friendsTab.Initialize(chatController, friendsController, socialAnalytics);
 23100    }
 101
 102    public void RefreshFriendsTab()
 103    {
 1104        friendsTab.RefreshControl();
 1105    }
 106
 107    public override void Awake()
 108    {
 23109        base.Awake();
 110
 23111        friendsTabFocusButton.onClick.AddListener(() => FocusTab(FRIENDS_LIST_TAB_INDEX));
 23112        friendRequestsTabFocusButton.onClick.AddListener(() => FocusTab(FRIENDS_REQUEST_TAB_INDEX));
 23113        closeButton.onClick.AddListener(() =>
 114        {
 0115            OnClose?.Invoke();
 0116            Hide();
 0117        });
 118
 23119        friendRequestsTab.Expand();
 23120    }
 121
 122    public void HideLoadingSpinner()
 123    {
 2124        loadingSpinner.SetActive(false);
 2125        model.isLoadingSpinnerActive = false;
 2126    }
 127
 128    public void ShowLoadingSpinner()
 129    {
 3130        loadingSpinner.SetActive(true);
 3131        model.isLoadingSpinnerActive = true;
 3132    }
 133
 134    public FriendEntryBase GetEntry(string userId)
 135    {
 14136        return (FriendEntryBase) friendsTab.Get(userId) ?? friendRequestsTab.Get(userId);
 137    }
 138
 0139    public void DisplayFriendUserNotFound() => friendRequestsTab.ShowUserNotFoundNotification();
 140
 141    public void Show()
 142    {
 2143        model.visible = true;
 2144        gameObject.SetActive(true);
 2145        AudioScriptableObjects.dialogOpen.Play(true);
 2146    }
 147
 148    public void Hide()
 149    {
 1150        model.visible = false;
 1151        gameObject.SetActive(false);
 1152        AudioScriptableObjects.dialogClose.Play(true);
 1153    }
 154
 155    public void Set(string userId, FriendEntryModel model)
 156    {
 7157        friendRequestsTab.Remove(userId);
 7158        friendsTab.Enqueue(userId, model);
 7159    }
 160
 161    public void Remove(string userId)
 162    {
 5163        friendRequestsTab.Remove(userId);
 5164        friendsTab.Remove(userId);
 5165    }
 166
 167    public void Set(string userId, FriendRequestEntryModel model)
 168    {
 6169        friendRequestsTab.Enqueue(userId, model);
 6170        friendsTab.Remove(userId);
 6171    }
 172
 3173    public bool IsActive() => gameObject.activeInHierarchy;
 174
 175    public void ShowRequestSendError(FriendRequestError error)
 176    {
 177        switch (error)
 178        {
 179            case FriendRequestError.AlreadyFriends:
 0180                friendRequestsTab.ShowAlreadyFriendsNotification();
 181                break;
 182        }
 0183    }
 184
 185    public void ShowRequestSendSuccess()
 186    {
 0187        friendRequestsTab.ShowRequestSuccessfullySentNotification();
 0188    }
 189
 2190    public void ShowMoreFriendsToLoadHint(int hiddenCount) => friendsTab.ShowMoreFriendsToLoadHint(hiddenCount);
 191
 1192    public void HideMoreFriendsToLoadHint() => friendsTab.HideMoreFriendsToLoadHint();
 193
 194    public void ShowMoreRequestsToLoadHint(int hiddenCount) =>
 2195        friendRequestsTab.ShowMoreEntriesToLoadHint(hiddenCount);
 196
 1197    public void HideMoreRequestsToLoadHint() => friendRequestsTab.HideMoreFriendsToLoadHint();
 198
 14199    public bool ContainsFriend(string userId) => friendsTab.Get(userId) != null;
 200
 14201    public bool ContainsFriendRequest(string userId) => friendRequestsTab.Get(userId) != null;
 202
 0203    public void EnableSearchMode() => friendsTab.EnableSearchMode();
 204
 0205    public void DisableSearchMode() => friendsTab.DisableSearchMode();
 206
 207    public void UpdateBlockStatus(string userId, bool blocked)
 208    {
 0209        UpdateBlockStatus(blocked, friendsTab.Get(userId));
 0210        UpdateBlockStatus(blocked, friendRequestsTab.Get(userId));
 0211    }
 212
 213    public void ClearAll()
 214    {
 1215        friendsTab.Clear();
 1216        friendRequestsTab.Clear();
 1217    }
 218
 219    public override void RefreshControl()
 220    {
 0221        if (model.isLoadingSpinnerActive)
 0222            ShowLoadingSpinner();
 223        else
 0224            HideLoadingSpinner();
 225
 0226        if (model.visible)
 0227            Show();
 228        else
 0229            Hide();
 230
 0231        FocusTab(model.focusedTabIndex);
 0232    }
 233
 234    internal void FocusTab(int index)
 235    {
 15236        model.focusedTabIndex = index;
 237
 15238        if (index == FRIENDS_LIST_TAB_INDEX)
 239        {
 8240            friendsTab.Show();
 8241            friendRequestsTab.Hide();
 8242            OnFriendListDisplayed?.Invoke();
 243        }
 7244        else if (index == FRIENDS_REQUEST_TAB_INDEX)
 245        {
 7246            friendsTab.Hide();
 7247            friendRequestsTab.Show();
 7248            OnRequestListDisplayed?.Invoke();
 249        }
 250        else
 0251            throw new IndexOutOfRangeException();
 252    }
 253
 254    private void UpdateBlockStatus(bool blocked, FriendEntryBase friendEntry)
 255    {
 0256        if (friendEntry == null) return;
 0257        var friendModel = friendEntry.Model;
 0258        friendModel.blocked = blocked;
 0259        friendEntry.RefreshControl();
 0260    }
 261
 262    [Serializable]
 263    private struct Model
 264    {
 265        public int focusedTabIndex;
 266        public bool isLoadingSpinnerActive;
 267        public bool visible;
 268    }
 269}

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, DCl.Social.Friends.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)