2018-09-02 20:59:20 +00:00
|
|
|
//
|
|
|
|
// UIViewController+StatusTableViewCellDelegate.swift
|
|
|
|
// Tusker
|
|
|
|
//
|
|
|
|
// Created by Shadowfacts on 8/27/18.
|
|
|
|
// Copyright © 2018 Shadowfacts. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
2018-09-11 14:52:21 +00:00
|
|
|
import Pachyderm
|
2018-09-02 20:59:20 +00:00
|
|
|
import SafariServices
|
|
|
|
|
2018-09-03 22:46:20 +00:00
|
|
|
extension StatusTableViewCellDelegate where Self: UIViewController {
|
2018-09-02 20:59:20 +00:00
|
|
|
|
|
|
|
func selected(account: Account) {
|
|
|
|
// don't open if the account is the same as the current one
|
|
|
|
if let profileController = self as? ProfileTableViewController,
|
|
|
|
profileController.account == account {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
guard let navigationController = navigationController else {
|
|
|
|
fatalError("Can't show profile VC when not in navigation controller")
|
|
|
|
}
|
|
|
|
let vc = ProfileTableViewController.create(for: account)
|
|
|
|
navigationController.pushViewController(vc, animated: true)
|
|
|
|
}
|
|
|
|
|
|
|
|
func selected(mention: Mention) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-09-11 14:52:21 +00:00
|
|
|
func selected(tag: Hashtag) {
|
2018-09-02 20:59:20 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func selected(url: URL) {
|
|
|
|
let vc = SFSafariViewController(url: url)
|
|
|
|
present(vc, animated: true)
|
|
|
|
}
|
|
|
|
|
|
|
|
func selected(status: Status) {
|
|
|
|
// don't open if the conversation is the same as the current one
|
|
|
|
if let conversationController = self as? ConversationViewController,
|
|
|
|
conversationController.mainStatus == status {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
guard let navigationController = navigationController else {
|
|
|
|
fatalError("Can't show conversation VC when not in navigation controller")
|
|
|
|
}
|
|
|
|
let vc = ConversationViewController.create(for: status)
|
|
|
|
navigationController.pushViewController(vc, animated: true)
|
|
|
|
}
|
|
|
|
|
|
|
|
func reply(to status: Status) {
|
|
|
|
let vc = ComposeViewController.create(inReplyTo: status)
|
|
|
|
present(vc, animated: true)
|
|
|
|
}
|
|
|
|
|
2018-09-02 22:22:29 +00:00
|
|
|
func showLargeImage(_ image: UIImage, description: String?, animatingFrom originView: UIView) {
|
2018-09-03 22:46:20 +00:00
|
|
|
guard let self = self as? UIViewController & LargeImageViewControllerDelegate else { return }
|
2018-09-02 22:22:29 +00:00
|
|
|
let vc = LargeImageViewController.create(image: image, description: description)
|
2018-09-02 20:59:20 +00:00
|
|
|
vc.delegate = self
|
2018-09-02 22:22:29 +00:00
|
|
|
var frame = originView.convert(originView.bounds, to: view)
|
2018-09-02 20:59:20 +00:00
|
|
|
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
|
2018-09-02 22:22:29 +00:00
|
|
|
vc.originCornerRadius = originView.layer.cornerRadius
|
2018-09-02 20:59:20 +00:00
|
|
|
vc.transitioningDelegate = self
|
|
|
|
present(vc, animated: true)
|
|
|
|
}
|
|
|
|
|
2018-09-11 22:17:48 +00:00
|
|
|
func showMoreOptions(status: Status) {
|
|
|
|
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)
|
2018-09-09 01:35:40 +00:00
|
|
|
}
|
|
|
|
|
2018-09-02 20:59:20 +00:00
|
|
|
}
|
|
|
|
|
2018-09-03 22:46:20 +00:00
|
|
|
extension LargeImageViewControllerDelegate where Self: UIViewController {
|
2018-09-02 20:59:20 +00:00
|
|
|
func closeLargeImage() {
|
|
|
|
dismiss(animated: true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension UIViewController: UIViewControllerTransitioningDelegate {
|
|
|
|
public func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
|
|
|
|
if presented is LargeImageViewController {
|
|
|
|
return LargeImageExpandAnimationController()
|
|
|
|
} else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
|
|
|
|
if let dismissed = dismissed as? LargeImageViewController {
|
|
|
|
return LargeImageShrinkAnimationController(interactionController: dismissed.dismissInteractionController)
|
|
|
|
} else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public func interactionControllerForDismissal(using animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
|
|
|
|
if let animator = animator as? LargeImageShrinkAnimationController,
|
|
|
|
let interactionController = animator.interactionController,
|
|
|
|
interactionController.inProgress {
|
|
|
|
|
|
|
|
return interactionController
|
|
|
|
} else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|