MediaViewController.swift 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. navigationItem.leftBarButtonItem = UIBarButtonItem(title: NSLocalizedString("SORT", comment: ""),
  38. style: .plain,
  39. target: self,
  40. action: #selector(handleSort))
  41. }
  42. // MARK: - PagerTabStripDataSource
  43. override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
  44. fatalError("this should only be used as subclass")
  45. }
  46. override func configure(cell: VLCLabelCell, for indicatorInfo: IndicatorInfo) {
  47. cell.iconLabel.text = indicatorInfo.title
  48. }
  49. override func updateIndicator(for viewController: PagerTabStripViewController, fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool) {
  50. super.updateIndicator(for: viewController, fromIndex: fromIndex, toIndex: toIndex, withProgressPercentage: progressPercentage, indexWasChanged: indexWasChanged)
  51. }
  52. override var preferredStatusBarStyle: UIStatusBarStyle {
  53. return PresentationTheme.current.colors.statusBarStyle
  54. }
  55. override func setEditing(_ editing: Bool, animated: Bool) {
  56. super.setEditing(editing, animated: animated)
  57. scrollingEnabled(!editing)
  58. navigationItem.leftBarButtonItem = editing ? nil : sortButton
  59. viewControllers[currentIndex].setEditing(editing, animated: animated)
  60. }
  61. // Hack to send to the child vc the sort event
  62. override func handleSort() {
  63. viewControllers[currentIndex].handleSort()
  64. }
  65. }
  66. extension UIViewController {
  67. @objc func handleSort() {}
  68. }