Parcourir la source

Improvement routine for getNumDownloadInProgressWWan (yes/no) and getNumUploadInProgressWWan (yes/no)

Marino Faggiana il y a 7 ans
Parent
commit
cea4278d4c

+ 1 - 12
iOSClient/AppDelegate.m

@@ -836,19 +836,8 @@
     
     NSInteger total = 0;
     
-    NSInteger queueDownload = [[[NCManageDatabase sharedInstance] getTableMetadataDownload] count] + [[[NCManageDatabase sharedInstance] getTableMetadataDownloadWWan] count];
-    
-    for (tableMetadata *record in [[NCManageDatabase sharedInstance] getTableMetadataUpload]) {
-        if (record.e2eEncrypted == false)
-            total++;
-    }
-    for (tableMetadata *record in [[NCManageDatabase sharedInstance] getTableMetadataUploadWWan]) {
-        if (record.e2eEncrypted == false)
-            total++;
-    }
-    
     // Total
-    total = total + queueDownload + [[NCManageDatabase sharedInstance] countQueueDownloadWithSession:nil] + [[NCManageDatabase sharedInstance] countQueueUploadWithSession:nil];
+    total = [[CCNetworking sharedNetworking] getNumDownloadInProgressWWan:NO] + [[CCNetworking sharedNetworking] getNumDownloadInProgressWWan:YES] + [[CCNetworking sharedNetworking] getNumUploadInProgressWWan:NO] + [[CCNetworking sharedNetworking] getNumUploadInProgressWWan:YES];
     
     [UIApplication sharedApplication].applicationIconBadgeNumber = total;
     

+ 5 - 0
iOSClient/Networking/CCNetworking.h

@@ -64,6 +64,11 @@
 - (void)uploadFile:(NSString *)fileName serverUrl:(NSString *)serverUrl session:(NSString *)session taskStatus:(NSInteger)taskStatus selector:(NSString *)selector selectorPost:(NSString *)selectorPost errorCode:(NSInteger)errorCode delegate:(id)delegate;
 - (void)uploadFileMetadata:(tableMetadata *)metadata taskStatus:(NSInteger)taskStatus;
 
+// Utility
+
+- (NSInteger)getNumDownloadInProgressWWan:(BOOL)WWan;
+- (NSInteger)getNumUploadInProgressWWan:(BOOL)WWan;
+
 @end
 
 @protocol CCNetworkingDelegate <NSObject>

+ 48 - 0
iOSClient/Networking/CCNetworking.m

@@ -1334,6 +1334,54 @@
     }
 }
 
+#pragma --------------------------------------------------------------------------------------------
+#pragma mark ===== Utility =====
+#pragma --------------------------------------------------------------------------------------------
+
+- (NSInteger)getNumDownloadInProgressWWan:(BOOL)WWan
+{
+    NSInteger numTableMetadataDownload, numTableQueueDownload;
+    
+    if (WWan) {
+        numTableMetadataDownload = [[[NCManageDatabase sharedInstance] getTableMetadataDownloadWWan] count];
+        numTableQueueDownload = [[NCManageDatabase sharedInstance] countQueueDownloadWithSession:k_download_session_wwan];
+    } else {
+        numTableMetadataDownload = [[[NCManageDatabase sharedInstance] getTableMetadataDownload] count];
+        numTableQueueDownload = [[NCManageDatabase sharedInstance] countQueueDownloadWithSession:k_download_session] + [[NCManageDatabase sharedInstance] countQueueDownloadWithSession:k_download_session_foreground];
+    }
+    
+    return numTableMetadataDownload + numTableQueueDownload;
+}
+
+- (NSInteger)getNumUploadInProgressWWan:(BOOL)WWan
+{
+    NSMutableArray *recordsInUpload = [NSMutableArray new];
+    
+    if (WWan) {
+        
+        for (tableMetadata *record in [[NCManageDatabase sharedInstance] getTableMetadataUploadWWan]) {
+            [recordsInUpload addObject:[record.fileNameView stringByAppendingString:record.assetLocalIdentifier]];
+        }
+        for (tableQueueUpload *record in [[NCManageDatabase sharedInstance] getQueueUploadWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND session = %@", _activeAccount, k_upload_session_wwan]]) {
+            if (![recordsInUpload containsObject:[record.fileName stringByAppendingString:record.assetLocalIdentifier]])
+                [recordsInUpload addObject:[record.fileName stringByAppendingString:record.assetLocalIdentifier]];
+        }
+        
+    } else {
+        
+        for (tableMetadata *record in [[NCManageDatabase sharedInstance] getTableMetadataUpload]) {
+            [recordsInUpload addObject:[record.fileNameView stringByAppendingString:record.assetLocalIdentifier]];
+        }
+        for (tableQueueUpload *record in [[NCManageDatabase sharedInstance] getQueueUploadWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND (session = %@ OR session = %@)", _activeAccount, k_upload_session, k_upload_session_foreground]]) {
+            if (![recordsInUpload containsObject:[record.fileName stringByAppendingString:record.assetLocalIdentifier]])
+                [recordsInUpload addObject:[record.fileName stringByAppendingString:record.assetLocalIdentifier]];
+        }
+    }
+    
+    return recordsInUpload.count;
+}
+
+
 @end
 
 #pragma --------------------------------------------------------------------------------------------

+ 10 - 27
iOSClient/Transfers/CCTransfers.m

@@ -355,20 +355,11 @@
     NSString *titleSection, *numberTitle;
     NSInteger typeOfSession = 0;
     
-    NSInteger queueDownload = [[[NCManageDatabase sharedInstance] getTableMetadataDownload] count] + [[NCManageDatabase sharedInstance] countQueueDownloadWithSession:k_download_session];
-    NSInteger queueDownloadWWan = [[[NCManageDatabase sharedInstance] getTableMetadataDownloadWWan] count] + [[NCManageDatabase sharedInstance] countQueueDownloadWithSession:k_download_session_wwan];
-    
-    NSInteger queueUpload = [[NCManageDatabase sharedInstance] countQueueUploadWithSession:k_upload_session];
-    for (tableMetadata *record in [[NCManageDatabase sharedInstance] getTableMetadataUpload]) {
-        if (record.e2eEncrypted == false)
-            queueUpload++;
-    }
-    
-    NSInteger queueUploadWWan = [[NCManageDatabase sharedInstance] countQueueUploadWithSession:k_upload_session_wwan];
-    for (tableMetadata *record in [[NCManageDatabase sharedInstance] getTableMetadataUploadWWan]) {
-        if (record.e2eEncrypted == false)
-            queueUploadWWan++;
-    }
+    NSInteger queueDownload = [[CCNetworking sharedNetworking] getNumDownloadInProgressWWan:NO];
+    NSInteger queueDownloadWWan = [[CCNetworking sharedNetworking] getNumDownloadInProgressWWan:YES];
+
+    NSInteger queueUpload = [[CCNetworking sharedNetworking] getNumUploadInProgressWWan:NO];
+    NSInteger queueUploadWWan = [[CCNetworking sharedNetworking] getNumUploadInProgressWWan:YES];
     
     if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]]) titleSection = [_sectionDataSource.sections objectAtIndex:section];
     if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSDate class]]) titleSection = [CCUtility getTitleSectionDate:[_sectionDataSource.sections objectAtIndex:section]];
@@ -450,7 +441,7 @@
     // Footer Download
     if ([titleSection containsString:@"download"] && ![titleSection containsString:@"wwan"] && titleSection != nil) {
         
-        NSInteger queueDownload = [[[NCManageDatabase sharedInstance] getTableMetadataDownload] count] + [[NCManageDatabase sharedInstance] countQueueDownloadWithSession:k_download_session];
+        NSInteger queueDownload = [[CCNetworking sharedNetworking] getNumDownloadInProgressWWan:NO];
         
         // element or elements ?
         if (queueDownload > 1) element_s = NSLocalizedString(@"_elements_",nil);
@@ -467,7 +458,7 @@
     // Footer Download WWAN
     if ([titleSection containsString:@"download"] && [titleSection containsString:@"wwan"] && titleSection != nil) {
         
-        NSInteger queueDownloadWWan = [[[NCManageDatabase sharedInstance] getTableMetadataDownloadWWan] count] + [[NCManageDatabase sharedInstance] countQueueDownloadWithSession:k_download_session_wwan];
+        NSInteger queueDownloadWWan = [[CCNetworking sharedNetworking] getNumDownloadInProgressWWan:YES];
         
         // element or elements ?
         if (queueDownloadWWan > 1) element_s = NSLocalizedString(@"_elements_",nil);
@@ -488,11 +479,7 @@
     // Footer Upload
     if ([titleSection containsString:@"upload"] && ![titleSection containsString:@"wwan"] && titleSection != nil) {
         
-        NSInteger queueUpload = [[NCManageDatabase sharedInstance] countQueueUploadWithSession:k_upload_session];
-        for (tableMetadata *record in [[NCManageDatabase sharedInstance] getTableMetadataUpload]) {
-            if (record.e2eEncrypted == false)
-                queueUpload++;
-        }
+        NSInteger queueUpload = [[CCNetworking sharedNetworking] getNumUploadInProgressWWan:NO];
         
         // element or elements ?
         if (queueUpload > 1) element_s = NSLocalizedString(@"_elements_",nil);
@@ -509,12 +496,8 @@
     // Footer Upload WWAN
     if ([titleSection containsString:@"upload"] && [titleSection containsString:@"wwan"] && titleSection != nil) {
         
-        NSInteger queueUploadWWan = [[NCManageDatabase sharedInstance] countQueueUploadWithSession:k_upload_session_wwan];
-        for (tableMetadata *record in [[NCManageDatabase sharedInstance] getTableMetadataUploadWWan]) {
-            if (record.e2eEncrypted == false)
-                queueUploadWWan++;
-        }
-        
+        NSInteger queueUploadWWan = [[CCNetworking sharedNetworking] getNumUploadInProgressWWan:YES];
+       
         // element or elements ?
         if (queueUploadWWan > 1) element_s = NSLocalizedString(@"_elements_",nil);
         else element_s = NSLocalizedString(@"_element_",nil);