AppCoordinator.swift 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. tabBarController.addChild(playerController)
  37. 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: tabBarController)
  44. }
  45. @objc func start() {
  46. childCoordinators.append(VLCTabBarCoordinator(tabBarController: tabBarController, services: services))
  47. }
  48. }
  49. extension AppCoordinator: MediaLibraryMigrationDelegate {
  50. func medialibraryDidStartMigration(_ medialibrary: MediaLibraryService) {
  51. DispatchQueue.main.async {
  52. [tabBarController, migrationViewController] in
  53. tabBarController.present(migrationViewController, animated: true, completion: nil)
  54. }
  55. }
  56. func medialibraryDidFinishMigration(_ medialibrary: MediaLibraryService) {
  57. DispatchQueue.main.async {
  58. [migrationViewController] in
  59. migrationViewController.dismiss(animated: true, completion: nil)
  60. }
  61. }
  62. func medialibraryDidStopMigration(_ medialibrary: MediaLibraryService) {
  63. if tabBarController.presentedViewController === migrationViewController {
  64. DispatchQueue.main.async {
  65. [tabBarController] in
  66. tabBarController.dismiss(animated: true, completion: nil)
  67. }
  68. }
  69. }
  70. }