< Summary

Class:HighlightsSubSectionComponentView
Assembly:ExploreV2
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/Sections/PlacesAndEventsSection/SubSections/HighlightsSubSection/HighlightsSubSectionMenu/HighlightsSubSectionComponentView.cs
Covered lines:118
Uncovered lines:12
Coverable lines:130
Total lines:314
Line coverage:90.7% (118 of 130)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
HighlightsSubSectionComponentView()0%110100%
Start()0%2.012087.5%
OnEnable()0%2.52050%
Dispose()0%330100%
SetActive(...)0%220100%
ConfigurePools()0%110100%
RefreshControl()0%2100%
SetTrendingPlacesAndEventsAsLoading(...)0%110100%
SetTrendingPlacesAndEventsActive(...)0%110100%
SetFeaturedPlacesAsLoading(...)0%220100%
SetLiveAsLoading(...)0%220100%
ShowPlaceModal(...)0%110100%
HidePlaceModal()0%220100%
ShowEventModal(...)0%110100%
HideEventModal()0%220100%
RestartScrollViewPosition()0%2100%
SetFeaturedPlaces(...)0%110100%
SetPlacesAsync()0%660100%
SetLiveEvents(...)0%110100%
SetEventsAsync()0%660100%
SetTrendingPlacesAndEvents(...)0%110100%
SetTrendingsAsync()0%7.467078.95%
UpdateCardsVisual()0%220100%
<UpdateCardsVisual()0%7.297081.82%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/Sections/PlacesAndEventsSection/SubSections/HighlightsSubSection/HighlightsSubSectionMenu/HighlightsSubSectionComponentView.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 HighlightsSubSectionComponentView : BaseComponentView, IHighlightsSubSectionComponentView
 11{
 12    private const string TRENDING_PLACE_CARDS_POOL_NAME = "Highlights_TrendingPlaceCardsPool";
 13    private const int TRENDING_PLACE_CARDS_POOL_PREWARM = 10;
 14    private const string TRENDING_EVENT_CARDS_POOL_NAME = "Highlights_TrendingEventCardsPool";
 15    private const int TRENDING_EVENT_CARDS_POOL_PREWARM = 10;
 16    private const string FEATURED_PLACE_CARDS_POOL_NAME = "Highlights_FeaturedPlaceCardsPool";
 17    private const int FEATURED_PLACE_CARDS_POOL_PREWARM = 9;
 18    private const string LIVE_EVENT_CARDS_POOL_NAME = "Highlights_LiveEventCardsPool";
 19    private const int LIVE_EVENT_CARDS_POOL_PREWARM = 3;
 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 PlaceCardComponentView placeCardLongPrefab;
 27    [SerializeField] internal EventCardComponentView eventCardLongPrefab;
 28    [SerializeField] internal PlaceCardComponentView placeCardPrefab;
 29    [SerializeField] internal PlaceCardComponentView placeCardModalPrefab;
 30    [SerializeField] internal EventCardComponentView eventCardPrefab;
 31    [SerializeField] internal EventCardComponentView eventCardModalPrefab;
 32
 33    [Header("Prefab References")]
 34    [SerializeField] internal ScrollRect scrollView;
 35    [SerializeField] internal CarouselComponentView trendingPlacesAndEvents;
 36    [SerializeField] internal GameObject trendingPlacesAndEventsLoading;
 37    [SerializeField] internal GridContainerComponentView featuredPlaces;
 38    [SerializeField] internal GameObject featuredPlacesLoading;
 39    [SerializeField] internal TMP_Text featuredPlacesNoDataText;
 40    [SerializeField] internal GridContainerComponentView liveEvents;
 41    [SerializeField] internal GameObject liveEventsLoading;
 42    [SerializeField] internal TMP_Text liveEventsNoDataText;
 43    [SerializeField] internal ButtonComponentView viewAllEventsButton;
 44    [SerializeField] internal Color[] friendColors = null;
 45
 46    [SerializeField] private Canvas canvas;
 47
 48    internal PlaceCardComponentView placeModal;
 49    internal EventCardComponentView eventModal;
 50    internal Pool trendingPlaceCardsPool;
 51    internal Pool trendingEventCardsPool;
 52    internal Pool featuredPlaceCardsPool;
 53    internal Pool liveEventCardsPool;
 54
 55    private bool isUpdatingCardsVisual;
 56
 057    public Color[] currentFriendColors => friendColors;
 58
 59    public event Action OnReady;
 60    public event Action<PlaceCardComponentModel> OnPlaceInfoClicked;
 61    public event Action<EventCardComponentModel> OnEventInfoClicked;
 62    public event Action<HotScenesController.HotSceneInfo> OnPlaceJumpInClicked;
 63    public event Action<EventFromAPIModel> OnEventJumpInClicked;
 64    public event Action<string> OnEventSubscribeEventClicked;
 65    public event Action<string> OnEventUnsubscribeEventClicked;
 66    public event Action OnViewAllEventsClicked;
 67    public event Action<FriendsHandler> OnFriendHandlerAdded;
 68    public event Action OnHighlightsSubSectionEnable;
 69
 70    public override void Start()
 71    {
 6172        placeModal = ExplorePlacesUtils.ConfigurePlaceCardModal(placeCardModalPrefab);
 6173        eventModal = ExploreEventsUtils.ConfigureEventCardModal(eventCardModalPrefab);
 74
 6175        trendingPlacesAndEvents.RemoveItems();
 6176        featuredPlaces.RemoveItems();
 6177        liveEvents.RemoveItems();
 78
 6179        viewAllEventsButton.onClick.AddListener(() => OnViewAllEventsClicked?.Invoke());
 80
 6181        OnReady?.Invoke();
 082    }
 83
 84    public override void OnEnable()
 85    {
 12086        OnHighlightsSubSectionEnable?.Invoke();
 087    }
 88
 89    public override void Dispose()
 90    {
 13991        base.Dispose();
 92
 13993        cancellationTokenSource.Cancel();
 94
 13995        trendingPlacesAndEvents.Dispose();
 13996        featuredPlaces.Dispose();
 13997        liveEvents.Dispose();
 98
 13999        if (placeModal != null)
 100        {
 88101            placeModal.Dispose();
 88102            Destroy(placeModal.gameObject);
 103        }
 104
 139105        if (eventModal != null)
 106        {
 88107            eventModal.Dispose();
 88108            Destroy(eventModal.gameObject);
 109        }
 110
 139111        viewAllEventsButton.onClick.RemoveAllListeners();
 139112    }
 113
 114    public void SetActive(bool isActive)
 115    {
 108116        canvas.enabled = isActive;
 117
 108118        if (isActive)
 56119            OnEnable();
 120        else
 52121            OnDisable();
 52122    }
 123
 124    public void ConfigurePools()
 125    {
 19126        ExplorePlacesUtils.ConfigurePlaceCardsPool(out trendingPlaceCardsPool, TRENDING_PLACE_CARDS_POOL_NAME, placeCard
 19127        ExploreEventsUtils.ConfigureEventCardsPool(out trendingEventCardsPool, TRENDING_EVENT_CARDS_POOL_NAME, eventCard
 19128        ExplorePlacesUtils.ConfigurePlaceCardsPool(out featuredPlaceCardsPool, FEATURED_PLACE_CARDS_POOL_NAME, placeCard
 19129        ExploreEventsUtils.ConfigureEventCardsPool(out liveEventCardsPool, LIVE_EVENT_CARDS_POOL_NAME, eventCardPrefab, 
 19130    }
 131
 132    public override void RefreshControl()
 133    {
 0134        trendingPlacesAndEvents.RefreshControl();
 0135        featuredPlaces.RefreshControl();
 0136        liveEvents.RefreshControl();
 0137    }
 138
 139    public void SetTrendingPlacesAndEventsAsLoading(bool isVisible)
 140    {
 3141        SetTrendingPlacesAndEventsActive(!isVisible);
 3142        trendingPlacesAndEventsLoading.SetActive(isVisible);
 3143    }
 144
 145    internal void SetTrendingPlacesAndEventsActive(bool isActive) =>
 5146        trendingPlacesAndEvents.gameObject.SetActive(isActive);
 147
 148    public void SetFeaturedPlacesAsLoading(bool isVisible)
 149    {
 6150        featuredPlaces.gameObject.SetActive(!isVisible);
 6151        featuredPlacesLoading.SetActive(isVisible);
 152
 6153        if (isVisible)
 1154            featuredPlacesNoDataText.gameObject.SetActive(false);
 6155    }
 156
 157    public void SetLiveAsLoading(bool isVisible)
 158    {
 6159        liveEvents.gameObject.SetActive(!isVisible);
 6160        liveEventsLoading.SetActive(isVisible);
 6161        viewAllEventsButton.gameObject.SetActive(!isVisible);
 162
 6163        if (isVisible)
 1164            liveEventsNoDataText.gameObject.SetActive(false);
 6165    }
 166
 167    public void ShowPlaceModal(PlaceCardComponentModel placeInfo)
 168    {
 1169        placeModal.Show();
 1170        ExplorePlacesUtils.ConfigurePlaceCard(placeModal, placeInfo, OnPlaceInfoClicked, OnPlaceJumpInClicked);
 1171    }
 172
 173    public void HidePlaceModal()
 174    {
 1175        if (placeModal != null)
 1176            placeModal.Hide();
 1177    }
 178
 179    public void ShowEventModal(EventCardComponentModel eventInfo)
 180    {
 1181        eventModal.Show();
 1182        ExploreEventsUtils.ConfigureEventCard(eventModal, eventInfo, OnEventInfoClicked, OnEventJumpInClicked, OnEventSu
 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 SetFeaturedPlaces(List<PlaceCardComponentModel> places)
 195    {
 4196        SetFeaturedPlacesAsLoading(false);
 4197        featuredPlacesNoDataText.gameObject.SetActive(places.Count == 0);
 198
 4199        featuredPlaceCardsPool.ReleaseAll();
 200
 4201        featuredPlaces.ExtractItems();
 4202        featuredPlaces.RemoveItems();
 203
 8204        cardsVisualUpdateBuffer.Enqueue(() => SetPlacesAsync(places, cancellationTokenSource.Token));
 4205        UpdateCardsVisual();
 4206    }
 207
 208    private async UniTask SetPlacesAsync(List<PlaceCardComponentModel> places, CancellationToken cancellationToken)
 209    {
 29210        foreach (PlaceCardComponentModel place in places)
 211        {
 12212            featuredPlaces.AddItem(
 213                ExplorePlacesUtils.InstantiateConfiguredPlaceCard(place, featuredPlaceCardsPool,
 214                    OnFriendHandlerAdded, OnPlaceInfoClicked, OnPlaceJumpInClicked));
 215
 36216            await UniTask.NextFrame(cancellationToken);
 217        }
 218
 1219        featuredPlaces.SetItemSizeForModel();
 2220        poolsPrewarmAsyncsBuffer.Enqueue(() => featuredPlaceCardsPool.PrewarmAsync(places.Count, cancellationToken));
 1221    }
 222
 223    public void SetLiveEvents(List<EventCardComponentModel> events)
 224    {
 4225        SetLiveAsLoading(false);
 4226        liveEventsNoDataText.gameObject.SetActive(events.Count == 0);
 227
 4228        liveEventCardsPool.ReleaseAll();
 229
 4230        liveEvents.ExtractItems();
 4231        liveEvents.RemoveItems();
 232
 8233        cardsVisualUpdateBuffer.Enqueue(() => SetEventsAsync(events, liveEvents, liveEventCardsPool, cancellationTokenSo
 4234        UpdateCardsVisual();
 4235    }
 236
 237    private async UniTask SetEventsAsync(List<EventCardComponentModel> events, GridContainerComponentView eventsGrid, Po
 238    {
 29239        foreach (EventCardComponentModel eventInfo in events)
 240        {
 12241            eventsGrid.AddItem(
 242                ExploreEventsUtils.InstantiateConfiguredEventCard(eventInfo, pool,
 243                    OnEventInfoClicked, OnEventJumpInClicked, OnEventSubscribeEventClicked, OnEventUnsubscribeEventClick
 244
 36245            await UniTask.NextFrame(cancellationToken);
 246        }
 247
 1248        eventsGrid.SetItemSizeForModel();
 249
 2250        poolsPrewarmAsyncsBuffer.Enqueue(() => pool.PrewarmAsync(events.Count, cancellationToken));
 1251    }
 252
 253    public void SetTrendingPlacesAndEvents(List<PlaceCardComponentModel> places, List<EventCardComponentModel> events)
 254    {
 1255        SetTrendingPlacesAndEventsAsLoading(false);
 256
 1257        trendingPlaceCardsPool.ReleaseAll();
 1258        trendingEventCardsPool.ReleaseAll();
 259
 1260        trendingPlacesAndEvents.ExtractItems();
 1261        trendingPlacesAndEvents.RemoveItems();
 262
 2263        cardsVisualUpdateBuffer.Enqueue(() => SetTrendingsAsync(places, events, cancellationTokenSource.Token));
 1264        UpdateCardsVisual();
 1265    }
 266
 267    private async UniTask SetTrendingsAsync(List<PlaceCardComponentModel> places, List<EventCardComponentModel> events, 
 268    {
 1269        int eventId = 0;
 1270        int placeId = 0;
 271
 8272        for (int i = 0 ; i < HighlightsSubSectionComponentController.DEFAULT_NUMBER_OF_TRENDING_PLACES; i++)
 273        {
 4274            if (i % 2 == 0 && eventId < events.Count)
 275            {
 2276                trendingPlacesAndEvents.AddItem(ExploreEventsUtils.InstantiateConfiguredEventCard(events[eventId], trend
 277                    OnEventInfoClicked, OnEventJumpInClicked, OnEventSubscribeEventClicked, OnEventUnsubscribeEventClick
 2278                eventId++;
 2279            }
 2280            else if (placeId < places.Count)
 281            {
 2282                trendingPlacesAndEvents.AddItem(ExplorePlacesUtils.InstantiateConfiguredPlaceCard(places[placeId], trend
 283                    OnFriendHandlerAdded, OnPlaceInfoClicked, OnPlaceJumpInClicked));
 2284                placeId++;
 285            }
 286
 12287            await UniTask.NextFrame(cancellationToken);
 288        }
 289
 0290        trendingPlacesAndEvents.SetManualControlsActive();
 0291        trendingPlacesAndEvents.GenerateDotsSelector();
 292
 0293        poolsPrewarmAsyncsBuffer.Enqueue(() => trendingPlaceCardsPool.PrewarmAsync(HighlightsSubSectionComponentControll
 0294    }
 295
 296    private void UpdateCardsVisual()
 297    {
 9298        if (!isUpdatingCardsVisual)
 9299            UpdateCardsVisualProcess().Forget();
 300
 301        async UniTask UpdateCardsVisualProcess()
 302        {
 9303            isUpdatingCardsVisual = true;
 304
 11305            while (cardsVisualUpdateBuffer.Count > 0)
 23306                await cardsVisualUpdateBuffer.Dequeue().Invoke();
 307
 4308            while (poolsPrewarmAsyncsBuffer.Count > 0)
 2309                await poolsPrewarmAsyncsBuffer.Dequeue().Invoke();
 310
 2311            isUpdatingCardsVisual = false;
 2312        }
 9313    }
 314}