< Summary

Class:SortDropdownView
Assembly:BuilderProjectsPanel
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/BuilderProjectsPanel/Scripts/Views/SearchBarView/SortDropdownView.cs
Covered lines:30
Uncovered lines:5
Coverable lines:35
Total lines:86
Line coverage:85.7% (30 of 35)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SortDropdownView()0%110100%
Awake()0%110100%
GetSortTypesCount()0%2100%
Show()0%330100%
Hide()0%2100%
AddSortType(...)0%220100%
AddSortType(...)0%220100%
Clear()0%2.312057.14%
OnSortButtonPressed(...)0%220100%
OnDeselect(...)0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/BuilderProjectsPanel/Scripts/Views/SearchBarView/SortDropdownView.cs

#LineLine coverage
 1using DCL.Helpers;
 2using System;
 3using System.Collections.Generic;
 4using UnityEngine;
 5using UnityEngine.EventSystems;
 6using Object = UnityEngine.Object;
 7
 8internal class SortDropdownView : MonoBehaviour, IDeselectHandler
 9{
 10    public event Action<string> OnSortTypeSelected;
 11
 12    [SerializeField] private Transform buttonsContainer;
 13    [SerializeField] private SortDropdownButton dropdownButtonBase;
 14    [SerializeField] private ShowHideAnimator showHideAnimator;
 15
 2616    private readonly Queue<SortDropdownButton> buttonsPool = new Queue<SortDropdownButton>();
 2617    internal readonly List<SortDropdownButton> activeButtons = new List<SortDropdownButton>();
 18
 19    private void Awake()
 20    {
 1221        dropdownButtonBase.gameObject.SetActive(false);
 1222        dropdownButtonBase.OnSelected += OnSortButtonPressed;
 1223        buttonsPool.Enqueue(dropdownButtonBase);
 24
 1225        gameObject.SetActive(false);
 1226    }
 27
 028    public int GetSortTypesCount() { return activeButtons.Count; }
 29
 30    public void Show()
 31    {
 132        if (!gameObject.activeSelf)
 33        {
 134            gameObject.SetActive(true);
 35        }
 36
 137        if (EventSystem.current != null)
 38        {
 139            EventSystem.current.SetSelectedGameObject(gameObject);
 40        }
 41
 142        showHideAnimator.Show();
 143    }
 44
 045    public void Hide() { showHideAnimator.Hide(); }
 46
 47    public void AddSortType(string[] texts)
 48    {
 3449        for (int i = 0; i < texts.Length; i++)
 50        {
 951            AddSortType(texts[i]);
 52        }
 853    }
 54
 55    public void AddSortType(string text)
 56    {
 57        SortDropdownButton button;
 958        if (buttonsPool.Count > 0)
 59        {
 460            button = buttonsPool.Dequeue();
 461        }
 62        else
 63        {
 564            button = Object.Instantiate(dropdownButtonBase, buttonsContainer);
 565            button.transform.ResetLocalTRS();
 566            button.OnSelected += OnSortButtonPressed;
 67        }
 968        button.SetText(text);
 969        button.gameObject.SetActive(true);
 970        activeButtons.Add(button);
 971    }
 72
 73    public void Clear()
 74    {
 1075        for (int i = 0; i < activeButtons.Count; i++)
 76        {
 077            activeButtons[i].gameObject.SetActive(false);
 078            buttonsPool.Enqueue(activeButtons[i]);
 79        }
 580        activeButtons.Clear();
 581    }
 82
 283    private void OnSortButtonPressed(string sortType) { OnSortTypeSelected?.Invoke(sortType); }
 84
 085    void IDeselectHandler.OnDeselect(BaseEventData eventData) { Hide(); }
 86}