Commit de719a59 authored by Edgar Fouillet's avatar Edgar Fouillet

MediaCategoryViewController: Add contextual quick actions

Closes #754
parent ffdbde14
/*****************************************************************************
* CollectionViewCellPreviewController.swift
*
* Copyright © 2019 VLC authors and VideoLAN
*
* Authors: Edgar Fouillet <vlc # edgar.fouillet.eu>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
class CollectionViewCellPreviewController: UIViewController {
var thumbnailView = UIImageView()
override func loadView() {
view = thumbnailView
}
init(thumbnail: UIImage) {
super.init(nibName: nil, bundle: nil)
thumbnailView.clipsToBounds = true
thumbnailView.contentMode = .scaleAspectFill
thumbnailView.image = thumbnail
let ratio = thumbnail.size.height / thumbnail.size.width
let width = UIApplication.shared.keyWindow?.frame.width ?? 0
let height = ratio * width
preferredContentSize = CGSize(width: width, height: height)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
......@@ -41,6 +41,17 @@ class EditButton {
generatedButton.accessibilityHint = accessibilityHint
return generatedButton
}
@available(iOS 13.0, *)
func action(_ handler: @escaping (UIAction) -> Void) -> UIAction {
let generatedAction = UIAction(title: title,
image: UIImage(named: image),
identifier: UIAction.Identifier(rawValue: image),
handler: handler)
generatedAction.accessibilityLabel = accessibilityLabel
generatedAction.accessibilityHint = accessibilityHint
return generatedAction
}
}
class EditButtonsFactory {
......
......@@ -357,6 +357,78 @@ class MediaCategoryViewController: UICollectionViewController, UISearchBarDelega
}
}
func objects(from modelContent: VLCMLObject) -> [VLCMLObject] {
if let media = modelContent as? VLCMLMedia {
return [media]
} else if let mediaCollection = modelContent as? MediaCollectionModel {
return mediaCollection.files() ?? [VLCMLObject]()
}
return [VLCMLObject]()
}
@available(iOS 13.0, *)
override func collectionView(_ collectionView: UICollectionView,
contextMenuConfigurationForItemAt indexPath: IndexPath,
point: CGPoint) -> UIContextMenuConfiguration? {
let cell = collectionView.cellForItem(at: indexPath)
var thumbnail: UIImage? = nil
if let cell = cell as? MovieCollectionViewCell {
thumbnail = cell.thumbnailView.image
} else if let cell = cell as? MediaCollectionViewCell {
thumbnail = cell.thumbnailView.image
}
let configuration = UIContextMenuConfiguration(identifier: nil, previewProvider: {
if let thumbnail = thumbnail {
return CollectionViewCellPreviewController(thumbnail: thumbnail)
} else {
return nil
}
}) {
[weak self] action in
let modelContent = self?.isSearching ?? false ? self?.searchDataSource.objectAtIndex(index: indexPath.row) : self?.model.anyfiles[indexPath.row]
let actionList = EditButtonsFactory.buttonList(for: self?.model.anyfiles.first)
let actions = EditButtonsFactory.generate(buttons: actionList)
return UIMenu(title: "", image: nil, identifier: nil, children: actions.map {
switch $0.identifier {
case .addToPlaylist:
return $0.action({
[weak self] _ in
if let modelContent = modelContent {
self?.editController.editActions.objects = self?.objects(from: modelContent) ?? []
self?.editController.editActions.addToPlaylist()
}
})
case .rename:
return $0.action({
[weak self] _ in
if let modelContent = modelContent {
self?.editController.editActions.objects = [modelContent]
self?.editController.editActions.rename()
}
})
case .delete:
return $0.action({
[weak self] _ in
if let modelContent = modelContent {
self?.editController.editActions.objects = [modelContent]
self?.editController.editActions.delete()
}
})
case .share:
return $0.action({
[weak self] _ in
if let modelContent = modelContent {
self?.editController.editActions.objects = self?.objects(from: modelContent) ?? []
self?.editController.editActions.share()
}
})
}
})
}
return configuration
}
func createSpotlightItem(media: VLCMLMedia) {
if KeychainCoordinator.passcodeLockEnabled {
return
......
......@@ -14,7 +14,7 @@ import Foundation
class MediaCollectionViewCell: BaseCollectionViewCell {
@IBOutlet private weak var thumbnailView: UIImageView!
@IBOutlet weak var thumbnailView: UIImageView!
@IBOutlet private weak var titleLabel: UILabel!
@IBOutlet private weak var descriptionLabel: UILabel!
@IBOutlet private weak var newLabel: UILabel!
......
......@@ -89,6 +89,7 @@
6D4756B123607D4A005F670E /* EditActions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D4756B023607D49005F670E /* EditActions.swift */; };
6D8E642A234CBF2200EBC8FC /* AudioCollectionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D8E6429234CBF2200EBC8FC /* AudioCollectionModel.swift */; };
6DBCE3CD2368811000BCA7D5 /* EditButtons.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DBCE3CC2368811000BCA7D5 /* EditButtons.swift */; };
6DBCE3CB23684EF500BCA7D5 /* CollectionViewCellPreviewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DBCE3CA23684EF500BCA7D5 /* CollectionViewCellPreviewController.swift */; };
7AC8629D1765DC560011611A /* style.css in Resources */ = {isa = PBXBuildFile; fileRef = 7AC8629B1765DC560011611A /* style.css */; };
7AC862A61765E9510011611A /* jquery-1.10.1.min.js in Resources */ = {isa = PBXBuildFile; fileRef = 7AC8629E1765E90C0011611A /* jquery-1.10.1.min.js */; };
7AC862A71765E9510011611A /* jquery.fileupload.js in Resources */ = {isa = PBXBuildFile; fileRef = 7AC8629F1765E90C0011611A /* jquery.fileupload.js */; };
......@@ -571,6 +572,7 @@
6D4756B023607D49005F670E /* EditActions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = EditActions.swift; path = Sources/EditActions.swift; sourceTree = "<group>"; };
6D8E6429234CBF2200EBC8FC /* AudioCollectionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioCollectionModel.swift; sourceTree = "<group>"; };
6DBCE3CC2368811000BCA7D5 /* EditButtons.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = EditButtons.swift; path = Sources/EditButtons.swift; sourceTree = "<group>"; };
6DBCE3CA23684EF500BCA7D5 /* CollectionViewCellPreviewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = CollectionViewCellPreviewController.swift; path = Sources/CollectionViewCellPreviewController.swift; sourceTree = "<group>"; };
703A80CCC005093CCDFBECBF /* Pods-VLC-iOS-Screenshots.distribution.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-VLC-iOS-Screenshots.distribution.xcconfig"; path = "Pods/Target Support Files/Pods-VLC-iOS-Screenshots/Pods-VLC-iOS-Screenshots.distribution.xcconfig"; sourceTree = "<group>"; };
7AC8629B1765DC560011611A /* style.css */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.css; path = style.css; sourceTree = "<group>"; };
7AC8629E1765E90C0011611A /* jquery-1.10.1.min.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = "jquery-1.10.1.min.js"; sourceTree = "<group>"; };
......@@ -1318,6 +1320,7 @@
8DF966B021188BDB00D0FCD6 /* EditController.swift */,
8D2AD4D722786F4000393833 /* AddToPlaylistViewController.swift */,
E03DECA522BEE27E00F44A05 /* MediaNavigationBar.swift */,
6DBCE3CA23684EF500BCA7D5 /* CollectionViewCellPreviewController.swift */,
);
name = "UI Elements";
sourceTree = "<group>";
......@@ -3071,6 +3074,7 @@
7D3784E9183A9A15009EE944 /* main.m in Sources */,
E03DECA622BEE27E00F44A05 /* MediaNavigationBar.swift in Sources */,
7D30F3C2183AB24C00FFC021 /* VLCHTTPConnection.m in Sources */,
6DBCE3CB23684EF500BCA7D5 /* CollectionViewCellPreviewController.swift in Sources */,
4129CF2F22D5E498005EF5E8 /* AppUtitlity.swift in Sources */,
DD3EFF371BDEBCE500B68579 /* VLCLocalNetworkServiceNetService.m in Sources */,
DD3EFF511BDEBCE500B68579 /* VLCPlexWebAPI.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