< Summary

Class:UnpublishPopupView
Assembly:BuilderProjectsPanel
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/BuilderProjectsPanel/Scripts/Unpublish/UnpublishPopupView.cs
Covered lines:65
Uncovered lines:1
Coverable lines:66
Total lines:144
Line coverage:98.4% (65 of 66)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%110100%
OnDestroy()0%110100%
Dispose()0%330100%
Show(...)0%110100%
Hide()0%110100%
SetProgress(...)0%110100%
SetError(...)0%110100%
SetSuccess(...)0%110100%
SetState(...)0%660100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/BuilderProjectsPanel/Scripts/Unpublish/UnpublishPopupView.cs

#LineLine coverage
 1using System;
 2using TMPro;
 3using UnityEngine;
 4using UnityEngine.UI;
 5
 6internal interface IUnpublishPopupView : IDisposable
 7{
 8    event Action OnConfirmPressed;
 9    event Action OnCancelPressed;
 10    void Show(string title, string info);
 11    void Hide();
 12    void SetProgress(string title, float progress);
 13    void SetError(string title, string error);
 14    void SetSuccess(string title, string info);
 15}
 16
 17internal class UnpublishPopupView : MonoBehaviour, IUnpublishPopupView
 18{
 19    [SerializeField] internal TextMeshProUGUI titleText;
 20    [SerializeField] internal TextMeshProUGUI infoText;
 21    [SerializeField] internal TextMeshProUGUI errorText;
 22    [SerializeField] internal Button cancelButton;
 23    [SerializeField] internal Button unpublishButton;
 24    [SerializeField] internal Button doneButton;
 25    [SerializeField] internal Button closeButton;
 26    [SerializeField] internal GameObject loadingBarContainer;
 27    [SerializeField] internal RectTransform loadingImageRT;
 28    [SerializeField] internal TextMeshProUGUI loadingText;
 29
 30    public event Action OnConfirmPressed;
 31    public event Action OnCancelPressed;
 32
 33    internal enum State
 34    {
 35        NONE,
 36        CONFIRM_UNPUBLISH,
 37        UNPUBLISHING,
 38        DONE_UNPUBLISH,
 39        ERROR_UNPUBLISH
 40    }
 41
 042    internal State state { private set; get; } = State.NONE;
 43
 44    private bool isDestroyed = false;
 45    private float loadingImageFullWidth;
 46
 47    private void Awake()
 48    {
 1049        unpublishButton.onClick.AddListener(() => { OnConfirmPressed?.Invoke(); });
 650        cancelButton.onClick.AddListener(() => { OnCancelPressed?.Invoke(); });
 651        closeButton.onClick.AddListener(() => { OnCancelPressed?.Invoke(); });
 652        doneButton.onClick.AddListener(() => { OnCancelPressed?.Invoke(); });
 653        loadingImageFullWidth = loadingImageRT.rect.size.x;
 654    }
 55
 1256    private void OnDestroy() { isDestroyed = true; }
 57
 58    public void Dispose()
 59    {
 1860        if (!isDestroyed && gameObject != null)
 61        {
 1862            Destroy(gameObject);
 63        }
 1864    }
 65
 66    void IUnpublishPopupView.Show(string title, string info)
 67    {
 368        titleText.text = title;
 369        infoText.text = info;
 370        SetState(State.CONFIRM_UNPUBLISH);
 371        gameObject.SetActive(true);
 372    }
 73
 3674    void IUnpublishPopupView.Hide() { gameObject.SetActive(false); }
 75
 76    void IUnpublishPopupView.SetProgress(string title, float progress)
 77    {
 478        titleText.text = title;
 479        loadingText.text = $"{Mathf.FloorToInt(100 * progress)}%";
 480        loadingImageRT.sizeDelta = new Vector2(loadingImageFullWidth * progress, loadingImageRT.sizeDelta.y);
 481        SetState(State.UNPUBLISHING);
 482    }
 83
 84    void IUnpublishPopupView.SetError(string title, string error)
 85    {
 286        titleText.text = title;
 287        errorText.text = error;
 288        SetState(State.ERROR_UNPUBLISH);
 289    }
 90
 91    void IUnpublishPopupView.SetSuccess(string title, string info)
 92    {
 293        titleText.text = title;
 294        infoText.text = info;
 295        SetState(State.DONE_UNPUBLISH);
 296    }
 97
 98    private void SetState(State newState)
 99    {
 11100        if (state == newState)
 1101            return;
 102
 10103        state = newState;
 10104        switch (state)
 105        {
 106            case State.CONFIRM_UNPUBLISH:
 3107                cancelButton.gameObject.SetActive(true);
 3108                unpublishButton.gameObject.SetActive(true);
 3109                doneButton.gameObject.SetActive(false);
 3110                infoText.gameObject.SetActive(true);
 3111                errorText.gameObject.SetActive(false);
 3112                loadingBarContainer.SetActive(false);
 3113                closeButton.gameObject.SetActive(true);
 3114                break;
 115            case State.UNPUBLISHING:
 3116                cancelButton.gameObject.SetActive(false);
 3117                unpublishButton.gameObject.SetActive(false);
 3118                doneButton.gameObject.SetActive(false);
 3119                infoText.gameObject.SetActive(false);
 3120                errorText.gameObject.SetActive(false);
 3121                loadingBarContainer.SetActive(true);
 3122                closeButton.gameObject.SetActive(false);
 3123                break;
 124            case State.DONE_UNPUBLISH:
 2125                cancelButton.gameObject.SetActive(false);
 2126                unpublishButton.gameObject.SetActive(false);
 2127                doneButton.gameObject.SetActive(true);
 2128                infoText.gameObject.SetActive(true);
 2129                errorText.gameObject.SetActive(false);
 2130                loadingBarContainer.SetActive(false);
 2131                closeButton.gameObject.SetActive(true);
 2132                break;
 133            case State.ERROR_UNPUBLISH:
 2134                cancelButton.gameObject.SetActive(false);
 2135                unpublishButton.gameObject.SetActive(false);
 2136                doneButton.gameObject.SetActive(true);
 2137                infoText.gameObject.SetActive(false);
 2138                errorText.gameObject.SetActive(true);
 2139                loadingBarContainer.SetActive(false);
 2140                closeButton.gameObject.SetActive(true);
 141                break;
 142        }
 2143    }
 144}