VLCTabBarCoordinator.swift 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*****************************************************************************
  2. * VLCTabBarCoordinator.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. class VLCTabBarCoordinator: NSObject {
  13. private var tabBarController: UITabBarController
  14. private var services: Services
  15. init(tabBarController: UITabBarController, services: Services) {
  16. self.tabBarController = tabBarController
  17. self.services = services
  18. super.init()
  19. setup()
  20. NotificationCenter.default.addObserver(self, selector: #selector(updateTheme), name: .VLCThemeDidChangeNotification, object: nil)
  21. }
  22. private func setup() {
  23. setupViewControllers()
  24. updateTheme()
  25. }
  26. @objc func updateTheme() {
  27. //Setting this in appearanceManager doesn't update tabbar and UINavigationbar of the settingsViewController on change hence we do it here
  28. tabBarController.tabBar.isTranslucent = false
  29. tabBarController.tabBar.backgroundColor = PresentationTheme.current.colors.tabBarColor
  30. tabBarController.tabBar.barTintColor = PresentationTheme.current.colors.tabBarColor
  31. tabBarController.tabBar.itemPositioning = .fill
  32. tabBarController.viewControllers?.forEach {
  33. if let navController = $0 as? UINavigationController, navController.topViewController is VLCSettingsController {
  34. navController.navigationBar.barTintColor = PresentationTheme.current.colors.navigationbarColor
  35. navController.navigationBar.tintColor = PresentationTheme.current.colors.orangeUI
  36. navController.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: PresentationTheme.current.colors.navigationbarTextColor]
  37. if #available(iOS 11.0, *) {
  38. navController.navigationBar.largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor: PresentationTheme.current.colors.navigationbarTextColor]
  39. }
  40. if #available(iOS 13.0, *) {
  41. navController.navigationBar.standardAppearance = AppearanceManager.navigationbarAppearance()
  42. navController.navigationBar.scrollEdgeAppearance = AppearanceManager.navigationbarAppearance()
  43. }
  44. }
  45. }
  46. }
  47. private func setupViewControllers() {
  48. let controllers: [UIViewController] = [
  49. VLCVideoViewController(services: services),
  50. VLCAudioViewController(services: services),
  51. VLCPlaylistViewController(services: services),
  52. VLCServerListViewController(nibName: nil, bundle: nil),
  53. VLCSettingsController(mediaLibraryService: services.medialibraryService)
  54. ]
  55. tabBarController.viewControllers = controllers.map { UINavigationController(rootViewController: $0) }
  56. }
  57. func handleShortcutItem(_ item: UIApplicationShortcutItem) {
  58. switch item.type {
  59. case kVLCApplicationShortcutLocalVideo:
  60. tabBarController.selectedIndex = tabBarController.viewControllers?.firstIndex(where: { vc -> Bool in
  61. vc is VLCVideoViewController
  62. }) ?? 0
  63. case kVLCApplicationShortcutLocalAudio:
  64. tabBarController.selectedIndex = tabBarController.viewControllers?.firstIndex(where: { vc -> Bool in
  65. vc is VLCAudioViewController
  66. }) ?? 1
  67. case kVLCApplicationShortcutPlaylist:
  68. tabBarController.selectedIndex = tabBarController.viewControllers?.firstIndex(where: { vc -> Bool in
  69. vc is VLCPlaylistViewController
  70. }) ?? 2
  71. case kVLCApplicationShortcutNetwork:
  72. tabBarController.selectedIndex = tabBarController.viewControllers?.firstIndex(where: { vc -> Bool in
  73. vc is VLCServerListViewController
  74. }) ?? 3
  75. default:
  76. assertionFailure("unhandled shortcut")
  77. }
  78. }
  79. }
  80. extension UITabBarController {
  81. open override var preferredStatusBarStyle: UIStatusBarStyle {
  82. return PresentationTheme.current.colors.statusBarStyle
  83. }
  84. }