A WIP iOS app for Mastodon and Pleroma.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
5.0 KiB

//
// TuskerNavigationDelegate.swift
// Tusker
//
// Created by Shadowfacts on 9/30/18.
// Copyright © 2018 Shadowfacts. All rights reserved.
//
import UIKit
import SafariServices
import Pachyderm
protocol TuskerNavigationDelegate {
var router: AppRouter { get }
func selected(account accountID: String)
func selected(mention: Mention)
func selected(tag: Hashtag)
func selected(url: URL)
func selected(status statusID: String)
func compose()
func reply(to statusID: String)
func largeImage(_ image: UIImage, description: String?, sourceView: UIView) -> LargeImageViewController
func largeImage(gifData: Data, description: String?, sourceView: UIView) -> LargeImageViewController
func showLargeImage(_ image: UIImage, description: String?, animatingFrom sourceView: UIView)
func showLargeImage(gifData: Data, description: String?, animatingFrom sourceView: UIView)
func showMoreOptions(forStatus statusID: String)
func showMoreOptions(forURL url: URL)
}
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
}
router.push(router.profile(for: accountID), animated: true)
}
func selected(mention: Mention) {
router.push(router.profile(for: mention), animated: true)
}
func selected(tag: Hashtag) {
router.push(router.timeline(tag: tag), animated: true)
}
func selected(url: URL) {
router.present(router.safariViewController(for: url), 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? ConversationTableViewController,
conversationController.mainStatusID == statusID {
return
}
router.push(router.conversation(for: statusID), animated: true)
}
func compose() {
let vc: UINavigationController = UINavigationController(rootViewController: router.compose())
router.present(vc, animated: true)
}
func reply(to statusID: String) {
let vc = UINavigationController(rootViewController: router.compose(inReplyTo: statusID))
router.present(vc, animated: true)
}
func largeImage(_ image: UIImage, description: String?, sourceView: UIView) -> LargeImageViewController {
var sourceFrame = sourceView.convert(sourceView.bounds, to: view)
if let scrollView = view as? UIScrollView {
let scale = scrollView.zoomScale
let width = sourceFrame.width * scale
let height = sourceFrame.height * scale
let x = sourceFrame.minX * scale - scrollView.contentOffset.x + scrollView.frame.minX
let y = sourceFrame.minY * scale - scrollView.contentOffset.y + scrollView.frame.minY
sourceFrame = CGRect(x: x, y: y, width: width, height: height)
}
let sourceCornerRadius = sourceView.layer.cornerRadius
return router.largeImage(image, description: description, sourceFrame: sourceFrame, sourceCornerRadius: sourceCornerRadius, transitioningDelegate: self)
}
func largeImage(gifData: Data, description: String?, sourceView: UIView) -> LargeImageViewController {
var sourceFrame = sourceView.convert(sourceView.bounds, to: view)
if let scrollView = view as? UIScrollView {
let scale = scrollView.zoomScale
let width = sourceFrame.width * scale
let height = sourceFrame.height * scale
let x = sourceFrame.minX * scale - scrollView.contentOffset.x + scrollView.frame.minX
let y = sourceFrame.minY * scale - scrollView.contentOffset.y + scrollView.frame.minY
sourceFrame = CGRect(x: x, y: y, width: width, height: height)
}
let sourceCornerRadius = sourceView.layer.cornerRadius
return router.largeImage(gifData: gifData, description: description, sourceFrame: sourceFrame, sourceCornerRadius: sourceCornerRadius, transitioningDelegate: self)
}
func showLargeImage(_ image: UIImage, description: String?, animatingFrom sourceView: UIView) {
router.present(largeImage(image, description: description, sourceView: sourceView), animated: true)
}
func showLargeImage(gifData: Data, description: String?, animatingFrom sourceView: UIView) {
router.present(largeImage(gifData: gifData, description: description, sourceView: sourceView), animated: true)
}
func showMoreOptions(forStatus statusID: String) {
router.present(router.moreOptions(forStatus: statusID), animated: true)
}
func showMoreOptions(forURL url: URL) {
router.present(router.moreOptions(forURL: url), animated: true)
}
}