Add context menu actions to item list
This commit is contained in:
parent
b2b99c6a11
commit
b2a8174099
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
import CoreData
|
import CoreData
|
||||||
|
import SafariServices
|
||||||
|
|
||||||
class ItemsViewController: UIViewController {
|
class ItemsViewController: UIViewController {
|
||||||
|
|
||||||
|
@ -88,7 +89,29 @@ extension ItemsViewController: UICollectionViewDelegate {
|
||||||
}
|
}
|
||||||
return UIContextMenuConfiguration(identifier: nil, previewProvider: {
|
return UIContextMenuConfiguration(identifier: nil, previewProvider: {
|
||||||
ReadViewController(item: item, fervorController: self.fervorController)
|
ReadViewController(item: item, fervorController: self.fervorController)
|
||||||
}, actionProvider: nil)
|
}, actionProvider: { _ in
|
||||||
|
var children: [UIAction] = []
|
||||||
|
if let url = item.url {
|
||||||
|
children.append(UIAction(title: "Open in Safari", image: UIImage(systemName: "safari"), handler: { [weak self] _ in
|
||||||
|
let vc = SFSafariViewController(url: url)
|
||||||
|
vc.preferredControlTintColor = .appTintColor
|
||||||
|
self?.present(vc, animated: true)
|
||||||
|
}))
|
||||||
|
children.append(UIAction(title: "Share", image: UIImage(systemName: "square.and.arrow.up"), handler: { [weak self] _ in
|
||||||
|
self?.present(UIActivityViewController(activityItems: [url], applicationActivities: nil), animated: true)
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
if item.read {
|
||||||
|
children.append(UIAction(title: "Mark as Unread", image: UIImage(systemName: "checkmark.circle"), handler: { _ in
|
||||||
|
item.read = false
|
||||||
|
}))
|
||||||
|
} else {
|
||||||
|
children.append(UIAction(title: "Mark as Read", image: UIImage(systemName: "checkmark.circle.fill"), handler: { _ in
|
||||||
|
item.read = true
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
return UIMenu(children: children)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func collectionView(_ collectionView: UICollectionView, willPerformPreviewActionForMenuWith configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionCommitAnimating) {
|
func collectionView(_ collectionView: UICollectionView, willPerformPreviewActionForMenuWith configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionCommitAnimating) {
|
||||||
|
|
|
@ -149,7 +149,8 @@ extension ReadViewController: WKUIDelegate {
|
||||||
} actionProvider: { _ in
|
} actionProvider: { _ in
|
||||||
return UIMenu(children: [
|
return UIMenu(children: [
|
||||||
UIAction(title: "Open in Safari", image: UIImage(systemName: "safari"), handler: { [weak self] _ in
|
UIAction(title: "Open in Safari", image: UIImage(systemName: "safari"), handler: { [weak self] _ in
|
||||||
self?.present(SFSafariViewController(url: url), animated: true)
|
guard let self = self else { return }
|
||||||
|
self.present(self.createSafariVC(url: url), animated: true)
|
||||||
}),
|
}),
|
||||||
UIAction(title: "Share", image: UIImage(systemName: "square.and.arrow.up"), handler: { [weak self] _ in
|
UIAction(title: "Share", image: UIImage(systemName: "square.and.arrow.up"), handler: { [weak self] _ in
|
||||||
self?.present(UIActivityViewController(activityItems: [url], applicationActivities: nil), animated: true)
|
self?.present(UIActivityViewController(activityItems: [url], applicationActivities: nil), animated: true)
|
||||||
|
|
Loading…
Reference in New Issue