< Summary

Class:DCL.Builder.PublishProjectProgressView
Assembly:BuilderPublisher
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Publisher/ProjectPublishHUD/Scripts/PublishProjectProgressView.cs
Covered lines:0
Uncovered lines:43
Coverable lines:43
Total lines:150
Line coverage:0% (0 of 43)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%2100%
Dispose()0%6200%
RefreshControl()0%2100%
ShowConfirmPopUp()0%2100%
Close()0%6200%
ConfirmPublish()0%6200%
PublishStarted()0%6200%
Hide()0%2100%
PublishError(...)0%2100%
SetPercentage(...)0%2100%
FakePublishProgress()0%12300%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/Publisher/ProjectPublishHUD/Scripts/PublishProjectProgressView.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using System.Collections.Generic;
 4using TMPro;
 5using UnityEngine;
 6using UnityEngine.UI;
 7
 8namespace DCL.Builder
 9{
 10    public interface IPublishProjectProgressView
 11    {
 12        /// <summary>
 13        /// This action will be called when the confirm button is pressed
 14        /// </summary>
 15        event Action OnPublishConfirmButtonPressed;
 16
 17        /// <summary>
 18        /// This action will be called when the view is closed
 19        /// </summary>
 20        event Action OnViewClosed;
 21
 22        /// <summary>
 23        /// Show the confirm publish pop up
 24        /// </summary>
 25        void ShowConfirmPopUp();
 26
 27        /// <summary>
 28        /// Call this function when the publish start
 29        /// </summary>
 30        void PublishStarted();
 31
 32        /// <summary>
 33        /// Hide the view
 34        /// </summary>
 35        void Hide();
 36
 37        /// <summary>
 38        /// Shows the errors passes in a pop up
 39        /// </summary>
 40        /// <param name="message"></param>
 41        void PublishError(string message);
 42
 43        /// <summary>
 44        /// Dispose the view
 45        /// </summary>
 46        void Dispose();
 47    }
 48
 49    public class PublishProjectProgressView : BaseComponentView, IPublishProjectProgressView
 50    {
 51        public event Action OnPublishConfirmButtonPressed;
 52        public event Action OnViewClosed;
 53
 54        [SerializeField] internal Button closeButton;
 55        [SerializeField] internal Button cancelButton;
 56        [SerializeField] internal Button publishButton;
 57        [SerializeField] internal TMP_Text errorTextView;
 58
 59        [SerializeField] internal ModalComponentView modal;
 60
 61        [SerializeField] internal GameObject errorGameObject;
 62        [SerializeField] internal GameObject confirmGameObject;
 63        [SerializeField] internal GameObject progressGameObject;
 64
 65        [SerializeField] internal LoadingBar loadingBar;
 66
 67        private float currentProgress = 0;
 68
 69        private Coroutine fakeProgressCoroutine;
 70
 71        public override void Awake()
 72        {
 073            base.Awake();
 074            closeButton.onClick.AddListener(Close);
 075            cancelButton.onClick.AddListener(Close);
 076            publishButton.onClick.AddListener(ConfirmPublish);
 077        }
 78
 79        public override void Dispose()
 80        {
 081            base.Dispose();
 082            closeButton.onClick.RemoveAllListeners();
 083            cancelButton.onClick.RemoveAllListeners();
 084            publishButton.onClick.RemoveAllListeners();
 85
 086            if (fakeProgressCoroutine != null)
 087                StopCoroutine(fakeProgressCoroutine);
 088        }
 89
 090        public override void RefreshControl() {  }
 91
 92        public void ShowConfirmPopUp()
 93        {
 094            modal.Show();
 095            errorGameObject.SetActive(false);
 096            confirmGameObject.SetActive(true);
 097            progressGameObject.SetActive(false);
 098        }
 99
 100        public void Close()
 101        {
 0102            modal.Hide();
 0103            OnViewClosed?.Invoke();
 0104        }
 105
 0106        public void ConfirmPublish() { OnPublishConfirmButtonPressed?.Invoke(); }
 107
 108        public void PublishStarted()
 109        {
 0110            currentProgress = 0;
 111
 0112            Show();
 0113            loadingBar.SetActive(true);
 0114            errorGameObject.SetActive(false);
 0115            confirmGameObject.SetActive(false);
 0116            if (fakeProgressCoroutine != null)
 0117                StopCoroutine(fakeProgressCoroutine);
 0118            fakeProgressCoroutine = StartCoroutine(FakePublishProgress());
 0119            AudioScriptableObjects.enable.Play();
 0120        }
 121
 0122        public void Hide() { modal.Hide(); }
 123
 124        public void PublishError(string message)
 125        {
 0126            loadingBar.SetActive(false);
 0127            errorGameObject.SetActive(true);
 0128            confirmGameObject.SetActive(false);
 129
 0130            errorTextView.text = message;
 0131        }
 132
 0133        public void SetPercentage(float newValue) { loadingBar.SetPercentage(newValue); }
 134
 135        private IEnumerator FakePublishProgress()
 136        {
 0137            while (true)
 138            {
 0139                float newPercentage = Mathf.Clamp(
 140                    currentProgress + UnityEngine.Random.Range(1f, 10f),
 141                    currentProgress,
 142                    99f);
 143
 0144                SetPercentage(newPercentage);
 145
 0146                yield return new WaitForSeconds(UnityEngine.Random.Range(0f, 0.5f));
 147            }
 148        }
 149    }
 150}