forked from shadowfacts/Tusker
Rename AttachmentsViewController to LoadingLargeImageViewController and
make non-specific to attachments
This commit is contained in:
parent
bd3e74c611
commit
3bbbb05083
|
@ -7,7 +7,7 @@
|
||||||
objects = {
|
objects = {
|
||||||
|
|
||||||
/* Begin PBXBuildFile section */
|
/* Begin PBXBuildFile section */
|
||||||
0411610022B442870030A9B7 /* AttachmentViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 041160FE22B442870030A9B7 /* AttachmentViewController.swift */; };
|
0411610022B442870030A9B7 /* LoadingLargeImageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 041160FE22B442870030A9B7 /* LoadingLargeImageViewController.swift */; };
|
||||||
0427033822B30F5F000D31B6 /* BehaviorPrefsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0427033722B30F5F000D31B6 /* BehaviorPrefsView.swift */; };
|
0427033822B30F5F000D31B6 /* BehaviorPrefsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0427033722B30F5F000D31B6 /* BehaviorPrefsView.swift */; };
|
||||||
0427033A22B31269000D31B6 /* AdvancedPrefsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0427033922B31269000D31B6 /* AdvancedPrefsView.swift */; };
|
0427033A22B31269000D31B6 /* AdvancedPrefsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0427033922B31269000D31B6 /* AdvancedPrefsView.swift */; };
|
||||||
0427037C22B316B9000D31B6 /* SilentActionPrefs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0427037B22B316B9000D31B6 /* SilentActionPrefs.swift */; };
|
0427037C22B316B9000D31B6 /* SilentActionPrefs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0427037B22B316B9000D31B6 /* SilentActionPrefs.swift */; };
|
||||||
|
@ -288,7 +288,7 @@
|
||||||
/* End PBXCopyFilesBuildPhase section */
|
/* End PBXCopyFilesBuildPhase section */
|
||||||
|
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
041160FE22B442870030A9B7 /* AttachmentViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttachmentViewController.swift; sourceTree = "<group>"; };
|
041160FE22B442870030A9B7 /* LoadingLargeImageViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingLargeImageViewController.swift; sourceTree = "<group>"; };
|
||||||
0427033722B30F5F000D31B6 /* BehaviorPrefsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BehaviorPrefsView.swift; sourceTree = "<group>"; };
|
0427033722B30F5F000D31B6 /* BehaviorPrefsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BehaviorPrefsView.swift; sourceTree = "<group>"; };
|
||||||
0427033922B31269000D31B6 /* AdvancedPrefsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdvancedPrefsView.swift; sourceTree = "<group>"; };
|
0427033922B31269000D31B6 /* AdvancedPrefsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdvancedPrefsView.swift; sourceTree = "<group>"; };
|
||||||
0427037B22B316B9000D31B6 /* SilentActionPrefs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SilentActionPrefs.swift; sourceTree = "<group>"; };
|
0427037B22B316B9000D31B6 /* SilentActionPrefs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SilentActionPrefs.swift; sourceTree = "<group>"; };
|
||||||
|
@ -570,7 +570,6 @@
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
04D14BAE22B34A2800642648 /* GalleryViewController.swift */,
|
04D14BAE22B34A2800642648 /* GalleryViewController.swift */,
|
||||||
041160FE22B442870030A9B7 /* AttachmentViewController.swift */,
|
|
||||||
);
|
);
|
||||||
path = "Attachment Gallery";
|
path = "Attachment Gallery";
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
|
@ -879,6 +878,7 @@
|
||||||
D646C954213B364600269FB5 /* Transitions */,
|
D646C954213B364600269FB5 /* Transitions */,
|
||||||
D6289E83217B795D0003D1D7 /* LargeImageViewController.xib */,
|
D6289E83217B795D0003D1D7 /* LargeImageViewController.xib */,
|
||||||
D6C94D862139E62700CB5196 /* LargeImageViewController.swift */,
|
D6C94D862139E62700CB5196 /* LargeImageViewController.swift */,
|
||||||
|
041160FE22B442870030A9B7 /* LoadingLargeImageViewController.swift */,
|
||||||
);
|
);
|
||||||
path = "Large Image";
|
path = "Large Image";
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
|
@ -1614,7 +1614,7 @@
|
||||||
D6C7D27D22B6EBF800071952 /* AttachmentsContainerView.swift in Sources */,
|
D6C7D27D22B6EBF800071952 /* AttachmentsContainerView.swift in Sources */,
|
||||||
D620483823D38190008A63EF /* StatusContentTextView.swift in Sources */,
|
D620483823D38190008A63EF /* StatusContentTextView.swift in Sources */,
|
||||||
D6F953F021251A2900CF0F2B /* MastodonController.swift in Sources */,
|
D6F953F021251A2900CF0F2B /* MastodonController.swift in Sources */,
|
||||||
0411610022B442870030A9B7 /* AttachmentViewController.swift in Sources */,
|
0411610022B442870030A9B7 /* LoadingLargeImageViewController.swift in Sources */,
|
||||||
D611C2CF232DC61100C86A49 /* HashtagTableViewCell.swift in Sources */,
|
D611C2CF232DC61100C86A49 /* HashtagTableViewCell.swift in Sources */,
|
||||||
D627944F23A9C99800D38C68 /* EditListAccountsViewController.swift in Sources */,
|
D627944F23A9C99800D38C68 /* EditListAccountsViewController.swift in Sources */,
|
||||||
D6945C3423AC6431005C403C /* AddSavedHashtagViewController.swift in Sources */,
|
D6945C3423AC6431005C403C /* AddSavedHashtagViewController.swift in Sources */,
|
||||||
|
|
|
@ -8,14 +8,16 @@
|
||||||
import UIKit
|
import UIKit
|
||||||
import Pachyderm
|
import Pachyderm
|
||||||
|
|
||||||
class AttachmentViewController: UIViewController {
|
class PendingLargeImageViewController: UIViewController {
|
||||||
|
|
||||||
let attachment: Attachment
|
let url: URL
|
||||||
|
let cache: ImageCache
|
||||||
|
let imageDescription: String?
|
||||||
|
|
||||||
var largeImageVC: LargeImageViewController?
|
var largeImageVC: LargeImageViewController?
|
||||||
var loadingVC: LoadingViewController?
|
var loadingVC: LoadingViewController?
|
||||||
|
|
||||||
var attachmentRequest: ImageCache.Request?
|
var imageRequest: ImageCache.Request?
|
||||||
|
|
||||||
private var initialControlsVisible: Bool = true
|
private var initialControlsVisible: Bool = true
|
||||||
var controlsVisible: Bool {
|
var controlsVisible: Bool {
|
||||||
|
@ -35,12 +37,18 @@ class AttachmentViewController: UIViewController {
|
||||||
return largeImageVC
|
return largeImageVC
|
||||||
}
|
}
|
||||||
|
|
||||||
init(attachment: Attachment) {
|
init(url: URL, cache: ImageCache, imageDescription: String?) {
|
||||||
self.attachment = attachment
|
self.url = url
|
||||||
|
self.cache = cache
|
||||||
|
self.imageDescription = imageDescription
|
||||||
|
|
||||||
super.init(nibName: nil, bundle: nil)
|
super.init(nibName: nil, bundle: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
convenience init(attachment: Attachment) {
|
||||||
|
self.init(url: attachment.url, cache: .attachments, imageDescription: attachment.description)
|
||||||
|
}
|
||||||
|
|
||||||
required init?(coder: NSCoder) {
|
required init?(coder: NSCoder) {
|
||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
}
|
}
|
||||||
|
@ -51,14 +59,14 @@ class AttachmentViewController: UIViewController {
|
||||||
overrideUserInterfaceStyle = .dark
|
overrideUserInterfaceStyle = .dark
|
||||||
view.backgroundColor = .black
|
view.backgroundColor = .black
|
||||||
|
|
||||||
if let data = ImageCache.attachments.get(attachment.url) {
|
if let data = cache.get(url) {
|
||||||
createLargeImage(data: data)
|
createLargeImage(data: data)
|
||||||
} else {
|
} else {
|
||||||
loadingVC = LoadingViewController()
|
loadingVC = LoadingViewController()
|
||||||
embedChild(loadingVC!)
|
embedChild(loadingVC!)
|
||||||
attachmentRequest = ImageCache.attachments.get(attachment.url) { [weak self] (data) in
|
imageRequest = cache.get(url) { [weak self] (data) in
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
self.attachmentRequest = nil
|
self.imageRequest = nil
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.loadingVC?.removeViewAndController()
|
self.loadingVC?.removeViewAndController()
|
||||||
self.createLargeImage(data: data!)
|
self.createLargeImage(data: data!)
|
||||||
|
@ -71,16 +79,16 @@ class AttachmentViewController: UIViewController {
|
||||||
super.didMove(toParent: parent)
|
super.didMove(toParent: parent)
|
||||||
|
|
||||||
if parent == nil {
|
if parent == nil {
|
||||||
attachmentRequest?.cancel()
|
imageRequest?.cancel()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func createLargeImage(data: Data) {
|
func createLargeImage(data: Data) {
|
||||||
guard let image = UIImage(data: data) else { return }
|
guard let image = UIImage(data: data) else { return }
|
||||||
largeImageVC = LargeImageViewController(image: image, description: attachment.description, sourceInfo: nil)
|
largeImageVC = LargeImageViewController(image: image, description: imageDescription, sourceInfo: nil)
|
||||||
largeImageVC!.initialControlsVisible = initialControlsVisible
|
largeImageVC!.initialControlsVisible = initialControlsVisible
|
||||||
largeImageVC!.shrinkGestureEnabled = false
|
largeImageVC!.shrinkGestureEnabled = false
|
||||||
if attachment.url.pathExtension == "gif" {
|
if url.pathExtension == "gif" {
|
||||||
largeImageVC!.gifData = data
|
largeImageVC!.gifData = data
|
||||||
}
|
}
|
||||||
embedChild(largeImageVC!)
|
embedChild(largeImageVC!)
|
||||||
|
|
|
@ -31,7 +31,7 @@ class GalleryViewController: UIPageViewController, UIPageViewControllerDataSourc
|
||||||
if let sourceImage = sourcesInfo[currentIndex]?.image {
|
if let sourceImage = sourcesInfo[currentIndex]?.image {
|
||||||
return sourceImage
|
return sourceImage
|
||||||
} else {
|
} else {
|
||||||
return (pages[currentIndex] as? AttachmentViewController)?.largeImageVC?.image
|
return (pages[currentIndex] as? LoadingLargeImageViewController)?.largeImageVC?.image
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var animationGifData: Data? {
|
var animationGifData: Data? {
|
||||||
|
@ -67,7 +67,7 @@ class GalleryViewController: UIPageViewController, UIPageViewControllerDataSourc
|
||||||
self.pages = attachments.map {
|
self.pages = attachments.map {
|
||||||
switch $0.kind {
|
switch $0.kind {
|
||||||
case .image:
|
case .image:
|
||||||
return AttachmentViewController(attachment: $0)
|
return LoadingLargeImageViewController(attachment: $0)
|
||||||
case .video, .audio:
|
case .video, .audio:
|
||||||
let vc = AVPlayerViewController()
|
let vc = AVPlayerViewController()
|
||||||
vc.player = AVPlayer(url: $0.url)
|
vc.player = AVPlayer(url: $0.url)
|
||||||
|
@ -133,8 +133,8 @@ class GalleryViewController: UIPageViewController, UIPageViewControllerDataSourc
|
||||||
|
|
||||||
// MARK: - Page View Controller Delegate
|
// MARK: - Page View Controller Delegate
|
||||||
func pageViewController(_ pageViewController: UIPageViewController, willTransitionTo pendingViewControllers: [UIViewController]) {
|
func pageViewController(_ pageViewController: UIPageViewController, willTransitionTo pendingViewControllers: [UIViewController]) {
|
||||||
if let pending = pendingViewControllers.first as? AttachmentViewController,
|
if let pending = pendingViewControllers.first as? LoadingLargeImageViewController,
|
||||||
let current = viewControllers!.first as? AttachmentViewController {
|
let current = viewControllers!.first as? LoadingLargeImageViewController {
|
||||||
pending.controlsVisible = current.controlsVisible
|
pending.controlsVisible = current.controlsVisible
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,97 @@
|
||||||
|
// LoadingLargeImageViewController.swift
|
||||||
|
// Tusker
|
||||||
|
//
|
||||||
|
// Created by Shadowfacts on 6/14/19.
|
||||||
|
// Copyright © 2019 Shadowfacts. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import UIKit
|
||||||
|
import Pachyderm
|
||||||
|
|
||||||
|
class LoadingLargeImageViewController: UIViewController {
|
||||||
|
|
||||||
|
let url: URL
|
||||||
|
let cache: ImageCache
|
||||||
|
let imageDescription: String?
|
||||||
|
|
||||||
|
var largeImageVC: LargeImageViewController?
|
||||||
|
var loadingVC: LoadingViewController?
|
||||||
|
|
||||||
|
var imageRequest: ImageCache.Request?
|
||||||
|
|
||||||
|
private var initialControlsVisible: Bool = true
|
||||||
|
var controlsVisible: Bool {
|
||||||
|
get {
|
||||||
|
return largeImageVC?.controlsVisible ?? initialControlsVisible
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
if let largeImageVC = largeImageVC {
|
||||||
|
largeImageVC.setControlsVisible(newValue, animated: false)
|
||||||
|
} else {
|
||||||
|
initialControlsVisible = newValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override var childForHomeIndicatorAutoHidden: UIViewController? {
|
||||||
|
return largeImageVC
|
||||||
|
}
|
||||||
|
|
||||||
|
init(url: URL, cache: ImageCache, imageDescription: String?) {
|
||||||
|
self.url = url
|
||||||
|
self.cache = cache
|
||||||
|
self.imageDescription = imageDescription
|
||||||
|
|
||||||
|
super.init(nibName: nil, bundle: nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
convenience init(attachment: Attachment) {
|
||||||
|
self.init(url: attachment.url, cache: .attachments, imageDescription: attachment.description)
|
||||||
|
}
|
||||||
|
|
||||||
|
required init?(coder: NSCoder) {
|
||||||
|
fatalError("init(coder:) has not been implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override func viewDidLoad() {
|
||||||
|
super.viewDidLoad()
|
||||||
|
|
||||||
|
overrideUserInterfaceStyle = .dark
|
||||||
|
view.backgroundColor = .black
|
||||||
|
|
||||||
|
if let data = cache.get(url) {
|
||||||
|
createLargeImage(data: data)
|
||||||
|
} else {
|
||||||
|
loadingVC = LoadingViewController()
|
||||||
|
embedChild(loadingVC!)
|
||||||
|
imageRequest = cache.get(url) { [weak self] (data) in
|
||||||
|
guard let self = self else { return }
|
||||||
|
self.imageRequest = nil
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.loadingVC?.removeViewAndController()
|
||||||
|
self.createLargeImage(data: data!)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override func didMove(toParent parent: UIViewController?) {
|
||||||
|
super.didMove(toParent: parent)
|
||||||
|
|
||||||
|
if parent == nil {
|
||||||
|
imageRequest?.cancel()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func createLargeImage(data: Data) {
|
||||||
|
guard let image = UIImage(data: data) else { return }
|
||||||
|
largeImageVC = LargeImageViewController(image: image, description: imageDescription, sourceInfo: nil)
|
||||||
|
largeImageVC!.initialControlsVisible = initialControlsVisible
|
||||||
|
largeImageVC!.shrinkGestureEnabled = false
|
||||||
|
if url.pathExtension == "gif" {
|
||||||
|
largeImageVC!.gifData = data
|
||||||
|
}
|
||||||
|
embedChild(largeImageVC!)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue