< Summary

Class:FavoritesSubSectionComponentView
Assembly:ExploreV2
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/Sections/PlacesAndEventsSection/SubSections/PlacesSubSection/FavoritesSubSection/FavoritesSubSectionComponentView.cs
Covered lines:22
Uncovered lines:39
Coverable lines:61
Total lines:165
Line coverage:36% (22 of 61)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
FavoritesSubSectionComponentView()0%110100%
SetAllAsLoading()0%2100%
SetShowMoreButtonActive(...)0%2100%
Awake()0%110100%
Start()0%2.022083.33%
OnEnable()0%2.52050%
Dispose()0%220100%
ConfigurePools()0%2100%
RefreshControl()0%2100%
SetFavorites(...)0%2100%
SetFavoritesAsLoading(...)0%6200%
AddFavorites(...)0%2100%
SetFavoritesAsync()0%90900%
SetActive(...)0%2.032080%
SetShowMoreFavoritesButtonActive(...)0%2100%
ShowPlaceModal(...)0%2100%
HidePlaceModal()0%6200%
RestartScrollViewPosition()0%2100%

File(s)

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

#LineLine coverage
 1using DCL;
 2using System;
 3using System.Collections.Generic;
 4using System.Threading;
 5using Cysharp.Threading.Tasks;
 6using TMPro;
 7using UnityEngine;
 8using UnityEngine.UI;
 9
 10public class FavoritesSubSectionComponentView : BaseComponentView, IFavoritesSubSectionComponentView
 11{
 12    internal const string FAVORITE_CARDS_POOL_NAME = "Places_FavoriteCardsPool";
 13    private const int FAVORITE_CARDS_POOL_PREWARM = 20;
 14
 4315    private readonly CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
 16
 17    [Header("Assets References")]
 18    [SerializeField] internal PlaceCardComponentView placeCardPrefab;
 19    [SerializeField] internal PlaceCardComponentView placeCardModalPrefab;
 20
 21    [Header("Prefab References")]
 22    [SerializeField] internal ScrollRect scrollView;
 23    [SerializeField] internal GridContainerComponentView favorites;
 24    [SerializeField] internal GameObject favoritesLoading;
 25    [SerializeField] internal GameObject noFavoritesPrompt;
 26    [SerializeField] internal Color[] friendColors = null;
 27    [SerializeField] internal GameObject showMoreFavoritesButtonContainer;
 28    [SerializeField] internal ButtonComponentView showMoreFavoritesButton;
 29
 30    [SerializeField] private Canvas canvas;
 31
 32    internal PlaceCardComponentView placeModal;
 33    internal Pool favoritesCardsPool;
 34    private Canvas favoritesCanvas;
 35
 036    public Color[] currentFriendColors => friendColors;
 37
 038    public int currentFavoritePlacesPerRow => favorites.currentItemsPerRow;
 39
 040    public void SetAllAsLoading() => SetFavoritesAsLoading(true);
 041    public void SetShowMoreButtonActive(bool isActive) => SetShowMoreFavoritesButtonActive(isActive);
 042    public int CurrentTilesPerRow => currentFavoritePlacesPerRow;
 43
 44    public event Action OnReady;
 45    public event Action<PlaceCardComponentModel> OnInfoClicked;
 46    public event Action<HotScenesController.HotSceneInfo> OnJumpInClicked;
 47    public event Action<FriendsHandler> OnFriendHandlerAdded;
 48    public event Action OnFavoriteSubSectionEnable;
 49    public event Action OnShowMoreFavoritesClicked;
 50
 51    public override void Awake()
 52    {
 4053        base.Awake();
 4054        favoritesCanvas = favorites.GetComponent<Canvas>();
 4055    }
 56
 57    public override void Start()
 58    {
 2859        placeModal = PlacesAndEventsCardsFactory.GetPlaceCardTemplateHiddenLazy(placeCardModalPrefab);
 60
 2861        favorites.RemoveItems();
 62
 2863        showMoreFavoritesButton.onClick.RemoveAllListeners();
 2864        showMoreFavoritesButton.onClick.AddListener(() => OnShowMoreFavoritesClicked?.Invoke());
 65
 2866        OnReady?.Invoke();
 067    }
 68
 69    public override void OnEnable()
 70    {
 4071        OnFavoriteSubSectionEnable?.Invoke();
 072    }
 73
 74    public override void Dispose()
 75    {
 9176        base.Dispose();
 9177        cancellationTokenSource.Cancel();
 78
 9179        showMoreFavoritesButton.onClick.RemoveAllListeners();
 80
 9181        favorites.Dispose();
 82
 9183        if (placeModal != null)
 84        {
 5685            placeModal.Dispose();
 5686            Destroy(placeModal.gameObject);
 87        }
 9188    }
 89
 90    public void ConfigurePools() =>
 091        favoritesCardsPool = PlacesAndEventsCardsFactory.GetCardsPoolLazy(FAVORITE_CARDS_POOL_NAME, placeCardPrefab, FAV
 92
 93    public override void RefreshControl() =>
 094        favorites.RefreshControl();
 95
 96    public void SetFavorites(List<PlaceCardComponentModel> places)
 97    {
 098        SetFavoritesAsLoading(false);
 099        noFavoritesPrompt.gameObject.SetActive(places.Count == 0);
 100
 0101        favoritesCardsPool.ReleaseAll();
 102
 0103        this.favorites.ExtractItems();
 0104        this.favorites.RemoveItems();
 105
 0106        SetFavoritesAsync(places, cancellationTokenSource.Token).Forget();
 0107    }
 108
 109    public void SetFavoritesAsLoading(bool isVisible)
 110    {
 0111        favoritesCanvas.enabled = !isVisible;
 112
 0113        favoritesLoading.SetActive(isVisible);
 114
 0115        if (isVisible)
 0116            noFavoritesPrompt.gameObject.SetActive(false);
 0117    }
 118
 119    public void AddFavorites(List<PlaceCardComponentModel> places) =>
 0120        SetFavoritesAsync(places, cancellationTokenSource.Token).Forget();
 121
 122    private async UniTask SetFavoritesAsync(List<PlaceCardComponentModel> places, CancellationToken cancellationToken)
 123    {
 0124        foreach (PlaceCardComponentModel place in places)
 125        {
 0126            PlaceCardComponentView placeCard = PlacesAndEventsCardsFactory.CreateConfiguredPlaceCard(favoritesCardsPool,
 0127            OnFriendHandlerAdded?.Invoke(placeCard.friendsHandler);
 128
 0129            this.favorites.AddItem(placeCard);
 130
 0131            await UniTask.NextFrame(cancellationToken);
 132        }
 133
 0134        this.favorites.SetItemSizeForModel();
 0135        await favoritesCardsPool.PrewarmAsync(places.Count, cancellationToken);
 0136    }
 137
 138    public void SetActive(bool isActive)
 139    {
 86140        canvas.enabled = isActive;
 141
 86142        if (isActive)
 0143            OnEnable();
 144        else
 86145            OnDisable();
 86146    }
 147
 148    public void SetShowMoreFavoritesButtonActive(bool isActive) =>
 0149        showMoreFavoritesButtonContainer.gameObject.SetActive(isActive);
 150
 151    public void ShowPlaceModal(PlaceCardComponentModel placeInfo)
 152    {
 0153        placeModal.Show();
 0154        PlacesCardsConfigurator.Configure(placeModal, placeInfo, OnInfoClicked, OnJumpInClicked);
 0155    }
 156
 157    public void HidePlaceModal()
 158    {
 0159        if (placeModal != null)
 0160            placeModal.Hide();
 0161    }
 162
 163    public void RestartScrollViewPosition() =>
 0164        scrollView.verticalNormalizedPosition = 1;
 165}