< 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:84
Uncovered lines:31
Coverable lines:115
Total lines:284
Line coverage:73% (84 of 115)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
EventsSubSectionComponentView()0%110100%
SetAllAsLoading()0%2100%
SetShowMoreButtonActive(...)0%2100%
Awake()0%110100%
Start()0%2.012088.89%
OnEnable()0%2.52050%
Dispose()0%220100%
SetActive(...)0%220100%
ConfigurePools()0%110100%
RefreshControl()0%2100%
SetAllEventGroupsAsLoading()0%2100%
SetFeaturedEventsGroupAsLoading()0%110100%
SetEventsGroupAsLoading(...)0%110100%
SetShowMoreUpcomingEventsButtonActive(...)0%110100%
ShowEventModal(...)0%110100%
HideEventModal()0%220100%
RestartScrollViewPosition()0%2100%
SetTrendingEvents(...)0%110100%
SetGoingEvents(...)0%110100%
SetUpcomingEvents(...)0%110100%
SetEvents(...)0%110100%
AddUpcomingEvents(...)0%110100%
SetEventsAsync()0%6.976070%
SetFeaturedEvents(...)0%110100%
SetFeaturedEventsAsync()0%7.736063.64%
UpdateCardsVisual()0%220100%
<UpdateCardsVisual()0%14.957045.45%

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 System.Threading;
 5using Cysharp.Threading.Tasks;
 6using TMPro;
 7using UnityEngine;
 8using UnityEngine.UI;
 9
 10public class EventsSubSectionComponentView : BaseComponentView, IEventsSubSectionComponentView
 11{
 12    internal const string FEATURED_EVENT_CARDS_POOL_NAME = "Events_FeaturedEventCardsPool";
 13    private const int FEATURED_EVENT_CARDS_POOL_PREWARM = 10;
 14    private const string TRENDING_EVENT_CARDS_POOL_NAME = "Events_TrendingEventCardsPool";
 15    private const int TRENDING_EVENT_CARDS_POOL_PREWARM = 12;
 16    private const string UPCOMING_EVENT_CARDS_POOL_NAME = "Events_UpcomingEventCardsPool";
 17    private const int UPCOMING_EVENT_CARDS_POOL_PREWARM = 9;
 18    private const string GOING_EVENT_CARDS_POOL_NAME = "Events_FeatureGoingEventCardsPool";
 19    private const int GOING_EVENT_CARDS_POOL_PREWARM = 9;
 20
 6221    private readonly Queue<Func<UniTask>> cardsVisualUpdateBuffer = new Queue<Func<UniTask>>();
 6222    private readonly Queue<Func<UniTask>> poolsPrewarmAsyncsBuffer = new Queue<Func<UniTask>>();
 6223    private readonly CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
 24
 25    [Header("Assets References")]
 26    [SerializeField] internal EventCardComponentView eventCardPrefab;
 27    [SerializeField] internal EventCardComponentView eventCardLongPrefab;
 28    [SerializeField] internal EventCardComponentView eventCardModalPrefab;
 29
 30    [Header("Prefab References")]
 31    [SerializeField] internal ScrollRect scrollView;
 32    [SerializeField] internal CarouselComponentView featuredEvents;
 33    [SerializeField] internal GameObject featuredEventsLoading;
 34    [SerializeField] internal GridContainerComponentView trendingEvents;
 35    [SerializeField] internal GameObject trendingEventsLoading;
 36    [SerializeField] internal TMP_Text trendingEventsNoDataText;
 37    [SerializeField] internal GridContainerComponentView upcomingEvents;
 38    [SerializeField] internal GameObject upcomingEventsLoading;
 39    [SerializeField] internal TMP_Text upcomingEventsNoDataText;
 40    [SerializeField] internal GridContainerComponentView goingEvents;
 41    [SerializeField] internal GameObject goingEventsLoading;
 42    [SerializeField] internal TMP_Text goingEventsNoDataText;
 43    [SerializeField] internal GameObject showMoreUpcomingEventsButtonContainer;
 44    [SerializeField] internal ButtonComponentView showMoreUpcomingEventsButton;
 45
 46    [SerializeField] private Canvas canvas;
 47
 48    internal Pool featuredEventCardsPool;
 49    internal Pool trendingEventCardsPool;
 50    internal Pool upcomingEventCardsPool;
 51    internal Pool goingEventCardsPool;
 52
 53    internal EventCardComponentView eventModal;
 54
 55    private Canvas trendingEventsCanvas;
 56    private Canvas upcomingEventsCanvas;
 57    private Canvas goingEventsCanvas;
 58
 59    private bool isUpdatingCardsVisual;
 60
 061    public int currentUpcomingEventsPerRow => upcomingEvents.currentItemsPerRow;
 62
 63
 064    public void SetAllAsLoading() => SetAllEventGroupsAsLoading();
 65
 066    public void SetShowMoreButtonActive(bool isActive) => SetShowMoreUpcomingEventsButtonActive(isActive);
 67
 068    public int CurrentTilesPerRow => currentUpcomingEventsPerRow;
 69
 70    public event Action OnReady;
 71    public event Action<EventCardComponentModel> OnInfoClicked;
 72    public event Action<EventFromAPIModel> OnJumpInClicked;
 73    public event Action<string> OnSubscribeEventClicked;
 74    public event Action<string> OnUnsubscribeEventClicked;
 75    public event Action OnShowMoreUpcomingEventsClicked;
 76    public event Action OnEventsSubSectionEnable;
 77
 78    public override void Awake()
 79    {
 5980        base.Awake();
 5981        trendingEventsCanvas = trendingEvents.GetComponent<Canvas>();
 5982        upcomingEventsCanvas = upcomingEvents.GetComponent<Canvas>();
 5983        goingEventsCanvas = goingEvents.GetComponent<Canvas>();
 5984    }
 85
 86    public override void Start()
 87    {
 5288        eventModal = PlacesAndEventsCardsFactory.GetEventCardTemplateHiddenLazy(eventCardModalPrefab);
 89
 5290        featuredEvents.RemoveItems();
 5291        trendingEvents.RemoveItems();
 5292        upcomingEvents.RemoveItems();
 5293        goingEvents.RemoveItems();
 94
 5295        showMoreUpcomingEventsButton.onClick.RemoveAllListeners();
 5296        showMoreUpcomingEventsButton.onClick.AddListener(() => OnShowMoreUpcomingEventsClicked?.Invoke());
 97
 5298        OnReady?.Invoke();
 099    }
 100
 101    public override void OnEnable()
 102    {
 62103        OnEventsSubSectionEnable?.Invoke();
 0104    }
 105
 106    public override void Dispose()
 107    {
 129108        base.Dispose();
 129109        cancellationTokenSource.Cancel();
 110
 129111        showMoreUpcomingEventsButton.onClick.RemoveAllListeners();
 112
 129113        featuredEvents.Dispose();
 129114        upcomingEvents.Dispose();
 129115        trendingEvents.Dispose();
 129116        goingEvents.Dispose();
 117
 129118        if (eventModal != null)
 119        {
 78120            eventModal.Dispose();
 78121            Destroy(eventModal.gameObject);
 122        }
 129123    }
 124
 125    public void SetActive(bool isActive)
 126    {
 89127        canvas.enabled = isActive;
 128
 89129        if (isActive)
 3130            OnEnable();
 131        else
 86132            OnDisable();
 86133    }
 134
 135    public void ConfigurePools()
 136    {
 19137        featuredEventCardsPool = PlacesAndEventsCardsFactory.GetCardsPoolLazy(FEATURED_EVENT_CARDS_POOL_NAME, eventCardL
 19138        trendingEventCardsPool = PlacesAndEventsCardsFactory.GetCardsPoolLazy(TRENDING_EVENT_CARDS_POOL_NAME, eventCardP
 19139        upcomingEventCardsPool = PlacesAndEventsCardsFactory.GetCardsPoolLazy(UPCOMING_EVENT_CARDS_POOL_NAME, eventCardP
 19140        goingEventCardsPool = PlacesAndEventsCardsFactory.GetCardsPoolLazy(GOING_EVENT_CARDS_POOL_NAME, eventCardPrefab,
 19141    }
 142
 143    public override void RefreshControl()
 144    {
 0145        featuredEvents.RefreshControl();
 0146        trendingEvents.RefreshControl();
 0147        upcomingEvents.RefreshControl();
 0148        goingEvents.RefreshControl();
 0149    }
 150
 151    public void SetAllEventGroupsAsLoading()
 152    {
 0153        SetFeaturedEventsGroupAsLoading();
 154
 0155        SetEventsGroupAsLoading(isVisible: true, goingEventsCanvas, goingEventsLoading);
 0156        SetEventsGroupAsLoading(isVisible: true, trendingEventsCanvas, trendingEventsLoading);
 0157        SetEventsGroupAsLoading(isVisible: true, upcomingEventsCanvas, upcomingEventsLoading);
 158
 0159        goingEventsNoDataText.gameObject.SetActive(false);
 0160        trendingEventsNoDataText.gameObject.SetActive(false);
 0161        upcomingEventsNoDataText.gameObject.SetActive(false);
 0162    }
 163
 164    internal void SetFeaturedEventsGroupAsLoading()
 165    {
 1166        featuredEvents.gameObject.SetActive(false);
 1167        featuredEventsLoading.SetActive(true);
 1168    }
 169
 170    public void SetEventsGroupAsLoading(bool isVisible, Canvas gridCanvas, GameObject loadingBar)
 171    {
 9172        gridCanvas.enabled = !isVisible;
 9173        loadingBar.SetActive(isVisible);
 9174    }
 175
 176    public void SetShowMoreUpcomingEventsButtonActive(bool isActive) =>
 2177        showMoreUpcomingEventsButtonContainer.gameObject.SetActive(isActive);
 178
 179    public void ShowEventModal(EventCardComponentModel eventInfo)
 180    {
 1181        eventModal.Show();
 1182        EventsCardsConfigurator.Configure(eventModal, eventInfo, OnInfoClicked, OnJumpInClicked, OnSubscribeEventClicked
 1183    }
 184
 185    public void HideEventModal()
 186    {
 1187        if (eventModal != null)
 1188            eventModal.Hide();
 1189    }
 190
 191    public void RestartScrollViewPosition() =>
 0192        scrollView.verticalNormalizedPosition = 1;
 193
 194    public void SetTrendingEvents(List<EventCardComponentModel> events) =>
 1195        SetEvents(events, trendingEvents, trendingEventsCanvas, trendingEventCardsPool, trendingEventsLoading, trendingE
 196
 197    public void SetGoingEvents(List<EventCardComponentModel> events) =>
 1198        SetEvents(events, goingEvents, goingEventsCanvas, goingEventCardsPool, goingEventsLoading, goingEventsNoDataText
 199
 200    public void SetUpcomingEvents(List<EventCardComponentModel> events) =>
 1201        SetEvents(events, upcomingEvents, upcomingEventsCanvas, upcomingEventCardsPool, upcomingEventsLoading, upcomingE
 202
 203    private void SetEvents(List<EventCardComponentModel> events, GridContainerComponentView eventsGrid, Canvas gridCanva
 204    {
 3205        SetEventsGroupAsLoading(false, gridCanvas, loadingBar);
 3206        eventsNoDataText.gameObject.SetActive(events.Count == 0);
 207
 3208        eventCardsPool.ReleaseAll();
 209
 3210        eventsGrid.ExtractItems();
 3211        eventsGrid.RemoveItems();
 212
 6213        cardsVisualUpdateBuffer.Enqueue(() => SetEventsAsync(events, eventsGrid, eventCardsPool, cancellationTokenSource
 3214        UpdateCardsVisual();
 3215    }
 216
 217    public void AddUpcomingEvents(List<EventCardComponentModel> events)
 218    {
 2219        cardsVisualUpdateBuffer.Enqueue(() => SetEventsAsync(events, upcomingEvents, upcomingEventCardsPool, cancellatio
 1220        UpdateCardsVisual();
 1221    }
 222
 223    private async UniTask SetEventsAsync(List<EventCardComponentModel> events, GridContainerComponentView eventsGrid, Po
 224    {
 20225        foreach (EventCardComponentModel eventInfo in events)
 226        {
 8227            eventsGrid.AddItem(
 228                PlacesAndEventsCardsFactory.CreateConfiguredEventCard(pool, eventInfo, OnInfoClicked, OnJumpInClicked, O
 229
 24230            await UniTask.NextFrame(cancellationToken);
 231        }
 232
 0233        eventsGrid.SetItemSizeForModel();
 0234        poolsPrewarmAsyncsBuffer.Enqueue(() => pool.PrewarmAsync(events.Count, cancellationToken));
 0235    }
 236
 237    public void SetFeaturedEvents(List<EventCardComponentModel> events)
 238    {
 1239        featuredEventsLoading.SetActive(false);
 1240        featuredEvents.gameObject.SetActive(events.Count > 0);
 241
 1242        featuredEventCardsPool.ReleaseAll();
 243
 1244        featuredEvents.ExtractItems();
 245
 2246        cardsVisualUpdateBuffer.Enqueue(() => SetFeaturedEventsAsync(events, cancellationTokenSource.Token));
 1247        UpdateCardsVisual();
 1248    }
 249
 250    private async UniTask SetFeaturedEventsAsync(List<EventCardComponentModel> events, CancellationToken cancellationTok
 251    {
 5252        foreach (EventCardComponentModel eventInfo in events)
 253        {
 2254            featuredEvents.AddItem(
 255                PlacesAndEventsCardsFactory.CreateConfiguredEventCard(featuredEventCardsPool, eventInfo, OnInfoClicked, 
 256
 6257            await UniTask.NextFrame(cancellationToken);
 258        }
 259
 0260        featuredEvents.SetManualControlsActive();
 0261        featuredEvents.GenerateDotsSelector();
 262
 0263        poolsPrewarmAsyncsBuffer.Enqueue(() => featuredEventCardsPool.PrewarmAsync(events.Count, cancellationToken));
 0264    }
 265
 266    private void UpdateCardsVisual()
 267    {
 5268        if (!isUpdatingCardsVisual)
 5269            ShowCardsProcess().Forget();
 270
 271        async UniTask ShowCardsProcess()
 272        {
 5273            isUpdatingCardsVisual = true;
 274
 5275            while (cardsVisualUpdateBuffer.Count > 0)
 15276                await cardsVisualUpdateBuffer.Dequeue().Invoke();
 277
 0278            while (poolsPrewarmAsyncsBuffer.Count > 0)
 0279                await poolsPrewarmAsyncsBuffer.Dequeue().Invoke();
 280
 0281            isUpdatingCardsVisual = false;
 0282        }
 5283    }
 284}