AppCoordinator.swift 3.5 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 medialibraryManager = VLCMediaLibraryManager()
  15. @objc let rendererDiscovererManager = VLCRendererDiscovererManager(presentingViewController: nil)
  16. }
  17. @objc class AppCoordinator: NSObject {
  18. private var childCoordinators: [NSObject] = []
  19. private var viewController: UIViewController
  20. private var playerController: VLCPlayerDisplayController
  21. private var tabBarController: UITabBarController
  22. private var services = Services()
  23. private var migrationViewController = VLCMigrationViewController(nibName: String(describing: VLCMigrationViewController.self),
  24. bundle: nil)
  25. @objc init(viewController: UIViewController) {
  26. self.viewController = viewController
  27. self.playerController = VLCPlayerDisplayController(services: services)
  28. self.tabBarController = UITabBarController()
  29. super.init()
  30. setupChildViewControllers()
  31. // Init the HTTP Server and clean its cache
  32. // FIXME: VLCHTTPUploaderController should perhaps be a service?
  33. VLCHTTPUploaderController.sharedInstance().cleanCache()
  34. services.medialibraryManager.migrationDelegate = self
  35. services.medialibraryManager.prepareMigrationIfNeeded()
  36. }
  37. private func setupChildViewControllers() {
  38. viewController.addChild(tabBarController)
  39. viewController.view.addSubview(tabBarController.view)
  40. tabBarController.view.frame = viewController.view.frame
  41. tabBarController.didMove(toParent: viewController)
  42. viewController.addChild(playerController)
  43. viewController.view.addSubview(playerController.view)
  44. playerController.view.layoutMargins = UIEdgeInsets(top: 0,
  45. left: 0,
  46. bottom: tabBarController.tabBar.frame.size.height,
  47. right: 0)
  48. playerController.realBottomAnchor = tabBarController.tabBar.topAnchor
  49. playerController.didMove(toParent: viewController)
  50. }
  51. @objc func start() {
  52. let tabbarCoordinator = VLCTabBarCoordinator(tabBarController: tabBarController, services: services)
  53. childCoordinators.append(tabbarCoordinator)
  54. }
  55. }
  56. extension AppCoordinator: MediaLibraryMigrationDelegate {
  57. func medialibraryDidStartMigration(_ medialibrary: VLCMediaLibraryManager) {
  58. tabBarController.present(migrationViewController, animated: true, completion: nil)
  59. }
  60. func medialibraryDidFinishMigration(_ medialibrary: VLCMediaLibraryManager) {
  61. if tabBarController.presentedViewController === migrationViewController {
  62. tabBarController.dismiss(animated: true, completion: nil)
  63. }
  64. }
  65. func medialibraryDidStopMigration(_ medialibrary: VLCMediaLibraryManager) {
  66. if tabBarController.presentedViewController === migrationViewController {
  67. tabBarController.dismiss(animated: true, completion: nil)
  68. }
  69. }
  70. }