AppCoordinator.swift 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*****************************************************************************
  2. * AppCoordinator.swift
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2018 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Carola Nitz <nitz.carola # gmail.com>
  9. *
  10. * Refer to the COPYING file of the official project for license.
  11. *****************************************************************************/
  12. @objc(VLCService)
  13. class Services: NSObject {
  14. @objc let medialibraryService = MediaLibraryService()
  15. @objc let rendererDiscovererManager = VLCRendererDiscovererManager(presentingViewController: nil)
  16. }
  17. @objc class AppCoordinator: NSObject {
  18. private var childCoordinators: [NSObject] = []
  19. private var playerController: VLCPlayerDisplayController
  20. private var tabBarController: UITabBarController
  21. private var services = Services()
  22. private var migrationViewController = VLCMigrationViewController(nibName: String(describing: VLCMigrationViewController.self),
  23. bundle: nil)
  24. @objc init(tabBarController: UITabBarController) {
  25. self.playerController = VLCPlayerDisplayController(services: services)
  26. self.tabBarController = tabBarController
  27. super.init()
  28. setupChildViewControllers()
  29. // Init the HTTP Server and clean its cache
  30. // FIXME: VLCHTTPUploaderController should perhaps be a service?
  31. VLCHTTPUploaderController.sharedInstance().cleanCache()
  32. VLCHTTPUploaderController.sharedInstance().medialibrary = services.medialibraryService
  33. services.medialibraryService.migrationDelegate = self
  34. }
  35. private func setupChildViewControllers() {
  36. self.tabBarController.addChild(playerController)
  37. self.tabBarController.view.addSubview(playerController.view)
  38. playerController.view.layoutMargins = UIEdgeInsets(top: 0,
  39. left: 0,
  40. bottom: tabBarController.tabBar.frame.size.height,
  41. right: 0)
  42. playerController.realBottomAnchor = tabBarController.tabBar.topAnchor
  43. playerController.didMove(toParent: self.tabBarController)
  44. }
  45. @objc func start() {
  46. let tabbarCoordinator = VLCTabBarCoordinator(tabBarController: tabBarController, services: services)
  47. childCoordinators.append(tabbarCoordinator)
  48. }
  49. }
  50. extension AppCoordinator: MediaLibraryMigrationDelegate {
  51. func medialibraryDidStartMigration(_ medialibrary: MediaLibraryService) {
  52. DispatchQueue.main.async {
  53. [tabBarController, migrationViewController] in
  54. tabBarController.present(migrationViewController, animated: true, completion: nil)
  55. }
  56. }
  57. func medialibraryDidFinishMigration(_ medialibrary: MediaLibraryService) {
  58. DispatchQueue.main.async {
  59. [migrationViewController] in
  60. migrationViewController.dismiss(animated: true, completion: nil)
  61. }
  62. }
  63. func medialibraryDidStopMigration(_ medialibrary: MediaLibraryService) {
  64. if tabBarController.presentedViewController === migrationViewController {
  65. DispatchQueue.main.async {
  66. [tabBarController] in
  67. tabBarController.dismiss(animated: true, completion: nil)
  68. }
  69. }
  70. }
  71. }