< 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:121
Uncovered lines:17
Coverable lines:138
Total lines:328
Line coverage:87.6% (121 of 138)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
HighlightsSubSectionComponentView()0%110100%
SetAllAsLoading()0%2100%
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%770100%
SetLiveEvents(...)0%110100%
SetEventsAsync()0%660100%
SetTrendingPlacesAndEvents(...)0%110100%
SetTrendingsAsync()0%8.518080%
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
 6221    private readonly Queue<Func<UniTask>> cardsVisualUpdateBuffer = new ();
 6222    private readonly Queue<Func<UniTask>> poolsPrewarmAsyncsBuffer = new ();
 6223    private readonly CancellationTokenSource cancellationTokenSource = new ();
 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 void SetAllAsLoading()
 60    {
 061        SetTrendingPlacesAndEventsAsLoading(true);
 062        SetFeaturedPlacesAsLoading(true);
 063        SetLiveAsLoading(true);
 064    }
 65
 066    public int CurrentTilesPerRow { get; }
 67
 68    public event Action OnReady;
 69    public event Action<PlaceCardComponentModel> OnPlaceInfoClicked;
 70    public event Action<EventCardComponentModel> OnEventInfoClicked;
 71    public event Action<HotScenesController.HotSceneInfo> OnPlaceJumpInClicked;
 72    public event Action<EventFromAPIModel> OnEventJumpInClicked;
 73    public event Action<string> OnEventSubscribeEventClicked;
 74    public event Action<string> OnEventUnsubscribeEventClicked;
 75    public event Action OnViewAllEventsClicked;
 76    public event Action<FriendsHandler> OnFriendHandlerAdded;
 77    public event Action OnHighlightsSubSectionEnable;
 78
 79    public override void Start()
 80    {
 5681        placeModal = PlacesAndEventsCardsFactory.GetPlaceCardTemplateHiddenLazy(placeCardModalPrefab);
 5682        eventModal = PlacesAndEventsCardsFactory.GetEventCardTemplateHiddenLazy(eventCardModalPrefab);
 83
 5684        trendingPlacesAndEvents.RemoveItems();
 5685        featuredPlaces.RemoveItems();
 5686        liveEvents.RemoveItems();
 87
 5688        viewAllEventsButton.onClick.AddListener(() => OnViewAllEventsClicked?.Invoke());
 89
 5690        OnReady?.Invoke();
 091    }
 92
 93    public override void OnEnable()
 94    {
 11195        OnHighlightsSubSectionEnable?.Invoke();
 096    }
 97
 98    public override void Dispose()
 99    {
 129100        base.Dispose();
 101
 129102        cancellationTokenSource.Cancel();
 103
 129104        trendingPlacesAndEvents.Dispose();
 129105        featuredPlaces.Dispose();
 129106        liveEvents.Dispose();
 107
 129108        if (placeModal != null)
 109        {
 78110            placeModal.Dispose();
 78111            Destroy(placeModal.gameObject);
 112        }
 113
 129114        if (eventModal != null)
 115        {
 78116            eventModal.Dispose();
 78117            Destroy(eventModal.gameObject);
 118        }
 119
 129120        viewAllEventsButton.onClick.RemoveAllListeners();
 129121    }
 122
 123    public void SetActive(bool isActive)
 124    {
 139125        canvas.enabled = isActive;
 126
 139127        if (isActive)
 52128            OnEnable();
 129        else
 87130            OnDisable();
 87131    }
 132
 133    public void ConfigurePools()
 134    {
 19135        trendingPlaceCardsPool = PlacesAndEventsCardsFactory.GetCardsPoolLazy(TRENDING_PLACE_CARDS_POOL_NAME, placeCardL
 19136        featuredPlaceCardsPool = PlacesAndEventsCardsFactory.GetCardsPoolLazy(FEATURED_PLACE_CARDS_POOL_NAME, placeCardP
 137
 19138        trendingEventCardsPool = PlacesAndEventsCardsFactory.GetCardsPoolLazy(TRENDING_EVENT_CARDS_POOL_NAME, eventCardL
 19139        liveEventCardsPool = PlacesAndEventsCardsFactory.GetCardsPoolLazy(LIVE_EVENT_CARDS_POOL_NAME, eventCardPrefab, L
 19140    }
 141
 142    public override void RefreshControl()
 143    {
 0144        trendingPlacesAndEvents.RefreshControl();
 0145        featuredPlaces.RefreshControl();
 0146        liveEvents.RefreshControl();
 0147    }
 148
 149    public void SetTrendingPlacesAndEventsAsLoading(bool isVisible)
 150    {
 3151        SetTrendingPlacesAndEventsActive(!isVisible);
 3152        trendingPlacesAndEventsLoading.SetActive(isVisible);
 3153    }
 154
 155    internal void SetTrendingPlacesAndEventsActive(bool isActive) =>
 5156        trendingPlacesAndEvents.gameObject.SetActive(isActive);
 157
 158    public void SetFeaturedPlacesAsLoading(bool isVisible)
 159    {
 6160        featuredPlaces.gameObject.SetActive(!isVisible);
 6161        featuredPlacesLoading.SetActive(isVisible);
 162
 6163        if (isVisible)
 1164            featuredPlacesNoDataText.gameObject.SetActive(false);
 6165    }
 166
 167    public void SetLiveAsLoading(bool isVisible)
 168    {
 6169        liveEvents.gameObject.SetActive(!isVisible);
 6170        liveEventsLoading.SetActive(isVisible);
 6171        viewAllEventsButton.gameObject.SetActive(!isVisible);
 172
 6173        if (isVisible)
 1174            liveEventsNoDataText.gameObject.SetActive(false);
 6175    }
 176
 177    public void ShowPlaceModal(PlaceCardComponentModel placeInfo)
 178    {
 1179        placeModal.Show();
 1180        PlacesCardsConfigurator.Configure(placeModal, placeInfo, OnPlaceInfoClicked, OnPlaceJumpInClicked);
 1181    }
 182
 183    public void HidePlaceModal()
 184    {
 1185        if (placeModal != null)
 1186            placeModal.Hide();
 1187    }
 188
 189    public void ShowEventModal(EventCardComponentModel eventInfo)
 190    {
 1191        eventModal.Show();
 1192        EventsCardsConfigurator.Configure(eventModal, eventInfo, OnEventInfoClicked, OnEventJumpInClicked, OnEventSubscr
 1193    }
 194
 195    public void HideEventModal()
 196    {
 1197        if (eventModal != null)
 1198            eventModal.Hide();
 1199    }
 200
 201    public void RestartScrollViewPosition() =>
 0202        scrollView.verticalNormalizedPosition = 1;
 203
 204    public void SetFeaturedPlaces(List<PlaceCardComponentModel> places)
 205    {
 4206        SetFeaturedPlacesAsLoading(false);
 4207        featuredPlacesNoDataText.gameObject.SetActive(places.Count == 0);
 208
 4209        featuredPlaceCardsPool.ReleaseAll();
 210
 4211        featuredPlaces.ExtractItems();
 4212        featuredPlaces.RemoveItems();
 213
 8214        cardsVisualUpdateBuffer.Enqueue(() => SetPlacesAsync(places, cancellationTokenSource.Token));
 4215        UpdateCardsVisual();
 4216    }
 217
 218    private async UniTask SetPlacesAsync(List<PlaceCardComponentModel> places, CancellationToken cancellationToken)
 219    {
 29220        foreach (PlaceCardComponentModel place in places)
 221        {
 12222            PlaceCardComponentView placeCard = PlacesAndEventsCardsFactory.CreateConfiguredPlaceCard(featuredPlaceCardsP
 12223            OnFriendHandlerAdded?.Invoke(placeCard.friendsHandler);
 224
 12225            this.featuredPlaces.AddItem(placeCard);
 226
 36227            await UniTask.NextFrame(cancellationToken);
 228        }
 229
 1230        featuredPlaces.SetItemSizeForModel();
 2231        poolsPrewarmAsyncsBuffer.Enqueue(() => featuredPlaceCardsPool.PrewarmAsync(places.Count, cancellationToken));
 1232    }
 233
 234    public void SetLiveEvents(List<EventCardComponentModel> events)
 235    {
 4236        SetLiveAsLoading(false);
 4237        liveEventsNoDataText.gameObject.SetActive(events.Count == 0);
 238
 4239        liveEventCardsPool.ReleaseAll();
 240
 4241        liveEvents.ExtractItems();
 4242        liveEvents.RemoveItems();
 243
 8244        cardsVisualUpdateBuffer.Enqueue(() => SetEventsAsync(events, liveEvents, liveEventCardsPool, cancellationTokenSo
 4245        UpdateCardsVisual();
 4246    }
 247
 248    private async UniTask SetEventsAsync(List<EventCardComponentModel> events, GridContainerComponentView eventsGrid, Po
 249    {
 29250        foreach (EventCardComponentModel eventInfo in events)
 251        {
 12252            eventsGrid.AddItem(
 253                PlacesAndEventsCardsFactory.CreateConfiguredEventCard(pool, eventInfo, OnEventInfoClicked, OnEventJumpIn
 254
 36255            await UniTask.NextFrame(cancellationToken);
 256        }
 257
 1258        eventsGrid.SetItemSizeForModel();
 259
 2260        poolsPrewarmAsyncsBuffer.Enqueue(() => pool.PrewarmAsync(events.Count, cancellationToken));
 1261    }
 262
 263    public void SetTrendingPlacesAndEvents(List<PlaceCardComponentModel> places, List<EventCardComponentModel> events)
 264    {
 1265        SetTrendingPlacesAndEventsAsLoading(false);
 266
 1267        trendingPlaceCardsPool.ReleaseAll();
 1268        trendingEventCardsPool.ReleaseAll();
 269
 1270        trendingPlacesAndEvents.ExtractItems();
 1271        trendingPlacesAndEvents.RemoveItems();
 272
 2273        cardsVisualUpdateBuffer.Enqueue(() => SetTrendingsAsync(places, events, cancellationTokenSource.Token));
 1274        UpdateCardsVisual();
 1275    }
 276
 277    private async UniTask SetTrendingsAsync(List<PlaceCardComponentModel> places, List<EventCardComponentModel> events, 
 278    {
 1279        int eventId = 0;
 1280        int placeId = 0;
 281
 8282        for (int i = 0; i < HighlightsSubSectionComponentController.DEFAULT_NUMBER_OF_TRENDING_PLACES; i++)
 283        {
 4284            if (i % 2 == 0 && eventId < events.Count)
 285            {
 2286                trendingPlacesAndEvents.AddItem(
 287                    PlacesAndEventsCardsFactory.CreateConfiguredEventCard(trendingEventCardsPool, events[eventId], OnEve
 288
 2289                eventId++;
 290            }
 2291            else if (placeId < places.Count)
 292            {
 2293                PlaceCardComponentView placeCard = PlacesAndEventsCardsFactory.CreateConfiguredPlaceCard(trendingPlaceCa
 2294                OnFriendHandlerAdded?.Invoke(placeCard.friendsHandler);
 295
 2296                trendingPlacesAndEvents.AddItem(placeCard);
 297
 2298                placeId++;
 299            }
 300
 12301            await UniTask.NextFrame(cancellationToken);
 302        }
 303
 0304        trendingPlacesAndEvents.SetManualControlsActive();
 0305        trendingPlacesAndEvents.GenerateDotsSelector();
 306
 0307        poolsPrewarmAsyncsBuffer.Enqueue(() => trendingPlaceCardsPool.PrewarmAsync(HighlightsSubSectionComponentControll
 0308    }
 309
 310    private void UpdateCardsVisual()
 311    {
 9312        if (!isUpdatingCardsVisual)
 9313            UpdateCardsVisualProcess().Forget();
 314
 315        async UniTask UpdateCardsVisualProcess()
 316        {
 9317            isUpdatingCardsVisual = true;
 318
 11319            while (cardsVisualUpdateBuffer.Count > 0)
 23320                await cardsVisualUpdateBuffer.Dequeue().Invoke();
 321
 4322            while (poolsPrewarmAsyncsBuffer.Count > 0)
 2323                await poolsPrewarmAsyncsBuffer.Dequeue().Invoke();
 324
 2325            isUpdatingCardsVisual = false;
 2326        }
 9327    }
 328}