marinofaggiana 4 years ago
parent
commit
89a6a510ee
3 changed files with 64 additions and 103 deletions
  1. 0 6
      iOSClient/AppDelegate.h
  2. 2 70
      iOSClient/AppDelegate.m
  3. 62 27
      iOSClient/Main/CCMain.m

+ 0 - 6
iOSClient/AppDelegate.h

@@ -101,12 +101,6 @@
 @property (nonatomic, strong) NSMutableDictionary *listMainVC;
 @property (nonatomic, strong) NSMutableDictionary *listProgressMetadata;
 
-@property (nonatomic, strong) NSMutableArray *arrayDeleteMetadata;
-@property (nonatomic, strong) NSMutableArray *arrayMoveMetadata;
-@property (nonatomic, strong) NSMutableArray *arrayMoveServerUrlTo;
-@property (nonatomic, strong) NSMutableArray *arrayCopyMetadata;
-@property (nonatomic, strong) NSMutableArray *arrayCopyServerUrlTo;
-
 @property (nonatomic) UIUserInterfaceStyle preferredUserInterfaceStyle API_AVAILABLE(ios(12.0));
 
 // Shares

+ 2 - 70
iOSClient/AppDelegate.m

@@ -85,12 +85,7 @@
 
     self.listProgressMetadata = [NSMutableDictionary new];
     self.listMainVC = [NSMutableDictionary new];
-    self.arrayDeleteMetadata = [NSMutableArray new];
-    self.arrayMoveMetadata = [NSMutableArray new];
-    self.arrayMoveServerUrlTo = [NSMutableArray new];
-    self.arrayCopyMetadata = [NSMutableArray new];
-    self.arrayCopyServerUrlTo = [NSMutableArray new];
-    
+   
     // Push Notification
     [application registerForRemoteNotifications];
     
@@ -158,13 +153,7 @@
 
     // init home
     [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_notificationCenter_initializeMain object:nil userInfo:nil];
-    
-    // Observer
-    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deleteFile:) name:k_notificationCenter_deleteFile object:nil];
-    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moveFile:) name:k_notificationCenter_moveFile object:nil];
-    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(copyFile:) name:k_notificationCenter_copyFile object:nil];
-    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(uploadedFile:) name:k_notificationCenter_uploadedFile object:nil];
-    
+
     // Passcode
     dispatch_async(dispatch_get_main_queue(), ^{
         [self passcodeWithAutomaticallyPromptForBiometricValidation:true];
@@ -645,63 +634,6 @@
     return [token copy];
 }
 
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ==== NotificationCenter ====
-#pragma --------------------------------------------------------------------------------------------
-
-- (void)deleteFile:(NSNotification *)notification
-{
-    if (self.arrayDeleteMetadata.count > 0) {
-        tableMetadata *metadata = self.arrayDeleteMetadata.firstObject;
-        [self.arrayDeleteMetadata removeObjectAtIndex:0];
-        tableAccount *account = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", metadata.account]];
-        if (account) {
-            [[NCNetworking shared] deleteMetadata:metadata account:metadata.account url:account.url completion:^(NSInteger errorCode, NSString *errorDescription) { }];
-        } else {
-            [self deleteFile:[NSNotification new]];
-        }
-    }
-}
-
-- (void)moveFile:(NSNotification *)notification
-{
-    if (self.arrayMoveMetadata.count > 0) {
-        tableMetadata *metadata = self.arrayMoveMetadata.firstObject;
-        NSString *serverUrlTo = self.arrayMoveServerUrlTo.firstObject;
-        [self.arrayMoveMetadata removeObjectAtIndex:0];
-        [self.arrayMoveServerUrlTo removeObjectAtIndex:0];
-        tableAccount *account = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", metadata.account]];
-        if (account) {
-            [[NCNetworking shared] moveMetadata:metadata serverUrlTo:serverUrlTo overwrite:true completion:^(NSInteger errorCode, NSString *errorDescription) { }];
-        } else {
-            [self moveFile:[NSNotification new]];
-        }
-    }
-}
-
-- (void)copyFile:(NSNotification *)notification
-{
-    if (self.arrayCopyMetadata.count > 0) {
-        tableMetadata *metadata = self.arrayCopyMetadata.firstObject;
-        NSString *serverUrlTo = self.arrayCopyServerUrlTo.firstObject;
-        [self.arrayCopyMetadata removeObjectAtIndex:0];
-        [self.arrayCopyServerUrlTo removeObjectAtIndex:0];
-        tableAccount *account = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", metadata.account]];
-        if (account) {
-            [[NCNetworking shared] copyMetadata:metadata serverUrlTo:serverUrlTo overwrite:true completion:^(NSInteger errorCode, NSString *errorDescription) { }];
-        } else {
-            [self copyFile:[NSNotification new]];
-        }
-    }
-}
-
-- (void)uploadedFile:(NSNotification *)notification
-{
-//    NSDictionary *userInfo = notification.userInfo;
-//    tableMetadata *metadata = userInfo[@"metadata"];
-//    NSInteger errorCode = [userInfo[@"errorCode"] integerValue];
-}
-
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ===== Quick Actions - ShotcutItem =====
 #pragma --------------------------------------------------------------------------------------------

+ 62 - 27
iOSClient/Main/CCMain.m

@@ -71,6 +71,13 @@
     
     CGFloat heightRichWorkspace;
     CGFloat heightSearchBar;
+    
+    //
+    NSMutableArray *arrayDeleteMetadata;
+    NSMutableArray *arrayMoveMetadata;
+    NSMutableArray *arrayMoveServerUrlTo;
+    NSMutableArray *arrayCopyMetadata;
+    NSMutableArray *arrayCopyServerUrlTo;
 }
 @end
 
@@ -114,6 +121,12 @@
     _cellFavouriteImage = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"favorite"] width:50 height:50 color:[UIColor whiteColor]];
     _cellTrashImage = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"trash"] width:50 height:50 color:[UIColor whiteColor]];
     
+    arrayDeleteMetadata = [NSMutableArray new];
+    arrayMoveMetadata = [NSMutableArray new];
+    arrayMoveServerUrlTo = [NSMutableArray new];
+    arrayCopyMetadata = [NSMutableArray new];
+    arrayCopyServerUrlTo = [NSMutableArray new];
+    
     // delegate
     self.tableView.tableFooterView = [UIView new];
     self.tableView.emptyDataSetDelegate = self;
@@ -429,54 +442,76 @@
 
 - (void)deleteFile:(NSNotification *)notification
 {
-    if (self.view.window == nil) { return; }
-    
     NSDictionary *userInfo = notification.userInfo;
     tableMetadata *metadata = userInfo[@"metadata"];
     NSInteger errorCode = [userInfo[@"errorCode"] integerValue];
     NSString *errorDescription = userInfo[@"errorDescription"];
     
-    if (errorCode == 0 && metadata) {
-        if ([metadata.serverUrl isEqualToString:self.serverUrl]) {
-            if ([metadata.fileNameView.lowercaseString isEqualToString:k_fileNameRichWorkspace.lowercaseString]) {
-                [self readFileReloadFolder];
-            } else {
-                if (self.searchController.isActive) {
-                    [self readFolder:self.serverUrl];
-                }
+    if (![metadata.serverUrl isEqualToString:self.serverUrl]) { return; }
+    
+    if (arrayDeleteMetadata.count > 0) {
+        tableMetadata *metadata = arrayDeleteMetadata.firstObject;
+        [arrayDeleteMetadata removeObjectAtIndex:0];
+        [[NCNetworking shared] deleteMetadata:metadata account:metadata.account url:metadata.url completion:^(NSInteger errorCode, NSString *errorDescription) { }];
+    }
+
+    if (errorCode == 0 ) {
+        if ([metadata.fileNameView.lowercaseString isEqualToString:k_fileNameRichWorkspace.lowercaseString]) {
+            [self readFileReloadFolder];
+        } else {
+            if (self.searchController.isActive) {
+                [self readFolder:self.serverUrl];
             }
         }
-    } else {
+    }
+    
+    if (errorCode != 0 && self.view.window != nil) {
         [[NCContentPresenter shared] messageNotification:@"_error_" description:errorDescription delay:k_dismissAfterSecond type:messageTypeError errorCode:errorCode];
     }
 }
 
 - (void)moveFile:(NSNotification *)notification
 {
-    if (self.view.window == nil) { return; }
-    
     NSDictionary *userInfo = notification.userInfo;
-//    tableMetadata *metadata = userInfo[@"metadata"];
+    tableMetadata *metadata = userInfo[@"metadata"];
 //    tableMetadata *metadataNew = userInfo[@"metadataNew"];
     NSInteger errorCode = [userInfo[@"errorCode"] integerValue];
     NSString *errorDescription = userInfo[@"errorDescription"];
     
-    if (errorCode != 0) {
+    if (![metadata.serverUrl isEqualToString:self.serverUrl]) { return; }
+    
+    if (arrayMoveMetadata.count > 0) {
+        tableMetadata *metadata = arrayMoveMetadata.firstObject;
+        NSString *serverUrlTo = arrayMoveServerUrlTo.firstObject;
+        [arrayMoveMetadata removeObjectAtIndex:0];
+        [arrayMoveServerUrlTo removeObjectAtIndex:0];
+        [[NCNetworking shared] moveMetadata:metadata serverUrlTo:serverUrlTo overwrite:true completion:^(NSInteger errorCode, NSString *errorDescription) { }];
+    }
+    
+    if (errorCode != 0 && self.view.window != nil) {
         [[NCContentPresenter shared] messageNotification:@"_error_" description:errorDescription delay:k_dismissAfterSecond type:messageTypeError errorCode:errorCode];
     }
 }
 
 - (void)copyFile:(NSNotification *)notification
 {
-    if (self.view.window == nil) { return; }
-    
     NSDictionary *userInfo = notification.userInfo;
-//    tableMetadata *metadata = userInfo[@"metadata"];
+    tableMetadata *metadata = userInfo[@"metadata"];
 //    NSString *serverUrlTo = userInfo[@"serverUrlTo"];
     NSInteger errorCode = [userInfo[@"errorCode"] integerValue];
     NSString *errorDescription = userInfo[@"errorDescription"];
     
-    if (errorCode != 0) {
+    if (![metadata.serverUrl isEqualToString:self.serverUrl]) { return; }
+    
+    if (arrayCopyMetadata.count > 0) {
+        tableMetadata *metadata = arrayCopyMetadata.firstObject;
+        NSString *serverUrlTo = arrayCopyServerUrlTo.firstObject;
+        [arrayCopyMetadata removeObjectAtIndex:0];
+        [arrayCopyServerUrlTo removeObjectAtIndex:0];
+        [[NCNetworking shared] copyMetadata:metadata serverUrlTo:serverUrlTo overwrite:true completion:^(NSInteger errorCode, NSString *errorDescription) { }];
+    }
+    
+    if (errorCode != 0 && self.view.window != nil) {
         [[NCContentPresenter shared] messageNotification:@"_error_" description:errorDescription delay:k_dismissAfterSecond type:messageTypeError errorCode:errorCode];
     }
 }
@@ -1293,13 +1328,13 @@
         return;
      
     if ([_selectedocIdsMetadatas count] > 0) {
-        [appDelegate.arrayDeleteMetadata addObjectsFromArray:[_selectedocIdsMetadatas allValues]];
+        [arrayDeleteMetadata addObjectsFromArray:[_selectedocIdsMetadatas allValues]];
     } else {
-        [appDelegate.arrayDeleteMetadata addObject:self.metadata];
+        [arrayDeleteMetadata addObject:self.metadata];
     }
     
-    [[NCNetworking shared] deleteMetadata:appDelegate.arrayDeleteMetadata.firstObject account:appDelegate.activeAccount url:appDelegate.activeUrl completion:^(NSInteger errorCode, NSString *errorDescription) { }];
-    [appDelegate.arrayDeleteMetadata removeObjectAtIndex:0];
+    [[NCNetworking shared] deleteMetadata:arrayDeleteMetadata.firstObject account:appDelegate.activeAccount url:appDelegate.activeUrl completion:^(NSInteger errorCode, NSString *errorDescription) { }];
+    [arrayDeleteMetadata removeObjectAtIndex:0];
         
     // End Select Table View
     [self tableViewSelect:false];
@@ -1317,11 +1352,11 @@
     NSMutableArray *arrayMetadata, *arrayServerUrlTo;
     
     if (move) {
-        arrayMetadata = appDelegate.arrayMoveMetadata;
-        arrayServerUrlTo = appDelegate.arrayMoveServerUrlTo;
+        arrayMetadata = arrayMoveMetadata;
+        arrayServerUrlTo = arrayMoveServerUrlTo;
     } else {
-        arrayMetadata = appDelegate.arrayCopyMetadata;
-        arrayServerUrlTo = appDelegate.arrayCopyServerUrlTo;
+        arrayMetadata = arrayCopyMetadata;
+        arrayServerUrlTo = arrayCopyServerUrlTo;
     }
     
     if ([_selectedocIdsMetadatas count] > 0) {