Browse Source

fix activity image

Signed-off-by: Marino Faggiana <ios@nextcloud.com>
Marino Faggiana 2 years ago
parent
commit
5ddf71cc7a

+ 11 - 20
iOSClient/Activity/NCActivityTableViewCell.swift

@@ -205,13 +205,11 @@ extension NCActivityTableViewCell: UICollectionViewDataSource {
 
             let source = activityPreview.source
 
-            NCUtility.shared.convertSVGtoPNGWriteToUserData(svgUrlString: source, fileName: nil, width: 100, rewrite: false, account: appDelegate.account) { imageNamePath in
-                if imageNamePath != nil {
-                    if let image = UIImage(contentsOfFile: imageNamePath!) {
-                        cell.imageView.image = image
-                    }
+            NCUtility.shared.convertSVGtoPNGWriteToUserData(svgUrlString: source, width: 100, rewrite: false, account: appDelegate.account, id: idActivity) { imageNamePath, id in
+                if let imageNamePath = imageNamePath, id == self.idActivity, let image = UIImage(contentsOfFile: imageNamePath) {
+                    cell.imageView.image = image
                 } else {
-                     cell.imageView.image = UIImage(named: "file_photo")
+                    cell.imageView.image = UIImage(named: "file")
                 }
             }
 
@@ -221,13 +219,11 @@ extension NCActivityTableViewCell: UICollectionViewDataSource {
 
                 let source = activityPreview.source
 
-                NCUtility.shared.convertSVGtoPNGWriteToUserData(svgUrlString: source, fileName: nil, width: 100, rewrite: false, account: appDelegate.account) { imageNamePath in
-                    if imageNamePath != nil {
-                        if let image = UIImage(contentsOfFile: imageNamePath!) {
-                            cell.imageView.image = image
-                        }
+                NCUtility.shared.convertSVGtoPNGWriteToUserData(svgUrlString: source, width: 100, rewrite: false, account: appDelegate.account, id: idActivity) { imageNamePath, id in
+                    if let imageNamePath = imageNamePath, id == self.idActivity, let image = UIImage(contentsOfFile: imageNamePath) {
+                        cell.imageView.image = image
                     } else {
-                        cell.imageView.image = UIImage(named: "file_photo")
+                        cell.imageView.image = UIImage(named: "file")
                     }
                 }
 
@@ -236,15 +232,10 @@ extension NCActivityTableViewCell: UICollectionViewDataSource {
                 if let activitySubjectRich = NCManageDatabase.shared.getActivitySubjectRich(account: activityPreview.account, idActivity: idActivity, id: fileId) {
 
                     let fileNamePath = CCUtility.getDirectoryUserData() + "/" + activitySubjectRich.name
-
-                    if FileManager.default.fileExists(atPath: fileNamePath) {
-
-                        if let image = UIImage(contentsOfFile: fileNamePath) {
-                            cell.imageView.image = image
-                        }
-
+                    
+                    if FileManager.default.fileExists(atPath: fileNamePath), let image = UIImage(contentsOfFile: fileNamePath) {
+                        cell.imageView.image = image
                     } else {
-
                         NCOperationQueue.shared.downloadThumbnailActivity(fileNamePathOrFileId: activityPreview.source, fileNamePreviewLocalPath: fileNamePath, fileId: fileId, cell: cell, collectionView: collectionView)
                     }
                 }

+ 1 - 1
iOSClient/Notification/NCNotification.swift

@@ -299,7 +299,7 @@ class NCNotification: UITableViewController, NCNotificationCellDelegate, NCEmpty
 
                 for notification in sortedListOfNotifications {
                     if let icon = (notification as! NKNotifications).icon {
-                        NCUtility.shared.convertSVGtoPNGWriteToUserData(svgUrlString: icon, fileName: nil, width: 25, rewrite: false, account: self.appDelegate.account, closure: { _ in })
+                        NCUtility.shared.convertSVGtoPNGWriteToUserData(svgUrlString: icon, fileName: nil, width: 25, rewrite: false, account: self.appDelegate.account, completion: { _, _ in })
                     }
                     self.notifications.append(notification as! NKNotifications)
                 }

+ 10 - 10
iOSClient/Utility/NCUtility.swift

@@ -38,13 +38,13 @@ class NCUtility: NSObject {
         return instance
     }()
 
-    func convertSVGtoPNGWriteToUserData(svgUrlString: String, fileName: String?, width: CGFloat?, rewrite: Bool, account: String, closure: @escaping (String?) -> Void) {
+    func convertSVGtoPNGWriteToUserData(svgUrlString: String, fileName: String? = nil, width: CGFloat? = nil, rewrite: Bool, account: String, id: Int? = nil, completion: @escaping (_ imageNamePath: String?, _ id: Int?) -> Void) {
 
         var fileNamePNG = ""
 
         guard let svgUrlString = svgUrlString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed),
               let iconURL = URL(string: svgUrlString) else {
-            return closure(nil)
+            return completion(nil, id)
         }
 
         if let fileName = fileName {
@@ -80,17 +80,17 @@ class NCUtility: NSObject {
                         }
 
                         guard let pngImageData = newImage.pngData() else {
-                            return closure(nil)
+                            return completion(nil, id)
                         }
 
                         try? pngImageData.write(to: URL(fileURLWithPath: imageNamePath))
 
-                        return closure(imageNamePath)
+                        return completion(imageNamePath, id)
 
                     } else {
 
                         guard let svgImage: SVGKImage = SVGKImage(data: data) else {
-                            return closure(nil)
+                            return completion(nil, id)
                         }
 
                         if width != nil {
@@ -99,23 +99,23 @@ class NCUtility: NSObject {
                         }
 
                         guard let image: UIImage = svgImage.uiImage else {
-                            return closure(nil)
+                            return completion(nil, id)
                         }
                         guard let pngImageData = image.pngData() else {
-                            return closure(nil)
+                            return completion(nil, id)
                         }
 
                         try? pngImageData.write(to: URL(fileURLWithPath: imageNamePath))
 
-                        return closure(imageNamePath)
+                        return completion(imageNamePath, id)
                     }
                 } else {
-                    return closure(nil)
+                    return completion(nil, id)
                 }
             }
 
         } else {
-            return closure(imageNamePath)
+            return completion(imageNamePath, id)
         }
     }