VLCTabBarCoordinator.swift 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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, UITabBarControllerDelegate {
  14. private var childCoordinators: [NSObject] = []
  15. private var tabBarController: UITabBarController
  16. private var services: Services
  17. private let displayController = VLCPlayerDisplayController()
  18. public init(tabBarController: UITabBarController, services: Services) {
  19. self.tabBarController = tabBarController
  20. self.services = services
  21. super.init()
  22. self.tabBarController.delegate = self
  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. tabBarController.tabBar.barTintColor = PresentationTheme.current.colors.tabBarColor
  31. customizeMoreViewController()
  32. }
  33. func customizeMoreViewController() {
  34. if let UITabBarCustomizeViewClass = NSClassFromString("UITabBarCustomizeView") {
  35. for subview in tabBarController.view.subviews where subview.isKind(of: UITabBarCustomizeViewClass) {
  36. subview.backgroundColor = PresentationTheme.current.colors.background
  37. subview.tintColor = PresentationTheme.current.colors.orangeUI
  38. }
  39. }
  40. }
  41. func tabBarController(_ tabBarController: UITabBarController, willBeginCustomizing viewControllers: [UIViewController]) {
  42. customizeMoreViewController()
  43. }
  44. func setupViewControllers() {
  45. tabBarController.addChildViewController(displayController)
  46. tabBarController.view.addSubview(displayController.view)
  47. displayController.view.layoutMargins = UIEdgeInsets(top:0, left:0, bottom:tabBarController.tabBar.frame.size.height, right:0)
  48. displayController.didMove(toParentViewController: tabBarController)
  49. let videoVC = VLCMediaViewController(services: services)
  50. //this should probably not be the delegate
  51. videoVC.delegate = self
  52. videoVC.title = NSLocalizedString("VIDEO", comment: "")
  53. videoVC.tabBarItem = UITabBarItem(
  54. title: NSLocalizedString("VIDEO", comment: ""),
  55. image: UIImage(named: "TVShowsIcon"),
  56. selectedImage: UIImage(named: "TVShowsIcon"))
  57. videoVC.tabBarItem.accessibilityIdentifier = "Video"
  58. // Audio
  59. let audioVC = VLCMediaViewController(services: services)
  60. //this should probably not be the delegate
  61. audioVC.delegate = self
  62. audioVC.title = NSLocalizedString("AUDIO", comment: "")
  63. audioVC.tabBarItem = UITabBarItem(
  64. title: NSLocalizedString("AUDIO", comment: ""),
  65. image: UIImage(named: "MusicAlbums"),
  66. selectedImage:UIImage(named: "MusicAlbums"))
  67. audioVC.tabBarItem.accessibilityIdentifier = "Audio"
  68. //Serverlist
  69. let serverVC = VLCServerListViewController(nibName: nil, bundle: nil)
  70. serverVC.title = NSLocalizedString("LOCAL_NETWORK", comment: "")
  71. serverVC.tabBarItem = UITabBarItem(
  72. title: NSLocalizedString("LOCAL_NETWORK", comment: ""),
  73. image: UIImage(named: "Local"),
  74. selectedImage: UIImage(named: "Local"))
  75. serverVC.tabBarItem.accessibilityIdentifier = "Server"
  76. //Settings
  77. let settingsVC = VLCSettingsController()
  78. settingsVC.title = NSLocalizedString("Settings", comment: "")
  79. settingsVC.tabBarItem = UITabBarItem(
  80. title: NSLocalizedString("Settings", comment: ""),
  81. image: UIImage(named: "Settings"),
  82. selectedImage: UIImage(named: "Settings"))
  83. settingsVC.tabBarItem.accessibilityIdentifier = "Settings"
  84. //Download
  85. let downloadVC = VLCDownloadViewController()
  86. downloadVC.title = NSLocalizedString("DOWNLOAD_FROM_HTTP", comment:"")
  87. downloadVC.tabBarItem = UITabBarItem(
  88. title: NSLocalizedString("DOWNLOAD_FROM_HTTP", comment: ""),
  89. image: UIImage(named: "Downloads"),
  90. selectedImage: UIImage(named: "Downloads"))
  91. downloadVC.tabBarItem.accessibilityIdentifier = "Downloads"
  92. //Streaming
  93. let streamVC = VLCOpenNetworkStreamViewController(nibName: "VLCOpenNetworkStreamViewController", bundle: Bundle.main)
  94. streamVC.title = NSLocalizedString("OPEN_NETWORK", comment: "")
  95. streamVC.tabBarItem = UITabBarItem(
  96. title: NSLocalizedString("OPEN_NETWORK", comment: ""),
  97. image: UIImage(named: "OpenNetStream"),
  98. selectedImage: UIImage(named: "OpenNetStream"))
  99. streamVC.tabBarItem.accessibilityIdentifier = "Stream"
  100. let controllers = [audioVC, serverVC, videoVC, settingsVC, downloadVC, streamVC]
  101. tabBarController.viewControllers = controllers.map { UINavigationController(rootViewController: $0)}
  102. }
  103. // MARK: - VLCMediaViewControllerDelegate
  104. func mediaViewControllerDidSelectMediaObject(_ VLCMediaViewController: VLCMediaViewController, mediaObject: NSManagedObject) {
  105. playMedia(media:mediaObject)
  106. }
  107. func mediaViewControllerDidSelectSort(_ VLCMediaViewController: VLCMediaViewController) {
  108. showSortOptions()
  109. }
  110. func playMedia(media: NSManagedObject) {
  111. //that should go into a Coordinator itself
  112. let vpc = VLCPlaybackController.sharedInstance()
  113. vpc?.playMediaLibraryObject(media)
  114. }
  115. func showSortOptions() {
  116. //This should be in a subclass
  117. let sortOptionsAlertController = UIAlertController(title: NSLocalizedString("SORT_BY", comment: ""), message: nil, preferredStyle: .actionSheet)
  118. let sortByNameAction = UIAlertAction(title: SortOption.alphabetically.localizedDescription, style: .default) { action in
  119. }
  120. let sortBySizeAction = UIAlertAction(title: SortOption.size.localizedDescription, style: .default) { action in
  121. }
  122. let sortbyDateAction = UIAlertAction(title: SortOption.insertonDate.localizedDescription, style: .default) { action in
  123. }
  124. let cancelAction = UIAlertAction(title: NSLocalizedString("CANCEL", comment: ""), style: .cancel, handler: nil)
  125. sortOptionsAlertController.addAction(sortByNameAction)
  126. sortOptionsAlertController.addAction(sortbyDateAction)
  127. sortOptionsAlertController.addAction(sortBySizeAction)
  128. sortOptionsAlertController.addAction(cancelAction)
  129. sortOptionsAlertController.view.tintColor = UIColor.vlcOrangeTint()
  130. tabBarController.present(sortOptionsAlertController, animated: true)
  131. }
  132. }