< 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:40
Uncovered lines:7
Coverable lines:47
Total lines:126
Line coverage:85.1% (40 of 47)
Covered branches:0
Total branches:0

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%440100%
RefreshControl()0%2100%
Dispose()0%110100%
CreateSubSectionSelectorMappings()0%550100%
RemoveSectionSelectorMappings()0%440100%

File(s)

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

#LineLine coverage
 1using UnityEngine;
 2
 3public interface IPlacesAndEventsSectionComponentView
 4{
 5    /// <summary>
 6    /// Highlights sub-section component.
 7    /// </summary>
 8    IHighlightsSubSectionComponentView HighlightsSubSectionView { get; }
 9
 10    /// <summary>
 11    /// Places sub-section component.
 12    /// </summary>
 13    IPlacesSubSectionComponentView PlacesSubSectionView { get; }
 14
 15    /// <summary>
 16    /// Events sub-section component.
 17    /// </summary>
 18    IEventsSubSectionComponentView EventsSubSectionView { get; }
 19
 20    /// <summary>
 21    /// Open a sub-section.
 22    /// </summary>
 23    /// <param name="subSectionIndex">Sub-section index.</param>
 24    void GoToSubsection(int subSectionIndex);
 25
 26    /// <summary>
 27    /// Activates/deactivates the section.
 28    /// </summary>
 29    /// <param name="isActive"></param>
 30    void SetActive(bool isActive);
 31}
 32
 33public class PlacesAndEventsSectionComponentView : BaseComponentView, IPlacesAndEventsSectionComponentView
 34{
 35    internal const int HIGHLIGHTS_SUB_SECTION_INDEX = 0;
 36    internal const int PLACES_SUB_SECTION_INDEX = 1;
 37    internal const int EVENTS_SUB_SECTION_INDEX = 2;
 38
 39    [Header("Top Menu")]
 40    [SerializeField] internal SectionSelectorComponentView subSectionSelector;
 41
 42    [Header("Sub-Sections")]
 43    [SerializeField] internal HighlightsSubSectionComponentView highlightsSubSection;
 44    [SerializeField] internal PlacesSubSectionComponentView placesSubSection;
 45    [SerializeField] internal EventsSubSectionComponentView eventsSubSection;
 46
 47    private Canvas canvas;
 4248    private int currentSelectedIndex = -1;
 49
 50    public override void Awake()
 51    {
 4052        base.Awake();
 4053        canvas = GetComponent<Canvas>();
 4054    }
 55
 56    public override void Start()
 57    {
 3958        CreateSubSectionSelectorMappings();
 3959        SetActive(false);
 3960    }
 61
 062    public IHighlightsSubSectionComponentView HighlightsSubSectionView => highlightsSubSection;
 063    public IPlacesSubSectionComponentView PlacesSubSectionView => placesSubSection;
 064    public IEventsSubSectionComponentView EventsSubSectionView => eventsSubSection;
 65
 66    public void GoToSubsection(int subSectionIndex) =>
 367        subSectionSelector.GetSection(subSectionIndex)?.SelectToggle(reselectIfAlreadyOn: true);
 68
 69    public void SetActive(bool isActive)
 70    {
 4171        canvas.enabled = isActive;
 72
 4173        highlightsSubSection.SetActive(isActive && currentSelectedIndex == HIGHLIGHTS_SUB_SECTION_INDEX);
 4174        placesSubSection.SetActive(isActive && currentSelectedIndex == PLACES_SUB_SECTION_INDEX);
 4175        eventsSubSection.SetActive(isActive && currentSelectedIndex == EVENTS_SUB_SECTION_INDEX);
 4176    }
 77
 78    public override void RefreshControl()
 79    {
 080        highlightsSubSection.RefreshControl();
 081        placesSubSection.RefreshControl();
 082        eventsSubSection.RefreshControl();
 083    }
 84
 85    public override void Dispose()
 86    {
 5187        base.Dispose();
 88
 5189        RemoveSectionSelectorMappings();
 5190        highlightsSubSection.Dispose();
 5191        placesSubSection.Dispose();
 5192        eventsSubSection.Dispose();
 5193    }
 94
 95    internal void CreateSubSectionSelectorMappings()
 96    {
 4597        subSectionSelector.GetSection(HIGHLIGHTS_SUB_SECTION_INDEX)?.onSelect.AddListener((isActive) =>
 98        {
 5399            highlightsSubSection.SetActive(isActive);
 53100            currentSelectedIndex = HIGHLIGHTS_SUB_SECTION_INDEX;
 53101        });
 45102        subSectionSelector.GetSection(PLACES_SUB_SECTION_INDEX)?.onSelect.AddListener((isActive) =>
 103        {
 3104            placesSubSection.SetActive(isActive);
 3105            currentSelectedIndex = PLACES_SUB_SECTION_INDEX;
 3106        });
 45107        subSectionSelector.GetSection(EVENTS_SUB_SECTION_INDEX)?.onSelect.AddListener((isActive) =>
 108        {
 3109            eventsSubSection.SetActive(isActive);
 3110            currentSelectedIndex = EVENTS_SUB_SECTION_INDEX;
 3111        });
 112
 45113        placesSubSection.SetActive(false);
 45114        eventsSubSection.SetActive(false);
 45115        highlightsSubSection.SetActive(false);
 116
 45117        subSectionSelector.GetSection(HIGHLIGHTS_SUB_SECTION_INDEX)?.SelectToggle(reselectIfAlreadyOn: true);
 45118    }
 119
 120    internal void RemoveSectionSelectorMappings()
 121    {
 54122        subSectionSelector.GetSection(HIGHLIGHTS_SUB_SECTION_INDEX)?.onSelect.RemoveAllListeners();
 54123        subSectionSelector.GetSection(PLACES_SUB_SECTION_INDEX)?.onSelect.RemoveAllListeners();
 54124        subSectionSelector.GetSection(EVENTS_SUB_SECTION_INDEX)?.onSelect.RemoveAllListeners();
 54125    }
 126}