MediaViewController.swift 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*****************************************************************************
  2. * MediaViewController.swift
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2018 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Carola Nitz <caro # videolan.org>
  9. *
  10. * Refer to the COPYING file of the official project for license.
  11. *****************************************************************************/
  12. import UIKit
  13. class VLCVideoViewController: VLCMediaViewController {
  14. override init(services: Services) {
  15. super.init(services: services)
  16. setupUI()
  17. }
  18. private func setupUI() {
  19. title = NSLocalizedString("VIDEO", comment: "")
  20. tabBarItem = UITabBarItem(
  21. title: NSLocalizedString("VIDEO", comment: ""),
  22. image: UIImage(named: "TVShowsIcon"),
  23. selectedImage: UIImage(named: "TVShowsIcon"))
  24. tabBarItem.accessibilityIdentifier = VLCAccessibilityIdentifier.video
  25. }
  26. override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
  27. let movies = VLCMediaCategoryViewController<MLFile>(services: services, subcategory: VLCMediaSubcategories.movies)
  28. movies.delegate = super.self()
  29. let episodes = VLCMediaCategoryViewController<MLShowEpisode>(services: services, subcategory: VLCMediaSubcategories.episodes)
  30. episodes.delegate = super.self()
  31. let playlists = VLCMediaCategoryViewController<MLLabel>(services: services, subcategory: VLCMediaSubcategories.videoPlaylists)
  32. playlists.delegate = super.self()
  33. return [movies, episodes, playlists]
  34. }
  35. }
  36. class VLCAudioViewController: VLCMediaViewController {
  37. override init(services: Services) {
  38. super.init(services: services)
  39. setupUI()
  40. }
  41. private func setupUI() {
  42. title = NSLocalizedString("AUDIO", comment: "")
  43. tabBarItem = UITabBarItem(
  44. title: NSLocalizedString("AUDIO", comment: ""),
  45. image: UIImage(named: "MusicAlbums"),
  46. selectedImage: UIImage(named: "MusicAlbums"))
  47. tabBarItem.accessibilityIdentifier = VLCAccessibilityIdentifier.audio
  48. }
  49. override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
  50. let tracks = VLCMediaCategoryViewController<MLFile>(services: services, subcategory: VLCMediaSubcategories.tracks)
  51. tracks.delegate = super.self()
  52. let genres = VLCMediaCategoryViewController<String>(services: services, subcategory: VLCMediaSubcategories.genres)
  53. genres.delegate = super.self()
  54. let artists = VLCMediaCategoryViewController<String>(services: services, subcategory: VLCMediaSubcategories.artists)
  55. artists.delegate = super.self()
  56. let albums = VLCMediaCategoryViewController<MLAlbum>(services: services, subcategory: VLCMediaSubcategories.albums)
  57. albums.delegate = super.self()
  58. let playlists = VLCMediaCategoryViewController<MLLabel>(services: services, subcategory: VLCMediaSubcategories.audioPlaylists)
  59. playlists.delegate = super.self()
  60. return [tracks, genres, artists, albums, playlists]
  61. }
  62. }
  63. class VLCMediaViewController: VLCPagingViewController<VLCLabelCell> {
  64. var services: Services
  65. private var rendererButton: UIButton
  66. init(services: Services) {
  67. self.services = services
  68. rendererButton = services.rendererDiscovererManager.setupRendererButton()
  69. super.init(nibName: nil, bundle: nil)
  70. }
  71. override func viewDidLoad() {
  72. changeCurrentIndexProgressive = { (oldCell: VLCLabelCell?, newCell: VLCLabelCell?, progressPercentage: CGFloat, changeCurrentIndex: Bool, animated: Bool) in
  73. guard changeCurrentIndex == true else { return }
  74. oldCell?.iconLabel.textColor = PresentationTheme.current.colors.cellDetailTextColor
  75. newCell?.iconLabel.textColor = PresentationTheme.current.colors.orangeUI
  76. }
  77. setupNavigationBar()
  78. super.viewDidLoad()
  79. }
  80. private func setupNavigationBar() {
  81. if #available(iOS 11.0, *) {
  82. navigationController?.navigationBar.prefersLargeTitles = false
  83. }
  84. navigationItem.leftBarButtonItem = UIBarButtonItem(title: NSLocalizedString("SORT", comment: ""), style: .plain, target: self, action: #selector(sort))
  85. navigationItem.rightBarButtonItem = UIBarButtonItem(customView: rendererButton)
  86. }
  87. @objc func sort() {
  88. // This should be in a subclass
  89. let sortOptionsAlertController = UIAlertController(title: NSLocalizedString("SORT_BY", comment: ""), message: nil, preferredStyle: .actionSheet)
  90. let sortByNameAction = UIAlertAction(title: SortOption.alphabetically.localizedDescription, style: .default) { action in
  91. }
  92. let sortBySizeAction = UIAlertAction(title: SortOption.size.localizedDescription, style: .default) { action in
  93. }
  94. let sortbyDateAction = UIAlertAction(title: SortOption.insertonDate.localizedDescription, style: .default) { action in
  95. }
  96. let cancelAction = UIAlertAction(title: NSLocalizedString("CANCEL", comment: ""), style: .cancel, handler: nil)
  97. sortOptionsAlertController.addAction(sortByNameAction)
  98. sortOptionsAlertController.addAction(sortbyDateAction)
  99. sortOptionsAlertController.addAction(sortBySizeAction)
  100. sortOptionsAlertController.addAction(cancelAction)
  101. sortOptionsAlertController.view.tintColor = UIColor.vlcOrangeTint()
  102. present(sortOptionsAlertController, animated: true)
  103. }
  104. // MARK: - PagerTabStripDataSource
  105. override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
  106. fatalError("this should only be used as subclass")
  107. }
  108. override func configure(cell: VLCLabelCell, for indicatorInfo: IndicatorInfo) {
  109. cell.iconLabel.text = indicatorInfo.title
  110. }
  111. override func updateIndicator(for viewController: PagerTabStripViewController, fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool) {
  112. super.updateIndicator(for: viewController, fromIndex: fromIndex, toIndex: toIndex, withProgressPercentage: progressPercentage, indexWasChanged: indexWasChanged)
  113. }
  114. override var preferredStatusBarStyle: UIStatusBarStyle {
  115. return PresentationTheme.current.colors.statusBarStyle
  116. }
  117. }
  118. // MARK: - VLCMediaCategoryViewControllerDelegate
  119. extension VLCMediaViewController: VLCMediaCategoryViewControllerDelegate {
  120. func mediaViewControllerDidSelectMediaObject(_ viewcontroller: UIViewController, mediaObject: NSManagedObject) {
  121. playMedia(media: mediaObject)
  122. }
  123. func playMedia(media: NSManagedObject) {
  124. //that should go into a Coordinator itself
  125. let vpc = VLCPlaybackController.sharedInstance()
  126. vpc?.playMediaLibraryObject(media)
  127. }
  128. }