MediaViewController.swift 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 VLCMediaViewController: VLCPagingViewController<VLCLabelCell> {
  14. var services: Services
  15. private var rendererButton: UIButton
  16. private var sortButton: UIBarButtonItem?
  17. init(services: Services) {
  18. self.services = services
  19. rendererButton = services.rendererDiscovererManager.setupRendererButton()
  20. super.init(nibName: nil, bundle: nil)
  21. }
  22. override func viewDidLoad() {
  23. changeCurrentIndexProgressive = { (oldCell: VLCLabelCell?, newCell: VLCLabelCell?, progressPercentage: CGFloat, changeCurrentIndex: Bool, animated: Bool) in
  24. guard changeCurrentIndex == true else { return }
  25. oldCell?.iconLabel.textColor = PresentationTheme.current.colors.cellDetailTextColor
  26. newCell?.iconLabel.textColor = PresentationTheme.current.colors.orangeUI
  27. }
  28. setupNavigationBar()
  29. super.viewDidLoad()
  30. }
  31. private func setupNavigationBar() {
  32. if #available(iOS 11.0, *) {
  33. navigationController?.navigationBar.prefersLargeTitles = false
  34. }
  35. navigationController?.navigationBar.isTranslucent = false
  36. navigationItem.rightBarButtonItems = [editButtonItem, UIBarButtonItem(customView: rendererButton)]
  37. sortButton = UIBarButtonItem(title: NSLocalizedString("SORT", comment: ""),
  38. style: .plain,
  39. target: self,
  40. action: #selector(handleSort))
  41. navigationItem.leftBarButtonItem = sortButton
  42. }
  43. // MARK: - PagerTabStripDataSource
  44. override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
  45. fatalError("this should only be used as subclass")
  46. }
  47. override func configure(cell: VLCLabelCell, for indicatorInfo: IndicatorInfo) {
  48. cell.iconLabel.text = indicatorInfo.title
  49. }
  50. override func updateIndicator(for viewController: PagerTabStripViewController, fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool) {
  51. super.updateIndicator(for: viewController, fromIndex: fromIndex, toIndex: toIndex, withProgressPercentage: progressPercentage, indexWasChanged: indexWasChanged)
  52. }
  53. override var preferredStatusBarStyle: UIStatusBarStyle {
  54. return PresentationTheme.current.colors.statusBarStyle
  55. }
  56. override func setEditing(_ editing: Bool, animated: Bool) {
  57. super.setEditing(editing, animated: animated)
  58. scrollingEnabled(!editing)
  59. navigationItem.leftBarButtonItem = editing ? nil : sortButton
  60. viewControllers[currentIndex].setEditing(editing, animated: animated)
  61. }
  62. @objc func handleSort() {
  63. if let mediaCategoryViewController = viewControllers[currentIndex] as? VLCMediaCategoryViewController {
  64. mediaCategoryViewController.handleSort()
  65. }
  66. }
  67. }