| | 1 | | using DCL; |
| | 2 | | using DCL.Social.Friends; |
| | 3 | | using ExploreV2Analytics; |
| | 4 | | using System; |
| | 5 | | using System.Collections.Generic; |
| | 6 | | using System.Linq; |
| | 7 | | using UnityEngine; |
| | 8 | | using static HotScenesController; |
| | 9 | |
|
| | 10 | | public class HighlightsSubSectionComponentController : IHighlightsSubSectionComponentController, IPlacesAndEventsAPIRequ |
| | 11 | | { |
| | 12 | | public event Action OnCloseExploreV2; |
| | 13 | | public event Action OnGoToEventsSubSection; |
| | 14 | |
|
| | 15 | | internal const int DEFAULT_NUMBER_OF_TRENDING_PLACES = 10; |
| | 16 | | private const int DEFAULT_NUMBER_OF_FEATURED_PLACES = 9; |
| | 17 | | private const int DEFAULT_NUMBER_OF_LIVE_EVENTS = 3; |
| | 18 | |
|
| | 19 | | internal readonly IHighlightsSubSectionComponentView view; |
| | 20 | | internal readonly IPlacesAPIController placesAPIApiController; |
| | 21 | | internal readonly IEventsAPIController eventsAPIApiController; |
| | 22 | | internal readonly FriendTrackerController friendsTrackerController; |
| | 23 | | private readonly IExploreV2Analytics exploreV2Analytics; |
| | 24 | | private readonly DataStore dataStore; |
| | 25 | |
|
| | 26 | | internal readonly PlaceAndEventsCardsReloader cardsReloader; |
| | 27 | |
|
| 21 | 28 | | internal List<HotSceneInfo> placesFromAPI = new (); |
| 21 | 29 | | internal List<EventFromAPIModel> eventsFromAPI = new (); |
| | 30 | |
|
| 21 | 31 | | public HighlightsSubSectionComponentController(IHighlightsSubSectionComponentView view, IPlacesAPIController placesA |
| | 32 | | DataStore dataStore) |
| | 33 | | { |
| 21 | 34 | | cardsReloader = new PlaceAndEventsCardsReloader(view, this, dataStore.exploreV2); |
| | 35 | |
|
| 21 | 36 | | this.view = view; |
| | 37 | |
|
| 21 | 38 | | this.view.OnReady += FirstLoading; |
| | 39 | |
|
| 21 | 40 | | this.view.OnPlaceInfoClicked += ShowPlaceDetailedInfo; |
| 21 | 41 | | this.view.OnPlaceJumpInClicked += JumpInToPlace; |
| | 42 | |
|
| 21 | 43 | | this.view.OnEventInfoClicked += ShowEventDetailedInfo; |
| 21 | 44 | | this.view.OnEventJumpInClicked += JumpInToEvent; |
| | 45 | |
|
| 21 | 46 | | this.view.OnEventSubscribeEventClicked += SubscribeToEvent; |
| 21 | 47 | | this.view.OnEventUnsubscribeEventClicked += UnsubscribeToEvent; |
| | 48 | |
|
| 21 | 49 | | this.view.OnViewAllEventsClicked += GoToEventsSubSection; |
| | 50 | |
|
| 21 | 51 | | this.view.OnFriendHandlerAdded += View_OnFriendHandlerAdded; |
| | 52 | |
|
| 21 | 53 | | this.dataStore = dataStore; |
| 21 | 54 | | this.dataStore.channels.currentJoinChannelModal.OnChange += OnChannelToJoinChanged; |
| | 55 | |
|
| 21 | 56 | | placesAPIApiController = placesAPI; |
| 21 | 57 | | eventsAPIApiController = eventsAPI; |
| | 58 | |
|
| 21 | 59 | | friendsTrackerController = new FriendTrackerController(friendsController, view.currentFriendColors); |
| | 60 | |
|
| 21 | 61 | | this.exploreV2Analytics = exploreV2Analytics; |
| | 62 | |
|
| 21 | 63 | | view.ConfigurePools(); |
| 21 | 64 | | } |
| | 65 | |
|
| | 66 | | public void Dispose() |
| | 67 | | { |
| 21 | 68 | | view.OnReady -= FirstLoading; |
| | 69 | |
|
| 21 | 70 | | view.OnPlaceInfoClicked -= ShowPlaceDetailedInfo; |
| 21 | 71 | | view.OnEventInfoClicked -= ShowEventDetailedInfo; |
| | 72 | |
|
| 21 | 73 | | view.OnPlaceJumpInClicked -= JumpInToPlace; |
| 21 | 74 | | view.OnEventJumpInClicked -= JumpInToEvent; |
| | 75 | |
|
| 21 | 76 | | view.OnEventSubscribeEventClicked -= SubscribeToEvent; |
| 21 | 77 | | view.OnEventUnsubscribeEventClicked -= UnsubscribeToEvent; |
| | 78 | |
|
| 21 | 79 | | view.OnFriendHandlerAdded -= View_OnFriendHandlerAdded; |
| | 80 | |
|
| 21 | 81 | | view.OnViewAllEventsClicked -= GoToEventsSubSection; |
| | 82 | |
|
| 21 | 83 | | dataStore.channels.currentJoinChannelModal.OnChange -= OnChannelToJoinChanged; |
| | 84 | |
|
| 21 | 85 | | cardsReloader.Dispose(); |
| 21 | 86 | | } |
| | 87 | |
|
| | 88 | | private void FirstLoading() |
| | 89 | | { |
| 0 | 90 | | view.OnHighlightsSubSectionEnable += RequestAllPlacesAndEvents; |
| 0 | 91 | | cardsReloader.Initialize(); |
| 0 | 92 | | } |
| | 93 | |
|
| | 94 | | internal void RequestAllPlacesAndEvents() |
| | 95 | | { |
| 2 | 96 | | if (cardsReloader.CanReload()) |
| 2 | 97 | | cardsReloader.RequestAll(); |
| 2 | 98 | | } |
| | 99 | |
|
| | 100 | | public void RequestAllFromAPI() |
| | 101 | | { |
| 2 | 102 | | placesAPIApiController.GetAllPlaces( |
| | 103 | | OnCompleted: placeList => |
| | 104 | | { |
| 0 | 105 | | placesFromAPI = placeList; |
| | 106 | |
|
| 0 | 107 | | eventsAPIApiController.GetAllEvents( |
| | 108 | | OnSuccess: eventList => |
| | 109 | | { |
| 0 | 110 | | eventsFromAPI = eventList; |
| 0 | 111 | | OnRequestedPlacesAndEventsUpdated(); |
| 0 | 112 | | }, |
| | 113 | | OnFail: error => |
| | 114 | | { |
| 0 | 115 | | OnRequestedPlacesAndEventsUpdated(); |
| 0 | 116 | | Debug.LogError($"Error receiving events from the API: {error}"); |
| 0 | 117 | | }); |
| 0 | 118 | | }); |
| 2 | 119 | | } |
| | 120 | |
|
| | 121 | | internal void OnRequestedPlacesAndEventsUpdated() |
| | 122 | | { |
| 1 | 123 | | friendsTrackerController.RemoveAllHandlers(); |
| | 124 | |
|
| 1 | 125 | | List<PlaceCardComponentModel> trendingPlaces = PlacesAndEventsCardsFactory.CreatePlacesCards(FilterTrendingPlace |
| 1 | 126 | | List<EventCardComponentModel> trendingEvents = PlacesAndEventsCardsFactory.CreateEventsCards(FilterTrendingEvent |
| 1 | 127 | | view.SetTrendingPlacesAndEvents(trendingPlaces, trendingEvents); |
| | 128 | |
|
| 1 | 129 | | view.SetFeaturedPlaces(PlacesAndEventsCardsFactory.CreatePlacesCards(FilterFeaturedPlaces())); |
| 1 | 130 | | view.SetLiveEvents(PlacesAndEventsCardsFactory.CreateEventsCards(FilterLiveEvents())); |
| 1 | 131 | | } |
| | 132 | |
|
| 2 | 133 | | internal List<HotSceneInfo> FilterTrendingPlaces() => placesFromAPI.Take(DEFAULT_NUMBER_OF_TRENDING_PLACES).ToList() |
| 6 | 134 | | internal List<EventFromAPIModel> FilterLiveEvents() => eventsFromAPI.Where(x => x.live).Take(DEFAULT_NUMBER_OF_LIVE_ |
| 6 | 135 | | internal List<EventFromAPIModel> FilterTrendingEvents(int amount) => eventsFromAPI.Where(e => e.highlighted).Take(am |
| | 136 | | internal List<HotSceneInfo> FilterFeaturedPlaces() |
| | 137 | | { |
| | 138 | | List<HotSceneInfo> featuredPlaces; |
| | 139 | |
|
| 2 | 140 | | if (placesFromAPI.Count >= DEFAULT_NUMBER_OF_TRENDING_PLACES) |
| | 141 | | { |
| 0 | 142 | | int numberOfPlaces = placesFromAPI.Count >= (DEFAULT_NUMBER_OF_TRENDING_PLACES + DEFAULT_NUMBER_OF_FEATURED_ |
| | 143 | | ? DEFAULT_NUMBER_OF_FEATURED_PLACES |
| | 144 | | : placesFromAPI.Count - DEFAULT_NUMBER_OF_TRENDING_PLACES; |
| | 145 | |
|
| 0 | 146 | | featuredPlaces = placesFromAPI |
| | 147 | | .GetRange(DEFAULT_NUMBER_OF_TRENDING_PLACES, numberOfPlaces) |
| | 148 | | .ToList(); |
| | 149 | | } |
| 2 | 150 | | else if (placesFromAPI.Count > 0) |
| 2 | 151 | | featuredPlaces = placesFromAPI.Take(DEFAULT_NUMBER_OF_FEATURED_PLACES).ToList(); |
| | 152 | | else |
| 0 | 153 | | featuredPlaces = new List<HotSceneInfo>(); |
| | 154 | |
|
| 2 | 155 | | return featuredPlaces; |
| | 156 | | } |
| | 157 | |
|
| | 158 | | private void View_OnFriendHandlerAdded(FriendsHandler friendsHandler) => |
| 0 | 159 | | friendsTrackerController.AddHandler(friendsHandler); |
| | 160 | |
|
| | 161 | | internal void ShowPlaceDetailedInfo(PlaceCardComponentModel placeModel) |
| | 162 | | { |
| 1 | 163 | | view.ShowPlaceModal(placeModel); |
| 1 | 164 | | exploreV2Analytics.SendClickOnPlaceInfo(placeModel.hotSceneInfo.id, placeModel.placeName); |
| 1 | 165 | | dataStore.exploreV2.currentVisibleModal.Set(ExploreV2CurrentModal.Places); |
| 1 | 166 | | } |
| | 167 | |
|
| | 168 | | internal void ShowEventDetailedInfo(EventCardComponentModel eventModel) |
| | 169 | | { |
| 1 | 170 | | view.ShowEventModal(eventModel); |
| 1 | 171 | | exploreV2Analytics.SendClickOnEventInfo(eventModel.eventId, eventModel.eventName); |
| 1 | 172 | | dataStore.exploreV2.currentVisibleModal.Set(ExploreV2CurrentModal.Events); |
| 1 | 173 | | } |
| | 174 | |
|
| | 175 | | internal void JumpInToPlace(HotSceneInfo placeFromAPI) |
| | 176 | | { |
| 1 | 177 | | PlacesSubSectionComponentController.JumpInToPlace(placeFromAPI); |
| 1 | 178 | | view.HidePlaceModal(); |
| | 179 | |
|
| 1 | 180 | | dataStore.exploreV2.currentVisibleModal.Set(ExploreV2CurrentModal.None); |
| 1 | 181 | | OnCloseExploreV2?.Invoke(); |
| 1 | 182 | | exploreV2Analytics.SendPlaceTeleport(placeFromAPI.id, placeFromAPI.name, placeFromAPI.baseCoords); |
| 1 | 183 | | } |
| | 184 | |
|
| | 185 | | internal void JumpInToEvent(EventFromAPIModel eventFromAPI) |
| | 186 | | { |
| 1 | 187 | | EventsSubSectionComponentController.JumpInToEvent(eventFromAPI); |
| 1 | 188 | | view.HideEventModal(); |
| | 189 | |
|
| 1 | 190 | | dataStore.exploreV2.currentVisibleModal.Set(ExploreV2CurrentModal.None); |
| 1 | 191 | | OnCloseExploreV2?.Invoke(); |
| 1 | 192 | | exploreV2Analytics.SendEventTeleport(eventFromAPI.id, eventFromAPI.name, new Vector2Int(eventFromAPI.coordinates |
| 1 | 193 | | } |
| | 194 | |
|
| | 195 | | private static void SubscribeToEvent(string eventId) => |
| 0 | 196 | | EventsSubSectionComponentController.SubscribeToEvent(eventId); |
| | 197 | |
|
| | 198 | | private static void UnsubscribeToEvent(string eventId) => |
| 0 | 199 | | EventsSubSectionComponentController.UnsubscribeToEvent(eventId); |
| | 200 | |
|
| | 201 | | internal void GoToEventsSubSection() => |
| 1 | 202 | | OnGoToEventsSubSection?.Invoke(); |
| | 203 | |
|
| | 204 | | private void OnChannelToJoinChanged(string currentChannelId, string previousChannelId) |
| | 205 | | { |
| 0 | 206 | | if (!string.IsNullOrEmpty(currentChannelId)) |
| 0 | 207 | | return; |
| | 208 | |
|
| 0 | 209 | | view.HidePlaceModal(); |
| 0 | 210 | | view.HideEventModal(); |
| 0 | 211 | | dataStore.exploreV2.currentVisibleModal.Set(ExploreV2CurrentModal.None); |
| 0 | 212 | | OnCloseExploreV2?.Invoke(); |
| 0 | 213 | | } |
| | 214 | | } |