< Summary

Class:DCL.ExperiencesViewer.ExperienceRowComponentView
Assembly:ExperiencesViewer
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ExperiencesViewer/Scripts/ExperienceRowComponentView.cs
Covered lines:95
Uncovered lines:8
Coverable lines:103
Total lines:284
Line coverage:92.2% (95 of 103)
Covered branches:0
Total branches:0
Covered methods:16
Total methods:16
Method coverage:100% (16 of 16)

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%110100%
SetIcon(...)0%3.013090%
SetName(...)0%2.032080%
SetUIVisibility(...)0%550100%
SetAsPlaying(...)0%8.068090%
SetRowColor(...)0%2.022083.33%
SetOnHoverColor(...)0%110100%
SetAllowStartStop(...)0%330100%
Dispose()0%440100%
ConfigureRowButtons()0%550100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/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<Expe
 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 ToggleComponentView 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        {
 2193            base.Awake();
 94
 2195            originalBackgroundColor = backgroundImage.color;
 2196            ConfigureRowButtons();
 2197        }
 98
 99        public override void OnEnable()
 100        {
 31101            base.OnEnable();
 102
 31103            SetUIVisibility(model.isUIVisible);
 31104            SetAsPlaying(model.isPlaying);
 31105        }
 106
 107        public void Configure(ExperienceRowComponentModel newModel)
 108        {
 12109            model = newModel;
 12110            RefreshControl();
 12111        }
 112
 113        public override void RefreshControl()
 114        {
 12115            if (model == null)
 0116                return;
 117
 12118            SetId(model.id);
 12119            SetIcon(model.iconUri);
 12120            SetName(model.name);
 12121            SetUIVisibility(model.isUIVisible);
 12122            SetAsPlaying(model.isPlaying);
 12123            SetRowColor(model.backgroundColor);
 12124            SetOnHoverColor(model.onHoverColor);
 12125            SetAllowStartStop(model.allowStartStop);
 12126        }
 127
 128        public override void OnFocus()
 129        {
 1130            base.OnFocus();
 131
 1132            backgroundImage.color = onHoverColor;
 1133        }
 134
 135        public override void OnLoseFocus()
 136        {
 32137            base.OnLoseFocus();
 138
 32139            backgroundImage.color = originalBackgroundColor;
 32140        }
 141
 142        public void SetId(string id)
 143        {
 13144            model.id = id;
 13145        }
 146
 147        public void SetIcon(string uri)
 148        {
 13149            model.iconUri = uri;
 150
 13151            if (iconImage == null)
 0152                return;
 153
 13154            if (!String.IsNullOrEmpty(uri))
 155            {
 2156                iconImage.gameObject.SetActive(true);
 2157                iconImage.SetImage(uri);
 2158                defaultIconImage.gameObject.SetActive(false);
 159            }
 160            else
 161            {
 11162                iconImage.gameObject.SetActive(false);
 11163                defaultIconImage.gameObject.SetActive(true);
 164            }
 11165        }
 166
 167        public void SetName(string name)
 168        {
 13169            model.name = name;
 170
 13171            if (nameText == null)
 0172                return;
 173
 13174            nameText.text = name;
 13175        }
 176
 177        public void SetUIVisibility(bool isVisible)
 178        {
 48179            model.isUIVisible = isVisible;
 180
 48181            if (showPEXUIButton != null)
 182            {
 48183                if (isVisible)
 35184                    showPEXUIButton.Hide();
 185                else
 13186                    showPEXUIButton.Show();
 187            }
 188
 48189            if (hidePEXUIButton != null)
 190            {
 48191                if (isVisible)
 35192                    hidePEXUIButton.Show();
 193                else
 13194                    hidePEXUIButton.Hide();
 195            }
 13196        }
 197
 198        public void SetAsPlaying(bool isPlaying)
 199        {
 54200            model.isPlaying = isPlaying;
 201
 54202            if (startStopPEXToggle != null && startStopPEXToggle.gameObject.activeSelf)
 54203                startStopPEXToggle.isOn = isPlaying;
 204
 54205            if (stopPEXButton != null && stopPEXButton.gameObject.activeSelf && !isPlaying)
 0206                stopPEXButton.gameObject.SetActive(false);
 207
 54208            if (showHideUIButtonsContainerAnimator != null)
 209            {
 54210                if (isPlaying)
 38211                    showHideUIButtonsContainerAnimator.Show();
 212                else
 16213                    showHideUIButtonsContainerAnimator.Hide();
 214            }
 16215        }
 216
 217        public void SetRowColor(Color color)
 218        {
 13219            model.backgroundColor = color;
 220
 13221            if (backgroundImage == null)
 0222                return;
 223
 13224            backgroundImage.color = color;
 13225            originalBackgroundColor = color;
 13226        }
 227
 228        public void SetOnHoverColor(Color color)
 229        {
 13230            model.onHoverColor = color;
 13231            onHoverColor = color;
 13232        }
 233
 234        public void SetAllowStartStop(bool isAllowed)
 235        {
 12236            model.allowStartStop = isAllowed;
 237
 12238            if (startStopPEXToggle != null)
 12239                startStopPEXToggle.gameObject.SetActive(isAllowed);
 240
 12241            if (stopPEXButton != null)
 12242                stopPEXButton.gameObject.SetActive(!isAllowed);
 12243        }
 244
 245        public override void Dispose()
 246        {
 37247            base.Dispose();
 248
 37249            showPEXUIButton?.onClick.RemoveAllListeners();
 37250            hidePEXUIButton?.onClick.RemoveAllListeners();
 37251            stopPEXButton?.onClick.RemoveAllListeners();
 37252        }
 253
 254        internal void ConfigureRowButtons()
 255        {
 21256            showPEXUIButton?.onClick.AddListener(() =>
 257            {
 2258                SetUIVisibility(true);
 2259                onShowPEXUI?.Invoke(model.id, true);
 2260            });
 261
 21262            hidePEXUIButton?.onClick.AddListener(() =>
 263            {
 1264                SetUIVisibility(false);
 1265                onShowPEXUI?.Invoke(model.id, false);
 1266            });
 267
 21268            if (startStopPEXToggle != null)
 269            {
 21270                startStopPEXToggle.OnSelectedChanged += (isOn, id, name) =>
 271                {
 9272                    SetAsPlaying(isOn);
 9273                    onStartPEX?.Invoke(model.id, isOn);
 6274                };
 275            }
 276
 21277            stopPEXButton?.onClick.AddListener(() =>
 278            {
 0279                SetAsPlaying(false);
 0280                onStartPEX?.Invoke(model.id, false);
 0281            });
 21282        }
 283    }
 284}