< Summary

Class:HighlightsSubSectionComponentView
Assembly:ExploreV2
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/Sections/PlacesAndEventsSection/SubSections/HighlightsSubSection/HighlightsSubSectionMenu/HighlightsSubSectionComponentView.cs
Covered lines:73
Uncovered lines:7
Coverable lines:80
Total lines:348
Line coverage:91.2% (73 of 80)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
OnEnable()0%2.52050%
Start()0%22091.67%
RefreshControl()0%2100%
Dispose()0%330100%
SetTrendingPlacesAndEvents(...)0%440100%
SetTrendingPlacesAndEventsAsLoading(...)0%110100%
SetTrendingPlacesAndEventsActive(...)0%110100%
SetFeaturedPlaces(...)0%110100%
SetFeaturedPlacesAsLoading(...)0%220100%
SetLiveEvents(...)0%110100%
SetLiveAsLoading(...)0%220100%
ShowPlaceModal(...)0%110100%
HidePlaceModal()0%110100%
ShowEventModal(...)0%110100%
HideEventModal()0%110100%
RestartScrollViewPosition()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/Sections/PlacesAndEventsSection/SubSections/HighlightsSubSection/HighlightsSubSectionMenu/HighlightsSubSectionComponentView.cs

#LineLine coverage
 1using DCL;
 2using System;
 3using System.Collections.Generic;
 4using TMPro;
 5using UnityEngine;
 6using UnityEngine.UI;
 7
 8public interface IHighlightsSubSectionComponentView
 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 place info button is clicked.
 17    /// </summary>
 18    event Action<PlaceCardComponentModel> OnPlaceInfoClicked;
 19
 20    /// <summary>
 21    /// It will be triggered when the event info button is clicked.
 22    /// </summary>
 23    event Action<EventCardComponentModel> OnEventInfoClicked;
 24
 25    /// <summary>
 26    /// It will be triggered when the place JumpIn button is clicked.
 27    /// </summary>
 28    event Action<HotScenesController.HotSceneInfo> OnPlaceJumpInClicked;
 29
 30    /// <summary>
 31    /// It will be triggered when the event JumpIn button is clicked.
 32    /// </summary>
 33    event Action<EventFromAPIModel> OnEventJumpInClicked;
 34
 35    /// <summary>
 36    /// It will be triggered when the subscribe event button is clicked.
 37    /// </summary>
 38    event Action<string> OnEventSubscribeEventClicked;
 39
 40    /// <summary>
 41    /// It will be triggered when the unsubscribe event button is clicked.
 42    /// </summary>
 43    event Action<string> OnEventUnsubscribeEventClicked;
 44
 45    /// <summary>
 46    /// It will be triggered when the view all events button is clicked.
 47    /// </summary>
 48    event Action OnViewAllEventsClicked;
 49
 50    /// <summary>
 51    /// It will be triggered when a new friend handler is added by a place card.
 52    /// </summary>
 53    event Action<FriendsHandler> OnFriendHandlerAdded;
 54
 55    /// <summary>
 56    /// It will be triggered each time the view is enabled.
 57    /// </summary>
 58    event Action OnHighlightsSubSectionEnable;
 59
 60    /// <summary>
 61    /// Colors used for the background of the friends heads.
 62    /// </summary>
 63    Color[] currentFriendColors { get; }
 64
 65    /// <summary>
 66    /// Set the trending places/events component with a list of places and events.
 67    /// </summary>
 68    /// <param name="places">List of places (model) to be loaded.</param>
 69    /// <param name="events">List of events (model) to be loaded.</param>
 70    void SetTrendingPlacesAndEvents(List<PlaceCardComponentModel> places, List<EventCardComponentModel> events);
 71
 72    /// <summary>
 73    /// Set the trending places and events component in loading mode.
 74    /// </summary>
 75    /// <param name="isVisible">True for activating the loading mode.</param>
 76    void SetTrendingPlacesAndEventsAsLoading(bool isVisible);
 77
 78    /// <summary>
 79    /// Activates/deactivates the trending places and events component.
 80    /// </summary>
 81    /// <param name="isActive">True for activating.</param>
 82    void SetTrendingPlacesAndEventsActive(bool isActive);
 83
 84    /// <summary>
 85    /// Set the featured places component with a list of places.
 86    /// </summary>
 87    /// <param name="places">List of places (model) to be loaded.</param>
 88    void SetFeaturedPlaces(List<PlaceCardComponentModel> places);
 89
 90    /// <summary>
 91    /// Set the featured places component in loading mode.
 92    /// </summary>
 93    /// <param name="isVisible">True for activating the loading mode.</param>
 94    void SetFeaturedPlacesAsLoading(bool isVisible);
 95
 96    /// <summary>
 97    /// Set the live events component with a list of places.
 98    /// </summary>
 99    /// <param name="events">List of events (model) to be loaded.</param>
 100    void SetLiveEvents(List<EventCardComponentModel> events);
 101
 102    /// <summary>
 103    /// Set the live events component in loading mode.
 104    /// </summary>
 105    /// <param name="isVisible">True for activating the loading mode.</param>
 106    void SetLiveAsLoading(bool isVisible);
 107
 108    /// <summary>
 109    /// Shows the Place Card modal with the provided information.
 110    /// </summary>
 111    /// <param name="placeInfo">Place (model) to be loaded in the card.</param>
 112    void ShowPlaceModal(PlaceCardComponentModel placeInfo);
 113
 114    /// <summary>
 115    /// Hides the Place Card modal.
 116    /// </summary>
 117    void HidePlaceModal();
 118
 119    /// <summary>
 120    /// Shows the Event Card modal with the provided information.
 121    /// </summary>
 122    /// <param name="eventInfo">Event (model) to be loaded in the card.</param>
 123    void ShowEventModal(EventCardComponentModel eventInfo);
 124
 125    /// <summary>
 126    /// Hides the Event Card modal.
 127    /// </summary>
 128    void HideEventModal();
 129
 130    /// <summary>
 131    /// Set the current scroll view position to 1.
 132    /// </summary>
 133    void RestartScrollViewPosition();
 134}
 135
 136public class HighlightsSubSectionComponentView : BaseComponentView, IHighlightsSubSectionComponentView
 137{
 138    internal const string TRENDING_PLACE_CARDS_POOL_NAME = "Highlights_TrendingPlaceCardsPool";
 139    internal const string TRENDING_EVENT_CARDS_POOL_NAME = "Highlights_TrendingEventCardsPool";
 140    internal const string FEATURED_PLACE_CARDS_POOL_NAME = "Highlights_FeaturedPlaceCardsPool";
 141    internal const string LIVE_EVENT_CARDS_POOL_NAME = "Highlights_LiveEventCardsPool";
 142
 143    [Header("Assets References")]
 144    [SerializeField] internal PlaceCardComponentView placeCardLongPrefab;
 145    [SerializeField] internal EventCardComponentView eventCardLongPrefab;
 146    [SerializeField] internal PlaceCardComponentView placeCardPrefab;
 147    [SerializeField] internal PlaceCardComponentView placeCardModalPrefab;
 148    [SerializeField] internal EventCardComponentView eventCardPrefab;
 149    [SerializeField] internal EventCardComponentView eventCardModalPrefab;
 150
 151    [Header("Prefab References")]
 152    [SerializeField] internal ScrollRect scrollView;
 153    [SerializeField] internal CarouselComponentView trendingPlacesAndEvents;
 154    [SerializeField] internal GameObject trendingPlacesAndEventsLoading;
 155    [SerializeField] internal GridContainerComponentView featuredPlaces;
 156    [SerializeField] internal GameObject featuredPlacesLoading;
 157    [SerializeField] internal TMP_Text featuredPlacesNoDataText;
 158    [SerializeField] internal GridContainerComponentView liveEvents;
 159    [SerializeField] internal GameObject liveEventsLoading;
 160    [SerializeField] internal TMP_Text liveEventsNoDataText;
 161    [SerializeField] internal ButtonComponentView viewAllEventsButton;
 162    [SerializeField] internal Color[] friendColors = null;
 163
 164    public event Action OnReady;
 165    public event Action<PlaceCardComponentModel> OnPlaceInfoClicked;
 166    public event Action<EventCardComponentModel> OnEventInfoClicked;
 167    public event Action<HotScenesController.HotSceneInfo> OnPlaceJumpInClicked;
 168    public event Action<EventFromAPIModel> OnEventJumpInClicked;
 169    public event Action<string> OnEventSubscribeEventClicked;
 170    public event Action<string> OnEventUnsubscribeEventClicked;
 171    public event Action OnViewAllEventsClicked;
 172    public event Action<FriendsHandler> OnFriendHandlerAdded;
 173    public event Action OnHighlightsSubSectionEnable;
 174
 175    internal PlaceCardComponentView placeModal;
 176    internal EventCardComponentView eventModal;
 177    internal Pool trendingPlaceCardsPool;
 178    internal Pool trendingEventCardsPool;
 179    internal Pool featuredPlaceCardsPool;
 180    internal Pool liveEventCardsPool;
 181
 0182    public Color[] currentFriendColors => friendColors;
 183
 66184    public override void OnEnable() { OnHighlightsSubSectionEnable?.Invoke(); }
 185
 186    public override void Start()
 187    {
 13188        placeModal = ExplorePlacesHelpers.ConfigurePlaceCardModal(placeCardModalPrefab);
 13189        eventModal = ExploreEventsHelpers.ConfigureEventCardModal(eventCardModalPrefab);
 13190        ExplorePlacesHelpers.ConfigurePlaceCardsPool(out trendingPlaceCardsPool, TRENDING_PLACE_CARDS_POOL_NAME, placeCa
 13191        ExploreEventsHelpers.ConfigureEventCardsPool(out trendingEventCardsPool, TRENDING_EVENT_CARDS_POOL_NAME, eventCa
 13192        ExplorePlacesHelpers.ConfigurePlaceCardsPool(out featuredPlaceCardsPool, FEATURED_PLACE_CARDS_POOL_NAME, placeCa
 13193        ExploreEventsHelpers.ConfigureEventCardsPool(out liveEventCardsPool, LIVE_EVENT_CARDS_POOL_NAME, eventCardPrefab
 194
 13195        trendingPlacesAndEvents.RemoveItems();
 13196        featuredPlaces.RemoveItems();
 13197        liveEvents.RemoveItems();
 198
 13199        viewAllEventsButton.onClick.AddListener(() => OnViewAllEventsClicked?.Invoke());
 200
 13201        OnReady?.Invoke();
 0202    }
 203
 204    public override void RefreshControl()
 205    {
 0206        trendingPlacesAndEvents.RefreshControl();
 0207        featuredPlaces.RefreshControl();
 0208        liveEvents.RefreshControl();
 0209    }
 210
 211    public override void Dispose()
 212    {
 136213        base.Dispose();
 214
 136215        trendingPlacesAndEvents.Dispose();
 136216        featuredPlaces.Dispose();
 136217        liveEvents.Dispose();
 218
 136219        if (placeModal != null)
 220        {
 17221            placeModal.Dispose();
 17222            Destroy(placeModal.gameObject);
 223        }
 224
 136225        if (eventModal != null)
 226        {
 17227            eventModal.Dispose();
 17228            Destroy(eventModal.gameObject);
 229        }
 230
 136231        viewAllEventsButton.onClick.RemoveAllListeners();
 136232    }
 233
 234    public void SetTrendingPlacesAndEvents(List<PlaceCardComponentModel> places, List<EventCardComponentModel> events)
 235    {
 1236        List<BaseComponentView> placesAndEventsToSet = new List<BaseComponentView>();
 237
 1238        trendingPlacesAndEvents.ExtractItems();
 1239        trendingPlaceCardsPool.ReleaseAll();
 1240        trendingEventCardsPool.ReleaseAll();
 241
 1242        List<BaseComponentView> placeComponentsToAdd = ExplorePlacesHelpers.InstantiateAndConfigurePlaceCards(
 243            places,
 244            trendingPlaceCardsPool,
 245            OnFriendHandlerAdded,
 246            OnPlaceInfoClicked,
 247            OnPlaceJumpInClicked);
 248
 1249        List<BaseComponentView> eventComponentsToAdd = ExploreEventsHelpers.InstantiateAndConfigureEventCards(
 250            events,
 251            trendingEventCardsPool,
 252            OnEventInfoClicked,
 253            OnEventJumpInClicked,
 254            OnEventSubscribeEventClicked,
 255            OnEventUnsubscribeEventClicked);
 256
 257
 22258        for (int i = 0; i < HighlightsSubSectionComponentController.DEFAULT_NUMBER_OF_TRENDING_PLACES; i++)
 259        {
 10260            if (eventComponentsToAdd.Count - 1 >= i)
 2261                placesAndEventsToSet.Add(eventComponentsToAdd[i]);
 262
 10263            if (placeComponentsToAdd.Count - 1 >= i)
 2264                placesAndEventsToSet.Add(placeComponentsToAdd[i]);
 265        }
 266
 1267        trendingPlacesAndEvents.SetItems(placesAndEventsToSet);
 1268        SetTrendingPlacesAndEventsActive(placesAndEventsToSet.Count > 0);
 1269    }
 270
 271    public void SetTrendingPlacesAndEventsAsLoading(bool isVisible)
 272    {
 2273        SetTrendingPlacesAndEventsActive(!isVisible);
 2274        trendingPlacesAndEventsLoading.SetActive(isVisible);
 2275    }
 276
 10277    public void SetTrendingPlacesAndEventsActive(bool isActive) { trendingPlacesAndEvents.gameObject.SetActive(isActive)
 278
 279    public void SetFeaturedPlaces(List<PlaceCardComponentModel> places)
 280    {
 1281        featuredPlaces.ExtractItems();
 1282        featuredPlaceCardsPool.ReleaseAll();
 283
 1284        List<BaseComponentView> placeComponentsToAdd = ExplorePlacesHelpers.InstantiateAndConfigurePlaceCards(
 285            places,
 286            featuredPlaceCardsPool,
 287            OnFriendHandlerAdded,
 288            OnPlaceInfoClicked,
 289            OnPlaceJumpInClicked);
 290
 1291        featuredPlaces.SetItems(placeComponentsToAdd);
 1292        featuredPlacesNoDataText.gameObject.SetActive(places.Count == 0);
 1293    }
 294
 295    public void SetFeaturedPlacesAsLoading(bool isVisible)
 296    {
 2297        featuredPlaces.gameObject.SetActive(!isVisible);
 2298        featuredPlacesLoading.SetActive(isVisible);
 299
 2300        if (isVisible)
 1301            featuredPlacesNoDataText.gameObject.SetActive(false);
 2302    }
 303
 304    public void SetLiveEvents(List<EventCardComponentModel> events)
 305    {
 1306        liveEvents.ExtractItems();
 1307        liveEventCardsPool.ReleaseAll();
 308
 1309        List<BaseComponentView> eventComponentsToAdd = ExploreEventsHelpers.InstantiateAndConfigureEventCards(
 310            events,
 311            liveEventCardsPool,
 312            OnEventInfoClicked,
 313            OnEventJumpInClicked,
 314            OnEventSubscribeEventClicked,
 315            OnEventUnsubscribeEventClicked);
 316
 1317        liveEvents.SetItems(eventComponentsToAdd);
 1318        liveEventsNoDataText.gameObject.SetActive(events.Count == 0);
 1319    }
 320
 321    public void SetLiveAsLoading(bool isVisible)
 322    {
 2323        liveEvents.gameObject.SetActive(!isVisible);
 2324        liveEventsLoading.SetActive(isVisible);
 2325        viewAllEventsButton.gameObject.SetActive(!isVisible);
 326
 2327        if (isVisible)
 1328            liveEventsNoDataText.gameObject.SetActive(false);
 2329    }
 330
 331    public void ShowPlaceModal(PlaceCardComponentModel placeInfo)
 332    {
 1333        placeModal.Show();
 1334        ExplorePlacesHelpers.ConfigurePlaceCard(placeModal, placeInfo, OnPlaceInfoClicked, OnPlaceJumpInClicked);
 1335    }
 336
 2337    public void HidePlaceModal() { placeModal.Hide(); }
 338
 339    public void ShowEventModal(EventCardComponentModel eventInfo)
 340    {
 1341        eventModal.Show();
 1342        ExploreEventsHelpers.ConfigureEventCard(eventModal, eventInfo, OnEventInfoClicked, OnEventJumpInClicked, OnEvent
 1343    }
 344
 2345    public void HideEventModal() { eventModal.Hide(); }
 346
 0347    public void RestartScrollViewPosition() { scrollView.verticalNormalizedPosition = 1; }
 348}