MediaViewController.swift 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. sortButton = UIBarButtonItem(title: NSLocalizedString("SORT", comment: ""), style: .plain, target: self, action: #selector(sort))
  37. navigationItem.leftBarButtonItem = sortButton
  38. navigationItem.rightBarButtonItems = [editButtonItem, UIBarButtonItem(customView: rendererButton)]
  39. }
  40. @objc func sort() {
  41. // This should be in a subclass
  42. let sortOptionsAlertController = UIAlertController(title: NSLocalizedString("SORT_BY", comment: ""), message: nil, preferredStyle: .actionSheet)
  43. let sortByNameAction = UIAlertAction(title: SortOption.alphabetically.localizedDescription, style: .default) {
  44. [weak self] action in
  45. // call medialibrary
  46. if let index = self?.currentIndex {
  47. let currentViewController = self?.viewControllers[index] as? VLCMediaCategoryViewController
  48. currentViewController?.sortByFileName()
  49. }
  50. }
  51. let sortBySizeAction = UIAlertAction(title: SortOption.size.localizedDescription, style: .default) {
  52. [weak self] action in
  53. if let index = self?.currentIndex {
  54. let currentViewController = self?.viewControllers[index] as? VLCMediaCategoryViewController
  55. currentViewController?.sortBySize()
  56. }
  57. }
  58. let sortbyDateAction = UIAlertAction(title: SortOption.insertonDate.localizedDescription, style: .default) {
  59. [weak self] action in
  60. if let index = self?.currentIndex {
  61. let currentViewController = self?.viewControllers[index] as? VLCMediaCategoryViewController
  62. currentViewController?.sortByDate()
  63. }
  64. }
  65. let cancelAction = UIAlertAction(title: NSLocalizedString("CANCEL", comment: ""), style: .cancel, handler: nil)
  66. sortOptionsAlertController.addAction(sortByNameAction)
  67. sortOptionsAlertController.addAction(sortbyDateAction)
  68. sortOptionsAlertController.addAction(sortBySizeAction)
  69. sortOptionsAlertController.addAction(cancelAction)
  70. sortOptionsAlertController.view.tintColor = .vlcOrangeTint
  71. sortOptionsAlertController.popoverPresentationController?.sourceView = self.view
  72. present(sortOptionsAlertController, animated: true)
  73. }
  74. // MARK: - PagerTabStripDataSource
  75. override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
  76. fatalError("this should only be used as subclass")
  77. }
  78. override func configure(cell: VLCLabelCell, for indicatorInfo: IndicatorInfo) {
  79. cell.iconLabel.text = indicatorInfo.title
  80. }
  81. override func updateIndicator(for viewController: PagerTabStripViewController, fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool) {
  82. super.updateIndicator(for: viewController, fromIndex: fromIndex, toIndex: toIndex, withProgressPercentage: progressPercentage, indexWasChanged: indexWasChanged)
  83. }
  84. override var preferredStatusBarStyle: UIStatusBarStyle {
  85. return PresentationTheme.current.colors.statusBarStyle
  86. }
  87. override func setEditing(_ editing: Bool, animated: Bool) {
  88. super.setEditing(editing, animated: animated)
  89. scrollingEnabled(!editing)
  90. navigationItem.leftBarButtonItem = editing ? nil : sortButton
  91. viewControllers[currentIndex].setEditing(editing, animated: animated)
  92. }
  93. }