Преглед на файлове

new system ProgressTask

Marino Faggiana преди 8 години
родител
ревизия
f4f0d00204

+ 6 - 1
Share Ext/ShareViewController.m

@@ -114,6 +114,8 @@
         }
     }
 
+    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(triggerProgressTask:) name:@"NotificationProgressTask" object:nil];
+    
     _filesName = [[NSMutableArray alloc] init];
     _filesSendCryptated = [[NSMutableArray alloc] init];
     _hud = [[CCHud alloc] initWithView:self.navigationController.view];
@@ -294,8 +296,11 @@
 #pragma mark ======================= NetWorking ==================================
 #pragma --------------------------------------------------------------------------------------------
 
-- (void)progressTask:(NSString *)fileID serverUrl:(NSString *)serverUrl cryptated:(BOOL)cryptated progress:(float)progress
+- (void)triggerProgressTask:(NSNotification *)notification
 {
+    NSDictionary *dict = notification.userInfo;
+    float progress = [[dict valueForKey:@"progress"] floatValue];
+
     [self.hud progress:progress];
 }
 

+ 6 - 5
iOSClient/AppDelegate.m

@@ -1269,6 +1269,8 @@
 
 - (void)changeTask:(CCMetadata *)metadata
 {
+    NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:metadata.account];
+    
     if ([[_listChangeTask objectForKey:metadata.fileID] isEqualToString:@"stopUpload"]) {
         
         // sessionTaskIdentifier on Stop
@@ -1288,8 +1290,6 @@
             
         if (metadata.sessionTaskIdentifier != k_taskIdentifierDone) downloadData = YES;
         if (metadata.sessionTaskIdentifierPlist != k_taskIdentifierDone) downloadPlist = YES;
-            
-        NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:metadata.account];
         
         dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
             [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:serverUrl downloadData:downloadData downloadPlist:downloadPlist selector:metadata.sessionSelector selectorPost:metadata.sessionSelectorPost session:k_download_session taskStatus:k_taskStatusResume delegate:nil];
@@ -1314,10 +1314,11 @@
     // delete progress
     [_listProgressMetadata removeObjectForKey:metadata.fileID];
     
-    // Detail
-    if (_activeDetail)
-        [_activeDetail progressTask:nil serverUrl:nil cryptated:NO progress:0];
+    // Progress Task
+    NSDictionary* userInfo = @{@"fileID": (metadata.fileID), @"serverUrl": (serverUrl), @"cryptated": ([NSNumber numberWithBool:NO]), @"progress": ([NSNumber numberWithFloat:0.0])};
     
+    [[NSNotificationCenter defaultCenter] postNotificationName:@"NotificationProgressTask" object:nil userInfo:userInfo];
+
     // Refresh
     if (_activeMain && [_listChangeTask count] == 0) {
         [_activeMain reloadDatasource:[CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:metadata.account] fileID:nil selector:nil];

+ 0 - 1
iOSClient/Main/CCDetail.h

@@ -69,7 +69,6 @@
 
 - (void)downloadPhotoBrowserFailure:(NSInteger)errorCode;
 - (void)downloadPhotoBrowserSuccess:(CCMetadata *)metadataVar selector:(NSString *)selector;
-- (void)progressTask:(NSString *)fileID serverUrl:(NSString *)serverUrl cryptated:(BOOL)cryptated progress:(float)progress;
 
 @end
 

+ 6 - 1
iOSClient/Main/CCDetail.m

@@ -60,6 +60,8 @@
     if (self = [super initWithCoder:aDecoder])  {
         
         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(insertGeocoderLocation:) name:@"insertGeocoderLocation" object:nil];
+        
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(triggerProgressTask:) name:@"NotificationProgressTask" object:nil];
 
         self.metadataDetail = [[CCMetadata alloc] init];
         self.photos = [[NSMutableArray alloc] init];
@@ -711,8 +713,11 @@
     [self.parentViewController presentViewController:alertController animated:YES completion:NULL];
 }
 
-- (void)progressTask:(NSString *)fileID serverUrl:(NSString *)serverUrl cryptated:(BOOL)cryptated progress:(float)progress
+- (void)triggerProgressTask:(NSNotification *)notification
 {
+    NSDictionary *dict = notification.userInfo;
+    float progress = [[dict valueForKey:@"progress"] floatValue];
+    
     if (progress == 0)
         [self.navigationController cancelCCProgress];
     else

+ 0 - 2
iOSClient/Main/CCMain.h

@@ -82,8 +82,6 @@
 
 - (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;
-
 - (void)reloadTaskButton:(CCMetadata *)metadata;
 - (void)cancelTaskButton:(CCMetadata *)metadata reloadTable:(BOOL)reloadTable;
 - (void)stopTaskButton:(CCMetadata *)metadata;

+ 10 - 4
iOSClient/Main/CCMain.m

@@ -109,8 +109,8 @@
         
         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(initializeMain:) name:@"initializeMain" object:nil];
         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(clearDateReadDataSource:) name:@"clearDateReadDataSource" object:nil];
-        
         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setTitle) name:@"setTitleMain" object:nil];
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(triggerProgressTask:) name:@"NotificationProgressTask" object:nil];
     }
     
     return self;
@@ -2621,17 +2621,23 @@
 #pragma mark ===== Progress & Task Button =====
 #pragma --------------------------------------------------------------------------------------------
 
-- (void)progressTask:(NSString *)fileID serverUrl:(NSString *)serverUrl cryptated:(BOOL)cryptated progress:(float)progress;
+- (void)triggerProgressTask:(NSNotification *)notification
 {
+    NSDictionary *dict = notification.userInfo;
+    NSString *fileID = [dict valueForKey:@"fileID"];
+    NSString *serverUrl = [dict valueForKey:@"serverUrl"];
+    BOOL cryptated = [[dict valueForKey:@"cryptated"] boolValue];
+    float progress = [[dict valueForKey:@"progress"] floatValue];
+    
     // Check
     if (!fileID)
         return;
     
     [app.listProgressMetadata setObject:[NSNumber numberWithFloat:progress] forKey:fileID];
-
+    
     if (![serverUrl isEqualToString:_serverUrl])
         return;
-
+    
     NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:fileID];
     
     if (indexPath) {

+ 0 - 1
iOSClient/MenuAccount+ControlCenter/CCControlCenterTransfer.h

@@ -16,6 +16,5 @@
 @property (nonatomic, weak) IBOutlet UITableView *tableView;
 
 - (void)reloadDatasource;
-- (void)progressTask:(NSString *)fileID serverUrl:(NSString *)serverUrl cryptated:(BOOL)cryptated progress:(float)progress;
 
 @end

+ 9 - 2
iOSClient/MenuAccount+ControlCenter/CCControlCenterTransfer.m

@@ -38,6 +38,8 @@
     if (self = [super initWithCoder:aDecoder])  {
         
         app.controlCenterTransfer = self;
+        
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(triggerProgressTask:) name:@"NotificationProgressTask" object:nil];
     }
     return self;
 }
@@ -85,9 +87,14 @@
 #pragma mark - ===== Progress & Task Button =====
 #pragma --------------------------------------------------------------------------------------------
 
-- (void)progressTask:(NSString *)fileID serverUrl:(NSString *)serverUrl cryptated:(BOOL)cryptated progress:(float)progress;
+- (void)triggerProgressTask:(NSNotification *)notification
 {
-    // Chech
+    NSDictionary *dict = notification.userInfo;
+    NSString *fileID = [dict valueForKey:@"fileID"];
+    BOOL cryptated = [[dict valueForKey:@"cryptated"] boolValue];
+    float progress = [[dict valueForKey:@"progress"] floatValue];
+    
+    // Check
     if (!fileID)
         return;
     

+ 0 - 2
iOSClient/Networking/CCNetworking.h

@@ -87,6 +87,4 @@
 @optional - (void)uploadFileSuccess:(CCMetadataNet *)metadataNet fileID:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector selectorPost:(NSString *)selectorPost;
 @optional - (void)uploadFileFailure:(CCMetadataNet *)metadataNet fileID:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector message:(NSString *)message errorCode:(NSInteger)errorCode;
 
-@optional - (void)progressTask:(NSString *)fileID serverUrl:(NSString *)serverUrl cryptated:(BOOL)cryptated progress:(float)progress;
-
 @end

+ 10 - 18
iOSClient/Networking/CCNetworking.m

@@ -589,17 +589,10 @@
     dispatch_async(dispatch_get_main_queue(), ^{
         
         if (_currentProgressMetadata) {
- 
-#ifndef EXTENSION
-            // Control Center
-           [app.controlCenterTransfer progressTask:_currentProgressMetadata.fileID serverUrl:serverUrl cryptated:_currentProgressMetadata.cryptated progress:progress];
-        
-            // Detail
-            if (app.activeDetail)
-                [app.activeDetail progressTask:_currentProgressMetadata.fileID serverUrl:serverUrl cryptated:_currentProgressMetadata.cryptated progress:progress];
-#endif
-            if ([self.delegate respondsToSelector:@selector(progressTask:serverUrl:cryptated:progress:)])
-                [self.delegate progressTask:_currentProgressMetadata.fileID serverUrl:serverUrl cryptated:_currentProgressMetadata.cryptated progress:progress];
+            
+            NSDictionary* userInfo = @{@"fileID": (_currentProgressMetadata.fileID), @"serverUrl": (serverUrl), @"cryptated": ([NSNumber numberWithBool:_currentProgressMetadata.cryptated]), @"progress": ([NSNumber numberWithFloat:progress])};
+            
+            [[NSNotificationCenter defaultCenter] postNotificationName:@"NotificationProgressTask" object:nil userInfo:userInfo];
         }
     });
 }
@@ -1271,13 +1264,12 @@
         
         if (_currentProgressMetadata) {
             
-#ifndef EXTENSION
-            // Control Center
-            [app.controlCenterTransfer progressTask:_currentProgressMetadata.fileID serverUrl:serverUrl cryptated:_currentProgressMetadata.cryptated progress:progress];
-#endif
-            
-            if ([self.delegate respondsToSelector:@selector(progressTask:serverUrl:cryptated:progress:)])
-                [self.delegate progressTask:_currentProgressMetadata.fileID serverUrl:serverUrl cryptated:_currentProgressMetadata.cryptated progress:progress];
+            if (_currentProgressMetadata) {
+                
+                NSDictionary* userInfo = @{@"fileID": (_currentProgressMetadata.fileID), @"serverUrl": (serverUrl), @"cryptated": ([NSNumber numberWithBool:_currentProgressMetadata.cryptated]), @"progress": ([NSNumber numberWithFloat:progress])};
+                
+                [[NSNotificationCenter defaultCenter] postNotificationName:@"NotificationProgressTask" object:nil userInfo:userInfo];
+            }
         }
     });
 }

+ 0 - 3
iOSClient/Networking/OCNetworking.h

@@ -118,9 +118,6 @@
 - (void)listingFavoritesSuccess:(CCMetadataNet *)metadataNet metadatas:(NSArray *)metadatas;
 - (void)listingFavoritesFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode;
 
-// HUD
-- (void)progressTask:(NSString *)fileID serverUrl:(NSString *)serverUrl cryptated:(BOOL)cryptated progress:(float)progress;
-
 @end
 
 @interface OCURLSessionManager : AFURLSessionManager