| | 1 | | using System; |
| | 2 | | using System.Globalization; |
| | 3 | | using UnityEngine; |
| | 4 | | using Environment = DCL.Environment; |
| | 5 | |
|
| | 6 | | /// <summary> |
| | 7 | | /// Utils related to the events management in ExploreV2. |
| | 8 | | /// </summary> |
| | 9 | | public 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 | | { |
| 27 | 25 | | eventCard.Configure(eventInfo); |
| | 26 | |
|
| 27 | 27 | | eventCard.onInfoClick?.RemoveAllListeners(); |
| 27 | 28 | | eventCard.onInfoClick?.AddListener(() => OnEventInfoClicked?.Invoke(eventInfo)); |
| 27 | 29 | | eventCard.onJumpInClick?.RemoveAllListeners(); |
| 27 | 30 | | eventCard.onJumpInClick?.AddListener(() => OnEventJumpInClicked?.Invoke(eventInfo.eventFromAPIInfo)); |
| 27 | 31 | | eventCard.onJumpInForNotLiveClick?.RemoveAllListeners(); |
| 27 | 32 | | eventCard.onJumpInForNotLiveClick?.AddListener(() => OnEventJumpInClicked?.Invoke(eventInfo.eventFromAPIInfo)); |
| 27 | 33 | | eventCard.onSubscribeClick?.RemoveAllListeners(); |
| 27 | 34 | | eventCard.onSubscribeClick?.AddListener(() => OnEventSubscribeEventClicked?.Invoke(eventInfo.eventId)); |
| 27 | 35 | | eventCard.onUnsubscribeClick?.RemoveAllListeners(); |
| 27 | 36 | | eventCard.onUnsubscribeClick?.AddListener(() => OnEventUnsubscribeEventClicked?.Invoke(eventInfo.eventId)); |
| | 37 | |
|
| 27 | 38 | | return eventCard; |
| | 39 | | } |
| | 40 | |
|
| | 41 | | public static EventCardComponentModel ConfigureFromAPIData(EventCardComponentModel cardModel, EventFromAPIModel even |
| | 42 | | { |
| 9 | 43 | | cardModel.eventId = eventFromAPI.id; |
| 9 | 44 | | cardModel.eventPictureUri = eventFromAPI.image; |
| 9 | 45 | | cardModel.isLive = eventFromAPI.live; |
| 9 | 46 | | cardModel.liveTagText = LIVE_TAG_TEXT; |
| 9 | 47 | | cardModel.eventDateText = FormatEventDate(eventFromAPI); |
| 9 | 48 | | cardModel.eventName = eventFromAPI.name; |
| 9 | 49 | | cardModel.eventDescription = eventFromAPI.description; |
| 9 | 50 | | cardModel.eventStartedIn = FormatEventStartDate(eventFromAPI); |
| 9 | 51 | | cardModel.eventStartsInFromTo = FormatEventStartDateFromTo(eventFromAPI); |
| 9 | 52 | | cardModel.eventOrganizer = FormatEventOrganized(eventFromAPI); |
| 9 | 53 | | cardModel.eventPlace = FormatEventPlace(eventFromAPI); |
| 9 | 54 | | cardModel.subscribedUsers = eventFromAPI.total_attendees; |
| 9 | 55 | | cardModel.isSubscribed = false; |
| 9 | 56 | | cardModel.coords = new Vector2Int(eventFromAPI.coordinates[0], eventFromAPI.coordinates[1]); |
| 9 | 57 | | cardModel.eventFromAPIInfo = eventFromAPI; |
| | 58 | |
|
| 9 | 59 | | return cardModel; |
| | 60 | | } |
| | 61 | |
|
| | 62 | | internal static string FormatEventDate(EventFromAPIModel eventFromAPI) |
| | 63 | | { |
| 10 | 64 | | DateTime eventDateTime = Convert.ToDateTime(eventFromAPI.next_start_at).ToUniversalTime(); |
| 10 | 65 | | return eventDateTime.ToString("MMMM d", new CultureInfo("en-US")); |
| | 66 | | } |
| | 67 | |
|
| | 68 | | internal static string FormatEventStartDate(EventFromAPIModel eventFromAPI) |
| | 69 | | { |
| 10 | 70 | | DateTime eventDateTime = Convert.ToDateTime(eventFromAPI.next_start_at).ToUniversalTime(); |
| | 71 | | string formattedDate; |
| | 72 | |
|
| 10 | 73 | | if (eventFromAPI.live) |
| | 74 | | { |
| 10 | 75 | | int daysAgo = (int)Math.Ceiling((DateTime.Now - eventDateTime).TotalDays); |
| 10 | 76 | | int hoursAgo = (int)Math.Ceiling((DateTime.Now - eventDateTime).TotalHours); |
| | 77 | |
|
| 10 | 78 | | if (daysAgo > 0) |
| 10 | 79 | | formattedDate = $"{daysAgo} days ago"; |
| | 80 | | else |
| 0 | 81 | | formattedDate = $"{hoursAgo} hr ago"; |
| | 82 | | } |
| | 83 | | else |
| | 84 | | { |
| 0 | 85 | | int daysToStart = (int)Math.Ceiling((eventDateTime - DateTime.Now).TotalDays); |
| 0 | 86 | | int hoursToStart = (int)Math.Ceiling((eventDateTime - DateTime.Now).TotalHours); |
| | 87 | |
|
| 0 | 88 | | if (daysToStart > 0) |
| 0 | 89 | | formattedDate = $"in {daysToStart} days"; |
| | 90 | | else |
| 0 | 91 | | formattedDate = $"in {hoursToStart} hours"; |
| | 92 | | } |
| | 93 | |
|
| 10 | 94 | | return formattedDate; |
| | 95 | | } |
| | 96 | |
|
| | 97 | | internal static string FormatEventStartDateFromTo(EventFromAPIModel eventFromAPI) |
| | 98 | | { |
| 10 | 99 | | CultureInfo cultureInfo = new CultureInfo("en-US"); |
| 10 | 100 | | DateTime eventStartDateTime = Convert.ToDateTime(eventFromAPI.next_start_at).ToUniversalTime(); |
| 10 | 101 | | DateTime eventEndDateTime = Convert.ToDateTime(eventFromAPI.finish_at).ToUniversalTime(); |
| | 102 | |
|
| 10 | 103 | | string formattedDate = $"From {eventStartDateTime.ToString("dddd", cultureInfo)}, {eventStartDateTime.Day} {even |
| | 104 | | $" to {eventEndDateTime.ToString("dddd", cultureInfo)}, {eventEndDateTime.Day} {eventEndD |
| | 105 | |
|
| 10 | 106 | | return formattedDate; |
| | 107 | | } |
| | 108 | |
|
| | 109 | | internal static string FormatEventOrganized(EventFromAPIModel eventFromAPI) => |
| 10 | 110 | | $"Public, Organized by {eventFromAPI.user_name}"; |
| | 111 | |
|
| | 112 | | internal static string FormatEventPlace(EventFromAPIModel eventFromAPI) => |
| 10 | 113 | | string.IsNullOrEmpty(eventFromAPI.scene_name) ? "Decentraland" : eventFromAPI.scene_name; |
| | 114 | | } |