< Summary

Class:SortDropdownView
Assembly:BuilderProjectsPanel
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/Views/SearchBarView/SortDropdownView.cs
Covered lines:29
Uncovered lines:6
Coverable lines:35
Total lines:86
Line coverage:82.8% (29 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%3.043083.33%
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/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/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    {
 1121        dropdownButtonBase.gameObject.SetActive(false);
 1122        dropdownButtonBase.OnSelected += OnSortButtonPressed;
 1123        buttonsPool.Enqueue(dropdownButtonBase);
 24
 1125        gameObject.SetActive(false);
 1126    }
 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        {
 039            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    {
 2449        for (int i = 0; i < texts.Length; i++)
 50        {
 551            AddSortType(texts[i]);
 52        }
 753    }
 54
 55    public void AddSortType(string text)
 56    {
 57        SortDropdownButton button;
 558        if (buttonsPool.Count > 0)
 59        {
 360            button = buttonsPool.Dequeue();
 361        }
 62        else
 63        {
 264            button = Object.Instantiate(dropdownButtonBase, buttonsContainer);
 265            button.transform.ResetLocalTRS();
 266            button.OnSelected += OnSortButtonPressed;
 67        }
 568        button.SetText(text);
 569        button.gameObject.SetActive(true);
 570        activeButtons.Add(button);
 571    }
 72
 73    public void Clear()
 74    {
 875        for (int i = 0; i < activeButtons.Count; i++)
 76        {
 077            activeButtons[i].gameObject.SetActive(false);
 078            buttonsPool.Enqueue(activeButtons[i]);
 79        }
 480        activeButtons.Clear();
 481    }
 82
 283    private void OnSortButtonPressed(string sortType) { OnSortTypeSelected?.Invoke(sortType); }
 84
 085    void IDeselectHandler.OnDeselect(BaseEventData eventData) { Hide(); }
 86}