MediaSubcategoryViewController.swift 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 = self.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 = self.mediaDelegate }
  32. return viewControllers
  33. }
  34. }
  35. class VLCMediaSubcategoryViewController: BaseButtonBarPagerTabStripViewController<VLCLabelCell> {
  36. internal var services: Services
  37. public weak var mediaDelegate: VLCMediaViewControllerDelegate?
  38. init(services: Services) {
  39. self.services = services
  40. super.init(nibName: nil, bundle: nil)
  41. }
  42. override func viewDidLoad() {
  43. changeCurrentIndexProgressive = { (oldCell: VLCLabelCell?, newCell: VLCLabelCell?, progressPercentage: CGFloat, changeCurrentIndex: Bool, animated: Bool) in
  44. guard changeCurrentIndex == true else { return }
  45. oldCell?.iconLabel.textColor = PresentationTheme.current.colors.cellDetailTextColor
  46. newCell?.iconLabel.textColor = PresentationTheme.current.colors.orangeUI
  47. }
  48. if #available(iOS 11.0, *) {
  49. navigationController?.navigationBar.prefersLargeTitles = false
  50. }
  51. super.viewDidLoad()
  52. }
  53. // MARK: - PagerTabStripDataSource
  54. override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
  55. fatalError("this should only be used as subclass")
  56. }
  57. override func configure(cell: VLCLabelCell, for indicatorInfo: IndicatorInfo) {
  58. cell.iconLabel.text = indicatorInfo.title
  59. }
  60. override func updateIndicator(for viewController: PagerTabStripViewController, fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool) {
  61. super.updateIndicator(for: viewController, fromIndex: fromIndex, toIndex: toIndex, withProgressPercentage: progressPercentage, indexWasChanged: indexWasChanged)
  62. if indexWasChanged && toIndex >= 0 && toIndex < viewControllers.count {
  63. let child = viewControllers[toIndex] as! IndicatorInfoProvider
  64. UIView.performWithoutAnimation({ [weak self] in
  65. guard let me = self else { return }
  66. me.navigationItem.leftBarButtonItem?.title = child.indicatorInfo(for: me).title
  67. })
  68. }
  69. }
  70. }