< 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:52
Uncovered lines:9
Coverable lines:61
Total lines:165
Line coverage:85.2% (52 of 61)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
PlacesSubSectionComponentView()0%110100%
SetAllAsLoading()0%2100%
SetShowMoreButtonActive(...)0%2100%
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%9.249085.71%
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
 6015    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
 040    public void SetAllAsLoading() => SetPlacesAsLoading(true);
 041    public void SetShowMoreButtonActive(bool isActive) => SetShowMorePlacesButtonActive(isActive);
 042    public int CurrentTilesPerRow => currentPlacesPerRow;
 43
 44    public event Action OnReady;
 45    public event Action<PlaceCardComponentModel> OnInfoClicked;
 46    public event Action<HotScenesController.HotSceneInfo> OnJumpInClicked;
 47    public event Action<FriendsHandler> OnFriendHandlerAdded;
 48    public event Action OnPlacesSubSectionEnable;
 49    public event Action OnShowMorePlacesClicked;
 50
 51    public override void Awake()
 52    {
 5753        base.Awake();
 5754        placesCanvas = places.GetComponent<Canvas>();
 5755    }
 56
 57    public override void Start()
 58    {
 5359        placeModal = PlacesAndEventsCardsFactory.GetPlaceCardTemplateHiddenLazy(placeCardModalPrefab);
 60
 5361        places.RemoveItems();
 62
 5363        showMorePlacesButton.onClick.RemoveAllListeners();
 5364        showMorePlacesButton.onClick.AddListener(() => OnShowMorePlacesClicked?.Invoke());
 65
 5366        OnReady?.Invoke();
 067    }
 68
 69    public override void OnEnable()
 70    {
 6071        OnPlacesSubSectionEnable?.Invoke();
 072    }
 73
 74    public override void Dispose()
 75    {
 12576        base.Dispose();
 12577        cancellationTokenSource.Cancel();
 78
 12579        showMorePlacesButton.onClick.RemoveAllListeners();
 80
 12581        places.Dispose();
 82
 12583        if (placeModal != null)
 84        {
 7685            placeModal.Dispose();
 7686            Destroy(placeModal.gameObject);
 87        }
 12588    }
 89
 90    public void ConfigurePools() =>
 1791        placeCardsPool = PlacesAndEventsCardsFactory.GetCardsPoolLazy(PLACE_CARDS_POOL_NAME, placeCardPrefab, PLACE_CARD
 92
 93    public override void RefreshControl() =>
 094        places.RefreshControl();
 95
 96    public void SetPlaces(List<PlaceCardComponentModel> places)
 97    {
 498        SetPlacesAsLoading(false);
 499        placesNoDataText.gameObject.SetActive(places.Count == 0);
 100
 4101        placeCardsPool.ReleaseAll();
 102
 4103        this.places.ExtractItems();
 4104        this.places.RemoveItems();
 105
 4106        SetPlacesAsync(places, cancellationTokenSource.Token).Forget();
 4107    }
 108
 109    public void SetPlacesAsLoading(bool isVisible)
 110    {
 6111        placesCanvas.enabled = !isVisible;
 112
 6113        placesLoading.SetActive(isVisible);
 114
 6115        if (isVisible)
 1116            placesNoDataText.gameObject.SetActive(false);
 6117    }
 118
 119    public void AddPlaces(List<PlaceCardComponentModel> places) =>
 4120        SetPlacesAsync(places, cancellationTokenSource.Token).Forget();
 121
 122    private async UniTask SetPlacesAsync(List<PlaceCardComponentModel> places, CancellationToken cancellationToken)
 123    {
 58124        foreach (PlaceCardComponentModel place in places)
 125        {
 24126            PlaceCardComponentView placeCard = PlacesAndEventsCardsFactory.CreateConfiguredPlaceCard(placeCardsPool, pla
 24127            OnFriendHandlerAdded?.Invoke(placeCard.friendsHandler);
 128
 24129            this.places.AddItem(placeCard);
 130
 72131            await UniTask.NextFrame(cancellationToken);
 132        }
 133
 2134        this.places.SetItemSizeForModel();
 2135        await placeCardsPool.PrewarmAsync(places.Count, cancellationToken);
 2136    }
 137
 138    public void SetActive(bool isActive)
 139    {
 89140        canvas.enabled = isActive;
 141
 89142        if (isActive)
 3143            OnEnable();
 144        else
 86145            OnDisable();
 86146    }
 147
 148    public void SetShowMorePlacesButtonActive(bool isActive) =>
 2149        showMorePlacesButtonContainer.gameObject.SetActive(isActive);
 150
 151    public void ShowPlaceModal(PlaceCardComponentModel placeInfo)
 152    {
 1153        placeModal.Show();
 1154        PlacesCardsConfigurator.Configure(placeModal, placeInfo, OnInfoClicked, OnJumpInClicked);
 1155    }
 156
 157    public void HidePlaceModal()
 158    {
 1159        if (placeModal != null)
 1160            placeModal.Hide();
 1161    }
 162
 163    public void RestartScrollViewPosition() =>
 0164        scrollView.verticalNormalizedPosition = 1;
 165}