marinofaggiana 5 жил өмнө
parent
commit
91f6fe040d

+ 4 - 144
iOSClient/Viewer/NCViewerNextcloudText.swift

@@ -1,9 +1,9 @@
 //
-//  NCViewerRichdocument.swift
+//  NCViewerNextcloudText.swift
 //  Nextcloud
 //
 //  Created by Marino Faggiana on 12/12/19.
-//  Copyright © 2018 Marino Faggiana. All rights reserved.
+//  Copyright © 2019 Marino Faggiana. All rights reserved.
 //
 //  Author Marino Faggiana <marino.faggiana@nextcloud.com>
 //
@@ -23,7 +23,7 @@
 
 import Foundation
 
-class NCViewerNextcloudText: WKWebView, WKNavigationDelegate, WKScriptMessageHandler, NCSelectDelegate {
+class NCViewerNextcloudText: WKWebView, WKNavigationDelegate, WKScriptMessageHandler {
     
     let appDelegate = UIApplication.shared.delegate as! AppDelegate
     var detail: CCDetail!
@@ -44,7 +44,7 @@ class NCViewerNextcloudText: WKWebView, WKNavigationDelegate, WKScriptMessageHan
         super.init(coder: coder)
     }
     
-    @objc func viewRichDocumentAt(_ link: String, detail: CCDetail, metadata: tableMetadata) {
+    @objc func viewNextcloudTextAt(_ link: String, detail: CCDetail, metadata: tableMetadata) {
         
         self.detail = detail
         self.metadata = metadata
@@ -82,148 +82,8 @@ class NCViewerNextcloudText: WKWebView, WKNavigationDelegate, WKScriptMessageHan
 
     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: -