MediaSubcategoryViewController.swift 4.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. {
  15. override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
  16. let movies = VLCMediaViewController(services: services, type: VLCMediaType(category: .video, subcategory: .allVideos))
  17. let episodes = VLCMediaViewController(services: services, type: VLCMediaType(category: .video, subcategory: .episodes))
  18. let playlists = VLCMediaViewController(services: services, type: VLCMediaType(category: .video, subcategory: .videoPlaylists))
  19. return [movies, episodes, playlists]
  20. }
  21. }
  22. class VLCAudioSubcategoryViewController: VLCMediaSubcategoryViewController
  23. {
  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. return [tracks, genres, artists, albums, playlists]
  31. }
  32. }
  33. class VLCMediaSubcategoryViewController: BaseButtonBarPagerTabStripViewController<IconLabelCell> {
  34. internal var services: Services
  35. init(services: Services) {
  36. self.services = services
  37. super.init(nibName: nil, bundle: nil)
  38. buttonBarItemSpec = ButtonBarItemSpec.nibFile(nibName: "IconLabelCell", bundle: Bundle.main, width: { _ in
  39. return 70.0
  40. })
  41. }
  42. required public init?(coder aDecoder: NSCoder) {
  43. fatalError("init(coder:) has not been implemented")
  44. }
  45. override func viewDidLoad() {
  46. // change selected bar color
  47. settings.style.buttonBarBackgroundColor = .white
  48. settings.style.selectedBarBackgroundColor = PresentationTheme.current.colors.orangeUI
  49. settings.style.selectedBarHeight = 4.0
  50. settings.style.buttonBarItemTitleColor = .black
  51. settings.style.buttonBarItemsShouldFillAvailableWidth = true
  52. changeCurrentIndexProgressive = { (oldCell: IconLabelCell?, newCell: IconLabelCell?, progressPercentage: CGFloat, changeCurrentIndex: Bool, animated: Bool) in
  53. guard changeCurrentIndex == true else { return }
  54. oldCell?.iconImage.tintColor = PresentationTheme.current.colors.cellDetailTextColor
  55. oldCell?.iconLabel.textColor = PresentationTheme.current.colors.cellDetailTextColor
  56. newCell?.iconImage.tintColor = PresentationTheme.current.colors.orangeUI
  57. newCell?.iconLabel.textColor = PresentationTheme.current.colors.orangeUI
  58. }
  59. if #available(iOS 11.0, *) {
  60. navigationController?.navigationBar.prefersLargeTitles = false
  61. }
  62. super.viewDidLoad()
  63. }
  64. // MARK: - PagerTabStripDataSource
  65. override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
  66. fatalError("this should only be used as subclass")
  67. }
  68. override func configure(cell: IconLabelCell, for indicatorInfo: IndicatorInfo) {
  69. cell.iconImage.image = indicatorInfo.image?.withRenderingMode(.alwaysTemplate)
  70. cell.iconLabel.text = indicatorInfo.title?.trimmingCharacters(in: .whitespacesAndNewlines)
  71. }
  72. override func updateIndicator(for viewController: PagerTabStripViewController, fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool) {
  73. super.updateIndicator(for: viewController, fromIndex: fromIndex, toIndex: toIndex, withProgressPercentage: progressPercentage, indexWasChanged: indexWasChanged)
  74. if indexWasChanged && toIndex >= 0 && toIndex < viewControllers.count {
  75. let child = viewControllers[toIndex] as! IndicatorInfoProvider
  76. UIView.performWithoutAnimation({ [weak self] in
  77. guard let me = self else { return }
  78. me.navigationItem.leftBarButtonItem?.title = child.indicatorInfo(for: me).title
  79. })
  80. }
  81. }
  82. }