Marino Faggiana преди 6 години
родител
ревизия
8e3d077975
променени са 5 файла, в които са добавени 53 реда и са изтрити 59 реда
  1. 3 11
      iOSClient/AppDelegate.m
  2. 5 3
      iOSClient/Favorites/CCFavorites.m
  3. 2 37
      iOSClient/Main/CCMain.m
  4. 43 0
      iOSClient/Main/NCMainCommon.swift
  5. 0 8
      iOSClient/Networking/CCNetworking.m

+ 3 - 11
iOSClient/AppDelegate.m

@@ -840,9 +840,6 @@
             [tbItem setBadgeValue:[NSString stringWithFormat:@"%li", (unsigned long)total]];
         } else {
             [tbItem setBadgeValue:nil];
-            
-            NSDictionary* userInfo = @{@"fileID": @"", @"serverUrl": @"", @"progress": [NSNumber numberWithFloat:0]};
-            [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"NotificationProgressTask" object:nil userInfo:userInfo];
         }
     }
 }
@@ -1354,15 +1351,10 @@
     // delete progress
     [_listProgressMetadata removeObjectForKey:fileID];
     
-    // Progress Task
-    NSDictionary* userInfo = @{@"fileID": (fileID), @"serverUrl": (serverUrl), @"status": ([NSNumber numberWithLong:metadata.status]), @"progress": ([NSNumber numberWithFloat:0.0]), @"totalBytes": ([NSNumber numberWithLongLong:0]), @"totalBytesExpected": ([NSNumber numberWithLongLong:0])};
-    
-    [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"NotificationProgressTask" object:nil userInfo:userInfo];
-
     // Refresh
-    if (_activeMain && [_listChangeTask count] == 0) {
-        [_activeMain reloadDatasource:serverUrl];
-    }
+    [_activeMain reloadDatasource:serverUrl];
+    [_activeFavorites reloadDatasource];
+    [_activeTransfers reloadDatasource];
 }
 
 #pragma --------------------------------------------------------------------------------------------

+ 5 - 3
iOSClient/Favorites/CCFavorites.m

@@ -37,6 +37,9 @@
     // Automatic Upload Folder
     NSString *_autoUploadFileName;
     NSString *_autoUploadDirectory;
+    
+    // Datasource
+    CCSectionDataSourceMetadata *sectionDataSource;
 }
 @end
 
@@ -125,8 +128,7 @@
 
 - (void)triggerProgressTask:(NSNotification *)notification
 {
-    //NSDictionary *dict = notification.userInfo;
-    //float progress = [[dict valueForKey:@"progress"] floatValue];
+    [[NCMainCommon sharedInstance] triggerProgressTask:notification sectionDataSourceFileIDIndexPath:sectionDataSource.fileIDIndexPath tableView:self.tableView];
 }
 
 #pragma --------------------------------------------------------------------------------------------
@@ -562,7 +564,7 @@
             recordsTableMetadata = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"directoryID == %@", directoryID] sorted:sorted ascending:[CCUtility getAscendingSettings]];
     }
         
-    CCSectionDataSourceMetadata *sectionDataSource = [CCSectionMetadata creataDataSourseSectionMetadata:recordsTableMetadata listProgressMetadata:nil groupByField:nil fileIDHide:nil activeAccount:appDelegate.activeAccount];
+    sectionDataSource = [CCSectionMetadata creataDataSourseSectionMetadata:recordsTableMetadata listProgressMetadata:nil groupByField:nil fileIDHide:nil activeAccount:appDelegate.activeAccount];
         
     NSArray *fileIDs = [sectionDataSource.sectionArrayRow objectForKey:@"_none_"];
     for (NSString *fileID in fileIDs)

+ 2 - 37
iOSClient/Main/CCMain.m

@@ -2180,42 +2180,7 @@
 
 - (void)triggerProgressTask:(NSNotification *)notification
 {
-    NSDictionary *dict = notification.userInfo;
-    NSString *fileID = [dict valueForKey:@"fileID"];
-    NSString *serverUrl = [dict valueForKey:@"serverUrl"];
-    long status = [[dict valueForKey:@"status"] longValue];
-    NSString *statusString = @"";
-    float progress = [[dict valueForKey:@"progress"] floatValue];
-    long long totalBytes = [[dict valueForKey:@"totalBytes"] longLongValue];
-    long long totalBytesExpected = [[dict valueForKey:@"totalBytesExpected"] longLongValue];
-
-    // Check
-    if (!fileID || [fileID isEqualToString: @""])
-        return;
-    
-    [appDelegate.listProgressMetadata setObject:[NSArray arrayWithObjects:[NSNumber numberWithFloat:progress], [dict valueForKey:@"totalBytes"], [dict valueForKey:@"totalBytesExpected"], nil] forKey:fileID];
-    
-    if (![serverUrl isEqualToString:_serverUrl])
-        return;
-    
-    NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:fileID];
-    
-    if ([self indexPathIsValid:indexPath]) {
-        
-        CCCellMainTransfer *cell = (CCCellMainTransfer *)[self.tableView cellForRowAtIndexPath:indexPath];
-        
-        if (status == k_metadataStatusInDownload) {
-            statusString = @"↓";
-        } else if (status == k_metadataStatusInUpload) {
-            statusString = @"↑";
-        }
-        
-        cell.labelInfoFile.text = [NSString stringWithFormat:@"%@ - %@%@", [CCUtility transformedSize:totalBytesExpected], statusString, [CCUtility transformedSize:totalBytes]];
-        
-        if ([cell isKindOfClass:[CCCellMainTransfer class]]) {
-            cell.transferButton.progress = progress;
-        }
-    }
+    [[NCMainCommon sharedInstance] triggerProgressTask:notification sectionDataSourceFileIDIndexPath:_sectionDataSource.fileIDIndexPath tableView:self.tableView];
 }
 
 - (void)cancelTaskButton:(id)sender withEvent:(UIEvent *)event
@@ -4469,7 +4434,7 @@
             }
         }
         
-        // More 
+        // More
         if ([self canOpenMenuAction:metadata]) {
             
             UITapGestureRecognizer *tapMore = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionMore:)];

+ 43 - 0
iOSClient/Main/NCMainCommon.swift

@@ -293,5 +293,48 @@ class NCMainCommon: NSObject {
         }
     }
     
+    @objc func triggerProgressTask(_ notification: Notification, sectionDataSourceFileIDIndexPath: NSDictionary, tableView: UITableView) {
+        
+        guard let dic = notification.userInfo else {
+            return
+        }
+        
+        let fileID = dic["fileID"] as! NSString
+        _ = dic["serverUrl"] as! NSString
+        let status = dic["status"] as! Int
+        let progress = dic["progress"] as! CGFloat
+        let totalBytes = dic["totalBytes"] as! Double
+        let totalBytesExpected = dic["totalBytesExpected"] as! Double
+        
+        appDelegate.listProgressMetadata.setObject([progress as NSNumber, totalBytes as NSNumber, totalBytesExpected as NSNumber], forKey: fileID)
+        
+        guard let indexPath = sectionDataSourceFileIDIndexPath.object(forKey: fileID) else {
+            return
+        }
+        
+        if isValidIndexPath(indexPath as! IndexPath, tableView: tableView) {
+        
+            if let cell = tableView.cellForRow(at: indexPath as! IndexPath) as? CCCellMainTransfer {
+                
+                var image = ""
+
+                if status == k_metadataStatusInDownload {
+                    image = "↓"
+                } else if status == k_metadataStatusInUpload {
+                    image = "↑"
+                }
+                
+                cell.labelInfoFile.text = CCUtility.transformedSize(totalBytesExpected) + " - " + image + CCUtility.transformedSize(totalBytes)
+                cell.transferButton.progress = progress
+            }
+        }
+    }
+    
+    func isValidIndexPath(_ indexPath: IndexPath, tableView: UITableView) -> Bool {
+        
+        return indexPath.section < tableView.numberOfSections && indexPath.row < tableView.numberOfRows(inSection: indexPath.section)
+
+    }
+    
 }
 

+ 0 - 8
iOSClient/Networking/CCNetworking.m

@@ -629,10 +629,6 @@
     [appDelegate.listProgressMetadata removeObjectForKey:fileID];
 #endif
     
-    // Progress Task
-    NSDictionary* userInfo = @{@"fileID": (fileID), @"serverUrl": (serverUrl), @"progress": ([NSNumber numberWithFloat:0.0])};
-    [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"NotificationProgressTask" object:nil userInfo:userInfo];
-        
     if (errorCode != 0) {
         
         if (errorCode != kCFURLErrorCancelled) {
@@ -1029,10 +1025,6 @@
     NSString *errorMessage = @"";
     BOOL isE2EEDirectory = false;
     
-    // Progress Task
-    NSDictionary* userInfo = @{@"fileID": (fileID), @"serverUrl": (serverUrl), @"progress": ([NSNumber numberWithFloat:0.0])};
-    [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"NotificationProgressTask" object:nil userInfo:userInfo];
-    
     // E2EE Directory ?
     if ([CCUtility isFolderEncrypted:serverUrl account:_activeAccount] && [CCUtility isEndToEndEnabled:_activeAccount]) {
         isE2EEDirectory = true;