marinofaggiana 3 lat temu
rodzic
commit
29a4381205

+ 1 - 1
iOSClient/Main/Create cloud/NCCreateFormUploadDocuments.swift

@@ -274,7 +274,7 @@ import NCCommunication
         } else {
             
             let result = NCCommunicationCommon.shared.getInternalType(fileName: fileNameForm as! String, mimeType: "", directory: false)
-            if NCUtility.shared.isDirectEditing(account: appDelegate.account, contentType: result.mimeType) == nil {
+            if NCUtility.shared.isDirectEditing(account: appDelegate.account, contentType: result.mimeType).count == 0 {
                 fileNameForm = (fileNameForm as! NSString).deletingPathExtension + "." + fileNameExtension
             }
             

+ 36 - 1
iOSClient/Menu/NCCollectionViewCommon+Menu.swift

@@ -67,7 +67,10 @@ extension NCCollectionViewCommon {
                 isOffline = localFile.offline
             }
         }
-            
+        
+        let editors = NCUtility.shared.isDirectEditing(account: metadata.account, contentType: metadata.contentType)
+        let isRichDocument = NCUtility.shared.isRichDocument(metadata)
+
         var iconHeader: UIImage!
         
         if imageIcon != nil {
@@ -152,6 +155,38 @@ extension NCCollectionViewCommon {
             )
         }
         
+        //
+        // OPEN with external editor
+        //
+        if metadata.typeFile == NCGlobal.shared.metadataTypeFileDocument && editors.contains(NCGlobal.shared.editorText) && ((editors.contains(NCGlobal.shared.editorOnlyoffice) || isRichDocument))  {
+            
+            var editor = ""
+            var title = ""
+            var icon: UIImage?
+            
+            if editors.contains(NCGlobal.shared.editorOnlyoffice) {
+                editor = NCGlobal.shared.editorOnlyoffice
+                title = NSLocalizedString("_open_in_onlyoffice_", comment: "")
+                icon = NCUtility.shared.loadImage(named: "onlyoffice")
+            } else if isRichDocument {
+                editor = NCGlobal.shared.editorCollabora
+                title = NSLocalizedString("_open_in_collabora_", comment: "")
+                icon = NCUtility.shared.loadImage(named: "collabora")
+            }
+            
+            if editor != "" {
+                actions.append(
+                    NCMenuAction(
+                        title: title,
+                        icon: icon!,
+                        action: { menuAction in
+                            NCViewer.shared.view(viewController: self, metadata: metadata, metadatas: [metadata], imageIcon: imageIcon, editor: editor, isRichDocument: isRichDocument)
+                        }
+                    )
+                )
+            }
+        }
+        
         //
         // OPEN IN
         //

+ 2 - 0
iOSClient/Supporting Files/en.lproj/Localizable.strings

@@ -806,6 +806,8 @@
 "_1_week_"                  = "1 week";
 "_1_day_"                   = "1 day";
 "_used_space_"              = "Used space";
+"_open_in_onlyoffice_"      = "Open in ONLYOFFICE";
+"_open_in_collabora_"       = "Open with Collabora Online";
 
 // ----------------------------------------------------------------------------------------------------------------------------------
 // IM

+ 19 - 11
iOSClient/Utility/NCUtility.swift

@@ -213,6 +213,14 @@ class NCUtility: NSObject {
             return false
         }
         
+        // contentype
+        for richdocumentMimetype: String in richdocumentsMimetypes {
+            if richdocumentMimetype.contains(metadata.contentType) || metadata.contentType == "text/plain" {
+                return true
+            }
+        }
+        
+        // mimetype
         if richdocumentsMimetypes.count > 0 && mimeType.components(separatedBy: ".").count > 2 {
             
             let mimeTypeArray = mimeType.components(separatedBy: ".")
@@ -228,9 +236,9 @@ class NCUtility: NSObject {
         return false
     }
     
-    @objc func isDirectEditing(account: String, contentType: String) -> String? {
+    @objc func isDirectEditing(account: String, contentType: String) -> [String] {
         
-        var editor: String?
+        var editor: [String] = []
         
         guard let results = NCManageDatabase.shared.getDirectEditingEditors(account: account) else {
             return editor
@@ -239,32 +247,32 @@ class NCUtility: NSObject {
         for result: tableDirectEditingEditors in results {
             for mimetype in result.mimetypes {
                 if mimetype == contentType {
-                    editor = result.editor
+                    editor.append(result.editor)
                 }
                 
                 // HARDCODE
                 // https://github.com/nextcloud/text/issues/913
                 
                 if mimetype == "text/markdown" && contentType == "text/x-markdown" {
-                    editor = result.editor
+                    editor.append(result.editor)
                 }
                 if contentType == "text/html" {
-                    editor = result.editor
+                    editor.append(result.editor)
                 }
             }
             for mimetype in result.optionalMimetypes {
                 if mimetype == contentType {
-                    editor = result.editor
+                    editor.append(result.editor)
                 }
             }
         }
         
         // HARDCODE
-        if editor == "" {
-            editor = NCGlobal.shared.editorText
-        }
-        
-        return editor
+        //if editor.count == 0 {
+        //    editor.append(NCGlobal.shared.editorText)
+        //}
+                
+        return Array(Set(editor))
     }
     
     @objc func removeAllSettings() {

+ 61 - 49
iOSClient/Viewer/NCViewer.swift

@@ -35,10 +35,12 @@ class NCViewer: NSObject {
     private var metadata = tableMetadata()
     private var metadatas: [tableMetadata] = []
 
-    func view(viewController: UIViewController, metadata: tableMetadata, metadatas: [tableMetadata], imageIcon: UIImage?) {
+    func view(viewController: UIViewController, metadata: tableMetadata, metadatas: [tableMetadata], imageIcon: UIImage?, editor: String = "", isRichDocument: Bool = false) {
 
         self.metadata = metadata
         self.metadatas = metadatas
+    
+        var editor = editor
         
         // IMAGE AUDIO VIDEO
         if metadata.typeFile == NCGlobal.shared.metadataTypeFileImage || metadata.typeFile == NCGlobal.shared.metadataTypeFileAudio || metadata.typeFile == NCGlobal.shared.metadataTypeFileVideo {
@@ -79,10 +81,66 @@ class NCViewer: NSObject {
                 return
             }
             
+            // EDITORS
+            let editors = NCUtility.shared.isDirectEditing(account: metadata.account, contentType: metadata.contentType)
+            
+            // RichDocument: Collabora
+            if isRichDocument && NCCommunication.shared.isNetworkReachable() {
+                                
+                if metadata.url == "" {
+                    
+                    NCUtility.shared.startActivityIndicator(backgroundView: viewController.view, blurEffect: true)
+                    NCCommunication.shared.createUrlRichdocuments(fileID: metadata.fileId) { (account, url, errorCode, errorDescription) in
+                        
+                        NCUtility.shared.stopActivityIndicator()
+
+                        if errorCode == 0 && account == self.appDelegate.account && url != nil {
+                                                          
+                            if let navigationController = viewController.navigationController {
+                                
+                                let viewController:NCViewerRichdocument = UIStoryboard(name: "NCViewerRichdocument", bundle: nil).instantiateInitialViewController() as! NCViewerRichdocument
+                            
+                                viewController.metadata = metadata
+                                viewController.link = url!
+                                viewController.imageIcon = imageIcon
+                            
+                                navigationController.pushViewController(viewController, animated: true)
+                            }
+                            
+                        } else if errorCode != 0 {
+                            
+                            NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
+                        }
+                    }
+                    
+                } else {
+                                            
+                    if let navigationController = viewController.navigationController {
+                        
+                        let viewController:NCViewerRichdocument = UIStoryboard(name: "NCViewerRichdocument", bundle: nil).instantiateInitialViewController() as! NCViewerRichdocument
+                    
+                        viewController.metadata = metadata
+                        viewController.link = metadata.url
+                        viewController.imageIcon = imageIcon
+                    
+                        navigationController.pushViewController(viewController, animated: true)
+                    }
+                }
+                
+                return
+            }
+            
             // DirectEditing: Nextcloud Text - OnlyOffice
-            if NCUtility.shared.isDirectEditing(account: metadata.account, contentType: metadata.contentType) != nil && NCCommunication.shared.isNetworkReachable() {
+            if editors.count > 0 && NCCommunication.shared.isNetworkReachable() {
+            
+                if editor == "" {
+                    if editors.contains(NCGlobal.shared.editorText) {
+                        editor = NCGlobal.shared.editorText
+                    } else if editors.contains(NCGlobal.shared.editorOnlyoffice) {
+                        editor = NCGlobal.shared.editorOnlyoffice
+                    }
+                }
                 
-                guard let editor = NCUtility.shared.isDirectEditing(account: metadata.account, contentType: metadata.contentType) else { return }
                 if editor == NCGlobal.shared.editorText || editor == NCGlobal.shared.editorOnlyoffice {
                     
                     if metadata.url == "" {
@@ -141,52 +199,6 @@ class NCViewer: NSObject {
                 
                 return
             }
-            
-            // RichDocument: Collabora
-            if NCUtility.shared.isRichDocument(metadata) && NCCommunication.shared.isNetworkReachable() {
-                                
-                if metadata.url == "" {
-                    
-                    NCUtility.shared.startActivityIndicator(backgroundView: viewController.view, blurEffect: true)
-                    NCCommunication.shared.createUrlRichdocuments(fileID: metadata.fileId) { (account, url, errorCode, errorDescription) in
-                        
-                        NCUtility.shared.stopActivityIndicator()
-
-                        if errorCode == 0 && account == self.appDelegate.account && url != nil {
-                                                          
-                            if let navigationController = viewController.navigationController {
-                                
-                                let viewController:NCViewerRichdocument = UIStoryboard(name: "NCViewerRichdocument", bundle: nil).instantiateInitialViewController() as! NCViewerRichdocument
-                            
-                                viewController.metadata = metadata
-                                viewController.link = url!
-                                viewController.imageIcon = imageIcon
-                            
-                                navigationController.pushViewController(viewController, animated: true)
-                            }
-                            
-                        } else if errorCode != 0 {
-                            
-                            NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
-                        }
-                    }
-                    
-                } else {
-                                            
-                    if let navigationController = viewController.navigationController {
-                        
-                        let viewController:NCViewerRichdocument = UIStoryboard(name: "NCViewerRichdocument", bundle: nil).instantiateInitialViewController() as! NCViewerRichdocument
-                    
-                        viewController.metadata = metadata
-                        viewController.link = metadata.url
-                        viewController.imageIcon = imageIcon
-                    
-                        navigationController.pushViewController(viewController, animated: true)
-                    }
-                }
-                
-                return
-            }
         }
         
         // OTHER