MediaSubcategoryViewController.swift 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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(services: services, type: VLCMediaType(category: .video, subcategory: .allVideos))
  16. let episodes = VLCMediaViewController(services: services, type: VLCMediaType(category: .video, subcategory: .episodes))
  17. let playlists = VLCMediaViewController(services: services, type: VLCMediaType(category: .video, subcategory: .videoPlaylists))
  18. let viewControllers = [movies, episodes, playlists]
  19. viewControllers.forEach { $0.delegate = mediaDelegate }
  20. return viewControllers
  21. }
  22. }
  23. class VLCAudioSubcategoryViewController: VLCMediaSubcategoryViewController {
  24. override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
  25. let tracks = VLCMediaViewController(services: services, type: VLCMediaType(category: .audio, subcategory: .tracks))
  26. let genres = VLCMediaViewController(services: services, type: VLCMediaType(category: .audio, subcategory: .genres))
  27. let artists = VLCMediaViewController(services: services, type: VLCMediaType(category: .audio, subcategory: .artists))
  28. let albums = VLCMediaViewController(services: services, type: VLCMediaType(category: .audio, subcategory: .albums))
  29. let playlists = VLCMediaViewController(services: services, type: VLCMediaType(category: .audio, subcategory: .audioPlaylists))
  30. let viewControllers = [tracks, genres, artists, albums, playlists]
  31. viewControllers.forEach { $0.delegate = mediaDelegate }
  32. return viewControllers
  33. }
  34. }
  35. class VLCMediaSubcategoryViewController: BaseButtonBarPagerTabStripViewController<VLCLabelCell> {
  36. var services: Services
  37. weak var mediaDelegate: VLCMediaViewControllerDelegate?
  38. private var rendererButton: UIButton
  39. init(services: Services) {
  40. self.services = services
  41. rendererButton = services.rendererDiscovererManager.setupRendererButton()
  42. super.init(nibName: nil, bundle: nil)
  43. }
  44. override func viewDidLoad() {
  45. changeCurrentIndexProgressive = { (oldCell: VLCLabelCell?, newCell: VLCLabelCell?, progressPercentage: CGFloat, changeCurrentIndex: Bool, animated: Bool) in
  46. guard changeCurrentIndex == true else { return }
  47. oldCell?.iconLabel.textColor = PresentationTheme.current.colors.cellDetailTextColor
  48. newCell?.iconLabel.textColor = PresentationTheme.current.colors.orangeUI
  49. }
  50. setupNavigationBar()
  51. super.viewDidLoad()
  52. }
  53. private func setupNavigationBar() {
  54. if #available(iOS 11.0, *) {
  55. navigationController?.navigationBar.prefersLargeTitles = false
  56. }
  57. navigationItem.leftBarButtonItem = UIBarButtonItem(title: NSLocalizedString("SORT", comment: ""), style: .plain, target: self, action: #selector(sort))
  58. navigationItem.rightBarButtonItem = UIBarButtonItem(customView: rendererButton)
  59. }
  60. @objc func sort() {
  61. // This should be in a subclass
  62. let sortOptionsAlertController = UIAlertController(title: NSLocalizedString("SORT_BY", comment: ""), message: nil, preferredStyle: .actionSheet)
  63. let sortByNameAction = UIAlertAction(title: SortOption.alphabetically.localizedDescription, style: .default) { action in
  64. }
  65. let sortBySizeAction = UIAlertAction(title: SortOption.size.localizedDescription, style: .default) { action in
  66. }
  67. let sortbyDateAction = UIAlertAction(title: SortOption.insertonDate.localizedDescription, style: .default) { action in
  68. }
  69. let cancelAction = UIAlertAction(title: NSLocalizedString("CANCEL", comment: ""), style: .cancel, handler: nil)
  70. sortOptionsAlertController.addAction(sortByNameAction)
  71. sortOptionsAlertController.addAction(sortbyDateAction)
  72. sortOptionsAlertController.addAction(sortBySizeAction)
  73. sortOptionsAlertController.addAction(cancelAction)
  74. sortOptionsAlertController.view.tintColor = UIColor.vlcOrangeTint()
  75. present(sortOptionsAlertController, animated: true)
  76. }
  77. // MARK: - PagerTabStripDataSource
  78. override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
  79. fatalError("this should only be used as subclass")
  80. }
  81. override func configure(cell: VLCLabelCell, for indicatorInfo: IndicatorInfo) {
  82. cell.iconLabel.text = indicatorInfo.title
  83. }
  84. override func updateIndicator(for viewController: PagerTabStripViewController, fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool) {
  85. super.updateIndicator(for: viewController, fromIndex: fromIndex, toIndex: toIndex, withProgressPercentage: progressPercentage, indexWasChanged: indexWasChanged)
  86. }
  87. override var preferredStatusBarStyle: UIStatusBarStyle {
  88. return PresentationTheme.current.colors.statusBarStyle
  89. }
  90. }