MediaViewController.swift 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
  15. let movies = VLCMediaCategoryViewController<MLFile>(services: services, subcategory: VLCMediaSubcategories.movies)
  16. movies.delegate = super.self()
  17. let episodes = VLCMediaCategoryViewController<MLShowEpisode>(services: services, subcategory: VLCMediaSubcategories.episodes)
  18. episodes.delegate = super.self()
  19. let playlists = VLCMediaCategoryViewController<MLLabel>(services: services, subcategory: VLCMediaSubcategories.videoPlaylists)
  20. playlists.delegate = super.self()
  21. return [movies, episodes, playlists]
  22. }
  23. }
  24. class VLCAudioViewController: VLCMediaViewController {
  25. override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
  26. let tracks = VLCMediaCategoryViewController<MLFile>(services: services, subcategory: VLCMediaSubcategories.tracks)
  27. tracks.delegate = super.self()
  28. let genres = VLCMediaCategoryViewController<String>(services: services, subcategory: VLCMediaSubcategories.genres)
  29. genres.delegate = super.self()
  30. let artists = VLCMediaCategoryViewController<String>(services: services, subcategory: VLCMediaSubcategories.artists)
  31. artists.delegate = super.self()
  32. let albums = VLCMediaCategoryViewController<MLAlbum>(services: services, subcategory: VLCMediaSubcategories.albums)
  33. albums.delegate = super.self()
  34. let playlists = VLCMediaCategoryViewController<MLLabel>(services: services, subcategory: VLCMediaSubcategories.audioPlaylists)
  35. playlists.delegate = super.self()
  36. return [tracks, genres, artists, albums, playlists]
  37. }
  38. }
  39. class VLCMediaViewController: VLCPagingViewController<VLCLabelCell> {
  40. var services: Services
  41. private var rendererButton: UIButton
  42. init(services: Services) {
  43. self.services = services
  44. rendererButton = services.rendererDiscovererManager.setupRendererButton()
  45. super.init(nibName: nil, bundle: nil)
  46. }
  47. override func viewDidLoad() {
  48. changeCurrentIndexProgressive = { (oldCell: VLCLabelCell?, newCell: VLCLabelCell?, progressPercentage: CGFloat, changeCurrentIndex: Bool, animated: Bool) in
  49. guard changeCurrentIndex == true else { return }
  50. oldCell?.iconLabel.textColor = PresentationTheme.current.colors.cellDetailTextColor
  51. newCell?.iconLabel.textColor = PresentationTheme.current.colors.orangeUI
  52. }
  53. setupNavigationBar()
  54. super.viewDidLoad()
  55. }
  56. private func setupNavigationBar() {
  57. if #available(iOS 11.0, *) {
  58. navigationController?.navigationBar.prefersLargeTitles = false
  59. }
  60. navigationItem.leftBarButtonItem = UIBarButtonItem(title: NSLocalizedString("SORT", comment: ""), style: .plain, target: self, action: #selector(sort))
  61. navigationItem.rightBarButtonItem = UIBarButtonItem(customView: rendererButton)
  62. }
  63. @objc func sort() {
  64. // This should be in a subclass
  65. let sortOptionsAlertController = UIAlertController(title: NSLocalizedString("SORT_BY", comment: ""), message: nil, preferredStyle: .actionSheet)
  66. let sortByNameAction = UIAlertAction(title: SortOption.alphabetically.localizedDescription, style: .default) { action in
  67. }
  68. let sortBySizeAction = UIAlertAction(title: SortOption.size.localizedDescription, style: .default) { action in
  69. }
  70. let sortbyDateAction = UIAlertAction(title: SortOption.insertonDate.localizedDescription, style: .default) { action in
  71. }
  72. let cancelAction = UIAlertAction(title: NSLocalizedString("CANCEL", comment: ""), style: .cancel, handler: nil)
  73. sortOptionsAlertController.addAction(sortByNameAction)
  74. sortOptionsAlertController.addAction(sortbyDateAction)
  75. sortOptionsAlertController.addAction(sortBySizeAction)
  76. sortOptionsAlertController.addAction(cancelAction)
  77. sortOptionsAlertController.view.tintColor = UIColor.vlcOrangeTint()
  78. present(sortOptionsAlertController, animated: true)
  79. }
  80. // MARK: - PagerTabStripDataSource
  81. override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
  82. fatalError("this should only be used as subclass")
  83. }
  84. override func configure(cell: VLCLabelCell, for indicatorInfo: IndicatorInfo) {
  85. cell.iconLabel.text = indicatorInfo.title
  86. }
  87. override func updateIndicator(for viewController: PagerTabStripViewController, fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool) {
  88. super.updateIndicator(for: viewController, fromIndex: fromIndex, toIndex: toIndex, withProgressPercentage: progressPercentage, indexWasChanged: indexWasChanged)
  89. }
  90. override var preferredStatusBarStyle: UIStatusBarStyle {
  91. return PresentationTheme.current.colors.statusBarStyle
  92. }
  93. }
  94. // MARK: - VLCMediaCategoryViewControllerDelegate
  95. extension VLCMediaViewController: VLCMediaCategoryViewControllerDelegate {
  96. func mediaViewControllerDidSelectMediaObject(_ viewcontroller: UIViewController, mediaObject: NSManagedObject) {
  97. playMedia(media: mediaObject)
  98. }
  99. func playMedia(media: NSManagedObject) {
  100. //that should go into a Coordinator itself
  101. let vpc = VLCPlaybackController.sharedInstance()
  102. vpc?.playMediaLibraryObject(media)
  103. }
  104. }