< 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:35
Uncovered lines:5
Coverable lines:40
Total lines:215
Line coverage:87.5% (35 of 40)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
OnEnable()0%2.52050%
ConfigurePools()0%110100%
Start()0%2.022083.33%
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%

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    /// <summary>
 91    /// Configure the needed pools for the places instantiation.
 92    /// </summary>
 93    void ConfigurePools();
 94}
 95
 96public class PlacesSubSectionComponentView : BaseComponentView, IPlacesSubSectionComponentView
 97{
 98    internal const string PLACE_CARDS_POOL_NAME = "Places_PlaceCardsPool";
 99    internal const int PLACE_CARDS_POOL_PREWARM = 20;
 100
 101    [Header("Assets References")]
 102    [SerializeField] internal PlaceCardComponentView placeCardPrefab;
 103    [SerializeField] internal PlaceCardComponentView placeCardModalPrefab;
 104
 105    [Header("Prefab References")]
 106    [SerializeField] internal ScrollRect scrollView;
 107    [SerializeField] internal GridContainerComponentView places;
 108    [SerializeField] internal GameObject placesLoading;
 109    [SerializeField] internal TMP_Text placesNoDataText;
 110    [SerializeField] internal Color[] friendColors = null;
 111    [SerializeField] internal GameObject showMorePlacesButtonContainer;
 112    [SerializeField] internal ButtonComponentView showMorePlacesButton;
 113
 114    public event Action OnReady;
 115    public event Action<PlaceCardComponentModel> OnInfoClicked;
 116    public event Action<HotScenesController.HotSceneInfo> OnJumpInClicked;
 117    public event Action<FriendsHandler> OnFriendHandlerAdded;
 118    public event Action OnPlacesSubSectionEnable;
 119    public event Action OnShowMorePlacesClicked;
 120
 121    internal PlaceCardComponentView placeModal;
 122    internal Pool placeCardsPool;
 123
 0124    public Color[] currentFriendColors => friendColors;
 125
 0126    public int currentPlacesPerRow => places.currentItemsPerRow;
 127
 13128    public override void OnEnable() { OnPlacesSubSectionEnable?.Invoke(); }
 129
 130    public void ConfigurePools()
 131    {
 11132        ExplorePlacesUtils.ConfigurePlaceCardsPool(out placeCardsPool, PLACE_CARDS_POOL_NAME, placeCardPrefab, PLACE_CAR
 11133    }
 134
 135    public override void Start()
 136    {
 11137        placeModal = ExplorePlacesUtils.ConfigurePlaceCardModal(placeCardModalPrefab);
 138
 11139        places.RemoveItems();
 140
 11141        showMorePlacesButton.onClick.RemoveAllListeners();
 11142        showMorePlacesButton.onClick.AddListener(() => OnShowMorePlacesClicked?.Invoke());
 143
 11144        OnReady?.Invoke();
 0145    }
 146
 0147    public override void RefreshControl() { places.RefreshControl(); }
 148
 149    public override void Dispose()
 150    {
 47151        base.Dispose();
 152
 47153        showMorePlacesButton.onClick.RemoveAllListeners();
 154
 47155        places.Dispose();
 156
 47157        if (placeModal != null)
 158        {
 15159            placeModal.Dispose();
 15160            Destroy(placeModal.gameObject);
 161        }
 47162    }
 163
 164    public void SetPlaces(List<PlaceCardComponentModel> places)
 165    {
 1166        this.places.ExtractItems();
 1167        placeCardsPool.ReleaseAll();
 168
 1169        List<BaseComponentView> placeComponentsToAdd = ExplorePlacesUtils.InstantiateAndConfigurePlaceCards(
 170            places,
 171            placeCardsPool,
 172            OnFriendHandlerAdded,
 173            OnInfoClicked,
 174            OnJumpInClicked);
 175
 1176        this.places.SetItems(placeComponentsToAdd);
 1177        placesNoDataText.gameObject.SetActive(places.Count == 0);
 1178    }
 179
 180    public void AddPlaces(List<PlaceCardComponentModel> places)
 181    {
 1182        List<BaseComponentView> placeComponentsToAdd = ExplorePlacesUtils.InstantiateAndConfigurePlaceCards(
 183            places,
 184            placeCardsPool,
 185            OnFriendHandlerAdded,
 186            OnInfoClicked,
 187            OnJumpInClicked);
 188
 6189        foreach (var place in placeComponentsToAdd)
 190        {
 2191            this.places.AddItem(place);
 192        }
 1193    }
 194
 195    public void SetPlacesAsLoading(bool isVisible)
 196    {
 2197        places.gameObject.SetActive(!isVisible);
 2198        placesLoading.SetActive(isVisible);
 199
 2200        if (isVisible)
 1201            placesNoDataText.gameObject.SetActive(false);
 2202    }
 203
 4204    public void SetShowMorePlacesButtonActive(bool isActive) { showMorePlacesButtonContainer.gameObject.SetActive(isActi
 205
 206    public void ShowPlaceModal(PlaceCardComponentModel placeInfo)
 207    {
 1208        placeModal.Show();
 1209        ExplorePlacesUtils.ConfigurePlaceCard(placeModal, placeInfo, OnInfoClicked, OnJumpInClicked);
 1210    }
 211
 2212    public void HidePlaceModal() { placeModal.Hide(); }
 213
 0214    public void RestartScrollViewPosition() { scrollView.verticalNormalizedPosition = 1; }
 215}