< 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:98
Uncovered lines:8
Coverable lines:106
Total lines:360
Line coverage:92.4% (98 of 106)
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%
ConfigureEventCardModal()0%110100%
ConfigureEventCardsPool(...)0%220100%
InstantiateAndConfigureEventCards(...)0%220100%
ConfigureEventCard(...)0%990100%

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 = "FeaturedEventCardsPool";
 136    internal const string TRENDING_EVENT_CARDS_POOL_NAME = "TrendingEventCardsPool";
 137    internal const string UPCOMING_EVENT_CARDS_POOL_NAME = "UpcomingEventCardsPool";
 138    internal const string GOING_EVENT_CARDS_POOL_NAME = "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
 31177    public override void OnEnable() { OnEventsSubSectionEnable?.Invoke(); }
 178
 179    public override void Start()
 180    {
 25181        ConfigureEventCardModal();
 25182        ConfigureEventCardsPool(out featuredEventCardsPool, FEATURED_EVENT_CARDS_POOL_NAME, eventCardLongPrefab, 10);
 25183        ConfigureEventCardsPool(out trendingEventCardsPool, TRENDING_EVENT_CARDS_POOL_NAME, eventCardPrefab, 100);
 25184        ConfigureEventCardsPool(out upcomingEventCardsPool, UPCOMING_EVENT_CARDS_POOL_NAME, eventCardPrefab, 100);
 25185        ConfigureEventCardsPool(out goingEventCardsPool, GOING_EVENT_CARDS_POOL_NAME, eventCardPrefab, 100);
 186
 25187        featuredEvents.RemoveItems();
 25188        trendingEvents.RemoveItems();
 25189        upcomingEvents.RemoveItems();
 25190        goingEvents.RemoveItems();
 191
 25192        showMoreUpcomingEventsButton.onClick.RemoveAllListeners();
 25193        showMoreUpcomingEventsButton.onClick.AddListener(() => OnShowMoreUpcomingEventsClicked?.Invoke());
 194
 25195        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    {
 63208        base.Dispose();
 209
 63210        showMoreUpcomingEventsButton.onClick.RemoveAllListeners();
 211
 63212        featuredEvents.Dispose();
 63213        upcomingEvents.Dispose();
 63214        trendingEvents.Dispose();
 63215        goingEvents.Dispose();
 216
 63217        if (eventModal != null)
 218        {
 27219            eventModal.Dispose();
 27220            Destroy(eventModal.gameObject);
 221        }
 63222    }
 223
 224    public void SetFeaturedEvents(List<EventCardComponentModel> events)
 225    {
 1226        featuredEvents.ExtractItems();
 1227        featuredEventCardsPool.ReleaseAll();
 1228        List<BaseComponentView> eventComponentsToAdd = InstantiateAndConfigureEventCards(events, featuredEventCardsPool)
 1229        featuredEvents.SetItems(eventComponentsToAdd);
 1230        SetFeaturedEventsActive(events.Count > 0);
 1231    }
 232    public void SetFeaturedEventsAsLoading(bool isVisible)
 233    {
 2234        SetFeaturedEventsActive(!isVisible);
 2235        featuredEventsLoading.SetActive(isVisible);
 2236    }
 237
 10238    public void SetFeaturedEventsActive(bool isActive) { featuredEvents.gameObject.SetActive(isActive); }
 239
 240    public void SetTrendingEvents(List<EventCardComponentModel> events)
 241    {
 1242        trendingEvents.ExtractItems();
 1243        trendingEventCardsPool.ReleaseAll();
 1244        List<BaseComponentView> eventComponentsToAdd = InstantiateAndConfigureEventCards(events, trendingEventCardsPool)
 1245        trendingEvents.SetItems(eventComponentsToAdd);
 1246        trendingEventsNoDataText.gameObject.SetActive(events.Count == 0);
 1247    }
 248
 249    public void SetTrendingEventsAsLoading(bool isVisible)
 250    {
 2251        trendingEvents.gameObject.SetActive(!isVisible);
 2252        trendingEventsLoading.SetActive(isVisible);
 253
 2254        if (isVisible)
 1255            trendingEventsNoDataText.gameObject.SetActive(false);
 2256    }
 257
 258    public void SetUpcomingEvents(List<EventCardComponentModel> events)
 259    {
 1260        upcomingEvents.ExtractItems();
 1261        upcomingEventCardsPool.ReleaseAll();
 1262        List<BaseComponentView> eventComponentsToAdd = InstantiateAndConfigureEventCards(events, upcomingEventCardsPool)
 1263        upcomingEvents.SetItems(eventComponentsToAdd);
 1264        upcomingEventsNoDataText.gameObject.SetActive(events.Count == 0);
 1265    }
 266
 267    public void AddUpcomingEvents(List<EventCardComponentModel> events)
 268    {
 1269        List<BaseComponentView> eventComponentsToAdd = InstantiateAndConfigureEventCards(events, upcomingEventCardsPool)
 6270        foreach (var eventToAdd in eventComponentsToAdd)
 271        {
 2272            upcomingEvents.AddItem(eventToAdd);
 273        }
 1274    }
 275
 276    public void SetUpcomingEventsAsLoading(bool isVisible)
 277    {
 2278        upcomingEvents.gameObject.SetActive(!isVisible);
 2279        upcomingEventsLoading.SetActive(isVisible);
 280
 2281        if (isVisible)
 1282            upcomingEventsNoDataText.gameObject.SetActive(false);
 2283    }
 284
 285    public void SetGoingEvents(List<EventCardComponentModel> events)
 286    {
 1287        goingEvents.ExtractItems();
 1288        goingEventCardsPool.ReleaseAll();
 1289        List<BaseComponentView> eventComponentsToAdd = InstantiateAndConfigureEventCards(events, goingEventCardsPool);
 1290        goingEvents.SetItems(eventComponentsToAdd);
 1291        goingEventsNoDataText.gameObject.SetActive(events.Count == 0);
 1292    }
 293
 294    public void SetGoingEventsAsLoading(bool isVisible)
 295    {
 2296        goingEvents.gameObject.SetActive(!isVisible);
 2297        goingEventsLoading.SetActive(isVisible);
 298
 2299        if (isVisible)
 1300            goingEventsNoDataText.gameObject.SetActive(false);
 2301    }
 302
 303    public void ShowEventModal(EventCardComponentModel eventInfo)
 304    {
 1305        eventModal.Show();
 1306        ConfigureEventCard(eventModal, eventInfo);
 1307    }
 308
 2309    public void HideEventModal() { eventModal.Hide(); }
 310
 0311    public void RestartScrollViewPosition() { scrollView.verticalNormalizedPosition = 1; }
 312
 4313    public void SetShowMoreUpcomingEventsButtonActive(bool isActive) { showMoreUpcomingEventsButtonContainer.gameObject.
 314
 315    internal void ConfigureEventCardModal()
 316    {
 26317        eventModal = GameObject.Instantiate(eventCardModalPrefab);
 26318        eventModal.Hide(true);
 26319    }
 320
 321    internal void ConfigureEventCardsPool(out Pool pool, string poolName, EventCardComponentView eventCardPrefab, int ma
 322    {
 104323        pool = PoolManager.i.GetPool(poolName);
 104324        if (pool == null)
 325        {
 4326            pool = PoolManager.i.AddPool(
 327                poolName,
 328                Instantiate(eventCardPrefab).gameObject,
 329                maxPrewarmCount: maxPrewarmCount,
 330                isPersistent: true);
 331        }
 104332    }
 333
 334    internal List<BaseComponentView> InstantiateAndConfigureEventCards(List<EventCardComponentModel> events, Pool pool)
 335    {
 5336        List<BaseComponentView> instantiatedEvents = new List<BaseComponentView>();
 337
 30338        foreach (EventCardComponentModel eventInfo in events)
 339        {
 10340            EventCardComponentView eventGO = pool.Get().gameObject.GetComponent<EventCardComponentView>();
 10341            ConfigureEventCard(eventGO, eventInfo);
 10342            instantiatedEvents.Add(eventGO);
 343        }
 344
 5345        return instantiatedEvents;
 346    }
 347
 348    internal void ConfigureEventCard(EventCardComponentView eventCard, EventCardComponentModel eventInfo)
 349    {
 11350        eventCard.Configure(eventInfo);
 11351        eventCard.onInfoClick?.RemoveAllListeners();
 11352        eventCard.onInfoClick?.AddListener(() => OnInfoClicked?.Invoke(eventInfo));
 11353        eventCard.onJumpInClick?.RemoveAllListeners();
 11354        eventCard.onJumpInClick?.AddListener(() => OnJumpInClicked?.Invoke(eventInfo.eventFromAPIInfo));
 11355        eventCard.onSubscribeClick?.RemoveAllListeners();
 11356        eventCard.onSubscribeClick?.AddListener(() => OnSubscribeEventClicked?.Invoke(eventInfo.eventId));
 11357        eventCard.onUnsubscribeClick?.RemoveAllListeners();
 11358        eventCard.onUnsubscribeClick?.AddListener(() => OnUnsubscribeEventClicked?.Invoke(eventInfo.eventId));
 11359    }
 360}