MediaSubcategoryViewController.swift 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*****************************************************************************
  2. * MediaSubcategoryViewController.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 VLCVideoSubcategoryViewController: VLCMediaSubcategoryViewController {
  14. override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
  15. let movies = VLCMediaViewController<MLFile>(services: services, subcategory: VLCMediaSubcategories.movies)
  16. movies.delegate = mediaDelegate
  17. let episodes = VLCMediaViewController<MLShowEpisode>(services: services, subcategory: VLCMediaSubcategories.episodes)
  18. episodes.delegate = mediaDelegate
  19. let playlists = VLCMediaViewController<MLLabel>(services: services, subcategory: VLCMediaSubcategories.videoPlaylists)
  20. playlists.delegate = mediaDelegate
  21. return [movies, episodes, playlists]
  22. }
  23. }
  24. class VLCAudioSubcategoryViewController: VLCMediaSubcategoryViewController {
  25. override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
  26. let tracks = VLCMediaViewController<MLFile>(services: services, subcategory: VLCMediaSubcategories.tracks)
  27. tracks.delegate = mediaDelegate
  28. let genres = VLCMediaViewController<String>(services: services, subcategory: VLCMediaSubcategories.genres)
  29. genres.delegate = mediaDelegate
  30. let artists = VLCMediaViewController<String>(services: services, subcategory: VLCMediaSubcategories.artists)
  31. artists.delegate = mediaDelegate
  32. let albums = VLCMediaViewController<MLAlbum>(services: services, subcategory: VLCMediaSubcategories.albums)
  33. albums.delegate = mediaDelegate
  34. let playlists = VLCMediaViewController<MLLabel>(services: services, subcategory: VLCMediaSubcategories.audioPlaylists)
  35. playlists.delegate = mediaDelegate
  36. return [tracks, genres, artists, albums, playlists]
  37. }
  38. }
  39. class VLCMediaSubcategoryViewController: BaseButtonBarPagerTabStripViewController<VLCLabelCell> {
  40. var services: Services
  41. weak var mediaDelegate: VLCMediaViewControllerDelegate?
  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. }