Browse Source

fix

Signed-off-by: Marino Faggiana <96728420+MarinoFaggianaAstraIridium@users.noreply.github.com>
Marino Faggiana 2 years ago
parent
commit
c65bc824ea

+ 13 - 7
iOSClient/Main/NCActionCenter.swift

@@ -71,15 +71,21 @@ class NCActionCenter: NSObject, UIDocumentInteractionControllerDelegate, NCSelec
         case NCGlobal.shared.selectorLoadFileQuickLook:
             let fileNamePath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!
             let fileNameTemp = NSTemporaryDirectory() + metadata.fileNameView
-            guard let image = UIImage(contentsOfFile: fileNamePath) else { return }
-            if let data = image.jpegData(compressionQuality: 1) {
-                do {
-                    try data.write(to: URL(fileURLWithPath: fileNameTemp))
-                } catch {
-                    return
+            var isCropEnabled: Bool = true
+            if let image = UIImage(contentsOfFile: fileNamePath) {
+                if let data = image.jpegData(compressionQuality: 1) {
+                    do {
+                        try data.write(to: URL(fileURLWithPath: fileNameTemp))
+                        isCropEnabled = true
+                    } catch {
+                        return
+                    }
                 }
+            } else {
+                CCUtility.copyFile(atPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView), toPath: fileNamePath)
+                isCropEnabled = false
             }
-            let viewerQuickLook = NCViewerQuickLook(with: URL(fileURLWithPath: fileNameTemp), isEditingEnabled: true, metadata: metadata)
+            let viewerQuickLook = NCViewerQuickLook(with: URL(fileURLWithPath: fileNameTemp), isEditingEnabled: true, isCropEnabled: isCropEnabled, metadata: metadata)
             let navigationController = UINavigationController(rootViewController: viewerQuickLook)
             navigationController.modalPresentationStyle = .fullScreen
             appDelegate.window?.rootViewController?.present(navigationController, animated: true)

+ 1 - 1
iOSClient/Settings/CCAdvanced.m

@@ -153,7 +153,7 @@
         row.action.formBlock = ^(XLFormRowDescriptor * sender) {
                     
             [self deselectFormRow:sender];
-            NCViewerQuickLook *viewerQuickLook = [[NCViewerQuickLook alloc] initWith:[NSURL fileURLWithPath:NKCommon.shared.filenamePathLog] isEditingEnabled:false metadata:nil];
+            NCViewerQuickLook *viewerQuickLook = [[NCViewerQuickLook alloc] initWith:[NSURL fileURLWithPath:NKCommon.shared.filenamePathLog] isEditingEnabled:false isCropEnabled:false metadata:nil];
             [self presentViewController:viewerQuickLook animated:YES completion:nil];
         };
         [section addFormRow:row];

+ 1 - 1
iOSClient/Viewer/NCViewer.swift

@@ -235,7 +235,7 @@ class NCViewer: NSObject {
         if QLPreviewController.canPreview(item as QLPreviewItem) {
             let fileNamePath = NSTemporaryDirectory() + metadata.fileNameView
             CCUtility.copyFile(atPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView), toPath: fileNamePath)
-            let viewerQuickLook = NCViewerQuickLook(with: URL(fileURLWithPath: fileNamePath), isEditingEnabled: false, metadata: metadata)
+            let viewerQuickLook = NCViewerQuickLook(with: URL(fileURLWithPath: fileNamePath), isEditingEnabled: false, isCropEnabled: false, metadata: metadata)
             viewController.present(viewerQuickLook, animated: true)
         } else {
         // Document Interaction Controller

+ 12 - 10
iOSClient/Viewer/NCViewerQuickLook/NCViewerQuickLook.swift

@@ -38,6 +38,7 @@ private var hasChangesQuickLook: Bool = false
     let url: URL
     var previewItems: [PreviewItem] = []
     var isEditingEnabled: Bool
+    var isCropEnabled: Bool
     var metadata: tableMetadata?
     var timer: Timer?
 
@@ -45,9 +46,10 @@ private var hasChangesQuickLook: Bool = false
         fatalError("init(coder:) has not been implemented")
     }
 
-    @objc init(with url: URL, isEditingEnabled: Bool, metadata: tableMetadata?) {
+    @objc init(with url: URL, isEditingEnabled: Bool, isCropEnabled: Bool, metadata: tableMetadata?) {
         self.url = url
         self.isEditingEnabled = isEditingEnabled
+        self.isCropEnabled = isCropEnabled
         if let metadata = metadata {
             self.metadata = tableMetadata.init(value: metadata)
         }
@@ -73,16 +75,16 @@ private var hasChangesQuickLook: Bool = false
             NCContentPresenter.shared.showInfo(error: error)
         }
 
-        let buttonDone = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(dismission))
-
-        if metadata?.classFile == NKCommon.typeClassFile.image.rawValue {
-            let buttonCrop = UIBarButtonItem(image: UIImage(systemName: "crop"), style: .plain, target: self, action: #selector(crop))
-            navigationItem.leftBarButtonItems = [buttonDone, buttonCrop]
-        } else {
-            navigationItem.leftBarButtonItems = [buttonDone]
+        if isCropEnabled {
+            let buttonDone = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(dismission))
+            if metadata?.classFile == NKCommon.typeClassFile.image.rawValue {
+                let buttonCrop = UIBarButtonItem(image: UIImage(systemName: "crop"), style: .plain, target: self, action: #selector(crop))
+                navigationItem.leftBarButtonItems = [buttonDone, buttonCrop]
+            } else {
+                navigationItem.leftBarButtonItems = [buttonDone]
+            }
+            startTimer(navigationItem: navigationItem)
         }
-
-        startTimer(navigationItem: navigationItem)
     }
 
     func startTimer(navigationItem: UINavigationItem) {