| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using TMPro; |
| | 5 | | using UnityEngine; |
| | 6 | |
|
| | 7 | | public interface IEventsSubSectionComponentView |
| | 8 | | { |
| | 9 | | /// <summary> |
| | 10 | | /// It will be triggered when all the UI components have been fully initialized. |
| | 11 | | /// </summary> |
| | 12 | | event Action OnReady; |
| | 13 | |
|
| | 14 | | /// <summary> |
| | 15 | | /// It will be triggered when the "Show More" button is clicked. |
| | 16 | | /// </summary> |
| | 17 | | event Action OnShowMoreUpcomingEventsClicked; |
| | 18 | |
|
| | 19 | | /// <summary> |
| | 20 | | /// It will be triggered each time the view is enabled. |
| | 21 | | /// </summary> |
| | 22 | | event Action OnEventsSubSectionEnable; |
| | 23 | |
|
| | 24 | | /// <summary> |
| | 25 | | /// Set the featured events component with a list of events. |
| | 26 | | /// </summary> |
| | 27 | | /// <param name="events">List of events (model) to be loaded.</param> |
| | 28 | | void SetFeaturedEvents(List<EventCardComponentModel> events); |
| | 29 | |
|
| | 30 | | /// <summary> |
| | 31 | | /// Set the featured events component in loading mode. |
| | 32 | | /// </summary> |
| | 33 | | /// <param name="isVisible">True for activating the loading mode.</param> |
| | 34 | | void SetFeaturedEventsAsLoading(bool isVisible); |
| | 35 | |
|
| | 36 | | /// <summary> |
| | 37 | | /// Set the trending events component with a list of events. |
| | 38 | | /// </summary> |
| | 39 | | /// <param name="events">List of events (model) to be loaded.</param> |
| | 40 | | void SetTrendingEvents(List<EventCardComponentModel> events); |
| | 41 | |
|
| | 42 | | /// <summary> |
| | 43 | | /// Set the trending events component in loading mode. |
| | 44 | | /// </summary> |
| | 45 | | /// <param name="isVisible">True for activating the loading mode.</param> |
| | 46 | | void SetTrendingEventsAsLoading(bool isVisible); |
| | 47 | |
|
| | 48 | | /// <summary> |
| | 49 | | /// Set the upcoming events component with a list of events. |
| | 50 | | /// </summary> |
| | 51 | | /// <param name="events">List of events (model) to be loaded.</param> |
| | 52 | | void SetUpcomingEvents(List<EventCardComponentModel> events); |
| | 53 | |
|
| | 54 | | /// <summary> |
| | 55 | | /// Set the upcoming events component in loading mode. |
| | 56 | | /// </summary> |
| | 57 | | /// <param name="isVisible">True for activating the loading mode.</param> |
| | 58 | | void SetUpcomingEventsAsLoading(bool isVisible); |
| | 59 | |
|
| | 60 | | /// <summary> |
| | 61 | | /// Activates/Deactivates the "Show More" button. |
| | 62 | | /// </summary> |
| | 63 | | /// <param name="isActive">True for activating it.</param> |
| | 64 | | void SetShowMoreUpcomingEventsButtonActive(bool isActive); |
| | 65 | |
|
| | 66 | | /// <summary> |
| | 67 | | /// Set the going events component with a list of events. |
| | 68 | | /// </summary> |
| | 69 | | /// <param name="events">List of events (model) to be loaded.</param> |
| | 70 | | void SetGoingEvents(List<EventCardComponentModel> events); |
| | 71 | |
|
| | 72 | | /// <summary> |
| | 73 | | /// Set the going events component in loading mode. |
| | 74 | | /// </summary> |
| | 75 | | /// <param name="isVisible">True for activating the loading mode.</param> |
| | 76 | | void SetGoingEventsAsLoading(bool isVisible); |
| | 77 | |
|
| | 78 | | /// <summary> |
| | 79 | | /// Shows the Event Card modal with the provided information. |
| | 80 | | /// </summary> |
| | 81 | | /// <param name="eventInfo">Event (model) to be loaded in the card.</param> |
| | 82 | | void ShowEventModal(EventCardComponentModel eventInfo); |
| | 83 | |
|
| | 84 | | /// <summary> |
| | 85 | | /// Hides the Event Card modal. |
| | 86 | | /// </summary> |
| | 87 | | void HideEventModal(); |
| | 88 | | } |
| | 89 | |
|
| | 90 | | public class EventsSubSectionComponentView : BaseComponentView, IEventsSubSectionComponentView |
| | 91 | | { |
| | 92 | | [Header("Assets References")] |
| | 93 | | [SerializeField] internal EventCardComponentView eventCardPrefab; |
| | 94 | | [SerializeField] internal EventCardComponentView eventCardLongPrefab; |
| | 95 | | [SerializeField] internal EventCardComponentView eventCardModalPrefab; |
| | 96 | |
|
| | 97 | | [Header("Prefab References")] |
| | 98 | | [SerializeField] internal CarouselComponentView featuredEvents; |
| | 99 | | [SerializeField] internal GameObject featuredEventsLoading; |
| | 100 | | [SerializeField] internal GridContainerComponentView trendingEvents; |
| | 101 | | [SerializeField] internal GameObject trendingEventsLoading; |
| | 102 | | [SerializeField] internal TMP_Text trendingEventsNoDataText; |
| | 103 | | [SerializeField] internal GridContainerComponentView upcomingEvents; |
| | 104 | | [SerializeField] internal GameObject upcomingEventsLoading; |
| | 105 | | [SerializeField] internal TMP_Text upcomingEventsNoDataText; |
| | 106 | | [SerializeField] internal GridContainerComponentView goingEvents; |
| | 107 | | [SerializeField] internal GameObject goingEventsLoading; |
| | 108 | | [SerializeField] internal TMP_Text goingEventsNoDataText; |
| | 109 | | [SerializeField] internal GameObject showMoreUpcomingEventsButtonContainer; |
| | 110 | | [SerializeField] internal ButtonComponentView showMoreUpcomingEventsButton; |
| | 111 | |
|
| | 112 | | public event Action OnReady; |
| | 113 | | public event Action OnShowMoreUpcomingEventsClicked; |
| | 114 | | public event Action OnEventsSubSectionEnable; |
| | 115 | |
|
| | 116 | | internal EventCardComponentView eventModal; |
| | 117 | |
|
| 1 | 118 | | private void OnEnable() { OnEventsSubSectionEnable?.Invoke(); } |
| | 119 | |
|
| | 120 | | public override void PostInitialization() |
| | 121 | | { |
| 1 | 122 | | StartCoroutine(WaitForComponentsInitialization()); |
| | 123 | |
|
| 1 | 124 | | eventModal = GameObject.Instantiate(eventCardModalPrefab); |
| 1 | 125 | | eventModal.gameObject.SetActive(false); |
| 1 | 126 | | } |
| | 127 | |
|
| | 128 | | public override void RefreshControl() |
| | 129 | | { |
| 0 | 130 | | featuredEvents.RefreshControl(); |
| 0 | 131 | | trendingEvents.RefreshControl(); |
| 0 | 132 | | upcomingEvents.RefreshControl(); |
| 0 | 133 | | goingEvents.RefreshControl(); |
| 0 | 134 | | } |
| | 135 | |
|
| | 136 | | public override void Dispose() |
| | 137 | | { |
| 1 | 138 | | base.Dispose(); |
| | 139 | |
|
| 1 | 140 | | showMoreUpcomingEventsButton.onClick.RemoveAllListeners(); |
| 1 | 141 | | } |
| | 142 | |
|
| | 143 | | public IEnumerator WaitForComponentsInitialization() |
| | 144 | | { |
| 2 | 145 | | yield return new WaitUntil(() => featuredEvents.isFullyInitialized && |
| | 146 | | trendingEvents.isFullyInitialized && |
| | 147 | | upcomingEvents.isFullyInitialized && |
| | 148 | | goingEvents.isFullyInitialized && |
| | 149 | | showMoreUpcomingEventsButton.isFullyInitialized); |
| | 150 | |
|
| 0 | 151 | | showMoreUpcomingEventsButton.onClick.RemoveAllListeners(); |
| 0 | 152 | | showMoreUpcomingEventsButton.onClick.AddListener(() => OnShowMoreUpcomingEventsClicked?.Invoke()); |
| 0 | 153 | | OnReady?.Invoke(); |
| 0 | 154 | | } |
| | 155 | |
|
| | 156 | | public void SetFeaturedEvents(List<EventCardComponentModel> events) |
| | 157 | | { |
| 0 | 158 | | List<BaseComponentView> eventComponentsToAdd = IntantiateAndConfigureEventCards(events, eventCardLongPrefab); |
| 0 | 159 | | featuredEvents.SetItems(eventComponentsToAdd, false); |
| 0 | 160 | | featuredEvents.gameObject.SetActive(events.Count > 0); |
| 0 | 161 | | } |
| | 162 | | public void SetFeaturedEventsAsLoading(bool isVisible) |
| | 163 | | { |
| 0 | 164 | | featuredEvents.gameObject.SetActive(!isVisible); |
| 0 | 165 | | featuredEventsLoading.SetActive(isVisible); |
| 0 | 166 | | } |
| | 167 | |
|
| | 168 | | public void SetTrendingEvents(List<EventCardComponentModel> events) |
| | 169 | | { |
| 0 | 170 | | List<BaseComponentView> eventComponentsToAdd = IntantiateAndConfigureEventCards(events, eventCardPrefab); |
| 0 | 171 | | trendingEvents.SetItems(eventComponentsToAdd, false); |
| 0 | 172 | | trendingEventsNoDataText.gameObject.SetActive(events.Count == 0); |
| 0 | 173 | | } |
| | 174 | |
|
| | 175 | | public void SetTrendingEventsAsLoading(bool isVisible) |
| | 176 | | { |
| 0 | 177 | | trendingEvents.gameObject.SetActive(!isVisible); |
| 0 | 178 | | trendingEventsLoading.SetActive(isVisible); |
| 0 | 179 | | trendingEventsNoDataText.gameObject.SetActive(false); |
| 0 | 180 | | } |
| | 181 | |
|
| | 182 | | public void SetUpcomingEvents(List<EventCardComponentModel> events) |
| | 183 | | { |
| 0 | 184 | | List<BaseComponentView> eventComponentsToAdd = IntantiateAndConfigureEventCards(events, eventCardPrefab); |
| 0 | 185 | | upcomingEvents.SetItems(eventComponentsToAdd, false); |
| 0 | 186 | | upcomingEventsNoDataText.gameObject.SetActive(events.Count == 0); |
| 0 | 187 | | } |
| | 188 | |
|
| | 189 | | public void SetUpcomingEventsAsLoading(bool isVisible) |
| | 190 | | { |
| 0 | 191 | | upcomingEvents.gameObject.SetActive(!isVisible); |
| 0 | 192 | | upcomingEventsLoading.SetActive(isVisible); |
| 0 | 193 | | upcomingEventsNoDataText.gameObject.SetActive(false); |
| 0 | 194 | | } |
| | 195 | |
|
| | 196 | | public void SetGoingEvents(List<EventCardComponentModel> events) |
| | 197 | | { |
| 0 | 198 | | List<BaseComponentView> eventComponentsToAdd = IntantiateAndConfigureEventCards(events, eventCardPrefab); |
| 0 | 199 | | goingEvents.SetItems(eventComponentsToAdd, false); |
| 0 | 200 | | goingEventsNoDataText.gameObject.SetActive(events.Count == 0); |
| 0 | 201 | | } |
| | 202 | |
|
| | 203 | | public void SetGoingEventsAsLoading(bool isVisible) |
| | 204 | | { |
| 0 | 205 | | goingEvents.gameObject.SetActive(!isVisible); |
| 0 | 206 | | goingEventsLoading.SetActive(isVisible); |
| 0 | 207 | | goingEventsNoDataText.gameObject.SetActive(false); |
| 0 | 208 | | } |
| | 209 | |
|
| | 210 | | public void ShowEventModal(EventCardComponentModel eventInfo) |
| | 211 | | { |
| 0 | 212 | | eventModal.gameObject.SetActive(true); |
| 0 | 213 | | eventModal.Configure(eventInfo); |
| 0 | 214 | | } |
| | 215 | |
|
| 0 | 216 | | public void HideEventModal() { eventModal.gameObject.SetActive(false); } |
| | 217 | |
|
| 0 | 218 | | public void SetShowMoreUpcomingEventsButtonActive(bool isActive) { showMoreUpcomingEventsButtonContainer.gameObject. |
| | 219 | |
|
| | 220 | | internal List<BaseComponentView> IntantiateAndConfigureEventCards(List<EventCardComponentModel> events, EventCardCom |
| | 221 | | { |
| 0 | 222 | | List<BaseComponentView> instantiatedEvents = new List<BaseComponentView>(); |
| | 223 | |
|
| 0 | 224 | | foreach (EventCardComponentModel eventInfo in events) |
| | 225 | | { |
| 0 | 226 | | EventCardComponentView eventGO = GameObject.Instantiate(prefabToUse); |
| 0 | 227 | | eventGO.Configure(eventInfo); |
| 0 | 228 | | instantiatedEvents.Add(eventGO); |
| | 229 | | } |
| | 230 | |
|
| 0 | 231 | | return instantiatedEvents; |
| | 232 | | } |
| | 233 | | } |