< Summary

Class:DCL.ExperiencesViewer.ExperienceRowComponentView
Assembly:ExperiencesViewer
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExperiencesViewer/Scripts/ExperienceRowComponentView.cs
Covered lines:94
Uncovered lines:10
Coverable lines:104
Total lines:282
Line coverage:90.3% (94 of 104)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%110100%
OnEnable()0%110100%
Configure(...)0%110100%
RefreshControl()0%22090.91%
OnFocus()0%110100%
OnLoseFocus()0%110100%
SetId(...)0%2100%
SetIcon(...)0%3.013090.91%
SetName(...)0%2.032080%
SetUIVisibility(...)0%550100%
SetAsPlaying(...)0%8.068090%
SetRowColor(...)0%2.022083.33%
SetOnHoverColor(...)0%110100%
SetAllowStartStop(...)0%330100%
Dispose()0%550100%
ConfigureRowButtons()0%550100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExperiencesViewer/Scripts/ExperienceRowComponentView.cs

#LineLine coverage
 1using System;
 2using TMPro;
 3using UnityEngine;
 4using UnityEngine.UI;
 5
 6namespace DCL.ExperiencesViewer
 7{
 8    public interface IExperienceRowComponentView
 9    {
 10        /// <summary>
 11        /// Event that will be triggered when the Show/Hide PEX UI button is clicked.
 12        /// </summary>
 13        event Action<string, bool> onShowPEXUI;
 14
 15        /// <summary>
 16        /// Event that will be triggered when the Start(Stop PEX button is clicked.
 17        /// </summary>
 18        event Action<string, bool> onStartPEX;
 19
 20        /// <summary>
 21        /// Set the PEX id.
 22        /// </summary>
 23        /// <param name="id">A string</param>
 24        void SetId(string id);
 25
 26        /// <summary>
 27        /// Set an icon image from an uri.
 28        /// </summary>
 29        /// <param name="uri">Url of the icon image.</param>
 30        void SetIcon(string uri);
 31
 32        /// <summary>
 33        /// Set the name label.
 34        /// </summary>
 35        /// <param name="name">A string.</param>
 36        void SetName(string name);
 37
 38        /// <summary>
 39        /// Set the PEX UI as visible or not.
 40        /// </summary>
 41        /// <param name="isPlaying">True for set the PEX UI as visible.</param>
 42        void SetUIVisibility(bool isVisible);
 43
 44        /// <summary>
 45        /// Set the PEX as playing or not.
 46        /// </summary>
 47        /// <param name="isPlaying">True for set it as playing.</param>
 48        void SetAsPlaying(bool isPlaying);
 49
 50        /// <summary>
 51        /// Set the background color of the row.
 52        /// </summary>
 53        /// <param name="color">Color to apply.</param>
 54        void SetRowColor(Color color);
 55
 56        /// <summary>
 57        /// Set the background color of the row when it is hovered.
 58        /// </summary>
 59        /// <param name="color">Color to apply.</param>
 60        void SetOnHoverColor(Color color);
 61
 62        /// <summary>
 63        /// Set the ability of start/stop the experience (with a toggle) or only stop it (with a stop button).
 64        /// </summary>
 65        /// <param name="isAllowed">True for allowing it.</param>
 66        void SetAllowStartStop(bool isAllowed);
 67    }
 68
 69    public class ExperienceRowComponentView : BaseComponentView, IExperienceRowComponentView, IComponentModelConfig
 70    {
 71        [Header("Prefab References")]
 72        [SerializeField] internal ImageComponentView iconImage;
 73        [SerializeField] internal ImageComponentView defaultIconImage;
 74        [SerializeField] internal TMP_Text nameText;
 75        [SerializeField] internal ShowHideAnimator showHideUIButtonsContainerAnimator;
 76        [SerializeField] internal ButtonComponentView showPEXUIButton;
 77        [SerializeField] internal ButtonComponentView hidePEXUIButton;
 78        [SerializeField] internal Toggle startStopPEXToggle;
 79        [SerializeField] internal ButtonComponentView stopPEXButton;
 80        [SerializeField] internal Image backgroundImage;
 81
 82        [Header("Configuration")]
 83        [SerializeField] internal ExperienceRowComponentModel model;
 84
 85        public event Action<string, bool> onShowPEXUI;
 86        public event Action<string, bool> onStartPEX;
 87
 88        internal Color originalBackgroundColor;
 89        internal Color onHoverColor;
 90
 91        public override void Awake()
 92        {
 2093            base.Awake();
 94
 2095            originalBackgroundColor = backgroundImage.color;
 2096            ConfigureRowButtons();
 2097        }
 98
 99        public override void OnEnable()
 100        {
 28101            base.OnEnable();
 102
 28103            SetUIVisibility(model.isUIVisible);
 28104            SetAsPlaying(model.isPlaying);
 28105        }
 106
 107        public void Configure(BaseComponentModel newModel)
 108        {
 10109            model = (ExperienceRowComponentModel)newModel;
 10110            RefreshControl();
 10111        }
 112
 113        public override void RefreshControl()
 114        {
 10115            if (model == null)
 0116                return;
 117
 10118            SetId(model.id);
 10119            SetIcon(model.iconUri);
 10120            SetName(model.name);
 10121            SetUIVisibility(model.isUIVisible);
 10122            SetAsPlaying(model.isPlaying);
 10123            SetRowColor(model.backgroundColor);
 10124            SetOnHoverColor(model.onHoverColor);
 10125            SetAllowStartStop(model.allowStartStop);
 10126        }
 127
 128        public override void OnFocus()
 129        {
 1130            base.OnFocus();
 131
 1132            backgroundImage.color = onHoverColor;
 1133        }
 134
 135        public override void OnLoseFocus()
 136        {
 29137            base.OnLoseFocus();
 138
 29139            backgroundImage.color = originalBackgroundColor;
 29140        }
 141
 142        public void SetId(string id)
 143        {
 0144            model.id = id;
 0145        }
 146
 147        public void SetIcon(string uri)
 148        {
 11149            model.iconUri = uri;
 150
 11151            if (iconImage == null)
 0152                return;
 153
 11154            if (!String.IsNullOrEmpty(uri))
 155            {
 2156                iconImage.gameObject.SetActive(true);
 2157                iconImage.SetImage(uri);
 2158                defaultIconImage.gameObject.SetActive(false);
 2159            }
 160            else
 161            {
 9162                iconImage.gameObject.SetActive(false);
 9163                defaultIconImage.gameObject.SetActive(true);
 164            }
 9165        }
 166
 167        public void SetName(string name)
 168        {
 11169            model.name = name;
 170
 11171            if (nameText == null)
 0172                return;
 173
 11174            nameText.text = name;
 11175        }
 176
 177        public void SetUIVisibility(bool isVisible)
 178        {
 42179            model.isUIVisible = isVisible;
 180
 42181            if (showPEXUIButton != null)
 182            {
 42183                if (isVisible)
 32184                    showPEXUIButton.Hide();
 185                else
 10186                    showPEXUIButton.Show();
 187            }
 188
 42189            if (hidePEXUIButton != null)
 190            {
 42191                if (isVisible)
 32192                    hidePEXUIButton.Show();
 193                else
 10194                    hidePEXUIButton.Hide();
 195            }
 10196        }
 197
 198        public void SetAsPlaying(bool isPlaying)
 199        {
 46200            model.isPlaying = isPlaying;
 201
 46202            if (startStopPEXToggle != null && startStopPEXToggle.gameObject.activeSelf)
 46203                startStopPEXToggle.isOn = isPlaying;
 204
 46205            if (stopPEXButton != null && stopPEXButton.gameObject.activeSelf && !isPlaying)
 0206                stopPEXButton.gameObject.SetActive(false);
 207
 46208            if (showHideUIButtonsContainerAnimator != null)
 209            {
 46210                if (isPlaying)
 34211                    showHideUIButtonsContainerAnimator.Show();
 212                else
 12213                    showHideUIButtonsContainerAnimator.Hide();
 214            }
 12215        }
 216
 217        public void SetRowColor(Color color)
 218        {
 11219            model.backgroundColor = color;
 220
 11221            if (backgroundImage == null)
 0222                return;
 223
 11224            backgroundImage.color = color;
 11225            originalBackgroundColor = color;
 11226        }
 227
 228        public void SetOnHoverColor(Color color)
 229        {
 11230            model.onHoverColor = color;
 11231            onHoverColor = color;
 11232        }
 233
 234        public void SetAllowStartStop(bool isAllowed)
 235        {
 10236            model.allowStartStop = isAllowed;
 237
 10238            if (startStopPEXToggle != null)
 10239                startStopPEXToggle.gameObject.SetActive(isAllowed);
 240
 10241            if (stopPEXButton != null)
 10242                stopPEXButton.gameObject.SetActive(!isAllowed);
 10243        }
 244
 245        public override void Dispose()
 246        {
 36247            base.Dispose();
 248
 36249            showPEXUIButton?.onClick.RemoveAllListeners();
 36250            hidePEXUIButton?.onClick.RemoveAllListeners();
 36251            startStopPEXToggle?.onValueChanged.RemoveAllListeners();
 36252            stopPEXButton?.onClick.RemoveAllListeners();
 36253        }
 254
 255        internal void ConfigureRowButtons()
 256        {
 20257            showPEXUIButton?.onClick.AddListener(() =>
 258            {
 1259                SetUIVisibility(true);
 1260                onShowPEXUI?.Invoke(model.id, true);
 1261            });
 262
 20263            hidePEXUIButton?.onClick.AddListener(() =>
 264            {
 1265                SetUIVisibility(false);
 1266                onShowPEXUI?.Invoke(model.id, false);
 1267            });
 268
 20269            startStopPEXToggle?.onValueChanged.AddListener((isOn) =>
 270            {
 6271                SetAsPlaying(isOn);
 6272                onStartPEX?.Invoke(model.id, isOn);
 4273            });
 274
 20275            stopPEXButton?.onClick.AddListener(() =>
 276            {
 0277                SetAsPlaying(false);
 0278                onStartPEX?.Invoke(model.id, false);
 0279            });
 20280        }
 281    }
 282}