| | 1 | | using System; |
| | 2 | | using DCL.Builder; |
| | 3 | |
|
| | 4 | | internal class SectionsHandler : IDisposable |
| | 5 | | { |
| | 6 | | private readonly ISectionsController sectionsController; |
| | 7 | | private readonly IScenesViewController scenesViewController; |
| | 8 | | private readonly SearchBarView searchBarView; |
| | 9 | | private readonly ILandsController landsController; |
| | 10 | | private readonly IProjectsController projectsController; |
| | 11 | |
|
| 17 | 12 | | public SectionsHandler(ISectionsController sectionsController, IScenesViewController scenesViewController, ILandsCon |
| | 13 | | { |
| 17 | 14 | | this.sectionsController = sectionsController; |
| 17 | 15 | | this.scenesViewController = scenesViewController; |
| 17 | 16 | | this.searchBarView = searchBarView; |
| 17 | 17 | | this.landsController = landsController; |
| 17 | 18 | | this.projectsController = projectsController; |
| | 19 | |
|
| 17 | 20 | | sectionsController.OnSectionShow += OnSectionShow; |
| 17 | 21 | | sectionsController.OnSectionHide += OnSectionHide; |
| 17 | 22 | | scenesViewController.OnProjectSelected += SelectProject; |
| 17 | 23 | | } |
| | 24 | |
|
| | 25 | | public void Dispose() |
| | 26 | | { |
| 17 | 27 | | sectionsController.OnSectionShow -= OnSectionShow; |
| 17 | 28 | | sectionsController.OnSectionHide -= OnSectionHide; |
| 17 | 29 | | scenesViewController.OnProjectSelected -= SelectProject; |
| 17 | 30 | | } |
| | 31 | |
|
| | 32 | | void OnSectionShow(SectionBase sectionBase) |
| | 33 | | { |
| 1 | 34 | | if (sectionBase is ISceneListener deployedSceneListener) |
| | 35 | | { |
| 1 | 36 | | scenesViewController.AddListener(deployedSceneListener); |
| | 37 | | } |
| | 38 | |
|
| 1 | 39 | | if (sectionBase is IProjectsListener projectsListener) |
| | 40 | | { |
| 0 | 41 | | projectsController.AddListener(projectsListener); |
| | 42 | | } |
| | 43 | |
|
| 1 | 44 | | if (sectionBase is ISelectSceneListener selectSceneListener) |
| | 45 | | { |
| 0 | 46 | | scenesViewController.AddListener(selectSceneListener); |
| | 47 | | } |
| | 48 | |
|
| 1 | 49 | | if (sectionBase is ILandsListener landsListener) |
| | 50 | | { |
| 0 | 51 | | landsController.AddListener(landsListener); |
| | 52 | | } |
| | 53 | |
|
| 1 | 54 | | searchBarView.SetSearchBar(sectionBase.searchHandler, sectionBase.searchBarConfig); |
| 1 | 55 | | } |
| | 56 | |
|
| | 57 | | void OnSectionHide(SectionBase sectionBase) |
| | 58 | | { |
| 1 | 59 | | if (sectionBase is ISceneListener deployedSceneListener) |
| | 60 | | { |
| 1 | 61 | | scenesViewController.RemoveListener(deployedSceneListener); |
| | 62 | | } |
| | 63 | |
|
| 1 | 64 | | if (sectionBase is IProjectsListener projectSceneListener) |
| | 65 | | { |
| 0 | 66 | | projectsController.RemoveListener(projectSceneListener); |
| | 67 | | } |
| | 68 | |
|
| 1 | 69 | | if (sectionBase is ISelectSceneListener selectSceneListener) |
| | 70 | | { |
| 0 | 71 | | scenesViewController.RemoveListener(selectSceneListener); |
| | 72 | | } |
| | 73 | |
|
| 1 | 74 | | if (sectionBase is ILandsListener landsListener) |
| | 75 | | { |
| 0 | 76 | | landsController.RemoveListener(landsListener); |
| | 77 | | } |
| | 78 | |
|
| 1 | 79 | | searchBarView.SetSearchBar(null, null); |
| 1 | 80 | | } |
| | 81 | |
|
| 4 | 82 | | void SelectProject(ISceneCardView sceneCardView) { sectionsController.OpenSection(SectionId.SETTINGS_PROJECT_GENERAL |
| | 83 | | } |