Browse Source

remake protocol downloadThumbnailSuccessFailure

Marino Faggiana 7 years ago
parent
commit
5a1954e497

+ 14 - 12
Picker/DocumentPickerViewController.swift

@@ -280,22 +280,24 @@ class DocumentPickerViewController: UIDocumentPickerExtensionViewController, CCN
     
     //  MARK: - Download Thumbnail
     
-    func downloadThumbnailFailure(_ metadataNet: CCMetadataNet!, message: String!, errorCode: Int) {
-        NSLog("[LOG] Thumbnail Error \(metadataNet.fileName) \(message) (error \(errorCode))");
-    }
-    
-    func downloadThumbnailSuccess(_ metadataNet: CCMetadataNet!) {
+    func downloadThumbnailSuccessFailure(_ metadataNet: CCMetadataNet!, message: String!, errorCode: Int) {
         
-        if let indexPath = thumbnailInLoading[metadataNet.fileID] {
-            
-            let path = "\(directoryUser)/\(metadataNet.fileID!).ico"
-            
-            if FileManager.default.fileExists(atPath: path) {
+        if (errorCode == 0) {
+        
+            if let indexPath = thumbnailInLoading[metadataNet.fileID] {
                 
-                if let cell = tableView.cellForRow(at: indexPath) as? recordMetadataCell {
-                    cell.fileImageView.image = UIImage(contentsOfFile: path)
+                let path = "\(directoryUser)/\(metadataNet.fileID!).ico"
+                
+                if FileManager.default.fileExists(atPath: path) {
+                    
+                    if let cell = tableView.cellForRow(at: indexPath) as? recordMetadataCell {
+                        cell.fileImageView.image = UIImage(contentsOfFile: path)
+                    }
                 }
             }
+        } else {
+            
+            NSLog("[LOG] Thumbnail Error \(metadataNet.fileName) \(message) (error \(errorCode))");
         }
     }
     

+ 3 - 8
iOSClient/Actions/CCActions.swift

@@ -42,7 +42,7 @@ import Foundation
 
 @objc protocol CCActionsDownloadThumbnailDelegate {
     
-    func downloadThumbnailSuccess(_ metadataNet: CCMetadataNet)
+    func downloadThumbnailSuccessFailure(_ metadataNet: CCMetadataNet, message: NSString, errorCode: NSInteger)
 }
 
 @objc protocol CCActionsSettingFavoriteDelegate {
@@ -355,14 +355,9 @@ class CCActions: NSObject {
         appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
     }
 
-    @objc func downloadThumbnailSuccess(_ metadataNet: CCMetadataNet) {
+    @objc func downloadThumbnailSuccessFailure(_ metadataNet: CCMetadataNet, message: NSString, errorCode: NSInteger) {
         
-        metadataNet.delegate?.downloadThumbnailSuccess(metadataNet)
-    }
-    
-    @objc func downloadThumbnailFailure(_ metadataNet: CCMetadataNet, message: NSString, errorCode: NSInteger) {
-        
-        NSLog("[LOG] Thumbnail Error \(metadataNet.fileName!) \(message) error %\(errorCode))")
+        metadataNet.delegate?.downloadThumbnailSuccessFailure(metadataNet, message: message, errorCode: errorCode)        
     }
 
     // --------------------------------------------------------------------------------------------

+ 1 - 1
iOSClient/Favorites/CCFavorites.m

@@ -286,7 +286,7 @@
 #pragma mark ==== Download Thumbnail <Delegate> ====
 #pragma --------------------------------------------------------------------------------------------
 
-- (void)downloadThumbnailSuccess:(CCMetadataNet *)metadataNet
+- (void)downloadThumbnailSuccessFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
 {
     // Check Active Account
     if (![metadataNet.account isEqualToString:appDelegate.activeAccount])

+ 14 - 16
iOSClient/Main/CCMain.m

@@ -1282,27 +1282,25 @@
 #pragma mark ==== Download Thumbnail Delegate ====
 #pragma --------------------------------------------------------------------------------------------
 
-- (void)downloadThumbnailFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
+- (void)downloadThumbnailSuccessFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
 {
     // Check Active Account
     if (![metadataNet.account isEqualToString:appDelegate.activeAccount])
         return;
     
-    NSLog(@"[LOG] Download Thumbnail Failure error %d, %@", (int)errorCode, message);
-}
-
-- (void)downloadThumbnailSuccess:(CCMetadataNet *)metadataNet
-{
-    // Check Active Account
-    if (![metadataNet.account isEqualToString:appDelegate.activeAccount])
-        return;
-    
-    NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadataNet.fileID];
-    
-    if ([self indexPathIsValid:indexPath]) {
-    
-        if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", appDelegate.directoryUser, metadataNet.fileID]])
-            [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
+    if (errorCode == 0) {
+        
+        NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadataNet.fileID];
+        
+        if ([self indexPathIsValid:indexPath]) {
+        
+            if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", appDelegate.directoryUser, metadataNet.fileID]])
+                [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
+        }
+        
+    } else {
+        
+        NSLog(@"[LOG] Download Thumbnail Failure error %d, %@", (int)errorCode, message);
     }
 }
 

+ 1 - 2
iOSClient/Networking/OCNetworking.h

@@ -48,8 +48,7 @@
 
 @optional
 
-- (void)downloadThumbnailSuccess:(CCMetadataNet *)metadataNet;
-- (void)downloadThumbnailFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode;
+- (void)downloadThumbnailSuccessFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode;
 
 - (void)readFolderSuccess:(CCMetadataNet *)metadataNet metadataFolder:(tableMetadata *)metadataFolder metadatas:(NSArray *)metadatas;
 - (void)readFolderFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode;

+ 10 - 8
iOSClient/Networking/OCNetworking.m

@@ -149,7 +149,8 @@
     
     if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.%@", directoryUser, _metadataNet.fileID, ext]]) {
         
-        [self.delegate downloadThumbnailSuccess:_metadataNet];
+        if ([self.delegate respondsToSelector:@selector(downloadThumbnailSuccessFailure:message:errorCode:)])
+            [self.delegate downloadThumbnailSuccessFailure:_metadataNet message:nil errorCode:0];
         
         [self complete];
         
@@ -170,12 +171,13 @@
             
             [CCGraphics saveIcoWithEtag:_metadataNet.fileID image:thumbnailImage writeToFile:[NSString stringWithFormat:@"%@/%@.%@", directoryUser, _metadataNet.fileID, ext] copy:NO move:NO fromPath:nil toPath:nil];
 
-            if ([self.delegate respondsToSelector:@selector(downloadThumbnailSuccess:)] && [_metadataNet.action isEqualToString:actionDownloadThumbnail])
-                [self.delegate downloadThumbnailSuccess:_metadataNet];
+            if ([self.delegate respondsToSelector:@selector(downloadThumbnailSuccessFailure:message:errorCode:)] && [_metadataNet.action isEqualToString:actionDownloadThumbnail])
+                [self.delegate downloadThumbnailSuccessFailure:_metadataNet message:nil errorCode:0];
+            
         } else {
             
-            if ([self.delegate respondsToSelector:@selector(downloadThumbnailFailure:message:errorCode:)] && [_metadataNet.action isEqualToString:actionDownloadThumbnail])
-                [self.delegate downloadThumbnailFailure:_metadataNet message:NSLocalizedStringFromTable(@"_error_user_not_available_", @"Error", nil) errorCode:k_CCErrorUserNotAvailble];
+            if ([self.delegate respondsToSelector:@selector(downloadThumbnailSuccessFailure:message:errorCode:)] && [_metadataNet.action isEqualToString:actionDownloadThumbnail])
+                [self.delegate downloadThumbnailSuccessFailure:_metadataNet message:NSLocalizedStringFromTable(@"_error_user_not_available_", @"Error", nil) errorCode:k_CCErrorUserNotAvailble];
         }
         
         [self complete];
@@ -187,12 +189,12 @@
             errorCode = error.code;
         
         // Error
-        if ([self.delegate respondsToSelector:@selector(downloadThumbnailFailure:message:errorCode:)] && [_metadataNet.action isEqualToString:actionDownloadThumbnail]) {
+        if ([self.delegate respondsToSelector:@selector(downloadThumbnailSuccessFailure:message:errorCode:)] && [_metadataNet.action isEqualToString:actionDownloadThumbnail]) {
             
             if (errorCode == 503)
-                [self.delegate downloadThumbnailFailure:_metadataNet message:NSLocalizedStringFromTable(@"_server_error_retry_", @"Error", nil) errorCode:errorCode];
+                [self.delegate downloadThumbnailSuccessFailure:_metadataNet message:NSLocalizedStringFromTable(@"_server_error_retry_", @"Error", nil) errorCode:errorCode];
             else
-                [self.delegate downloadThumbnailFailure:_metadataNet message:[CCError manageErrorOC:response.statusCode error:error] errorCode:errorCode];
+                [self.delegate downloadThumbnailSuccessFailure:_metadataNet message:[CCError manageErrorOC:response.statusCode error:error] errorCode:errorCode];
         }
         
         [self complete];

+ 16 - 19
iOSClient/PeekPop/CCPeekPop.m

@@ -90,30 +90,27 @@
 #pragma mark ==== Download Thumbnail ====
 #pragma --------------------------------------------------------------------------------------------
 
-- (void)downloadThumbnailSuccess:(CCMetadataNet *)metadataNet
+- (void)downloadThumbnailSuccessFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
 {
     // Check Active Account
     if (![metadataNet.account isEqualToString:appDelegate.activeAccount])
         return;
     
-    UIImage *image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.pvw",appDelegate.directoryUser, _metadata.fileID]];
-    
-    _imagePreview.image = image;
-    
-    _imagePreview.contentMode = UIViewContentModeScaleToFill;
-    
-    self.preferredContentSize = CGSizeMake(image.size.width, image.size.height);
-}
-
-- (void)downloadThumbnailFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
-{
-    // Check Active Account
-    if (![metadataNet.account isEqualToString:appDelegate.activeAccount])
-        return;
-    
-    [appDelegate messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
-    
-    [self dismissViewControllerAnimated:YES completion:nil];
+    if (errorCode == 0) {
+        
+        UIImage *image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.pvw",appDelegate.directoryUser, _metadata.fileID]];
+        
+        _imagePreview.image = image;
+        _imagePreview.contentMode = UIViewContentModeScaleToFill;
+        
+        self.preferredContentSize = CGSizeMake(image.size.width, image.size.height);
+        
+    } else {
+        
+        [appDelegate messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
+        
+        [self dismissViewControllerAnimated:YES completion:nil];
+    }
 }
 
 - (void)downloadThumbnail:(tableMetadata *)metadata

+ 10 - 7
iOSClient/Photos/CCPhotos.m

@@ -507,18 +507,21 @@
 #pragma mark ==== Download Thumbnail Delegate ====
 #pragma --------------------------------------------------------------------------------------------
 
-- (void)downloadThumbnailSuccess:(CCMetadataNet *)metadataNet
+- (void)downloadThumbnailSuccessFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
 {
     // Check Active Account
     if (![metadataNet.account isEqualToString:appDelegate.activeAccount])
         return;
     
-    NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadataNet.fileID];
-    
-    if ([self indexPathIsValid:indexPath]) {
-    
-        if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", appDelegate.directoryUser, metadataNet.fileID]])
-            [self.collectionView reloadItemsAtIndexPaths:@[indexPath]];
+    if (errorCode == 0) {
+        
+        NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadataNet.fileID];
+        
+        if ([self indexPathIsValid:indexPath]) {
+        
+            if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", appDelegate.directoryUser, metadataNet.fileID]])
+                [self.collectionView reloadItemsAtIndexPaths:@[indexPath]];
+        }
     }
 }
 

+ 5 - 2
iOSClient/Shares/NCShares.m

@@ -143,9 +143,12 @@
 #pragma mark ==== Download Thumbnail <Delegate> ====
 #pragma --------------------------------------------------------------------------------------------
 
-- (void)downloadThumbnailSuccess:(CCMetadataNet *)metadataNet
+- (void)downloadThumbnailSuccessFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
 {
-    [self reloadDatasource];
+    if (errorCode == 0) {
+        
+        [self reloadDatasource];
+    }
 }
 
 #pragma --------------------------------------------------------------------------------------------

+ 8 - 5
iOSClient/Transfers/CCTransfers.m

@@ -293,17 +293,20 @@
 #pragma mark - ==== download Thumbnail ====
 #pragma --------------------------------------------------------------------------------------------
 
-- (void)downloadThumbnailSuccess:(CCMetadataNet *)metadataNet
+- (void)downloadThumbnailSuccessFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
 {
     // Check Active Account
     if (![metadataNet.account isEqualToString:appDelegate.activeAccount])
         return;
     
-    NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadataNet.fileID];
-    
-    if (indexPath && [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", appDelegate.directoryUser, metadataNet.fileID]]) {
+    if (errorCode == 0) {
+        
+        NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadataNet.fileID];
         
-        [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
+        if (indexPath && [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", appDelegate.directoryUser, metadataNet.fileID]]) {
+            
+            [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
+        }
     }
 }