1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- /*****************************************************************************
- * MediaViewController.swift
- * VLC for iOS
- *****************************************************************************
- * Copyright (c) 2018 VideoLAN. All rights reserved.
- * $Id$
- *
- * Authors: Carola Nitz <caro # videolan.org>
- *
- * Refer to the COPYING file of the official project for license.
- *****************************************************************************/
- import UIKit
- class VLCMediaViewController: VLCPagingViewController<VLCLabelCell> {
- var services: Services
- private var rendererButton: UIButton
- init(services: Services) {
- self.services = services
- rendererButton = services.rendererDiscovererManager.setupRendererButton()
- super.init(nibName: nil, bundle: nil)
- }
- override func viewDidLoad() {
- changeCurrentIndexProgressive = { (oldCell: VLCLabelCell?, newCell: VLCLabelCell?, progressPercentage: CGFloat, changeCurrentIndex: Bool, animated: Bool) in
- guard changeCurrentIndex == true else { return }
- oldCell?.iconLabel.textColor = PresentationTheme.current.colors.cellDetailTextColor
- newCell?.iconLabel.textColor = PresentationTheme.current.colors.orangeUI
- }
- setupNavigationBar()
- super.viewDidLoad()
- }
- private func setupNavigationBar() {
- if #available(iOS 11.0, *) {
- navigationController?.navigationBar.prefersLargeTitles = false
- }
- navigationItem.leftBarButtonItem = UIBarButtonItem(title: NSLocalizedString("SORT", comment: ""), style: .plain, target: self, action: #selector(sort))
- navigationItem.rightBarButtonItem = UIBarButtonItem(customView: rendererButton)
- }
- @objc func sort() {
- // This should be in a subclass
- let sortOptionsAlertController = UIAlertController(title: NSLocalizedString("SORT_BY", comment: ""), message: nil, preferredStyle: .actionSheet)
- let sortByNameAction = UIAlertAction(title: SortOption.alphabetically.localizedDescription, style: .default) {
- [weak self] action in
- // call medialibrary
- if let index = self?.currentIndex {
- let currentViewController = self?.viewControllers[index] as? VLCMediaCategoryViewController
- currentViewController?.sortByFileName()
- }
- }
- let sortBySizeAction = UIAlertAction(title: SortOption.size.localizedDescription, style: .default) {
- [weak self] action in
- if let index = self?.currentIndex {
- let currentViewController = self?.viewControllers[index] as? VLCMediaCategoryViewController
- currentViewController?.sortBySize()
- }
- }
- let sortbyDateAction = UIAlertAction(title: SortOption.insertonDate.localizedDescription, style: .default) {
- [weak self] action in
- if let index = self?.currentIndex {
- let currentViewController = self?.viewControllers[index] as? VLCMediaCategoryViewController
- currentViewController?.sortByDate()
- }
- }
- let cancelAction = UIAlertAction(title: NSLocalizedString("CANCEL", comment: ""), style: .cancel, handler: nil)
- sortOptionsAlertController.addAction(sortByNameAction)
- sortOptionsAlertController.addAction(sortbyDateAction)
- sortOptionsAlertController.addAction(sortBySizeAction)
- sortOptionsAlertController.addAction(cancelAction)
- sortOptionsAlertController.view.tintColor = UIColor.vlcOrangeTint()
- sortOptionsAlertController.popoverPresentationController?.sourceView = self.view
- present(sortOptionsAlertController, animated: true)
- }
- // MARK: - PagerTabStripDataSource
- override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
- fatalError("this should only be used as subclass")
- }
- override func configure(cell: VLCLabelCell, for indicatorInfo: IndicatorInfo) {
- cell.iconLabel.text = indicatorInfo.title
- }
- override func updateIndicator(for viewController: PagerTabStripViewController, fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool) {
- super.updateIndicator(for: viewController, fromIndex: fromIndex, toIndex: toIndex, withProgressPercentage: progressPercentage, indexWasChanged: indexWasChanged)
- }
- override var preferredStatusBarStyle: UIStatusBarStyle {
- return PresentationTheme.current.colors.statusBarStyle
- }
- }
|