marinofaggiana 5 éve
szülő
commit
4a77f99e93

+ 4 - 0
Nextcloud.xcodeproj/project.pbxproj

@@ -459,6 +459,7 @@
 		F7C40C122199BA620004137E /* RealmSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F7C40C112199BA620004137E /* RealmSwift.framework */; };
 		F7C525A01E3B48B700FFE02C /* CCNotification.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7C5259F1E3B48B700FFE02C /* CCNotification.swift */; };
 		F7C525A21E3B6DA800FFE02C /* CCNotification.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F7C525A11E3B6DA800FFE02C /* CCNotification.storyboard */; };
+		F7C7B489245EBA4100D93E60 /* NCViewerQuickLook.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7C7B488245EBA4100D93E60 /* NCViewerQuickLook.swift */; };
 		F7C9555321F0C4CA0024296E /* NCActivity.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F7C9555221F0C4CA0024296E /* NCActivity.storyboard */; };
 		F7C9555521F0C5470024296E /* NCActivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7C9555421F0C5470024296E /* NCActivity.swift */; };
 		F7CA1ED020E7E3FE002CC65E /* UIImage+PKDownloadButton.m in Sources */ = {isa = PBXBuildFile; fileRef = F7CA1EBC20E7E3FE002CC65E /* UIImage+PKDownloadButton.m */; };
@@ -1121,6 +1122,7 @@
 		F7C525A11E3B6DA800FFE02C /* CCNotification.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = CCNotification.storyboard; path = Notification/CCNotification.storyboard; sourceTree = "<group>"; };
 		F7C742C01E7BD01F00D9C973 /* iOSClient.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; path = iOSClient.entitlements; sourceTree = "<group>"; };
 		F7C742D01E7BD35B00D9C973 /* Share.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; path = Share.entitlements; sourceTree = "<group>"; };
+		F7C7B488245EBA4100D93E60 /* NCViewerQuickLook.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCViewerQuickLook.swift; sourceTree = "<group>"; };
 		F7C8C1901B482CEA0048180E /* CCGlobal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCGlobal.h; sourceTree = "<group>"; };
 		F7C9555221F0C4CA0024296E /* NCActivity.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = NCActivity.storyboard; sourceTree = "<group>"; };
 		F7C9555421F0C5470024296E /* NCActivity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCActivity.swift; sourceTree = "<group>"; };
@@ -1999,6 +2001,7 @@
 				F76D3CEF2428B3DD005DFA87 /* NCViewerPDF */,
 				F790110D21415BF600D7B136 /* NCViewerRichdocument.swift */,
 				F7FB1D3D215E191D00D669EA /* NCViewerDocumentWeb.swift */,
+				F7C7B488245EBA4100D93E60 /* NCViewerQuickLook.swift */,
 				F79630ED215527D40015EEA5 /* NCViewerVideo.swift */,
 			);
 			path = Viewer;
@@ -3305,6 +3308,7 @@
 				F75AC2431F1F62450073EC19 /* NCManageAutoUploadFileName.swift in Sources */,
 				F79630EE215527D40015EEA5 /* NCViewerVideo.swift in Sources */,
 				F7CA1ED620E7E3FE002CC65E /* CALayer+PKDownloadButtonAnimations.m in Sources */,
+				F7C7B489245EBA4100D93E60 /* NCViewerQuickLook.swift in Sources */,
 				F758B45E212C569D00515F55 /* ScanCell.swift in Sources */,
 				F781996922636BFA00EBDF6A /* HCFeatures.m in Sources */,
 				F70022FE1EC4C9100080073F /* UtilsFramework.m in Sources */,

+ 13 - 0
iOSClient/Networking/NCNetworkingNotificationCenter.swift

@@ -72,6 +72,19 @@ import Foundation
                     // open View File
                     if (selector == selectorLoadFileView || selector == selectorLoadFileViewFavorite || selector == selectorLoadFileInternalView) && UIApplication.shared.applicationState == UIApplication.State.active {
                     
+                        //
+                        let quicklook = NCViewerQuickLook.init()
+                        let fileNamePath = NSTemporaryDirectory() + metadata.fileNameView
+
+                        CCUtility.copyFile(atPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView), toPath: fileNamePath)
+
+                        quicklook.quickLook(url: URL(fileURLWithPath: fileNamePath), viewController: appDelegate.activeMain)
+                        
+                        return
+                        
+                        //
+                        
+                        
                         if metadata.contentType.contains("opendocument") && !NCUtility.sharedInstance.isRichDocument(metadata) {
                             metadata.typeFile = k_metadataTypeFile_unknown
                         }

+ 87 - 0
iOSClient/Viewer/NCViewerQuickLook.swift

@@ -0,0 +1,87 @@
+//
+//  NCViewerQuickLook.swift
+//  Nextcloud
+//
+//  Created by Marino Faggiana on 03/05/2020.
+//  Copyright © 2020 Marino Faggiana. All rights reserved.
+//
+
+import Foundation
+import QuickLook
+
+@objc class NCViewerQuickLook: NSObject, QLPreviewControllerDelegate, QLPreviewControllerDataSource {
+
+    let previewController = QLPreviewController()
+    var previewItems: [PreviewItem] = []
+    var viewController: UIViewController?
+        
+    @objc func quickLook(url: URL, viewController: UIViewController) {
+        
+        self.viewController = viewController
+        
+        URLSession.shared.dataTask(with: url) { data, response, error in
+            
+            guard let data = data, error == nil else {
+                self.presentAlertController(with: error?.localizedDescription ?? "Failed to download the pdf!!!")
+                return
+            }
+                        
+            let httpURLResponse = response as? HTTPURLResponse
+            let mimeType = httpURLResponse?.mimeType
+            
+            do {
+                // rename the temporary file or save it to the document or library directory if you want to keep the file
+                let suggestedFilename = httpURLResponse?.suggestedFilename ?? "quicklook.pdf"
+                var previewURL = FileManager.default.temporaryDirectory.appendingPathComponent(suggestedFilename)
+                try data.write(to: previewURL, options: .atomic)   // atomic option overwrites it if needed
+                previewURL.hasHiddenExtension = true
+                let previewItem = PreviewItem()
+                previewItem.previewItemURL = previewURL
+                self.previewItems.append(previewItem)
+                DispatchQueue.main.async {
+                    UIApplication.shared.isNetworkActivityIndicatorVisible = false
+                    self.previewController.delegate = self
+                    self.previewController.dataSource = self
+                    self.previewController.currentPreviewItemIndex = 0
+                    self.viewController?.present(self.previewController, animated: true)
+                 }
+            } catch {
+                print(error)
+                return
+            }
+        }.resume()
+        UIApplication.shared.isNetworkActivityIndicatorVisible = true
+    }
+    
+    func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem { previewItems[index] }
+    
+    func numberOfPreviewItems(in controller: QLPreviewController) -> Int {
+        previewItems.count
+    }
+    
+    func presentAlertController(with message: String) {
+         // present your alert controller from the main thread
+        DispatchQueue.main.async {
+            UIApplication.shared.isNetworkActivityIndicatorVisible = false
+            let alert = UIAlertController(title: "Alert", message: message, preferredStyle: .alert)
+            alert.addAction(.init(title: "OK", style: .default))
+            self.viewController?.present(alert, animated: true)
+        }
+    }
+}
+
+extension URL {
+    var hasHiddenExtension: Bool {
+        get { (try? resourceValues(forKeys: [.hasHiddenExtensionKey]))?.hasHiddenExtension == true }
+        set {
+            var resourceValues = URLResourceValues()
+            resourceValues.hasHiddenExtension = newValue
+            try? setResourceValues(resourceValues)
+        }
+    }
+}
+
+import QuickLook
+class PreviewItem: NSObject, QLPreviewItem {
+    var previewItemURL: URL?
+}