Use same nav delegate more options for context menu share sheet

This commit is contained in:
Shadowfacts 2019-12-14 13:36:05 -05:00
parent 4c0607af79
commit 05d79d5d03
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
10 changed files with 57 additions and 29 deletions

View File

@ -80,6 +80,7 @@
D627943523A5525100D38C68 /* StatusActivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = D627943423A5525100D38C68 /* StatusActivity.swift */; };
D627943723A552C200D38C68 /* BookmarkStatusActivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = D627943623A552C200D38C68 /* BookmarkStatusActivity.swift */; };
D627943923A553B600D38C68 /* UnbookmarkStatusActivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = D627943823A553B600D38C68 /* UnbookmarkStatusActivity.swift */; };
D627943B23A55BA600D38C68 /* NavigableTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D627943A23A55BA600D38C68 /* NavigableTableViewCell.swift */; };
D627FF76217E923E00CC0648 /* DraftsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = D627FF75217E923E00CC0648 /* DraftsManager.swift */; };
D627FF79217E950100CC0648 /* DraftsTableViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = D627FF78217E950100CC0648 /* DraftsTableViewController.xib */; };
D627FF7B217E951500CC0648 /* DraftsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D627FF7A217E951500CC0648 /* DraftsTableViewController.swift */; };
@ -347,6 +348,7 @@
D627943423A5525100D38C68 /* StatusActivity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusActivity.swift; sourceTree = "<group>"; };
D627943623A552C200D38C68 /* BookmarkStatusActivity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarkStatusActivity.swift; sourceTree = "<group>"; };
D627943823A553B600D38C68 /* UnbookmarkStatusActivity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnbookmarkStatusActivity.swift; sourceTree = "<group>"; };
D627943A23A55BA600D38C68 /* NavigableTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigableTableViewCell.swift; sourceTree = "<group>"; };
D627FF75217E923E00CC0648 /* DraftsManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DraftsManager.swift; sourceTree = "<group>"; };
D627FF78217E950100CC0648 /* DraftsTableViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = DraftsTableViewController.xib; sourceTree = "<group>"; };
D627FF7A217E951500CC0648 /* DraftsTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DraftsTableViewController.swift; sourceTree = "<group>"; };
@ -1093,6 +1095,7 @@
D6C693F82162E4DB007D6A6D /* StatusContentLabel.swift */,
D641C77E213DC78A004B4513 /* InlineTextAttachment.swift */,
04ED00B021481ED800567C53 /* SteppedProgressView.swift */,
D627943A23A55BA600D38C68 /* NavigableTableViewCell.swift */,
D627943123A5466600D38C68 /* SelectableTableViewCell.swift */,
D67C57A721E2649B00C3118B /* Account Detail */,
D67C57B021E28F9400C3118B /* Compose Status Reply */,
@ -1639,6 +1642,7 @@
D6C94D872139E62700CB5196 /* LargeImageViewController.swift in Sources */,
D6434EB3215B1856001A919A /* XCBRequest.swift in Sources */,
D663626221360B1900C9CBA2 /* Preferences.swift in Sources */,
D627943B23A55BA600D38C68 /* NavigableTableViewCell.swift in Sources */,
D6333B792139AEFD00CE884A /* Date+TimeAgo.swift in Sources */,
D641C77F213DC78A004B4513 /* InlineTextAttachment.swift in Sources */,
D627943523A5525100D38C68 /* StatusActivity.swift in Sources */,

View File

@ -247,17 +247,10 @@ extension ProfileTableViewController: ProfileHeaderTableViewCellDelegate {
MastodonCache.relationship(for: account.id) { [weak self] (relationship) in
guard let self = self else { return }
let customActivities: [UIActivity]
var customActivities: [UIActivity] = [OpenInSafariActivity()]
if let relationship = relationship {
let toggleFollowActivity = relationship.following ? UnfollowAccountActivity() : FollowAccountActivity()
customActivities = [
toggleFollowActivity,
OpenInSafariActivity()
]
} else {
customActivities = [
OpenInSafariActivity()
]
customActivities.insert(toggleFollowActivity, at: 0)
}
DispatchQueue.main.async {

View File

@ -14,27 +14,25 @@ protocol MenuPreviewProvider {
typealias PreviewProviders = (content: UIContextMenuContentPreviewProvider, actions: () -> [UIAction])
var navigationDelegate: TuskerNavigationDelegate? { get }
func getPreviewProviders(for location: CGPoint, sourceViewController: UIViewController) -> PreviewProviders?
}
extension MenuPreviewProvider {
fileprivate func present(_ vc: UIViewController) {
UIApplication.shared.keyWindow!.rootViewController!.present(vc, animated: true)
}
func actionsForProfile(accountID: String) -> [UIAction] {
guard let account = MastodonCache.account(for: accountID) else { return [] }
return [
createAction(identifier: "openinsafari", title: "Open in Safari", systemImageName: "safari", handler: { (_) in
self.present(SFSafariViewController(url: account.url))
self.navigationDelegate?.selected(url: account.url)
}),
createAction(identifier: "sendmessage", title: "Send Message", systemImageName: "envelope", handler: { (_) in
self.present(UINavigationController(rootViewController: ComposeViewController(mentioningAcct: account.acct)))
self.navigationDelegate?.compose(mentioning: account.acct)
}),
createAction(identifier: "share", title: "Share...", systemImageName: "square.and.arrow.up", handler: { (_) in
self.present(UIActivityViewController(activityItems: [account.url], applicationActivities: nil))
self.navigationDelegate?.showMoreOptions(forAccount: accountID)
})
]
}
@ -42,10 +40,10 @@ extension MenuPreviewProvider {
func actionsForURL(_ url: URL) -> [UIAction] {
return [
createAction(identifier: "openinsafari", title: "Open in Safari", systemImageName: "safari", handler: { (_) in
self.present(SFSafariViewController(url: url))
self.navigationDelegate?.selected(url: url)
}),
createAction(identifier: "share", title: "Share...", systemImageName: "square.and.arrow.up", handler: { (_) in
self.present(UIActivityViewController(activityItems: [url], applicationActivities: nil))
self.navigationDelegate?.showMoreOptions(forURL: url)
})
]
}
@ -58,13 +56,13 @@ extension MenuPreviewProvider {
guard let status = MastodonCache.status(for: statusID) else { return [] }
return [
createAction(identifier: "reply", title: "Reply", systemImageName: "arrowshape.turn.up.left", handler: { (_) in
self.present(UINavigationController(rootViewController: ComposeViewController(inReplyTo: statusID)))
self.navigationDelegate?.reply(to: statusID)
}),
createAction(identifier: "openinsafari", title: "Open in Safari", systemImageName: "safari", handler: { (_) in
self.present(SFSafariViewController(url: status.url!))
self.navigationDelegate?.selected(url: status.url!)
}),
createAction(identifier: "share", title: "Share...", systemImageName: "square.and.arrow.up", handler: { (_) in
self.present(UIActivityViewController(activityItems: [status.url!], applicationActivities: nil))
self.navigationDelegate?.showMoreOptions(forStatus: statusID)
})
]
}

View File

@ -28,6 +28,8 @@ protocol TuskerNavigationDelegate {
func compose()
func compose(mentioning: String?)
func reply(to statusID: String)
func largeImage(_ image: UIImage, description: String?, sourceView: UIImageView) -> LargeImageViewController
@ -44,6 +46,8 @@ protocol TuskerNavigationDelegate {
func showMoreOptions(forStatus statusID: String)
func showMoreOptions(forAccount accountID: String)
func showMoreOptions(forURL url: URL)
func showFollowedByList(accountIDs: [String])
@ -112,8 +116,13 @@ extension TuskerNavigationDelegate where Self: UIViewController {
show(ConversationTableViewController(for: statusID, state: state), sender: self)
}
// protocols can't have parameter defaults, so this stub is necessary to fulfill the protocol req
func compose() {
let compose = ComposeViewController()
compose(mentioning: nil)
}
func compose(mentioning: String? = nil) {
let compose = ComposeViewController( mentioningAcct: mentioning)
let vc = UINavigationController(rootViewController: compose)
vc.presentationController?.delegate = compose
present(vc, animated: true)
@ -185,10 +194,10 @@ extension TuskerNavigationDelegate where Self: UIViewController {
private func moreOptions(forStatus statusID: String) -> UIViewController {
guard let status = MastodonCache.status(for: statusID) else { fatalError("Missing cached status \(statusID)") }
guard let url = status.url else { fatalError("Missing url for status \(statusID)") }
var customActivites = [UIActivity]()
var customActivites: [UIActivity] = [OpenInSafariActivity()]
if let bookmarked = status.bookmarked {
customActivites.append(bookmarked ? UnbookmarkStatusActivity() : BookmarkStatusActivity())
customActivites.insert(bookmarked ? UnbookmarkStatusActivity() : BookmarkStatusActivity(), at: 0)
}
let activityController = UIActivityViewController(activityItems: [url, status], applicationActivities: customActivites)
@ -196,6 +205,11 @@ extension TuskerNavigationDelegate where Self: UIViewController {
return activityController
}
private func moreOptions(forAccount accountID: String) -> UIViewController {
guard let account = MastodonCache.account(for: accountID) else { fatalError("Missing cached account \(accountID)") }
return moreOptions(forURL: account.url)
}
func showMoreOptions(forStatus statusID: String) {
present(moreOptions(forStatus: statusID), animated: true)
}
@ -204,6 +218,10 @@ extension TuskerNavigationDelegate where Self: UIViewController {
present(moreOptions(forURL: url), animated: true)
}
func showMoreOptions(forAccount accountID: String) {
present(moreOptions(forAccount: accountID), animated: true)
}
func showFollowedByList(accountIDs: [String]) {
let vc = AccountListTableViewController(accountIDs: accountIDs)
vc.title = NSLocalizedString("Followed By", comment: "followed by accounts list title")

View File

@ -65,9 +65,9 @@ extension AccountTableViewCell: SelectableTableViewCell {
}
extension AccountTableViewCell: MenuPreviewProvider {
var navigationDelegate: TuskerNavigationDelegate? { return delegate }
func getPreviewProviders(for location: CGPoint, sourceViewController: UIViewController) -> PreviewProviders? {
return (content: { ProfileTableViewController(accountID: self.accountID) }, actions: { self.actionsForProfile(accountID: self.accountID) })
}
}

View File

@ -0,0 +1,13 @@
//
// NavigableTableViewCell.swift
// Tusker
//
// Created by Shadowfacts on 12/14/19.
// Copyright © 2019 Shadowfacts. All rights reserved.
//
import Foundation
protocol NavigableTableViewCell {
var navigationDelegate: TuskerNavigationDelegate? { get }
}

View File

@ -172,6 +172,7 @@ extension ActionNotificationGroupTableViewCell: SelectableTableViewCell {
}
extension ActionNotificationGroupTableViewCell: MenuPreviewProvider {
var navigationDelegate: TuskerNavigationDelegate? { return delegate }
func getPreviewProviders(for location: CGPoint, sourceViewController: UIViewController) -> PreviewProviders? {
return (content: {
@ -191,5 +192,4 @@ extension ActionNotificationGroupTableViewCell: MenuPreviewProvider {
return []
})
}
}

View File

@ -130,6 +130,7 @@ extension FollowNotificationGroupTableViewCell: SelectableTableViewCell {
}
extension FollowNotificationGroupTableViewCell: MenuPreviewProvider {
var navigationDelegate: TuskerNavigationDelegate? { return delegate }
func getPreviewProviders(for location: CGPoint, sourceViewController: UIViewController) -> PreviewProviders? {
return (content: {
@ -143,5 +144,4 @@ extension FollowNotificationGroupTableViewCell: MenuPreviewProvider {
return []
})
}
}

View File

@ -151,6 +151,7 @@ class ProfileHeaderTableViewCell: UITableViewCell {
}
extension ProfileHeaderTableViewCell: MenuPreviewProvider {
var navigationDelegate: TuskerNavigationDelegate? { return delegate }
func getPreviewProviders(for location: CGPoint, sourceViewController: UIViewController) -> PreviewProviders? {
let noteLabelPoint = noteLabel.convert(location, from: self)
if noteLabel.bounds.contains(noteLabelPoint),

View File

@ -15,13 +15,12 @@ protocol StatusTableViewCellDelegate: TuskerNavigationDelegate {
}
class BaseStatusTableViewCell: UITableViewCell {
var delegate: StatusTableViewCellDelegate? {
didSet {
contentLabel.navigationDelegate = delegate
}
}
@IBOutlet weak var avatarImageView: UIImageView!
@IBOutlet weak var displayNameLabel: UILabel!
@IBOutlet weak var usernameLabel: UILabel!
@ -311,6 +310,8 @@ extension BaseStatusTableViewCell: AttachmentViewDelegate {
}
extension BaseStatusTableViewCell: MenuPreviewProvider {
var navigationDelegate: TuskerNavigationDelegate? { return delegate }
func getPreviewProviders(for location: CGPoint, sourceViewController: UIViewController) -> PreviewProviders? {
if avatarImageView.frame.contains(location) {
return (content: { ProfileTableViewController(accountID: self.accountID)}, actions: { self.actionsForProfile(accountID: self.accountID) })