VLCTabBarCoordinator.swift 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 = VLCMediaViewController(services: services, type: VLCMediaType(category: .video, subcategory: .allVideos))
  49. //this should probably not be the delegate
  50. videoVC.delegate = self
  51. videoVC.title = NSLocalizedString("VIDEO", comment: "")
  52. videoVC.tabBarItem = UITabBarItem(
  53. title: NSLocalizedString("VIDEO", comment: ""),
  54. image: UIImage(named: "TVShowsIcon"),
  55. selectedImage: UIImage(named: "TVShowsIcon"))
  56. videoVC.tabBarItem.accessibilityIdentifier = VLCAccessibilityIdentifier.video
  57. // Audio
  58. let audioVC = VLCMediaViewController(services: services, type: VLCMediaType(category: .audio, subcategory: .tracks))
  59. //this should probably not be the delegate
  60. audioVC.delegate = self
  61. audioVC.title = NSLocalizedString("AUDIO", comment: "")
  62. audioVC.tabBarItem = UITabBarItem(
  63. title: NSLocalizedString("AUDIO", comment: ""),
  64. image: UIImage(named: "MusicAlbums"),
  65. selectedImage: UIImage(named: "MusicAlbums"))
  66. audioVC.tabBarItem.accessibilityIdentifier = VLCAccessibilityIdentifier.audio
  67. // Serverlist
  68. let serverVC = VLCServerListViewController(nibName: nil, bundle: nil)
  69. serverVC.title = NSLocalizedString("LOCAL_NETWORK", comment: "")
  70. serverVC.tabBarItem = UITabBarItem(
  71. title: NSLocalizedString("LOCAL_NETWORK", comment: ""),
  72. image: UIImage(named: "Local"),
  73. selectedImage: UIImage(named: "Local"))
  74. serverVC.tabBarItem.accessibilityIdentifier = VLCAccessibilityIdentifier.localNetwork
  75. // Settings
  76. let settingsVC = VLCSettingsController()
  77. settingsVC.title = NSLocalizedString("Settings", comment: "")
  78. settingsVC.tabBarItem = UITabBarItem(
  79. title: NSLocalizedString("Settings", comment: ""),
  80. image: UIImage(named: "Settings"),
  81. selectedImage: UIImage(named: "Settings"))
  82. settingsVC.tabBarItem.accessibilityIdentifier = VLCAccessibilityIdentifier.settings
  83. let controllers = [audioVC, serverVC, videoVC, settingsVC]
  84. tabBarController.viewControllers = controllers.map { UINavigationController(rootViewController: $0) }
  85. }
  86. // MARK: - VLCMediaViewControllerDelegate
  87. func mediaViewControllerDidSelectMediaObject(_ VLCMediaViewController: VLCMediaViewController, mediaObject: NSManagedObject) {
  88. playMedia(media: mediaObject)
  89. }
  90. func mediaViewControllerDidSelectSort(_ VLCMediaViewController: VLCMediaViewController) {
  91. showSortOptions()
  92. }
  93. func playMedia(media: NSManagedObject) {
  94. //that should go into a Coordinator itself
  95. let vpc = VLCPlaybackController.sharedInstance()
  96. vpc?.playMediaLibraryObject(media)
  97. }
  98. func showSortOptions() {
  99. // This should be in a subclass
  100. let sortOptionsAlertController = UIAlertController(title: NSLocalizedString("SORT_BY", comment: ""), message: nil, preferredStyle: .actionSheet)
  101. let sortByNameAction = UIAlertAction(title: SortOption.alphabetically.localizedDescription, style: .default) { action in
  102. }
  103. let sortBySizeAction = UIAlertAction(title: SortOption.size.localizedDescription, style: .default) { action in
  104. }
  105. let sortbyDateAction = UIAlertAction(title: SortOption.insertonDate.localizedDescription, style: .default) { action in
  106. }
  107. let cancelAction = UIAlertAction(title: NSLocalizedString("CANCEL", comment: ""), style: .cancel, handler: nil)
  108. sortOptionsAlertController.addAction(sortByNameAction)
  109. sortOptionsAlertController.addAction(sortbyDateAction)
  110. sortOptionsAlertController.addAction(sortBySizeAction)
  111. sortOptionsAlertController.addAction(cancelAction)
  112. sortOptionsAlertController.view.tintColor = UIColor.vlcOrangeTint()
  113. tabBarController.present(sortOptionsAlertController, animated: true)
  114. }
  115. }