< Summary

Class:EventsSubSectionComponentView
Assembly:ExploreV2
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/Sections/PlacesAndEventsSection/SubSections/EventsSubSection/EventsSubSectionMenu/EventsSubSectionComponentView.cs
Covered lines:9
Uncovered lines:51
Coverable lines:60
Total lines:233
Line coverage:15% (9 of 60)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
OnEnable()0%2.52050%
PostInitialization()0%110100%
RefreshControl()0%2100%
Dispose()0%110100%
WaitForComponentsInitialization()0%12.194020%
SetFeaturedEvents(...)0%2100%
SetFeaturedEventsAsLoading(...)0%2100%
SetTrendingEvents(...)0%2100%
SetTrendingEventsAsLoading(...)0%2100%
SetUpcomingEvents(...)0%2100%
SetUpcomingEventsAsLoading(...)0%2100%
SetGoingEvents(...)0%2100%
SetGoingEventsAsLoading(...)0%2100%
ShowEventModal(...)0%2100%
HideEventModal()0%2100%
SetShowMoreUpcomingEventsButtonActive(...)0%2100%
IntantiateAndConfigureEventCards(...)0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/Sections/PlacesAndEventsSection/SubSections/EventsSubSection/EventsSubSectionMenu/EventsSubSectionComponentView.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using System.Collections.Generic;
 4using TMPro;
 5using UnityEngine;
 6
 7public interface IEventsSubSectionComponentView
 8{
 9    /// <summary>
 10    /// It will be triggered when all the UI components have been fully initialized.
 11    /// </summary>
 12    event Action OnReady;
 13
 14    /// <summary>
 15    /// It will be triggered when the "Show More" button is clicked.
 16    /// </summary>
 17    event Action OnShowMoreUpcomingEventsClicked;
 18
 19    /// <summary>
 20    /// It will be triggered each time the view is enabled.
 21    /// </summary>
 22    event Action OnEventsSubSectionEnable;
 23
 24    /// <summary>
 25    /// Set the featured events component with a list of events.
 26    /// </summary>
 27    /// <param name="events">List of events (model) to be loaded.</param>
 28    void SetFeaturedEvents(List<EventCardComponentModel> events);
 29
 30    /// <summary>
 31    /// Set the featured events component in loading mode.
 32    /// </summary>
 33    /// <param name="isVisible">True for activating the loading mode.</param>
 34    void SetFeaturedEventsAsLoading(bool isVisible);
 35
 36    /// <summary>
 37    /// Set the trending events component with a list of events.
 38    /// </summary>
 39    /// <param name="events">List of events (model) to be loaded.</param>
 40    void SetTrendingEvents(List<EventCardComponentModel> events);
 41
 42    /// <summary>
 43    /// Set the trending events component in loading mode.
 44    /// </summary>
 45    /// <param name="isVisible">True for activating the loading mode.</param>
 46    void SetTrendingEventsAsLoading(bool isVisible);
 47
 48    /// <summary>
 49    /// Set the upcoming events component with a list of events.
 50    /// </summary>
 51    /// <param name="events">List of events (model) to be loaded.</param>
 52    void SetUpcomingEvents(List<EventCardComponentModel> events);
 53
 54    /// <summary>
 55    /// Set the upcoming events component in loading mode.
 56    /// </summary>
 57    /// <param name="isVisible">True for activating the loading mode.</param>
 58    void SetUpcomingEventsAsLoading(bool isVisible);
 59
 60    /// <summary>
 61    /// Activates/Deactivates the "Show More" button.
 62    /// </summary>
 63    /// <param name="isActive">True for activating it.</param>
 64    void SetShowMoreUpcomingEventsButtonActive(bool isActive);
 65
 66    /// <summary>
 67    /// Set the going events component with a list of events.
 68    /// </summary>
 69    /// <param name="events">List of events (model) to be loaded.</param>
 70    void SetGoingEvents(List<EventCardComponentModel> events);
 71
 72    /// <summary>
 73    /// Set the going events component in loading mode.
 74    /// </summary>
 75    /// <param name="isVisible">True for activating the loading mode.</param>
 76    void SetGoingEventsAsLoading(bool isVisible);
 77
 78    /// <summary>
 79    /// Shows the Event Card modal with the provided information.
 80    /// </summary>
 81    /// <param name="eventInfo">Event (model) to be loaded in the card.</param>
 82    void ShowEventModal(EventCardComponentModel eventInfo);
 83
 84    /// <summary>
 85    /// Hides the Event Card modal.
 86    /// </summary>
 87    void HideEventModal();
 88}
 89
 90public class EventsSubSectionComponentView : BaseComponentView, IEventsSubSectionComponentView
 91{
 92    [Header("Assets References")]
 93    [SerializeField] internal EventCardComponentView eventCardPrefab;
 94    [SerializeField] internal EventCardComponentView eventCardLongPrefab;
 95    [SerializeField] internal EventCardComponentView eventCardModalPrefab;
 96
 97    [Header("Prefab References")]
 98    [SerializeField] internal CarouselComponentView featuredEvents;
 99    [SerializeField] internal GameObject featuredEventsLoading;
 100    [SerializeField] internal GridContainerComponentView trendingEvents;
 101    [SerializeField] internal GameObject trendingEventsLoading;
 102    [SerializeField] internal TMP_Text trendingEventsNoDataText;
 103    [SerializeField] internal GridContainerComponentView upcomingEvents;
 104    [SerializeField] internal GameObject upcomingEventsLoading;
 105    [SerializeField] internal TMP_Text upcomingEventsNoDataText;
 106    [SerializeField] internal GridContainerComponentView goingEvents;
 107    [SerializeField] internal GameObject goingEventsLoading;
 108    [SerializeField] internal TMP_Text goingEventsNoDataText;
 109    [SerializeField] internal GameObject showMoreUpcomingEventsButtonContainer;
 110    [SerializeField] internal ButtonComponentView showMoreUpcomingEventsButton;
 111
 112    public event Action OnReady;
 113    public event Action OnShowMoreUpcomingEventsClicked;
 114    public event Action OnEventsSubSectionEnable;
 115
 116    internal EventCardComponentView eventModal;
 117
 1118    private void OnEnable() { OnEventsSubSectionEnable?.Invoke(); }
 119
 120    public override void PostInitialization()
 121    {
 1122        StartCoroutine(WaitForComponentsInitialization());
 123
 1124        eventModal = GameObject.Instantiate(eventCardModalPrefab);
 1125        eventModal.gameObject.SetActive(false);
 1126    }
 127
 128    public override void RefreshControl()
 129    {
 0130        featuredEvents.RefreshControl();
 0131        trendingEvents.RefreshControl();
 0132        upcomingEvents.RefreshControl();
 0133        goingEvents.RefreshControl();
 0134    }
 135
 136    public override void Dispose()
 137    {
 1138        base.Dispose();
 139
 1140        showMoreUpcomingEventsButton.onClick.RemoveAllListeners();
 1141    }
 142
 143    public IEnumerator WaitForComponentsInitialization()
 144    {
 2145        yield return new WaitUntil(() => featuredEvents.isFullyInitialized &&
 146                                         trendingEvents.isFullyInitialized &&
 147                                         upcomingEvents.isFullyInitialized &&
 148                                         goingEvents.isFullyInitialized &&
 149                                         showMoreUpcomingEventsButton.isFullyInitialized);
 150
 0151        showMoreUpcomingEventsButton.onClick.RemoveAllListeners();
 0152        showMoreUpcomingEventsButton.onClick.AddListener(() => OnShowMoreUpcomingEventsClicked?.Invoke());
 0153        OnReady?.Invoke();
 0154    }
 155
 156    public void SetFeaturedEvents(List<EventCardComponentModel> events)
 157    {
 0158        List<BaseComponentView> eventComponentsToAdd = IntantiateAndConfigureEventCards(events, eventCardLongPrefab);
 0159        featuredEvents.SetItems(eventComponentsToAdd, false);
 0160        featuredEvents.gameObject.SetActive(events.Count > 0);
 0161    }
 162    public void SetFeaturedEventsAsLoading(bool isVisible)
 163    {
 0164        featuredEvents.gameObject.SetActive(!isVisible);
 0165        featuredEventsLoading.SetActive(isVisible);
 0166    }
 167
 168    public void SetTrendingEvents(List<EventCardComponentModel> events)
 169    {
 0170        List<BaseComponentView> eventComponentsToAdd = IntantiateAndConfigureEventCards(events, eventCardPrefab);
 0171        trendingEvents.SetItems(eventComponentsToAdd, false);
 0172        trendingEventsNoDataText.gameObject.SetActive(events.Count == 0);
 0173    }
 174
 175    public void SetTrendingEventsAsLoading(bool isVisible)
 176    {
 0177        trendingEvents.gameObject.SetActive(!isVisible);
 0178        trendingEventsLoading.SetActive(isVisible);
 0179        trendingEventsNoDataText.gameObject.SetActive(false);
 0180    }
 181
 182    public void SetUpcomingEvents(List<EventCardComponentModel> events)
 183    {
 0184        List<BaseComponentView> eventComponentsToAdd = IntantiateAndConfigureEventCards(events, eventCardPrefab);
 0185        upcomingEvents.SetItems(eventComponentsToAdd, false);
 0186        upcomingEventsNoDataText.gameObject.SetActive(events.Count == 0);
 0187    }
 188
 189    public void SetUpcomingEventsAsLoading(bool isVisible)
 190    {
 0191        upcomingEvents.gameObject.SetActive(!isVisible);
 0192        upcomingEventsLoading.SetActive(isVisible);
 0193        upcomingEventsNoDataText.gameObject.SetActive(false);
 0194    }
 195
 196    public void SetGoingEvents(List<EventCardComponentModel> events)
 197    {
 0198        List<BaseComponentView> eventComponentsToAdd = IntantiateAndConfigureEventCards(events, eventCardPrefab);
 0199        goingEvents.SetItems(eventComponentsToAdd, false);
 0200        goingEventsNoDataText.gameObject.SetActive(events.Count == 0);
 0201    }
 202
 203    public void SetGoingEventsAsLoading(bool isVisible)
 204    {
 0205        goingEvents.gameObject.SetActive(!isVisible);
 0206        goingEventsLoading.SetActive(isVisible);
 0207        goingEventsNoDataText.gameObject.SetActive(false);
 0208    }
 209
 210    public void ShowEventModal(EventCardComponentModel eventInfo)
 211    {
 0212        eventModal.gameObject.SetActive(true);
 0213        eventModal.Configure(eventInfo);
 0214    }
 215
 0216    public void HideEventModal() { eventModal.gameObject.SetActive(false); }
 217
 0218    public void SetShowMoreUpcomingEventsButtonActive(bool isActive) { showMoreUpcomingEventsButtonContainer.gameObject.
 219
 220    internal List<BaseComponentView> IntantiateAndConfigureEventCards(List<EventCardComponentModel> events, EventCardCom
 221    {
 0222        List<BaseComponentView> instantiatedEvents = new List<BaseComponentView>();
 223
 0224        foreach (EventCardComponentModel eventInfo in events)
 225        {
 0226            EventCardComponentView eventGO = GameObject.Instantiate(prefabToUse);
 0227            eventGO.Configure(eventInfo);
 0228            instantiatedEvents.Add(eventGO);
 229        }
 230
 0231        return instantiatedEvents;
 232    }
 233}