Bläddra i källkod

Create : NCNetworkingMain

Marino Faggiana 6 år sedan
förälder
incheckning
e60c00f453
3 ändrade filer med 110 tillägg och 37 borttagningar
  1. 4 0
      iOSClient/Main/CCMain.h
  2. 38 33
      iOSClient/Main/CCMain.m
  3. 68 4
      iOSClient/Main/NCMainCommon.swift

+ 4 - 0
iOSClient/Main/CCMain.h

@@ -71,6 +71,10 @@
 
 - (void)shouldPerformSegue;
 
+- (void)saveToPhotoAlbum:(tableMetadata *)metadata;
+
+- (void)copyFileToPasteboard:(tableMetadata *)metadata;
+
 - (void)closeAllMenu;
 - (void)returnCreate:(NSInteger)type;
 

+ 38 - 33
iOSClient/Main/CCMain.m

@@ -946,7 +946,42 @@
 #pragma mark ===== Save selected File =====
 #pragma --------------------------------------------------------------------------------------------
 
--(void)saveSelectedFilesSelector:(NSString *)path didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
+- (void)saveToPhotoAlbum:(tableMetadata *)metadata
+{
+    NSString *fileNamePath = [CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileNameView:metadata.fileNameView];
+    PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
+    
+    if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image] && status == PHAuthorizationStatusAuthorized) {
+        
+        UIImage *image = [UIImage imageWithContentsOfFile:fileNamePath];
+        
+        if (image)
+            UIImageWriteToSavedPhotosAlbum(image, self, @selector(saveSelectedFilesSelector: didFinishSavingWithError: contextInfo:), nil);
+        else
+            [appDelegate messageNotification:@"_save_selected_files_" description:@"_file_not_saved_cameraroll_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
+    }
+    
+    if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video] && status == PHAuthorizationStatusAuthorized) {
+        
+        if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(fileNamePath)) {
+            
+            UISaveVideoAtPathToSavedPhotosAlbum(fileNamePath, self, @selector(saveSelectedFilesSelector: didFinishSavingWithError: contextInfo:), nil);
+        } else {
+            [appDelegate messageNotification:@"_save_selected_files_" description:@"_file_not_saved_cameraroll_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
+        }
+    }
+    
+    if (status != PHAuthorizationStatusAuthorized) {
+        
+        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_access_photo_not_enabled_", nil) message:NSLocalizedString(@"_access_photo_not_enabled_msg_", nil) preferredStyle:UIAlertControllerStyleAlert];
+        UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
+        
+        [alertController addAction:okAction];
+        [self presentViewController:alertController animated:YES completion:nil];
+    }
+}
+
+- (void)saveSelectedFilesSelector:(NSString *)path didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
 {
     if (error)
         [appDelegate messageNotification:@"_save_selected_files_" description:@"_file_not_saved_cameraroll_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
@@ -1133,39 +1168,9 @@
         // Save to Photo Album
         if ([selector isEqualToString:selectorSave] && [[UIApplication sharedApplication] applicationState] == UIApplicationStateActive) {
             
-            NSString *fileNamePath = [CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileNameView:metadata.fileNameView];
-            PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
-            
-            if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image] && status == PHAuthorizationStatusAuthorized) {
-                
-                UIImage *image = [UIImage imageWithContentsOfFile:fileNamePath];
-                
-                if (image)
-                    UIImageWriteToSavedPhotosAlbum(image, self, @selector(saveSelectedFilesSelector: didFinishSavingWithError: contextInfo:), nil);
-                else
-                    [appDelegate messageNotification:@"_save_selected_files_" description:@"_file_not_saved_cameraroll_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
-            }
-            
-            if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video] && status == PHAuthorizationStatusAuthorized) {
-                
-                if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(fileNamePath)) {
-                    
-                    UISaveVideoAtPathToSavedPhotosAlbum(fileNamePath, self, @selector(saveSelectedFilesSelector: didFinishSavingWithError: contextInfo:), nil);
-                } else {
-                    [appDelegate messageNotification:@"_save_selected_files_" description:@"_file_not_saved_cameraroll_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
-                }
-            }
-            
-            if (status != PHAuthorizationStatusAuthorized) {
-                
-                UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_access_photo_not_enabled_", nil) message:NSLocalizedString(@"_access_photo_not_enabled_msg_", nil) preferredStyle:UIAlertControllerStyleAlert];
-                UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
-                
-                [alertController addAction:okAction];
-                [self presentViewController:alertController animated:YES completion:nil];
-            }
-            
             [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:serverUrl fileID:fileID action:k_action_MOD];
+            
+            [self saveToPhotoAlbum:metadata];
         }
         
         // Copy File

+ 68 - 4
iOSClient/Main/NCMainCommon.swift

@@ -705,14 +705,15 @@ class NCNetworkingMain: NSObject, CCNetworkingDelegate {
         
         if errorCode == 0 {
             
+            NCMainCommon.sharedInstance.reloadDatasource(ServerUrl: serverUrl, fileID: fileID, action: Int32(k_action_MOD))
+            
             // Synchronized
             if selector == selectorDownloadSynchronize {
-                NCMainCommon.sharedInstance.reloadDatasource(ServerUrl: serverUrl, fileID: fileID, action: Int32(k_action_MOD))
+                //
             }
             
             // open View File
             if selector == selectorLoadFileView && UIApplication.shared.applicationState == UIApplicationState.active {
-                NCMainCommon.sharedInstance.reloadDatasource(ServerUrl: serverUrl, fileID: fileID, action: Int32(k_action_MOD))
             
                 if metadata.typeFile == k_metadataTypeFile_compress || metadata.typeFile == k_metadataTypeFile_unknown {
                 
@@ -735,8 +736,71 @@ class NCNetworkingMain: NSObject, CCNetworkingDelegate {
                     }
                 }
             }
-        }
-       
+            
+            // Open in...
+            if selector == selectorOpenIn && UIApplication.shared.applicationState == UIApplicationState.active {
+
+                if appDelegate.activeMain.view.window != nil {
+                    appDelegate.activeMain.open(in: metadata)
+                }
+                if appDelegate.activeFavorites.view.window != nil {
+                    appDelegate.activeFavorites.open(in: metadata)
+                }
+            }
+            
+            // Save to Photo Album
+            if selector == selectorSave {
+                
+                appDelegate.activeMain.save(toPhotoAlbum: metadata)
+            }
+            
+            // Copy File
+            if selector == selectorLoadCopy {
+                
+                appDelegate.activeMain.copyFile(toPasteboard: metadata)
+            }
+            
+            //selectorLoadViewImage
+            if selector == selectorLoadViewImage {
+                
+                if appDelegate.activeDetail.view.window != nil {
+                    appDelegate.activeDetail.downloadPhotoBrowserSuccessFailure(metadata, selector: selector, errorCode: errorCode)
+                }
+                if appDelegate.activeMedia.view.window != nil {
+                    appDelegate.activeMedia.downloadFileSuccessFailure(metadata.fileName, fileID: metadata.fileID, serverUrl: serverUrl, selector: selector, errorMessage: errorMessage, errorCode: errorCode)
+                }
+            }
+            
+            self.appDelegate.performSelector(onMainThread: #selector(self.appDelegate.loadAutoDownloadUpload), with: nil, waitUntilDone: true)
+            
+        } else {
+            
+            // File do not exists on server, remove in local
+            if (errorCode == kOCErrorServerPathNotFound || errorCode == -1011) { // - 1011 = kCFURLErrorBadServerResponse
+                
+                do {
+                    try FileManager.default.removeItem(atPath: CCUtility.getDirectoryProviderStorageFileID(metadata.fileID))
+                } catch { }
+                
+                NCManageDatabase.sharedInstance.deleteMetadata(predicate: NSPredicate(format: "fileID == %@", metadata.fileID), clearDateReadDirectoryID: metadata.directoryID)
+                NCManageDatabase.sharedInstance.deleteLocalFile(predicate: NSPredicate(format: "fileID == %@", metadata.fileID))
+                NCManageDatabase.sharedInstance.deletePhotos(fileID: fileID)
+                
+                NCMainCommon.sharedInstance.reloadDatasource(ServerUrl: serverUrl, fileID: fileID, action: Int32(k_action_DEL))
+            }
+            
+            if selector == selectorLoadViewImage {
+                
+                if appDelegate.activeDetail.view.window != nil {
+                    appDelegate.activeDetail.downloadPhotoBrowserSuccessFailure(metadata, selector: selector, errorCode: errorCode)
+                }
+                if appDelegate.activeMedia.view.window != nil {
+                    appDelegate.activeMedia.downloadFileSuccessFailure(metadata.fileName, fileID: metadata.fileID, serverUrl: serverUrl, selector: selector, errorMessage: errorMessage, errorCode: errorCode)
+                }
+                
+                NCMainCommon.sharedInstance.reloadDatasource(ServerUrl: serverUrl, fileID: fileID, action: Int32(k_action_MOD))
+            }
+        }       
     }
     
     // UPLOAD