< Summary

Class:ViewAllComponentView
Assembly:PassportHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/Passport/Passport/PassportNavigation/ViewAllComponentView.cs
Covered lines:0
Uncovered lines:68
Coverable lines:68
Total lines:153
Line coverage:0% (0 of 68)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:15
Method coverage:0% (0 of 15)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ViewAllComponentView()0%2100%
ViewAllComponentView()0%2100%
Awake()0%2100%
Initialize(...)0%2100%
SetTotalElements(...)0%6200%
RequestPage(...)0%6200%
RefreshControl()0%2100%
SetVisible(...)0%2100%
ShowNftIcons(...)0%12300%
SetLoadingActive(...)0%2100%
CloseAllNftItemInfos()0%6200%
FocusOnNFTIconView(...)0%6200%
ClickOnBuyWearable(...)0%6200%
GetNftElementsEntryPool()0%6200%
ClearNftPool()0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/Passport/Passport/PassportNavigation/ViewAllComponentView.cs

#LineLine coverage
 1using System;
 2using DCL;
 3using System.Collections.Generic;
 4using TMPro;
 5using UnityEngine;
 6
 7public class ViewAllComponentView : BaseComponentView, IViewAllComponentView
 8{
 9    private const int ELEMENTS_PER_PAGE = 20;
 10    private const string NFT_ELEMENTS_POOL_NAME_PREFIX = "NFTElementsEntriesPool_";
 011    private static readonly Vector3 NFT_ICON_SCALE = new Vector3(0.75f, 0.75f, 0.75f);
 12
 13    [SerializeField] private TMP_Text sectionName;
 14    [SerializeField] private TMP_Text sectionAmount;
 15    [SerializeField] private ButtonComponentView backButton;
 16    [SerializeField] private Transform itemsContainer;
 17    [SerializeField] private UIPageSelector pageSelector;
 18    [SerializeField] private GameObject nftPageElement;
 19    [SerializeField] private GameObject loadingSpinner;
 20    [SerializeField] internal NFTItemInfo nftItemInfo;
 21
 22    public event Action OnBackFromViewAll;
 23    public event Action<PassportSection, int, int> OnRequestCollectibleElements;
 24    public event Action<NftInfo> OnClickBuyNft;
 25
 026    private List<PoolableObject> nftElementsPoolableQueue = new List<PoolableObject>();
 27    private Pool nftElementsEntryPool;
 28    private PassportSection section;
 029    private readonly List<NFTIconComponentView> nftWearableViews = new List<NFTIconComponentView>();
 30    private string poolEntryId;
 31
 32    public override void Awake()
 33    {
 034        base.Awake();
 35
 036        backButton.onClick.RemoveAllListeners();
 037        backButton.onClick.AddListener(()=>
 38        {
 039            ClearNftPool();
 040            OnBackFromViewAll?.Invoke();
 041        });
 042        pageSelector.OnValueChanged += RequestPage;
 43
 044        poolEntryId = NFT_ELEMENTS_POOL_NAME_PREFIX + name + GetInstanceID();
 045    }
 46
 47    public void Initialize(PassportSection passportSection)
 48    {
 049        nftElementsEntryPool = GetNftElementsEntryPool();
 050        section = passportSection;
 051        sectionName.text = passportSection.ToString();
 052        sectionAmount.gameObject.SetActive(false);
 053        pageSelector.SelectPage(0);
 054    }
 55
 56    public void SetTotalElements(int totalElements)
 57    {
 058        pageSelector.Setup((totalElements + ELEMENTS_PER_PAGE - 1) / ELEMENTS_PER_PAGE);
 059        sectionAmount.text = $"({totalElements})";
 060        if (!sectionAmount.gameObject.activeSelf)
 061            sectionAmount.gameObject.SetActive(true);
 062    }
 63
 64    private void RequestPage(int pageNumber)
 65    {
 066        ClearNftPool();
 067        OnRequestCollectibleElements?.Invoke(section, pageNumber + 1, ELEMENTS_PER_PAGE);
 068    }
 69
 070    public override void RefreshControl() { }
 71
 72    public void SetVisible(bool isVisible)
 73    {
 074        gameObject.SetActive(isVisible);
 075    }
 76
 77    public void ShowNftIcons(List<(NFTIconComponentModel model, WearableItem wearable)> iconsWithWearables)
 78    {
 079        nftWearableViews.Clear();
 80
 081        foreach (var wearableData in iconsWithWearables)
 82        {
 083            PoolableObject poolableObject = nftElementsEntryPool.Get();
 084            nftElementsPoolableQueue.Add(poolableObject);
 085            poolableObject.gameObject.transform.SetParent(itemsContainer, false);
 086            poolableObject.gameObject.transform.localScale = NFT_ICON_SCALE;
 087            NFTIconComponentView nftIconComponentView = poolableObject.gameObject.GetComponent<NFTIconComponentView>();
 088            nftIconComponentView.onMarketplaceButtonClick.RemoveAllListeners();
 089            nftIconComponentView.onMarketplaceButtonClick.AddListener(() => ClickOnBuyWearable(wearableData.model.nftInf
 090            nftIconComponentView.Configure(wearableData.model);
 091            nftIconComponentView.onFocused -= FocusOnNFTIconView;
 092            nftIconComponentView.onFocused += FocusOnNFTIconView;
 93
 094            if (wearableData.wearable != null)
 95            {
 096                nftIconComponentView.onDetailInfoButtonClick.AddListener(() => nftIconComponentView.SetNFTItemInfoActive
 097                nftIconComponentView.ConfigureNFTItemInfo(nftItemInfo, wearableData.wearable, !wearableData.wearable.IsE
 98            }
 99            else
 0100                nftIconComponentView.onDetailInfoButtonClick.RemoveAllListeners();
 101
 0102            nftWearableViews.Add(nftIconComponentView);
 103        }
 0104    }
 105
 106    public void SetLoadingActive(bool isLoading)
 107    {
 0108        loadingSpinner.SetActive(isLoading);
 0109        itemsContainer.gameObject.SetActive(!isLoading);
 0110    }
 111
 112    public void CloseAllNftItemInfos()
 113    {
 0114        foreach (var nftView in nftWearableViews)
 0115            nftView.SetNFTItemInfoActive(false);
 0116    }
 117
 118    private void FocusOnNFTIconView(bool isFocused)
 119    {
 0120        if (!isFocused)
 0121            return;
 122
 0123        CloseAllNftItemInfos();
 0124    }
 125
 126    private void ClickOnBuyWearable(NftInfo nftInfo)
 127    {
 0128        OnClickBuyNft?.Invoke(nftInfo);
 0129    }
 130
 131    private Pool GetNftElementsEntryPool()
 132    {
 0133        var pool = PoolManager.i.GetPool(poolEntryId);
 0134        if (pool != null) return pool;
 135
 0136        pool = PoolManager.i.AddPool(
 137            poolEntryId,
 138            Instantiate(nftPageElement).gameObject,
 139            maxPrewarmCount: ELEMENTS_PER_PAGE,
 140            isPersistent: true);
 141
 0142        pool.ForcePrewarm();
 0143        return pool;
 144    }
 145
 146    private void ClearNftPool()
 147    {
 0148        foreach (var poolObject in nftElementsPoolableQueue)
 0149            nftElementsEntryPool.Release(poolObject);
 150
 0151        nftElementsPoolableQueue = new List<PoolableObject>();
 0152    }
 153}