AppCoordinator.swift 2.44 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
/*****************************************************************************
 * 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(VLCService)
14
class Services: NSObject {
15
    @objc let medialibraryManager = VLCMediaLibraryManager()
16
    @objc let rendererDiscovererManager = VLCRendererDiscovererManager(presentingViewController: nil)
17 18
}

19
@objc class AppCoordinator: NSObject {
20
    private var childCoordinators: [NSObject] = []
21
    private var viewController: UIViewController
22
    private var playerController: VLCPlayerDisplayController
23
    private var tabBarController: UITabBarController
24 25
    private var services = Services()

26 27
    @objc init(viewController: UIViewController) {
        self.viewController = viewController
28
        self.playerController = VLCPlayerDisplayController(services: services)
29
        self.tabBarController = UITabBarController()
30
        super.init()
31
        setupChildViewControllers()
32 33 34 35

        // Init the HTTP Server and clean its cache
        // FIXME: VLCHTTPUploaderController should perhaps be a service?
        VLCHTTPUploaderController.sharedInstance().cleanCache()
36 37
    }

38
    private func setupChildViewControllers() {
Soomin Lee's avatar
Soomin Lee committed
39
        viewController.addChild(tabBarController)
40 41
        viewController.view.addSubview(tabBarController.view)
        tabBarController.view.frame = viewController.view.frame
Soomin Lee's avatar
Soomin Lee committed
42
        tabBarController.didMove(toParent: viewController)
43

Soomin Lee's avatar
Soomin Lee committed
44
        viewController.addChild(playerController)
45
        viewController.view.addSubview(playerController.view)
Soomin Lee's avatar
Soomin Lee committed
46 47 48 49
        playerController.view.layoutMargins = UIEdgeInsets(top: 0,
                                                           left: 0,
                                                           bottom: tabBarController.tabBar.frame.size.height,
                                                           right: 0)
50
        playerController.realBottomAnchor = tabBarController.tabBar.topAnchor
Soomin Lee's avatar
Soomin Lee committed
51
        playerController.didMove(toParent: viewController)
52 53
    }

54
    @objc func start() {
55

56
        let tabbarCoordinator = VLCTabBarCoordinator(tabBarController: tabBarController, services: services)
57 58 59
        childCoordinators.append(tabbarCoordinator)
    }
}