|
@@ -5,6 +5,7 @@
|
|
|
// Created by Marino Faggiana on 03/05/2020.
|
|
|
// Copyright © 2020 Marino Faggiana. All rights reserved.
|
|
|
// Copyright © 2022 Henrik Storch. All rights reserved.
|
|
|
+// Copyright © 2023 Marino Faggiana. All rights reserved.
|
|
|
//
|
|
|
// Author Marino Faggiana <marino.faggiana@nextcloud.com>
|
|
|
// Author Henrik Storch <henrik.storch@nextcloud.com>
|
|
@@ -28,12 +29,17 @@ import QuickLook
|
|
|
import NextcloudKit
|
|
|
import Mantis
|
|
|
|
|
|
+protocol NCViewerQuickLookDelegate: AnyObject {
|
|
|
+ func dismiss(url: URL, hasChanges: Bool)
|
|
|
+}
|
|
|
+
|
|
|
@objc class NCViewerQuickLook: QLPreviewController {
|
|
|
|
|
|
let url: URL
|
|
|
var previewItems: [PreviewItem] = []
|
|
|
var isEditingEnabled: Bool
|
|
|
var metadata: tableMetadata?
|
|
|
+ var delegateViewer: NCViewerQuickLookDelegate?
|
|
|
|
|
|
// if the document has any changes (annotations)
|
|
|
var hasChanges = false
|
|
@@ -41,6 +47,9 @@ import Mantis
|
|
|
// used to display the save alert
|
|
|
var parentVC: UIViewController?
|
|
|
|
|
|
+ // if the Crop is presented
|
|
|
+ var isPresentCrop = false
|
|
|
+
|
|
|
required init?(coder: NSCoder) {
|
|
|
fatalError("init(coder:) has not been implemented")
|
|
|
}
|
|
@@ -84,6 +93,8 @@ import Mantis
|
|
|
override func viewDidDisappear(_ animated: Bool) {
|
|
|
super.viewDidDisappear(animated)
|
|
|
|
|
|
+ guard !isPresentCrop else { return }
|
|
|
+ delegateViewer?.dismiss(url: url, hasChanges: hasChanges)
|
|
|
guard isEditingEnabled, hasChanges, let metadata = metadata else { return }
|
|
|
|
|
|
let alertController = UIAlertController(title: NSLocalizedString("_save_", comment: ""), message: nil, preferredStyle: .alert)
|
|
@@ -108,7 +119,7 @@ import Mantis
|
|
|
|
|
|
@objc func crop() {
|
|
|
|
|
|
- guard let fileName = self.metadata?.fileNameView, let image = UIImage(contentsOfFile: NSTemporaryDirectory() + fileName) else { return }
|
|
|
+ guard let image = UIImage(contentsOfFile: url.path) else { return }
|
|
|
let config = Mantis.Config()
|
|
|
|
|
|
if let bundleIdentifier = Bundle.main.bundleIdentifier {
|
|
@@ -120,6 +131,7 @@ import Mantis
|
|
|
cropViewController.delegate = self
|
|
|
cropViewController.modalPresentationStyle = .fullScreen
|
|
|
|
|
|
+ self.isPresentCrop = true
|
|
|
self.present(cropViewController, animated: true)
|
|
|
}
|
|
|
}
|
|
@@ -188,7 +200,9 @@ extension NCViewerQuickLook: QLPreviewControllerDataSource, QLPreviewControllerD
|
|
|
extension NCViewerQuickLook: CropViewControllerDelegate {
|
|
|
|
|
|
func cropViewControllerDidCrop(_ cropViewController: Mantis.CropViewController, cropped: UIImage, transformation: Mantis.Transformation, cropInfo: Mantis.CropInfo) {
|
|
|
- cropViewController.dismiss(animated: true)
|
|
|
+ cropViewController.dismiss(animated: true) {
|
|
|
+ self.isPresentCrop = false
|
|
|
+ }
|
|
|
|
|
|
guard let data = cropped.jpegData(compressionQuality: 1) else { return }
|
|
|
|
|
@@ -200,7 +214,9 @@ extension NCViewerQuickLook: CropViewControllerDelegate {
|
|
|
|
|
|
func cropViewControllerDidCancel(_ cropViewController: Mantis.CropViewController, original: UIImage) {
|
|
|
|
|
|
- cropViewController.dismiss(animated: true)
|
|
|
+ cropViewController.dismiss(animated: true) {
|
|
|
+ self.isPresentCrop = false
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|