< 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:28
Coverable lines:112
Total lines:277
Line coverage:75% (84 of 112)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
EventsSubSectionComponentView()0%110100%
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
 6721    private readonly Queue<Func<UniTask>> cardsVisualUpdateBuffer = new Queue<Func<UniTask>>();
 6722    private readonly Queue<Func<UniTask>> poolsPrewarmAsyncsBuffer = new Queue<Func<UniTask>>();
 6723    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    public event Action OnReady;
 64    public event Action<EventCardComponentModel> OnInfoClicked;
 65    public event Action<EventFromAPIModel> OnJumpInClicked;
 66    public event Action<string> OnSubscribeEventClicked;
 67    public event Action<string> OnUnsubscribeEventClicked;
 68    public event Action OnShowMoreUpcomingEventsClicked;
 69    public event Action OnEventsSubSectionEnable;
 70
 71    public override void Awake()
 72    {
 6473        base.Awake();
 6474        trendingEventsCanvas = trendingEvents.GetComponent<Canvas>();
 6475        upcomingEventsCanvas = upcomingEvents.GetComponent<Canvas>();
 6476        goingEventsCanvas = goingEvents.GetComponent<Canvas>();
 6477    }
 78
 79    public override void Start()
 80    {
 5781        eventModal = ExploreEventsUtils.ConfigureEventCardModal(eventCardModalPrefab);
 82
 5783        featuredEvents.RemoveItems();
 5784        trendingEvents.RemoveItems();
 5785        upcomingEvents.RemoveItems();
 5786        goingEvents.RemoveItems();
 87
 5788        showMoreUpcomingEventsButton.onClick.RemoveAllListeners();
 5789        showMoreUpcomingEventsButton.onClick.AddListener(() => OnShowMoreUpcomingEventsClicked?.Invoke());
 90
 5791        OnReady?.Invoke();
 092    }
 93
 94    public override void OnEnable()
 95    {
 6796        OnEventsSubSectionEnable?.Invoke();
 097    }
 98
 99    public override void Dispose()
 100    {
 139101        base.Dispose();
 139102        cancellationTokenSource.Cancel();
 103
 139104        showMoreUpcomingEventsButton.onClick.RemoveAllListeners();
 105
 139106        featuredEvents.Dispose();
 139107        upcomingEvents.Dispose();
 139108        trendingEvents.Dispose();
 139109        goingEvents.Dispose();
 110
 139111        if (eventModal != null)
 112        {
 88113            eventModal.Dispose();
 88114            Destroy(eventModal.gameObject);
 115        }
 139116    }
 117
 118    public void SetActive(bool isActive)
 119    {
 53120        canvas.enabled = isActive;
 121
 53122        if (isActive)
 3123            OnEnable();
 124        else
 50125            OnDisable();
 50126    }
 127
 128    public void ConfigurePools()
 129    {
 19130        ExploreEventsUtils.ConfigureEventCardsPool(out featuredEventCardsPool, FEATURED_EVENT_CARDS_POOL_NAME, eventCard
 19131        ExploreEventsUtils.ConfigureEventCardsPool(out trendingEventCardsPool, TRENDING_EVENT_CARDS_POOL_NAME, eventCard
 19132        ExploreEventsUtils.ConfigureEventCardsPool(out upcomingEventCardsPool, UPCOMING_EVENT_CARDS_POOL_NAME, eventCard
 19133        ExploreEventsUtils.ConfigureEventCardsPool(out goingEventCardsPool, GOING_EVENT_CARDS_POOL_NAME, eventCardPrefab
 19134    }
 135
 136    public override void RefreshControl()
 137    {
 0138        featuredEvents.RefreshControl();
 0139        trendingEvents.RefreshControl();
 0140        upcomingEvents.RefreshControl();
 0141        goingEvents.RefreshControl();
 0142    }
 143
 144    public void SetAllEventGroupsAsLoading()
 145    {
 0146        SetFeaturedEventsGroupAsLoading();
 147
 0148        SetEventsGroupAsLoading(isVisible: true, goingEventsCanvas, goingEventsLoading);
 0149        SetEventsGroupAsLoading(isVisible: true, trendingEventsCanvas, trendingEventsLoading);
 0150        SetEventsGroupAsLoading(isVisible: true, upcomingEventsCanvas, upcomingEventsLoading);
 151
 0152        goingEventsNoDataText.gameObject.SetActive(false);
 0153        trendingEventsNoDataText.gameObject.SetActive(false);
 0154        upcomingEventsNoDataText.gameObject.SetActive(false);
 0155    }
 156
 157    internal void SetFeaturedEventsGroupAsLoading()
 158    {
 1159        featuredEvents.gameObject.SetActive(false);
 1160        featuredEventsLoading.SetActive(true);
 1161    }
 162
 163    public void SetEventsGroupAsLoading(bool isVisible, Canvas gridCanvas, GameObject loadingBar)
 164    {
 9165        gridCanvas.enabled = !isVisible;
 9166        loadingBar.SetActive(isVisible);
 9167    }
 168
 169    public void SetShowMoreUpcomingEventsButtonActive(bool isActive) =>
 2170        showMoreUpcomingEventsButtonContainer.gameObject.SetActive(isActive);
 171
 172    public void ShowEventModal(EventCardComponentModel eventInfo)
 173    {
 1174        eventModal.Show();
 1175        ExploreEventsUtils.ConfigureEventCard(eventModal, eventInfo, OnInfoClicked, OnJumpInClicked, OnSubscribeEventCli
 1176    }
 177
 178    public void HideEventModal()
 179    {
 1180        if (eventModal != null)
 1181            eventModal.Hide();
 1182    }
 183
 184    public void RestartScrollViewPosition() =>
 0185        scrollView.verticalNormalizedPosition = 1;
 186
 187    public void SetTrendingEvents(List<EventCardComponentModel> events) =>
 1188        SetEvents(events, trendingEvents, trendingEventsCanvas, trendingEventCardsPool, trendingEventsLoading, trendingE
 189
 190    public void SetGoingEvents(List<EventCardComponentModel> events) =>
 1191        SetEvents(events, goingEvents, goingEventsCanvas, goingEventCardsPool, goingEventsLoading, goingEventsNoDataText
 192
 193    public void SetUpcomingEvents(List<EventCardComponentModel> events) =>
 1194        SetEvents(events, upcomingEvents, upcomingEventsCanvas, upcomingEventCardsPool, upcomingEventsLoading, upcomingE
 195
 196    private void SetEvents(List<EventCardComponentModel> events, GridContainerComponentView eventsGrid, Canvas gridCanva
 197    {
 3198        SetEventsGroupAsLoading(false, gridCanvas, loadingBar);
 3199        eventsNoDataText.gameObject.SetActive(events.Count == 0);
 200
 3201        eventCardsPool.ReleaseAll();
 202
 3203        eventsGrid.ExtractItems();
 3204        eventsGrid.RemoveItems();
 205
 6206        cardsVisualUpdateBuffer.Enqueue(() => SetEventsAsync(events, eventsGrid, eventCardsPool, cancellationTokenSource
 3207        UpdateCardsVisual();
 3208    }
 209
 210    public void AddUpcomingEvents(List<EventCardComponentModel> events)
 211    {
 2212        cardsVisualUpdateBuffer.Enqueue(() => SetEventsAsync(events, upcomingEvents, upcomingEventCardsPool, cancellatio
 1213        UpdateCardsVisual();
 1214    }
 215
 216    private async UniTask SetEventsAsync(List<EventCardComponentModel> events, GridContainerComponentView eventsGrid, Po
 217    {
 20218        foreach (EventCardComponentModel eventInfo in events)
 219        {
 8220            eventsGrid.AddItem(
 221                ExploreEventsUtils.InstantiateConfiguredEventCard(eventInfo, pool,
 222                    OnInfoClicked, OnJumpInClicked, OnSubscribeEventClicked, OnUnsubscribeEventClicked));
 24223            await UniTask.NextFrame(cancellationToken);
 224        }
 225
 0226        eventsGrid.SetItemSizeForModel();
 0227        poolsPrewarmAsyncsBuffer.Enqueue(() => pool.PrewarmAsync(events.Count, cancellationToken));
 0228    }
 229
 230    public void SetFeaturedEvents(List<EventCardComponentModel> events)
 231    {
 1232        featuredEventsLoading.SetActive(false);
 1233        featuredEvents.gameObject.SetActive(events.Count > 0);
 234
 1235        featuredEventCardsPool.ReleaseAll();
 236
 1237        featuredEvents.ExtractItems();
 238
 2239        cardsVisualUpdateBuffer.Enqueue(() => SetFeaturedEventsAsync(events, cancellationTokenSource.Token));
 1240        UpdateCardsVisual();
 1241    }
 242
 243    private async UniTask SetFeaturedEventsAsync(List<EventCardComponentModel> events, CancellationToken cancellationTok
 244    {
 5245        foreach (EventCardComponentModel eventInfo in events)
 246        {
 2247            featuredEvents.AddItem(
 248                ExploreEventsUtils.InstantiateConfiguredEventCard(eventInfo, featuredEventCardsPool,
 249                    OnInfoClicked, OnJumpInClicked, OnSubscribeEventClicked, OnUnsubscribeEventClicked));
 6250            await UniTask.NextFrame(cancellationToken);
 251        }
 252
 0253        featuredEvents.SetManualControlsActive();
 0254        featuredEvents.GenerateDotsSelector();
 255
 0256        poolsPrewarmAsyncsBuffer.Enqueue(() => featuredEventCardsPool.PrewarmAsync(events.Count, cancellationToken));
 0257    }
 258
 259    private void UpdateCardsVisual()
 260    {
 5261        if (!isUpdatingCardsVisual)
 5262            ShowCardsProcess().Forget();
 263
 264        async UniTask ShowCardsProcess()
 265        {
 5266            isUpdatingCardsVisual = true;
 267
 5268            while (cardsVisualUpdateBuffer.Count > 0)
 15269                await cardsVisualUpdateBuffer.Dequeue().Invoke();
 270
 0271            while (poolsPrewarmAsyncsBuffer.Count > 0)
 0272                await poolsPrewarmAsyncsBuffer.Dequeue().Invoke();
 273
 0274            isUpdatingCardsVisual = false;
 0275        }
 5276    }
 277}