< Summary

Class:HighlightsSubSectionComponentController
Assembly:ExploreV2
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/Sections/PlacesAndEventsSection/SubSections/HighlightsSubSection/HighlightsSubSectionMenu/HighlightsSubSectionComponentController.cs
Covered lines:74
Uncovered lines:25
Coverable lines:99
Total lines:214
Line coverage:74.7% (74 of 99)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
HighlightsSubSectionComponentController(...)0%110100%
Dispose()0%110100%
FirstLoading()0%2100%
RequestAllPlacesAndEvents()0%220100%
RequestAllFromAPI()0%110100%
OnRequestedPlacesAndEventsUpdated()0%110100%
FilterTrendingPlaces()0%110100%
FilterLiveEvents()0%220100%
FilterTrendingEvents(...)0%220100%
FilterFeaturedPlaces()0%5.264057.14%
View_OnFriendHandlerAdded(...)0%2100%
ShowPlaceDetailedInfo(...)0%110100%
ShowEventDetailedInfo(...)0%110100%
JumpInToPlace(...)0%220100%
JumpInToEvent(...)0%220100%
SubscribeToEvent(...)0%2100%
UnsubscribeToEvent(...)0%2100%
GoToEventsSubSection()0%220100%
OnChannelToJoinChanged(...)0%12300%

File(s)

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

#LineLine coverage
 1using DCL;
 2using DCL.Social.Friends;
 3using ExploreV2Analytics;
 4using System;
 5using System.Collections.Generic;
 6using System.Linq;
 7using UnityEngine;
 8using static HotScenesController;
 9
 10public class HighlightsSubSectionComponentController : IHighlightsSubSectionComponentController, IPlacesAndEventsAPIRequ
 11{
 12    public event Action OnCloseExploreV2;
 13    public event Action OnGoToEventsSubSection;
 14
 15    internal const int DEFAULT_NUMBER_OF_TRENDING_PLACES = 10;
 16    private const int DEFAULT_NUMBER_OF_FEATURED_PLACES = 9;
 17    private const int DEFAULT_NUMBER_OF_LIVE_EVENTS = 3;
 18
 19    internal readonly IHighlightsSubSectionComponentView view;
 20    internal readonly IPlacesAPIController placesAPIApiController;
 21    internal readonly IEventsAPIController eventsAPIApiController;
 22    internal readonly FriendTrackerController friendsTrackerController;
 23    private readonly IExploreV2Analytics exploreV2Analytics;
 24    private readonly DataStore dataStore;
 25
 26    internal readonly PlaceAndEventsCardsReloader cardsReloader;
 27
 2128    internal List<HotSceneInfo> placesFromAPI = new ();
 2129    internal List<EventFromAPIModel> eventsFromAPI = new ();
 30
 2131    public HighlightsSubSectionComponentController(IHighlightsSubSectionComponentView view, IPlacesAPIController placesA
 32        DataStore dataStore)
 33    {
 2134        cardsReloader = new PlaceAndEventsCardsReloader(view, this, dataStore.exploreV2);
 35
 2136        this.view = view;
 37
 2138        this.view.OnReady += FirstLoading;
 39
 2140        this.view.OnPlaceInfoClicked += ShowPlaceDetailedInfo;
 2141        this.view.OnPlaceJumpInClicked += JumpInToPlace;
 42
 2143        this.view.OnEventInfoClicked += ShowEventDetailedInfo;
 2144        this.view.OnEventJumpInClicked += JumpInToEvent;
 45
 2146        this.view.OnEventSubscribeEventClicked += SubscribeToEvent;
 2147        this.view.OnEventUnsubscribeEventClicked += UnsubscribeToEvent;
 48
 2149        this.view.OnViewAllEventsClicked += GoToEventsSubSection;
 50
 2151        this.view.OnFriendHandlerAdded += View_OnFriendHandlerAdded;
 52
 2153        this.dataStore = dataStore;
 2154        this.dataStore.channels.currentJoinChannelModal.OnChange += OnChannelToJoinChanged;
 55
 2156        placesAPIApiController = placesAPI;
 2157        eventsAPIApiController = eventsAPI;
 58
 2159        friendsTrackerController = new FriendTrackerController(friendsController, view.currentFriendColors);
 60
 2161        this.exploreV2Analytics = exploreV2Analytics;
 62
 2163        view.ConfigurePools();
 2164    }
 65
 66    public void Dispose()
 67    {
 2168        view.OnReady -= FirstLoading;
 69
 2170        view.OnPlaceInfoClicked -= ShowPlaceDetailedInfo;
 2171        view.OnEventInfoClicked -= ShowEventDetailedInfo;
 72
 2173        view.OnPlaceJumpInClicked -= JumpInToPlace;
 2174        view.OnEventJumpInClicked -= JumpInToEvent;
 75
 2176        view.OnEventSubscribeEventClicked -= SubscribeToEvent;
 2177        view.OnEventUnsubscribeEventClicked -= UnsubscribeToEvent;
 78
 2179        view.OnFriendHandlerAdded -= View_OnFriendHandlerAdded;
 80
 2181        view.OnViewAllEventsClicked -= GoToEventsSubSection;
 82
 2183        dataStore.channels.currentJoinChannelModal.OnChange -= OnChannelToJoinChanged;
 84
 2185        cardsReloader.Dispose();
 2186    }
 87
 88    private void FirstLoading()
 89    {
 090        view.OnHighlightsSubSectionEnable += RequestAllPlacesAndEvents;
 091        cardsReloader.Initialize();
 092    }
 93
 94    internal void RequestAllPlacesAndEvents()
 95    {
 296        if (cardsReloader.CanReload())
 297            cardsReloader.RequestAll();
 298    }
 99
 100    public void RequestAllFromAPI()
 101    {
 2102        placesAPIApiController.GetAllPlaces(
 103            OnCompleted: placeList =>
 104            {
 0105                placesFromAPI = placeList;
 106
 0107                eventsAPIApiController.GetAllEvents(
 108                    OnSuccess: eventList =>
 109                    {
 0110                        eventsFromAPI = eventList;
 0111                        OnRequestedPlacesAndEventsUpdated();
 0112                    },
 113                    OnFail: error =>
 114                    {
 0115                        OnRequestedPlacesAndEventsUpdated();
 0116                        Debug.LogError($"Error receiving events from the API: {error}");
 0117                    });
 0118            });
 2119    }
 120
 121    internal void OnRequestedPlacesAndEventsUpdated()
 122    {
 1123        friendsTrackerController.RemoveAllHandlers();
 124
 1125        List<PlaceCardComponentModel> trendingPlaces = PlacesAndEventsCardsFactory.CreatePlacesCards(FilterTrendingPlace
 1126        List<EventCardComponentModel> trendingEvents = PlacesAndEventsCardsFactory.CreateEventsCards(FilterTrendingEvent
 1127        view.SetTrendingPlacesAndEvents(trendingPlaces, trendingEvents);
 128
 1129        view.SetFeaturedPlaces(PlacesAndEventsCardsFactory.CreatePlacesCards(FilterFeaturedPlaces()));
 1130        view.SetLiveEvents(PlacesAndEventsCardsFactory.CreateEventsCards(FilterLiveEvents()));
 1131    }
 132
 2133    internal List<HotSceneInfo> FilterTrendingPlaces() => placesFromAPI.Take(DEFAULT_NUMBER_OF_TRENDING_PLACES).ToList()
 6134    internal List<EventFromAPIModel> FilterLiveEvents() => eventsFromAPI.Where(x => x.live).Take(DEFAULT_NUMBER_OF_LIVE_
 6135    internal List<EventFromAPIModel> FilterTrendingEvents(int amount) => eventsFromAPI.Where(e => e.highlighted).Take(am
 136    internal List<HotSceneInfo> FilterFeaturedPlaces()
 137    {
 138        List<HotSceneInfo> featuredPlaces;
 139
 2140        if (placesFromAPI.Count >= DEFAULT_NUMBER_OF_TRENDING_PLACES)
 141        {
 0142            int numberOfPlaces = placesFromAPI.Count >= (DEFAULT_NUMBER_OF_TRENDING_PLACES + DEFAULT_NUMBER_OF_FEATURED_
 143                ? DEFAULT_NUMBER_OF_FEATURED_PLACES
 144                : placesFromAPI.Count - DEFAULT_NUMBER_OF_TRENDING_PLACES;
 145
 0146            featuredPlaces = placesFromAPI
 147                            .GetRange(DEFAULT_NUMBER_OF_TRENDING_PLACES, numberOfPlaces)
 148                            .ToList();
 149        }
 2150        else if (placesFromAPI.Count > 0)
 2151            featuredPlaces = placesFromAPI.Take(DEFAULT_NUMBER_OF_FEATURED_PLACES).ToList();
 152        else
 0153            featuredPlaces = new List<HotSceneInfo>();
 154
 2155        return featuredPlaces;
 156    }
 157
 158    private void View_OnFriendHandlerAdded(FriendsHandler friendsHandler) =>
 0159        friendsTrackerController.AddHandler(friendsHandler);
 160
 161    internal void ShowPlaceDetailedInfo(PlaceCardComponentModel placeModel)
 162    {
 1163        view.ShowPlaceModal(placeModel);
 1164        exploreV2Analytics.SendClickOnPlaceInfo(placeModel.hotSceneInfo.id, placeModel.placeName);
 1165        dataStore.exploreV2.currentVisibleModal.Set(ExploreV2CurrentModal.Places);
 1166    }
 167
 168    internal void ShowEventDetailedInfo(EventCardComponentModel eventModel)
 169    {
 1170        view.ShowEventModal(eventModel);
 1171        exploreV2Analytics.SendClickOnEventInfo(eventModel.eventId, eventModel.eventName);
 1172        dataStore.exploreV2.currentVisibleModal.Set(ExploreV2CurrentModal.Events);
 1173    }
 174
 175    internal void JumpInToPlace(HotSceneInfo placeFromAPI)
 176    {
 1177        PlacesSubSectionComponentController.JumpInToPlace(placeFromAPI);
 1178        view.HidePlaceModal();
 179
 1180        dataStore.exploreV2.currentVisibleModal.Set(ExploreV2CurrentModal.None);
 1181        OnCloseExploreV2?.Invoke();
 1182        exploreV2Analytics.SendPlaceTeleport(placeFromAPI.id, placeFromAPI.name, placeFromAPI.baseCoords);
 1183    }
 184
 185    internal void JumpInToEvent(EventFromAPIModel eventFromAPI)
 186    {
 1187        EventsSubSectionComponentController.JumpInToEvent(eventFromAPI);
 1188        view.HideEventModal();
 189
 1190        dataStore.exploreV2.currentVisibleModal.Set(ExploreV2CurrentModal.None);
 1191        OnCloseExploreV2?.Invoke();
 1192        exploreV2Analytics.SendEventTeleport(eventFromAPI.id, eventFromAPI.name, new Vector2Int(eventFromAPI.coordinates
 1193    }
 194
 195    private static void SubscribeToEvent(string eventId) =>
 0196        EventsSubSectionComponentController.SubscribeToEvent(eventId);
 197
 198    private static void UnsubscribeToEvent(string eventId) =>
 0199        EventsSubSectionComponentController.UnsubscribeToEvent(eventId);
 200
 201    internal void GoToEventsSubSection() =>
 1202        OnGoToEventsSubSection?.Invoke();
 203
 204    private void OnChannelToJoinChanged(string currentChannelId, string previousChannelId)
 205    {
 0206        if (!string.IsNullOrEmpty(currentChannelId))
 0207            return;
 208
 0209        view.HidePlaceModal();
 0210        view.HideEventModal();
 0211        dataStore.exploreV2.currentVisibleModal.Set(ExploreV2CurrentModal.None);
 0212        OnCloseExploreV2?.Invoke();
 0213    }
 214}