Browse Source

- Improvements API preview image

marinofaggiana 5 years ago
parent
commit
ec08fce065

+ 1 - 1
Cartfile

@@ -1,4 +1,4 @@
-github "nextcloud/ios-communication-library" "v0.54"
+github "nextcloud/ios-communication-library" "develop"
 github "tilltue/TLPhotoPicker" "2.0.7"
 github "kishikawakatsumi/UICKeyChainStore" "v2.1.2"
 github "danielsaidi/Sheeeeeeeeet" "3.0.9"

+ 2 - 3
Cartfile.resolved

@@ -17,12 +17,11 @@ github "kishikawakatsumi/UICKeyChainStore" "v2.1.2"
 github "krzyzanowskim/OpenSSL" "1.0.218"
 github "malcommac/SwiftRichString" "3.7.1"
 github "marinofaggiana/AFNetworking" "2967678c3e0e98c9b8d7e06222ad12d1f49c26f2"
-github "marinofaggiana/ATGMediaBrowser" "d0cab56177b57b61db6318747232d88006f8d0d3"
 github "marinofaggiana/FastScroll" "81967c2309d29bc2c330d422da612160a30bade8"
-github "nextcloud/ios-communication-library" "v0.54"
+github "nextcloud/ios-communication-library" "12f1c4efa1717082f84681cdc6deb282272eddab"
 github "realm/realm-cocoa" "v4.3.1"
 github "rechsteiner/Parchment" "v1.7.0"
-github "scenee/FloatingPanel" "v1.7.2"
+github "scenee/FloatingPanel" "v1.7.4"
 github "tilltue/TLPhotoPicker" "2.0.7"
 github "weichsel/ZIPFoundation" "0.9.10"
 github "yahoojapan/SwiftyXMLParser" "5.1.0"

+ 1 - 4
File Provider Extension/FileProviderExtension+Thumbnail.swift

@@ -42,14 +42,11 @@ extension FileProviderExtension {
             
             if (metadata.hasPreview) {
                 
-                let width = NCUtility.sharedInstance.getScreenWidthForPreview()
-                let height = NCUtility.sharedInstance.getScreenHeightForPreview()
-                
                 let fileNamePath = CCUtility.returnFileNamePath(fromFileName: metadata.fileName, serverUrl: metadata.serverUrl, activeUrl: fileProviderData.sharedInstance.accountUrl)!
                 let fileNameLocalPath = CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, fileNameView: metadata.fileNameView)!
                 let serverUrl = fileProviderData.sharedInstance.accountUrl
                     
-                NCCommunication.sharedInstance.downloadPreview(serverUrl: serverUrl, fileNamePath: fileNamePath, fileNameLocalPath: fileNameLocalPath ,width: width, height: height, account: fileProviderData.sharedInstance.account) { (account, data, errorCode, errorDescription) in
+                NCCommunication.sharedInstance.downloadPreview(serverUrl: serverUrl, fileNamePath: fileNamePath, fileNameLocalPath: fileNameLocalPath ,width: CGFloat(k_sizePreview), height: CGFloat(k_sizePreview), account: fileProviderData.sharedInstance.account) { (account, data, errorCode, errorDescription) in
                     if errorCode == 0 && data != nil {
                         perThumbnailCompletionHandler(itemIdentifier, data, nil)
                     } else {

+ 4 - 4
iOSClient/Activity/NCActivity.swift

@@ -494,11 +494,11 @@ extension activityTableViewCell: UICollectionViewDataSource {
                             
                         } else {
                             
-                            OCNetworking.sharedManager()?.downloadPreview(withAccount: appDelegate.activeAccount, serverPath: activityPreview.source, fileNamePath: fileNamePath, completion: { (account, image, message, errorCode) in
-                                if errorCode == 0 {
-                                    cell.imageView.image = image
+                            NCCommunication.sharedInstance.downloadPreview(serverUrlPath: activityPreview.source, fileNameLocalPath: fileNamePath, width: CGFloat(k_sizePreview), height: CGFloat(k_sizePreview), account: appDelegate.activeAccount) { (account, data, errorCode, errorMessage) in
+                                if errorCode == 0 && data != nil {
+                                    cell.imageView.image = UIImage.init(data: data!)
                                 }
-                            })
+                            }
                         }
                     }
                 }

+ 2 - 0
iOSClient/CCGlobal.h

@@ -80,6 +80,8 @@
 
 #define k_maxErrorAutoUploadAll                         100
 
+#define k_sizePreview                                   1024
+
 // Database Realm
 #define k_databaseDefault                               @"nextcloud.realm"
 #define k_databaseSchemaVersion                         88

+ 2 - 8
iOSClient/Main/NCDetailViewController.swift

@@ -544,15 +544,9 @@ extension NCDetailViewController: NCViewerImageViewControllerDelegate, NCViewerI
             let fileNamePath = CCUtility.returnFileNamePath(fromFileName: metadata.fileName, serverUrl: metadata.serverUrl, activeUrl: appDelegate.activeUrl)!
             let fileNameLocalPath = CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, fileNameView: metadata.fileNameView)!
                     
-            NCCommunication.sharedInstance.downloadPreview(serverUrl: appDelegate.activeUrl, fileNamePath: fileNamePath, fileNameLocalPath: fileNameLocalPath, width: NCUtility.sharedInstance.getScreenWidthForPreview(), height: NCUtility.sharedInstance.getScreenHeightForPreview(), account: metadata.account) { (account, data, errorCode, errorMessage) in
+            NCCommunication.sharedInstance.downloadPreview(serverUrl: appDelegate.activeUrl, fileNamePath: fileNamePath, fileNameLocalPath: fileNameLocalPath, width: CGFloat(k_sizePreview), height: CGFloat(k_sizePreview), account: metadata.account) { (account, data, errorCode, errorMessage) in
                 if errorCode == 0 && data != nil {
-                    do {
-                        let url = URL.init(fileURLWithPath: fileNameLocalPath)
-                        try data!.write(to: url, options: .atomic)
-                        completion(index, UIImage.init(data: data!), metadata, ZoomScale.default, nil)
-                    } catch {
-                        completion(index, NCViewerImageCommon.shared.getImageOffOutline(frame: self.view.frame, type: metadata.typeFile), metadata, ZoomScale.default, nil)
-                    }
+                    completion(index, UIImage.init(data: data!), metadata, ZoomScale.default, nil)
                 } else {
                     completion(index, NCViewerImageCommon.shared.getImageOffOutline(frame: self.view.frame, type: metadata.typeFile), metadata, ZoomScale.default, nil)
                 }

+ 26 - 26
iOSClient/Main/NCMainCommon.swift

@@ -1482,41 +1482,41 @@ class NCNetworkingMain: NSObject, CCNetworkingDelegate, IMImagemeterViewerDelega
     func downloadThumbnail(with metadata: tableMetadata, view: Any, indexPath: IndexPath, closure: @escaping () -> ()) {
         
         if !metadata.isInvalidated && metadata.hasPreview && (!CCUtility.fileProviderStorageIconExists(metadata.ocId, fileNameView: metadata.fileName) || metadata.typeFile == k_metadataTypeFile_document) {
-            
-            let width = NCUtility.sharedInstance.getScreenWidthForPreview()
-            let height = NCUtility.sharedInstance.getScreenHeightForPreview()
-            
-            OCNetworking.sharedManager().downloadPreview(withAccount: metadata.account, metadata: metadata, withWidth: width, andHeight: height, completion: { (account, image, message, errorCode) in
-                
-                if errorCode == 0 && account == self.appDelegate.activeAccount && !metadata.isInvalidated && CCUtility.fileProviderStorageIconExists(metadata.ocId, fileNameView: metadata.fileName) {
+                        
+            let fileNamePath = CCUtility.returnFileNamePath(fromFileName: metadata.fileName, serverUrl: metadata.serverUrl, activeUrl: appDelegate.activeUrl)!
+            let fileNameLocalPath = CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, fileNameView: metadata.fileNameView)!
                     
-                    if view is UICollectionView && NCMainCommon.sharedInstance.isValidIndexPath(indexPath, view: view) {
-                        if let cell = (view as! UICollectionView).cellForItem(at: indexPath) {
-                            if cell is NCListCell {
-                                (cell as! NCListCell).imageItem.image = image
-                            } else if cell is NCGridCell {
-                                (cell as! NCGridCell).imageItem.image = image
-                            } else if cell is NCGridMediaCell {
-                                (cell as! NCGridMediaCell).imageItem.image = image
+            NCCommunication.sharedInstance.downloadPreview(serverUrl: appDelegate.activeUrl, fileNamePath: fileNamePath, fileNameLocalPath: fileNameLocalPath, width: CGFloat(k_sizePreview), height: CGFloat(k_sizePreview), account: metadata.account) { (account, data, errorCode, errorMessage) in
+                
+                if errorCode == 0 && data != nil  {
+                    if let image = UIImage.init(data: data!) {
+                        
+                        if view is UICollectionView && NCMainCommon.sharedInstance.isValidIndexPath(indexPath, view: view) {
+                            if let cell = (view as! UICollectionView).cellForItem(at: indexPath) {
+                                if cell is NCListCell {
+                                    (cell as! NCListCell).imageItem.image = image
+                                } else if cell is NCGridCell {
+                                    (cell as! NCGridCell).imageItem.image = image
+                                } else if cell is NCGridMediaCell {
+                                    (cell as! NCGridMediaCell).imageItem.image = image
+                                }
                             }
                         }
-                    }
-                    
-                    if view is UITableView && CCUtility.fileProviderStorageIconExists(metadata.ocId, fileNameView: metadata.fileName) && NCMainCommon.sharedInstance.isValidIndexPath(indexPath, view: view) {
-                        if let cell = (view as! UITableView).cellForRow(at: indexPath) {
-                            if cell is CCCellMainTransfer {
-                                (cell as! CCCellMainTransfer).file.image = image
-                            } else if cell is CCCellMain {
-                                (cell as! CCCellMain).file.image = image
+                        
+                        if view is UITableView && CCUtility.fileProviderStorageIconExists(metadata.ocId, fileNameView: metadata.fileName) && NCMainCommon.sharedInstance.isValidIndexPath(indexPath, view: view) {
+                            if let cell = (view as! UITableView).cellForRow(at: indexPath) {
+                                if cell is CCCellMainTransfer {
+                                    (cell as! CCCellMainTransfer).file.image = image
+                                } else if cell is CCCellMain {
+                                    (cell as! CCCellMain).file.image = image
+                                }
                             }
                         }
                     }
                 }
-                
                 return closure()
-            })
+            }
         }
-        
         return closure()
     }
 }

+ 2 - 0
iOSClient/Networking/OCNetworking.h

@@ -57,9 +57,11 @@
 
 #pragma mark ===== downloadPreview =====
 
+/*
 - (void)downloadPreviewWithAccount:(NSString *)account metadata:(tableMetadata*)metadata withWidth:(CGFloat)width andHeight:(CGFloat)height completion:(void (^)(NSString *account, UIImage *image, NSString *message, NSInteger errorCode))completion;
 - (void)downloadPreviewWithAccount:(NSString *)account serverPath:(NSString *)serverPath fileNamePath:(NSString *)fileNamePath completion:(void (^)(NSString *account, UIImage *image, NSString *message, NSInteger errorCode))completion;
 - (void)downloadPreviewTrashWithAccount:(NSString *)account fileId:(NSString *)fileId size:(NSString *)size fileName:(NSString *)fileName completion:(void (^)(NSString *account, UIImage *image, NSString *message, NSInteger errorCode))completion;
+*/
 
 #pragma mark ===== Share =====
 

+ 6 - 5
iOSClient/PeekPop/CCPeekPop.m

@@ -101,12 +101,13 @@
 
 - (void)downloadThumbnail
 {
-    CGFloat width = [[NCUtility sharedInstance] getScreenWidthForPreview];
-    CGFloat height = [[NCUtility sharedInstance] getScreenHeightForPreview];
+    NSString *fileNamePath = [CCUtility returnFileNamePathFromFileName:self.metadata.fileName serverUrl:self.metadata.serverUrl activeUrl:appDelegate.activeUrl];
+    NSString *fileNameLocalPath = [CCUtility getDirectoryProviderStorageOcId:self.metadata.ocId fileNameView:self.metadata.fileNameView];
     
-    [[OCNetworking sharedManager] downloadPreviewWithAccount:appDelegate.activeAccount metadata:self.metadata withWidth:width andHeight:height completion:^(NSString *account, UIImage *image, NSString *message, NSInteger errorCode) {
-     
-        if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
+    [[NCCommunication sharedInstance] downloadPreviewWithServerUrl:appDelegate.activeUrl fileNamePath:fileNamePath fileNameLocalPath:fileNameLocalPath width:k_sizePreview height:k_sizePreview account:self.metadata.account completionHandler:^(NSString *account, NSData *data, NSInteger errorCode, NSString *errorDescription) {
+
+        if (errorCode == 0) {
+            UIImage *image = [UIImage imageWithData:data];
             self.imagePreview.image = [CCGraphics scaleImage:image toSize:CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height) isAspectRation:true];
             self.preferredContentSize = CGSizeMake(self.imagePreview.image.size.width, self.imagePreview.image.size.height + highLabelFileName);
         }

+ 6 - 4
iOSClient/Trash/NCTrash.swift

@@ -779,10 +779,12 @@ extension NCTrash {
     
     func downloadThumbnail(with tableTrash: tableTrash, indexPath: IndexPath) {
         
-        OCNetworking.sharedManager().downloadPreviewTrash(withAccount: appDelegate.activeAccount, fileId: tableTrash.fileId, size: "128", fileName: tableTrash.fileName, completion: { (account, image, message, errorCode) in
+        let fileNameLocalPath = CCUtility.getDirectoryProviderStorageIconOcId(tableTrash.fileId, fileNameView: tableTrash.fileName)!
+        
+        NCCommunication.sharedInstance.downloadPreviewTrash(serverUrl: appDelegate.activeUrl, fileId: tableTrash.fileId, fileNameLocalPath: fileNameLocalPath, width: CGFloat(k_sizePreview), height: CGFloat(k_sizePreview), account: appDelegate.activeAccount) { (account, data, errorCode, errorDescription) in
             
-            if errorCode == 0 && account == self.appDelegate.activeAccount {
-                if let cell = self.collectionView.cellForItem(at: indexPath) {
+            if errorCode == 0 && data != nil && account == self.appDelegate.activeAccount {
+                if let cell = self.collectionView.cellForItem(at: indexPath), let image = UIImage.init(data: data!) {
                     if cell is NCTrashListCell {
                         (cell as! NCTrashListCell).imageItem.image = image
                     } else if cell is NCGridCell {
@@ -790,6 +792,6 @@ extension NCTrash {
                     }
                 }
             }
-        })
+        }
     }
 }

+ 2 - 5
iOSClient/Utility/CCGraphics.m

@@ -139,11 +139,8 @@
         
         originalImage = [self generateImageFromVideo:[NSTemporaryDirectory() stringByAppendingString:@"tempvideo.mp4"]];
     }
-    
-    CGFloat width = [[NCUtility sharedInstance] getScreenWidthForPreview];
-    CGFloat height = [[NCUtility sharedInstance] getScreenHeightForPreview];
-    
-    scaleImage = [self scaleImage:originalImage toSize:CGSizeMake(width, height) isAspectRation:YES];
+
+    scaleImage = [self scaleImage:originalImage toSize:CGSizeMake(k_sizePreview, k_sizePreview) isAspectRation:YES];
     scaleImage = [UIImage imageWithData:UIImageJPEGRepresentation(scaleImage, 0.5f)];
     
     // it is request write photo  ?

+ 0 - 16
iOSClient/Utility/NCUtility.swift

@@ -108,22 +108,6 @@ class NCUtility: NSObject {
         return 0
     }
     
-    @objc func getScreenWidthForPreview() -> CGFloat {
-        
-        let screenSize = UIScreen.main.bounds
-        let screenWidth = screenSize.width * 0.75
-        
-        return screenWidth
-    }
-    
-    @objc func getScreenHeightForPreview() -> CGFloat {
-        
-        let screenSize = UIScreen.main.bounds
-        let screenWidth = screenSize.height * 0.75
-        
-        return screenWidth
-    }
-    
     @objc func resizeImage(image: UIImage, newWidth: CGFloat) -> UIImage {
         
         let scale = newWidth / image.size.width