瀏覽代碼

new Class

Marino Faggiana 6 年之前
父節點
當前提交
3a125770f6
共有 2 個文件被更改,包括 55 次插入2 次删除
  1. 36 2
      iOSClient/Main/NCMainCommon.swift
  2. 19 0
      iOSClient/Transfers/CCTransfers.m

+ 36 - 2
iOSClient/Main/NCMainCommon.swift

@@ -343,6 +343,10 @@ class NCMainCommon: NSObject {
     
     @objc func cancelTransferMetadata(_ metadata: tableMetadata, reloadDatasource: Bool) {
         
+        if metadata.session.count == 0 {
+            return
+        }
+        
         let session = CCNetworking.shared().getSessionfromSessionDescription(metadata.session) as URLSession
         
         // SESSION EXTENSION
@@ -361,8 +365,8 @@ class NCMainCommon: NSObject {
          
             appDelegate.activeMain.reloadDatasource()
             appDelegate.activeFavorites.reloadDatasource()
-            if (self.appDelegate.activeTransfers != nil) {
-                self.appDelegate.activeTransfers.reloadDatasource()
+            if (appDelegate.activeTransfers != nil) {
+                appDelegate.activeTransfers.reloadDatasource()
             }
             
             return
@@ -370,11 +374,25 @@ class NCMainCommon: NSObject {
         
         session.getTasksWithCompletionHandler { (dataTasks, uploadTasks, downloadTasks) in
             
+            var cancel = false
+            
             // DOWNLOAD
             if metadata.session.count > 0 && metadata.session.contains("download") {
                 for task in downloadTasks {
                     if task.taskIdentifier == metadata.sessionTaskIdentifier {
                         task.cancel()
+                        cancel = true
+                    }
+                }
+                if cancel == false {
+                    DispatchQueue.main.async {
+                        NCManageDatabase.sharedInstance.setMetadataSession("", sessionError: "", sessionSelector: "", sessionTaskIdentifier: Int(k_taskIdentifierDone), status: Int(k_metadataStatusNormal), predicate: NSPredicate(format: "fileID == %@", metadata.fileID))
+                        
+                        self.appDelegate.activeMain.reloadDatasource()
+                        self.appDelegate.activeFavorites.reloadDatasource()
+                        if (self.appDelegate.activeTransfers != nil) {
+                            self.appDelegate.activeTransfers.reloadDatasource()
+                        }
                     }
                 }
             }
@@ -384,6 +402,22 @@ class NCMainCommon: NSObject {
                 for task in uploadTasks {
                     if task.taskIdentifier == metadata.sessionTaskIdentifier {
                         task.cancel()
+                        cancel = true
+                    }
+                }
+                if cancel == false {
+                    DispatchQueue.main.async {
+                        do {
+                            try FileManager.default.removeItem(atPath: CCUtility.getDirectoryProviderStorageFileID(metadata.fileID))
+                        }
+                        catch { }
+                        NCManageDatabase.sharedInstance.deleteMetadata(predicate: NSPredicate(format: "fileID == %@", metadata.fileID), clearDateReadDirectoryID: metadata.directoryID)
+                        
+                        self.appDelegate.activeMain.reloadDatasource()
+                        self.appDelegate.activeFavorites.reloadDatasource()
+                        if (self.appDelegate.activeTransfers != nil) {
+                            self.appDelegate.activeTransfers.reloadDatasource()
+                        }
                     }
                 }
             }

+ 19 - 0
iOSClient/Transfers/CCTransfers.m

@@ -142,6 +142,20 @@
     return [[NSAttributedString alloc] initWithString:text attributes:attributes];
 }
 
+#pragma --------------------------------------------------------------------------------------------
+#pragma mark ==== Download Thumbnail ====
+#pragma --------------------------------------------------------------------------------------------
+
+- (void)downloadThumbnail:(tableMetadata *)metadata serverUrl:(NSString *)serverUrl indexPath:(NSIndexPath *)indexPath
+{
+    OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:nil metadataNet:nil withUser:appDelegate.activeUser withUserID:appDelegate.activeUserID withPassword:appDelegate.activePassword withUrl:appDelegate.activeUrl];
+    [ocNetworking downloadThumbnailWithDimOfThumbnail:@"m" fileID:metadata.fileID fileNamePath:[CCUtility returnFileNamePathFromFileName:metadata.fileName serverUrl:serverUrl activeUrl:appDelegate.activeUrl] fileNameView:metadata.fileNameView completion:^(NSString *message, NSInteger errorCode) {
+        if(errorCode == 0 && [[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageIconFileID:metadata.fileID fileNameView:metadata.fileNameView]]) {
+            [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
+        }
+    }];
+}
+
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark - ===== Progress & Task Button =====
 #pragma --------------------------------------------------------------------------------------------
@@ -436,6 +450,11 @@
     }
     
     tableMetadata *metadataFolder = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", directory.fileID]];
+    
+    // Download thumbnail
+    if (metadata.thumbnailExists && ![[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageIconFileID:metadata.fileID fileNameView:metadata.fileNameView]] && !metadataFolder.e2eEncrypted) {
+        [self downloadThumbnail:metadata serverUrl:serverUrl indexPath:indexPath];
+    }
   
     UITableViewCell *cell = [[NCMainCommon sharedInstance] cellForRowAtIndexPath:indexPath tableView:tableView metadata:metadata metadataFolder:metadataFolder serverUrl:serverUrl autoUploadFileName:@"" autoUploadDirectory:@""];