< Summary

Class:SectionSceneContributorsSettingsView
Assembly:BuilderProjectsPanel
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/Views/MenuSections/SectionSceneContributorsSettingsView.cs
Covered lines:41
Uncovered lines:7
Coverable lines:48
Total lines:119
Line coverage:85.4% (41 of 48)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SectionSceneContributorsSettingsView()0%110100%
Awake()0%110100%
OnDestroy()0%110100%
Dispose()0%220100%
SetParent(...)0%2100%
SetActive(...)0%2100%
GetSearchPromptView()0%2100%
SetEmptyList(...)0%3.13077.78%
SetContributorsCount(...)0%110100%
AddUser(...)0%220100%
RemoveUser(...)0%2.032080%
PoolView(...)0%110100%
GetView()0%220100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/Views/MenuSections/SectionSceneContributorsSettingsView.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using DCL.Helpers;
 4using TMPro;
 5using UnityEngine;
 6using UnityEngine.UI;
 7
 8internal class SectionSceneContributorsSettingsView : MonoBehaviour, IDisposable
 9{
 10    [SerializeField] internal UsersSearchPromptView usersSearchPromptView;
 11    [SerializeField] internal Button addUserButton;
 12    [SerializeField] internal UserElementView userElementView;
 13    [SerializeField] internal Transform usersContainer;
 14    [SerializeField] internal GameObject emptyListContainer;
 15    [SerializeField] internal TextMeshProUGUI labelContributor;
 16
 17    public event Action OnSearchUserButtonPressed;
 18
 519    internal readonly Dictionary<string, UserElementView> userElementViews = new Dictionary<string, UserElementView>();
 520    private readonly Queue<UserElementView> userElementViewsPool = new Queue<UserElementView>();
 21
 22    private string contributorLabelFormat;
 23    private bool isDestroyed = false;
 24
 25    private void Awake()
 26    {
 427        addUserButton.onClick.AddListener(() => OnSearchUserButtonPressed?.Invoke());
 428        PoolView(userElementView);
 429        contributorLabelFormat = labelContributor.text;
 430    }
 31
 832    private void OnDestroy() { isDestroyed  = true; }
 33
 34    public void Dispose()
 35    {
 436        if (!isDestroyed)
 37        {
 438            Destroy(gameObject);
 39        }
 440    }
 41
 42    public void SetParent(Transform parent)
 43    {
 044        transform.SetParent(parent);
 045        transform.ResetLocalTRS();
 046    }
 47
 048    public void SetActive(bool active) { gameObject.SetActive(active); }
 49
 050    public UsersSearchPromptView GetSearchPromptView() { return usersSearchPromptView; }
 51
 52    public void SetEmptyList(bool isEmpty)
 53    {
 554        usersContainer.gameObject.SetActive(!isEmpty);
 555        emptyListContainer.SetActive(isEmpty);
 56
 557        if (isEmpty)
 58        {
 459            foreach (UserElementView view in userElementViews.Values)
 60            {
 061                PoolView(view);
 62            }
 263            userElementViews.Clear();
 64        }
 565    }
 66
 867    public void SetContributorsCount(int count) { labelContributor.text = string.Format(contributorLabelFormat, count); 
 68
 69    public UserElementView AddUser(string userId)
 70    {
 671        if (!userElementViews.TryGetValue(userId, out UserElementView view))
 72        {
 473            view = GetView();
 474            view.SetUserName(userId);
 475            view.SetUserId(userId);
 476            view.SetAlwaysHighlighted(false);
 477            view.SetIsAdded(true);
 478            view.SetActive(true);
 479            userElementViews.Add(userId, view);
 80        }
 81
 682        bool isBlocked = UserProfile.GetOwnUserProfile().blocked.Contains(userId);
 683        view.SetBlocked(isBlocked);
 684        return view;
 85    }
 86
 87    public bool RemoveUser(string userId)
 88    {
 289        if (!userElementViews.TryGetValue(userId, out UserElementView view))
 90        {
 091            return false;
 92        }
 293        userElementViews.Remove(userId);
 294        PoolView(view);
 295        return true;
 96    }
 97
 98    void PoolView(UserElementView view)
 99    {
 6100        view.SetActive(false);
 6101        userElementViewsPool.Enqueue(view);
 6102    }
 103
 104    UserElementView GetView()
 105    {
 106        UserElementView userView;
 107
 4108        if (userElementViewsPool.Count > 0)
 109        {
 2110            userView = userElementViewsPool.Dequeue();
 2111        }
 112        else
 113        {
 2114            userView = Instantiate(userElementView, usersContainer);
 115        }
 4116        userView.ClearThumbnail();
 4117        return userView;
 118    }
 119}