marinofaggiana 4 anos atrás
pai
commit
20dec9931d

+ 4 - 4
Nextcloud.xcodeproj/project.pbxproj

@@ -171,7 +171,7 @@
 		F774264A22EB4D0000B23912 /* NCShareUserDropDownCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = F774264822EB4D0000B23912 /* NCShareUserDropDownCell.xib */; };
 		F77444F522281649000D5EB0 /* NCGridMediaCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = F77444F322281649000D5EB0 /* NCGridMediaCell.swift */; };
 		F77444F622281649000D5EB0 /* NCGridMediaCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = F77444F422281649000D5EB0 /* NCGridMediaCell.xib */; };
-		F77444F8222816D5000D5EB0 /* NCPhotosPickerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F77444F7222816D5000D5EB0 /* NCPhotosPickerViewController.swift */; };
+		F77444F8222816D5000D5EB0 /* NCPickerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F77444F7222816D5000D5EB0 /* NCPickerViewController.swift */; };
 		F774DF0F1FCC26BE002AF9FC /* iTunesArtwork@1x.png in Resources */ = {isa = PBXBuildFile; fileRef = F774DF0C1FCC26BD002AF9FC /* iTunesArtwork@1x.png */; };
 		F774DF101FCC26BE002AF9FC /* iTunesArtwork@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = F774DF0D1FCC26BD002AF9FC /* iTunesArtwork@2x.png */; };
 		F774DF111FCC26BE002AF9FC /* iTunesArtwork@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = F774DF0E1FCC26BE002AF9FC /* iTunesArtwork@3x.png */; };
@@ -547,7 +547,7 @@
 		F77439621FCD6D9C00662C46 /* es-UY */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "es-UY"; path = "es-UY.lproj/Localizable.strings"; sourceTree = "<group>"; };
 		F77444F322281649000D5EB0 /* NCGridMediaCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCGridMediaCell.swift; sourceTree = "<group>"; };
 		F77444F422281649000D5EB0 /* NCGridMediaCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NCGridMediaCell.xib; sourceTree = "<group>"; };
-		F77444F7222816D5000D5EB0 /* NCPhotosPickerViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCPhotosPickerViewController.swift; sourceTree = "<group>"; };
+		F77444F7222816D5000D5EB0 /* NCPickerViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCPickerViewController.swift; sourceTree = "<group>"; };
 		F774DF0C1FCC26BD002AF9FC /* iTunesArtwork@1x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "iTunesArtwork@1x.png"; sourceTree = "<group>"; };
 		F774DF0D1FCC26BD002AF9FC /* iTunesArtwork@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "iTunesArtwork@2x.png"; sourceTree = "<group>"; };
 		F774DF0E1FCC26BE002AF9FC /* iTunesArtwork@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "iTunesArtwork@3x.png"; sourceTree = "<group>"; };
@@ -831,7 +831,7 @@
 				F7E09CE223E3087F00FB3E9E /* NCMainRefreshControl.swift */,
 				F7682FDF23C36B0500983A04 /* NCMainTabBar.swift */,
 				F7E09CE623E308AD00FB3E9E /* NCMasterNavigationController.swift */,
-				F77444F7222816D5000D5EB0 /* NCPhotosPickerViewController.swift */,
+				F77444F7222816D5000D5EB0 /* NCPickerViewController.swift */,
 				F7E09CE423E3088A00FB3E9E /* NCSplitViewController.swift */,
 			);
 			path = Main;
@@ -2000,7 +2000,7 @@
 				F7DFB7F0219C5B8000680748 /* NCCreateFormUploadAssets.swift in Sources */,
 				F73B422C2476764F00A30FD3 /* NCNotification.swift in Sources */,
 				371B5A2E23D0B04500FAFAE9 /* NCMainMenuTableViewController.swift in Sources */,
-				F77444F8222816D5000D5EB0 /* NCPhotosPickerViewController.swift in Sources */,
+				F77444F8222816D5000D5EB0 /* NCPickerViewController.swift in Sources */,
 				F72A47EC2487B06B005AD489 /* NCOperationQueue.swift in Sources */,
 				F7E09CE523E3088C00FB3E9E /* NCSplitViewController.swift in Sources */,
 				F710D1F724057C9400A6033D /* NCDetailNavigationController.swift in Sources */,

+ 0 - 1
iOSClient/Main/CCMain.h

@@ -74,7 +74,6 @@
 
 - (void)uploadFileAsset:(NSMutableArray *)assets serverUrl:(NSString *)serverUrl useSubFolder:(BOOL)useSubFolder session:(NSString *)session;
 
-- (void)openImportDocumentPicker;
 
 - (void)setTableViewHeader;
 

+ 0 - 81
iOSClient/Main/CCMain.m

@@ -689,87 +689,6 @@
     [self tableViewSelect:false];
 }
 
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ===== Document Picker =====
-#pragma --------------------------------------------------------------------------------------------
-
-- (void)documentMenuWasCancelled:(UIDocumentMenuViewController *)documentMenu
-{
-}
-
-- (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller
-{
-}
-
-- (void)documentMenu:(UIDocumentMenuViewController *)documentMenu didPickDocumentPicker:(UIDocumentPickerViewController *)documentPicker
-{
-    documentPicker.delegate = self;
-    [self presentViewController:documentPicker animated:YES completion:nil];
-}
-
-- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url
-{
-    if (controller.documentPickerMode == UIDocumentPickerModeImport) {
-        
-        NSFileCoordinator *coordinator = [[NSFileCoordinator alloc] initWithFilePresenter:nil];
-        __block NSError *error;
-        
-        [coordinator coordinateReadingItemAtURL:url options:NSFileCoordinatorReadingForUploading error:&error byAccessor:^(NSURL *newURL) {
-            
-            NSString *serverUrl = appDelegate.activeServerUrl;
-            NSString *fileName =  [url lastPathComponent];
-            NSString *ocId = [[NSUUID UUID] UUIDString];
-            NSData *data = [NSData dataWithContentsOfURL:newURL];
-            
-            if (data && error == nil) {
-                
-                if ([data writeToFile:[CCUtility getDirectoryProviderStorageOcId:ocId fileNameView:fileName] options:NSDataWritingAtomic error:&error]) {
-                    
-                    tableMetadata *metadataForUpload = [[NCManageDatabase sharedInstance] createMetadataWithAccount:appDelegate.account fileName:fileName ocId:ocId serverUrl:serverUrl urlBase:appDelegate.urlBase url:@"" contentType:@"" livePhoto:false];
-                    
-                    metadataForUpload.session = NCNetworking.shared.sessionIdentifierBackground;
-                    metadataForUpload.sessionSelector = selectorUploadFile;
-                    metadataForUpload.size = data.length;
-                    metadataForUpload.status = k_metadataStatusWaitUpload;
-                    
-                    if ([[NCUtility shared] getMetadataConflictWithAccount:appDelegate.account serverUrl:serverUrl fileName:fileName] != nil) {
-                       
-                        NCCreateFormUploadConflict *conflict = [[UIStoryboard storyboardWithName:@"NCCreateFormUploadConflict" bundle:nil] instantiateInitialViewController];
-                        conflict.serverUrl = self.serverUrl;
-                        conflict.metadatasUploadInConflict = @[metadataForUpload];
-                        
-                        [self presentViewController:conflict animated:YES completion:nil];
-                        
-                    } else {
-                        
-                        [[NCManageDatabase sharedInstance] addMetadata:metadataForUpload];
-                        [[appDelegate networkingAutoUpload] startProcess];
-                    }
-
-                } else {
-                                        
-                    [[NCContentPresenter shared] messageNotification:@"_error_" description:error.description delay:k_dismissAfterSecond type:messageTypeError errorCode:error.code forced:false];
-                }
-                
-            } else {
-                
-                [[NCContentPresenter shared] messageNotification:@"_error_" description:@"_read_file_error_" delay:k_dismissAfterSecond type:messageTypeError errorCode:error.code forced:false];
-            }
-        }];
-    }
-}
-
-- (void)openImportDocumentPicker
-{
-    UIDocumentMenuViewController *documentProviderMenu = [[UIDocumentMenuViewController alloc] initWithDocumentTypes:@[@"public.data"] inMode:UIDocumentPickerModeImport];
-    
-    documentProviderMenu.modalPresentationStyle = UIModalPresentationFormSheet;
-    documentProviderMenu.popoverPresentationController.sourceView = self.tabBarController.tabBar;
-    documentProviderMenu.popoverPresentationController.sourceRect = self.tabBarController.tabBar.bounds;
-    documentProviderMenu.delegate = self;
-    
-    [self presentViewController:documentProviderMenu animated:YES completion:nil];
-}
 
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ===== Save selected File =====

+ 5 - 5
iOSClient/Main/Menu/AppDelegate+Menu.swift

@@ -27,11 +27,7 @@ import FloatingPanel
 import NCCommunication
 
 extension AppDelegate {
-    func dismissFormUploadAssets() {
-        
-    }
     
-
     @objc public func showMenuIn(viewController: UIViewController) {
         
         let mainMenuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateViewController(withIdentifier: "NCMainMenuTableViewController") as! NCMainMenuTableViewController
@@ -70,7 +66,11 @@ extension AppDelegate {
                 title: NSLocalizedString("_upload_file_", comment: ""),
                 icon: CCGraphics.changeThemingColorImage(UIImage(named: "file"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
                 action: { menuAction in
-                    appDelegate.activeMain.openImportDocumentPicker()
+                    if let navigationController = (self.window.rootViewController as! UISplitViewController).viewControllers.first as? UINavigationController {
+                        if let tabBarController = navigationController.topViewController as? UITabBarController {
+                            NCDocumentPickerViewController.init(tabBarController: tabBarController)
+                        }
+                    }
                 }
             )
         )

+ 78 - 1
iOSClient/Main/NCPhotosPickerViewController.swift → iOSClient/Main/NCPickerViewController.swift

@@ -1,5 +1,5 @@
 //
-//  NCPhotosPickerViewController.swift
+//  NCPickerViewController.swift
 //  Nextcloud
 //
 //  Created by Marino Faggiana on 11/11/2018.
@@ -23,6 +23,9 @@
 
 import Foundation
 import TLPhotoPicker
+import MobileCoreServices
+
+//MARK: - Photo Picker
 
 class NCPhotosPickerViewController: NSObject {
 
@@ -111,3 +114,77 @@ class customPhotoPickerViewController: TLPhotosPickerViewController {
         self.customNavItem.rightBarButtonItem?.tintColor = NCBrandColor.sharedInstance.brandElement
     }
 }
+
+//MARK: - Document Picker
+
+class NCDocumentPickerViewController: NSObject, UIDocumentPickerDelegate {
+
+    let appDelegate = UIApplication.shared.delegate as! AppDelegate
+    
+    @discardableResult
+    init (tabBarController: UITabBarController) {
+        super.init()
+          
+        let documentProviderMenu = UIDocumentPickerViewController(documentTypes: ["public.data"], in: .import)
+        
+        documentProviderMenu.modalPresentationStyle = .formSheet
+        documentProviderMenu.popoverPresentationController?.sourceView = tabBarController.tabBar
+        documentProviderMenu.popoverPresentationController?.sourceRect = tabBarController.tabBar.bounds
+        documentProviderMenu.delegate = self
+        
+        appDelegate.window.rootViewController?.present(documentProviderMenu, animated: true, completion: nil)
+    }
+    
+    func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
+            
+        if controller.documentPickerMode == .import {
+            
+            let coordinator = NSFileCoordinator.init(filePresenter: nil)
+
+            coordinator.coordinate(readingItemAt: url, options: NSFileCoordinator.ReadingOptions.forUploading, error: nil) { (url) in
+                
+                let fileName = url.lastPathComponent
+                let serverUrl = appDelegate.activeServerUrl!
+                let ocId = NSUUID().uuidString
+                let data = try? Data.init(contentsOf: url)
+                let path = URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(ocId, fileNameView: fileName)!)
+                
+                if data != nil {
+                    
+                    do {
+                        try data?.write(to: path)
+                        let metadataForUpload = NCManageDatabase.sharedInstance.createMetadata(account: appDelegate.account, fileName: fileName, ocId: ocId, serverUrl: serverUrl, urlBase: appDelegate.urlBase, url: "", contentType: "", livePhoto: false)
+                        
+                        metadataForUpload.session = NCNetworking.shared.sessionIdentifierBackground
+                        metadataForUpload.sessionSelector = selectorUploadFile
+                        metadataForUpload.size = Double(data?.count ?? 0)
+                        metadataForUpload.status = Int(k_metadataStatusWaitUpload)
+                        
+                        if NCUtility.shared.getMetadataConflict(account: appDelegate.account, serverUrl: serverUrl, fileName: fileName) != nil {
+                            
+                            if let conflict = UIStoryboard.init(name: "NCCreateFormUploadConflict", bundle: nil).instantiateInitialViewController() as? NCCreateFormUploadConflict {
+                                
+                                conflict.serverUrl = serverUrl
+                                conflict.metadatasUploadInConflict = [metadataForUpload]
+                            
+                                appDelegate.window.rootViewController?.present(conflict, animated: true, completion: nil)
+                            }
+                        
+                        } else {
+                            
+                            NCManageDatabase.sharedInstance.addMetadata(metadataForUpload)
+                            appDelegate.networkingAutoUpload.startProcess()
+                        }
+                        
+                    } catch {
+                        NCContentPresenter.shared.messageNotification("_error_", description: "_write_file_error_", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: Int(k_CCErrorInternalError))
+                    }
+                } else {
+                    NCContentPresenter.shared.messageNotification("_error_", description: "_read_file_error_", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: Int(k_CCErrorInternalError))
+                }
+            }
+        }
+    }
+}
+
+

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

@@ -153,6 +153,7 @@
 "_no_reuploadfile_"         = "Could not find nor resend file. Delete the upload and reload the file to upload it.";
 "_file_already_exists_"     = "Unable to complete the operation, a file with the same name exists";
 "_read_file_error_"         = "Could not read the file";
+"_write_file_error_"        = "Could not write the file";
 
 // More