marinofaggiana 5 年之前
父节点
当前提交
ca2b7c528c

+ 4 - 0
Nextcloud.xcodeproj/project.pbxproj

@@ -234,6 +234,7 @@
 		F75A9EE823796C6F0044CFCE /* NCNetworking.swift in Sources */ = {isa = PBXBuildFile; fileRef = F75A9EE523796C6F0044CFCE /* NCNetworking.swift */; };
 		F75AC2431F1F62450073EC19 /* NCManageAutoUploadFileName.swift in Sources */ = {isa = PBXBuildFile; fileRef = F75AC2421F1F62450073EC19 /* NCManageAutoUploadFileName.swift */; };
 		F75ADF451DC75FFE008A7347 /* CCLogin.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F75ADF441DC75FFE008A7347 /* CCLogin.storyboard */; };
+		F75C0C4823D1FAE300163CC8 /* NCRichWorkspaceCommon.swift in Sources */ = {isa = PBXBuildFile; fileRef = F75C0C4723D1FAE300163CC8 /* NCRichWorkspaceCommon.swift */; };
 		F75EDFBD1E8C112F00E6F369 /* libsqlite3.0.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = F75EDFBC1E8C112F00E6F369 /* libsqlite3.0.tbd */; };
 		F75EDFBF1E8C116D00E6F369 /* libstdc++.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = F75EDFBE1E8C116D00E6F369 /* libstdc++.tbd */; };
 		F760F77B21F21F61006B1A73 /* icomoon.ttf in Resources */ = {isa = PBXBuildFile; fileRef = F760F75721F21F61006B1A73 /* icomoon.ttf */; };
@@ -913,6 +914,7 @@
 		F75B91E21ECAE17800199C96 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/Localizable.strings; sourceTree = "<group>"; };
 		F75B91F71ECAE26300199C96 /* pt-BR */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "pt-BR"; path = "pt-BR.lproj/Localizable.strings"; sourceTree = "<group>"; };
 		F75B923D1ECAE55E00199C96 /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ru; path = ru.lproj/Localizable.strings; sourceTree = "<group>"; };
+		F75C0C4723D1FAE300163CC8 /* NCRichWorkspaceCommon.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCRichWorkspaceCommon.swift; sourceTree = "<group>"; };
 		F75CDBF51DF063AD00116AD0 /* .gitignore */ = {isa = PBXFileReference; lastKnownFileType = text; name = .gitignore; path = ../.gitignore; sourceTree = "<group>"; };
 		F75EDFBC1E8C112F00E6F369 /* libsqlite3.0.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libsqlite3.0.tbd; path = usr/lib/libsqlite3.0.tbd; sourceTree = SDKROOT; };
 		F75EDFBE1E8C116D00E6F369 /* libstdc++.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = "libstdc++.tbd"; path = "usr/lib/libstdc++.tbd"; sourceTree = SDKROOT; };
@@ -2505,6 +2507,7 @@
 			children = (
 				F7F4B1D723C74B3E00D82A6E /* NCRichWorkspace.swift */,
 				F722814223C8C34500C41898 /* NCRichWorkspace.xib */,
+				F75C0C4723D1FAE300163CC8 /* NCRichWorkspaceCommon.swift */,
 				F78A18B523CDD07D00F681F3 /* NCViewerNextcloudText.swift */,
 				F7D1611F23CF19E30039EBBF /* NCViewerRichWorkspace.storyboard */,
 				F78A18B723CDE2B300F681F3 /* NCViewerRichWorkspace.swift */,
@@ -3587,6 +3590,7 @@
 				F760F77D21F21F61006B1A73 /* ColorsCollectionViewDelegate.swift in Sources */,
 				F7BAADC81ED5A87C00B7EAD4 /* NCDatabase.swift in Sources */,
 				F70022E61EC4C9100080073F /* OCXMLServerErrorsParser.m in Sources */,
+				F75C0C4823D1FAE300163CC8 /* NCRichWorkspaceCommon.swift in Sources */,
 				F762CB171EACB66200B38484 /* XLFormRegexValidator.m in Sources */,
 				F729B92D217A2F1B00FE2150 /* NCActionSheetHeaderView.swift in Sources */,
 				F760F78721F21F61006B1A73 /* PhotoEditor+Font.swift in Sources */,

+ 12 - 19
iOSClient/Main/CCMain.m

@@ -34,7 +34,7 @@
 #import "NCNetworkingEndToEnd.h"
 #import "PKDownloadButton.h"
 
-@interface CCMain () <UITextViewDelegate, createFormUploadAssetsDelegate, MGSwipeTableCellDelegate, NCSelectDelegate, UITextFieldDelegate>
+@interface CCMain () <UITextViewDelegate, createFormUploadAssetsDelegate, MGSwipeTableCellDelegate, NCSelectDelegate, UITextFieldDelegate, UIAdaptivePresentationControllerDelegate>
 {
     AppDelegate *appDelegate;
         
@@ -272,6 +272,11 @@
     }];
 }
 
+- (void)presentationControllerWillDismiss:(UIPresentationController *)presentationController
+{
+    [self viewDidAppear:true];
+}
+
 - (BOOL)prefersStatusBarHidden
 {
     return NO;
@@ -1950,25 +1955,13 @@
 
 - (void)createRichWorkspace
 {
+    NCRichWorkspaceTextCommon *richWorkspaceTextCommon = [NCRichWorkspaceTextCommon new];
     tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND fileNameView LIKE[c] %@", appDelegate.activeAccount, self.serverUrl, k_fileNameRichWorkspace.lowercaseString]];
-    if (metadata && [[NCUtility sharedInstance] isDirectEditing:metadata]) {
-        if (appDelegate.reachability.isReachable) {
-            [self shouldPerformSegue:metadata selector:@""];
-        } else {
-            [[NCContentPresenter shared] messageNotification:@"_info_" description:@"_go_online_" delay:k_dismissAfterSecond type:messageTypeInfo errorCode:0];
-        }
-    } else if (metadata == nil) {
-        NSString *fileNamePath = [CCUtility returnFileNamePathFromFileName:k_fileNameRichWorkspace serverUrl:self.serverUrl activeUrl:appDelegate.activeUrl];
-        [[NCCommunication sharedInstance] NCTextCreateFileWithUrlString:appDelegate.activeUrl fileNamePath:fileNamePath editor:@"text" templateId:@"" account:appDelegate.activeAccount completionHandler:^(NSString *account, NSString *url, NSInteger errorCode, NSString *errorMessage) {
-            if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
-                tableMetadata *metadata = [CCUtility createMetadataWithAccount:appDelegate.activeAccount date:[NSDate date] directory:false ocId:[CCUtility createRandomString:12] serverUrl:self.serverUrl fileName:k_fileNameRichWorkspace etag:@"" size:0 status:k_metadataStatusNormal url:url contentType:@"text/markdown"];
-                [self shouldPerformSegue:metadata selector:@""];
-            } else if (errorCode != 0) {
-                [NCContentPresenter.shared  messageNotification:@"_error_" description:errorMessage delay:k_dismissAfterSecond type:messageTypeError errorCode:errorCode];
-            } else {
-                NSLog(@"[LOG] It has been changed user during networking process, error.");
-            }
-        }];
+    
+    if (metadata) {
+        [richWorkspaceTextCommon openViewerNextcloudTextWithServerUrl:self.serverUrl viewController:self];
+    } else {
+        [richWorkspaceTextCommon createViewerNextcloudTextWithServerUrl:self.serverUrl viewController:self];
     }
 }
 

+ 110 - 0
iOSClient/RichWorkspace/NCRichWorkspaceCommon.swift

@@ -0,0 +1,110 @@
+//
+//  NCRichWorkspaceCommon.swift
+//  Nextcloud
+//
+//  Created by Marino Faggiana on 17/01/2020.
+//  Copyright © 2020 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
+import NCCommunication
+
+@objc class NCRichWorkspaceTextCommon: NSObject {
+
+    let appDelegate = UIApplication.shared.delegate as! AppDelegate
+
+    @objc func createViewerNextcloudText(serverUrl: String,viewController: UIViewController) {
+        
+        if !appDelegate.reachability.isReachable() {
+            
+            NCContentPresenter.shared.messageNotification("_error_", description: "_go_online_", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.info, errorCode: 0)
+            return;
+        }
+        
+        NCUtility.sharedInstance.startActivityIndicator(view: viewController.view, bottom: 0)
+        
+        let fileNamePath = CCUtility.returnFileNamePath(fromFileName: k_fileNameRichWorkspace, serverUrl: serverUrl, activeUrl: appDelegate.activeUrl)!
+        NCCommunication.sharedInstance.NCTextCreateFile(urlString: appDelegate.activeUrl, fileNamePath: fileNamePath, editor: "text", templateId: "", account: appDelegate.activeAccount) { (account, url, errorCode, errorMessage) in
+            
+            NCUtility.sharedInstance.stopActivityIndicator()
+            
+            if errorCode == 0 && account == self.appDelegate.activeAccount {
+                
+                if let viewerNextcloudText = UIStoryboard.init(name: "NCViewerRichWorkspace", bundle: nil).instantiateViewController(withIdentifier: "NCViewerNextcloudText") as? NCViewerNextcloudText {
+                    
+                    viewerNextcloudText.url = url!
+                    viewerNextcloudText.presentationController?.delegate = viewController as? UIAdaptivePresentationControllerDelegate
+                    
+                    viewController.present(viewerNextcloudText, animated: true, completion: nil)
+                }
+                
+            } else if errorCode != 0 {
+                NCContentPresenter.shared.messageNotification("_error_", description: errorMessage, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.info, errorCode: errorCode)
+            }
+        }
+    }
+    
+    @objc func openViewerNextcloudText(serverUrl: String, viewController: UIViewController) {
+        
+        if !appDelegate.reachability.isReachable() {
+            
+            NCContentPresenter.shared.messageNotification("_error_", description: "_go_online_", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.info, errorCode: 0)
+            return;
+        }
+        
+        if let metadata = NCManageDatabase.sharedInstance.getMetadata(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileNameView LIKE[c] %@", appDelegate.activeAccount, serverUrl, k_fileNameRichWorkspace.lowercased())) {
+            
+            if metadata.url == "" {
+                
+                NCUtility.sharedInstance.startActivityIndicator(view: viewController.view, bottom: 0)
+                
+                let fileNamePath = CCUtility.returnFileNamePath(fromFileName: metadata.fileName, serverUrl: metadata.serverUrl, activeUrl: appDelegate.activeUrl)!
+                NCCommunication.sharedInstance.NCTextOpenFile(urlString: appDelegate.activeUrl, fileNamePath: fileNamePath, editor: "text", account: appDelegate.activeAccount) { (account, url, errorCode, errorMessage) in
+                    
+                    NCUtility.sharedInstance.stopActivityIndicator()
+                    
+                    if errorCode == 0 && account == self.appDelegate.activeAccount {
+                        
+                        if let viewerNextcloudText = UIStoryboard.init(name: "NCViewerRichWorkspace", bundle: nil).instantiateViewController(withIdentifier: "NCViewerNextcloudText") as? NCViewerNextcloudText {
+                            
+                            viewerNextcloudText.url = url!
+                            viewerNextcloudText.metadata = metadata
+                            viewerNextcloudText.presentationController?.delegate = viewController as? UIAdaptivePresentationControllerDelegate
+                            
+                            viewController.present(viewerNextcloudText, animated: true, completion: nil)
+                        }
+                        
+                    } else if errorCode != 0 {
+                        NCContentPresenter.shared.messageNotification("_error_", description: errorMessage, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.info, errorCode: errorCode)
+                    }
+                }
+                
+            } else {
+                
+                if let viewerNextcloudText = UIStoryboard.init(name: "NCViewerRichWorkspace", bundle: nil).instantiateViewController(withIdentifier: "NCViewerNextcloudText") as? NCViewerNextcloudText {
+                    
+                    viewerNextcloudText.url = metadata.url
+                    viewerNextcloudText.metadata = metadata
+                    viewerNextcloudText.presentationController?.delegate = viewController as? UIAdaptivePresentationControllerDelegate
+                    
+                    viewController.present(viewerNextcloudText, animated: true, completion: nil)
+                }
+            }
+        }
+    }
+}

+ 4 - 2
iOSClient/RichWorkspace/NCViewerNextcloudText.swift

@@ -28,7 +28,7 @@ class NCViewerNextcloudText: UIViewController, WKNavigationDelegate, WKScriptMes
     @IBOutlet weak var webView: WKWebView!
 
     let appDelegate = UIApplication.shared.delegate as! AppDelegate
-    @objc var metadata: tableMetadata!
+    @objc var metadata: tableMetadata?
     @objc var url: String = ""
 
     override func viewDidLoad() {
@@ -79,7 +79,9 @@ class NCViewerNextcloudText: UIViewController, WKNavigationDelegate, WKScriptMes
             }
             
             if message.body as? String == "share" {
-                NCMainCommon.sharedInstance.openShare(ViewController: self, metadata: metadata, indexPage: 2)
+                if (metadata != nil) {
+                     NCMainCommon.sharedInstance.openShare(ViewController: self, metadata: metadata!, indexPage: 2)
+                }
             }
             
             if message.body as? String == "loading" {

+ 2 - 37
iOSClient/RichWorkspace/NCViewerRichWorkspace.swift

@@ -80,42 +80,7 @@ import NCCommunication
     
     @IBAction func editItemAction(_ sender: Any) {
         
-        if let metadata = NCManageDatabase.sharedInstance.getMetadata(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileNameView LIKE[c] %@", appDelegate.activeAccount, serverUrl, k_fileNameRichWorkspace.lowercased())) {
-            
-            if metadata.url == "" {
-                NCUtility.sharedInstance.startActivityIndicator(view: self.view, bottom: 0)
-                let fileNamePath = CCUtility.returnFileNamePath(fromFileName: metadata.fileName, serverUrl: metadata.serverUrl, activeUrl: appDelegate.activeUrl)!
-                NCCommunication.sharedInstance.NCTextOpenFile(urlString: appDelegate.activeUrl, fileNamePath: fileNamePath, editor: "text", account: appDelegate.activeAccount) { (account, url, errorCode, errorMessage) in
-                    
-                    NCUtility.sharedInstance.stopActivityIndicator()
-                    
-                    if errorCode == 0 && account == self.appDelegate.activeAccount {
-                        
-                        if let viewerNextcloudText = UIStoryboard.init(name: "NCViewerRichWorkspace", bundle: nil).instantiateViewController(withIdentifier: "NCViewerNextcloudText") as? NCViewerNextcloudText {
-                            
-                            viewerNextcloudText.url = url!
-                            viewerNextcloudText.metadata = metadata
-                            viewerNextcloudText.presentationController?.delegate = self
-                            
-                            self.present(viewerNextcloudText, animated: true, completion: nil)
-                        }
-                        
-                    } else if errorCode != 0 {
-                        NCContentPresenter.shared.messageNotification("_error_", description: errorMessage, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.info, errorCode: errorCode)
-                    }
-                }
-                
-            } else {
-                
-                if let viewerNextcloudText = UIStoryboard.init(name: "NCViewerRichWorkspace", bundle: nil).instantiateViewController(withIdentifier: "NCViewerNextcloudText") as? NCViewerNextcloudText {
-                    
-                    viewerNextcloudText.url = metadata.url
-                    viewerNextcloudText.metadata = metadata
-                    viewerNextcloudText.presentationController?.delegate = self
-                    
-                    self.present(viewerNextcloudText, animated: true, completion: nil)
-                }
-            }
-        }
+        let richWorkspaceTextCommon = NCRichWorkspaceTextCommon()
+        richWorkspaceTextCommon.openViewerNextcloudText(serverUrl: serverUrl, viewController: self)
     }
 }