< 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:150
Uncovered lines:24
Coverable lines:174
Total lines:469
Line coverage:86.2% (150 of 174)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
EventCardComponentView()0%110100%
Start()0%550100%
Configure(...)0%110100%
RefreshControl()0%5.515072.73%
OnFocus()0%220100%
OnLoseFocus()0%220100%
Dispose()0%550100%
SetEventPicture(...)0%4.374071.43%
SetEventPicture(...)0%6.65060%
SetEventPicture(...)0%6.65060%
SetEventAsLive(...)0%13130100%
SetLiveTagText(...)0%2.032080%
SetEventDate(...)0%2.032080%
SetEventName(...)0%2.032080%
SetEventDescription(...)0%220100%
SetEventStartedIn(...)0%220100%
SetEventStartsInFromTo(...)0%220100%
SetEventOrganizer(...)0%220100%
SetEventPlace(...)0%220100%
SetSubscribersUsers(...)0%4.024090%
SetCoords(...)0%330100%
SetLoadingIndicatorVisible(...)0%110100%
OnEventImageLoaded(...)0%110100%
RebuildCardLayouts()0%440100%
CloseModal()0%110100%
OnCloseActionTriggered(...)0%110100%

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 DCL.Helpers;
 2using TMPro;
 3using UnityEngine;
 4using UnityEngine.UI;
 5
 6public interface IEventCardComponentView
 7{
 8    /// <summary>
 9    /// Event that will be triggered when the jumpIn button is clicked.
 10    /// </summary>
 11    Button.ButtonClickedEvent onJumpInClick { get; }
 12
 13    /// <summary>
 14    /// Event that will be triggered when the info button is clicked.
 15    /// </summary>
 16    Button.ButtonClickedEvent onInfoClick { get; }
 17
 18    /// <summary>
 19    /// Event that will be triggered when the subscribe event button is clicked.
 20    /// </summary>
 21    Button.ButtonClickedEvent onSubscribeClick { get; }
 22
 23    /// <summary>
 24    /// Event that will be triggered when the unsubscribe event button is clicked.
 25    /// </summary>
 26    Button.ButtonClickedEvent onUnsubscribeClick { get; }
 27
 28    /// <summary>
 29    /// Set the event picture directly from a sprite.
 30    /// </summary>
 31    /// <param name="sprite">Event picture (sprite).</param>
 32    void SetEventPicture(Sprite sprite);
 33
 34    /// <summary>
 35    /// Set the event picture from a 2D texture.
 36    /// </summary>
 37    /// <param name="texture">Event picture (url).</param>
 38    void SetEventPicture(Texture2D texture);
 39
 40    /// <summary>
 41    /// Set the event picture from an uri.
 42    /// </summary>
 43    /// <param name="uri"></param>
 44    void SetEventPicture(string uri);
 45
 46    /// <summary>
 47    /// Set the event card as live mode.
 48    /// </summary>
 49    /// <param name="isLive">True to set the event as live.</param>
 50    void SetEventAsLive(bool isLive);
 51
 52    /// <summary>
 53    /// Set the live tag text.
 54    /// </summary>
 55    /// <param name="newText">New text.</param>
 56    void SetLiveTagText(string newText);
 57
 58    /// <summary>
 59    /// Set the event date.
 60    /// </summary>
 61    /// <param name="newDate">The new date showed in the event card.</param>
 62    void SetEventDate(string newDate);
 63
 64    /// <summary>
 65    /// Set the event name in the card.
 66    /// </summary>
 67    /// <param name="newText">New event name.</param>
 68    void SetEventName(string newText);
 69
 70    /// <summary>
 71    /// Set the event description in the card.
 72    /// </summary>
 73    /// <param name="newText">New event description.</param>
 74    void SetEventDescription(string newText);
 75
 76    /// <summary>
 77    /// Set the event started time in the card.
 78    /// </summary>
 79    /// <param name="newText">New event started time.</param>
 80    void SetEventStartedIn(string newText);
 81
 82    /// <summary>
 83    /// Set the event dates range in the card.
 84    /// </summary>
 85    /// <param name="newText">New event date range.</param>
 86    void SetEventStartsInFromTo(string newText);
 87
 88    /// <summary>
 89    /// Set the event organizer in the card.
 90    /// </summary>
 91    /// <param name="newText">New event organizer.</param>
 92    void SetEventOrganizer(string newText);
 93
 94    /// <summary>
 95    /// Set the event place in the card.
 96    /// </summary>
 97    /// <param name="newText">New event place.</param>
 98    void SetEventPlace(string newText);
 99
 100    /// <summary>
 101    /// Set the the number of users subscribed to the event.
 102    /// </summary>
 103    /// <param name="newNumberOfUsers">Number of users subscribed.</param>
 104    void SetSubscribersUsers(int newNumberOfUsers);
 105
 106    /// <summary>
 107    /// Set the event coords.
 108    /// </summary>
 109    /// <param name="newCoords">Event coords.</param>
 110    void SetCoords(Vector2Int newCoords);
 111
 112    /// <summary>
 113    /// Active or deactive the loading indicator.
 114    /// </summary>
 115    /// <param name="isVisible">True for showing the loading indicator and hiding the card info.</param>
 116    void SetLoadingIndicatorVisible(bool isVisible);
 117}
 118
 119public class EventCardComponentView : BaseComponentView, IEventCardComponentView, IComponentModelConfig
 120{
 121    internal const string USERS_CONFIRMED_MESSAGE = "{0} confirmed";
 122    internal const string NOBODY_CONFIRMED_MESSAGE = "Nobody confirmed yet";
 123
 1124    internal static readonly int ON_FOCUS_CARD_COMPONENT_BOOL = Animator.StringToHash("OnFocus");
 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 Button modalBackgroundButton;
 142    [SerializeField] internal ButtonComponentView closeCardButton;
 143    [SerializeField] internal InputAction_Trigger closeAction;
 144    [SerializeField] internal ButtonComponentView infoButton;
 145    [SerializeField] internal ButtonComponentView jumpinButton;
 146    [SerializeField] internal ButtonComponentView subscribeEventButton;
 147    [SerializeField] internal ButtonComponentView unsubscribeEventButton;
 148    [SerializeField] internal GameObject imageContainer;
 149    [SerializeField] internal GameObject eventInfoContainer;
 150    [SerializeField] internal GameObject loadingSpinner;
 151    [SerializeField] internal Animator cardAnimator;
 152    [SerializeField] internal VerticalLayoutGroup contentVerticalLayout;
 153    [SerializeField] internal VerticalLayoutGroup infoVerticalLayout;
 154    [SerializeField] internal HorizontalLayoutGroup timeAndPlayersHorizontalLayout;
 155
 156    [Header("Configuration")]
 157    [SerializeField] internal Sprite defaultPicture;
 158    [SerializeField] internal bool isEventCardModal = false;
 159    [SerializeField] internal EventCardComponentModel model;
 160
 0161    public Button.ButtonClickedEvent onJumpInClick => jumpinButton?.onClick;
 0162    public Button.ButtonClickedEvent onInfoClick => infoButton?.onClick;
 0163    public Button.ButtonClickedEvent onSubscribeClick => subscribeEventButton?.onClick;
 0164    public Button.ButtonClickedEvent onUnsubscribeClick => unsubscribeEventButton?.onClick;
 165
 166    public override void Start()
 167    {
 54168        if (eventImage != null)
 54169            eventImage.OnLoaded += OnEventImageLoaded;
 170
 54171        if (closeCardButton != null)
 26172            closeCardButton.onClick.AddListener(CloseModal);
 173
 54174        if (closeAction != null)
 26175            closeAction.OnTriggered += OnCloseActionTriggered;
 176
 54177        if (modalBackgroundButton != null)
 26178            modalBackgroundButton.onClick.AddListener(CloseModal);
 54179    }
 180
 181    public void Configure(BaseComponentModel newModel)
 182    {
 18183        model = (EventCardComponentModel)newModel;
 18184        RefreshControl();
 18185    }
 186
 187    public override void RefreshControl()
 188    {
 18189        if (model == null)
 0190            return;
 191
 18192        if (model.eventPictureSprite != null)
 18193            SetEventPicture(model.eventPictureSprite);
 0194        else if (model.eventPictureTexture != null)
 0195            SetEventPicture(model.eventPictureTexture);
 0196        else if (!string.IsNullOrEmpty(model.eventPictureUri))
 0197            SetEventPicture(model.eventPictureUri);
 198        else
 0199            SetEventPicture(sprite: null);
 200
 18201        SetEventAsLive(model.isLive);
 18202        SetLiveTagText(model.liveTagText);
 18203        SetEventDate(model.eventDateText);
 18204        SetEventName(model.eventName);
 18205        SetEventDescription(model.eventDescription);
 18206        SetEventStartedIn(model.eventStartedIn);
 18207        SetEventStartsInFromTo(model.eventStartsInFromTo);
 18208        SetEventOrganizer(model.eventOrganizer);
 18209        SetEventPlace(model.eventPlace);
 18210        SetSubscribersUsers(model.subscribedUsers);
 18211        SetCoords(model.coords);
 212
 18213        RebuildCardLayouts();
 18214    }
 215
 216    public override void OnFocus()
 217    {
 26218        base.OnFocus();
 219
 26220        if (cardAnimator != null)
 26221            cardAnimator.SetBool(ON_FOCUS_CARD_COMPONENT_BOOL, true);
 26222    }
 223
 224    public override void OnLoseFocus()
 225    {
 26226        base.OnLoseFocus();
 227
 26228        if (cardAnimator != null)
 26229            cardAnimator.SetBool(ON_FOCUS_CARD_COMPONENT_BOOL, false);
 26230    }
 231
 232    public override void Dispose()
 233    {
 323234        base.Dispose();
 235
 323236        if (eventImage != null)
 237        {
 323238            eventImage.OnLoaded -= OnEventImageLoaded;
 323239            eventImage.Dispose();
 240        }
 241
 323242        if (closeCardButton != null)
 119243            closeCardButton.onClick.RemoveAllListeners();
 244
 323245        if (closeAction != null)
 119246            closeAction.OnTriggered -= OnCloseActionTriggered;
 247
 323248        if (modalBackgroundButton != null)
 119249            modalBackgroundButton.onClick.RemoveAllListeners();
 323250    }
 251
 252    public void SetEventPicture(Sprite sprite)
 253    {
 20254        if (sprite == null && defaultPicture != null)
 0255            sprite = defaultPicture;
 256
 20257        model.eventPictureSprite = sprite;
 258
 20259        if (eventImage == null)
 0260            return;
 261
 20262        eventImage.SetImage(sprite);
 20263    }
 264
 265    public void SetEventPicture(Texture2D texture)
 266    {
 1267        if (texture == null && defaultPicture != null)
 268        {
 0269            SetEventPicture(defaultPicture);
 0270            return;
 271        }
 272
 1273        model.eventPictureTexture = texture;
 274
 1275        if (!Application.isPlaying)
 0276            return;
 277
 1278        if (eventImage == null)
 0279            return;
 280
 1281        eventImage.SetImage(texture);
 1282    }
 283
 284    public void SetEventPicture(string uri)
 285    {
 1286        if (string.IsNullOrEmpty(uri) && defaultPicture != null)
 287        {
 0288            SetEventPicture(defaultPicture);
 0289            return;
 290        }
 291
 1292        model.eventPictureUri = uri;
 293
 1294        if (!Application.isPlaying)
 0295            return;
 296
 1297        if (eventImage == null)
 0298            return;
 299
 1300        eventImage.SetImage(uri);
 1301    }
 302
 303    public void SetEventAsLive(bool isLive)
 304    {
 22305        model.isLive = isLive;
 306
 22307        if (liveTag != null)
 22308            liveTag.gameObject.SetActive(isLive);
 309
 22310        if (eventDateText != null)
 22311            eventDateText.gameObject.SetActive(!isLive);
 312
 22313        if (jumpinButton != null)
 22314            jumpinButton.gameObject.SetActive(isLive);
 315
 22316        if (subscribeEventButton != null)
 22317            subscribeEventButton.gameObject.SetActive(!isLive && !model.isSubscribed);
 318
 22319        if (unsubscribeEventButton != null)
 22320            unsubscribeEventButton.gameObject.SetActive(!isLive && model.isSubscribed);
 321
 22322        if (eventStartedInTitleForLive)
 19323            eventStartedInTitleForLive.gameObject.SetActive(isLive);
 324
 22325        if (eventStartedInTitleForNotLive)
 19326            eventStartedInTitleForNotLive.gameObject.SetActive(!isLive);
 327
 22328        if (subscribedUsersTitleForLive != null)
 19329            subscribedUsersTitleForLive.gameObject.SetActive(isLive);
 330
 22331        if (subscribedUsersTitleForNotLive != null)
 19332            subscribedUsersTitleForNotLive.gameObject.SetActive(!isLive);
 22333    }
 334
 335    public void SetLiveTagText(string newText)
 336    {
 19337        model.liveTagText = newText;
 338
 19339        if (liveTag == null)
 0340            return;
 341
 19342        liveTag.SetText(newText);
 19343    }
 344
 345    public void SetEventDate(string newDate)
 346    {
 19347        model.eventDateText = newDate;
 348
 19349        if (eventDateText == null)
 0350            return;
 351
 19352        eventDateText.text = newDate;
 19353    }
 354
 355    public void SetEventName(string newText)
 356    {
 19357        model.eventName = newText;
 358
 19359        if (eventNameText == null)
 0360            return;
 361
 19362        eventNameText.text = newText;
 19363    }
 364
 365    public void SetEventDescription(string newText)
 366    {
 19367        model.eventDescription = newText;
 368
 19369        if (eventDescText == null)
 11370            return;
 371
 8372        eventDescText.text = newText;
 8373    }
 374
 375    public void SetEventStartedIn(string newText)
 376    {
 19377        model.eventStartedIn = newText;
 378
 19379        if (eventStartedInText == null)
 3380            return;
 381
 16382        eventStartedInText.text = newText;
 16383    }
 384
 385    public void SetEventStartsInFromTo(string newText)
 386    {
 19387        model.eventStartsInFromTo = newText;
 388
 19389        if (eventStartsInFromToText == null)
 15390            return;
 391
 4392        eventStartsInFromToText.text = newText;
 4393    }
 394
 395    public void SetEventOrganizer(string newText)
 396    {
 19397        model.eventOrganizer = newText;
 398
 19399        if (eventOrganizerText == null)
 15400            return;
 401
 4402        eventOrganizerText.text = newText;
 4403    }
 404
 405    public void SetEventPlace(string newText)
 406    {
 19407        model.eventPlace = newText;
 408
 19409        if (eventPlaceText == null)
 15410            return;
 411
 4412        eventPlaceText.text = newText;
 4413    }
 414
 415    public void SetSubscribersUsers(int newNumberOfUsers)
 416    {
 22417        model.subscribedUsers = newNumberOfUsers;
 418
 22419        if (subscribedUsersText == null)
 0420            return;
 421
 22422        if (!isEventCardModal)
 423        {
 17424            subscribedUsersText.text = newNumberOfUsers.ToString();
 17425        }
 426        else
 427        {
 5428            if (newNumberOfUsers > 0)
 4429                subscribedUsersText.text = string.Format(USERS_CONFIRMED_MESSAGE, newNumberOfUsers);
 430            else
 1431                subscribedUsersText.text = NOBODY_CONFIRMED_MESSAGE;
 432        }
 1433    }
 434
 435    public void SetCoords(Vector2Int newCoords)
 436    {
 19437        model.coords = newCoords;
 438
 19439        if (jumpinButton == null || !isEventCardModal)
 15440            return;
 441
 4442        jumpinButton.SetText($"{newCoords.x},{newCoords.y}");
 4443    }
 444
 445    public void SetLoadingIndicatorVisible(bool isVisible)
 446    {
 2447        imageContainer.SetActive(!isVisible);
 2448        eventInfoContainer.SetActive(!isVisible);
 2449        loadingSpinner.SetActive(isVisible);
 2450    }
 451
 2452    internal void OnEventImageLoaded(Sprite sprite) { SetEventPicture(sprite); }
 453
 454    internal void RebuildCardLayouts()
 455    {
 18456        if (contentVerticalLayout != null)
 3457            Utils.ForceRebuildLayoutImmediate(contentVerticalLayout.transform as RectTransform);
 458
 18459        if (infoVerticalLayout != null)
 3460            Utils.ForceRebuildLayoutImmediate(infoVerticalLayout.transform as RectTransform);
 461
 18462        if (timeAndPlayersHorizontalLayout != null)
 15463            Utils.ForceRebuildLayoutImmediate(timeAndPlayersHorizontalLayout.transform as RectTransform);
 18464    }
 465
 4466    internal void CloseModal() { Hide(); }
 467
 2468    internal void OnCloseActionTriggered(DCLAction_Trigger action) { CloseModal(); }
 469}