| | 1 | | using DCL; |
| | 2 | | using ExploreV2Analytics; |
| | 3 | | using System; |
| | 4 | | using DCL.Social.Friends; |
| | 5 | |
|
| | 6 | | public interface IPlacesAndEventsSectionComponentController : IDisposable |
| | 7 | | { |
| | 8 | | /// <summary> |
| | 9 | | /// It will be triggered when the section want to request to close the ExploreV2 main menu. |
| | 10 | | /// </summary> |
| | 11 | | event Action<bool> OnCloseExploreV2; |
| | 12 | | } |
| | 13 | |
|
| | 14 | | public class PlacesAndEventsSectionComponentController : IPlacesAndEventsSectionComponentController |
| | 15 | | { |
| | 16 | | internal const float MIN_TIME_TO_CHECK_API = 60f; |
| | 17 | |
|
| | 18 | | public event Action<bool> OnCloseExploreV2; |
| | 19 | |
|
| | 20 | | internal IPlacesAndEventsSectionComponentView view; |
| | 21 | | internal IHighlightsSubSectionComponentController highlightsSubSectionComponentController; |
| | 22 | | internal IPlacesSubSectionComponentController placesSubSectionComponentController; |
| | 23 | | internal IEventsSubSectionComponentController eventsSubSectionComponentController; |
| | 24 | | private DataStore dataStore; |
| | 25 | |
|
| 18 | 26 | | internal BaseVariable<bool> placesAndEventsVisible => dataStore.exploreV2.placesAndEventsVisible; |
| | 27 | |
|
| 6 | 28 | | public PlacesAndEventsSectionComponentController( |
| | 29 | | IPlacesAndEventsSectionComponentView view, |
| | 30 | | IExploreV2Analytics exploreV2Analytics, |
| | 31 | | DataStore dataStore) |
| | 32 | | { |
| 6 | 33 | | this.view = view; |
| 6 | 34 | | this.dataStore = dataStore; |
| | 35 | |
|
| 6 | 36 | | PlacesAPIController placesAPI = new PlacesAPIController(); |
| 6 | 37 | | EventsAPIController eventsAPI = new EventsAPIController(); |
| | 38 | |
|
| 6 | 39 | | highlightsSubSectionComponentController = new HighlightsSubSectionComponentController( |
| | 40 | | view.HighlightsSubSectionView, |
| | 41 | | placesAPI, |
| | 42 | | eventsAPI, |
| | 43 | | FriendsController.i, |
| | 44 | | exploreV2Analytics, |
| | 45 | | dataStore); |
| | 46 | |
|
| 6 | 47 | | highlightsSubSectionComponentController.OnCloseExploreV2 += RequestExploreV2Closing; |
| 6 | 48 | | highlightsSubSectionComponentController.OnGoToEventsSubSection += GoToEventsSubSection; |
| | 49 | |
|
| 6 | 50 | | placesSubSectionComponentController = new PlacesSubSectionComponentController( |
| | 51 | | view.PlacesSubSectionView, |
| | 52 | | placesAPI, |
| | 53 | | FriendsController.i, |
| | 54 | | exploreV2Analytics, |
| | 55 | | dataStore); |
| | 56 | |
|
| 6 | 57 | | placesSubSectionComponentController.OnCloseExploreV2 += RequestExploreV2Closing; |
| | 58 | |
|
| 6 | 59 | | eventsSubSectionComponentController = new EventsSubSectionComponentController( |
| | 60 | | view.EventsSubSectionView, |
| | 61 | | eventsAPI, |
| | 62 | | exploreV2Analytics, |
| | 63 | | dataStore); |
| | 64 | |
|
| 6 | 65 | | eventsSubSectionComponentController.OnCloseExploreV2 += RequestExploreV2Closing; |
| | 66 | |
|
| 6 | 67 | | placesAndEventsVisible.OnChange += PlacesAndEventsVisibleChanged; |
| 6 | 68 | | PlacesAndEventsVisibleChanged(placesAndEventsVisible.Get(), false); |
| 6 | 69 | | } |
| | 70 | |
|
| 2 | 71 | | internal void RequestExploreV2Closing() { OnCloseExploreV2?.Invoke(false); } |
| | 72 | |
|
| 2 | 73 | | internal void GoToEventsSubSection() { view.GoToSubsection(PlacesAndEventsSectionComponentView.EVENTS_SUB_SECTION_IN |
| | 74 | |
|
| | 75 | | public void Dispose() |
| | 76 | | { |
| 6 | 77 | | highlightsSubSectionComponentController.OnCloseExploreV2 -= RequestExploreV2Closing; |
| 6 | 78 | | highlightsSubSectionComponentController.OnGoToEventsSubSection -= GoToEventsSubSection; |
| 6 | 79 | | highlightsSubSectionComponentController.Dispose(); |
| | 80 | |
|
| 6 | 81 | | placesSubSectionComponentController.OnCloseExploreV2 -= RequestExploreV2Closing; |
| 6 | 82 | | placesSubSectionComponentController.Dispose(); |
| | 83 | |
|
| 6 | 84 | | eventsSubSectionComponentController.OnCloseExploreV2 -= RequestExploreV2Closing; |
| 6 | 85 | | eventsSubSectionComponentController.Dispose(); |
| | 86 | |
|
| 6 | 87 | | placesAndEventsVisible.OnChange -= PlacesAndEventsVisibleChanged; |
| 6 | 88 | | } |
| | 89 | |
|
| 8 | 90 | | internal void PlacesAndEventsVisibleChanged(bool current, bool _) => view.SetActive(current); |
| | 91 | | } |