VLCTabBarCoordinator.swift 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 let displayController = VLCPlayerDisplayController()
  18. public init(tabBarController: UITabBarController, services: Services) {
  19. self.tabBarController = tabBarController
  20. self.services = services
  21. super.init()
  22. NotificationCenter.default.addObserver(self, selector: #selector(updateTheme), name: .VLCThemeDidChangeNotification, object: nil)
  23. }
  24. @objc public func start() {
  25. setupViewControllers()
  26. updateTheme()
  27. }
  28. @objc func updateTheme() {
  29. tabBarController.tabBar.barTintColor = PresentationTheme.current.colors.tabBarColor
  30. }
  31. func setupViewControllers() {
  32. tabBarController.addChildViewController(displayController)
  33. tabBarController.view.addSubview(displayController.view)
  34. displayController.view.layoutMargins = UIEdgeInsets(top:0, left:0, bottom:tabBarController.tabBar.frame.size.height, right:0)
  35. displayController.didMove(toParentViewController: tabBarController)
  36. let videoVC = VLCMediaViewController(services: services)
  37. //this should probably not be the delegate
  38. videoVC.delegate = self
  39. videoVC.title = NSLocalizedString("VIDEO", comment: "")
  40. videoVC.tabBarItem = UITabBarItem(
  41. title: NSLocalizedString("VIDEO", comment: ""),
  42. image: UIImage(named: "TVShowsIcon"),
  43. selectedImage: UIImage(named: "TVShowsIcon"))
  44. videoVC.tabBarItem.accessibilityIdentifier = "Video"
  45. // Audio
  46. let audioVC = VLCMediaViewController(services: services)
  47. //this should probably not be the delegate
  48. audioVC.delegate = self
  49. audioVC.title = NSLocalizedString("AUDIO", comment: "")
  50. audioVC.tabBarItem = UITabBarItem(
  51. title: NSLocalizedString("AUDIO", comment: ""),
  52. image: UIImage(named: "MusicAlbums"),
  53. selectedImage:UIImage(named: "MusicAlbums"))
  54. audioVC.tabBarItem.accessibilityIdentifier = "Audio"
  55. //Serverlist
  56. let serverVC = VLCServerListViewController(nibName: nil, bundle: nil)
  57. serverVC.title = NSLocalizedString("LOCAL_NETWORK", comment: "")
  58. serverVC.tabBarItem = UITabBarItem(
  59. title: NSLocalizedString("LOCAL_NETWORK", comment: ""),
  60. image: UIImage(named: "Local"),
  61. selectedImage: UIImage(named: "Local"))
  62. serverVC.tabBarItem.accessibilityIdentifier = "LocalNetwork"
  63. //Settings
  64. let settingsVC = VLCSettingsController()
  65. settingsVC.title = NSLocalizedString("Settings", comment: "")
  66. settingsVC.tabBarItem = UITabBarItem(
  67. title: NSLocalizedString("Settings", comment: ""),
  68. image: UIImage(named: "Settings"),
  69. selectedImage: UIImage(named: "Settings"))
  70. settingsVC.tabBarItem.accessibilityIdentifier = "Settings"
  71. let controllers = [audioVC, serverVC, videoVC, settingsVC]
  72. tabBarController.viewControllers = controllers.map { UINavigationController(rootViewController: $0)}
  73. }
  74. // MARK: - VLCMediaViewControllerDelegate
  75. func mediaViewControllerDidSelectMediaObject(_ VLCMediaViewController: VLCMediaViewController, mediaObject: NSManagedObject) {
  76. playMedia(media:mediaObject)
  77. }
  78. func mediaViewControllerDidSelectSort(_ VLCMediaViewController: VLCMediaViewController) {
  79. showSortOptions()
  80. }
  81. func playMedia(media: NSManagedObject) {
  82. //that should go into a Coordinator itself
  83. let vpc = VLCPlaybackController.sharedInstance()
  84. vpc?.playMediaLibraryObject(media)
  85. }
  86. func showSortOptions() {
  87. //This should be in a subclass
  88. let sortOptionsAlertController = UIAlertController(title: NSLocalizedString("SORT_BY", comment: ""), message: nil, preferredStyle: .actionSheet)
  89. let sortByNameAction = UIAlertAction(title: SortOption.alphabetically.localizedDescription, style: .default) { action in
  90. }
  91. let sortBySizeAction = UIAlertAction(title: SortOption.size.localizedDescription, style: .default) { action in
  92. }
  93. let sortbyDateAction = UIAlertAction(title: SortOption.insertonDate.localizedDescription, style: .default) { action in
  94. }
  95. let cancelAction = UIAlertAction(title: NSLocalizedString("CANCEL", comment: ""), style: .cancel, handler: nil)
  96. sortOptionsAlertController.addAction(sortByNameAction)
  97. sortOptionsAlertController.addAction(sortbyDateAction)
  98. sortOptionsAlertController.addAction(sortBySizeAction)
  99. sortOptionsAlertController.addAction(cancelAction)
  100. sortOptionsAlertController.view.tintColor = UIColor.vlcOrangeTint()
  101. tabBarController.present(sortOptionsAlertController, animated: true)
  102. }
  103. }