< Summary

Class:PlacesAndEventsSectionComponentView
Assembly:ExploreV2
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/Sections/PlacesAndEventsSection/PlacesAndEventsSectionComponentView.cs
Covered lines:57
Uncovered lines:32
Coverable lines:89
Total lines:213
Line coverage:64% (57 of 89)
Covered branches:0
Total branches:0
Covered methods:8
Total methods:17
Method coverage:47% (8 of 17)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
PlacesAndEventsSectionComponentView()0%110100%
Awake()0%110100%
Start()0%110100%
GoToSubsection(...)0%220100%
SetActive(...)0%9.169087.5%
EnableSearchBar(...)0%2100%
RefreshControl()0%2100%
Dispose()0%110100%
CreateSubSectionSelectorMappings()0%770100%
SearchTextChanged(...)0%72800%
RemoveSectionSelectorMappings()0%660100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/Sections/PlacesAndEventsSection/PlacesAndEventsSectionComponentView.cs

#LineLine coverage
 1using DCL;
 2using UnityEngine;
 3
 4public interface IPlacesAndEventsSectionComponentView
 5{
 6    /// <summary>
 7    /// Places sub-section component.
 8    /// </summary>
 9    IPlacesSubSectionComponentView PlacesSubSectionView { get; }
 10
 11    /// <summary>
 12    /// Places sub-section component.
 13    /// </summary>
 14    IWorldsSubSectionComponentView WorldsSubSectionView { get; }
 15
 16    /// <summary>
 17    /// Events sub-section component.
 18    /// </summary>
 19    IEventsSubSectionComponentView EventsSubSectionView { get; }
 20
 21    /// <summary>
 22    /// Favorites sub-section component.
 23    /// </summary>
 24    IFavoriteSubSectionComponentView FavoritesSubSectionView { get; }
 25
 26    /// <summary>
 27    /// Favorites sub-section component.
 28    /// </summary>
 29    ISearchSubSectionComponentView SearchSubSectionView { get; }
 30
 31    SearchBarComponentView SearchBar { get; }
 32
 33    /// <summary>
 34    /// Open a sub-section.
 35    /// </summary>
 36    /// <param name="subSectionIndex">Sub-section index.</param>
 37    void GoToSubsection(int subSectionIndex);
 38
 39    /// <summary>
 40    /// Activates/deactivates the section.
 41    /// </summary>
 42    /// <param name="isActive"></param>
 43    void SetActive(bool isActive);
 44
 45    void EnableSearchBar(bool isActive);
 46}
 47
 48public class PlacesAndEventsSectionComponentView : BaseComponentView, IPlacesAndEventsSectionComponentView
 49{
 50    internal const int PLACES_SUB_SECTION_INDEX = 0;
 51    internal const int WORLDS_SUB_SECTION_INDEX = 1;
 52    internal const int EVENTS_SUB_SECTION_INDEX = 2;
 53    internal const int FAVORITES_SUB_SECTION_INDEX = 3;
 54    internal const int SEARCH_SUB_SECTION_INDEX = 4;
 55
 56    internal const string WORLDS_SUBSECTION_FF = "worlds_subsection";
 57
 58    [Header("Top Menu")]
 59    [SerializeField] internal SectionSelectorComponentView subSectionSelector;
 60
 61    [Header("Sub-Sections")]
 62    [SerializeField] internal PlacesSubSectionComponentView placesSubSection;
 63    [SerializeField] internal WorldsSubSectionComponentView worldsSubSection;
 64    [SerializeField] internal EventsSubSectionComponentView eventsSubSection;
 65    [SerializeField] internal FavoriteSubSectionComponentView favoritesSubSection;
 66    [SerializeField] internal SearchSubSectionComponentView searchSubSection;
 67    [SerializeField] internal SearchBarComponentView searchBar;
 68
 69    private Canvas canvas;
 3970    private int currentSelectedIndex = -1;
 71
 72    public override void Awake()
 73    {
 3774        base.Awake();
 3775        canvas = GetComponent<Canvas>();
 3776    }
 77
 78    public void Start()
 79    {
 3680        CreateSubSectionSelectorMappings();
 3681        SetActive(false);
 3682    }
 83
 084    public IPlacesSubSectionComponentView PlacesSubSectionView => placesSubSection;
 085    public IWorldsSubSectionComponentView WorldsSubSectionView => worldsSubSection;
 086    public IEventsSubSectionComponentView EventsSubSectionView => eventsSubSection;
 087    public IFavoriteSubSectionComponentView FavoritesSubSectionView => favoritesSubSection;
 088    public ISearchSubSectionComponentView SearchSubSectionView => searchSubSection;
 089    public SearchBarComponentView SearchBar => searchBar;
 90
 91    public void GoToSubsection(int subSectionIndex) =>
 292        subSectionSelector.GetSection(subSectionIndex)?.SelectToggle(reselectIfAlreadyOn: true);
 93
 94    public void SetActive(bool isActive)
 95    {
 3896        canvas.enabled = isActive;
 97
 98        //Temporary untill the full feature is released
 3899        if(DataStore.i.HUDs.enableFavoritePlaces.Get())
 0100            subSectionSelector.EnableSection(FAVORITES_SUB_SECTION_INDEX);
 101        else
 38102            subSectionSelector.DisableSection(FAVORITES_SUB_SECTION_INDEX);
 103
 104        //Temporary until the full feature is released
 38105        if (DataStore.i.featureFlags.flags.Get().IsFeatureEnabled(WORLDS_SUBSECTION_FF))
 0106            subSectionSelector.EnableSection(WORLDS_SUB_SECTION_INDEX);
 107        else
 38108            subSectionSelector.DisableSection(WORLDS_SUB_SECTION_INDEX);
 109
 38110        placesSubSection.SetActive(isActive && currentSelectedIndex == PLACES_SUB_SECTION_INDEX);
 38111        worldsSubSection.SetActive(isActive && currentSelectedIndex == WORLDS_SUB_SECTION_INDEX);
 38112        eventsSubSection.SetActive(isActive && currentSelectedIndex == EVENTS_SUB_SECTION_INDEX);
 38113        favoritesSubSection.SetActive(isActive && currentSelectedIndex == FAVORITES_SUB_SECTION_INDEX);
 38114        searchSubSection.SetActive(isActive && currentSelectedIndex == SEARCH_SUB_SECTION_INDEX);
 115
 38116        if (!isActive)
 117        {
 37118            searchBar.ClearSearch(false);
 37119            searchSubSection.SetHeaderEnabled("");
 120        }
 38121    }
 122
 123    public void EnableSearchBar(bool isActive)
 124    {
 0125        searchBar.gameObject.SetActive(isActive);
 0126    }
 127
 128    public override void RefreshControl()
 129    {
 0130        placesSubSection.RefreshControl();
 0131        worldsSubSection.RefreshControl();
 0132        eventsSubSection.RefreshControl();
 0133        favoritesSubSection.RefreshControl();
 0134        searchSubSection.RefreshControl();
 0135    }
 136
 137    public override void Dispose()
 138    {
 45139        base.Dispose();
 140
 45141        RemoveSectionSelectorMappings();
 45142        placesSubSection.Dispose();
 45143        worldsSubSection.Dispose();
 45144        eventsSubSection.Dispose();
 45145        favoritesSubSection.Dispose();
 45146        searchSubSection.Dispose();
 45147    }
 148
 149    internal void CreateSubSectionSelectorMappings()
 150    {
 40151        subSectionSelector.GetSection(PLACES_SUB_SECTION_INDEX)?.onSelect.AddListener((isActive) =>
 152        {
 46153            placesSubSection.SetActive(isActive);
 46154            searchSubSection.SetActive(false);
 46155            currentSelectedIndex = PLACES_SUB_SECTION_INDEX;
 46156        });
 40157        subSectionSelector.GetSection(WORLDS_SUB_SECTION_INDEX)?.onSelect.AddListener((isActive) =>
 158        {
 0159            worldsSubSection.SetActive(isActive);
 0160            searchSubSection.SetActive(false);
 0161            currentSelectedIndex = WORLDS_SUB_SECTION_INDEX;
 0162        });
 40163        subSectionSelector.GetSection(EVENTS_SUB_SECTION_INDEX)?.onSelect.AddListener((isActive) =>
 164        {
 3165            eventsSubSection.SetActive(isActive);
 3166            searchSubSection.SetActive(false);
 3167            currentSelectedIndex = EVENTS_SUB_SECTION_INDEX;
 3168        });
 40169        subSectionSelector.GetSection(FAVORITES_SUB_SECTION_INDEX)?.onSelect.AddListener((isActive) =>
 170        {
 0171            favoritesSubSection.SetActive(isActive);
 0172            searchSubSection.SetActive(false);
 0173            currentSelectedIndex = FAVORITES_SUB_SECTION_INDEX;
 0174        });
 40175        subSectionSelector.GetSection(SEARCH_SUB_SECTION_INDEX)?.onSelect.AddListener((isActive) =>
 176        {
 0177            searchSubSection.SetActive(isActive);
 0178        });
 179
 40180        searchBar.OnSearchText += SearchTextChanged;
 181
 40182        placesSubSection.SetActive(false);
 40183        worldsSubSection.SetActive(false);
 40184        eventsSubSection.SetActive(false);
 40185        favoritesSubSection.SetActive(false);
 40186        searchSubSection.SetActive(false);
 187
 40188        subSectionSelector.GetSection(PLACES_SUB_SECTION_INDEX)?.SelectToggle(reselectIfAlreadyOn: true);
 40189    }
 190
 191    private void SearchTextChanged(string searchText)
 192    {
 0193        if (string.IsNullOrEmpty(searchText))
 194        {
 0195            subSectionSelector.GetSection(currentSelectedIndex)?.onSelect?.Invoke(true);
 0196            subSectionSelector.GetSection(SEARCH_SUB_SECTION_INDEX)?.UnSelectToggle(true);
 197        }
 198        else
 199        {
 0200            subSectionSelector.GetSection(currentSelectedIndex)?.onSelect?.Invoke(false);
 0201            subSectionSelector.GetSection(SEARCH_SUB_SECTION_INDEX)?.SelectToggle(true);
 202        }
 0203    }
 204
 205    internal void RemoveSectionSelectorMappings()
 206    {
 47207        subSectionSelector.GetSection(PLACES_SUB_SECTION_INDEX)?.onSelect.RemoveAllListeners();
 47208        subSectionSelector.GetSection(WORLDS_SUB_SECTION_INDEX)?.onSelect.RemoveAllListeners();
 47209        subSectionSelector.GetSection(EVENTS_SUB_SECTION_INDEX)?.onSelect.RemoveAllListeners();
 47210        subSectionSelector.GetSection(FAVORITES_SUB_SECTION_INDEX)?.onSelect.RemoveAllListeners();
 47211        subSectionSelector.GetSection(SEARCH_SUB_SECTION_INDEX)?.onSelect.RemoveAllListeners();
 47212    }
 213}