Move StatusTableViewCellDelegate methods to TuskerNavigationDelegate

This commit is contained in:
Shadowfacts 2018-09-30 19:29:52 -04:00
parent 728a5a4ff1
commit 139a214d2f
Signed by untrusted user: shadowfacts
GPG Key ID: 94A5AB95422746E5
7 changed files with 126 additions and 112 deletions

View File

@ -102,6 +102,7 @@
D6C693CA2161253F007D6A6D /* SilentActionPermissionsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6C693C92161253F007D6A6D /* SilentActionPermissionsTableViewController.swift */; }; D6C693CA2161253F007D6A6D /* SilentActionPermissionsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6C693C92161253F007D6A6D /* SilentActionPermissionsTableViewController.swift */; };
D6C693CD2161257B007D6A6D /* SilentActionPermissionCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = D6C693CC2161257B007D6A6D /* SilentActionPermissionCell.xib */; }; D6C693CD2161257B007D6A6D /* SilentActionPermissionCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = D6C693CC2161257B007D6A6D /* SilentActionPermissionCell.xib */; };
D6C693CF216125FC007D6A6D /* SilentActionPermissionTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6C693CE216125FC007D6A6D /* SilentActionPermissionTableViewCell.swift */; }; D6C693CF216125FC007D6A6D /* SilentActionPermissionTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6C693CE216125FC007D6A6D /* SilentActionPermissionTableViewCell.swift */; };
D6C693EF216192C2007D6A6D /* TuskerNavigationDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6C693EE216192C2007D6A6D /* TuskerNavigationDelegate.swift */; };
D6C94D852139DFD800CB5196 /* LargeImage.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D6C94D842139DFD800CB5196 /* LargeImage.storyboard */; }; D6C94D852139DFD800CB5196 /* LargeImage.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D6C94D842139DFD800CB5196 /* LargeImage.storyboard */; };
D6C94D872139E62700CB5196 /* LargeImageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6C94D862139E62700CB5196 /* LargeImageViewController.swift */; }; D6C94D872139E62700CB5196 /* LargeImageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6C94D862139E62700CB5196 /* LargeImageViewController.swift */; };
D6C94D892139E6EC00CB5196 /* AttachmentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6C94D882139E6EC00CB5196 /* AttachmentView.swift */; }; D6C94D892139E6EC00CB5196 /* AttachmentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6C94D882139E6EC00CB5196 /* AttachmentView.swift */; };
@ -267,6 +268,7 @@
D6C693C92161253F007D6A6D /* SilentActionPermissionsTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SilentActionPermissionsTableViewController.swift; sourceTree = "<group>"; }; D6C693C92161253F007D6A6D /* SilentActionPermissionsTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SilentActionPermissionsTableViewController.swift; sourceTree = "<group>"; };
D6C693CC2161257B007D6A6D /* SilentActionPermissionCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SilentActionPermissionCell.xib; sourceTree = "<group>"; }; D6C693CC2161257B007D6A6D /* SilentActionPermissionCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SilentActionPermissionCell.xib; sourceTree = "<group>"; };
D6C693CE216125FC007D6A6D /* SilentActionPermissionTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SilentActionPermissionTableViewCell.swift; sourceTree = "<group>"; }; D6C693CE216125FC007D6A6D /* SilentActionPermissionTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SilentActionPermissionTableViewCell.swift; sourceTree = "<group>"; };
D6C693EE216192C2007D6A6D /* TuskerNavigationDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TuskerNavigationDelegate.swift; sourceTree = "<group>"; };
D6C94D842139DFD800CB5196 /* LargeImage.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = LargeImage.storyboard; sourceTree = "<group>"; }; D6C94D842139DFD800CB5196 /* LargeImage.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = LargeImage.storyboard; sourceTree = "<group>"; };
D6C94D862139E62700CB5196 /* LargeImageViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LargeImageViewController.swift; sourceTree = "<group>"; }; D6C94D862139E62700CB5196 /* LargeImageViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LargeImageViewController.swift; sourceTree = "<group>"; };
D6C94D882139E6EC00CB5196 /* AttachmentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttachmentView.swift; sourceTree = "<group>"; }; D6C94D882139E6EC00CB5196 /* AttachmentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttachmentView.swift; sourceTree = "<group>"; };
@ -661,6 +663,7 @@
D64D0AAC2128D88B005A6F37 /* LocalData.swift */, D64D0AAC2128D88B005A6F37 /* LocalData.swift */,
04DACE8D212CC7CC009840C4 /* AvatarCache.swift */, 04DACE8D212CC7CC009840C4 /* AvatarCache.swift */,
D6028B9A2150811100F223B9 /* MastodonCache.swift */, D6028B9A2150811100F223B9 /* MastodonCache.swift */,
D6C693EE216192C2007D6A6D /* TuskerNavigationDelegate.swift */,
D6757A7A2157E00100721E32 /* XCallbackURL */, D6757A7A2157E00100721E32 /* XCallbackURL */,
D663626021360A9600C9CBA2 /* Preferences */, D663626021360A9600C9CBA2 /* Preferences */,
D667E5F62135C2ED0057A976 /* Extensions */, D667E5F62135C2ED0057A976 /* Extensions */,
@ -988,6 +991,7 @@
D6BED174212667E900F02DA0 /* StatusTableViewCell.swift in Sources */, D6BED174212667E900F02DA0 /* StatusTableViewCell.swift in Sources */,
D64D0AAD2128D88B005A6F37 /* LocalData.swift in Sources */, D64D0AAD2128D88B005A6F37 /* LocalData.swift in Sources */,
D6C94D892139E6EC00CB5196 /* AttachmentView.swift in Sources */, D6C94D892139E6EC00CB5196 /* AttachmentView.swift in Sources */,
D6C693EF216192C2007D6A6D /* TuskerNavigationDelegate.swift in Sources */,
D6C94D872139E62700CB5196 /* LargeImageViewController.swift in Sources */, D6C94D872139E62700CB5196 /* LargeImageViewController.swift in Sources */,
D6434EB3215B1856001A919A /* XCBRequest.swift in Sources */, D6434EB3215B1856001A919A /* XCBRequest.swift in Sources */,
D663626221360B1900C9CBA2 /* Preferences.swift in Sources */, D663626221360B1900C9CBA2 /* Preferences.swift in Sources */,

View File

@ -10,93 +10,6 @@ import UIKit
import Pachyderm import Pachyderm
import SafariServices import SafariServices
extension StatusTableViewCellDelegate where Self: UIViewController {
func selected(account accountID: String) {
// don't open if the account is the same as the current one
if let profileController = self as? ProfileTableViewController,
profileController.accountID == accountID {
return
}
guard let navigationController = navigationController else {
fatalError("Can't show profile VC when not in navigation controller")
}
let vc = ProfileTableViewController.create(for: accountID)
navigationController.pushViewController(vc, animated: true)
}
func selected(mention: Mention) {
}
func selected(tag: Hashtag) {
}
func selected(url: URL) {
let vc = SFSafariViewController(url: url)
present(vc, animated: true)
}
func selected(status statusID: String) {
// don't open if the conversation is the same as the current one
if let conversationController = self as? ConversationViewController,
conversationController.mainStatusID == statusID {
return
}
guard let navigationController = navigationController else {
fatalError("Can't show conversation VC when not in navigation controller")
}
let vc = ConversationViewController.create(for: statusID)
navigationController.pushViewController(vc, animated: true)
}
func reply(to statusID: String) {
let vc = ComposeViewController.create(inReplyTo: statusID)
present(vc, animated: true)
}
func showLargeImage(_ image: UIImage, description: String?, animatingFrom originView: UIView) {
guard let self = self as? UIViewController & LargeImageViewControllerDelegate else { return }
let vc = LargeImageViewController.create(image: image, description: description)
vc.delegate = self
var frame = originView.convert(originView.bounds, to: view)
if let scrollView = view as? UIScrollView {
let scale = scrollView.zoomScale
let width = frame.width * scale
let height = frame.height * scale
let x = frame.minX * scale - scrollView.contentOffset.x + scrollView.frame.minX
let y = frame.minY * scale - scrollView.contentOffset.y + scrollView.frame.minY
frame = CGRect(x: x, y: y, width: width, height: height)
}
vc.originFrame = frame
vc.originCornerRadius = originView.layer.cornerRadius
vc.transitioningDelegate = self
present(vc, animated: true)
}
func showMoreOptions(status statusID: String) {
guard let status = MastodonCache.status(for: statusID) else { fatalError("Missing cached status \(statusID)") }
let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
if let url = status.url {
alert.addAction(UIAlertAction(title: "Open in Safari...", style: .default, handler: { _ in
let vc = SFSafariViewController(url: url)
self.present(vc, animated: true)
}))
alert.addAction(UIAlertAction(title: "Share...", style: .default, handler: { _ in
let vc = UIActivityViewController(activityItems: [url], applicationActivities: nil)
self.present(vc, animated: true)
}))
}
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
present(alert, animated: true)
}
}
extension LargeImageViewControllerDelegate where Self: UIViewController { extension LargeImageViewControllerDelegate where Self: UIViewController {
func closeLargeImage() { func closeLargeImage() {
dismiss(animated: true) dismiss(animated: true)

View File

@ -169,6 +169,7 @@ class ProfileTableViewController: UITableViewController, PreferencesAdaptive {
} }
extension ProfileTableViewController: StatusTableViewCellDelegate {}
extension ProfileTableViewController: ProfileHeaderTableViewCellDelegate { extension ProfileTableViewController: ProfileHeaderTableViewCellDelegate {
func showMoreOptions() { func showMoreOptions() {
@ -216,5 +217,4 @@ extension ProfileTableViewController: ProfileHeaderTableViewCellDelegate {
} }
} }
extension ProfileTableViewController: LargeImageViewControllerDelegate {} extension ProfileTableViewController: LargeImageViewControllerDelegate {}

View File

@ -0,0 +1,116 @@
//
// TuskerNavigationDelegate.swift
// Tusker
//
// Created by Shadowfacts on 9/30/18.
// Copyright © 2018 Shadowfacts. All rights reserved.
//
import UIKit
import SafariServices
import Pachyderm
protocol TuskerNavigationDelegate {
func selected(account accountID: String)
func selected(mention: Mention)
func selected(tag: Hashtag)
func selected(url: URL)
func selected(status statusID: String)
func reply(to statusID: String)
func showLargeImage(_ image: UIImage, description: String?, animatingFrom originView: UIView)
func showMoreOptions(forStatus statusID: String)
}
extension TuskerNavigationDelegate where Self: UIViewController {
func selected(account accountID: String) {
// don't open if the account is the same as the current one
if let profileController = self as? ProfileTableViewController,
profileController.accountID == accountID {
return
}
guard let navigationController = navigationController else {
fatalError("Can't show profile VC when not in navigation controller")
}
let vc = ProfileTableViewController.create(for: accountID)
navigationController.pushViewController(vc, animated: true)
}
func selected(mention: Mention) {
}
func selected(tag: Hashtag) {
}
func selected(url: URL) {
let vc = SFSafariViewController(url: url)
present(vc, animated: true)
}
func selected(status statusID: String) {
// don't open if the conversation is the same as the current one
if let conversationController = self as? ConversationViewController,
conversationController.mainStatusID == statusID {
return
}
guard let navigationController = navigationController else {
fatalError("Can't show conversation VC when not in navigation controller")
}
let vc = ConversationViewController.create(for: statusID)
navigationController.pushViewController(vc, animated: true)
}
func reply(to statusID: String) {
let vc = ComposeViewController.create(inReplyTo: statusID)
present(vc, animated: true)
}
func showLargeImage(_ image: UIImage, description: String?, animatingFrom originView: UIView) {
guard let self = self as? UIViewController & LargeImageViewControllerDelegate else { return }
let vc = LargeImageViewController.create(image: image, description: description)
vc.delegate = self
var frame = originView.convert(originView.bounds, to: view)
if let scrollView = view as? UIScrollView {
let scale = scrollView.zoomScale
let width = frame.width * scale
let height = frame.height * scale
let x = frame.minX * scale - scrollView.contentOffset.x + scrollView.frame.minX
let y = frame.minY * scale - scrollView.contentOffset.y + scrollView.frame.minY
frame = CGRect(x: x, y: y, width: width, height: height)
}
vc.originFrame = frame
vc.originCornerRadius = originView.layer.cornerRadius
vc.transitioningDelegate = self
present(vc, animated: true)
}
func showMoreOptions(forStatus statusID: String) {
guard let status = MastodonCache.status(for: statusID) else { fatalError("Missing cached status \(statusID)") }
let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
if let url = status.url {
alert.addAction(UIAlertAction(title: "Open in Safari...", style: .default, handler: { _ in
let vc = SFSafariViewController(url: url)
self.present(vc, animated: true)
}))
alert.addAction(UIAlertAction(title: "Share...", style: .default, handler: { _ in
let vc = UIActivityViewController(activityItems: [url], applicationActivities: nil)
self.present(vc, animated: true)
}))
}
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
present(alert, animated: true)
}
}

View File

@ -9,10 +9,8 @@
import UIKit import UIKit
import Pachyderm import Pachyderm
protocol ProfileHeaderTableViewCellDelegate: StatusTableViewCellDelegate { protocol ProfileHeaderTableViewCellDelegate: TuskerNavigationDelegate {
func showMoreOptions() func showMoreOptions()
} }
class ProfileHeaderTableViewCell: UITableViewCell, PreferencesAdaptive { class ProfileHeaderTableViewCell: UITableViewCell, PreferencesAdaptive {

View File

@ -213,7 +213,7 @@ class ConversationMainStatusTableViewCell: UITableViewCell, PreferencesAdaptive
} }
@IBAction func morePressed(_ sender: Any) { @IBAction func morePressed(_ sender: Any) {
delegate?.showMoreOptions(status: statusID) delegate?.showMoreOptions(forStatus: statusID)
} }
} }

View File

@ -9,24 +9,7 @@
import UIKit import UIKit
import Pachyderm import Pachyderm
protocol StatusTableViewCellDelegate { protocol StatusTableViewCellDelegate: TuskerNavigationDelegate {
func selected(account accountID: String)
func selected(mention: Mention)
func selected(tag: Hashtag)
func selected(url: URL)
func selected(status statusID: String)
func reply(to statusID: String)
func showLargeImage(_ image: UIImage, description: String?, animatingFrom originView: UIView)
func showMoreOptions(status statusID: String)
} }
class StatusTableViewCell: UITableViewCell, PreferencesAdaptive { class StatusTableViewCell: UITableViewCell, PreferencesAdaptive {
@ -264,7 +247,7 @@ class StatusTableViewCell: UITableViewCell, PreferencesAdaptive {
} }
@IBAction func morePressed(_ sender: Any) { @IBAction func morePressed(_ sender: Any) {
delegate?.showMoreOptions(status: statusID) delegate?.showMoreOptions(forStatus: statusID)
} }
} }
@ -356,7 +339,7 @@ extension StatusTableViewCell: TableViewSwipeActionProvider {
reply.backgroundColor = tintColor reply.backgroundColor = tintColor
let more = UIContextualAction(style: .normal, title: "More") { (action, view, completion) in let more = UIContextualAction(style: .normal, title: "More") { (action, view, completion) in
completion(true) completion(true)
self.delegate?.showMoreOptions(status: self.statusID) self.delegate?.showMoreOptions(forStatus: self.statusID)
} }
more.image = StatusTableViewCell.moreActionImage more.image = StatusTableViewCell.moreActionImage
more.backgroundColor = .gray more.backgroundColor = .gray