< 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:75
Uncovered lines:8
Coverable lines:83
Total lines:354
Line coverage:90.3% (75 of 83)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
OnEnable()0%2.52050%
Start()0%22092.31%
RefreshControl()0%2100%
Dispose()0%220100%
SetFeaturedEvents(...)0%110100%
SetFeaturedEventsAsLoading(...)0%110100%
SetFeaturedEventsActive(...)0%110100%
SetTrendingEvents(...)0%110100%
SetTrendingEventsAsLoading(...)0%220100%
SetUpcomingEvents(...)0%110100%
AddUpcomingEvents(...)0%220100%
SetUpcomingEventsAsLoading(...)0%220100%
SetGoingEvents(...)0%110100%
SetGoingEventsAsLoading(...)0%220100%
ShowEventModal(...)0%110100%
HideEventModal()0%110100%
RestartScrollViewPosition()0%2100%
SetShowMoreUpcomingEventsButtonActive(...)0%110100%

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 DCL;
 2using System;
 3using System.Collections.Generic;
 4using TMPro;
 5using UnityEngine;
 6using UnityEngine.UI;
 7
 8public interface IEventsSubSectionComponentView
 9{
 10    /// <summary>
 11    /// It will be triggered when all the UI components have been fully initialized.
 12    /// </summary>
 13    event Action OnReady;
 14
 15    /// <summary>
 16    /// It will be triggered when the info button is clicked.
 17    /// </summary>
 18    event Action<EventCardComponentModel> OnInfoClicked;
 19
 20    /// <summary>
 21    /// It will be triggered when the JumpIn button is clicked.
 22    /// </summary>
 23    event Action<EventFromAPIModel> OnJumpInClicked;
 24
 25    /// <summary>
 26    /// It will be triggered when the subscribe event button is clicked.
 27    /// </summary>
 28    event Action<string> OnSubscribeEventClicked;
 29
 30    /// <summary>
 31    /// It will be triggered when the unsubscribe event button is clicked.
 32    /// </summary>
 33    event Action<string> OnUnsubscribeEventClicked;
 34
 35    /// <summary>
 36    /// It will be triggered when the "Show More" button is clicked.
 37    /// </summary>
 38    event Action OnShowMoreUpcomingEventsClicked;
 39
 40    /// <summary>
 41    /// It will be triggered each time the view is enabled.
 42    /// </summary>
 43    event Action OnEventsSubSectionEnable;
 44
 45    /// <summary>
 46    /// Number of events per row that fit with the current upcoming events grid configuration.
 47    /// </summary>
 48    int currentUpcomingEventsPerRow { get; }
 49
 50    /// <summary>
 51    /// Set the featured events component with a list of events.
 52    /// </summary>
 53    /// <param name="events">List of events (model) to be loaded.</param>
 54    void SetFeaturedEvents(List<EventCardComponentModel> events);
 55
 56    /// <summary>
 57    /// Set the featured events component in loading mode.
 58    /// </summary>
 59    /// <param name="isVisible">True for activating the loading mode.</param>
 60    void SetFeaturedEventsAsLoading(bool isVisible);
 61
 62    /// <summary>
 63    /// Activates/deactivates the featured events component.
 64    /// </summary>
 65    /// <param name="isActive"></param>
 66    void SetFeaturedEventsActive(bool isActive);
 67
 68    /// <summary>
 69    /// Set the trending events component with a list of events.
 70    /// </summary>
 71    /// <param name="events">List of events (model) to be loaded.</param>
 72    void SetTrendingEvents(List<EventCardComponentModel> events);
 73
 74    /// <summary>
 75    /// Set the trending events component in loading mode.
 76    /// </summary>
 77    /// <param name="isVisible">True for activating the loading mode.</param>
 78    void SetTrendingEventsAsLoading(bool isVisible);
 79
 80    /// <summary>
 81    /// Set the upcoming events component with a list of events.
 82    /// </summary>
 83    /// <param name="events">List of events (model) to be loaded.</param>
 84    void SetUpcomingEvents(List<EventCardComponentModel> events);
 85
 86    /// <summary>
 87    /// Add a list of events in the events component.
 88    /// </summary>
 89    /// <param name="places">List of events (model) to be added.</param>
 90    void AddUpcomingEvents(List<EventCardComponentModel> events);
 91
 92    /// <summary>
 93    /// Set the upcoming events component in loading mode.
 94    /// </summary>
 95    /// <param name="isVisible">True for activating the loading mode.</param>
 96    void SetUpcomingEventsAsLoading(bool isVisible);
 97
 98    /// <summary>
 99    /// Activates/Deactivates the "Show More" button.
 100    /// </summary>
 101    /// <param name="isActive">True for activating it.</param>
 102    void SetShowMoreUpcomingEventsButtonActive(bool isActive);
 103
 104    /// <summary>
 105    /// Set the going events component with a list of events.
 106    /// </summary>
 107    /// <param name="events">List of events (model) to be loaded.</param>
 108    void SetGoingEvents(List<EventCardComponentModel> events);
 109
 110    /// <summary>
 111    /// Set the going events component in loading mode.
 112    /// </summary>
 113    /// <param name="isVisible">True for activating the loading mode.</param>
 114    void SetGoingEventsAsLoading(bool isVisible);
 115
 116    /// <summary>
 117    /// Shows the Event Card modal with the provided information.
 118    /// </summary>
 119    /// <param name="eventInfo">Event (model) to be loaded in the card.</param>
 120    void ShowEventModal(EventCardComponentModel eventInfo);
 121
 122    /// <summary>
 123    /// Hides the Event Card modal.
 124    /// </summary>
 125    void HideEventModal();
 126
 127    /// <summary>
 128    /// Set the current scroll view position to 1.
 129    /// </summary>
 130    void RestartScrollViewPosition();
 131}
 132
 133public class EventsSubSectionComponentView : BaseComponentView, IEventsSubSectionComponentView
 134{
 135    internal const string FEATURED_EVENT_CARDS_POOL_NAME = "Events_FeaturedEventCardsPool";
 136    internal const string TRENDING_EVENT_CARDS_POOL_NAME = "Events_TrendingEventCardsPool";
 137    internal const string UPCOMING_EVENT_CARDS_POOL_NAME = "Events_UpcomingEventCardsPool";
 138    internal const string GOING_EVENT_CARDS_POOL_NAME = "Events_FeatureGoingEventCardsPool";
 139
 140    [Header("Assets References")]
 141    [SerializeField] internal EventCardComponentView eventCardPrefab;
 142    [SerializeField] internal EventCardComponentView eventCardLongPrefab;
 143    [SerializeField] internal EventCardComponentView eventCardModalPrefab;
 144
 145    [Header("Prefab References")]
 146    [SerializeField] internal ScrollRect scrollView;
 147    [SerializeField] internal CarouselComponentView featuredEvents;
 148    [SerializeField] internal GameObject featuredEventsLoading;
 149    [SerializeField] internal GridContainerComponentView trendingEvents;
 150    [SerializeField] internal GameObject trendingEventsLoading;
 151    [SerializeField] internal TMP_Text trendingEventsNoDataText;
 152    [SerializeField] internal GridContainerComponentView upcomingEvents;
 153    [SerializeField] internal GameObject upcomingEventsLoading;
 154    [SerializeField] internal TMP_Text upcomingEventsNoDataText;
 155    [SerializeField] internal GridContainerComponentView goingEvents;
 156    [SerializeField] internal GameObject goingEventsLoading;
 157    [SerializeField] internal TMP_Text goingEventsNoDataText;
 158    [SerializeField] internal GameObject showMoreUpcomingEventsButtonContainer;
 159    [SerializeField] internal ButtonComponentView showMoreUpcomingEventsButton;
 160
 161    public event Action OnReady;
 162    public event Action<EventCardComponentModel> OnInfoClicked;
 163    public event Action<EventFromAPIModel> OnJumpInClicked;
 164    public event Action<string> OnSubscribeEventClicked;
 165    public event Action<string> OnUnsubscribeEventClicked;
 166    public event Action OnShowMoreUpcomingEventsClicked;
 167    public event Action OnEventsSubSectionEnable;
 168
 169    internal EventCardComponentView eventModal;
 170    internal Pool featuredEventCardsPool;
 171    internal Pool trendingEventCardsPool;
 172    internal Pool upcomingEventCardsPool;
 173    internal Pool goingEventCardsPool;
 174
 0175    public int currentUpcomingEventsPerRow => upcomingEvents.currentItemsPerRow;
 176
 24177    public override void OnEnable() { OnEventsSubSectionEnable?.Invoke(); }
 178
 179    public override void Start()
 180    {
 22181        eventModal = ExploreEventsHelpers.ConfigureEventCardModal(eventCardModalPrefab);
 22182        ExploreEventsHelpers.ConfigureEventCardsPool(out featuredEventCardsPool, FEATURED_EVENT_CARDS_POOL_NAME, eventCa
 22183        ExploreEventsHelpers.ConfigureEventCardsPool(out trendingEventCardsPool, TRENDING_EVENT_CARDS_POOL_NAME, eventCa
 22184        ExploreEventsHelpers.ConfigureEventCardsPool(out upcomingEventCardsPool, UPCOMING_EVENT_CARDS_POOL_NAME, eventCa
 22185        ExploreEventsHelpers.ConfigureEventCardsPool(out goingEventCardsPool, GOING_EVENT_CARDS_POOL_NAME, eventCardPref
 186
 22187        featuredEvents.RemoveItems();
 22188        trendingEvents.RemoveItems();
 22189        upcomingEvents.RemoveItems();
 22190        goingEvents.RemoveItems();
 191
 22192        showMoreUpcomingEventsButton.onClick.RemoveAllListeners();
 22193        showMoreUpcomingEventsButton.onClick.AddListener(() => OnShowMoreUpcomingEventsClicked?.Invoke());
 194
 22195        OnReady?.Invoke();
 0196    }
 197
 198    public override void RefreshControl()
 199    {
 0200        featuredEvents.RefreshControl();
 0201        trendingEvents.RefreshControl();
 0202        upcomingEvents.RefreshControl();
 0203        goingEvents.RefreshControl();
 0204    }
 205
 206    public override void Dispose()
 207    {
 107208        base.Dispose();
 209
 107210        showMoreUpcomingEventsButton.onClick.RemoveAllListeners();
 211
 107212        featuredEvents.Dispose();
 107213        upcomingEvents.Dispose();
 107214        trendingEvents.Dispose();
 107215        goingEvents.Dispose();
 216
 107217        if (eventModal != null)
 218        {
 30219            eventModal.Dispose();
 30220            Destroy(eventModal.gameObject);
 221        }
 107222    }
 223
 224    public void SetFeaturedEvents(List<EventCardComponentModel> events)
 225    {
 1226        featuredEvents.ExtractItems();
 1227        featuredEventCardsPool.ReleaseAll();
 228
 1229        List<BaseComponentView> eventComponentsToAdd = ExploreEventsHelpers.InstantiateAndConfigureEventCards(
 230            events,
 231            featuredEventCardsPool,
 232            OnInfoClicked,
 233            OnJumpInClicked,
 234            OnSubscribeEventClicked,
 235            OnUnsubscribeEventClicked);
 236
 1237        featuredEvents.SetItems(eventComponentsToAdd);
 1238        SetFeaturedEventsActive(events.Count > 0);
 1239    }
 240
 241    public void SetFeaturedEventsAsLoading(bool isVisible)
 242    {
 2243        SetFeaturedEventsActive(!isVisible);
 2244        featuredEventsLoading.SetActive(isVisible);
 2245    }
 246
 10247    public void SetFeaturedEventsActive(bool isActive) { featuredEvents.gameObject.SetActive(isActive); }
 248
 249    public void SetTrendingEvents(List<EventCardComponentModel> events)
 250    {
 1251        trendingEvents.ExtractItems();
 1252        trendingEventCardsPool.ReleaseAll();
 253
 1254        List<BaseComponentView> eventComponentsToAdd = ExploreEventsHelpers.InstantiateAndConfigureEventCards(
 255            events,
 256            trendingEventCardsPool,
 257            OnInfoClicked,
 258            OnJumpInClicked,
 259            OnSubscribeEventClicked,
 260            OnUnsubscribeEventClicked);
 261
 1262        trendingEvents.SetItems(eventComponentsToAdd);
 1263        trendingEventsNoDataText.gameObject.SetActive(events.Count == 0);
 1264    }
 265
 266    public void SetTrendingEventsAsLoading(bool isVisible)
 267    {
 2268        trendingEvents.gameObject.SetActive(!isVisible);
 2269        trendingEventsLoading.SetActive(isVisible);
 270
 2271        if (isVisible)
 1272            trendingEventsNoDataText.gameObject.SetActive(false);
 2273    }
 274
 275    public void SetUpcomingEvents(List<EventCardComponentModel> events)
 276    {
 1277        upcomingEvents.ExtractItems();
 1278        upcomingEventCardsPool.ReleaseAll();
 279
 1280        List<BaseComponentView> eventComponentsToAdd = ExploreEventsHelpers.InstantiateAndConfigureEventCards(
 281            events,
 282            upcomingEventCardsPool,
 283            OnInfoClicked,
 284            OnJumpInClicked,
 285            OnSubscribeEventClicked,
 286            OnUnsubscribeEventClicked);
 287
 1288        upcomingEvents.SetItems(eventComponentsToAdd);
 1289        upcomingEventsNoDataText.gameObject.SetActive(events.Count == 0);
 1290    }
 291
 292    public void AddUpcomingEvents(List<EventCardComponentModel> events)
 293    {
 1294        List<BaseComponentView> eventComponentsToAdd = ExploreEventsHelpers.InstantiateAndConfigureEventCards(
 295            events,
 296            upcomingEventCardsPool,
 297            OnInfoClicked,
 298            OnJumpInClicked,
 299            OnSubscribeEventClicked,
 300            OnUnsubscribeEventClicked);
 301
 6302        foreach (var eventToAdd in eventComponentsToAdd)
 303        {
 2304            upcomingEvents.AddItem(eventToAdd);
 305        }
 1306    }
 307
 308    public void SetUpcomingEventsAsLoading(bool isVisible)
 309    {
 2310        upcomingEvents.gameObject.SetActive(!isVisible);
 2311        upcomingEventsLoading.SetActive(isVisible);
 312
 2313        if (isVisible)
 1314            upcomingEventsNoDataText.gameObject.SetActive(false);
 2315    }
 316
 317    public void SetGoingEvents(List<EventCardComponentModel> events)
 318    {
 1319        goingEvents.ExtractItems();
 1320        goingEventCardsPool.ReleaseAll();
 321
 1322        List<BaseComponentView> eventComponentsToAdd = ExploreEventsHelpers.InstantiateAndConfigureEventCards(
 323            events,
 324            goingEventCardsPool,
 325            OnInfoClicked,
 326            OnJumpInClicked,
 327            OnSubscribeEventClicked,
 328            OnUnsubscribeEventClicked);
 329
 1330        goingEvents.SetItems(eventComponentsToAdd);
 1331        goingEventsNoDataText.gameObject.SetActive(events.Count == 0);
 1332    }
 333
 334    public void SetGoingEventsAsLoading(bool isVisible)
 335    {
 2336        goingEvents.gameObject.SetActive(!isVisible);
 2337        goingEventsLoading.SetActive(isVisible);
 338
 2339        if (isVisible)
 1340            goingEventsNoDataText.gameObject.SetActive(false);
 2341    }
 342
 343    public void ShowEventModal(EventCardComponentModel eventInfo)
 344    {
 1345        eventModal.Show();
 1346        ExploreEventsHelpers.ConfigureEventCard(eventModal, eventInfo, OnInfoClicked, OnJumpInClicked, OnSubscribeEventC
 1347    }
 348
 2349    public void HideEventModal() { eventModal.Hide(); }
 350
 0351    public void RestartScrollViewPosition() { scrollView.verticalNormalizedPosition = 1; }
 352
 4353    public void SetShowMoreUpcomingEventsButtonActive(bool isActive) { showMoreUpcomingEventsButtonContainer.gameObject.
 354}