< 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:74
Uncovered lines:7
Coverable lines:81
Total lines:361
Line coverage:91.3% (74 of 81)
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.012087.5%
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    /// <summary>
 136    /// Configure the needed pools for the places and events instantiation.
 137    /// </summary>
 138    void ConfigurePools();
 139}
 140
 141public class HighlightsSubSectionComponentView : BaseComponentView, IHighlightsSubSectionComponentView
 142{
 143    internal const string TRENDING_PLACE_CARDS_POOL_NAME = "Highlights_TrendingPlaceCardsPool";
 144    internal const int TRENDING_PLACE_CARDS_POOL_PREWARM = 10;
 145    internal const string TRENDING_EVENT_CARDS_POOL_NAME = "Highlights_TrendingEventCardsPool";
 146    internal const int TRENDING_EVENT_CARDS_POOL_PREWARM = 10;
 147    internal const string FEATURED_PLACE_CARDS_POOL_NAME = "Highlights_FeaturedPlaceCardsPool";
 148    internal const int FEATURED_PLACE_CARDS_POOL_PREWARM = 9;
 149    internal const string LIVE_EVENT_CARDS_POOL_NAME = "Highlights_LiveEventCardsPool";
 150    internal const int LIVE_EVENT_CARDS_POOL_PREWARM = 3;
 151
 152    [Header("Assets References")]
 153    [SerializeField] internal PlaceCardComponentView placeCardLongPrefab;
 154    [SerializeField] internal EventCardComponentView eventCardLongPrefab;
 155    [SerializeField] internal PlaceCardComponentView placeCardPrefab;
 156    [SerializeField] internal PlaceCardComponentView placeCardModalPrefab;
 157    [SerializeField] internal EventCardComponentView eventCardPrefab;
 158    [SerializeField] internal EventCardComponentView eventCardModalPrefab;
 159
 160    [Header("Prefab References")]
 161    [SerializeField] internal ScrollRect scrollView;
 162    [SerializeField] internal CarouselComponentView trendingPlacesAndEvents;
 163    [SerializeField] internal GameObject trendingPlacesAndEventsLoading;
 164    [SerializeField] internal GridContainerComponentView featuredPlaces;
 165    [SerializeField] internal GameObject featuredPlacesLoading;
 166    [SerializeField] internal TMP_Text featuredPlacesNoDataText;
 167    [SerializeField] internal GridContainerComponentView liveEvents;
 168    [SerializeField] internal GameObject liveEventsLoading;
 169    [SerializeField] internal TMP_Text liveEventsNoDataText;
 170    [SerializeField] internal ButtonComponentView viewAllEventsButton;
 171    [SerializeField] internal Color[] friendColors = null;
 172
 173    public event Action OnReady;
 174    public event Action<PlaceCardComponentModel> OnPlaceInfoClicked;
 175    public event Action<EventCardComponentModel> OnEventInfoClicked;
 176    public event Action<HotScenesController.HotSceneInfo> OnPlaceJumpInClicked;
 177    public event Action<EventFromAPIModel> OnEventJumpInClicked;
 178    public event Action<string> OnEventSubscribeEventClicked;
 179    public event Action<string> OnEventUnsubscribeEventClicked;
 180    public event Action OnViewAllEventsClicked;
 181    public event Action<FriendsHandler> OnFriendHandlerAdded;
 182    public event Action OnHighlightsSubSectionEnable;
 183
 184    internal PlaceCardComponentView placeModal;
 185    internal EventCardComponentView eventModal;
 186    internal Pool trendingPlaceCardsPool;
 187    internal Pool trendingEventCardsPool;
 188    internal Pool featuredPlaceCardsPool;
 189    internal Pool liveEventCardsPool;
 190
 0191    public Color[] currentFriendColors => friendColors;
 192
 29193    public override void OnEnable() { OnHighlightsSubSectionEnable?.Invoke(); }
 194
 195    public void ConfigurePools()
 196    {
 13197        ExplorePlacesUtils.ConfigurePlaceCardsPool(out trendingPlaceCardsPool, TRENDING_PLACE_CARDS_POOL_NAME, placeCard
 13198        ExploreEventsUtils.ConfigureEventCardsPool(out trendingEventCardsPool, TRENDING_EVENT_CARDS_POOL_NAME, eventCard
 13199        ExplorePlacesUtils.ConfigurePlaceCardsPool(out featuredPlaceCardsPool, FEATURED_PLACE_CARDS_POOL_NAME, placeCard
 13200        ExploreEventsUtils.ConfigureEventCardsPool(out liveEventCardsPool, LIVE_EVENT_CARDS_POOL_NAME, eventCardPrefab, 
 13201    }
 202
 203    public override void Start()
 204    {
 13205        placeModal = ExplorePlacesUtils.ConfigurePlaceCardModal(placeCardModalPrefab);
 13206        eventModal = ExploreEventsUtils.ConfigureEventCardModal(eventCardModalPrefab);
 207
 13208        trendingPlacesAndEvents.RemoveItems();
 13209        featuredPlaces.RemoveItems();
 13210        liveEvents.RemoveItems();
 211
 13212        viewAllEventsButton.onClick.AddListener(() => OnViewAllEventsClicked?.Invoke());
 213
 13214        OnReady?.Invoke();
 0215    }
 216
 217    public override void RefreshControl()
 218    {
 0219        trendingPlacesAndEvents.RefreshControl();
 0220        featuredPlaces.RefreshControl();
 0221        liveEvents.RefreshControl();
 0222    }
 223
 224    public override void Dispose()
 225    {
 61226        base.Dispose();
 227
 61228        trendingPlacesAndEvents.Dispose();
 61229        featuredPlaces.Dispose();
 61230        liveEvents.Dispose();
 231
 61232        if (placeModal != null)
 233        {
 17234            placeModal.Dispose();
 17235            Destroy(placeModal.gameObject);
 236        }
 237
 61238        if (eventModal != null)
 239        {
 17240            eventModal.Dispose();
 17241            Destroy(eventModal.gameObject);
 242        }
 243
 61244        viewAllEventsButton.onClick.RemoveAllListeners();
 61245    }
 246
 247    public void SetTrendingPlacesAndEvents(List<PlaceCardComponentModel> places, List<EventCardComponentModel> events)
 248    {
 1249        List<BaseComponentView> placesAndEventsToSet = new List<BaseComponentView>();
 250
 1251        trendingPlacesAndEvents.ExtractItems();
 1252        trendingPlaceCardsPool.ReleaseAll();
 1253        trendingEventCardsPool.ReleaseAll();
 254
 1255        List<BaseComponentView> placeComponentsToAdd = ExplorePlacesUtils.InstantiateAndConfigurePlaceCards(
 256            places,
 257            trendingPlaceCardsPool,
 258            OnFriendHandlerAdded,
 259            OnPlaceInfoClicked,
 260            OnPlaceJumpInClicked);
 261
 1262        List<BaseComponentView> eventComponentsToAdd = ExploreEventsUtils.InstantiateAndConfigureEventCards(
 263            events,
 264            trendingEventCardsPool,
 265            OnEventInfoClicked,
 266            OnEventJumpInClicked,
 267            OnEventSubscribeEventClicked,
 268            OnEventUnsubscribeEventClicked);
 269
 270
 22271        for (int i = 0; i < HighlightsSubSectionComponentController.DEFAULT_NUMBER_OF_TRENDING_PLACES; i++)
 272        {
 10273            if (eventComponentsToAdd.Count - 1 >= i)
 2274                placesAndEventsToSet.Add(eventComponentsToAdd[i]);
 275
 10276            if (placeComponentsToAdd.Count - 1 >= i)
 2277                placesAndEventsToSet.Add(placeComponentsToAdd[i]);
 278        }
 279
 1280        trendingPlacesAndEvents.SetItems(placesAndEventsToSet);
 1281        SetTrendingPlacesAndEventsActive(placesAndEventsToSet.Count > 0);
 1282    }
 283
 284    public void SetTrendingPlacesAndEventsAsLoading(bool isVisible)
 285    {
 2286        SetTrendingPlacesAndEventsActive(!isVisible);
 2287        trendingPlacesAndEventsLoading.SetActive(isVisible);
 2288    }
 289
 10290    public void SetTrendingPlacesAndEventsActive(bool isActive) { trendingPlacesAndEvents.gameObject.SetActive(isActive)
 291
 292    public void SetFeaturedPlaces(List<PlaceCardComponentModel> places)
 293    {
 1294        featuredPlaces.ExtractItems();
 1295        featuredPlaceCardsPool.ReleaseAll();
 296
 1297        List<BaseComponentView> placeComponentsToAdd = ExplorePlacesUtils.InstantiateAndConfigurePlaceCards(
 298            places,
 299            featuredPlaceCardsPool,
 300            OnFriendHandlerAdded,
 301            OnPlaceInfoClicked,
 302            OnPlaceJumpInClicked);
 303
 1304        featuredPlaces.SetItems(placeComponentsToAdd);
 1305        featuredPlacesNoDataText.gameObject.SetActive(places.Count == 0);
 1306    }
 307
 308    public void SetFeaturedPlacesAsLoading(bool isVisible)
 309    {
 2310        featuredPlaces.gameObject.SetActive(!isVisible);
 2311        featuredPlacesLoading.SetActive(isVisible);
 312
 2313        if (isVisible)
 1314            featuredPlacesNoDataText.gameObject.SetActive(false);
 2315    }
 316
 317    public void SetLiveEvents(List<EventCardComponentModel> events)
 318    {
 1319        liveEvents.ExtractItems();
 1320        liveEventCardsPool.ReleaseAll();
 321
 1322        List<BaseComponentView> eventComponentsToAdd = ExploreEventsUtils.InstantiateAndConfigureEventCards(
 323            events,
 324            liveEventCardsPool,
 325            OnEventInfoClicked,
 326            OnEventJumpInClicked,
 327            OnEventSubscribeEventClicked,
 328            OnEventUnsubscribeEventClicked);
 329
 1330        liveEvents.SetItems(eventComponentsToAdd);
 1331        liveEventsNoDataText.gameObject.SetActive(events.Count == 0);
 1332    }
 333
 334    public void SetLiveAsLoading(bool isVisible)
 335    {
 2336        liveEvents.gameObject.SetActive(!isVisible);
 2337        liveEventsLoading.SetActive(isVisible);
 2338        viewAllEventsButton.gameObject.SetActive(!isVisible);
 339
 2340        if (isVisible)
 1341            liveEventsNoDataText.gameObject.SetActive(false);
 2342    }
 343
 344    public void ShowPlaceModal(PlaceCardComponentModel placeInfo)
 345    {
 1346        placeModal.Show();
 1347        ExplorePlacesUtils.ConfigurePlaceCard(placeModal, placeInfo, OnPlaceInfoClicked, OnPlaceJumpInClicked);
 1348    }
 349
 2350    public void HidePlaceModal() { placeModal.Hide(); }
 351
 352    public void ShowEventModal(EventCardComponentModel eventInfo)
 353    {
 1354        eventModal.Show();
 1355        ExploreEventsUtils.ConfigureEventCard(eventModal, eventInfo, OnEventInfoClicked, OnEventJumpInClicked, OnEventSu
 1356    }
 357
 2358    public void HideEventModal() { eventModal.Hide(); }
 359
 0360    public void RestartScrollViewPosition() { scrollView.verticalNormalizedPosition = 1; }
 361}