< 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:72
Uncovered lines:33
Coverable lines:105
Total lines:266
Line coverage:68.5% (72 of 105)
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%
Awake()0%110100%
HideLoadingSpinner()0%110100%
ShowLoadingSpinner()0%110100%
GetAllEntries()0%2100%
GetEntry(...)0%220100%
DisplayFriendUserNotFound()0%2100%
IsFriendListCreationReady()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%
FilterFriends(...)0%2100%
ClearFriendFilter()0%2100%
UpdateBlockStatus(...)0%2100%
RefreshControl()0%12300%
FocusTab(...)0%3.013090%
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 System.Collections.Generic;
 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.OnRequireMoreFriends += value;
 159        remove => friendsTab.OnRequireMoreFriends -= 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 OnClose;
 75
 276    public RectTransform Transform => transform as RectTransform;
 77
 78    public bool ListByOnlineStatus
 79    {
 180        set => friendsTab.ListByOnlineStatus = value;
 81    }
 82
 1483    public int FriendCount => friendsTab.Count;
 1484    public int FriendRequestCount => friendRequestsTab.Count;
 85
 86    public static FriendsHUDComponentView Create()
 87    {
 2388        var view = Instantiate(Resources.Load<GameObject>("SocialBarV1/FriendsHUD"))
 89            .GetComponent<FriendsHUDComponentView>();
 2390        return view;
 91    }
 92
 93    public void Initialize(IChatController chatController,
 94        ILastReadMessagesService lastReadMessagesService,
 95        IFriendsController friendsController,
 96        ISocialAnalytics socialAnalytics)
 97    {
 2398        friendsTab.Initialize(chatController, lastReadMessagesService, friendsController, socialAnalytics);
 2399    }
 100
 101    public override void Awake()
 102    {
 23103        base.Awake();
 104
 23105        friendsTabFocusButton.onClick.AddListener(() => FocusTab(FRIENDS_LIST_TAB_INDEX));
 23106        friendRequestsTabFocusButton.onClick.AddListener(() => FocusTab(FRIENDS_REQUEST_TAB_INDEX));
 23107        closeButton.onClick.AddListener(() =>
 108        {
 0109            OnClose?.Invoke();
 0110            Hide();
 0111        });
 112
 23113        friendsTab.Expand();
 23114        friendRequestsTab.Expand();
 23115    }
 116
 117    public void HideLoadingSpinner()
 118    {
 2119        loadingSpinner.SetActive(false);
 2120        model.isLoadingSpinnerActive = false;
 2121    }
 122
 123    public void ShowLoadingSpinner()
 124    {
 3125        loadingSpinner.SetActive(true);
 3126        model.isLoadingSpinnerActive = true;
 3127    }
 128
 129    public List<FriendEntryBase> GetAllEntries()
 130    {
 0131        var result = new List<FriendEntryBase>();
 0132        result.AddRange(friendsTab.Entries.Values);
 0133        result.AddRange(friendRequestsTab.Entries.Values);
 0134        return result;
 135    }
 136
 137    public FriendEntryBase GetEntry(string userId)
 138    {
 14139        return (FriendEntryBase) friendsTab.Get(userId) ?? friendRequestsTab.Get(userId);
 140    }
 141
 0142    public void DisplayFriendUserNotFound() => friendRequestsTab.ShowUserNotFoundNotification();
 143
 0144    public bool IsFriendListCreationReady() => friendsTab.DidDeferredCreationCompleted;
 145
 146    public void Show()
 147    {
 2148        model.visible = true;
 2149        gameObject.SetActive(true);
 2150        AudioScriptableObjects.dialogOpen.Play(true);
 2151    }
 152
 153    public void Hide()
 154    {
 1155        model.visible = false;
 1156        gameObject.SetActive(false);
 1157        AudioScriptableObjects.dialogClose.Play(true);
 1158    }
 159
 160    public void Set(string userId, FriendEntryModel model)
 161    {
 6162        friendRequestsTab.Remove(userId);
 6163        friendsTab.Enqueue(userId, model);
 6164    }
 165
 166    public void Remove(string userId)
 167    {
 5168        friendRequestsTab.Remove(userId);
 5169        friendsTab.Remove(userId);
 5170    }
 171
 172    public void Set(string userId, FriendRequestEntryModel model)
 173    {
 5174        friendRequestsTab.Enqueue(userId, model);
 5175        friendsTab.Remove(userId);
 5176    }
 177
 3178    public bool IsActive() => gameObject.activeInHierarchy;
 179
 180    public void ShowRequestSendError(FriendRequestError error)
 181    {
 182        switch (error)
 183        {
 184            case FriendRequestError.AlreadyFriends:
 0185                friendRequestsTab.ShowAlreadyFriendsNotification();
 186                break;
 187        }
 0188    }
 189
 190    public void ShowRequestSendSuccess()
 191    {
 0192        friendRequestsTab.ShowRequestSuccessfullySentNotification();
 0193    }
 194
 1195    public void ShowMoreFriendsToLoadHint(int pendingFriendsCount) => friendsTab.ShowMoreFriendsToLoadHint(pendingFriend
 196
 1197    public void HideMoreFriendsToLoadHint() => friendsTab.HideMoreFriendsToLoadHint();
 198
 199    public void ShowMoreRequestsToLoadHint(int pendingRequestsCount) =>
 1200        friendRequestsTab.ShowMoreFriendsToLoadHint(pendingRequestsCount);
 201
 1202    public void HideMoreRequestsToLoadHint() => friendRequestsTab.HideMoreFriendsToLoadHint();
 203
 14204    public bool ContainsFriend(string userId) => friendsTab.Get(userId) != null;
 205
 14206    public bool ContainsFriendRequest(string userId) => friendRequestsTab.Get(userId) != null;
 207
 0208    public void FilterFriends(Dictionary<string, FriendEntryModel> friends) => friendsTab.Filter(friends);
 209
 0210    public void ClearFriendFilter() => friendsTab.ClearFilter();
 211
 212    public void UpdateBlockStatus(string userId, bool blocked)
 213    {
 0214        UpdateBlockStatus(blocked, friendsTab.Get(userId));
 0215        UpdateBlockStatus(blocked, friendRequestsTab.Get(userId));
 0216    }
 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        }
 7242        else if (index == FRIENDS_REQUEST_TAB_INDEX)
 243        {
 7244            friendsTab.Hide();
 7245            friendRequestsTab.Show();
 7246        }
 247        else
 0248            throw new IndexOutOfRangeException();
 249    }
 250
 251    private void UpdateBlockStatus(bool blocked, FriendEntryBase friendEntry)
 252    {
 0253        if (friendEntry == null) return;
 0254        var friendModel = friendEntry.Model;
 0255        friendModel.blocked = blocked;
 0256        friendEntry.RefreshControl();
 0257    }
 258
 259    [Serializable]
 260    private struct Model
 261    {
 262        public int focusedTabIndex;
 263        public bool isLoadingSpinnerActive;
 264        public bool visible;
 265    }
 266}

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()
ListByOnlineStatus(System.Boolean)
FriendCount()
FriendRequestCount()
Create()
Initialize(IChatController, ILastReadMessagesService, IFriendsController, SocialFeaturesAnalytics.ISocialAnalytics)
Awake()
HideLoadingSpinner()
ShowLoadingSpinner()
GetAllEntries()
GetEntry(System.String)
DisplayFriendUserNotFound()
IsFriendListCreationReady()
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)
FilterFriends(System.Collections.Generic.Dictionary[String,FriendEntryModel])
ClearFriendFilter()
UpdateBlockStatus(System.String, System.Boolean)
RefreshControl()
FocusTab(System.Int32)
UpdateBlockStatus(System.Boolean, FriendEntryBase)