< Summary

Class:ProfileCardComponentView
Assembly:UIComponents
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/UIComponents/Scripts/Components/ProfileCard/ProfileCardComponentView.cs
Covered lines:42
Uncovered lines:28
Coverable lines:70
Total lines:198
Line coverage:60% (42 of 70)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
PostInitialization()0%220100%
Configure(...)0%110100%
RefreshControl()0%7.465053.85%
Dispose()0%3.033085.71%
SetProfilePicture(...)0%2.032080%
SetProfilePicture(...)0%12300%
SetProfilePicture(...)0%12300%
SetProfileName(...)0%4.134080%
SetProfileAddress(...)0%4.054085.71%
SetLoadingIndicatorVisible(...)0%110100%
OnProfileImageLoaded(...)0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/UIComponents/Scripts/Components/ProfileCard/ProfileCardComponentView.cs

#LineLine coverage
 1using TMPro;
 2using UnityEngine;
 3using UnityEngine.UI;
 4
 5public interface IProfileCardComponentView
 6{
 7    /// <summary>
 8    /// Event that will be triggered when the profile card is clicked.
 9    /// </summary>
 10    Button.ButtonClickedEvent onClick { get; set; }
 11
 12    /// <summary>
 13    /// Fill the model and updates the profile card with this data.
 14    /// </summary>
 15    /// <param name="model">Data to configure the profile card.</param>
 16    void Configure(ProfileCardComponentModel model);
 17
 18    /// <summary>
 19    /// Set the profile picture directly from a sprite.
 20    /// </summary>
 21    /// <param name="sprite">Profile picture (sprite).</param>
 22    void SetProfilePicture(Sprite sprite);
 23
 24    /// <summary>
 25    /// Set the profile picture from a 2D texture.
 26    /// </summary>
 27    /// <param name="newPicture">Profile picture (2D texture).</param>
 28    void SetProfilePicture(Texture2D newPicture);
 29
 30    /// <summary>
 31    /// Set the profile picture from an uri.
 32    /// </summary>
 33    /// <param name="uri">Profile picture (url).</param>
 34    void SetProfilePicture(string uri);
 35
 36    /// <summary>
 37    /// Set the profile name.
 38    /// </summary>
 39    /// <param name="newName">Profile name.</param>
 40    void SetProfileName(string newName);
 41
 42    /// <summary>
 43    /// Set the profile address. It will only show the last 4 caracteres.
 44    /// </summary>
 45    /// <param name="newAddress">Profile address.</param>
 46    void SetProfileAddress(string newAddress);
 47
 48    /// <summary>
 49    /// Active or deactive the loading indicator.
 50    /// </summary>
 51    /// <param name="isVisible">True for showing the loading indicator.</param>
 52    void SetLoadingIndicatorVisible(bool isVisible);
 53}
 54
 55public class ProfileCardComponentView : BaseComponentView, IProfileCardComponentView
 56{
 57    [Header("Prefab References")]
 58    [SerializeField] internal Button button;
 59    [SerializeField] internal ImageComponentView profileImage;
 60    [SerializeField] internal TMP_Text profileName;
 61    [SerializeField] internal TMP_Text profileAddress;
 62
 63    [Header("Configuration")]
 64    [SerializeField] internal ProfileCardComponentModel model;
 65
 66    public Button.ButtonClickedEvent onClick
 67    {
 68        get
 69        {
 170            if (button == null)
 071                return null;
 72
 173            return button.onClick;
 74        }
 75        set
 76        {
 1977            model.onClick = value;
 78
 1979            if (button != null)
 80            {
 1981                button.onClick.RemoveAllListeners();
 1982                button.onClick.AddListener(() =>
 83                {
 084                    value?.Invoke();
 085                });
 86            }
 1987        }
 88    }
 89
 90    public override void PostInitialization()
 91    {
 1792        if (profileImage != null)
 1793            profileImage.OnLoaded += OnProfileImageLoaded;
 94
 1795        Configure(model);
 1796    }
 97
 98    public void Configure(ProfileCardComponentModel model)
 99    {
 18100        this.model = model;
 18101        RefreshControl();
 18102    }
 103
 104    public override void RefreshControl()
 105    {
 19106        if (model == null)
 0107            return;
 108
 19109        if (model.profilePictureSprite != null)
 19110            SetProfilePicture(model.profilePictureSprite);
 0111        else if (model.profilePictureTexture != null)
 0112            SetProfilePicture(model.profilePictureTexture);
 0113        else if (!string.IsNullOrEmpty(model.profilePictureUri))
 0114            SetProfilePicture(model.profilePictureUri);
 115        else
 0116            SetProfilePicture(sprite: null);
 117
 19118        SetProfileName(model.profileName);
 19119        SetProfileAddress(model.profileAddress);
 19120        onClick = model.onClick;
 19121    }
 122
 123    public override void Dispose()
 124    {
 40125        base.Dispose();
 126
 40127        if (profileImage != null)
 40128            profileImage.OnLoaded += OnProfileImageLoaded;
 129
 40130        if (button == null)
 0131            return;
 132
 40133        button.onClick.RemoveAllListeners();
 40134    }
 135
 136    public void SetProfilePicture(Sprite sprite)
 137    {
 20138        model.profilePictureSprite = sprite;
 139
 20140        if (profileImage == null)
 0141            return;
 142
 20143        profileImage.SetImage(sprite);
 20144    }
 145
 146    public void SetProfilePicture(Texture2D texture)
 147    {
 0148        model.profilePictureTexture = texture;
 149
 0150        if (!Application.isPlaying)
 0151            return;
 152
 0153        if (profileImage == null)
 0154            return;
 155
 0156        profileImage.SetImage(texture);
 0157    }
 158
 159    public void SetProfilePicture(string uri)
 160    {
 0161        model.profilePictureUri = uri;
 162
 0163        if (!Application.isPlaying)
 0164            return;
 165
 0166        if (profileImage == null)
 0167            return;
 168
 0169        profileImage.SetImage(uri);
 0170    }
 171
 172    public void SetProfileName(string newName)
 173    {
 21174        model.profileName = newName;
 175
 21176        if (profileName == null)
 0177            return;
 178
 21179        profileName.text = !string.IsNullOrEmpty(newName) ? newName : string.Empty;
 21180    }
 181
 182    public void SetProfileAddress(string newAddress)
 183    {
 22184        model.profileAddress = newAddress;
 185
 22186        if (profileAddress == null)
 0187            return;
 188
 22189        if (!string.IsNullOrEmpty(newAddress))
 21190            profileAddress.text = newAddress.Length >= 4 ? $"#{newAddress.Substring(newAddress.Length - 4, 4)}" : $"#{ne
 191        else
 1192            profileAddress.text = string.Empty;
 1193    }
 194
 4195    public void SetLoadingIndicatorVisible(bool isVisible) { profileImage.SetLoadingIndicatorVisible(isVisible); }
 196
 0197    internal void OnProfileImageLoaded(Sprite sprite) { SetProfilePicture(sprite); }
 198}