Commit 5fbf7911 authored by Carola Nitz's avatar Carola Nitz

add segmentedControl for sorting

parent 35b3005d
......@@ -7,3 +7,89 @@
//
import Foundation
public enum SortOption:Int {
case alphabetically
case insertonDate
case size
static let mapper: [SortOption: String] = [
.alphabetically: NSLocalizedString("Name", comment: ""),
.insertonDate: NSLocalizedString("Date", comment: ""),
.size: NSLocalizedString("Size", comment: "")
]
var string: String {
return SortOption.mapper[self]!
}
}
public protocol PresentationViewDelegate: class {
func presentationOptionsViewSelectedCreateFolder(presentationOptionsView:PresentationOptionsView)
func presentationOptionsViewSelectedTableViewPresentation(presentationOptionsView:PresentationOptionsView, showAsTableView:Bool)
func presentationOptionsViewChangeSorting(presentationOptionsView:PresentationOptionsView, to:SortOption)
}
public class PresentationOptionsView: UICollectionReusableView {
public weak var delegate:PresentationViewDelegate?
var sortOptionsControl: UISegmentedControl!
var folderButton:UIButton!
var tableViewButton:UIButton!
static let reuseIdentifier = "PresentationOptionsView"
public override init(frame: CGRect) {
super.init(frame: frame)
setupSubviews()
}
required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setupSubviews() {
let sortAlphabetically = SortOption.alphabetically.string
let sortByInsertionDate = SortOption.insertonDate.string
let sortBySize = SortOption.size.string
sortOptionsControl = UISegmentedControl(items: [sortAlphabetically, sortByInsertionDate, sortBySize])
sortOptionsControl.translatesAutoresizingMaskIntoConstraints = false
sortOptionsControl.addTarget(self, action: #selector(changeSorting), for: UIControlEvents.touchUpInside)
folderButton = UIButton(type: UIButtonType.contactAdd)
folderButton.translatesAutoresizingMaskIntoConstraints = false
folderButton.addTarget(self, action: #selector(createNewFolder), for: .touchUpInside)
tableViewButton = UIButton(type: .detailDisclosure)
tableViewButton.imageView?.image = #imageLiteral(resourceName: "tableViewIcon")
tableViewButton.translatesAutoresizingMaskIntoConstraints = false
tableViewButton.addTarget(self, action: #selector(tableViewSelected), for: .touchUpInside)
let stackview = UIStackView(arrangedSubviews: [folderButton, sortOptionsControl, tableViewButton])
stackview.translatesAutoresizingMaskIntoConstraints = false
stackview.distribution = .equalSpacing
stackview.isLayoutMarginsRelativeArrangement = true
stackview.layoutMargins = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
addSubview(stackview)
NSLayoutConstraint.activate([
sortOptionsControl.widthAnchor.constraint(equalTo: self.widthAnchor, multiplier: 0.5, constant: 0),
stackview.leftAnchor.constraint(equalTo: self.leftAnchor),
stackview.rightAnchor.constraint(equalTo: self.rightAnchor),
stackview.topAnchor.constraint(equalTo: self.topAnchor),
stackview.bottomAnchor.constraint(equalTo: self.bottomAnchor)
])
}
@objc private func createNewFolder() {
delegate?.presentationOptionsViewSelectedCreateFolder(presentationOptionsView:self)
}
@objc private func tableViewSelected() {
delegate?.presentationOptionsViewSelectedTableViewPresentation(presentationOptionsView: self, showAsTableView: tableViewButton.isSelected)
tableViewButton.isSelected = !tableViewButton.isSelected
}
@objc private func changeSorting() {
delegate?.presentationOptionsViewChangeSorting(presentationOptionsView:self, to: SortOption(rawValue: sortOptionsControl.selectedSegmentIndex)!)
}
}
......@@ -61,6 +61,7 @@ public class VLCVideoViewController: UICollectionViewController, UICollectionVie
func setupCollectionView(){
let playlistnib = UINib(nibName: "VLCPlaylistCollectionViewCell", bundle:nil)
collectionView?.register(playlistnib, forCellWithReuseIdentifier: VLCPlaylistCollectionViewCell.cellIdentifier())
collectionView?.register(PresentationOptionsView.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: PresentationOptionsView.reuseIdentifier)
collectionView?.backgroundColor = .white
collectionView?.alwaysBounceVertical = true
if #available(iOS 11.0, *) {
......@@ -146,6 +147,14 @@ public class VLCVideoViewController: UICollectionViewController, UICollectionVie
collectionView?.collectionViewLayout.invalidateLayout()
}
public override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
let presentationOptions = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionElementKindSectionHeader, withReuseIdentifier: PresentationOptionsView.reuseIdentifier, for: indexPath)
return presentationOptions
}
public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
return CGSize(width: view.bounds.size.width, height: 44.0)
}
//MARK: - Search
public func updateSearchResults(for searchController: UISearchController) {
searchDataSource.shouldReloadTable(forSearch: searchController.searchBar.text, searchableFiles: mediaDataSource.allObjects())
......
......@@ -209,6 +209,7 @@ NSString *const VLCDropboxSessionWasAuthorized = @"VLCDropboxSessionWasAuthorize
[[UINavigationBar appearance] setTitleTextAttributes: @{ NSForegroundColorAttributeName : [UIColor whiteColor] }];
// For the edit selection indicators
[[UITableView appearance] setTintColor:vlcOrange];
[[UISegmentedControl appearance] setTintColor:vlcOrange];
[[UISwitch appearance] setOnTintColor:vlcOrange];
[[UISearchBar appearance] setBarTintColor:[UIColor whiteColor]];
}
......
......@@ -17,6 +17,7 @@
26F1BFD01A770408001DF30C /* libMediaVLC.xml in Resources */ = {isa = PBXBuildFile; fileRef = 26F1BFCF1A770408001DF30C /* libMediaVLC.xml */; };
29125E5617492219003F03E5 /* index.html in Resources */ = {isa = PBXBuildFile; fileRef = 29125E5417492219003F03E5 /* index.html */; };
2915544317490D4A00B86CAD /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2915544217490D4A00B86CAD /* Security.framework */; };
410045511FD49FC900FD7EAD /* PresentationOptionsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 410045501FD49FC900FD7EAD /* PresentationOptionsView.swift */; };
4121A87F1FCDF79A0048F1ED /* VideoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4121A87E1FCDF79A0048F1ED /* VideoViewController.swift */; };
41251ED01FD0CF7900099110 /* AppCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41251ECE1FD0CF7900099110 /* AppCoordinator.swift */; };
41251ED11FD0CF7900099110 /* Coordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41251ECF1FD0CF7900099110 /* Coordinator.swift */; };
......@@ -738,6 +739,7 @@
3C12F87F27BDCE3D0A58354E /* Pods-VLC-iOS-no-watch-Debug.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-VLC-iOS-no-watch-Debug.debug.xcconfig"; path = "Pods/Target Support Files/Pods-VLC-iOS-no-watch-Debug/Pods-VLC-iOS-no-watch-Debug.debug.xcconfig"; sourceTree = "<group>"; };
3DD533B1D45EEA70099433D8 /* libPods-VLC-iOS-no-watch.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-VLC-iOS-no-watch.a"; sourceTree = BUILT_PRODUCTS_DIR; };
402E6F0E5362B530B7909338 /* libPods-VLC-iOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-VLC-iOS.a"; sourceTree = BUILT_PRODUCTS_DIR; };
410045501FD49FC900FD7EAD /* PresentationOptionsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PresentationOptionsView.swift; sourceTree = "<group>"; };
4121A87E1FCDF79A0048F1ED /* VideoViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VideoViewController.swift; sourceTree = "<group>"; };
41251ECB1FD0C5C100099110 /* VLC-iOS-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "VLC-iOS-Bridging-Header.h"; sourceTree = SOURCE_ROOT; };
41251ECE1FD0CF7900099110 /* AppCoordinator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AppCoordinator.swift; path = SharedSources/Coordinators/AppCoordinator.swift; sourceTree = SOURCE_ROOT; };
......@@ -2289,6 +2291,7 @@
7D37849D183A98DD009EE944 /* VLCThumbnailsCache.m */,
DD7110EE1AF38B2B00854776 /* MLMediaLibrary+playlist.h */,
DD7110EF1AF38B2B00854776 /* MLMediaLibrary+playlist.m */,
410045501FD49FC900FD7EAD /* PresentationOptionsView.swift */,
);
name = Library;
sourceTree = "<group>";
......@@ -3802,6 +3805,7 @@
41F9BC7C1F4F20E400268461 /* VLCTrackSelectorView.m in Sources */,
7D378499183A98D1009EE944 /* VLCPlaylistCollectionViewCell.m in Sources */,
DD8F84311B00EB3B0009138A /* VLCPlaybackController+MediaLibrary.m in Sources */,
410045511FD49FC900FD7EAD /* PresentationOptionsView.swift in Sources */,
41EB91DD1F7BFF8500821AA5 /* VLCMetadata.m in Sources */,
DD3EFF551BDEBCE500B68579 /* VLCLocalNetworkServiceBrowserDSM.m in Sources */,
7D37849A183A98D1009EE944 /* VLCPlaylistTableViewCell.m in Sources */,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment