< Summary

Class:UnpublishPopupView
Assembly:BuilderProjectsPanel
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/Unpublish/UnpublishPopupView.cs
Covered lines:66
Uncovered lines:3
Coverable lines:69
Total lines:147
Line coverage:95.6% (66 of 69)
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%3.333066.67%
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/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/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    {
 2360        if (gameObject == null)
 061            return;
 62
 2363        if (isDestroyed)
 064            return;
 65
 2366        Destroy(gameObject);
 2367    }
 68
 69    void IUnpublishPopupView.Show(string title, string info)
 70    {
 371        titleText.text = title;
 372        infoText.text = info;
 373        SetState(State.CONFIRM_UNPUBLISH);
 374        gameObject.SetActive(true);
 375    }
 76
 4677    void IUnpublishPopupView.Hide() { gameObject.SetActive(false); }
 78
 79    void IUnpublishPopupView.SetProgress(string title, float progress)
 80    {
 481        titleText.text = title;
 482        loadingText.text = $"{Mathf.FloorToInt(100 * progress)}%";
 483        loadingImageRT.sizeDelta = new Vector2(loadingImageFullWidth * progress, loadingImageRT.sizeDelta.y);
 484        SetState(State.UNPUBLISHING);
 485    }
 86
 87    void IUnpublishPopupView.SetError(string title, string error)
 88    {
 289        titleText.text = title;
 290        errorText.text = error;
 291        SetState(State.ERROR_UNPUBLISH);
 292    }
 93
 94    void IUnpublishPopupView.SetSuccess(string title, string info)
 95    {
 296        titleText.text = title;
 297        infoText.text = info;
 298        SetState(State.DONE_UNPUBLISH);
 299    }
 100
 101    private void SetState(State newState)
 102    {
 11103        if (state == newState)
 1104            return;
 105
 10106        state = newState;
 10107        switch (state)
 108        {
 109            case State.CONFIRM_UNPUBLISH:
 3110                cancelButton.gameObject.SetActive(true);
 3111                unpublishButton.gameObject.SetActive(true);
 3112                doneButton.gameObject.SetActive(false);
 3113                infoText.gameObject.SetActive(true);
 3114                errorText.gameObject.SetActive(false);
 3115                loadingBarContainer.SetActive(false);
 3116                closeButton.gameObject.SetActive(true);
 3117                break;
 118            case State.UNPUBLISHING:
 3119                cancelButton.gameObject.SetActive(false);
 3120                unpublishButton.gameObject.SetActive(false);
 3121                doneButton.gameObject.SetActive(false);
 3122                infoText.gameObject.SetActive(false);
 3123                errorText.gameObject.SetActive(false);
 3124                loadingBarContainer.SetActive(true);
 3125                closeButton.gameObject.SetActive(false);
 3126                break;
 127            case State.DONE_UNPUBLISH:
 2128                cancelButton.gameObject.SetActive(false);
 2129                unpublishButton.gameObject.SetActive(false);
 2130                doneButton.gameObject.SetActive(true);
 2131                infoText.gameObject.SetActive(true);
 2132                errorText.gameObject.SetActive(false);
 2133                loadingBarContainer.SetActive(false);
 2134                closeButton.gameObject.SetActive(true);
 2135                break;
 136            case State.ERROR_UNPUBLISH:
 2137                cancelButton.gameObject.SetActive(false);
 2138                unpublishButton.gameObject.SetActive(false);
 2139                doneButton.gameObject.SetActive(true);
 2140                infoText.gameObject.SetActive(false);
 2141                errorText.gameObject.SetActive(true);
 2142                loadingBarContainer.SetActive(false);
 2143                closeButton.gameObject.SetActive(true);
 144                break;
 145        }
 2146    }
 147}