MediaViewController.swift 3.7 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. var subcategories: VLCMediaSubcategories
  17. init(services: Services) {
  18. self.services = services
  19. rendererButton = services.rendererDiscovererManager.setupRendererButton()
  20. subcategories = VLCMediaSubcategories()
  21. super.init(nibName: nil, bundle: nil)
  22. }
  23. override func viewDidLoad() {
  24. changeCurrentIndexProgressive = { (oldCell: VLCLabelCell?, newCell: VLCLabelCell?, progressPercentage: CGFloat, changeCurrentIndex: Bool, animated: Bool) in
  25. guard changeCurrentIndex == true else { return }
  26. oldCell?.iconLabel.textColor = PresentationTheme.current.colors.cellDetailTextColor
  27. newCell?.iconLabel.textColor = PresentationTheme.current.colors.orangeUI
  28. }
  29. setupNavigationBar()
  30. super.viewDidLoad()
  31. }
  32. private func setupNavigationBar() {
  33. if #available(iOS 11.0, *) {
  34. navigationController?.navigationBar.prefersLargeTitles = false
  35. }
  36. navigationItem.leftBarButtonItem = UIBarButtonItem(title: NSLocalizedString("SORT", comment: ""), style: .plain, target: self, action: #selector(sort))
  37. navigationItem.rightBarButtonItem = UIBarButtonItem(customView: rendererButton)
  38. }
  39. @objc func sort() {
  40. // This should be in a subclass
  41. let sortOptionsAlertController = UIAlertController(title: NSLocalizedString("SORT_BY", comment: ""), message: nil, preferredStyle: .actionSheet)
  42. let sortByNameAction = UIAlertAction(title: SortOption.alphabetically.localizedDescription, style: .default) { action in
  43. }
  44. let sortBySizeAction = UIAlertAction(title: SortOption.size.localizedDescription, style: .default) { action in
  45. }
  46. let sortbyDateAction = UIAlertAction(title: SortOption.insertonDate.localizedDescription, style: .default) { action in
  47. }
  48. let cancelAction = UIAlertAction(title: NSLocalizedString("CANCEL", comment: ""), style: .cancel, handler: nil)
  49. sortOptionsAlertController.addAction(sortByNameAction)
  50. sortOptionsAlertController.addAction(sortbyDateAction)
  51. sortOptionsAlertController.addAction(sortBySizeAction)
  52. sortOptionsAlertController.addAction(cancelAction)
  53. sortOptionsAlertController.view.tintColor = UIColor.vlcOrangeTint()
  54. present(sortOptionsAlertController, animated: true)
  55. }
  56. // MARK: - PagerTabStripDataSource
  57. override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
  58. fatalError("this should only be used as subclass")
  59. }
  60. override func configure(cell: VLCLabelCell, for indicatorInfo: IndicatorInfo) {
  61. cell.iconLabel.text = indicatorInfo.title
  62. }
  63. override func updateIndicator(for viewController: PagerTabStripViewController, fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool) {
  64. super.updateIndicator(for: viewController, fromIndex: fromIndex, toIndex: toIndex, withProgressPercentage: progressPercentage, indexWasChanged: indexWasChanged)
  65. }
  66. override var preferredStatusBarStyle: UIStatusBarStyle {
  67. return PresentationTheme.current.colors.statusBarStyle
  68. }
  69. }