< Summary

Class:EventsCardsConfigurator
Assembly:ExploreV2
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/Sections/PlacesAndEventsSection/EventsCardsConfigurator.cs
Covered lines:44
Uncovered lines:6
Coverable lines:50
Total lines:114
Line coverage:88% (44 of 50)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Configure(...)0%11110100%
ConfigureFromAPIData(...)0%110100%
FormatEventDate(...)0%110100%
FormatEventStartDate(...)0%5.574053.85%
FormatEventStartDateFromTo(...)0%110100%
FormatEventOrganized(...)0%110100%
FormatEventPlace(...)0%220100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/Sections/PlacesAndEventsSection/EventsCardsConfigurator.cs

#LineLine coverage
 1using System;
 2using System.Globalization;
 3using UnityEngine;
 4using Environment = DCL.Environment;
 5
 6/// <summary>
 7/// Utils related to the events management in ExploreV2.
 8/// </summary>
 9public static class EventsCardsConfigurator
 10{
 11    internal const string LIVE_TAG_TEXT = "LIVE";
 12
 13    /// <summary>
 14    /// Configure a event card with the given model.
 15    /// </summary>
 16    /// <param name="eventCard">Event card to configure.</param>
 17    /// <param name="eventInfo">Model to apply.</param>
 18    /// <param name="OnEventInfoClicked">Action to inform when the Info button has been clicked.</param>
 19    /// <param name="OnEventJumpInClicked">Action to inform when the JumpIn button has been clicked.</param>
 20    /// <param name="OnEventSubscribeEventClicked">Action to inform when the Subscribe button has been clicked.</param>
 21    /// <param name="OnEventUnsubscribeEventClicked">Action to inform when the Unsubscribe button has been clicked.</par
 22    public static EventCardComponentView Configure(EventCardComponentView eventCard, EventCardComponentModel eventInfo, 
 23        Action<string> OnEventUnsubscribeEventClicked)
 24    {
 2725        eventCard.Configure(eventInfo);
 26
 2727        eventCard.onInfoClick?.RemoveAllListeners();
 2728        eventCard.onInfoClick?.AddListener(() => OnEventInfoClicked?.Invoke(eventInfo));
 2729        eventCard.onJumpInClick?.RemoveAllListeners();
 2730        eventCard.onJumpInClick?.AddListener(() => OnEventJumpInClicked?.Invoke(eventInfo.eventFromAPIInfo));
 2731        eventCard.onJumpInForNotLiveClick?.RemoveAllListeners();
 2732        eventCard.onJumpInForNotLiveClick?.AddListener(() => OnEventJumpInClicked?.Invoke(eventInfo.eventFromAPIInfo));
 2733        eventCard.onSubscribeClick?.RemoveAllListeners();
 2734        eventCard.onSubscribeClick?.AddListener(() => OnEventSubscribeEventClicked?.Invoke(eventInfo.eventId));
 2735        eventCard.onUnsubscribeClick?.RemoveAllListeners();
 2736        eventCard.onUnsubscribeClick?.AddListener(() => OnEventUnsubscribeEventClicked?.Invoke(eventInfo.eventId));
 37
 2738        return eventCard;
 39    }
 40
 41    public static EventCardComponentModel ConfigureFromAPIData(EventCardComponentModel cardModel, EventFromAPIModel even
 42    {
 943        cardModel.eventId = eventFromAPI.id;
 944        cardModel.eventPictureUri = eventFromAPI.image;
 945        cardModel.isLive = eventFromAPI.live;
 946        cardModel.liveTagText = LIVE_TAG_TEXT;
 947        cardModel.eventDateText = FormatEventDate(eventFromAPI);
 948        cardModel.eventName = eventFromAPI.name;
 949        cardModel.eventDescription = eventFromAPI.description;
 950        cardModel.eventStartedIn = FormatEventStartDate(eventFromAPI);
 951        cardModel.eventStartsInFromTo = FormatEventStartDateFromTo(eventFromAPI);
 952        cardModel.eventOrganizer = FormatEventOrganized(eventFromAPI);
 953        cardModel.eventPlace = FormatEventPlace(eventFromAPI);
 954        cardModel.subscribedUsers = eventFromAPI.total_attendees;
 955        cardModel.isSubscribed = false;
 956        cardModel.coords = new Vector2Int(eventFromAPI.coordinates[0], eventFromAPI.coordinates[1]);
 957        cardModel.eventFromAPIInfo = eventFromAPI;
 58
 959        return cardModel;
 60    }
 61
 62    internal static string FormatEventDate(EventFromAPIModel eventFromAPI)
 63    {
 1064        DateTime eventDateTime = Convert.ToDateTime(eventFromAPI.next_start_at).ToUniversalTime();
 1065        return eventDateTime.ToString("MMMM d", new CultureInfo("en-US"));
 66    }
 67
 68    internal static string FormatEventStartDate(EventFromAPIModel eventFromAPI)
 69    {
 1070        DateTime eventDateTime = Convert.ToDateTime(eventFromAPI.next_start_at).ToUniversalTime();
 71        string formattedDate;
 72
 1073        if (eventFromAPI.live)
 74        {
 1075            int daysAgo = (int)Math.Ceiling((DateTime.Now - eventDateTime).TotalDays);
 1076            int hoursAgo = (int)Math.Ceiling((DateTime.Now - eventDateTime).TotalHours);
 77
 1078            if (daysAgo > 0)
 1079                formattedDate = $"{daysAgo} days ago";
 80            else
 081                formattedDate = $"{hoursAgo} hr ago";
 82        }
 83        else
 84        {
 085            int daysToStart = (int)Math.Ceiling((eventDateTime - DateTime.Now).TotalDays);
 086            int hoursToStart = (int)Math.Ceiling((eventDateTime - DateTime.Now).TotalHours);
 87
 088            if (daysToStart > 0)
 089                formattedDate = $"in {daysToStart} days";
 90            else
 091                formattedDate = $"in {hoursToStart} hours";
 92        }
 93
 1094        return formattedDate;
 95    }
 96
 97    internal static string FormatEventStartDateFromTo(EventFromAPIModel eventFromAPI)
 98    {
 1099        CultureInfo cultureInfo = new CultureInfo("en-US");
 10100        DateTime eventStartDateTime = Convert.ToDateTime(eventFromAPI.next_start_at).ToUniversalTime();
 10101        DateTime eventEndDateTime = Convert.ToDateTime(eventFromAPI.finish_at).ToUniversalTime();
 102
 10103        string formattedDate = $"From {eventStartDateTime.ToString("dddd", cultureInfo)}, {eventStartDateTime.Day} {even
 104                               $" to {eventEndDateTime.ToString("dddd", cultureInfo)}, {eventEndDateTime.Day} {eventEndD
 105
 10106        return formattedDate;
 107    }
 108
 109    internal static string FormatEventOrganized(EventFromAPIModel eventFromAPI) =>
 10110        $"Public, Organized by {eventFromAPI.user_name}";
 111
 112    internal static string FormatEventPlace(EventFromAPIModel eventFromAPI) =>
 10113        string.IsNullOrEmpty(eventFromAPI.scene_name) ? "Decentraland" : eventFromAPI.scene_name;
 114}