< Summary

Class:ProfileCardComponentView
Assembly:UIComponents
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/UIComponents/Scripts/Components/ProfileCard/ProfileCardComponentView.cs
Covered lines:50
Uncovered lines:13
Coverable lines:63
Total lines:180
Line coverage:79.3% (50 of 63)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Start()0%220100%
Configure(...)0%110100%
RefreshControl()0%7.465053.85%
Dispose()0%220100%
SetProfilePicture(...)0%2.032080%
SetProfilePicture(...)0%3.213071.43%
SetProfilePicture(...)0%3.213071.43%
SetProfileName(...)0%6.296080%
SetProfileAddress(...)0%4.054085.71%
SetIsClaimedName(...)0%550100%
SetLoadingIndicatorVisible(...)0%110100%
OnProfileImageLoaded(...)0%110100%

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; }
 11
 12    /// <summary>
 13    /// Set the profile picture directly from a sprite.
 14    /// </summary>
 15    /// <param name="sprite">Profile picture (sprite).</param>
 16    void SetProfilePicture(Sprite sprite);
 17
 18    /// <summary>
 19    /// Set the profile picture from a 2D texture.
 20    /// </summary>
 21    /// <param name="newPicture">Profile picture (2D texture).</param>
 22    void SetProfilePicture(Texture2D newPicture);
 23
 24    /// <summary>
 25    /// Set the profile picture from an uri.
 26    /// </summary>
 27    /// <param name="uri">Profile picture (url).</param>
 28    void SetProfilePicture(string uri);
 29
 30    /// <summary>
 31    /// Set the profile name.
 32    /// </summary>
 33    /// <param name="newName">Profile name.</param>
 34    void SetProfileName(string newName);
 35
 36    /// <summary>
 37    /// Set the profile address. It will only show the last 4 caracteres.
 38    /// </summary>
 39    /// <param name="newAddress">Profile address.</param>
 40    void SetProfileAddress(string newAddress);
 41
 42    /// <summary>
 43    /// Set the profile name.
 44    /// </summary>
 45    /// <param name="newName">Profile name.</param>
 46    void SetIsClaimedName(bool isClaimedName);
 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, IComponentModelConfig<ProfileCardC
 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
 166    public Button.ButtonClickedEvent onClick => button?.onClick;
 67
 68    public override void Start()
 69    {
 2970        if (profileImage != null)
 2971            profileImage.OnLoaded += OnProfileImageLoaded;
 2972    }
 73
 74    public void Configure(ProfileCardComponentModel newModel)
 75    {
 176        model = newModel;
 177        RefreshControl();
 178    }
 79
 80    public override void RefreshControl()
 81    {
 182        if (model == null)
 083            return;
 84
 185        if (model.profilePictureSprite != null)
 186            SetProfilePicture(model.profilePictureSprite);
 087        else if (model.profilePictureTexture != null)
 088            SetProfilePicture(model.profilePictureTexture);
 089        else if (!string.IsNullOrEmpty(model.profilePictureUri))
 090            SetProfilePicture(model.profilePictureUri);
 91        else
 092            SetProfilePicture(sprite: null);
 93
 194        SetProfileName(model.profileName);
 195        SetProfileAddress(model.profileAddress);
 196        SetIsClaimedName(model.isClaimedName);
 197    }
 98
 99    public override void Dispose()
 100    {
 61101        base.Dispose();
 102
 61103        if (profileImage != null)
 61104            profileImage.OnLoaded += OnProfileImageLoaded;
 61105    }
 106
 107    public void SetProfilePicture(Sprite sprite)
 108    {
 3109        model.profilePictureSprite = sprite;
 110
 3111        if (profileImage == null)
 0112            return;
 113
 3114        profileImage.SetImage(sprite);
 3115    }
 116
 117    public void SetProfilePicture(Texture2D texture)
 118    {
 1119        model.profilePictureTexture = texture;
 120
 1121        if (!Application.isPlaying)
 0122            return;
 123
 1124        if (profileImage == null)
 0125            return;
 126
 1127        profileImage.SetImage(texture);
 1128    }
 129
 130    public void SetProfilePicture(string uri)
 131    {
 1132        model.profilePictureUri = uri;
 133
 1134        if (!Application.isPlaying)
 0135            return;
 136
 1137        if (profileImage == null)
 0138            return;
 139
 1140        profileImage.SetImage(uri);
 1141    }
 142
 143    public void SetProfileName(string newName)
 144    {
 4145        model.profileName = newName;
 146
 4147        if (profileName == null)
 0148            return;
 149
 4150        profileName.text = !string.IsNullOrEmpty(newName) ? (model.isClaimedName ? newName : newName.Split('#')[0]) : st
 4151    }
 152
 153    public void SetProfileAddress(string newAddress)
 154    {
 4155        model.profileAddress = newAddress;
 156
 4157        if (profileAddress == null)
 0158            return;
 159
 4160        if (!string.IsNullOrEmpty(newAddress))
 3161            profileAddress.text = newAddress.Length >= 4 ? $"#{newAddress.Substring(newAddress.Length - 4, 4)}" : $"#{ne
 162        else
 1163            profileAddress.text = string.Empty;
 1164    }
 165
 166    public void SetIsClaimedName(bool isClaimedName)
 167    {
 3168        model.isClaimedName = isClaimedName;
 169
 3170        if (profileName != null)
 3171            profileName.alignment = isClaimedName ? TextAlignmentOptions.Center : TextAlignmentOptions.Right;
 172
 3173        if (profileAddress != null)
 3174            profileAddress.gameObject.SetActive(!isClaimedName);
 3175    }
 176
 4177    public void SetLoadingIndicatorVisible(bool isVisible) { profileImage.SetLoadingIndicatorVisible(isVisible); }
 178
 2179    internal void OnProfileImageLoaded(Sprite sprite) { SetProfilePicture(sprite); }
 180}