Marino Faggiana 8 years ago
parent
commit
e776c93796

+ 62 - 4
iOSClient/Create/CCCreateCloud.swift

@@ -248,7 +248,7 @@ class CreateFormUpload: XLFormViewController, CCMoveDelegate {
         var section : XLFormSectionDescriptor
         var row : XLFormRowDescriptor
 
-        section = XLFormSectionDescriptor.formSection(withTitle: NSLocalizedString("_destination_folder_", comment: "")) as XLFormSectionDescriptor
+        section = XLFormSectionDescriptor.formSection()
         form.addFormSection(section)
         
         row = XLFormRowDescriptor(tag: "ButtonDestinationFolder", rowType: XLFormRowDescriptorTypeButton, title: self.titleLocalServerUrl)
@@ -256,14 +256,14 @@ class CreateFormUpload: XLFormViewController, CCMoveDelegate {
         row.action.formSelector = #selector(changeDestinationFolder(_:))
         section.addFormRow(row)
         
-        section = XLFormSectionDescriptor.formSection(withTitle: NSLocalizedString("_use_folder_photos_", comment: "")) as XLFormSectionDescriptor
+        section = XLFormSectionDescriptor.formSection()
         form.addFormSection(section)
         
         row = XLFormRowDescriptor(tag: "useFolderPhoto", rowType: XLFormRowDescriptorTypeBooleanSwitch, title: NSLocalizedString("_photo_camera_", comment: ""))
         row.value = 0
         section.addFormRow(row)
         
-        row = XLFormRowDescriptor(tag: "useSubfolder", rowType: XLFormRowDescriptorTypeBooleanSwitch, title: NSLocalizedString("_upload_camera_create_subfolder_", comment: ""))
+        row = XLFormRowDescriptor(tag: "useSubFolder", rowType: XLFormRowDescriptorTypeBooleanSwitch, title: NSLocalizedString("_upload_camera_create_subfolder_", comment: ""))
         row.hidden = "$\("useFolderPhoto") == 0"
         
         if CCCoreData.getCameraUploadCreateSubfolderActiveAccount(appDelegate.activeAccount) == true {
@@ -284,6 +284,55 @@ class CreateFormUpload: XLFormViewController, CCMoveDelegate {
         self.form = form
     }
     
+    //MARK: XLFormDescriptorDelegate
+    
+    override func formRowDescriptorValueHasChanged(_ formRow: XLFormRowDescriptor!, oldValue: Any!, newValue: Any!) {
+        
+        super.formRowDescriptorValueHasChanged(formRow, oldValue: oldValue, newValue: newValue)
+        
+        if formRow.tag == "useFolderPhoto" {
+            
+            if (formRow.value! as AnyObject).boolValue  == true {
+                
+                let buttonDestinationFolder : XLFormRowDescriptor  = self.form.formRow(withTag: "ButtonDestinationFolder")!
+                buttonDestinationFolder.hidden = true
+                
+            } else{
+                
+                let buttonDestinationFolder : XLFormRowDescriptor  = self.form.formRow(withTag: "ButtonDestinationFolder")!
+                buttonDestinationFolder.hidden = false
+            }
+        }
+        else if formRow.tag == "useSubFolder" {
+            
+            if (formRow.value! as AnyObject).boolValue  == true {
+            
+            } else{
+                
+            }
+        }
+    }
+    
+    override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
+        
+        var returnTitle : String?
+        
+        if section == 0 {
+            let buttonDestinationFolder : XLFormRowDescriptor  = self.form.formRow(withTag: "ButtonDestinationFolder")!
+            if buttonDestinationFolder.isHidden() {
+                returnTitle = ""
+            } else {
+                returnTitle = NSLocalizedString("_destination_folder_", comment: "")
+            }
+        }
+        
+        if section == 1 {
+            returnTitle = NSLocalizedString("_use_folder_photos_", comment: "")
+        }
+        
+        return returnTitle
+    }
+
     func reloadForm() {
         
         self.form.delegate = nil
@@ -327,8 +376,17 @@ class CreateFormUpload: XLFormViewController, CCMoveDelegate {
     }
     
     func save() {
+        
         self.dismiss(animated: true, completion: {
-            self.appDelegate.activeMain.uploadFileAsset(self.assets, serverUrl: self.localServerUrl, cryptated: self.cryptated!, session: self.session)
+            
+            let useFolderPhoto : XLFormRowDescriptor  = self.form.formRow(withTag: "useFolderPhoto")!
+            let useSubfolder : XLFormRowDescriptor  = self.form.formRow(withTag: "useSubFolder")!
+            
+            if (useFolderPhoto.value! as AnyObject).boolValue == true {
+                self.localServerUrl = CCCoreData.getCameraUploadFolderNamePathActiveAccount(self.appDelegate.activeAccount, activeUrl: self.appDelegate.activeUrl, typeCloud: self.appDelegate.typeCloud)
+            }
+            
+            self.appDelegate.activeMain.uploadFileAsset(self.assets, serverUrl: self.localServerUrl, cryptated: self.cryptated!, useSubFolder: (useSubfolder.value! as AnyObject).boolValue, session: self.session)
         })
     }
 

+ 2 - 2
iOSClient/FileSystem/CCCoreData.m

@@ -225,8 +225,8 @@
     NSString *cameraFolderName = [self getCameraUploadFolderNameActiveAccount:activeAccount];
     NSString *cameraFolderPath = [self getCameraUploadFolderPathActiveAccount:activeAccount activeUrl:activeUrl typeCloud:typeCloud];
     
-    NSString *result = [CCUtility stringAppendServerUrl:cameraFolderPath addServerUrl:cameraFolderName];
-    return result;
+    NSString *folderPhotos = [CCUtility stringAppendServerUrl:cameraFolderPath addServerUrl:cameraFolderName];
+    return folderPhotos;
 }
 
 + (BOOL)getCameraUploadActiveAccount:(NSString *)activeAccount

+ 1 - 1
iOSClient/Main/CCMain.h

@@ -81,7 +81,7 @@
 - (void)createFolder:(NSString *)fileNameFolder folderCameraUpload:(BOOL)folderCameraUpload;
 - (void)readFolderWithForced:(BOOL)forced;
 
-- (void)uploadFileAsset:(NSMutableArray *)assets serverUrl:(NSString *)serverUrl cryptated:(BOOL)cryptated session:(NSString *)session;
+- (void)uploadFileAsset:(NSMutableArray *)assets serverUrl:(NSString *)serverUrl cryptated:(BOOL)cryptated useSubFolder:(BOOL)useSubFolder session:(NSString *)session;
 
 - (void)progressTask:(NSString *)fileID serverUrl:(NSString *)serverUrl cryptated:(BOOL)cryptated progress:(float)progress;
 

+ 30 - 5
iOSClient/Main/CCMain.m

@@ -706,10 +706,7 @@
         
         //navController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
         
-        [self presentViewController:navigationController animated:YES completion:nil];
-        
-        // OLD :
-        // [self uploadFileAsset:assets serverUrl:_localServerUrl cryptated:_isPickerCriptate session:upload_session];
+        [self presentViewController:navigationController animated:YES completion:nil];        
     }];
 }
 
@@ -1407,12 +1404,40 @@
     }
 }
 
-- (void)uploadFileAsset:(NSMutableArray *)assets serverUrl:(NSString *)serverUrl cryptated:(BOOL)cryptated session:(NSString *)session
+- (void)uploadFileAsset:(NSMutableArray *)assets serverUrl:(NSString *)serverUrl cryptated:(BOOL)cryptated useSubFolder:(BOOL)useSubFolder session:(NSString *)session
 {
     NSLog(@"[LOG] Asset N. %lu", (unsigned long)[assets count]);
     
     // remove title
     [self setTitleBackgroundTableView:nil];
+
+    NSString *folderPhotos = [CCCoreData getCameraUploadFolderNamePathActiveAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud];
+    
+    // Create if request the folder for Photos
+    if (useSubFolder || [serverUrl isEqualToString:folderPhotos]) {
+        
+        if(![app.activePhotosCameraUpload createFolder:folderPhotos]) {
+            
+            [app messageNotification:@"_error_" description:@"_error_createsubfolders_upload_" visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeInfo];
+            
+            return;
+        }
+    }
+    
+    // Subfolder ? Create
+    if (useSubFolder) {
+        
+        for (NSString *dateSubFolder in [CCUtility createNameSubFolder:assets]) {
+                
+            if(![app.activePhotosCameraUpload createFolder:[NSString stringWithFormat:@"%@/%@", folderPhotos, dateSubFolder]]) {
+                
+                [app messageNotification:@"_error_" description:@"_error_createsubfolders_upload_" visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeInfo];
+                    
+                return;
+            }
+        }
+    }
+
     
     NSString *directoryID = [CCCoreData getDirectoryIDFromServerUrl:serverUrl activeAccount:app.activeAccount];
 

+ 1 - 0
iOSClient/PhotosCameraUpload/CCPhotosCameraUpload.h

@@ -51,5 +51,6 @@
 - (void)downloadFileFailure:(NSInteger)errorCode;
 
 - (void)reloadDatasourceForced;
+- (BOOL)createFolder:(NSString *)folderPathName;
 
 @end

+ 6 - 6
iOSClient/PhotosCameraUpload/CCPhotosCameraUpload.m

@@ -1110,10 +1110,10 @@
     // STOP new request : initStateCameraUpload
     _AutomaticCameraUploadInProgress = YES;
     
-    NSString *folderPathName = [CCCoreData getCameraUploadFolderNamePathActiveAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud];
+    NSString *folderPhotos = [CCCoreData getCameraUploadFolderNamePathActiveAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud];
     
     // verify/create folder Camera Upload, if error exit
-    if(![self createFolder:folderPathName]) {
+    if(![self createFolder:folderPhotos]) {
         
         // Full Upload ?
         if (assetsFull)
@@ -1159,7 +1159,7 @@
     NSMutableArray *newItemsPHAssetToUpload = [[NSMutableArray alloc] init];
     NSMutableOrderedSet *datesSubFolder = [[NSMutableOrderedSet alloc] init];
     
-    NSString *folderCameraUpload = [CCCoreData getCameraUploadFolderNamePathActiveAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud];
+    NSString *folderPhotos = [CCCoreData getCameraUploadFolderNamePathActiveAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud];
     BOOL createSubfolders = [CCCoreData getCameraUploadCreateSubfolderActiveAccount:app.activeAccount];
     
     for (ALAsset *asset in newItemsToUpload) {
@@ -1190,7 +1190,7 @@
         
         for (NSString *dateSubFolder in datesSubFolder) {
             
-            if(![self createFolder:[NSString stringWithFormat:@"%@/%@", folderCameraUpload, dateSubFolder]]) {
+            if(![self createFolder:[NSString stringWithFormat:@"%@/%@", folderPhotos, dateSubFolder]]) {
                 
                 [self endLoadingAssets];
                 
@@ -1226,9 +1226,9 @@
         NSString *monthString = [formatter stringFromDate:assetDate];
 
         if (createSubfolders)
-            serverUrl = [NSString stringWithFormat:@"%@/%@/%@", folderCameraUpload, yearString, monthString];
+            serverUrl = [NSString stringWithFormat:@"%@/%@/%@", folderPhotos, yearString, monthString];
         else
-            serverUrl = folderCameraUpload;
+            serverUrl = folderPhotos;
         
         CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
             

+ 1 - 1
iOSClient/QuickActions/CCQuickActions.m

@@ -171,7 +171,7 @@
 
 - (void)move:(NSString *)serverUrlTo title:(NSString *)title selectedMetadatas:(NSArray *)selectedMetadatas
 {    
-    [_mainVC uploadFileAsset:_assets serverUrl:serverUrlTo cryptated:_cryptated session:upload_session];
+    [_mainVC uploadFileAsset:_assets serverUrl:serverUrlTo cryptated:_cryptated useSubFolder:NO session:upload_session];
 }
 
 - (void)moveOpenWindow:(NSArray *)indexPaths

+ 2 - 0
iOSClient/Utility/CCUtility.h

@@ -155,6 +155,8 @@
 
 + (NSString *)localizableBrand:(NSString *)localize table:(NSString *)table;
 
++ (NSArray *)createNameSubFolder:(NSArray *)alassets;
+
 // ===== CCMetadata =====
 
 + (CCMetadata *)trasformedOCFileToCCMetadata:(OCFileDto *)itemDto fileNamePrint:(NSString *)fileNamePrint serverUrl:(NSString *)serverUrl directoryID:(NSString *)directoryID cameraFolderName:(NSString *)cameraFolderName cameraFolderPath:(NSString *)cameraFolderPath activeAccount:(NSString *)activeAccount directoryUser:(NSString *)directoryUser typeCloud:(NSString *)typeCloud;

+ 26 - 0
iOSClient/Utility/CCUtility.m

@@ -716,6 +716,32 @@
     return translate;
 }
 
++ (NSArray *)createNameSubFolder:(NSArray *)alassets
+{
+    NSMutableOrderedSet *datesSubFolder = [[NSMutableOrderedSet alloc] init];
+    
+    for (ALAsset *asset in alassets) {
+        
+        NSURL *url = [asset valueForProperty:@"ALAssetPropertyAssetURL"];
+        PHFetchResult *fetchResult = [PHAsset fetchAssetsWithALAssetURLs:@[url] options:nil];
+        PHAsset *asset = [fetchResult firstObject];
+        
+        NSDate *assetDate = asset.creationDate;
+            
+        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
+        [formatter setDateFormat:@"yyyy"];
+        NSString *yearString = [formatter stringFromDate:assetDate];
+        [datesSubFolder addObject:yearString];
+            
+        [formatter setDateFormat:@"MM"];
+        NSString *monthString = [formatter stringFromDate:assetDate];
+        monthString = [NSString stringWithFormat:@"%@/%@", yearString, monthString];
+        [datesSubFolder addObject:monthString];
+    }
+    
+    return (NSArray *)datesSubFolder;
+}
+
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ===== CCMetadata =====
 #pragma --------------------------------------------------------------------------------------------