Commit a5914f2b authored by Soomin Lee's avatar Soomin Lee

Sort foundation

parent 3aeed3cc
......@@ -25,6 +25,7 @@ protocol MediaLibraryBaseModel {
func append(_ item: VLCMLObject)
func isIncluded(_ item: VLCMLObject)
func sort(by criteria: VLCMLSortingCriteria)
}
protocol MLBaseModel: MediaLibraryBaseModel {
......@@ -40,6 +41,7 @@ protocol MLBaseModel: MediaLibraryBaseModel {
func append(_ item: MLType)
func isIncluded(_ item: MLType)
func sort(by criteria: VLCMLSortingCriteria)
}
extension MLBaseModel {
......@@ -54,4 +56,8 @@ extension MLBaseModel {
func isIncluded(_ item: VLCMLObject) {
fatalError()
}
func sort(by criteria: VLCMLSortingCriteria) {
fatalError()
}
}
......@@ -212,6 +212,23 @@ class VLCMediaCategoryViewController: UICollectionViewController, UICollectionVi
}
}
// MARK: - Sort
extension VLCMediaCategoryViewController {
// FIXME: Need to add a button for ascending/descending result
func sortByFileName() {
category.sort(by: .filename)
}
func sortByDate() {
category.sort(by: .insertionDate)
}
func sortBySize() {
category.sort(by: .fileSize)
}
}
// MARK: - Player
extension VLCMediaCategoryViewController {
......
......@@ -44,11 +44,28 @@ class VLCMediaViewController: VLCPagingViewController<VLCLabelCell> {
@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) { action in
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) { action in
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) { action in
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)
......
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