VLCTabBarCoordinator.swift 2.46 KB
Newer Older
1
/*****************************************************************************
2
 * VLCTabBarCoordinator.swift
3 4 5 6 7 8 9 10 11 12
 * 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.
 *****************************************************************************/

13
class VLCTabBarCoordinator: NSObject {
14
    private var tabBarController: UITabBarController
15
    private var services: Services
16

17
    init(tabBarController: UITabBarController, services: Services) {
18
        self.tabBarController = tabBarController
19
        self.services = services
20
        super.init()
21
        setup()
22 23 24
        NotificationCenter.default.addObserver(self, selector: #selector(updateTheme), name: .VLCThemeDidChangeNotification, object: nil)
    }

25
    private func setup() {
26 27 28 29 30
        setupViewControllers()
        updateTheme()
    }

    @objc func updateTheme() {
31
        //Setting this in appearanceManager doesn't update tabbar and UINavigationbar of the settingsViewController on change hence we do it here
32
        tabBarController.tabBar.barTintColor = PresentationTheme.current.colors.tabBarColor
33 34
        tabBarController.viewControllers?.forEach {
            if let navController = $0 as? UINavigationController, navController.topViewController is VLCSettingsController {
35 36
                navController.navigationBar.barTintColor = PresentationTheme.current.colors.navigationbarColor
                navController.navigationBar.tintColor = PresentationTheme.current.colors.orangeUI
37 38 39 40 41 42 43
                navController.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor:  PresentationTheme.current.colors.navigationbarTextColor]

                if #available(iOS 11.0, *) {
                    navController.navigationBar.largeTitleTextAttributes = [NSAttributedStringKey.foregroundColor:  PresentationTheme.current.colors.navigationbarTextColor]
                }
            }
        }
44 45
    }

46
    private func setupViewControllers() {
47 48 49 50 51 52
        let controllers = [
            VLCVideoViewController(services: services),
            VLCAudioViewController(services: services),
            VLCServerListViewController(nibName: nil, bundle: nil),
            VLCSettingsController()
        ]
53

Kevin Bettin's avatar
Kevin Bettin committed
54
        tabBarController.viewControllers = controllers.map { UINavigationController(rootViewController: $0) }
55 56
    }
}