< 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:76
Uncovered lines:8
Coverable lines:84
Total lines:367
Line coverage:90.4% (76 of 84)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
OnEnable()0%2.52050%
ConfigurePools()0%110100%
Start()0%2.012088.89%
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    /// <summary>
 133    /// Configure the needed pools for the events instantiation.
 134    /// </summary>
 135    void ConfigurePools();
 136}
 137
 138public class EventsSubSectionComponentView : BaseComponentView, IEventsSubSectionComponentView
 139{
 140    internal const string FEATURED_EVENT_CARDS_POOL_NAME = "Events_FeaturedEventCardsPool";
 141    internal const int FEATURED_EVENT_CARDS_POOL_PREWARM = 10;
 142    internal const string TRENDING_EVENT_CARDS_POOL_NAME = "Events_TrendingEventCardsPool";
 143    internal const int TRENDING_EVENT_CARDS_POOL_PREWARM = 12;
 144    internal const string UPCOMING_EVENT_CARDS_POOL_NAME = "Events_UpcomingEventCardsPool";
 145    internal const int UPCOMING_EVENT_CARDS_POOL_PREWARM = 9;
 146    internal const string GOING_EVENT_CARDS_POOL_NAME = "Events_FeatureGoingEventCardsPool";
 147    internal const int GOING_EVENT_CARDS_POOL_PREWARM = 9;
 148
 149    [Header("Assets References")]
 150    [SerializeField] internal EventCardComponentView eventCardPrefab;
 151    [SerializeField] internal EventCardComponentView eventCardLongPrefab;
 152    [SerializeField] internal EventCardComponentView eventCardModalPrefab;
 153
 154    [Header("Prefab References")]
 155    [SerializeField] internal ScrollRect scrollView;
 156    [SerializeField] internal CarouselComponentView featuredEvents;
 157    [SerializeField] internal GameObject featuredEventsLoading;
 158    [SerializeField] internal GridContainerComponentView trendingEvents;
 159    [SerializeField] internal GameObject trendingEventsLoading;
 160    [SerializeField] internal TMP_Text trendingEventsNoDataText;
 161    [SerializeField] internal GridContainerComponentView upcomingEvents;
 162    [SerializeField] internal GameObject upcomingEventsLoading;
 163    [SerializeField] internal TMP_Text upcomingEventsNoDataText;
 164    [SerializeField] internal GridContainerComponentView goingEvents;
 165    [SerializeField] internal GameObject goingEventsLoading;
 166    [SerializeField] internal TMP_Text goingEventsNoDataText;
 167    [SerializeField] internal GameObject showMoreUpcomingEventsButtonContainer;
 168    [SerializeField] internal ButtonComponentView showMoreUpcomingEventsButton;
 169
 170    public event Action OnReady;
 171    public event Action<EventCardComponentModel> OnInfoClicked;
 172    public event Action<EventFromAPIModel> OnJumpInClicked;
 173    public event Action<string> OnSubscribeEventClicked;
 174    public event Action<string> OnUnsubscribeEventClicked;
 175    public event Action OnShowMoreUpcomingEventsClicked;
 176    public event Action OnEventsSubSectionEnable;
 177
 178    internal EventCardComponentView eventModal;
 179    internal Pool featuredEventCardsPool;
 180    internal Pool trendingEventCardsPool;
 181    internal Pool upcomingEventCardsPool;
 182    internal Pool goingEventCardsPool;
 183
 0184    public int currentUpcomingEventsPerRow => upcomingEvents.currentItemsPerRow;
 185
 24186    public override void OnEnable() { OnEventsSubSectionEnable?.Invoke(); }
 187
 188    public void ConfigurePools()
 189    {
 22190        ExploreEventsUtils.ConfigureEventCardsPool(out featuredEventCardsPool, FEATURED_EVENT_CARDS_POOL_NAME, eventCard
 22191        ExploreEventsUtils.ConfigureEventCardsPool(out trendingEventCardsPool, TRENDING_EVENT_CARDS_POOL_NAME, eventCard
 22192        ExploreEventsUtils.ConfigureEventCardsPool(out upcomingEventCardsPool, UPCOMING_EVENT_CARDS_POOL_NAME, eventCard
 22193        ExploreEventsUtils.ConfigureEventCardsPool(out goingEventCardsPool, GOING_EVENT_CARDS_POOL_NAME, eventCardPrefab
 22194    }
 195
 196    public override void Start()
 197    {
 22198        eventModal = ExploreEventsUtils.ConfigureEventCardModal(eventCardModalPrefab);
 199
 22200        featuredEvents.RemoveItems();
 22201        trendingEvents.RemoveItems();
 22202        upcomingEvents.RemoveItems();
 22203        goingEvents.RemoveItems();
 204
 22205        showMoreUpcomingEventsButton.onClick.RemoveAllListeners();
 22206        showMoreUpcomingEventsButton.onClick.AddListener(() => OnShowMoreUpcomingEventsClicked?.Invoke());
 207
 22208        OnReady?.Invoke();
 0209    }
 210
 211    public override void RefreshControl()
 212    {
 0213        featuredEvents.RefreshControl();
 0214        trendingEvents.RefreshControl();
 0215        upcomingEvents.RefreshControl();
 0216        goingEvents.RefreshControl();
 0217    }
 218
 219    public override void Dispose()
 220    {
 69221        base.Dispose();
 222
 69223        showMoreUpcomingEventsButton.onClick.RemoveAllListeners();
 224
 69225        featuredEvents.Dispose();
 69226        upcomingEvents.Dispose();
 69227        trendingEvents.Dispose();
 69228        goingEvents.Dispose();
 229
 69230        if (eventModal != null)
 231        {
 30232            eventModal.Dispose();
 30233            Destroy(eventModal.gameObject);
 234        }
 69235    }
 236
 237    public void SetFeaturedEvents(List<EventCardComponentModel> events)
 238    {
 1239        featuredEvents.ExtractItems();
 1240        featuredEventCardsPool.ReleaseAll();
 241
 1242        List<BaseComponentView> eventComponentsToAdd = ExploreEventsUtils.InstantiateAndConfigureEventCards(
 243            events,
 244            featuredEventCardsPool,
 245            OnInfoClicked,
 246            OnJumpInClicked,
 247            OnSubscribeEventClicked,
 248            OnUnsubscribeEventClicked);
 249
 1250        featuredEvents.SetItems(eventComponentsToAdd);
 1251        SetFeaturedEventsActive(events.Count > 0);
 1252    }
 253
 254    public void SetFeaturedEventsAsLoading(bool isVisible)
 255    {
 2256        SetFeaturedEventsActive(!isVisible);
 2257        featuredEventsLoading.SetActive(isVisible);
 2258    }
 259
 10260    public void SetFeaturedEventsActive(bool isActive) { featuredEvents.gameObject.SetActive(isActive); }
 261
 262    public void SetTrendingEvents(List<EventCardComponentModel> events)
 263    {
 1264        trendingEvents.ExtractItems();
 1265        trendingEventCardsPool.ReleaseAll();
 266
 1267        List<BaseComponentView> eventComponentsToAdd = ExploreEventsUtils.InstantiateAndConfigureEventCards(
 268            events,
 269            trendingEventCardsPool,
 270            OnInfoClicked,
 271            OnJumpInClicked,
 272            OnSubscribeEventClicked,
 273            OnUnsubscribeEventClicked);
 274
 1275        trendingEvents.SetItems(eventComponentsToAdd);
 1276        trendingEventsNoDataText.gameObject.SetActive(events.Count == 0);
 1277    }
 278
 279    public void SetTrendingEventsAsLoading(bool isVisible)
 280    {
 2281        trendingEvents.gameObject.SetActive(!isVisible);
 2282        trendingEventsLoading.SetActive(isVisible);
 283
 2284        if (isVisible)
 1285            trendingEventsNoDataText.gameObject.SetActive(false);
 2286    }
 287
 288    public void SetUpcomingEvents(List<EventCardComponentModel> events)
 289    {
 1290        upcomingEvents.ExtractItems();
 1291        upcomingEventCardsPool.ReleaseAll();
 292
 1293        List<BaseComponentView> eventComponentsToAdd = ExploreEventsUtils.InstantiateAndConfigureEventCards(
 294            events,
 295            upcomingEventCardsPool,
 296            OnInfoClicked,
 297            OnJumpInClicked,
 298            OnSubscribeEventClicked,
 299            OnUnsubscribeEventClicked);
 300
 1301        upcomingEvents.SetItems(eventComponentsToAdd);
 1302        upcomingEventsNoDataText.gameObject.SetActive(events.Count == 0);
 1303    }
 304
 305    public void AddUpcomingEvents(List<EventCardComponentModel> events)
 306    {
 1307        List<BaseComponentView> eventComponentsToAdd = ExploreEventsUtils.InstantiateAndConfigureEventCards(
 308            events,
 309            upcomingEventCardsPool,
 310            OnInfoClicked,
 311            OnJumpInClicked,
 312            OnSubscribeEventClicked,
 313            OnUnsubscribeEventClicked);
 314
 6315        foreach (var eventToAdd in eventComponentsToAdd)
 316        {
 2317            upcomingEvents.AddItem(eventToAdd);
 318        }
 1319    }
 320
 321    public void SetUpcomingEventsAsLoading(bool isVisible)
 322    {
 2323        upcomingEvents.gameObject.SetActive(!isVisible);
 2324        upcomingEventsLoading.SetActive(isVisible);
 325
 2326        if (isVisible)
 1327            upcomingEventsNoDataText.gameObject.SetActive(false);
 2328    }
 329
 330    public void SetGoingEvents(List<EventCardComponentModel> events)
 331    {
 1332        goingEvents.ExtractItems();
 1333        goingEventCardsPool.ReleaseAll();
 334
 1335        List<BaseComponentView> eventComponentsToAdd = ExploreEventsUtils.InstantiateAndConfigureEventCards(
 336            events,
 337            goingEventCardsPool,
 338            OnInfoClicked,
 339            OnJumpInClicked,
 340            OnSubscribeEventClicked,
 341            OnUnsubscribeEventClicked);
 342
 1343        goingEvents.SetItems(eventComponentsToAdd);
 1344        goingEventsNoDataText.gameObject.SetActive(events.Count == 0);
 1345    }
 346
 347    public void SetGoingEventsAsLoading(bool isVisible)
 348    {
 2349        goingEvents.gameObject.SetActive(!isVisible);
 2350        goingEventsLoading.SetActive(isVisible);
 351
 2352        if (isVisible)
 1353            goingEventsNoDataText.gameObject.SetActive(false);
 2354    }
 355
 356    public void ShowEventModal(EventCardComponentModel eventInfo)
 357    {
 1358        eventModal.Show();
 1359        ExploreEventsUtils.ConfigureEventCard(eventModal, eventInfo, OnInfoClicked, OnJumpInClicked, OnSubscribeEventCli
 1360    }
 361
 2362    public void HideEventModal() { eventModal.Hide(); }
 363
 0364    public void RestartScrollViewPosition() { scrollView.verticalNormalizedPosition = 1; }
 365
 4366    public void SetShowMoreUpcomingEventsButtonActive(bool isActive) { showMoreUpcomingEventsButtonContainer.gameObject.
 367}