< Summary

Class:ListView[T]
Assembly:BuilderInWorldCommon
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Scripts/BuilderInWorldCommon/ListView.cs
Covered lines:1
Uncovered lines:21
Coverable lines:22
Total lines:63
Line coverage:4.5% (1 of 22)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ListView()0%110100%
SetContent(...)0%2100%
RefreshDisplay()0%2100%
AddAdapters()0%2100%
RemoveAdapters()0%42600%
CheckEmptyContent()0%12300%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Scripts/BuilderInWorldCommon/ListView.cs

#LineLine coverage
 1using System.Collections;
 2using System.Collections.Generic;
 3using UnityEngine;
 4
 5/// <summary>
 6///  This class is a generic implementantion for a view that list items. It should be use when you want to list items in
 7///
 8///  The general logic of this class is that it will instanciate one adapter per one item in the list you set. The adapt
 9///  while this class will manage the availability of the adapters. This way you can switch adapter to show them in dife
 10///
 11///  You will need to implement at least one adapter in the AddAdapters function and instanciated it as a children of th
 12///
 13///  You are required to implement the AddAdapters with your own adapter logic, this is done in order to mantain it more
 14/// </summary>
 15public class ListView<T> : MonoBehaviour
 16{
 17
 18    public Transform contentPanelTransform;
 19    public GameObject emptyContentMark;
 20
 10521    protected List<T> contentList = new List<T>();
 22    public void SetContent(List<T> content)
 23    {
 024        contentList = content;
 025        RefreshDisplay();
 026    }
 27
 28    public virtual void RefreshDisplay()
 29    {
 030        RemoveAdapters();
 031        AddAdapters();
 032        CheckEmptyContent();
 033    }
 34
 035    public virtual void AddAdapters() { }
 36
 37    public virtual void RemoveAdapters()
 38    {
 039        if (contentPanelTransform == null ||
 40            contentPanelTransform.transform == null ||
 41            contentPanelTransform.transform.childCount <= 0)
 042            return;
 43
 44
 045        for (int i = 0; i < contentPanelTransform.transform.childCount; i++)
 46        {
 047            GameObject toRemove = contentPanelTransform.transform.GetChild(i).gameObject;
 048            if (toRemove != null)
 049                Destroy(toRemove);
 50        }
 051    }
 52
 53    private void CheckEmptyContent()
 54    {
 055        bool contentIsEmpty = contentList.Count == 0;
 56
 057        if (contentPanelTransform != null)
 058            contentPanelTransform.gameObject.SetActive(!contentIsEmpty);
 59
 060        if (emptyContentMark != null)
 061            emptyContentMark.SetActive(contentIsEmpty);
 062    }
 63}