| | 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 | | /// <summary> |
| | 133 | | /// Configure the needed pools for the events instantiation. |
| | 134 | | /// </summary> |
| | 135 | | void ConfigurePools(); |
| | 136 | | } |
| | 137 | |
|
| | 138 | | public class EventsSubSectionComponentView : BaseComponentView, IEventsSubSectionComponentView |
| | 139 | | { |
| | 140 | | internal const string FEATURED_EVENT_CARDS_POOL_NAME = "Events_FeaturedEventCardsPool"; |
| | 141 | | internal const int FEATURED_EVENT_CARDS_POOL_PREWARM = 10; |
| | 142 | | internal const string TRENDING_EVENT_CARDS_POOL_NAME = "Events_TrendingEventCardsPool"; |
| | 143 | | internal const int TRENDING_EVENT_CARDS_POOL_PREWARM = 12; |
| | 144 | | internal const string UPCOMING_EVENT_CARDS_POOL_NAME = "Events_UpcomingEventCardsPool"; |
| | 145 | | internal const int UPCOMING_EVENT_CARDS_POOL_PREWARM = 9; |
| | 146 | | internal const string GOING_EVENT_CARDS_POOL_NAME = "Events_FeatureGoingEventCardsPool"; |
| | 147 | | internal const int GOING_EVENT_CARDS_POOL_PREWARM = 9; |
| | 148 | |
|
| | 149 | | [Header("Assets References")] |
| | 150 | | [SerializeField] internal EventCardComponentView eventCardPrefab; |
| | 151 | | [SerializeField] internal EventCardComponentView eventCardLongPrefab; |
| | 152 | | [SerializeField] internal EventCardComponentView eventCardModalPrefab; |
| | 153 | |
|
| | 154 | | [Header("Prefab References")] |
| | 155 | | [SerializeField] internal ScrollRect scrollView; |
| | 156 | | [SerializeField] internal CarouselComponentView featuredEvents; |
| | 157 | | [SerializeField] internal GameObject featuredEventsLoading; |
| | 158 | | [SerializeField] internal GridContainerComponentView trendingEvents; |
| | 159 | | [SerializeField] internal GameObject trendingEventsLoading; |
| | 160 | | [SerializeField] internal TMP_Text trendingEventsNoDataText; |
| | 161 | | [SerializeField] internal GridContainerComponentView upcomingEvents; |
| | 162 | | [SerializeField] internal GameObject upcomingEventsLoading; |
| | 163 | | [SerializeField] internal TMP_Text upcomingEventsNoDataText; |
| | 164 | | [SerializeField] internal GridContainerComponentView goingEvents; |
| | 165 | | [SerializeField] internal GameObject goingEventsLoading; |
| | 166 | | [SerializeField] internal TMP_Text goingEventsNoDataText; |
| | 167 | | [SerializeField] internal GameObject showMoreUpcomingEventsButtonContainer; |
| | 168 | | [SerializeField] internal ButtonComponentView showMoreUpcomingEventsButton; |
| | 169 | |
|
| | 170 | | public event Action OnReady; |
| | 171 | | public event Action<EventCardComponentModel> OnInfoClicked; |
| | 172 | | public event Action<EventFromAPIModel> OnJumpInClicked; |
| | 173 | | public event Action<string> OnSubscribeEventClicked; |
| | 174 | | public event Action<string> OnUnsubscribeEventClicked; |
| | 175 | | public event Action OnShowMoreUpcomingEventsClicked; |
| | 176 | | public event Action OnEventsSubSectionEnable; |
| | 177 | |
|
| | 178 | | internal EventCardComponentView eventModal; |
| | 179 | | internal Pool featuredEventCardsPool; |
| | 180 | | internal Pool trendingEventCardsPool; |
| | 181 | | internal Pool upcomingEventCardsPool; |
| | 182 | | internal Pool goingEventCardsPool; |
| | 183 | |
|
| 0 | 184 | | public int currentUpcomingEventsPerRow => upcomingEvents.currentItemsPerRow; |
| | 185 | |
|
| 24 | 186 | | public override void OnEnable() { OnEventsSubSectionEnable?.Invoke(); } |
| | 187 | |
|
| | 188 | | public void ConfigurePools() |
| | 189 | | { |
| 22 | 190 | | ExploreEventsUtils.ConfigureEventCardsPool(out featuredEventCardsPool, FEATURED_EVENT_CARDS_POOL_NAME, eventCard |
| 22 | 191 | | ExploreEventsUtils.ConfigureEventCardsPool(out trendingEventCardsPool, TRENDING_EVENT_CARDS_POOL_NAME, eventCard |
| 22 | 192 | | ExploreEventsUtils.ConfigureEventCardsPool(out upcomingEventCardsPool, UPCOMING_EVENT_CARDS_POOL_NAME, eventCard |
| 22 | 193 | | ExploreEventsUtils.ConfigureEventCardsPool(out goingEventCardsPool, GOING_EVENT_CARDS_POOL_NAME, eventCardPrefab |
| 22 | 194 | | } |
| | 195 | |
|
| | 196 | | public override void Start() |
| | 197 | | { |
| 22 | 198 | | eventModal = ExploreEventsUtils.ConfigureEventCardModal(eventCardModalPrefab); |
| | 199 | |
|
| 22 | 200 | | featuredEvents.RemoveItems(); |
| 22 | 201 | | trendingEvents.RemoveItems(); |
| 22 | 202 | | upcomingEvents.RemoveItems(); |
| 22 | 203 | | goingEvents.RemoveItems(); |
| | 204 | |
|
| 22 | 205 | | showMoreUpcomingEventsButton.onClick.RemoveAllListeners(); |
| 22 | 206 | | showMoreUpcomingEventsButton.onClick.AddListener(() => OnShowMoreUpcomingEventsClicked?.Invoke()); |
| | 207 | |
|
| 22 | 208 | | OnReady?.Invoke(); |
| 0 | 209 | | } |
| | 210 | |
|
| | 211 | | public override void RefreshControl() |
| | 212 | | { |
| 0 | 213 | | featuredEvents.RefreshControl(); |
| 0 | 214 | | trendingEvents.RefreshControl(); |
| 0 | 215 | | upcomingEvents.RefreshControl(); |
| 0 | 216 | | goingEvents.RefreshControl(); |
| 0 | 217 | | } |
| | 218 | |
|
| | 219 | | public override void Dispose() |
| | 220 | | { |
| 69 | 221 | | base.Dispose(); |
| | 222 | |
|
| 69 | 223 | | showMoreUpcomingEventsButton.onClick.RemoveAllListeners(); |
| | 224 | |
|
| 69 | 225 | | featuredEvents.Dispose(); |
| 69 | 226 | | upcomingEvents.Dispose(); |
| 69 | 227 | | trendingEvents.Dispose(); |
| 69 | 228 | | goingEvents.Dispose(); |
| | 229 | |
|
| 69 | 230 | | if (eventModal != null) |
| | 231 | | { |
| 30 | 232 | | eventModal.Dispose(); |
| 30 | 233 | | Destroy(eventModal.gameObject); |
| | 234 | | } |
| 69 | 235 | | } |
| | 236 | |
|
| | 237 | | public void SetFeaturedEvents(List<EventCardComponentModel> events) |
| | 238 | | { |
| 1 | 239 | | featuredEvents.ExtractItems(); |
| 1 | 240 | | featuredEventCardsPool.ReleaseAll(); |
| | 241 | |
|
| 1 | 242 | | List<BaseComponentView> eventComponentsToAdd = ExploreEventsUtils.InstantiateAndConfigureEventCards( |
| | 243 | | events, |
| | 244 | | featuredEventCardsPool, |
| | 245 | | OnInfoClicked, |
| | 246 | | OnJumpInClicked, |
| | 247 | | OnSubscribeEventClicked, |
| | 248 | | OnUnsubscribeEventClicked); |
| | 249 | |
|
| 1 | 250 | | featuredEvents.SetItems(eventComponentsToAdd); |
| 1 | 251 | | SetFeaturedEventsActive(events.Count > 0); |
| 1 | 252 | | } |
| | 253 | |
|
| | 254 | | public void SetFeaturedEventsAsLoading(bool isVisible) |
| | 255 | | { |
| 2 | 256 | | SetFeaturedEventsActive(!isVisible); |
| 2 | 257 | | featuredEventsLoading.SetActive(isVisible); |
| 2 | 258 | | } |
| | 259 | |
|
| 10 | 260 | | public void SetFeaturedEventsActive(bool isActive) { featuredEvents.gameObject.SetActive(isActive); } |
| | 261 | |
|
| | 262 | | public void SetTrendingEvents(List<EventCardComponentModel> events) |
| | 263 | | { |
| 1 | 264 | | trendingEvents.ExtractItems(); |
| 1 | 265 | | trendingEventCardsPool.ReleaseAll(); |
| | 266 | |
|
| 1 | 267 | | List<BaseComponentView> eventComponentsToAdd = ExploreEventsUtils.InstantiateAndConfigureEventCards( |
| | 268 | | events, |
| | 269 | | trendingEventCardsPool, |
| | 270 | | OnInfoClicked, |
| | 271 | | OnJumpInClicked, |
| | 272 | | OnSubscribeEventClicked, |
| | 273 | | OnUnsubscribeEventClicked); |
| | 274 | |
|
| 1 | 275 | | trendingEvents.SetItems(eventComponentsToAdd); |
| 1 | 276 | | trendingEventsNoDataText.gameObject.SetActive(events.Count == 0); |
| 1 | 277 | | } |
| | 278 | |
|
| | 279 | | public void SetTrendingEventsAsLoading(bool isVisible) |
| | 280 | | { |
| 2 | 281 | | trendingEvents.gameObject.SetActive(!isVisible); |
| 2 | 282 | | trendingEventsLoading.SetActive(isVisible); |
| | 283 | |
|
| 2 | 284 | | if (isVisible) |
| 1 | 285 | | trendingEventsNoDataText.gameObject.SetActive(false); |
| 2 | 286 | | } |
| | 287 | |
|
| | 288 | | public void SetUpcomingEvents(List<EventCardComponentModel> events) |
| | 289 | | { |
| 1 | 290 | | upcomingEvents.ExtractItems(); |
| 1 | 291 | | upcomingEventCardsPool.ReleaseAll(); |
| | 292 | |
|
| 1 | 293 | | List<BaseComponentView> eventComponentsToAdd = ExploreEventsUtils.InstantiateAndConfigureEventCards( |
| | 294 | | events, |
| | 295 | | upcomingEventCardsPool, |
| | 296 | | OnInfoClicked, |
| | 297 | | OnJumpInClicked, |
| | 298 | | OnSubscribeEventClicked, |
| | 299 | | OnUnsubscribeEventClicked); |
| | 300 | |
|
| 1 | 301 | | upcomingEvents.SetItems(eventComponentsToAdd); |
| 1 | 302 | | upcomingEventsNoDataText.gameObject.SetActive(events.Count == 0); |
| 1 | 303 | | } |
| | 304 | |
|
| | 305 | | public void AddUpcomingEvents(List<EventCardComponentModel> events) |
| | 306 | | { |
| 1 | 307 | | List<BaseComponentView> eventComponentsToAdd = ExploreEventsUtils.InstantiateAndConfigureEventCards( |
| | 308 | | events, |
| | 309 | | upcomingEventCardsPool, |
| | 310 | | OnInfoClicked, |
| | 311 | | OnJumpInClicked, |
| | 312 | | OnSubscribeEventClicked, |
| | 313 | | OnUnsubscribeEventClicked); |
| | 314 | |
|
| 6 | 315 | | foreach (var eventToAdd in eventComponentsToAdd) |
| | 316 | | { |
| 2 | 317 | | upcomingEvents.AddItem(eventToAdd); |
| | 318 | | } |
| 1 | 319 | | } |
| | 320 | |
|
| | 321 | | public void SetUpcomingEventsAsLoading(bool isVisible) |
| | 322 | | { |
| 2 | 323 | | upcomingEvents.gameObject.SetActive(!isVisible); |
| 2 | 324 | | upcomingEventsLoading.SetActive(isVisible); |
| | 325 | |
|
| 2 | 326 | | if (isVisible) |
| 1 | 327 | | upcomingEventsNoDataText.gameObject.SetActive(false); |
| 2 | 328 | | } |
| | 329 | |
|
| | 330 | | public void SetGoingEvents(List<EventCardComponentModel> events) |
| | 331 | | { |
| 1 | 332 | | goingEvents.ExtractItems(); |
| 1 | 333 | | goingEventCardsPool.ReleaseAll(); |
| | 334 | |
|
| 1 | 335 | | List<BaseComponentView> eventComponentsToAdd = ExploreEventsUtils.InstantiateAndConfigureEventCards( |
| | 336 | | events, |
| | 337 | | goingEventCardsPool, |
| | 338 | | OnInfoClicked, |
| | 339 | | OnJumpInClicked, |
| | 340 | | OnSubscribeEventClicked, |
| | 341 | | OnUnsubscribeEventClicked); |
| | 342 | |
|
| 1 | 343 | | goingEvents.SetItems(eventComponentsToAdd); |
| 1 | 344 | | goingEventsNoDataText.gameObject.SetActive(events.Count == 0); |
| 1 | 345 | | } |
| | 346 | |
|
| | 347 | | public void SetGoingEventsAsLoading(bool isVisible) |
| | 348 | | { |
| 2 | 349 | | goingEvents.gameObject.SetActive(!isVisible); |
| 2 | 350 | | goingEventsLoading.SetActive(isVisible); |
| | 351 | |
|
| 2 | 352 | | if (isVisible) |
| 1 | 353 | | goingEventsNoDataText.gameObject.SetActive(false); |
| 2 | 354 | | } |
| | 355 | |
|
| | 356 | | public void ShowEventModal(EventCardComponentModel eventInfo) |
| | 357 | | { |
| 1 | 358 | | eventModal.Show(); |
| 1 | 359 | | ExploreEventsUtils.ConfigureEventCard(eventModal, eventInfo, OnInfoClicked, OnJumpInClicked, OnSubscribeEventCli |
| 1 | 360 | | } |
| | 361 | |
|
| 2 | 362 | | public void HideEventModal() { eventModal.Hide(); } |
| | 363 | |
|
| 0 | 364 | | public void RestartScrollViewPosition() { scrollView.verticalNormalizedPosition = 1; } |
| | 365 | |
|
| 4 | 366 | | public void SetShowMoreUpcomingEventsButtonActive(bool isActive) { showMoreUpcomingEventsButtonContainer.gameObject. |
| | 367 | | } |