VLCTabBarCoordinator.swift 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*****************************************************************************
  2. * VLCTabbarCooordinator.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. import Foundation
  13. class VLCTabbarCooordinator: NSObject, VLCMediaViewControllerDelegate {
  14. private var childCoordinators: [NSObject] = []
  15. private var tabBarController: UITabBarController
  16. private var services: Services
  17. private var displayController: VLCPlayerDisplayController
  18. public init(tabBarController: UITabBarController, services: Services) {
  19. self.tabBarController = tabBarController
  20. self.services = services
  21. displayController = VLCPlayerDisplayController(services: services)
  22. super.init()
  23. NotificationCenter.default.addObserver(self, selector: #selector(updateTheme), name: .VLCThemeDidChangeNotification, object: nil)
  24. }
  25. @objc public func start() {
  26. setupViewControllers()
  27. updateTheme()
  28. }
  29. @objc func updateTheme() {
  30. //Setting this in appearanceManager doesn't update tabbar and UINavigationbar of the settingsViewController on change hence we do it here
  31. tabBarController.tabBar.barTintColor = PresentationTheme.current.colors.tabBarColor
  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 = [NSAttributedStringKey.foregroundColor: PresentationTheme.current.colors.navigationbarTextColor]
  37. if #available(iOS 11.0, *) {
  38. navController.navigationBar.largeTitleTextAttributes = [NSAttributedStringKey.foregroundColor: PresentationTheme.current.colors.navigationbarTextColor]
  39. }
  40. }
  41. }
  42. }
  43. func setupViewControllers() {
  44. tabBarController.addChildViewController(displayController)
  45. tabBarController.view.addSubview(displayController.view)
  46. displayController.view.layoutMargins = UIEdgeInsets(top: 0, left: 0, bottom: tabBarController.tabBar.frame.size.height, right: 0)
  47. displayController.didMove(toParentViewController: tabBarController)
  48. let videoVC = VLCVideoSubcategoryViewController(services: services)
  49. //videoVC.delegate = self
  50. videoVC.title = NSLocalizedString("VIDEO", comment: "")
  51. videoVC.tabBarItem = UITabBarItem(
  52. title: NSLocalizedString("VIDEO", comment: ""),
  53. image: UIImage(named: "TVShowsIcon"),
  54. selectedImage: UIImage(named: "TVShowsIcon"))
  55. videoVC.tabBarItem.accessibilityIdentifier = VLCAccessibilityIdentifier.video
  56. // Audio
  57. let audioVC = VLCAudioSubcategoryViewController(services: services)
  58. //audioVC.delegate = self
  59. audioVC.title = NSLocalizedString("AUDIO", comment: "")
  60. audioVC.tabBarItem = UITabBarItem(
  61. title: NSLocalizedString("AUDIO", comment: ""),
  62. image: UIImage(named: "MusicAlbums"),
  63. selectedImage: UIImage(named: "MusicAlbums"))
  64. audioVC.tabBarItem.accessibilityIdentifier = VLCAccessibilityIdentifier.audio
  65. // Serverlist
  66. let serverVC = VLCServerListViewController(nibName: nil, bundle: nil)
  67. serverVC.title = NSLocalizedString("LOCAL_NETWORK", comment: "")
  68. serverVC.tabBarItem = UITabBarItem(
  69. title: NSLocalizedString("LOCAL_NETWORK", comment: ""),
  70. image: UIImage(named: "Local"),
  71. selectedImage: UIImage(named: "Local"))
  72. serverVC.tabBarItem.accessibilityIdentifier = VLCAccessibilityIdentifier.localNetwork
  73. // Settings
  74. let settingsVC = VLCSettingsController()
  75. settingsVC.title = NSLocalizedString("Settings", comment: "")
  76. settingsVC.tabBarItem = UITabBarItem(
  77. title: NSLocalizedString("Settings", comment: ""),
  78. image: UIImage(named: "Settings"),
  79. selectedImage: UIImage(named: "Settings"))
  80. settingsVC.tabBarItem.accessibilityIdentifier = VLCAccessibilityIdentifier.settings
  81. let controllers = [videoVC, audioVC, serverVC, settingsVC]
  82. tabBarController.viewControllers = controllers.map { UINavigationController(rootViewController: $0) }
  83. }
  84. // MARK: - VLCMediaViewControllerDelegate
  85. func mediaViewControllerDidSelectMediaObject(_ VLCMediaViewController: VLCMediaViewController, mediaObject: NSManagedObject) {
  86. playMedia(media: mediaObject)
  87. }
  88. func mediaViewControllerDidSelectSort(_ VLCMediaViewController: VLCMediaViewController) {
  89. showSortOptions()
  90. }
  91. func playMedia(media: NSManagedObject) {
  92. //that should go into a Coordinator itself
  93. let vpc = VLCPlaybackController.sharedInstance()
  94. vpc?.playMediaLibraryObject(media)
  95. }
  96. func showSortOptions() {
  97. // This should be in a subclass
  98. let sortOptionsAlertController = UIAlertController(title: NSLocalizedString("SORT_BY", comment: ""), message: nil, preferredStyle: .actionSheet)
  99. let sortByNameAction = UIAlertAction(title: SortOption.alphabetically.localizedDescription, style: .default) { action in
  100. }
  101. let sortBySizeAction = UIAlertAction(title: SortOption.size.localizedDescription, style: .default) { action in
  102. }
  103. let sortbyDateAction = UIAlertAction(title: SortOption.insertonDate.localizedDescription, style: .default) { action in
  104. }
  105. let cancelAction = UIAlertAction(title: NSLocalizedString("CANCEL", comment: ""), style: .cancel, handler: nil)
  106. sortOptionsAlertController.addAction(sortByNameAction)
  107. sortOptionsAlertController.addAction(sortbyDateAction)
  108. sortOptionsAlertController.addAction(sortBySizeAction)
  109. sortOptionsAlertController.addAction(cancelAction)
  110. sortOptionsAlertController.view.tintColor = UIColor.vlcOrangeTint()
  111. tabBarController.present(sortOptionsAlertController, animated: true)
  112. }
  113. }