< Summary

Class:SearchInputField
Assembly:BuilderProjectsPanel
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/Views/SearchBarView/SearchInputField.cs
Covered lines:47
Uncovered lines:5
Coverable lines:52
Total lines:116
Line coverage:90.3% (47 of 52)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SearchInputField()0%110100%
ShowSearchSpinner()0%110100%
ShowSearchClearButton()0%110100%
ClearSearch()0%110100%
SetIdleSearchTime(...)0%2100%
Awake()0%110100%
OnValueChanged(...)0%2.032080%
OnSubmit(...)0%220100%
OnClear()0%220100%
StartSearchWhileTyping()0%2.062075%
StopSearchWhileTyping()0%220100%
SearchWhileTypingRoutine()0%6.226081.82%
SetTypingMode()0%110100%
SetSearchMode()0%110100%
SetClearMode()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/Views/SearchBarView/SearchInputField.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using TMPro;
 4using UnityEngine;
 5using UnityEngine.UI;
 6
 7internal class SearchInputField : MonoBehaviour
 8{
 9    public event Action<string> OnSearchText;
 10
 11    [SerializeField] internal TMP_InputField inputField;
 12    [SerializeField] internal GameObject searchSpinner;
 13    [SerializeField] internal Button clearSearchButton;
 5714    [SerializeField] internal float idleTimeToTriggerSearch = 1;
 15
 16    private Coroutine searchWhileTypingRoutine;
 17    private float lastValueChangeTime = 0;
 18
 419    public void ShowSearchSpinner() { SetTypingMode(); }
 20
 221    public void ShowSearchClearButton() { SetSearchMode(); }
 22
 1223    public void ClearSearch() { OnClear(); }
 24
 025    public void SetIdleSearchTime(float idleSearchTime) { idleTimeToTriggerSearch = idleSearchTime; }
 26
 27    private void Awake()
 28    {
 1729        inputField.onValueChanged.AddListener(OnValueChanged);
 1730        inputField.onSubmit.AddListener(OnSubmit);
 1731        clearSearchButton.onClick.AddListener(OnClear);
 32
 1733        SetClearMode();
 1734    }
 35
 36    private void OnValueChanged(string value)
 37    {
 238        if (idleTimeToTriggerSearch < 0)
 039            return;
 40
 241        lastValueChangeTime = Time.unscaledTime;
 242        StartSearchWhileTyping();
 243    }
 44
 45    internal void OnSubmit(string value)
 46    {
 347        StopSearchWhileTyping();
 348        SetSearchMode();
 349        OnSearchText?.Invoke(value);
 350    }
 51
 52    private void OnClear()
 53    {
 754        inputField.SetTextWithoutNotify(string.Empty);
 755        SetClearMode();
 756        OnSearchText?.Invoke(string.Empty);
 757    }
 58
 59    private void StartSearchWhileTyping()
 60    {
 261        if (searchWhileTypingRoutine != null)
 062            return;
 63
 264        searchWhileTypingRoutine = StartCoroutine(SearchWhileTypingRoutine());
 265    }
 66
 67    private void StopSearchWhileTyping()
 68    {
 369        if (searchWhileTypingRoutine == null)
 270            return;
 71
 172        StopCoroutine(searchWhileTypingRoutine);
 173        searchWhileTypingRoutine = null;
 174    }
 75
 76    private IEnumerator SearchWhileTypingRoutine()
 77    {
 278        SetTypingMode();
 79
 21780        while ((Time.unscaledTime - lastValueChangeTime) < idleTimeToTriggerSearch)
 81        {
 21682            yield return null;
 83        }
 84
 185        string value = inputField.text;
 186        if (string.IsNullOrEmpty(value))
 87        {
 088            SetClearMode();
 089        }
 90        else
 91        {
 192            SetSearchMode();
 93        }
 94
 195        OnSearchText?.Invoke(value);
 196        searchWhileTypingRoutine = null;
 197    }
 98
 99    private void SetTypingMode()
 100    {
 4101        clearSearchButton.gameObject.SetActive(false);
 4102        searchSpinner.SetActive(true);
 4103    }
 104
 105    private void SetSearchMode()
 106    {
 5107        clearSearchButton.gameObject.SetActive(true);
 5108        searchSpinner.SetActive(false);
 5109    }
 110
 111    private void SetClearMode()
 112    {
 24113        clearSearchButton.gameObject.SetActive(false);
 24114        searchSpinner.SetActive(false);
 24115    }
 116}