marinofaggiana 5 år sedan
förälder
incheckning
7830eb647f

+ 10 - 6
Nextcloud.xcodeproj/project.pbxproj

@@ -87,6 +87,7 @@
 		F716FE7823795E5000FABE50 /* NCCommunication.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F716FE7723795E5000FABE50 /* NCCommunication.framework */; settings = {ATTRIBUTES = (Required, ); }; };
 		F716FE7A23795EC500FABE50 /* FileProviderExtension+NetworkingDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F716FE7923795EC500FABE50 /* FileProviderExtension+NetworkingDelegate.swift */; };
 		F7226EDC1EE4089300EBECB1 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F7226EDB1EE4089300EBECB1 /* Main.storyboard */; };
+		F7233CEE23A24F990011D898 /* NCViewerNextcloudText.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7233CED23A24F990011D898 /* NCViewerNextcloudText.swift */; };
 		F72382C02295856A005B8A07 /* FirebaseMLVisionTextModel.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F72382BB22958569005B8A07 /* FirebaseMLVisionTextModel.framework */; };
 		F72382C22295856A005B8A07 /* GoogleMVTextDetectorResources.bundle in Resources */ = {isa = PBXBuildFile; fileRef = F72382BE22958569005B8A07 /* GoogleMVTextDetectorResources.bundle */; };
 		F72382C32295856A005B8A07 /* GoogleToolboxForMac.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F72382BF22958569005B8A07 /* GoogleToolboxForMac.framework */; };
@@ -756,6 +757,7 @@
 		F716FE7923795EC500FABE50 /* FileProviderExtension+NetworkingDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FileProviderExtension+NetworkingDelegate.swift"; sourceTree = "<group>"; };
 		F7226EDB1EE4089300EBECB1 /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = "<group>"; };
 		F7229B491DF71BB300E8C4E7 /* AUTHORS */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = AUTHORS; sourceTree = SOURCE_ROOT; };
+		F7233CED23A24F990011D898 /* NCViewerNextcloudText.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCViewerNextcloudText.swift; sourceTree = "<group>"; };
 		F72382BB22958569005B8A07 /* FirebaseMLVisionTextModel.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = FirebaseMLVisionTextModel.framework; sourceTree = "<group>"; };
 		F72382BE22958569005B8A07 /* GoogleMVTextDetectorResources.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = GoogleMVTextDetectorResources.bundle; sourceTree = "<group>"; };
 		F72382BF22958569005B8A07 /* GoogleToolboxForMac.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = GoogleToolboxForMac.framework; sourceTree = "<group>"; };
@@ -2269,6 +2271,7 @@
 			children = (
 				F790110D21415BF600D7B136 /* NCViewerRichdocument.swift */,
 				F7FB1D3D215E191D00D669EA /* NCViewerDocumentWeb.swift */,
+				F7233CED23A24F990011D898 /* NCViewerNextcloudText.swift */,
 				F79630ED215527D40015EEA5 /* NCViewerMedia.swift */,
 			);
 			path = Viewer;
@@ -3691,6 +3694,7 @@
 				F762CB151EACB66200B38484 /* XLFormRowNavigationAccessoryView.m in Sources */,
 				F762CB0A1EACB66200B38484 /* XLFormDescriptor.m in Sources */,
 				F7D4238C1F0596C6009C9782 /* UIXToolbarView.m in Sources */,
+				F7233CEE23A24F990011D898 /* NCViewerNextcloudText.swift in Sources */,
 				F7020FCE2233D7F700B7297D /* NCCreateFormUploadVoiceNote.swift in Sources */,
 				F726EEEC1FED1C820030B9C8 /* NCEndToEndInitialize.swift in Sources */,
 				F79A65C62191D95E00FF6DCC /* NCSelect.swift in Sources */,
@@ -3850,7 +3854,7 @@
 				CODE_SIGN_ENTITLEMENTS = iOSClient/Brand/Share.entitlements;
 				CODE_SIGN_IDENTITY = "iPhone Developer";
 				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
-				CURRENT_PROJECT_VERSION = 7;
+				CURRENT_PROJECT_VERSION = 8;
 				DEBUG_INFORMATION_FORMAT = dwarf;
 				DEVELOPMENT_TEAM = 6JLRKY9ZV7;
 				FRAMEWORK_SEARCH_PATHS = (
@@ -3894,7 +3898,7 @@
 				CODE_SIGN_ENTITLEMENTS = iOSClient/Brand/Share.entitlements;
 				CODE_SIGN_IDENTITY = "iPhone Developer";
 				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
-				CURRENT_PROJECT_VERSION = 7;
+				CURRENT_PROJECT_VERSION = 8;
 				DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
 				DEVELOPMENT_TEAM = 6JLRKY9ZV7;
 				FRAMEWORK_SEARCH_PATHS = (
@@ -3944,7 +3948,7 @@
 				CODE_SIGN_IDENTITY = "iPhone Developer";
 				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
 				CODE_SIGN_STYLE = Automatic;
-				CURRENT_PROJECT_VERSION = 7;
+				CURRENT_PROJECT_VERSION = 8;
 				DEBUG_INFORMATION_FORMAT = dwarf;
 				DEVELOPMENT_TEAM = 6JLRKY9ZV7;
 				FRAMEWORK_SEARCH_PATHS = (
@@ -3994,7 +3998,7 @@
 				CODE_SIGN_IDENTITY = "iPhone Developer";
 				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
 				CODE_SIGN_STYLE = Automatic;
-				CURRENT_PROJECT_VERSION = 7;
+				CURRENT_PROJECT_VERSION = 8;
 				DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
 				DEVELOPMENT_TEAM = 6JLRKY9ZV7;
 				FRAMEWORK_SEARCH_PATHS = (
@@ -4036,7 +4040,7 @@
 				CODE_SIGN_ENTITLEMENTS = iOSClient/Brand/iOSClient.entitlements;
 				CODE_SIGN_IDENTITY = "iPhone Developer";
 				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
-				CURRENT_PROJECT_VERSION = 7;
+				CURRENT_PROJECT_VERSION = 8;
 				DEVELOPMENT_TEAM = 6JLRKY9ZV7;
 				ENABLE_BITCODE = YES;
 				FRAMEWORK_SEARCH_PATHS = (
@@ -4083,7 +4087,7 @@
 				CODE_SIGN_IDENTITY = "iPhone Developer";
 				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
 				COPY_PHASE_STRIP = NO;
-				CURRENT_PROJECT_VERSION = 7;
+				CURRENT_PROJECT_VERSION = 8;
 				DEVELOPMENT_TEAM = 6JLRKY9ZV7;
 				ENABLE_BITCODE = YES;
 				FRAMEWORK_SEARCH_PATHS = (

+ 10 - 5
iOSClient/Main/CCDetail.m

@@ -218,6 +218,7 @@
         
         // Direct Editing
         if ([[NCUtility sharedInstance] isDirectEditing:self.metadataDetail] != nil && appDelegate.reachability.isReachable) {
+            
             NSString *editor = [[NCUtility sharedInstance] isDirectEditing:self.metadataDetail];
             if ([editor.lowercaseString isEqualToString:@"nextcloud text"]) {
                 
@@ -231,15 +232,19 @@
                         
                     } else {
                         
-                        [[NCUtility sharedInstance] stopActivityIndicator];
+                        if (errorCode != 0) {
+                            [appDelegate messageNotification:@"_error_" description:errorMessage visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
+                        } else {
+                            NSLog(@"[LOG] It has been changed user during networking process, error.");
+                        }
                         
-                        self.edgesForExtendedLayout = UIRectEdgeBottom;
-                        [self createToolbar];
-                        [[NCViewerDocumentWeb sharedInstance] viewDocumentWebAt:self.metadataDetail detail:self];
+                        [self.navigationController popViewControllerAnimated:YES];
                     }
-                    
                 }];
                 
+            } else {
+                
+                
             }
             return;
         }

+ 249 - 0
iOSClient/Viewer/NCViewerNextcloudText.swift

@@ -0,0 +1,249 @@
+//
+//  NCViewerRichdocument.swift
+//  Nextcloud
+//
+//  Created by Marino Faggiana on 12/12/19.
+//  Copyright © 2018 Marino Faggiana. All rights reserved.
+//
+//  Author Marino Faggiana <marino.faggiana@nextcloud.com>
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+import Foundation
+
+class NCViewerNextcloudText: WKWebView, WKNavigationDelegate, WKScriptMessageHandler, NCSelectDelegate {
+    
+    let appDelegate = UIApplication.shared.delegate as! AppDelegate
+    var detail: CCDetail!
+    @objc var metadata: tableMetadata!
+    var documentInteractionController: UIDocumentInteractionController!
+   
+    override init(frame: CGRect, configuration: WKWebViewConfiguration) {
+        super.init(frame: frame, configuration: configuration)
+
+        let contentController = configuration.userContentController
+        contentController.add(self, name: "RichDocumentsMobileInterface")
+        
+        autoresizingMask = [.flexibleWidth, .flexibleHeight]
+        navigationDelegate = self
+    }
+    
+    required init?(coder: NSCoder) {
+        super.init(coder: coder)
+    }
+    
+    @objc func viewRichDocumentAt(_ link: String, detail: CCDetail, metadata: tableMetadata) {
+        
+        self.detail = detail
+        self.metadata = metadata
+        
+        NotificationCenter.default.addObserver(self, selector: #selector(keyboardDidShow), name: UIResponder.keyboardDidShowNotification, object: nil)
+        NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil)
+        
+        if (UIDevice.current.userInterfaceIdiom == .phone) {
+            detail.navigationController?.setNavigationBarHidden(true, animated: false)
+        }
+        
+        var request = URLRequest(url: URL(string: link)!)
+        request.addValue("true", forHTTPHeaderField: "OCS-APIRequest")
+        let language = NSLocale.preferredLanguages[0] as String
+        request.addValue(language, forHTTPHeaderField: "Accept-Language")
+        
+        let userAgent : String = CCUtility.getUserAgent()
+        customUserAgent = userAgent
+        load(request)        
+    }
+    
+    @objc func keyboardDidShow(notification: Notification) {
+        guard let info = notification.userInfo else { return }
+        guard let frameInfo = info[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue else { return }
+        let keyboardFrame = frameInfo.cgRectValue
+        //print("keyboardFrame: \(keyboardFrame)")
+        frame.size.height = detail.view.bounds.height - keyboardFrame.size.height
+    }
+    
+    @objc func keyboardWillHide(notification: Notification) {
+        frame = detail.view.bounds
+    }
+    
+    //MARK: -
+
+    public func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
+        
+        if (message.name == "RichDocumentsMobileInterface") {
+            
+            if message.body as? String == "close" {
+                
+                removeFromSuperview()
+                
+                detail.navigationController?.popViewController(animated: true)
+                detail.navigationController?.navigationBar.topItem?.title = ""
+            }
+            
+            if message.body as? String == "insertGraphic" {
+                
+                let storyboard = UIStoryboard(name: "NCSelect", bundle: nil)
+                let navigationController = storyboard.instantiateInitialViewController() as! UINavigationController
+                let viewController = navigationController.topViewController as! NCSelect
+                
+                viewController.delegate = self
+                viewController.hideButtonCreateFolder = true
+                viewController.selectFile = true
+                viewController.includeDirectoryE2EEncryption = false
+                viewController.includeImages = true
+                viewController.type = ""
+                viewController.layoutViewSelect = k_layout_view_richdocument
+                
+                navigationController.modalPresentationStyle = UIModalPresentationStyle.fullScreen
+                self.detail.present(navigationController, animated: true, completion: nil)
+            }
+            
+            if message.body as? String == "share" {
+                NCMainCommon.sharedInstance.openShare(ViewController: detail, metadata: metadata, indexPage: 2)
+            }
+            
+            if let param = message.body as? Dictionary<AnyHashable,Any> {
+                if param["MessageName"] as? String == "downloadAs" {
+                    if let values = param["Values"] as? Dictionary<AnyHashable,Any> {
+                        guard let type = values["Type"] as? String else {
+                            return
+                        }
+                        guard let urlString = values["URL"] as? String else {
+                            return
+                        }
+                        guard let url = URL(string: urlString) else {
+                            return
+                        }
+                        guard let components = URLComponents(url: url, resolvingAgainstBaseURL: false) else {
+                            return
+                        }
+                        
+                        let filename = (components.path as NSString).lastPathComponent
+                        let fileNameLocalPath = CCUtility.getDirectoryUserData() + "/" + filename
+                    
+                        if type == "print" {
+                            NCUtility.sharedInstance.startActivityIndicator(view: self, bottom: 0)
+                        }
+                        
+                        _ = OCNetworking.sharedManager()?.download(withAccount: metadata.account, url: urlString, fileNameLocalPath: fileNameLocalPath, encode:false, completion: { (account, message, errorCode) in
+
+                            if errorCode == 0 && account == self.metadata.account {
+                                if type == "print" {
+                                    NCUtility.sharedInstance.stopActivityIndicator()
+                                    let pic = UIPrintInteractionController.shared
+                                    let printInfo = UIPrintInfo.printInfo()
+                                    printInfo.outputType = UIPrintInfo.OutputType.general
+                                    printInfo.orientation = UIPrintInfo.Orientation.portrait
+                                    printInfo.jobName = "Document"
+                                    pic.printInfo = printInfo
+                                    pic.printingItem = URL(fileURLWithPath: fileNameLocalPath)
+                                    pic.present(from: CGRect.zero, in: self, animated: true, completionHandler: { (pci, completed, error) in
+                                        // end.
+                                    })
+                                } else {
+                                    self.documentInteractionController = UIDocumentInteractionController()
+                                    self.documentInteractionController.url = URL(fileURLWithPath: fileNameLocalPath)
+                                    self.documentInteractionController.presentOptionsMenu(from: self.appDelegate.window.rootViewController!.view.bounds, in: self.appDelegate.window.rootViewController!.view, animated: true)
+                                }
+                            } else {
+                                self.appDelegate.messageNotification("_error_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
+                            }
+                        })
+                    }
+                } else if param["MessageName"] as? String == "fileRename" {
+                    if let values = param["Values"] as? Dictionary<AnyHashable,Any> {
+                        guard let newName = values["NewName"] as? String else {
+                            return
+                        }
+                        metadata.fileName = newName
+                        metadata.fileNameView = newName
+                    }
+                }
+            }
+            
+            if message.body as? String == "documentLoaded" {
+                print("documentLoaded")
+            }
+            
+            if message.body as? String == "paste" {
+                self.paste(self)
+            }
+        }
+    }
+    
+    //MARK: -
+
+    @objc func grabFocus() {
+    
+        let functionJS = "OCA.RichDocuments.documentsMain.postGrabFocus()"
+        evaluateJavaScript(functionJS) { (result, error) in }
+    }
+    
+    //MARK: -
+    
+    func dismissSelect(serverUrl: String?, metadata: tableMetadata?, type: String) {
+        
+        if serverUrl != nil && metadata != nil {
+            
+            OCNetworking.sharedManager().createAssetRichdocuments(withAccount: metadata?.account, fileName: metadata?.fileName, serverUrl: serverUrl, completion: { (account, url, message, errorCode) in
+                if errorCode == 0 && account == self.appDelegate.activeAccount {
+                    let functionJS = "OCA.RichDocuments.documentsMain.postAsset('\(metadata!.fileNameView)', '\(url!)')"
+                    self.evaluateJavaScript(functionJS, completionHandler: { (result, error) in })
+                } else if errorCode != 0 {
+                    self.appDelegate.messageNotification("_error_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: Int(k_CCErrorInternalError))
+                } else {
+                    print("[LOG] It has been changed user during networking process, error.")
+                }
+            })
+        }
+    }
+    
+    func select(_ metadata: tableMetadata!, serverUrl: String!) {
+        
+        OCNetworking.sharedManager().createAssetRichdocuments(withAccount: metadata?.account, fileName: metadata?.fileName, serverUrl: serverUrl, completion: { (account, url, message, errorCode) in
+            if errorCode == 0 && account == self.appDelegate.activeAccount {
+                let functionJS = "OCA.RichDocuments.documentsMain.postAsset('\(metadata.fileNameView)', '\(url!)')"
+                self.evaluateJavaScript(functionJS, completionHandler: { (result, error) in })
+            } else if errorCode != 0 {
+                self.appDelegate.messageNotification("_error_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: Int(k_CCErrorInternalError))
+            } else {
+                print("[LOG] It has been changed user during networking process, error.")
+            }
+        })
+    }
+    
+    
+    //MARK: -
+
+    public func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
+        if let serverTrust = challenge.protectionSpace.serverTrust {
+            completionHandler(Foundation.URLSession.AuthChallengeDisposition.useCredential, URLCredential(trust: serverTrust))
+        } else {
+            completionHandler(URLSession.AuthChallengeDisposition.useCredential, nil);
+        }
+    }
+    
+    public func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
+        print("didStartProvisionalNavigation");
+    }
+    
+    public func webView(_ webView: WKWebView, didReceiveServerRedirectForProvisionalNavigation navigation: WKNavigation!) {
+        print("didReceiveServerRedirectForProvisionalNavigation");
+    }
+    
+    public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
+        NCUtility.sharedInstance.stopActivityIndicator()
+    }
+}