MediaViewController.swift 5.6 KB

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