marinofaggiana 4 年之前
父節點
當前提交
f7451373dc

+ 13 - 1
Nextcloud.xcodeproj/project.pbxproj

@@ -88,6 +88,7 @@
 		F73B422B2476764F00A30FD3 /* NCNotification.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F73B42292476764F00A30FD3 /* NCNotification.storyboard */; };
 		F73B422C2476764F00A30FD3 /* NCNotification.swift in Sources */ = {isa = PBXBuildFile; fileRef = F73B422A2476764F00A30FD3 /* NCNotification.swift */; };
 		F73CB3B222E072A000AD728E /* NCShareHeaderView.xib in Resources */ = {isa = PBXBuildFile; fileRef = F73CB3B122E072A000AD728E /* NCShareHeaderView.xib */; };
+		F73D11FA253C5F4800DF9BEC /* NCViewerNextcloudText.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F73D11F9253C5F4800DF9BEC /* NCViewerNextcloudText.storyboard */; };
 		F73D5E47246DE09200DF6467 /* NCElementsJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = F73D5E46246DE09200DF6467 /* NCElementsJSON.swift */; };
 		F73D5E48246DE09200DF6467 /* NCElementsJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = F73D5E46246DE09200DF6467 /* NCElementsJSON.swift */; };
 		F73D5E49246DE09200DF6467 /* NCElementsJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = F73D5E46246DE09200DF6467 /* NCElementsJSON.swift */; };
@@ -440,6 +441,7 @@
 		F73B422A2476764F00A30FD3 /* NCNotification.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = NCNotification.swift; path = Notification/NCNotification.swift; sourceTree = "<group>"; };
 		F73CB3B122E072A000AD728E /* NCShareHeaderView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NCShareHeaderView.xib; sourceTree = "<group>"; };
 		F73CB5771ED46807005F2A5A /* NCBridgeSwift.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NCBridgeSwift.h; sourceTree = "<group>"; };
+		F73D11F9253C5F4800DF9BEC /* NCViewerNextcloudText.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = NCViewerNextcloudText.storyboard; sourceTree = "<group>"; };
 		F73D5E46246DE09200DF6467 /* NCElementsJSON.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCElementsJSON.swift; sourceTree = "<group>"; };
 		F73F537E1E929C8500F8678D /* CCMore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CCMore.swift; sourceTree = "<group>"; };
 		F7417DB2216CE925007D05F5 /* NCTrashSectionHeaderFooter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCTrashSectionHeaderFooter.swift; sourceTree = "<group>"; };
@@ -946,6 +948,15 @@
 			path = Offline;
 			sourceTree = "<group>";
 		};
+		F73D11FF253C5F5400DF9BEC /* NCViewerNextcloudText */ = {
+			isa = PBXGroup;
+			children = (
+				F72D404823D2082500A97FD0 /* NCViewerNextcloudText.swift */,
+				F73D11F9253C5F4800DF9BEC /* NCViewerNextcloudText.storyboard */,
+			);
+			path = NCViewerNextcloudText;
+			sourceTree = "<group>";
+		};
 		F73FAEE224D2CA830090692E /* Diagnostics */ = {
 			isa = PBXGroup;
 			children = (
@@ -1097,7 +1108,7 @@
 				F76D3CEF2428B3DD005DFA87 /* NCViewerPDF */,
 				F71CEB0D253A0B1A00832FFE /* NCViewerVideo */,
 				F79018B1240962C7007C9B6D /* NCViewerImage */,
-				F72D404823D2082500A97FD0 /* NCViewerNextcloudText.swift */,
+				F73D11FF253C5F5400DF9BEC /* NCViewerNextcloudText */,
 				F790110D21415BF600D7B136 /* NCViewerRichdocument.swift */,
 			);
 			path = Viewer;
@@ -1872,6 +1883,7 @@
 				F78ACD54219047D40088454D /* NCSectionFooter.xib in Resources */,
 				F704B5E32430AA6F00632F5F /* NCCreateFormUploadConflict.storyboard in Resources */,
 				F77B0F611D118A16002130FE /* Acknowledgements.rtf in Resources */,
+				F73D11FA253C5F4800DF9BEC /* NCViewerNextcloudText.storyboard in Resources */,
 				F73B422B2476764F00A30FD3 /* NCNotification.storyboard in Resources */,
 				F7D1612023CF19E30039EBBF /* NCViewerRichWorkspace.storyboard in Resources */,
 				F77B0F631D118A16002130FE /* Localizable.strings in Resources */,

+ 4 - 1
iOSClient/Detail/NCDetailViewController.swift

@@ -220,12 +220,14 @@ class NCDetailViewController: UIViewController {
                     
                     // update subview
                     for view in view.subviews {
+                        /*
                         if view is NCViewerNextcloudText {
                             (view as! NCViewerNextcloudText).metadata = self.metadata
                         }
                         else if view is NCViewerRichdocument {
                             (view as! NCViewerRichdocument).metadata = self.metadata
                         }
+                        */
                     }
                 }
             }
@@ -383,7 +385,7 @@ class NCDetailViewController: UIViewController {
         // DOCUMENT
         if metadata.typeFile == k_metadataTypeFile_document {
             
-            
+            /*
             
             // DirectEditinf: Nextcloud Text - OnlyOffice
             if NCUtility.shared.isDirectEditing(account: metadata.account, contentType: metadata.contentType) != nil &&  NCCommunication.shared.isNetworkReachable() {
@@ -439,6 +441,7 @@ class NCDetailViewController: UIViewController {
                 
                 return
             }
+            */
             
             // RichDocument: Collabora
             if NCUtility.shared.isRichDocument(metadata) &&  NCCommunication.shared.isNetworkReachable() {

+ 61 - 0
iOSClient/Viewer/NCViewer.swift

@@ -22,6 +22,7 @@
 //
 
 import Foundation
+import NCCommunication
 
 class NCViewer: NSObject {
     @objc static let shared: NCViewer = {
@@ -62,6 +63,66 @@ class NCViewer: NSObject {
                 }
                 return
             }
+            
+            // DirectEditinf: Nextcloud Text - OnlyOffice
+            if NCUtility.shared.isDirectEditing(account: metadata.account, contentType: metadata.contentType) != nil &&  NCCommunication.shared.isNetworkReachable() {
+                
+                guard let editor = NCUtility.shared.isDirectEditing(account: metadata.account, contentType: metadata.contentType) else { return }
+                if editor == k_editor_text || editor == k_editor_onlyoffice {
+                    
+                    if metadata.url == "" {
+                        
+                        var customUserAgent: String?
+                        let fileNamePath = CCUtility.returnFileNamePath(fromFileName: metadata.fileName, serverUrl: metadata.serverUrl, urlBase: metadata.urlBase, account: metadata.account)!
+                        
+                        if editor == k_editor_onlyoffice {
+                            customUserAgent = NCUtility.shared.getCustomUserAgentOnlyOffice()
+                            //self.navigationController?.navigationBar.topItem?.title = ""
+                        }
+                        
+                        NCCommunication.shared.NCTextOpenFile(fileNamePath: fileNamePath, editor: editor, customUserAgent: customUserAgent) { (account, url, errorCode, errorMessage) in
+                            
+                            if errorCode == 0 && account == self.appDelegate.account && url != nil {
+                                
+                                if let navigationController = self.getPushNavigationController(viewController: viewController, serverUrl: metadata.serverUrl) {
+                                    let viewController:NCViewerNextcloudText = UIStoryboard(name: "NCViewerNextcloudText", bundle: nil).instantiateInitialViewController() as! NCViewerNextcloudText
+                                
+                                    viewController.metadata = metadata
+                                    viewController.editor = editor
+                                    viewController.link = url!
+                                
+                                    navigationController.pushViewController(viewController, animated: true)
+                                }
+                                
+                            } else if errorCode != 0 {
+                                
+                                NCContentPresenter.shared.messageNotification("_error_", description: errorMessage, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: errorCode)
+                            }
+                        }
+                        
+                    } else {
+                        
+                        if editor == k_editor_onlyoffice {
+                            //self.navigationController?.navigationBar.topItem?.title = ""
+                        }
+                            
+                        if let navigationController = self.getPushNavigationController(viewController: viewController, serverUrl: metadata.serverUrl) {
+                            let viewController:NCViewerNextcloudText = UIStoryboard(name: "NCViewerNextcloudText", bundle: nil).instantiateInitialViewController() as! NCViewerNextcloudText
+                        
+                            viewController.metadata = metadata
+                            viewController.editor = editor
+                            viewController.link = metadata.url
+                        
+                            navigationController.pushViewController(viewController, animated: true)
+                        }
+                    }
+                } else {
+                    NCContentPresenter.shared.messageNotification("_error_", description: "_editor_unknown_", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: Int(k_CCErrorInternalError))
+                }
+                
+                return
+            }
+            
         }
         
         // OTHER

+ 33 - 0
iOSClient/Viewer/NCViewerNextcloudText/NCViewerNextcloudText.storyboard

@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17156" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="Ov9-Mv-xPL">
+    <device id="retina6_1" orientation="portrait" appearance="light"/>
+    <dependencies>
+        <deployment identifier="iOS"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17125"/>
+        <capability name="Safe area layout guides" minToolsVersion="9.0"/>
+        <capability name="System colors in document resources" minToolsVersion="11.0"/>
+        <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
+    </dependencies>
+    <scenes>
+        <!--Viewer Nextcloud Text-->
+        <scene sceneID="mqn-3b-5TY">
+            <objects>
+                <viewController hidesBottomBarWhenPushed="YES" id="Ov9-Mv-xPL" customClass="NCViewerNextcloudText" customModule="Nextcloud" customModuleProvider="target" sceneMemberID="viewController">
+                    <view key="view" contentMode="scaleToFill" id="lUw-uE-JhW">
+                        <rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
+                        <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
+                        <viewLayoutGuide key="safeArea" id="iN8-Oo-EgM"/>
+                        <color key="backgroundColor" systemColor="systemBackgroundColor"/>
+                    </view>
+                </viewController>
+                <placeholder placeholderIdentifier="IBFirstResponder" id="CxR-CZ-Cnd" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
+            </objects>
+            <point key="canvasLocation" x="23" y="60"/>
+        </scene>
+    </scenes>
+    <resources>
+        <systemColor name="systemBackgroundColor">
+            <color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
+        </systemColor>
+    </resources>
+</document>

+ 29 - 35
iOSClient/Viewer/NCViewerNextcloudText.swift → iOSClient/Viewer/NCViewerNextcloudText/NCViewerNextcloudText.swift

@@ -24,41 +24,37 @@
 import Foundation
 import WebKit
 
-class NCViewerNextcloudText: WKWebView, WKNavigationDelegate, WKScriptMessageHandler {
+class NCViewerNextcloudText: UIViewController, WKNavigationDelegate, WKScriptMessageHandler {
     
     let appDelegate = UIApplication.shared.delegate as! AppDelegate
-    var editor: String!
-    var metadata: tableMetadata!
-    var view: UIView!
-    var viewController: UIViewController!
+    var webView = WKWebView()
+    
+    var link: String = ""
+    var editor: String = ""
+    var metadata: tableMetadata = tableMetadata()
     var documentInteractionController: UIDocumentInteractionController!
    
-    override init(frame: CGRect, configuration: WKWebViewConfiguration) {
-        super.init(frame: frame, configuration: configuration)
-
-        let contentController = configuration.userContentController
-        contentController.add(self, name: "DirectEditingMobileInterface")
-        
-        autoresizingMask = [.flexibleWidth, .flexibleHeight]
-        navigationDelegate = self
-    }
-    
     required init?(coder: NSCoder) {
         super.init(coder: coder)
     }
     
-    override func layoutSubviews() {
-        super.layoutSubviews()
-        self.frame = CGRect(x: 0, y: 0, width: self.frame.width, height: self.frame.height)
-    }
-    
-    @objc func viewerAt(_ link: String, metadata: tableMetadata, editor: String, view: UIView, viewController: UIViewController) {
-                
-        self.metadata = metadata
-        self.editor = editor
-        self.view = view
-        self.viewController = viewController
-
+    override func viewDidLoad() {
+        super.viewDidLoad()
+             
+        let config = WKWebViewConfiguration()
+        config.websiteDataStore = WKWebsiteDataStore.nonPersistent()
+        let contentController = config.userContentController
+        contentController.add(self, name: "DirectEditingMobileInterface")
+        
+        webView = WKWebView(frame: CGRect.zero, configuration: config)
+        webView.navigationDelegate = self
+        view.addSubview(webView)
+        webView.translatesAutoresizingMaskIntoConstraints = false
+        webView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 0).isActive = true
+        webView.rightAnchor.constraint(equalTo: view.rightAnchor, constant: 0).isActive = true
+        webView.topAnchor.constraint(equalTo: view.topAnchor, constant: 0).isActive = true
+        webView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 0).isActive = true
+        
         NotificationCenter.default.addObserver(self, selector: #selector(keyboardDidShow), name: UIResponder.keyboardDidShowNotification, object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil)
         
@@ -68,25 +64,23 @@ class NCViewerNextcloudText: WKWebView, WKNavigationDelegate, WKScriptMessageHan
         request.addValue(language, forHTTPHeaderField: "Accept-Language")
                 
         if editor == k_editor_onlyoffice {
-            customUserAgent = NCUtility.shared.getCustomUserAgentOnlyOffice()
+            webView.customUserAgent = NCUtility.shared.getCustomUserAgentOnlyOffice()
         } else {
-            customUserAgent = CCUtility.getUserAgent()
+            webView.customUserAgent = CCUtility.getUserAgent()
         }
         
-        load(request)
-        
-        self.view.addSubview(self)
+        webView.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
-        frame.size.height = view.frame.height - keyboardFrame.size.height
+        self.view.frame.size.height = view.frame.height - keyboardFrame.size.height
     }
     
     @objc func keyboardWillHide(notification: Notification) {
-        frame = view.frame
+        self.view.frame = view.frame
     }
     
     //MARK: -
@@ -102,7 +96,7 @@ class NCViewerNextcloudText: WKWebView, WKNavigationDelegate, WKScriptMessageHan
             }
             
             if message.body as? String == "share" {
-                NCNetworkingNotificationCenter.shared.openShare(ViewController: viewController, metadata: metadata, indexPage: 2)
+                NCNetworkingNotificationCenter.shared.openShare(ViewController: self, metadata: metadata, indexPage: 2)
             }
             
             if message.body as? String == "loading" {