< 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:54
Uncovered lines:5
Coverable lines:59
Total lines:235
Line coverage:91.5% (54 of 59)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
OnEnable()0%2.52050%
Start()0%2.012085.71%
RefreshControl()0%2100%
Dispose()0%220100%
SetPlaces(...)0%110100%
AddPlaces(...)0%220100%
SetPlacesAsLoading(...)0%220100%
SetShowMorePlacesButtonActive(...)0%110100%
ShowPlaceModal(...)0%110100%
HidePlaceModal()0%110100%
RestartScrollViewPosition()0%2100%
ConfigurePlaceCardModal()0%110100%
ConfigurePlaceCardsPool()0%220100%
InstantiateAndConfigurePlaceCards(...)0%330100%
ConfigurePlaceCard(...)0%550100%

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 TMPro;
 5using UnityEngine;
 6using UnityEngine.UI;
 7
 8public interface IPlacesSubSectionComponentView
 9{
 10    /// <summary>
 11    /// It will be triggered when all the UI components have been fully initialized.
 12    /// </summary>
 13    event Action OnReady;
 14
 15    /// <summary>
 16    /// It will be triggered when the info button is clicked.
 17    /// </summary>
 18    event Action<PlaceCardComponentModel> OnInfoClicked;
 19
 20    /// <summary>
 21    /// It will be triggered when the JumpIn button is clicked.
 22    /// </summary>
 23    event Action<HotScenesController.HotSceneInfo> OnJumpInClicked;
 24
 25    /// <summary>
 26    /// It will be triggered when a new friend handler is added by a place card.
 27    /// </summary>
 28    event Action<FriendsHandler> OnFriendHandlerAdded;
 29
 30    /// <summary>
 31    /// It will be triggered each time the view is enabled.
 32    /// </summary>
 33    event Action OnPlacesSubSectionEnable;
 34
 35    /// <summary>
 36    /// It will be triggered when the "Show More" button is clicked.
 37    /// </summary>
 38    event Action OnShowMorePlacesClicked;
 39
 40    /// <summary>
 41    /// Colors used for the background of the friends heads.
 42    /// </summary>
 43    Color[] currentFriendColors { get; }
 44
 45    /// <summary>
 46    /// Number of places per row that fit with the current places grid configuration.
 47    /// </summary>
 48    int currentPlacesPerRow { get; }
 49
 50    /// <summary>
 51    /// Set the places component with a list of places.
 52    /// </summary>
 53    /// <param name="places">List of places (model) to be loaded.</param>
 54    void SetPlaces(List<PlaceCardComponentModel> places);
 55
 56    /// <summary>
 57    /// Add a list of places in the places component.
 58    /// </summary>
 59    /// <param name="places">List of places (model) to be added.</param>
 60    void AddPlaces(List<PlaceCardComponentModel> places);
 61
 62    /// <summary>
 63    /// Set the places component in loading mode.
 64    /// </summary>
 65    /// <param name="isVisible">True for activating the loading mode.</param>
 66    void SetPlacesAsLoading(bool isVisible);
 67
 68    /// <summary>
 69    /// Activates/Deactivates the "Show More" button.
 70    /// </summary>
 71    /// <param name="isActive">True for activating it.</param>
 72    void SetShowMorePlacesButtonActive(bool isActive);
 73
 74    /// <summary>
 75    /// Shows the Place Card modal with the provided information.
 76    /// </summary>
 77    /// <param name="placeInfo">Place (model) to be loaded in the card.</param>
 78    void ShowPlaceModal(PlaceCardComponentModel placeInfo);
 79
 80    /// <summary>
 81    /// Hides the Place Card modal.
 82    /// </summary>
 83    void HidePlaceModal();
 84
 85    /// <summary>
 86    /// Set the current scroll view position to 1.
 87    /// </summary>
 88    void RestartScrollViewPosition();
 89}
 90
 91public class PlacesSubSectionComponentView : BaseComponentView, IPlacesSubSectionComponentView
 92{
 93    internal const string PLACE_CARDS_POOL_NAME = "PlaceCardsPool";
 94
 95    [Header("Assets References")]
 96    [SerializeField] internal PlaceCardComponentView placeCardPrefab;
 97    [SerializeField] internal PlaceCardComponentView placeCardModalPrefab;
 98
 99    [Header("Prefab References")]
 100    [SerializeField] internal ScrollRect scrollView;
 101    [SerializeField] internal GridContainerComponentView places;
 102    [SerializeField] internal GameObject placesLoading;
 103    [SerializeField] internal TMP_Text placesNoDataText;
 104    [SerializeField] internal Color[] friendColors = null;
 105    [SerializeField] internal GameObject showMorePlacesButtonContainer;
 106    [SerializeField] internal ButtonComponentView showMorePlacesButton;
 107
 108    public event Action OnReady;
 109    public event Action<PlaceCardComponentModel> OnInfoClicked;
 110    public event Action<HotScenesController.HotSceneInfo> OnJumpInClicked;
 111    public event Action<FriendsHandler> OnFriendHandlerAdded;
 112    public event Action OnPlacesSubSectionEnable;
 113    public event Action OnShowMorePlacesClicked;
 114
 115    internal PlaceCardComponentView placeModal;
 116    internal Pool placeCardsPool;
 117
 0118    public Color[] currentFriendColors => friendColors;
 119
 0120    public int currentPlacesPerRow => places.currentItemsPerRow;
 121
 14122    public override void OnEnable() { OnPlacesSubSectionEnable?.Invoke(); }
 123
 124    public override void Start()
 125    {
 11126        ConfigurePlaceCardModal();
 11127        ConfigurePlaceCardsPool();
 128
 11129        places.RemoveItems();
 130
 11131        showMorePlacesButton.onClick.RemoveAllListeners();
 11132        showMorePlacesButton.onClick.AddListener(() => OnShowMorePlacesClicked?.Invoke());
 133
 11134        OnReady?.Invoke();
 0135    }
 136
 0137    public override void RefreshControl() { places.RefreshControl(); }
 138
 139    public override void Dispose()
 140    {
 35141        base.Dispose();
 142
 35143        showMorePlacesButton.onClick.RemoveAllListeners();
 144
 35145        places.Dispose();
 146
 35147        if (placeModal != null)
 148        {
 12149            placeModal.Dispose();
 12150            Destroy(placeModal.gameObject);
 151        }
 35152    }
 153
 154    public void SetPlaces(List<PlaceCardComponentModel> places)
 155    {
 1156        this.places.ExtractItems();
 1157        placeCardsPool.ReleaseAll();
 1158        List<BaseComponentView> placeComponentsToAdd = InstantiateAndConfigurePlaceCards(places);
 1159        this.places.SetItems(placeComponentsToAdd);
 1160        placesNoDataText.gameObject.SetActive(places.Count == 0);
 1161    }
 162
 163    public void AddPlaces(List<PlaceCardComponentModel> places)
 164    {
 1165        List<BaseComponentView> placeComponentsToAdd = InstantiateAndConfigurePlaceCards(places);
 6166        foreach (var place in placeComponentsToAdd)
 167        {
 2168            this.places.AddItem(place);
 169        }
 1170    }
 171
 172    public void SetPlacesAsLoading(bool isVisible)
 173    {
 2174        places.gameObject.SetActive(!isVisible);
 2175        placesLoading.SetActive(isVisible);
 176
 2177        if (isVisible)
 1178            placesNoDataText.gameObject.SetActive(false);
 2179    }
 180
 4181    public void SetShowMorePlacesButtonActive(bool isActive) { showMorePlacesButtonContainer.gameObject.SetActive(isActi
 182
 183    public void ShowPlaceModal(PlaceCardComponentModel placeInfo)
 184    {
 1185        placeModal.Show();
 1186        ConfigurePlaceCard(placeModal, placeInfo);
 1187    }
 188
 2189    public void HidePlaceModal() { placeModal.Hide(); }
 190
 0191    public void RestartScrollViewPosition() { scrollView.verticalNormalizedPosition = 1; }
 192
 193    internal void ConfigurePlaceCardModal()
 194    {
 12195        placeModal = Instantiate(placeCardModalPrefab);
 12196        placeModal.Hide(true);
 12197    }
 198
 199    internal void ConfigurePlaceCardsPool()
 200    {
 12201        placeCardsPool = PoolManager.i.GetPool(PLACE_CARDS_POOL_NAME);
 12202        if (placeCardsPool == null)
 203        {
 1204            placeCardsPool = PoolManager.i.AddPool(
 205                PLACE_CARDS_POOL_NAME,
 206                Instantiate(placeCardPrefab).gameObject,
 207                maxPrewarmCount: 200,
 208                isPersistent: true);
 209        }
 12210    }
 211
 212    internal List<BaseComponentView> InstantiateAndConfigurePlaceCards(List<PlaceCardComponentModel> places)
 213    {
 2214        List<BaseComponentView> instantiatedPlaces = new List<BaseComponentView>();
 215
 12216        foreach (PlaceCardComponentModel placeInfo in places)
 217        {
 4218            PlaceCardComponentView placeGO = placeCardsPool.Get().gameObject.GetComponent<PlaceCardComponentView>();
 4219            ConfigurePlaceCard(placeGO, placeInfo);
 4220            OnFriendHandlerAdded?.Invoke(placeGO.friendsHandler);
 4221            instantiatedPlaces.Add(placeGO);
 222        }
 223
 2224        return instantiatedPlaces;
 225    }
 226
 227    internal void ConfigurePlaceCard(PlaceCardComponentView placeCard, PlaceCardComponentModel placeInfo)
 228    {
 6229        placeCard.Configure(placeInfo);
 6230        placeCard.onInfoClick?.RemoveAllListeners();
 6231        placeCard.onInfoClick?.AddListener(() => OnInfoClicked?.Invoke(placeInfo));
 6232        placeCard.onJumpInClick?.RemoveAllListeners();
 6233        placeCard.onJumpInClick?.AddListener(() => OnJumpInClicked?.Invoke(placeInfo.hotSceneInfo));
 6234    }
 235}