< Summary

Class:PlacesSubSectionComponentView
Assembly:ExploreV2
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/Sections/PlacesAndEventsSection/SubSections/PlacesSubSection/PlacesSubSectionMenu/PlacesSubSectionComponentView.cs
Covered lines:50
Uncovered lines:6
Coverable lines:56
Total lines:158
Line coverage:89.2% (50 of 56)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
PlacesSubSectionComponentView()0%110100%
Awake()0%110100%
Start()0%2.022083.33%
OnEnable()0%2.52050%
Dispose()0%220100%
ConfigurePools()0%110100%
RefreshControl()0%2100%
SetPlaces(...)0%110100%
SetPlacesAsLoading(...)0%220100%
AddPlaces(...)0%110100%
SetPlacesAsync()0%8.38083.33%
SetActive(...)0%220100%
SetShowMorePlacesButtonActive(...)0%110100%
ShowPlaceModal(...)0%110100%
HidePlaceModal()0%220100%
RestartScrollViewPosition()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/Sections/PlacesAndEventsSection/SubSections/PlacesSubSection/PlacesSubSectionMenu/PlacesSubSectionComponentView.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 PlacesSubSectionComponentView : BaseComponentView, IPlacesSubSectionComponentView
 11{
 12    internal const string PLACE_CARDS_POOL_NAME = "Places_PlaceCardsPool";
 13    private const int PLACE_CARDS_POOL_PREWARM = 20;
 14
 6515    private readonly CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
 16
 17    [Header("Assets References")]
 18    [SerializeField] internal PlaceCardComponentView placeCardPrefab;
 19    [SerializeField] internal PlaceCardComponentView placeCardModalPrefab;
 20
 21    [Header("Prefab References")]
 22    [SerializeField] internal ScrollRect scrollView;
 23    [SerializeField] internal GridContainerComponentView places;
 24    [SerializeField] internal GameObject placesLoading;
 25    [SerializeField] internal TMP_Text placesNoDataText;
 26    [SerializeField] internal Color[] friendColors = null;
 27    [SerializeField] internal GameObject showMorePlacesButtonContainer;
 28    [SerializeField] internal ButtonComponentView showMorePlacesButton;
 29
 30    [SerializeField] private Canvas canvas;
 31
 32    internal PlaceCardComponentView placeModal;
 33    internal Pool placeCardsPool;
 34    private Canvas placesCanvas;
 35
 036    public Color[] currentFriendColors => friendColors;
 37
 038    public int currentPlacesPerRow => places.currentItemsPerRow;
 39
 40    public event Action OnReady;
 41    public event Action<PlaceCardComponentModel> OnInfoClicked;
 42    public event Action<HotScenesController.HotSceneInfo> OnJumpInClicked;
 43    public event Action<FriendsHandler> OnFriendHandlerAdded;
 44    public event Action OnPlacesSubSectionEnable;
 45    public event Action OnShowMorePlacesClicked;
 46
 47    public override void Awake()
 48    {
 6249        base.Awake();
 6250        placesCanvas = places.GetComponent<Canvas>();
 6251    }
 52
 53    public override void Start()
 54    {
 5855        placeModal = ExplorePlacesUtils.ConfigurePlaceCardModal(placeCardModalPrefab);
 56
 5857        places.RemoveItems();
 58
 5859        showMorePlacesButton.onClick.RemoveAllListeners();
 5860        showMorePlacesButton.onClick.AddListener(() => OnShowMorePlacesClicked?.Invoke());
 61
 5862        OnReady?.Invoke();
 063    }
 64
 65    public override void OnEnable()
 66    {
 6567        OnPlacesSubSectionEnable?.Invoke();
 068    }
 69
 70    public override void Dispose()
 71    {
 13572        base.Dispose();
 13573        cancellationTokenSource.Cancel();
 74
 13575        showMorePlacesButton.onClick.RemoveAllListeners();
 76
 13577        places.Dispose();
 78
 13579        if (placeModal != null)
 80        {
 8681            placeModal.Dispose();
 8682            Destroy(placeModal.gameObject);
 83        }
 13584    }
 85
 86    public void ConfigurePools() =>
 1787        ExplorePlacesUtils.ConfigurePlaceCardsPool(out placeCardsPool, PLACE_CARDS_POOL_NAME, placeCardPrefab, PLACE_CAR
 88
 89    public override void RefreshControl() =>
 090        places.RefreshControl();
 91
 92    public void SetPlaces(List<PlaceCardComponentModel> places)
 93    {
 494        SetPlacesAsLoading(false);
 495        placesNoDataText.gameObject.SetActive(places.Count == 0);
 96
 497        placeCardsPool.ReleaseAll();
 98
 499        this.places.ExtractItems();
 4100        this.places.RemoveItems();
 101
 4102        SetPlacesAsync(places, cancellationTokenSource.Token).Forget();
 4103    }
 104
 105    public void SetPlacesAsLoading(bool isVisible)
 106    {
 6107        placesCanvas.enabled = !isVisible;
 108
 6109        placesLoading.SetActive(isVisible);
 110
 6111        if (isVisible)
 1112            placesNoDataText.gameObject.SetActive(false);
 6113    }
 114
 115    public void AddPlaces(List<PlaceCardComponentModel> places) =>
 4116        SetPlacesAsync(places, cancellationTokenSource.Token).Forget();
 117
 118    private async UniTask SetPlacesAsync(List<PlaceCardComponentModel> places, CancellationToken cancellationToken)
 119    {
 58120        foreach (PlaceCardComponentModel place in places)
 121        {
 24122            this.places.AddItem(
 123                ExplorePlacesUtils.InstantiateConfiguredPlaceCard(place, placeCardsPool, OnFriendHandlerAdded, OnInfoCli
 72124            await UniTask.NextFrame(cancellationToken);
 125        }
 126
 2127        this.places.SetItemSizeForModel();
 2128        await placeCardsPool.PrewarmAsync(places.Count, cancellationToken);
 2129    }
 130
 131    public void SetActive(bool isActive)
 132    {
 53133        canvas.enabled = isActive;
 134
 53135        if (isActive)
 3136            OnEnable();
 137        else
 50138            OnDisable();
 50139    }
 140
 141    public void SetShowMorePlacesButtonActive(bool isActive) =>
 2142        showMorePlacesButtonContainer.gameObject.SetActive(isActive);
 143
 144    public void ShowPlaceModal(PlaceCardComponentModel placeInfo)
 145    {
 1146        placeModal.Show();
 1147        ExplorePlacesUtils.ConfigurePlaceCard(placeModal, placeInfo, OnInfoClicked, OnJumpInClicked);
 1148    }
 149
 150    public void HidePlaceModal()
 151    {
 1152        if (placeModal != null)
 1153            placeModal.Hide();
 1154    }
 155
 156    public void RestartScrollViewPosition() =>
 0157        scrollView.verticalNormalizedPosition = 1;
 158}