< Summary

Class:FavoriteSubSectionComponentView
Assembly:ExploreV2
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/Sections/PlacesAndEventsSection/SubSections/PlacesSubSection/FavoritesSubSection/FavoriteSubSectionComponentView.cs
Covered lines:58
Uncovered lines:151
Coverable lines:209
Total lines:408
Line coverage:27.7% (58 of 209)
Covered branches:0
Total branches:0
Covered methods:11
Total methods:34
Method coverage:32.3% (11 of 34)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
FavoriteSubSectionComponentView()0%110100%
Awake()0%110100%
InitialiseButtonEvents()0%550100%
RequestAdditionalPage()0%30500%
OnBackButtonPressed()0%2100%
RequestAllPlaces()0%6200%
RequestAllWorlds()0%6200%
ShowPlaces(...)0%12300%
ShowWorlds(...)0%12300%
CheckAndSetNoResults()0%20400%
ConfigurePlaceCardActions(...)0%2100%
ConfigureWorldCardActions(...)0%2100%
ViewOnVoteChanged(...)0%6200%
ViewOnOnFavoriteChanged(...)0%6200%
ShowPlaceModal(...)0%2100%
ShowWorldModal(...)0%2100%
ShowAllPlaces(...)0%6200%
ShowAllWorlds(...)0%6200%
InitializePools()0%110100%
RestartScrollViewPosition()0%2100%
CloseFullList()0%2100%
SetAllAsLoading()0%2100%
SetHeaderEnabled(...)0%20400%
SetActive(...)0%3.033085.71%
OnEnable()0%2.062075%
RefreshControl()0%2100%
Dispose()0%110100%
HideWorldModal()0%6200%
ClearPlacesPool()0%2.152066.67%
ClearFullPlacesPool()0%2.152066.67%
ClearWorldsPool()0%2.152066.67%
ClearFullWorldsPool()0%2.152066.67%

File(s)

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

#LineLine coverage
 1using DCL;
 2using MainScripts.DCL.Controllers.HotScenes;
 3using MainScripts.DCL.Helpers.Utils;
 4using System;
 5using System.Collections.Generic;
 6using TMPro;
 7using UnityEngine;
 8using UnityEngine.Serialization;
 9using UnityEngine.UI;
 10using Utils = DCL.Helpers.Utils;
 11
 12public class FavoriteSubSectionComponentView : BaseComponentView, IFavoriteSubSectionComponentView
 13{
 14    private const int MAX_POOL_COUNT = 6;
 15    internal const string WORLDS_SUBSECTION_FF = "worlds_subsection";
 16
 017    public int CurrentTilesPerRow { get; }
 018    public int CurrentGoingTilesPerRow { get; }
 19
 20    [SerializeField] private GameObject minimalFavoriteList;
 21    [SerializeField] private TMP_Text headerText;
 22    [SerializeField] private GameObject fullFavoriteList;
 23    [SerializeField] private GameObject normalHeader;
 24    [SerializeField] private GameObject fullFavoriteListHeader;
 25    [SerializeField] private Button backButton;
 26
 27    [SerializeField] private Canvas canvas;
 28    [SerializeField] private GameObject worldsSection;
 29    [SerializeField] private Transform placesParent;
 30    [SerializeField] private Transform worldsParent;
 31    [SerializeField] private RectTransform fullPlacesParent;
 32    [SerializeField] private RectTransform fullWorldsParent;
 33    [SerializeField] private RectTransform gridContainer;
 34    [SerializeField] private PlaceCardComponentView placePrefab;
 35    [SerializeField] private GameObject loadingPlaces;
 36    [SerializeField] private GameObject loadingWorlds;
 37    [SerializeField] private GameObject loadingAll;
 38    [SerializeField] private Button showAllPlaces;
 39    [SerializeField] private Button showAllWorlds;
 40    [SerializeField] private Button showMore;
 41
 42    [SerializeField] internal GameObject noPlaces;
 43    [SerializeField] internal GameObject noWorlds;
 44    [SerializeField] internal GameObject noResults;
 45    [SerializeField] private TMP_Text noPlacesText;
 46    [SerializeField] private TMP_Text noWorldsText;
 47    [SerializeField] internal PlaceCardComponentView placeCardModalPrefab;
 48    [SerializeField] internal PlaceCardComponentView worldCardModalPrefab;
 49
 50    internal PlaceCardComponentView placeModal;
 51    internal PlaceCardComponentView worldModal;
 52    public event Action OnRequestFavorites;
 53    public event Action<int> OnRequestAllPlaces;
 54    public event Action<int> OnRequestAllWorlds;
 55    public event Action<PlaceCardComponentModel, int> OnPlaceInfoClicked;
 56    public event Action<IHotScenesController.PlaceInfo> OnPlaceJumpInClicked;
 57    public event Action<PlaceCardComponentModel, int> OnWorldInfoClicked;
 58    public event Action<IHotScenesController.PlaceInfo> OnWorldJumpInClicked;
 59    public event Action<string, bool?> OnVoteChanged;
 60    public event Action<string, bool> OnPlaceFavoriteChanged;
 61
 62    private UnityObjectPool<PlaceCardComponentView> placesPool;
 3963    internal List<PlaceCardComponentView> pooledPlaces = new List<PlaceCardComponentView>();
 64    private UnityObjectPool<PlaceCardComponentView> fullPlacesPool;
 3965    internal List<PlaceCardComponentView> pooledFullPlaces = new List<PlaceCardComponentView>();
 66    private UnityObjectPool<PlaceCardComponentView> worldsPool;
 3967    internal List<PlaceCardComponentView> pooledWorlds = new List<PlaceCardComponentView>();
 68    private UnityObjectPool<PlaceCardComponentView> fullWorldsPool;
 3969    internal List<PlaceCardComponentView> pooledFullWorlds = new List<PlaceCardComponentView>();
 70    private int currentPage = 0;
 71
 72    public override void Awake()
 73    {
 3774        InitializePools();
 3775        InitialiseButtonEvents();
 76
 3777        noPlaces.SetActive(false);
 3778        placeModal = PlacesAndEventsCardsFactory.GetPlaceCardTemplateHiddenLazy(placeCardModalPrefab);
 3779        worldModal = PlacesAndEventsCardsFactory.GetWorldCardTemplateHiddenLazy(worldCardModalPrefab);
 3780    }
 81
 82    private void InitialiseButtonEvents()
 83    {
 3784        if (showAllPlaces != null)
 85        {
 3786            showAllPlaces.onClick.RemoveAllListeners();
 3787            showAllPlaces.onClick.AddListener(RequestAllPlaces);
 88        }
 89
 3790        if (showAllWorlds != null)
 91        {
 3792            showAllWorlds.onClick.RemoveAllListeners();
 3793            showAllWorlds.onClick.AddListener(RequestAllWorlds);
 94        }
 95
 3796        if (showMore != null)
 97        {
 3798            showMore.onClick.RemoveAllListeners();
 3799            showMore.onClick.AddListener(RequestAdditionalPage);
 100        }
 101
 37102        if (backButton != null)
 103        {
 37104            backButton.onClick.RemoveAllListeners();
 37105            backButton.onClick.AddListener(OnBackButtonPressed);
 106        }
 37107    }
 108
 109    private void RequestAdditionalPage()
 110    {
 0111        currentPage++;
 112
 0113        if(fullPlacesParent.gameObject.activeSelf)
 0114            OnRequestAllPlaces?.Invoke(currentPage);
 0115        else if(fullWorldsParent.gameObject.activeSelf)
 0116            OnRequestAllWorlds?.Invoke(currentPage);
 0117    }
 118
 119    private void OnBackButtonPressed()
 120    {
 0121        SetHeaderEnabled(false);
 0122        minimalFavoriteList.SetActive(true);
 0123        fullFavoriteList.SetActive(false);
 0124    }
 125
 126    private void RequestAllPlaces()
 127    {
 0128        currentPage = 0;
 0129        minimalFavoriteList.SetActive(false);
 0130        fullFavoriteList.SetActive(true);
 0131        fullPlacesParent.gameObject.SetActive(true);
 0132        fullWorldsParent.gameObject.SetActive(false);
 0133        loadingAll.SetActive(true);
 0134        ClearFullPlacesPool();
 0135        OnRequestAllPlaces?.Invoke(currentPage);
 0136    }
 137
 138    private void RequestAllWorlds()
 139    {
 0140        currentPage = 0;
 0141        minimalFavoriteList.SetActive(false);
 0142        fullFavoriteList.SetActive(true);
 0143        fullPlacesParent.gameObject.SetActive(false);
 0144        fullWorldsParent.gameObject.SetActive(true);
 0145        loadingAll.SetActive(true);
 0146        ClearFullWorldsPool();
 0147        OnRequestAllWorlds?.Invoke(currentPage);
 0148    }
 149
 150    public void ShowPlaces(List<PlaceCardComponentModel> places)
 151    {
 0152        ClearPlacesPool();
 0153        foreach (PlaceCardComponentModel placeCardComponentModel in places)
 154        {
 0155            PlaceCardComponentView placeCardComponentView = placesPool.Get();
 0156            placeCardComponentView.model = placeCardComponentModel;
 0157            placeCardComponentView.RefreshControl();
 0158            pooledPlaces.Add(placeCardComponentView);
 0159            ConfigurePlaceCardActions(placeCardComponentView, placeCardComponentModel);
 160        }
 0161        placesParent.gameObject.SetActive(true);
 0162        loadingPlaces.gameObject.SetActive(false);
 163
 0164        showAllPlaces.gameObject.SetActive(places.Count == 6);
 0165        if (places.Count == 0)
 166        {
 0167            noPlaces.SetActive(true);
 0168            noPlacesText.text = $"No favorite places found";
 169        }
 170        else
 171        {
 0172            noPlaces.SetActive(false);
 173        }
 0174        CheckAndSetNoResults();
 0175    }
 176
 177    public void ShowWorlds(List<PlaceCardComponentModel> worlds)
 178    {
 0179        ClearWorldsPool();
 0180        foreach (PlaceCardComponentModel placeCardComponentModel in worlds)
 181        {
 0182            PlaceCardComponentView placeCardComponentView = worldsPool.Get();
 0183            placeCardComponentView.model = placeCardComponentModel;
 0184            placeCardComponentView.RefreshControl();
 0185            pooledWorlds.Add(placeCardComponentView);
 0186            ConfigureWorldCardActions(placeCardComponentView, placeCardComponentModel);
 187        }
 0188        worldsParent.gameObject.SetActive(true);
 0189        loadingWorlds.gameObject.SetActive(false);
 190
 0191        showAllWorlds.gameObject.SetActive(worlds.Count == 6);
 0192        if (worlds.Count == 0)
 193        {
 0194            noWorlds.SetActive(true);
 0195            noWorldsText.text = $"No favorite worlds found";
 196        }
 197        else
 198        {
 0199            noWorlds.SetActive(false);
 200        }
 0201        CheckAndSetNoResults();
 0202    }
 203
 204    private void CheckAndSetNoResults()
 205    {
 0206        if (noPlaces.activeSelf && noWorlds.activeSelf)
 207        {
 0208            noResults.SetActive(true);
 0209            minimalFavoriteList.SetActive(false);
 210        }
 211        else
 212        {
 0213            noResults.SetActive(false);
 0214            if(minimalFavoriteList.activeSelf == false)
 0215                minimalFavoriteList.SetActive(true);
 216        }
 0217        Utils.ForceRebuildLayoutImmediate(gridContainer);
 0218    }
 219
 220    private void ConfigurePlaceCardActions(PlaceCardComponentView view, PlaceCardComponentModel model)
 221    {
 0222        view.onInfoClick.RemoveAllListeners();
 0223        view.onBackgroundClick.RemoveAllListeners();
 0224        view.onJumpInClick.RemoveAllListeners();
 0225        view.OnFavoriteChanged -= ViewOnOnFavoriteChanged;
 0226        view.OnVoteChanged -= ViewOnVoteChanged;
 0227        view.onInfoClick.AddListener(()=>OnPlaceInfoClicked?.Invoke(model, view.transform.GetSiblingIndex()));
 0228        view.onBackgroundClick.AddListener(()=>OnPlaceInfoClicked?.Invoke(model, view.transform.GetSiblingIndex()));
 0229        view.onJumpInClick.AddListener(()=>OnPlaceJumpInClicked?.Invoke(model.placeInfo));
 0230        view.OnFavoriteChanged += ViewOnOnFavoriteChanged;
 0231        view.OnVoteChanged += ViewOnVoteChanged;
 0232    }
 233
 234    private void ConfigureWorldCardActions(PlaceCardComponentView view, PlaceCardComponentModel model)
 235    {
 0236        view.onInfoClick.RemoveAllListeners();
 0237        view.onBackgroundClick.RemoveAllListeners();
 0238        view.onJumpInClick.RemoveAllListeners();
 0239        view.OnFavoriteChanged -= ViewOnOnFavoriteChanged;
 0240        view.OnVoteChanged -= ViewOnVoteChanged;
 0241        view.onInfoClick.AddListener(()=>OnWorldInfoClicked?.Invoke(model, view.transform.GetSiblingIndex()));
 0242        view.onBackgroundClick.AddListener(()=>OnWorldInfoClicked?.Invoke(model, view.transform.GetSiblingIndex()));
 0243        view.onJumpInClick.AddListener(()=>OnWorldJumpInClicked?.Invoke(model.placeInfo));
 0244        view.OnFavoriteChanged += ViewOnOnFavoriteChanged;
 0245        view.OnVoteChanged += ViewOnVoteChanged;
 0246    }
 247
 248    private void ViewOnVoteChanged(string placeName, bool? isUpvoted)
 249    {
 0250        OnVoteChanged?.Invoke(placeName, isUpvoted);
 0251    }
 252
 253    private void ViewOnOnFavoriteChanged(string placeId, bool isFavorite)
 254    {
 0255        OnPlaceFavoriteChanged?.Invoke(placeId, isFavorite);
 0256    }
 257
 258    public void ShowPlaceModal(PlaceCardComponentModel placeModel)
 259    {
 0260        placeModal.Show();
 0261        PlacesCardsConfigurator.Configure(placeModal, placeModel, null, OnPlaceJumpInClicked, OnVoteChanged, OnPlaceFavo
 0262    }
 263
 264    public void ShowWorldModal(PlaceCardComponentModel placeModel)
 265    {
 0266        worldModal.Show();
 0267        PlacesCardsConfigurator.Configure(worldModal, placeModel, null, OnWorldJumpInClicked, OnVoteChanged, OnPlaceFavo
 0268    }
 269
 270    public void ShowAllPlaces(List<PlaceCardComponentModel> places, bool showMoreButton)
 271    {
 0272        showMore.gameObject.SetActive(showMoreButton);
 0273        foreach (PlaceCardComponentModel placeCardComponentModel in places)
 274        {
 0275            PlaceCardComponentView placeCardComponentView = fullPlacesPool.Get();
 0276            placeCardComponentView.model = placeCardComponentModel;
 0277            placeCardComponentView.RefreshControl();
 0278            placeCardComponentView.OnLoseFocus();
 0279            placeCardComponentView.transform.SetAsLastSibling();
 0280            pooledFullPlaces.Add(placeCardComponentView);
 0281            ConfigurePlaceCardActions(placeCardComponentView, placeCardComponentModel);
 282        }
 0283        loadingAll.SetActive(false);
 0284        Utils.ForceRebuildLayoutImmediate(fullPlacesParent);
 0285    }
 286
 287    public void ShowAllWorlds(List<PlaceCardComponentModel> worlds, bool showMoreButton)
 288    {
 0289        showMore.gameObject.SetActive(showMoreButton);
 0290        foreach (PlaceCardComponentModel placeCardComponentModel in worlds)
 291        {
 0292            PlaceCardComponentView placeCardComponentView = fullWorldsPool.Get();
 0293            placeCardComponentView.model = placeCardComponentModel;
 0294            placeCardComponentView.RefreshControl();
 0295            placeCardComponentView.OnLoseFocus();
 0296            placeCardComponentView.transform.SetAsLastSibling();
 0297            pooledFullWorlds.Add(placeCardComponentView);
 0298            ConfigureWorldCardActions(placeCardComponentView, placeCardComponentModel);
 299        }
 0300        loadingAll.SetActive(false);
 0301        Utils.ForceRebuildLayoutImmediate(fullWorldsParent);
 0302    }
 303
 304    private void InitializePools()
 305    {
 37306        placesPool = new UnityObjectPool<PlaceCardComponentView>(placePrefab, placesParent);
 37307        placesPool.Prewarm(MAX_POOL_COUNT);
 37308        worldsPool = new UnityObjectPool<PlaceCardComponentView>(placePrefab, worldsParent);
 37309        worldsPool.Prewarm(MAX_POOL_COUNT);
 37310        fullPlacesPool = new UnityObjectPool<PlaceCardComponentView>(placePrefab, fullPlacesParent);
 37311        fullPlacesPool.Prewarm(MAX_POOL_COUNT);
 37312        fullWorldsPool = new UnityObjectPool<PlaceCardComponentView>(placePrefab, fullWorldsParent);
 37313        fullWorldsPool.Prewarm(MAX_POOL_COUNT);
 37314    }
 315
 316    public void RestartScrollViewPosition()
 317    {
 0318    }
 319
 320    private void CloseFullList()
 321    {
 0322        minimalFavoriteList.SetActive(true);
 0323        fullFavoriteList.SetActive(false);
 0324    }
 325
 326    public void SetAllAsLoading()
 327    {
 0328        CloseFullList();
 0329        placesParent.gameObject.SetActive(false);
 0330        worldsParent.gameObject.SetActive(false);
 0331        loadingPlaces.SetActive(true);
 0332        loadingWorlds.SetActive(true);
 0333    }
 334
 335    public void SetHeaderEnabled(bool isFullHeaderActive)
 336    {
 0337        normalHeader.SetActive(!isFullHeaderActive);
 0338        fullFavoriteListHeader.SetActive(isFullHeaderActive);
 339
 0340        if (isFullHeaderActive)
 0341            headerText.text = fullPlacesParent.gameObject.activeSelf ? "Favorite Places" : "Favorite Worlds";
 0342    }
 343
 344    public void SetActive(bool isActive)
 345    {
 78346        if (canvas.enabled == isActive)
 42347            return;
 36348        canvas.enabled = isActive;
 349
 36350        if (isActive)
 0351            OnEnable();
 352        else
 36353            OnDisable();
 36354    }
 355
 356    public override void OnEnable()
 357    {
 37358        base.OnEnable();
 359
 360        //Temporary until the full feature is released
 37361        worldsSection.SetActive(DataStore.i.featureFlags.flags.Get().IsFeatureEnabled(WORLDS_SUBSECTION_FF));
 37362        OnRequestFavorites?.Invoke();
 0363    }
 364
 365    public override void RefreshControl()
 366    {
 0367    }
 368
 369    public override void Dispose()
 370    {
 82371        ClearPlacesPool();
 82372        ClearFullPlacesPool();
 82373        ClearWorldsPool();
 82374        ClearFullWorldsPool();
 82375    }
 376
 377    public void HideWorldModal()
 378    {
 0379        if(worldModal != null)
 0380            worldModal.Hide();
 0381    }
 382
 383    private void ClearPlacesPool()
 384    {
 164385        foreach (var pooledEvent in pooledPlaces)
 0386            placesPool.Release(pooledEvent);
 82387        pooledPlaces.Clear();
 82388    }
 389
 390    private void ClearFullPlacesPool(){
 164391        foreach (var pooledEvent in pooledFullPlaces)
 0392            fullPlacesPool.Release(pooledEvent);
 82393        pooledFullPlaces.Clear();
 82394    }
 395
 396    private void ClearWorldsPool()
 397    {
 164398        foreach (var pooledWorld in pooledWorlds)
 0399            worldsPool.Release(pooledWorld);
 82400        pooledWorlds.Clear();
 82401    }
 402
 403    private void ClearFullWorldsPool(){
 164404        foreach (var pooledWorld in pooledFullWorlds)
 0405            fullWorldsPool.Release(pooledWorld);
 82406        pooledFullWorlds.Clear();
 82407    }
 408}