< 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:147
Uncovered lines:19
Coverable lines:166
Total lines:453
Line coverage:88.5% (147 of 166)
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%2.032080%
SetEventPicture(...)0%3.213071.43%
SetEventPicture(...)0%3.213071.43%
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 bool isEventCardModal = false;
 158    [SerializeField] internal EventCardComponentModel model;
 159
 0160    public Button.ButtonClickedEvent onJumpInClick => jumpinButton?.onClick;
 0161    public Button.ButtonClickedEvent onInfoClick => infoButton?.onClick;
 0162    public Button.ButtonClickedEvent onSubscribeClick => subscribeEventButton?.onClick;
 0163    public Button.ButtonClickedEvent onUnsubscribeClick => unsubscribeEventButton?.onClick;
 164
 165    public override void Start()
 166    {
 52167        if (eventImage != null)
 52168            eventImage.OnLoaded += OnEventImageLoaded;
 169
 52170        if (closeCardButton != null)
 26171            closeCardButton.onClick.AddListener(CloseModal);
 172
 52173        if (closeAction != null)
 26174            closeAction.OnTriggered += OnCloseActionTriggered;
 175
 52176        if (modalBackgroundButton != null)
 26177            modalBackgroundButton.onClick.AddListener(CloseModal);
 52178    }
 179
 180    public void Configure(BaseComponentModel newModel)
 181    {
 12182        model = (EventCardComponentModel)newModel;
 12183        RefreshControl();
 12184    }
 185
 186    public override void RefreshControl()
 187    {
 12188        if (model == null)
 0189            return;
 190
 12191        if (model.eventPictureSprite != null)
 12192            SetEventPicture(model.eventPictureSprite);
 0193        else if (model.eventPictureTexture != null)
 0194            SetEventPicture(model.eventPictureTexture);
 0195        else if (!string.IsNullOrEmpty(model.eventPictureUri))
 0196            SetEventPicture(model.eventPictureUri);
 197        else
 0198            SetEventPicture(sprite: null);
 199
 12200        SetEventAsLive(model.isLive);
 12201        SetLiveTagText(model.liveTagText);
 12202        SetEventDate(model.eventDateText);
 12203        SetEventName(model.eventName);
 12204        SetEventDescription(model.eventDescription);
 12205        SetEventStartedIn(model.eventStartedIn);
 12206        SetEventStartsInFromTo(model.eventStartsInFromTo);
 12207        SetEventOrganizer(model.eventOrganizer);
 12208        SetEventPlace(model.eventPlace);
 12209        SetSubscribersUsers(model.subscribedUsers);
 12210        SetCoords(model.coords);
 211
 12212        RebuildCardLayouts();
 12213    }
 214
 215    public override void OnFocus()
 216    {
 26217        base.OnFocus();
 218
 26219        if (cardAnimator != null)
 26220            cardAnimator.SetBool(ON_FOCUS_CARD_COMPONENT_BOOL, true);
 26221    }
 222
 223    public override void OnLoseFocus()
 224    {
 26225        base.OnLoseFocus();
 226
 26227        if (cardAnimator != null)
 26228            cardAnimator.SetBool(ON_FOCUS_CARD_COMPONENT_BOOL, false);
 26229    }
 230
 231    public override void Dispose()
 232    {
 256233        base.Dispose();
 234
 256235        if (eventImage != null)
 236        {
 256237            eventImage.OnLoaded -= OnEventImageLoaded;
 256238            eventImage.Dispose();
 239        }
 240
 256241        if (closeCardButton != null)
 105242            closeCardButton.onClick.RemoveAllListeners();
 243
 256244        if (closeAction != null)
 105245            closeAction.OnTriggered -= OnCloseActionTriggered;
 246
 256247        if (modalBackgroundButton != null)
 105248            modalBackgroundButton.onClick.RemoveAllListeners();
 256249    }
 250
 251    public void SetEventPicture(Sprite sprite)
 252    {
 14253        model.eventPictureSprite = sprite;
 254
 14255        if (eventImage == null)
 0256            return;
 257
 14258        eventImage.SetImage(sprite);
 14259    }
 260
 261    public void SetEventPicture(Texture2D texture)
 262    {
 1263        model.eventPictureTexture = texture;
 264
 1265        if (!Application.isPlaying)
 0266            return;
 267
 1268        if (eventImage == null)
 0269            return;
 270
 1271        eventImage.SetImage(texture);
 1272    }
 273
 274    public void SetEventPicture(string uri)
 275    {
 1276        model.eventPictureUri = uri;
 277
 1278        if (!Application.isPlaying)
 0279            return;
 280
 1281        if (eventImage == null)
 0282            return;
 283
 1284        eventImage.SetImage(uri);
 1285    }
 286
 287    public void SetEventAsLive(bool isLive)
 288    {
 16289        model.isLive = isLive;
 290
 16291        if (liveTag != null)
 16292            liveTag.gameObject.SetActive(isLive);
 293
 16294        if (eventDateText != null)
 16295            eventDateText.gameObject.SetActive(!isLive);
 296
 16297        if (jumpinButton != null)
 16298            jumpinButton.gameObject.SetActive(isLive);
 299
 16300        if (subscribeEventButton != null)
 16301            subscribeEventButton.gameObject.SetActive(!isLive && !model.isSubscribed);
 302
 16303        if (unsubscribeEventButton != null)
 16304            unsubscribeEventButton.gameObject.SetActive(!isLive && model.isSubscribed);
 305
 16306        if (eventStartedInTitleForLive)
 15307            eventStartedInTitleForLive.gameObject.SetActive(isLive);
 308
 16309        if (eventStartedInTitleForNotLive)
 15310            eventStartedInTitleForNotLive.gameObject.SetActive(!isLive);
 311
 16312        if (subscribedUsersTitleForLive != null)
 15313            subscribedUsersTitleForLive.gameObject.SetActive(isLive);
 314
 16315        if (subscribedUsersTitleForNotLive != null)
 15316            subscribedUsersTitleForNotLive.gameObject.SetActive(!isLive);
 16317    }
 318
 319    public void SetLiveTagText(string newText)
 320    {
 13321        model.liveTagText = newText;
 322
 13323        if (liveTag == null)
 0324            return;
 325
 13326        liveTag.SetText(newText);
 13327    }
 328
 329    public void SetEventDate(string newDate)
 330    {
 13331        model.eventDateText = newDate;
 332
 13333        if (eventDateText == null)
 0334            return;
 335
 13336        eventDateText.text = newDate;
 13337    }
 338
 339    public void SetEventName(string newText)
 340    {
 13341        model.eventName = newText;
 342
 13343        if (eventNameText == null)
 0344            return;
 345
 13346        eventNameText.text = newText;
 13347    }
 348
 349    public void SetEventDescription(string newText)
 350    {
 13351        model.eventDescription = newText;
 352
 13353        if (eventDescText == null)
 9354            return;
 355
 4356        eventDescText.text = newText;
 4357    }
 358
 359    public void SetEventStartedIn(string newText)
 360    {
 13361        model.eventStartedIn = newText;
 362
 13363        if (eventStartedInText == null)
 1364            return;
 365
 12366        eventStartedInText.text = newText;
 12367    }
 368
 369    public void SetEventStartsInFromTo(string newText)
 370    {
 13371        model.eventStartsInFromTo = newText;
 372
 13373        if (eventStartsInFromToText == null)
 11374            return;
 375
 2376        eventStartsInFromToText.text = newText;
 2377    }
 378
 379    public void SetEventOrganizer(string newText)
 380    {
 13381        model.eventOrganizer = newText;
 382
 13383        if (eventOrganizerText == null)
 11384            return;
 385
 2386        eventOrganizerText.text = newText;
 2387    }
 388
 389    public void SetEventPlace(string newText)
 390    {
 13391        model.eventPlace = newText;
 392
 13393        if (eventPlaceText == null)
 11394            return;
 395
 2396        eventPlaceText.text = newText;
 2397    }
 398
 399    public void SetSubscribersUsers(int newNumberOfUsers)
 400    {
 16401        model.subscribedUsers = newNumberOfUsers;
 402
 16403        if (subscribedUsersText == null)
 0404            return;
 405
 16406        if (!isEventCardModal)
 407        {
 13408            subscribedUsersText.text = newNumberOfUsers.ToString();
 13409        }
 410        else
 411        {
 3412            if (newNumberOfUsers > 0)
 2413                subscribedUsersText.text = string.Format(USERS_CONFIRMED_MESSAGE, newNumberOfUsers);
 414            else
 1415                subscribedUsersText.text = NOBODY_CONFIRMED_MESSAGE;
 416        }
 1417    }
 418
 419    public void SetCoords(Vector2Int newCoords)
 420    {
 13421        model.coords = newCoords;
 422
 13423        if (jumpinButton == null || !isEventCardModal)
 11424            return;
 425
 2426        jumpinButton.SetText($"{newCoords.x},{newCoords.y}");
 2427    }
 428
 429    public void SetLoadingIndicatorVisible(bool isVisible)
 430    {
 2431        imageContainer.SetActive(!isVisible);
 2432        eventInfoContainer.SetActive(!isVisible);
 2433        loadingSpinner.SetActive(isVisible);
 2434    }
 435
 2436    internal void OnEventImageLoaded(Sprite sprite) { SetEventPicture(sprite); }
 437
 438    internal void RebuildCardLayouts()
 439    {
 12440        if (contentVerticalLayout != null)
 1441            Utils.ForceRebuildLayoutImmediate(contentVerticalLayout.transform as RectTransform);
 442
 12443        if (infoVerticalLayout != null)
 1444            Utils.ForceRebuildLayoutImmediate(infoVerticalLayout.transform as RectTransform);
 445
 12446        if (timeAndPlayersHorizontalLayout != null)
 11447            Utils.ForceRebuildLayoutImmediate(timeAndPlayersHorizontalLayout.transform as RectTransform);
 12448    }
 449
 4450    internal void CloseModal() { Hide(); }
 451
 2452    internal void OnCloseActionTriggered(DCLAction_Trigger action) { CloseModal(); }
 453}