< 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:34
Uncovered lines:5
Coverable lines:39
Total lines:205
Line coverage:87.1% (34 of 39)
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%

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 = "Places_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
 13122    public override void OnEnable() { OnPlacesSubSectionEnable?.Invoke(); }
 123
 124    public override void Start()
 125    {
 11126        placeModal = ExplorePlacesHelpers.ConfigurePlaceCardModal(placeCardModalPrefab);
 11127        ExplorePlacesHelpers.ConfigurePlaceCardsPool(out placeCardsPool, PLACE_CARDS_POOL_NAME, placeCardPrefab, 200);
 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    {
 85141        base.Dispose();
 142
 85143        showMorePlacesButton.onClick.RemoveAllListeners();
 144
 85145        places.Dispose();
 146
 85147        if (placeModal != null)
 148        {
 15149            placeModal.Dispose();
 15150            Destroy(placeModal.gameObject);
 151        }
 85152    }
 153
 154    public void SetPlaces(List<PlaceCardComponentModel> places)
 155    {
 1156        this.places.ExtractItems();
 1157        placeCardsPool.ReleaseAll();
 158
 1159        List<BaseComponentView> placeComponentsToAdd = ExplorePlacesHelpers.InstantiateAndConfigurePlaceCards(
 160            places,
 161            placeCardsPool,
 162            OnFriendHandlerAdded,
 163            OnInfoClicked,
 164            OnJumpInClicked);
 165
 1166        this.places.SetItems(placeComponentsToAdd);
 1167        placesNoDataText.gameObject.SetActive(places.Count == 0);
 1168    }
 169
 170    public void AddPlaces(List<PlaceCardComponentModel> places)
 171    {
 1172        List<BaseComponentView> placeComponentsToAdd = ExplorePlacesHelpers.InstantiateAndConfigurePlaceCards(
 173            places,
 174            placeCardsPool,
 175            OnFriendHandlerAdded,
 176            OnInfoClicked,
 177            OnJumpInClicked);
 178
 6179        foreach (var place in placeComponentsToAdd)
 180        {
 2181            this.places.AddItem(place);
 182        }
 1183    }
 184
 185    public void SetPlacesAsLoading(bool isVisible)
 186    {
 2187        places.gameObject.SetActive(!isVisible);
 2188        placesLoading.SetActive(isVisible);
 189
 2190        if (isVisible)
 1191            placesNoDataText.gameObject.SetActive(false);
 2192    }
 193
 4194    public void SetShowMorePlacesButtonActive(bool isActive) { showMorePlacesButtonContainer.gameObject.SetActive(isActi
 195
 196    public void ShowPlaceModal(PlaceCardComponentModel placeInfo)
 197    {
 1198        placeModal.Show();
 1199        ExplorePlacesHelpers.ConfigurePlaceCard(placeModal, placeInfo, OnInfoClicked, OnJumpInClicked);
 1200    }
 201
 2202    public void HidePlaceModal() { placeModal.Hide(); }
 203
 0204    public void RestartScrollViewPosition() { scrollView.verticalNormalizedPosition = 1; }
 205}