123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- /*****************************************************************************
- * AppCoordinator.swift
- * VLC for iOS
- *****************************************************************************
- * Copyright (c) 2018 VideoLAN. All rights reserved.
- * $Id$
- *
- * Authors: Carola Nitz <nitz.carola # gmail.com>
- *
- * Refer to the COPYING file of the official project for license.
- *****************************************************************************/
- @objc(VLCServices)
- class Services: NSObject {
- @objc let medialibraryService = MediaLibraryService()
- @objc let rendererDiscovererManager = VLCRendererDiscovererManager(presentingViewController: nil)
- }
- @objc class AppCoordinator: NSObject {
- private var services = Services()
- private var childCoordinators: [NSObject] = []
- private var playerDisplayController: VLCPlayerDisplayController
- private var tabBarController: UITabBarController
- private lazy var tabBarCoordinator: VLCTabBarCoordinator = {
- return VLCTabBarCoordinator(tabBarController: tabBarController, services: services)
- }()
- private var migrationViewController = VLCMigrationViewController(nibName: String(describing: VLCMigrationViewController.self),
- bundle: nil)
- @objc init(tabBarController: UITabBarController) {
- self.playerDisplayController = VLCPlayerDisplayController(services: services)
- self.tabBarController = tabBarController
- super.init()
- setupChildViewControllers()
- // Init the HTTP Server and clean its cache
- // FIXME: VLCHTTPUploaderController should perhaps be a service?
- VLCHTTPUploaderController.sharedInstance().cleanCache()
- VLCHTTPUploaderController.sharedInstance().medialibrary = services.medialibraryService
- services.medialibraryService.migrationDelegate = self
- }
- private func setupChildViewControllers() {
- tabBarController.addChild(playerDisplayController)
- tabBarController.view.addSubview(playerDisplayController.view)
- playerDisplayController.view.layoutMargins = UIEdgeInsets(top: 0,
- left: 0,
- bottom: tabBarController.tabBar.frame.size.height,
- right: 0)
- playerDisplayController.realBottomAnchor = tabBarController.tabBar.topAnchor
- playerDisplayController.didMove(toParent: tabBarController)
- // Set app cornerRadius back to 0
- // For some unknown reason, reading tabBarController anchors sets round corners for the entire app.
- // We set cornerRadius to 0 for the topmost layer so there are no round corners anymore.
- if #available(iOS 13, *) {
- tabBarController.view.layer.superlayer?.cornerRadius = 0
- }
- }
- @objc func start() {
- childCoordinators.append(tabBarCoordinator)
- }
- @objc func handleShortcutItem(_ item: UIApplicationShortcutItem) {
- tabBarCoordinator.handleShortcutItem(item)
- }
- @objc func mediaForUserActivity(_ activity: NSUserActivity) -> VLCMLMedia? {
- let userActivityType = activity.activityType
- guard let dict = activity.userInfo else { return nil }
- var identifier: Int64? = nil
- if userActivityType == CSSearchableItemActionType, let searchIdentifier = dict[CSSearchableItemActivityIdentifier] as? NSString {
- identifier = Int64(searchIdentifier.integerValue)
- } else if let mediaIdentifier = dict["playingmedia"] as? Int64 {
- identifier = mediaIdentifier
- }
- guard let mediaIdentifier = identifier else { return nil }
- return services.medialibraryService.media(for: mediaIdentifier)
- }
- }
- extension AppCoordinator: MediaLibraryMigrationDelegate {
- func medialibraryDidStartMigration(_ medialibrary: MediaLibraryService) {
- DispatchQueue.main.async {
- [tabBarController, migrationViewController] in
- tabBarController.present(migrationViewController, animated: true, completion: nil)
- }
- }
- func medialibraryDidFinishMigration(_ medialibrary: MediaLibraryService) {
- DispatchQueue.main.async {
- [migrationViewController] in
- migrationViewController.dismiss(animated: true, completion: nil)
- }
- }
- func medialibraryDidStopMigration(_ medialibrary: MediaLibraryService) {
- if tabBarController.presentedViewController === migrationViewController {
- DispatchQueue.main.async {
- [tabBarController] in
- tabBarController.dismiss(animated: true, completion: nil)
- }
- }
- }
- }
|