< Summary

Class:WorldsSubSectionComponentView
Assembly:ExploreV2
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/Sections/PlacesAndEventsSection/SubSections/WorldsSubSection/WorldsSubSectionMenu/WorldsSubSectionComponentView.cs
Covered lines:74
Uncovered lines:32
Coverable lines:106
Total lines:262
Line coverage:69.8% (74 of 106)
Covered branches:0
Total branches:0
Covered methods:18
Total methods:30
Method coverage:60% (18 of 30)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
WorldsSubSectionComponentView()0%110100%
SetAllAsLoading()0%2100%
SetShowMoreButtonActive(...)0%2100%
SetPOICoords(...)0%2100%
Awake()0%110100%
Start()0%22091.67%
LoadSortByDropdown()0%110100%
SortByDropdownValueChanged(...)0%12300%
OnEnable()0%2.032080%
Dispose()0%440100%
ConfigurePools()0%110100%
RefreshControl()0%2100%
SetWorlds(...)0%220100%
SetWorldsAsLoading(...)0%220100%
AddWorlds(...)0%110100%
AddWorldsAsync()0%18.0612065.22%
SetActive(...)0%3.033085.71%
SetShowMoreWorldsButtonActive(...)0%110100%
ShowWorldModal(...)0%2100%
HideWorldModal()0%6200%
RestartScrollViewPosition()0%2100%
SetSortDropdownValue(...)0%110100%
OnPointerClick(...)0%20400%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/Sections/PlacesAndEventsSection/SubSections/WorldsSubSection/WorldsSubSectionMenu/WorldsSubSectionComponentView.cs

#LineLine coverage
 1using Cysharp.Threading.Tasks;
 2using DCL;
 3using DCL.Tasks;
 4using System;
 5using System.Collections.Generic;
 6using System.Threading;
 7using UnityEngine;
 8using UnityEngine.UI;
 9using MainScripts.DCL.Controllers.HotScenes;
 10using TMPro;
 11using UnityEngine.EventSystems;
 12
 13public class WorldsSubSectionComponentView : BaseComponentView, IWorldsSubSectionComponentView, IPointerClickHandler
 14{
 15    private const string WORLD_CARDS_POOL_NAME = "Worlds_WorldCardsPool";
 16    private const int WORLD_CARDS_POOL_PREWARM = 20;
 17    private const string MOST_ACTIVE_FILTER_ID = "most_active";
 18    private const string MOST_ACTIVE_FILTER_TEXT = "Most active";
 19    private const string BEST_FILTER_ID = "like_rate";
 20    private const string BEST_FILTER_TEXT = "Best";
 21
 5222    private readonly CancellationTokenSource disposeCts = new ();
 5223    private CancellationTokenSource setWorldsCts = new ();
 24
 25    private List<string> poiCoords;
 26
 27    [Header("Assets References")]
 28    [SerializeField] internal PlaceCardComponentView worldCardPrefab;
 29    [SerializeField] internal PlaceCardComponentView worldCardModalPrefab;
 30
 31    [Header("Prefab References")]
 32    [SerializeField] internal ScrollRect scrollView;
 33    [SerializeField] internal GridContainerComponentView worlds;
 34    [SerializeField] internal GameObject worldsLoading;
 35    [SerializeField] internal GameObject worldsNoDataContainer;
 36    [SerializeField] internal Color[] friendColors = null;
 37    [SerializeField] internal GameObject showMoreWorldsButtonContainer;
 38    [SerializeField] internal ButtonComponentView showMoreWorldsButton;
 39    [SerializeField] internal DropdownComponentView sortByDropdown;
 40    [SerializeField] internal Button findOutMoreButton;
 41    [SerializeField] internal TMP_Text textComponent;
 42
 43    [SerializeField] private Canvas canvas;
 44
 45    internal PlaceCardComponentView worldModal;
 46    internal Pool worldCardsPool;
 47    private Canvas worldsCanvas;
 48
 049    public Color[] currentFriendColors => friendColors;
 50
 051    public int currentWorldsPerRow => worlds.currentItemsPerRow;
 52
 053    public void SetAllAsLoading() => SetWorldsAsLoading(true);
 054    public void SetShowMoreButtonActive(bool isActive) => SetShowMoreWorldsButtonActive(isActive);
 55
 56    public void SetPOICoords(List<string> poiList) =>
 057        poiCoords = poiList;
 58
 059    public int CurrentTilesPerRow => currentWorldsPerRow;
 9760    public string filter { get; private set; }
 9761    public string sort { get; private set; }
 62
 63    public event Action OnReady;
 64    public event Action<PlaceCardComponentModel> OnInfoClicked;
 65    public event Action<IHotScenesController.PlaceInfo> OnJumpInClicked;
 66    public event Action<string, bool?> OnVoteChanged;
 67    public event Action<string, bool> OnFavoriteClicked;
 68    public event Action<IFriendTrackerHandler> OnFriendHandlerAdded;
 69    public event Action OnWorldsSubSectionEnable;
 70    public event Action OnSortingChanged;
 71    public event Action OnShowMoreWorldsClicked;
 72    public event Action OnOpenWorldsInfo;
 73    public event Action OnOpenWorldsDaoProposal;
 74
 75    public override void Awake()
 76    {
 4977        base.Awake();
 4978        worldsCanvas = worlds.GetComponent<Canvas>();
 4979    }
 80
 81    public void Start()
 82    {
 4883        worldModal = PlacesAndEventsCardsFactory.GetWorldCardTemplateHiddenLazy(worldCardModalPrefab);
 84
 4885        worlds.RemoveItems();
 4886        LoadSortByDropdown();
 4887        findOutMoreButton.onClick.RemoveAllListeners();
 4888        findOutMoreButton.onClick.AddListener(()=>OnOpenWorldsInfo?.Invoke());
 89
 4890        showMoreWorldsButton.onClick.RemoveAllListeners();
 4891        showMoreWorldsButton.onClick.AddListener(() => OnShowMoreWorldsClicked?.Invoke());
 4892        sortByDropdown.OnOptionSelectionChanged += SortByDropdownValueChanged;
 4893        filter = "";
 4894        SetSortDropdownValue(MOST_ACTIVE_FILTER_ID, MOST_ACTIVE_FILTER_TEXT, false);
 4895        OnReady?.Invoke();
 096    }
 97
 98    private void LoadSortByDropdown()
 99    {
 48100        List<ToggleComponentModel> sortingMethodsToAdd = new List<ToggleComponentModel>
 101        {
 102            new () { id = MOST_ACTIVE_FILTER_ID, text = MOST_ACTIVE_FILTER_TEXT, isOn = true, isTextActive = true, chang
 103            new () { id = BEST_FILTER_ID, text = BEST_FILTER_TEXT, isOn = false, isTextActive = true, changeTextColorOnS
 104        };
 105
 48106        sortByDropdown.SetTitle(sortingMethodsToAdd[0].text);
 48107        sortByDropdown.SetOptions(sortingMethodsToAdd);
 48108    }
 109
 110    private void SortByDropdownValueChanged(bool isOn, string optionId, string optionName)
 111    {
 0112        if (!isOn)
 0113            return;
 114
 0115        SetSortDropdownValue(optionId, optionName, false);
 0116        OnSortingChanged?.Invoke();
 0117    }
 118
 119    public override void OnEnable()
 120    {
 49121        base.OnEnable();
 122
 49123        filter = "";
 49124        SetSortDropdownValue(MOST_ACTIVE_FILTER_ID, MOST_ACTIVE_FILTER_TEXT, false);
 49125        OnWorldsSubSectionEnable?.Invoke();
 0126    }
 127
 128    public override void Dispose()
 129    {
 106130        base.Dispose();
 106131        disposeCts?.SafeCancelAndDispose();
 106132        setWorldsCts?.SafeCancelAndDispose();
 133
 106134        showMoreWorldsButton.onClick.RemoveAllListeners();
 135
 106136        sortByDropdown.OnOptionSelectionChanged -= SortByDropdownValueChanged;
 137
 106138        worlds.Dispose();
 139
 106140        if (worldModal != null)
 141        {
 70142            worldModal.Dispose();
 70143            Destroy(worldModal.gameObject);
 144        }
 106145    }
 146
 147    public void ConfigurePools() =>
 12148        worldCardsPool = PlacesAndEventsCardsFactory.GetCardsPoolLazy(WORLD_CARDS_POOL_NAME, worldCardPrefab, WORLD_CARD
 149
 150    public override void RefreshControl() =>
 0151        worlds.RefreshControl();
 152
 153    public void SetWorlds(List<PlaceCardComponentModel> worlds)
 154    {
 4155        SetWorldsAsLoading(false);
 4156        worldsNoDataContainer.SetActive(worlds.Count == 0);
 157
 4158        worldCardsPool.ReleaseAll();
 159
 4160        this.worlds.ExtractItems();
 4161        this.worlds.RemoveItems();
 162
 4163        setWorldsCts?.SafeCancelAndDispose();
 4164        setWorldsCts = CancellationTokenSource.CreateLinkedTokenSource(disposeCts.Token);
 4165        AddWorldsAsync(worlds, setWorldsCts.Token).Forget();
 4166    }
 167
 168    public void SetWorldsAsLoading(bool isVisible)
 169    {
 6170        worldsCanvas.enabled = !isVisible;
 171
 6172        worldsLoading.SetActive(isVisible);
 173
 6174        if (isVisible)
 1175            worldsNoDataContainer.SetActive(false);
 6176    }
 177
 178    public void AddWorlds(List<PlaceCardComponentModel> worlds) =>
 4179        AddWorldsAsync(worlds, disposeCts.Token).Forget();
 180
 181    private async UniTask AddWorldsAsync(List<PlaceCardComponentModel> worlds, CancellationToken cancellationToken)
 182    {
 58183        foreach (PlaceCardComponentModel world in worlds)
 184        {
 24185            PlaceCardComponentView worldCard = PlacesAndEventsCardsFactory.CreateConfiguredPlaceCard(worldCardsPool, wor
 186
 24187            var isPoi = false;
 188
 24189            if (poiCoords != null)
 190            {
 0191                foreach (Vector2Int worldParcel in world.parcels)
 192                {
 0193                    if (!poiCoords.Contains($"{worldParcel.x},{worldParcel.y}"))
 194                        continue;
 195
 0196                    isPoi = true;
 0197                    break;
 198                }
 199            }
 200
 24201            worldCard.SetIsPOI(isPoi);
 202
 24203            OnFriendHandlerAdded?.Invoke(worldCard.friendsHandler);
 204
 24205            this.worlds.AddItem(worldCard);
 206
 72207            await UniTask.NextFrame(cancellationToken);
 208        }
 209
 2210        this.worlds.SetItemSizeForModel();
 2211        await worldCardsPool.PrewarmAsync(worlds.Count, cancellationToken);
 2212    }
 213
 214    public void SetActive(bool isActive)
 215    {
 78216        if (canvas.enabled == isActive)
 42217            return;
 36218        canvas.enabled = isActive;
 219
 36220        if (isActive)
 0221            OnEnable();
 222        else
 36223            OnDisable();
 36224    }
 225
 226    public void SetShowMoreWorldsButtonActive(bool isActive) =>
 2227        showMoreWorldsButtonContainer.gameObject.SetActive(isActive);
 228
 229    public void ShowWorldModal(PlaceCardComponentModel worldInfo)
 230    {
 0231        worldModal.Show();
 0232        PlacesCardsConfigurator.Configure(worldModal, worldInfo, OnInfoClicked, OnJumpInClicked, OnVoteChanged, OnFavori
 0233    }
 234
 235    public void HideWorldModal()
 236    {
 0237        if (worldModal != null)
 0238            worldModal.Hide();
 0239    }
 240
 241    public void RestartScrollViewPosition() =>
 0242        scrollView.verticalNormalizedPosition = 1;
 243
 244    private void SetSortDropdownValue(string id, string title, bool notify)
 245    {
 97246        sort = id;
 97247        sortByDropdown.SetTitle(title);
 97248        sortByDropdown.SelectOption(id, notify);
 97249    }
 250
 251    public void OnPointerClick(PointerEventData eventData)
 252    {
 0253        int linkIndex = TMP_TextUtilities.FindIntersectingLink(textComponent, eventData.position, textComponent.canvas.w
 254
 0255        if (linkIndex == -1) return;
 256
 0257        TMP_LinkInfo linkInfo = textComponent.textInfo.linkInfo[linkIndex];
 258
 0259        if (linkInfo.GetLinkID() == "dao")
 0260            OnOpenWorldsDaoProposal?.Invoke();
 0261    }
 262}