< Summary

Class:EventCardComponentView
Assembly:ExploreV2
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/Sections/PlacesAndEventsSection/SubSections/EventsSubSection/EventCard/EventCardComponentView.cs
Covered lines:12
Uncovered lines:160
Coverable lines:172
Total lines:476
Line coverage:6.9% (12 of 172)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
PostInitialization()0%6200%
Configure(...)0%2100%
RefreshControl()0%30500%
Dispose()0%660100%
SetEventPicture(...)0%6200%
SetEventPicture(...)0%12300%
SetEventPicture(...)0%12300%
SetEventAsLive(...)0%1821300%
SetLiveTagText(...)0%6200%
SetEventDate(...)0%6200%
SetEventName(...)0%6200%
SetEventDescription(...)0%6200%
SetEventStartedIn(...)0%6200%
SetEventStartsInFromTo(...)0%6200%
SetEventOrganizer(...)0%6200%
SetEventPlace(...)0%6200%
SetSubscribersUsers(...)0%20400%
SetLoadingIndicatorVisible(...)0%2100%
SetJumpInConfiguration(...)0%6200%
OnEventImageLoaded(...)0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/Sections/PlacesAndEventsSection/SubSections/EventsSubSection/EventCard/EventCardComponentView.cs

#LineLine coverage
 1using TMPro;
 2using UnityEngine;
 3using UnityEngine.UI;
 4
 5public interface IEventCardComponentView
 6{
 7    /// <summary>
 8    /// Event that will be triggered when the jumpIn button is clicked.
 9    /// </summary>
 10    Button.ButtonClickedEvent onJumpInClick { get; set; }
 11
 12    /// <summary>
 13    /// Event that will be triggered when the info button is clicked.
 14    /// </summary>
 15    Button.ButtonClickedEvent onInfoClick { get; set; }
 16
 17    /// <summary>
 18    /// Event that will be triggered when the subscribe event button is clicked.
 19    /// </summary>
 20    Button.ButtonClickedEvent onSubscribeClick { get; set; }
 21
 22    /// <summary>
 23    /// Event that will be triggered when the unsubscribe event button is clicked.
 24    /// </summary>
 25    Button.ButtonClickedEvent onUnsubscribeClick { get; set; }
 26
 27    /// <summary>
 28    /// Fill the model and updates the event card with this data.
 29    /// </summary>
 30    /// <param name="model">Data to configure the event card.</param>
 31    void Configure(EventCardComponentModel model);
 32
 33    /// <summary>
 34    /// Set the event picture directly from a sprite.
 35    /// </summary>
 36    /// <param name="sprite">Event picture (sprite).</param>
 37    void SetEventPicture(Sprite sprite);
 38
 39    /// <summary>
 40    /// Set the event picture from a 2D texture.
 41    /// </summary>
 42    /// <param name="texture">Event picture (url).</param>
 43    void SetEventPicture(Texture2D texture);
 44
 45    /// <summary>
 46    /// Set the event picture from an uri.
 47    /// </summary>
 48    /// <param name="uri"></param>
 49    void SetEventPicture(string uri);
 50
 51    /// <summary>
 52    /// Set the event card as live mode.
 53    /// </summary>
 54    /// <param name="isLive">True to set the event as live.</param>
 55    void SetEventAsLive(bool isLive);
 56
 57    /// <summary>
 58    /// Set the live tag text.
 59    /// </summary>
 60    /// <param name="newText">New text.</param>
 61    void SetLiveTagText(string newText);
 62
 63    /// <summary>
 64    /// Set the event date.
 65    /// </summary>
 66    /// <param name="newDate">The new date showed in the event card.</param>
 67    void SetEventDate(string newDate);
 68
 69    /// <summary>
 70    /// Set the event name in the card.
 71    /// </summary>
 72    /// <param name="newText">New event name.</param>
 73    void SetEventName(string newText);
 74
 75    /// <summary>
 76    /// Set the event description in the card.
 77    /// </summary>
 78    /// <param name="newText">New event description.</param>
 79    void SetEventDescription(string newText);
 80
 81    /// <summary>
 82    /// Set the event started time in the card.
 83    /// </summary>
 84    /// <param name="newText">New event started time.</param>
 85    void SetEventStartedIn(string newText);
 86
 87    /// <summary>
 88    /// Set the event dates range in the card.
 89    /// </summary>
 90    /// <param name="newText">New event date range.</param>
 91    void SetEventStartsInFromTo(string newText);
 92
 93    /// <summary>
 94    /// Set the event organizer in the card.
 95    /// </summary>
 96    /// <param name="newText">New event organizer.</param>
 97    void SetEventOrganizer(string newText);
 98
 99    /// <summary>
 100    /// Set the event place in the card.
 101    /// </summary>
 102    /// <param name="newText">New event place.</param>
 103    void SetEventPlace(string newText);
 104
 105    /// <summary>
 106    /// Set the the number of users subscribed to the event.
 107    /// </summary>
 108    /// <param name="newNumberOfUsers">Number of users subscribed.</param>
 109    void SetSubscribersUsers(int newNumberOfUsers);
 110
 111    /// <summary>
 112    /// Active or deactive the loading indicator.
 113    /// </summary>
 114    /// <param name="isVisible">True for showing the loading indicator and hiding the card info.</param>
 115    void SetLoadingIndicatorVisible(bool isVisible);
 116
 117    /// <summary>
 118    /// Set the configuration of the JumpIn button.
 119    /// </summary>
 120    /// <param name="jumpInConfig">JumpIn configuration.</param>
 121    void SetJumpInConfiguration(JumpInConfig jumpInConfig);
 122}
 123
 124public class EventCardComponentView : BaseComponentView, IEventCardComponentView
 125{
 126    [Header("Prefab References")]
 127    [SerializeField] internal ImageComponentView eventImage;
 128    [SerializeField] internal TagComponentView liveTag;
 129    [SerializeField] internal TMP_Text eventDateText;
 130    [SerializeField] internal TMP_Text eventNameText;
 131    [SerializeField] internal TMP_Text eventDescText;
 132    [SerializeField] internal TMP_Text eventStartedInTitleForLive;
 133    [SerializeField] internal TMP_Text eventStartedInTitleForNotLive;
 134    [SerializeField] internal TMP_Text eventStartedInText;
 135    [SerializeField] internal TMP_Text eventStartsInFromToText;
 136    [SerializeField] internal TMP_Text eventOrganizerText;
 137    [SerializeField] internal TMP_Text eventPlaceText;
 138    [SerializeField] internal TMP_Text subscribedUsersTitleForLive;
 139    [SerializeField] internal TMP_Text subscribedUsersTitleForNotLive;
 140    [SerializeField] internal TMP_Text subscribedUsersText;
 141    [SerializeField] internal ButtonComponentView infoButton;
 142    [SerializeField] internal ButtonComponentView jumpinButton;
 143    [SerializeField] internal ButtonComponentView subscribeEventButton;
 144    [SerializeField] internal ButtonComponentView unsubscribeEventButton;
 145    [SerializeField] internal GameObject imageContainer;
 146    [SerializeField] internal GameObject eventInfoContainer;
 147    [SerializeField] internal GameObject loadingSpinner;
 148
 149    [Header("Configuration")]
 150    [SerializeField] internal bool isEventCardModal = false;
 151    [SerializeField] internal EventCardComponentModel model;
 152
 153    public Button.ButtonClickedEvent onJumpInClick
 154    {
 155        get
 156        {
 0157            if (jumpinButton == null)
 0158                return null;
 159
 0160            return jumpinButton.onClick;
 161        }
 162        set
 163        {
 0164            model.onJumpInClick = value;
 165
 0166            if (jumpinButton != null)
 0167                jumpinButton.onClick = value;
 0168        }
 169    }
 170
 171    public Button.ButtonClickedEvent onInfoClick
 172    {
 173        get
 174        {
 0175            if (infoButton == null)
 0176                return null;
 177
 0178            return infoButton.onClick;
 179        }
 180        set
 181        {
 0182            model.onInfoClick = value;
 183
 0184            if (infoButton != null)
 0185                infoButton.onClick = value;
 0186        }
 187    }
 188
 189    public Button.ButtonClickedEvent onSubscribeClick
 190    {
 191        get
 192        {
 0193            if (subscribeEventButton == null)
 0194                return null;
 195
 0196            return subscribeEventButton.onClick;
 197        }
 198        set
 199        {
 0200            model.onSubscribeClick = value;
 201
 0202            if (subscribeEventButton != null)
 0203                subscribeEventButton.onClick = value;
 0204        }
 205    }
 206
 207    public Button.ButtonClickedEvent onUnsubscribeClick
 208    {
 209        get
 210        {
 0211            if (unsubscribeEventButton == null)
 0212                return null;
 213
 0214            return unsubscribeEventButton.onClick;
 215        }
 216        set
 217        {
 0218            model.onUnsubscribeClick = value;
 219
 0220            if (unsubscribeEventButton != null)
 0221                unsubscribeEventButton.onClick = value;
 0222        }
 223    }
 224
 225    public override void PostInitialization()
 226    {
 0227        if (eventImage != null)
 0228            eventImage.OnLoaded += OnEventImageLoaded;
 229
 0230        Configure(model);
 0231    }
 232
 233    public void Configure(EventCardComponentModel model)
 234    {
 0235        this.model = model;
 0236        RefreshControl();
 0237    }
 238
 239    public override void RefreshControl()
 240    {
 0241        if (model == null)
 0242            return;
 243
 0244        if (model.eventPictureSprite != null)
 0245            SetEventPicture(model.eventPictureSprite);
 0246        else if (model.eventPictureTexture != null)
 0247            SetEventPicture(model.eventPictureTexture);
 0248        else if (!string.IsNullOrEmpty(model.eventPictureUri))
 0249            SetEventPicture(model.eventPictureUri);
 250        else
 0251            SetEventPicture(sprite: null);
 252
 0253        SetEventAsLive(model.isLive);
 0254        SetLiveTagText(model.liveTagText);
 0255        SetEventDate(model.eventDateText);
 0256        SetEventName(model.eventName);
 0257        SetEventDescription(model.eventDescription);
 0258        SetEventStartedIn(model.eventStartedIn);
 0259        SetEventStartsInFromTo(model.eventStartsInFromTo);
 0260        SetEventOrganizer(model.eventOrganizer);
 0261        SetEventPlace(model.eventPlace);
 0262        SetSubscribersUsers(model.subscribedUsers);
 0263        SetJumpInConfiguration(model.jumpInConfiguration);
 0264        onJumpInClick = model.onJumpInClick;
 0265        onInfoClick = model.onInfoClick;
 0266        onSubscribeClick = model.onSubscribeClick;
 0267        onUnsubscribeClick = model.onUnsubscribeClick;
 0268    }
 269
 270    public override void Dispose()
 271    {
 31272        base.Dispose();
 273
 31274        if (eventImage != null)
 31275            eventImage.OnLoaded -= OnEventImageLoaded;
 276
 31277        if (infoButton != null)
 30278            infoButton.onClick.RemoveAllListeners();
 279
 31280        if (subscribeEventButton != null)
 31281            subscribeEventButton.onClick.RemoveAllListeners();
 282
 31283        if (unsubscribeEventButton != null)
 31284            unsubscribeEventButton.onClick.RemoveAllListeners();
 285
 31286        if (jumpinButton != null)
 31287            jumpinButton.onClick.RemoveAllListeners();
 31288    }
 289
 290    public void SetEventPicture(Sprite sprite)
 291    {
 0292        model.eventPictureSprite = sprite;
 293
 0294        if (eventImage == null)
 0295            return;
 296
 0297        eventImage.SetImage(sprite);
 0298    }
 299
 300    public void SetEventPicture(Texture2D texture)
 301    {
 0302        model.eventPictureTexture = texture;
 303
 0304        if (!Application.isPlaying)
 0305            return;
 306
 0307        if (eventImage == null)
 0308            return;
 309
 0310        eventImage.SetImage(texture);
 0311    }
 312
 313    public void SetEventPicture(string uri)
 314    {
 0315        model.eventPictureUri = uri;
 316
 0317        if (!Application.isPlaying)
 0318            return;
 319
 0320        if (eventImage == null)
 0321            return;
 322
 0323        eventImage.SetImage(uri);
 0324    }
 325
 326    public void SetEventAsLive(bool isLive)
 327    {
 0328        model.isLive = isLive;
 329
 0330        if (liveTag != null)
 0331            liveTag.gameObject.SetActive(isLive);
 332
 0333        if (eventDateText != null)
 0334            eventDateText.gameObject.SetActive(!isLive);
 335
 0336        if (jumpinButton != null)
 0337            jumpinButton.gameObject.SetActive(isLive);
 338
 0339        if (subscribeEventButton != null)
 0340            subscribeEventButton.gameObject.SetActive(!isLive && !model.isSubscribed);
 341
 0342        if (unsubscribeEventButton != null)
 0343            unsubscribeEventButton.gameObject.SetActive(!isLive && model.isSubscribed);
 344
 0345        if (eventStartedInTitleForLive)
 0346            eventStartedInTitleForLive.gameObject.SetActive(isLive);
 347
 0348        if (eventStartedInTitleForNotLive)
 0349            eventStartedInTitleForNotLive.gameObject.SetActive(!isLive);
 350
 0351        if (subscribedUsersTitleForLive != null)
 0352            subscribedUsersTitleForLive.gameObject.SetActive(isLive);
 353
 0354        if (subscribedUsersTitleForNotLive != null)
 0355            subscribedUsersTitleForNotLive.gameObject.SetActive(!isLive);
 0356    }
 357
 358    public void SetLiveTagText(string newText)
 359    {
 0360        model.liveTagText = newText;
 361
 0362        if (liveTag == null)
 0363            return;
 364
 0365        liveTag.SetText(newText);
 0366    }
 367
 368    public void SetEventDate(string newDate)
 369    {
 0370        model.eventDateText = newDate;
 371
 0372        if (eventDateText == null)
 0373            return;
 374
 0375        eventDateText.text = newDate;
 0376    }
 377
 378    public void SetEventName(string newText)
 379    {
 0380        model.eventName = newText;
 381
 0382        if (eventNameText == null)
 0383            return;
 384
 0385        eventNameText.text = newText;
 0386    }
 387
 388    public void SetEventDescription(string newText)
 389    {
 0390        model.eventDescription = newText;
 391
 0392        if (eventDescText == null)
 0393            return;
 394
 0395        eventDescText.text = newText;
 0396    }
 397
 398    public void SetEventStartedIn(string newText)
 399    {
 0400        model.eventStartedIn = newText;
 401
 0402        if (eventStartedInText == null)
 0403            return;
 404
 0405        eventStartedInText.text = newText;
 0406    }
 407
 408    public void SetEventStartsInFromTo(string newText)
 409    {
 0410        model.eventStartsInFromTo = newText;
 411
 0412        if (eventStartsInFromToText == null)
 0413            return;
 414
 0415        eventStartsInFromToText.text = newText;
 0416    }
 417
 418    public void SetEventOrganizer(string newText)
 419    {
 0420        model.eventOrganizer = newText;
 421
 0422        if (eventOrganizerText == null)
 0423            return;
 424
 0425        eventOrganizerText.text = newText;
 0426    }
 427
 428    public void SetEventPlace(string newText)
 429    {
 0430        model.eventPlace = newText;
 431
 0432        if (eventPlaceText == null)
 0433            return;
 434
 0435        eventPlaceText.text = newText;
 0436    }
 437
 438    public void SetSubscribersUsers(int newNumberOfUsers)
 439    {
 0440        model.subscribedUsers = newNumberOfUsers;
 441
 0442        if (subscribedUsersText == null)
 0443            return;
 444
 0445        if (!isEventCardModal)
 446        {
 0447            subscribedUsersText.text = newNumberOfUsers.ToString();
 0448        }
 449        else
 450        {
 0451            if (newNumberOfUsers > 0)
 0452                subscribedUsersText.text = $"{newNumberOfUsers} confirmed";
 453            else
 0454                subscribedUsersText.text = "Nobody confirmed yet";
 455        }
 0456    }
 457
 458    public void SetLoadingIndicatorVisible(bool isVisible)
 459    {
 0460        imageContainer.SetActive(!isVisible);
 0461        eventInfoContainer.SetActive(!isVisible);
 0462        loadingSpinner.SetActive(isVisible);
 0463    }
 464
 465    public void SetJumpInConfiguration(JumpInConfig jumpInConfig)
 466    {
 0467        jumpinButton.GetComponent<JumpInAction>().coords = jumpInConfig.coords;
 0468        jumpinButton.GetComponent<JumpInAction>().serverName = jumpInConfig.serverName;
 0469        jumpinButton.GetComponent<JumpInAction>().layerName = jumpInConfig.layerName;
 470
 0471        if (isEventCardModal)
 0472            jumpinButton.SetText($"{jumpInConfig.coords[0]},{jumpInConfig.coords[1]}");
 0473    }
 474
 0475    private void OnEventImageLoaded(Sprite sprite) { SetEventPicture(sprite); }
 476}