< Summary

Class:PlacesSubSectionComponentController
Assembly:ExploreV2
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/Sections/PlacesAndEventsSection/SubSections/PlacesSubSection/PlacesSubSectionMenu/PlacesSubSectionComponentController.cs
Covered lines:67
Uncovered lines:20
Coverable lines:87
Total lines:193
Line coverage:77% (67 of 87)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
PlacesSubSectionComponentController(...)0%110100%
FirstLoading()0%110100%
OnExploreV2Open(...)0%6200%
RequestAllPlaces()0%3.183072.73%
IsInShowAnimationTransitonChanged(...)0%2100%
RequestAllPlacesFromAPI()0%110100%
OnRequestedPlacesUpdated()0%110100%
LoadPlaces()0%2.062075%
ShowMorePlaces()0%4.344072.22%
Dispose()0%110100%
ShowPlaceDetailedInfo(...)0%110100%
JumpInToPlace(...)0%220100%
View_OnFriendHandlerAdded(...)0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/Sections/PlacesAndEventsSection/SubSections/PlacesSubSection/PlacesSubSectionMenu/PlacesSubSectionComponentController.cs

#LineLine coverage
 1using DCL;
 2using ExploreV2Analytics;
 3using System;
 4using System.Collections.Generic;
 5using System.Linq;
 6using UnityEngine;
 7using static HotScenesController;
 8
 9public interface IPlacesSubSectionComponentController : IDisposable
 10{
 11    /// <summary>
 12    /// It will be triggered when the sub-section want to request to close the ExploreV2 main menu.
 13    /// </summary>
 14    event Action OnCloseExploreV2;
 15
 16    /// <summary>
 17    /// Request all places from the API.
 18    /// </summary>
 19    void RequestAllPlaces();
 20
 21    /// <summary>
 22    /// Load the places with the last requested ones.
 23    /// </summary>
 24    void LoadPlaces();
 25
 26    /// <summary>
 27    /// Increment the number of places loaded.
 28    /// </summary>
 29    void ShowMorePlaces();
 30}
 31
 32public class PlacesSubSectionComponentController : IPlacesSubSectionComponentController
 33{
 34    public event Action OnCloseExploreV2;
 35    internal event Action OnPlacesFromAPIUpdated;
 36
 37    internal const int INITIAL_NUMBER_OF_ROWS = 5;
 38    internal const int SHOW_MORE_ROWS_INCREMENT = 3;
 39    internal IPlacesSubSectionComponentView view;
 40    internal IPlacesAPIController placesAPIApiController;
 41    internal FriendTrackerController friendsTrackerController;
 1842    internal List<HotSceneInfo> placesFromAPI = new List<HotSceneInfo>();
 43    internal int currentPlacesShowed = 0;
 44    internal bool reloadPlaces = false;
 45    internal IExploreV2Analytics exploreV2Analytics;
 46
 1847    public PlacesSubSectionComponentController(
 48        IPlacesSubSectionComponentView view,
 49        IPlacesAPIController placesAPI,
 50        IFriendsController friendsController,
 51        IExploreV2Analytics exploreV2Analytics)
 52    {
 1853        this.view = view;
 1854        this.view.OnReady += FirstLoading;
 1855        this.view.OnInfoClicked += ShowPlaceDetailedInfo;
 1856        this.view.OnJumpInClicked += JumpInToPlace;
 1857        this.view.OnFriendHandlerAdded += View_OnFriendHandlerAdded;
 1858        this.view.OnShowMorePlacesClicked += ShowMorePlaces;
 59
 1860        placesAPIApiController = placesAPI;
 1861        OnPlacesFromAPIUpdated += OnRequestedPlacesUpdated;
 62
 1863        friendsTrackerController = new FriendTrackerController(friendsController, view.currentFriendColors);
 64
 1865        this.exploreV2Analytics = exploreV2Analytics;
 66
 1867        view.ConfigurePools();
 1868    }
 69
 70    internal void FirstLoading()
 71    {
 172        reloadPlaces = true;
 173        RequestAllPlaces();
 74
 175        view.OnPlacesSubSectionEnable += RequestAllPlaces;
 176        DataStore.i.exploreV2.isOpen.OnChange += OnExploreV2Open;
 177    }
 78
 79    internal void OnExploreV2Open(bool current, bool previous)
 80    {
 081        if (current)
 082            return;
 83
 084        reloadPlaces = true;
 085    }
 86
 87    public void RequestAllPlaces()
 88    {
 289        if (!reloadPlaces)
 090            return;
 91
 292        currentPlacesShowed = view.currentPlacesPerRow * INITIAL_NUMBER_OF_ROWS;
 293        view.RestartScrollViewPosition();
 294        view.SetPlacesAsLoading(true);
 295        view.SetShowMorePlacesButtonActive(false);
 296        reloadPlaces = false;
 97
 298        if (!DataStore.i.exploreV2.isInShowAnimationTransiton.Get())
 299            RequestAllPlacesFromAPI();
 100        else
 0101            DataStore.i.exploreV2.isInShowAnimationTransiton.OnChange += IsInShowAnimationTransitonChanged;
 0102    }
 103
 104    internal void IsInShowAnimationTransitonChanged(bool current, bool previous)
 105    {
 0106        DataStore.i.exploreV2.isInShowAnimationTransiton.OnChange -= IsInShowAnimationTransitonChanged;
 0107        RequestAllPlacesFromAPI();
 0108    }
 109
 110    internal void RequestAllPlacesFromAPI()
 111    {
 3112        placesAPIApiController.GetAllPlaces(
 113            (placeList) =>
 114            {
 0115                placesFromAPI = placeList;
 0116                OnPlacesFromAPIUpdated?.Invoke();
 0117            });
 3118    }
 119
 2120    internal void OnRequestedPlacesUpdated() { LoadPlaces(); }
 121
 122    public void LoadPlaces()
 123    {
 2124        friendsTrackerController.RemoveAllHandlers();
 125
 2126        List<PlaceCardComponentModel> places = new List<PlaceCardComponentModel>();
 2127        List<HotSceneInfo> placesFiltered = placesFromAPI.Take(currentPlacesShowed).ToList();
 4128        foreach (HotSceneInfo receivedPlace in placesFiltered)
 129        {
 0130            PlaceCardComponentModel placeCardModel = ExplorePlacesUtils.CreatePlaceCardModelFromAPIPlace(receivedPlace);
 0131            places.Add(placeCardModel);
 132        }
 133
 2134        view.SetPlaces(places);
 2135        view.SetShowMorePlacesButtonActive(currentPlacesShowed < placesFromAPI.Count);
 2136        view.SetPlacesAsLoading(false);
 2137    }
 138
 139    public void ShowMorePlaces()
 140    {
 2141        List<PlaceCardComponentModel> places = new List<PlaceCardComponentModel>();
 2142        List<HotSceneInfo> placesFiltered = new List<HotSceneInfo>();
 2143        int numberOfExtraItemsToAdd = ((int)Mathf.Ceil((float)currentPlacesShowed / view.currentPlacesPerRow) * view.cur
 2144        int numberOfItemsToAdd = view.currentPlacesPerRow * SHOW_MORE_ROWS_INCREMENT + numberOfExtraItemsToAdd;
 145
 2146        if (currentPlacesShowed + numberOfItemsToAdd <= placesFromAPI.Count)
 2147            placesFiltered = placesFromAPI.GetRange(currentPlacesShowed, numberOfItemsToAdd);
 148        else
 0149            placesFiltered = placesFromAPI.GetRange(currentPlacesShowed, placesFromAPI.Count - currentPlacesShowed);
 150
 4151        foreach (HotSceneInfo receivedPlace in placesFiltered)
 152        {
 0153            PlaceCardComponentModel placeCardModel = ExplorePlacesUtils.CreatePlaceCardModelFromAPIPlace(receivedPlace);
 0154            places.Add(placeCardModel);
 155        }
 156
 2157        view.AddPlaces(places);
 158
 2159        currentPlacesShowed += numberOfItemsToAdd;
 2160        if (currentPlacesShowed > placesFromAPI.Count)
 0161            currentPlacesShowed = placesFromAPI.Count;
 162
 2163        view.SetShowMorePlacesButtonActive(currentPlacesShowed < placesFromAPI.Count);
 2164    }
 165
 166    public void Dispose()
 167    {
 18168        view.OnReady -= FirstLoading;
 18169        view.OnInfoClicked -= ShowPlaceDetailedInfo;
 18170        view.OnJumpInClicked -= JumpInToPlace;
 18171        view.OnPlacesSubSectionEnable -= RequestAllPlaces;
 18172        view.OnFriendHandlerAdded -= View_OnFriendHandlerAdded;
 18173        view.OnShowMorePlacesClicked -= ShowMorePlaces;
 18174        OnPlacesFromAPIUpdated -= OnRequestedPlacesUpdated;
 18175        DataStore.i.exploreV2.isOpen.OnChange -= OnExploreV2Open;
 18176    }
 177
 178    internal void ShowPlaceDetailedInfo(PlaceCardComponentModel placeModel)
 179    {
 1180        view.ShowPlaceModal(placeModel);
 1181        exploreV2Analytics.SendClickOnPlaceInfo(placeModel.hotSceneInfo.id, placeModel.placeName);
 1182    }
 183
 184    internal void JumpInToPlace(HotSceneInfo placeFromAPI)
 185    {
 1186        ExplorePlacesUtils.JumpInToPlace(placeFromAPI);
 1187        view.HidePlaceModal();
 1188        OnCloseExploreV2?.Invoke();
 1189        exploreV2Analytics.SendPlaceTeleport(placeFromAPI.id, placeFromAPI.name, placeFromAPI.baseCoords);
 1190    }
 191
 0192    internal void View_OnFriendHandlerAdded(FriendsHandler friendsHandler) { friendsTrackerController.AddHandler(friends
 193}