| | 1 | | using DCL; |
| | 2 | | using System; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using TMPro; |
| | 5 | | using UnityEngine; |
| | 6 | | using UnityEngine.UI; |
| | 7 | |
|
| | 8 | | public interface IEventsSubSectionComponentView |
| | 9 | | { |
| | 10 | | /// <summary> |
| | 11 | | /// It will be triggered when all the UI components have been fully initialized. |
| | 12 | | /// </summary> |
| | 13 | | event Action OnReady; |
| | 14 | |
|
| | 15 | | /// <summary> |
| | 16 | | /// It will be triggered when the info button is clicked. |
| | 17 | | /// </summary> |
| | 18 | | event Action<EventCardComponentModel> OnInfoClicked; |
| | 19 | |
|
| | 20 | | /// <summary> |
| | 21 | | /// It will be triggered when the JumpIn button is clicked. |
| | 22 | | /// </summary> |
| | 23 | | event Action<EventFromAPIModel> OnJumpInClicked; |
| | 24 | |
|
| | 25 | | /// <summary> |
| | 26 | | /// It will be triggered when the subscribe event button is clicked. |
| | 27 | | /// </summary> |
| | 28 | | event Action<string> OnSubscribeEventClicked; |
| | 29 | |
|
| | 30 | | /// <summary> |
| | 31 | | /// It will be triggered when the unsubscribe event button is clicked. |
| | 32 | | /// </summary> |
| | 33 | | event Action<string> OnUnsubscribeEventClicked; |
| | 34 | |
|
| | 35 | | /// <summary> |
| | 36 | | /// It will be triggered when the "Show More" button is clicked. |
| | 37 | | /// </summary> |
| | 38 | | event Action OnShowMoreUpcomingEventsClicked; |
| | 39 | |
|
| | 40 | | /// <summary> |
| | 41 | | /// It will be triggered each time the view is enabled. |
| | 42 | | /// </summary> |
| | 43 | | event Action OnEventsSubSectionEnable; |
| | 44 | |
|
| | 45 | | /// <summary> |
| | 46 | | /// Number of events per row that fit with the current upcoming events grid configuration. |
| | 47 | | /// </summary> |
| | 48 | | int currentUpcomingEventsPerRow { get; } |
| | 49 | |
|
| | 50 | | /// <summary> |
| | 51 | | /// Set the featured events component with a list of events. |
| | 52 | | /// </summary> |
| | 53 | | /// <param name="events">List of events (model) to be loaded.</param> |
| | 54 | | void SetFeaturedEvents(List<EventCardComponentModel> events); |
| | 55 | |
|
| | 56 | | /// <summary> |
| | 57 | | /// Set the featured events component in loading mode. |
| | 58 | | /// </summary> |
| | 59 | | /// <param name="isVisible">True for activating the loading mode.</param> |
| | 60 | | void SetFeaturedEventsAsLoading(bool isVisible); |
| | 61 | |
|
| | 62 | | /// <summary> |
| | 63 | | /// Activates/deactivates the featured events component. |
| | 64 | | /// </summary> |
| | 65 | | /// <param name="isActive"></param> |
| | 66 | | void SetFeaturedEventsActive(bool isActive); |
| | 67 | |
|
| | 68 | | /// <summary> |
| | 69 | | /// Set the trending events component with a list of events. |
| | 70 | | /// </summary> |
| | 71 | | /// <param name="events">List of events (model) to be loaded.</param> |
| | 72 | | void SetTrendingEvents(List<EventCardComponentModel> events); |
| | 73 | |
|
| | 74 | | /// <summary> |
| | 75 | | /// Set the trending events component in loading mode. |
| | 76 | | /// </summary> |
| | 77 | | /// <param name="isVisible">True for activating the loading mode.</param> |
| | 78 | | void SetTrendingEventsAsLoading(bool isVisible); |
| | 79 | |
|
| | 80 | | /// <summary> |
| | 81 | | /// Set the upcoming events component with a list of events. |
| | 82 | | /// </summary> |
| | 83 | | /// <param name="events">List of events (model) to be loaded.</param> |
| | 84 | | void SetUpcomingEvents(List<EventCardComponentModel> events); |
| | 85 | |
|
| | 86 | | /// <summary> |
| | 87 | | /// Add a list of events in the events component. |
| | 88 | | /// </summary> |
| | 89 | | /// <param name="places">List of events (model) to be added.</param> |
| | 90 | | void AddUpcomingEvents(List<EventCardComponentModel> events); |
| | 91 | |
|
| | 92 | | /// <summary> |
| | 93 | | /// Set the upcoming events component in loading mode. |
| | 94 | | /// </summary> |
| | 95 | | /// <param name="isVisible">True for activating the loading mode.</param> |
| | 96 | | void SetUpcomingEventsAsLoading(bool isVisible); |
| | 97 | |
|
| | 98 | | /// <summary> |
| | 99 | | /// Activates/Deactivates the "Show More" button. |
| | 100 | | /// </summary> |
| | 101 | | /// <param name="isActive">True for activating it.</param> |
| | 102 | | void SetShowMoreUpcomingEventsButtonActive(bool isActive); |
| | 103 | |
|
| | 104 | | /// <summary> |
| | 105 | | /// Set the going events component with a list of events. |
| | 106 | | /// </summary> |
| | 107 | | /// <param name="events">List of events (model) to be loaded.</param> |
| | 108 | | void SetGoingEvents(List<EventCardComponentModel> events); |
| | 109 | |
|
| | 110 | | /// <summary> |
| | 111 | | /// Set the going events component in loading mode. |
| | 112 | | /// </summary> |
| | 113 | | /// <param name="isVisible">True for activating the loading mode.</param> |
| | 114 | | void SetGoingEventsAsLoading(bool isVisible); |
| | 115 | |
|
| | 116 | | /// <summary> |
| | 117 | | /// Shows the Event Card modal with the provided information. |
| | 118 | | /// </summary> |
| | 119 | | /// <param name="eventInfo">Event (model) to be loaded in the card.</param> |
| | 120 | | void ShowEventModal(EventCardComponentModel eventInfo); |
| | 121 | |
|
| | 122 | | /// <summary> |
| | 123 | | /// Hides the Event Card modal. |
| | 124 | | /// </summary> |
| | 125 | | void HideEventModal(); |
| | 126 | |
|
| | 127 | | /// <summary> |
| | 128 | | /// Set the current scroll view position to 1. |
| | 129 | | /// </summary> |
| | 130 | | void RestartScrollViewPosition(); |
| | 131 | | } |
| | 132 | |
|
| | 133 | | public class EventsSubSectionComponentView : BaseComponentView, IEventsSubSectionComponentView |
| | 134 | | { |
| | 135 | | internal const string FEATURED_EVENT_CARDS_POOL_NAME = "FeaturedEventCardsPool"; |
| | 136 | | internal const string TRENDING_EVENT_CARDS_POOL_NAME = "TrendingEventCardsPool"; |
| | 137 | | internal const string UPCOMING_EVENT_CARDS_POOL_NAME = "UpcomingEventCardsPool"; |
| | 138 | | internal const string GOING_EVENT_CARDS_POOL_NAME = "FeatureGoingEventCardsPool"; |
| | 139 | |
|
| | 140 | | [Header("Assets References")] |
| | 141 | | [SerializeField] internal EventCardComponentView eventCardPrefab; |
| | 142 | | [SerializeField] internal EventCardComponentView eventCardLongPrefab; |
| | 143 | | [SerializeField] internal EventCardComponentView eventCardModalPrefab; |
| | 144 | |
|
| | 145 | | [Header("Prefab References")] |
| | 146 | | [SerializeField] internal ScrollRect scrollView; |
| | 147 | | [SerializeField] internal CarouselComponentView featuredEvents; |
| | 148 | | [SerializeField] internal GameObject featuredEventsLoading; |
| | 149 | | [SerializeField] internal GridContainerComponentView trendingEvents; |
| | 150 | | [SerializeField] internal GameObject trendingEventsLoading; |
| | 151 | | [SerializeField] internal TMP_Text trendingEventsNoDataText; |
| | 152 | | [SerializeField] internal GridContainerComponentView upcomingEvents; |
| | 153 | | [SerializeField] internal GameObject upcomingEventsLoading; |
| | 154 | | [SerializeField] internal TMP_Text upcomingEventsNoDataText; |
| | 155 | | [SerializeField] internal GridContainerComponentView goingEvents; |
| | 156 | | [SerializeField] internal GameObject goingEventsLoading; |
| | 157 | | [SerializeField] internal TMP_Text goingEventsNoDataText; |
| | 158 | | [SerializeField] internal GameObject showMoreUpcomingEventsButtonContainer; |
| | 159 | | [SerializeField] internal ButtonComponentView showMoreUpcomingEventsButton; |
| | 160 | |
|
| | 161 | | public event Action OnReady; |
| | 162 | | public event Action<EventCardComponentModel> OnInfoClicked; |
| | 163 | | public event Action<EventFromAPIModel> OnJumpInClicked; |
| | 164 | | public event Action<string> OnSubscribeEventClicked; |
| | 165 | | public event Action<string> OnUnsubscribeEventClicked; |
| | 166 | | public event Action OnShowMoreUpcomingEventsClicked; |
| | 167 | | public event Action OnEventsSubSectionEnable; |
| | 168 | |
|
| | 169 | | internal EventCardComponentView eventModal; |
| | 170 | | internal Pool featuredEventCardsPool; |
| | 171 | | internal Pool trendingEventCardsPool; |
| | 172 | | internal Pool upcomingEventCardsPool; |
| | 173 | | internal Pool goingEventCardsPool; |
| | 174 | |
|
| 0 | 175 | | public int currentUpcomingEventsPerRow => upcomingEvents.currentItemsPerRow; |
| | 176 | |
|
| 31 | 177 | | public override void OnEnable() { OnEventsSubSectionEnable?.Invoke(); } |
| | 178 | |
|
| | 179 | | public override void Start() |
| | 180 | | { |
| 25 | 181 | | ConfigureEventCardModal(); |
| 25 | 182 | | ConfigureEventCardsPool(out featuredEventCardsPool, FEATURED_EVENT_CARDS_POOL_NAME, eventCardLongPrefab, 10); |
| 25 | 183 | | ConfigureEventCardsPool(out trendingEventCardsPool, TRENDING_EVENT_CARDS_POOL_NAME, eventCardPrefab, 100); |
| 25 | 184 | | ConfigureEventCardsPool(out upcomingEventCardsPool, UPCOMING_EVENT_CARDS_POOL_NAME, eventCardPrefab, 100); |
| 25 | 185 | | ConfigureEventCardsPool(out goingEventCardsPool, GOING_EVENT_CARDS_POOL_NAME, eventCardPrefab, 100); |
| | 186 | |
|
| 25 | 187 | | featuredEvents.RemoveItems(); |
| 25 | 188 | | trendingEvents.RemoveItems(); |
| 25 | 189 | | upcomingEvents.RemoveItems(); |
| 25 | 190 | | goingEvents.RemoveItems(); |
| | 191 | |
|
| 25 | 192 | | showMoreUpcomingEventsButton.onClick.RemoveAllListeners(); |
| 25 | 193 | | showMoreUpcomingEventsButton.onClick.AddListener(() => OnShowMoreUpcomingEventsClicked?.Invoke()); |
| | 194 | |
|
| 25 | 195 | | OnReady?.Invoke(); |
| 0 | 196 | | } |
| | 197 | |
|
| | 198 | | public override void RefreshControl() |
| | 199 | | { |
| 0 | 200 | | featuredEvents.RefreshControl(); |
| 0 | 201 | | trendingEvents.RefreshControl(); |
| 0 | 202 | | upcomingEvents.RefreshControl(); |
| 0 | 203 | | goingEvents.RefreshControl(); |
| 0 | 204 | | } |
| | 205 | |
|
| | 206 | | public override void Dispose() |
| | 207 | | { |
| 63 | 208 | | base.Dispose(); |
| | 209 | |
|
| 63 | 210 | | showMoreUpcomingEventsButton.onClick.RemoveAllListeners(); |
| | 211 | |
|
| 63 | 212 | | featuredEvents.Dispose(); |
| 63 | 213 | | upcomingEvents.Dispose(); |
| 63 | 214 | | trendingEvents.Dispose(); |
| 63 | 215 | | goingEvents.Dispose(); |
| | 216 | |
|
| 63 | 217 | | if (eventModal != null) |
| | 218 | | { |
| 27 | 219 | | eventModal.Dispose(); |
| 27 | 220 | | Destroy(eventModal.gameObject); |
| | 221 | | } |
| 63 | 222 | | } |
| | 223 | |
|
| | 224 | | public void SetFeaturedEvents(List<EventCardComponentModel> events) |
| | 225 | | { |
| 1 | 226 | | featuredEvents.ExtractItems(); |
| 1 | 227 | | featuredEventCardsPool.ReleaseAll(); |
| 1 | 228 | | List<BaseComponentView> eventComponentsToAdd = InstantiateAndConfigureEventCards(events, featuredEventCardsPool) |
| 1 | 229 | | featuredEvents.SetItems(eventComponentsToAdd); |
| 1 | 230 | | SetFeaturedEventsActive(events.Count > 0); |
| 1 | 231 | | } |
| | 232 | | public void SetFeaturedEventsAsLoading(bool isVisible) |
| | 233 | | { |
| 2 | 234 | | SetFeaturedEventsActive(!isVisible); |
| 2 | 235 | | featuredEventsLoading.SetActive(isVisible); |
| 2 | 236 | | } |
| | 237 | |
|
| 10 | 238 | | public void SetFeaturedEventsActive(bool isActive) { featuredEvents.gameObject.SetActive(isActive); } |
| | 239 | |
|
| | 240 | | public void SetTrendingEvents(List<EventCardComponentModel> events) |
| | 241 | | { |
| 1 | 242 | | trendingEvents.ExtractItems(); |
| 1 | 243 | | trendingEventCardsPool.ReleaseAll(); |
| 1 | 244 | | List<BaseComponentView> eventComponentsToAdd = InstantiateAndConfigureEventCards(events, trendingEventCardsPool) |
| 1 | 245 | | trendingEvents.SetItems(eventComponentsToAdd); |
| 1 | 246 | | trendingEventsNoDataText.gameObject.SetActive(events.Count == 0); |
| 1 | 247 | | } |
| | 248 | |
|
| | 249 | | public void SetTrendingEventsAsLoading(bool isVisible) |
| | 250 | | { |
| 2 | 251 | | trendingEvents.gameObject.SetActive(!isVisible); |
| 2 | 252 | | trendingEventsLoading.SetActive(isVisible); |
| | 253 | |
|
| 2 | 254 | | if (isVisible) |
| 1 | 255 | | trendingEventsNoDataText.gameObject.SetActive(false); |
| 2 | 256 | | } |
| | 257 | |
|
| | 258 | | public void SetUpcomingEvents(List<EventCardComponentModel> events) |
| | 259 | | { |
| 1 | 260 | | upcomingEvents.ExtractItems(); |
| 1 | 261 | | upcomingEventCardsPool.ReleaseAll(); |
| 1 | 262 | | List<BaseComponentView> eventComponentsToAdd = InstantiateAndConfigureEventCards(events, upcomingEventCardsPool) |
| 1 | 263 | | upcomingEvents.SetItems(eventComponentsToAdd); |
| 1 | 264 | | upcomingEventsNoDataText.gameObject.SetActive(events.Count == 0); |
| 1 | 265 | | } |
| | 266 | |
|
| | 267 | | public void AddUpcomingEvents(List<EventCardComponentModel> events) |
| | 268 | | { |
| 1 | 269 | | List<BaseComponentView> eventComponentsToAdd = InstantiateAndConfigureEventCards(events, upcomingEventCardsPool) |
| 6 | 270 | | foreach (var eventToAdd in eventComponentsToAdd) |
| | 271 | | { |
| 2 | 272 | | upcomingEvents.AddItem(eventToAdd); |
| | 273 | | } |
| 1 | 274 | | } |
| | 275 | |
|
| | 276 | | public void SetUpcomingEventsAsLoading(bool isVisible) |
| | 277 | | { |
| 2 | 278 | | upcomingEvents.gameObject.SetActive(!isVisible); |
| 2 | 279 | | upcomingEventsLoading.SetActive(isVisible); |
| | 280 | |
|
| 2 | 281 | | if (isVisible) |
| 1 | 282 | | upcomingEventsNoDataText.gameObject.SetActive(false); |
| 2 | 283 | | } |
| | 284 | |
|
| | 285 | | public void SetGoingEvents(List<EventCardComponentModel> events) |
| | 286 | | { |
| 1 | 287 | | goingEvents.ExtractItems(); |
| 1 | 288 | | goingEventCardsPool.ReleaseAll(); |
| 1 | 289 | | List<BaseComponentView> eventComponentsToAdd = InstantiateAndConfigureEventCards(events, goingEventCardsPool); |
| 1 | 290 | | goingEvents.SetItems(eventComponentsToAdd); |
| 1 | 291 | | goingEventsNoDataText.gameObject.SetActive(events.Count == 0); |
| 1 | 292 | | } |
| | 293 | |
|
| | 294 | | public void SetGoingEventsAsLoading(bool isVisible) |
| | 295 | | { |
| 2 | 296 | | goingEvents.gameObject.SetActive(!isVisible); |
| 2 | 297 | | goingEventsLoading.SetActive(isVisible); |
| | 298 | |
|
| 2 | 299 | | if (isVisible) |
| 1 | 300 | | goingEventsNoDataText.gameObject.SetActive(false); |
| 2 | 301 | | } |
| | 302 | |
|
| | 303 | | public void ShowEventModal(EventCardComponentModel eventInfo) |
| | 304 | | { |
| 1 | 305 | | eventModal.Show(); |
| 1 | 306 | | ConfigureEventCard(eventModal, eventInfo); |
| 1 | 307 | | } |
| | 308 | |
|
| 2 | 309 | | public void HideEventModal() { eventModal.Hide(); } |
| | 310 | |
|
| 0 | 311 | | public void RestartScrollViewPosition() { scrollView.verticalNormalizedPosition = 1; } |
| | 312 | |
|
| 4 | 313 | | public void SetShowMoreUpcomingEventsButtonActive(bool isActive) { showMoreUpcomingEventsButtonContainer.gameObject. |
| | 314 | |
|
| | 315 | | internal void ConfigureEventCardModal() |
| | 316 | | { |
| 26 | 317 | | eventModal = GameObject.Instantiate(eventCardModalPrefab); |
| 26 | 318 | | eventModal.Hide(true); |
| 26 | 319 | | } |
| | 320 | |
|
| | 321 | | internal void ConfigureEventCardsPool(out Pool pool, string poolName, EventCardComponentView eventCardPrefab, int ma |
| | 322 | | { |
| 104 | 323 | | pool = PoolManager.i.GetPool(poolName); |
| 104 | 324 | | if (pool == null) |
| | 325 | | { |
| 4 | 326 | | pool = PoolManager.i.AddPool( |
| | 327 | | poolName, |
| | 328 | | Instantiate(eventCardPrefab).gameObject, |
| | 329 | | maxPrewarmCount: maxPrewarmCount, |
| | 330 | | isPersistent: true); |
| | 331 | | } |
| 104 | 332 | | } |
| | 333 | |
|
| | 334 | | internal List<BaseComponentView> InstantiateAndConfigureEventCards(List<EventCardComponentModel> events, Pool pool) |
| | 335 | | { |
| 5 | 336 | | List<BaseComponentView> instantiatedEvents = new List<BaseComponentView>(); |
| | 337 | |
|
| 30 | 338 | | foreach (EventCardComponentModel eventInfo in events) |
| | 339 | | { |
| 10 | 340 | | EventCardComponentView eventGO = pool.Get().gameObject.GetComponent<EventCardComponentView>(); |
| 10 | 341 | | ConfigureEventCard(eventGO, eventInfo); |
| 10 | 342 | | instantiatedEvents.Add(eventGO); |
| | 343 | | } |
| | 344 | |
|
| 5 | 345 | | return instantiatedEvents; |
| | 346 | | } |
| | 347 | |
|
| | 348 | | internal void ConfigureEventCard(EventCardComponentView eventCard, EventCardComponentModel eventInfo) |
| | 349 | | { |
| 11 | 350 | | eventCard.Configure(eventInfo); |
| 11 | 351 | | eventCard.onInfoClick?.RemoveAllListeners(); |
| 11 | 352 | | eventCard.onInfoClick?.AddListener(() => OnInfoClicked?.Invoke(eventInfo)); |
| 11 | 353 | | eventCard.onJumpInClick?.RemoveAllListeners(); |
| 11 | 354 | | eventCard.onJumpInClick?.AddListener(() => OnJumpInClicked?.Invoke(eventInfo.eventFromAPIInfo)); |
| 11 | 355 | | eventCard.onSubscribeClick?.RemoveAllListeners(); |
| 11 | 356 | | eventCard.onSubscribeClick?.AddListener(() => OnSubscribeEventClicked?.Invoke(eventInfo.eventId)); |
| 11 | 357 | | eventCard.onUnsubscribeClick?.RemoveAllListeners(); |
| 11 | 358 | | eventCard.onUnsubscribeClick?.AddListener(() => OnUnsubscribeEventClicked?.Invoke(eventInfo.eventId)); |
| 11 | 359 | | } |
| | 360 | | } |