Browse Source

coding

Signed-off-by: marinofaggiana <ios@nextcloud.com>
marinofaggiana 2 years ago
parent
commit
225ae1d266

+ 10 - 3
iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

@@ -1418,13 +1418,20 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
         if !metadata.directory {
         if !metadata.directory {
             if metadata.name == NCGlobal.shared.appName {
             if metadata.name == NCGlobal.shared.appName {
 
 
-                let imagePath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!
+                let filePath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!
                 let iconImagePath = CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag)!
                 let iconImagePath = CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag)!
 
 
                 if FileManager().fileExists(atPath: iconImagePath) {
                 if FileManager().fileExists(atPath: iconImagePath) {
                     (cell as! NCCellProtocol).filePreviewImageView?.image =  UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag))
                     (cell as! NCCellProtocol).filePreviewImageView?.image =  UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag))
-                } else if metadata.status > NCGlobal.shared.metadataStatusNormal && FileManager().fileExists(atPath: imagePath) {
-                    if let image = UIImage(contentsOfFile: imagePath), let image = image.resizeImage(size: CGSize(width: NCGlobal.shared.sizeIcon, height: NCGlobal.shared.sizeIcon), isAspectRation: true), let data = image.jpegData(compressionQuality: 0.5) {
+                } else if metadata.status > NCGlobal.shared.metadataStatusNormal && metadata.classFile == NCCommunicationCommon.typeClassFile.image.rawValue && FileManager().fileExists(atPath: filePath) {
+                    if let image = UIImage(contentsOfFile: filePath), let image = image.resizeImage(size: CGSize(width: NCGlobal.shared.sizeIcon, height: NCGlobal.shared.sizeIcon), isAspectRation: true), let data = image.jpegData(compressionQuality: 0.5) {
+                        do {
+                            try data.write(to: URL.init(fileURLWithPath: iconImagePath), options: .atomic)
+                            (cell as! NCCellProtocol).filePreviewImageView?.image = image
+                        } catch { }
+                    }
+                } else if metadata.status > NCGlobal.shared.metadataStatusNormal && metadata.classFile == NCCommunicationCommon.typeClassFile.video.rawValue && FileManager().fileExists(atPath: filePath) {
+                    if let image = NCUtility.shared.imageFromVideo(url: URL(fileURLWithPath: filePath), at: 0), let image = image.resizeImage(size: CGSize(width: NCGlobal.shared.sizeIcon, height: NCGlobal.shared.sizeIcon), isAspectRation: true), let data = image.jpegData(compressionQuality: 0.5) {
                         do {
                         do {
                             try data.write(to: URL.init(fileURLWithPath: iconImagePath), options: .atomic)
                             try data.write(to: URL.init(fileURLWithPath: iconImagePath), options: .atomic)
                             (cell as! NCCellProtocol).filePreviewImageView?.image = image
                             (cell as! NCCellProtocol).filePreviewImageView?.image = image

+ 3 - 2
iOSClient/Networking/NCNetworkingProcessUpload.swift

@@ -40,7 +40,7 @@ class NCNetworkingProcessUpload: NSObject {
 
 
     @objc func startProcess() {
     @objc func startProcess() {
         if timerProcess?.isValid ?? false {
         if timerProcess?.isValid ?? false {
-            process()
+            DispatchQueue.main.async { self.process() }
         }
         }
     }
     }
 
 
@@ -57,6 +57,7 @@ class NCNetworkingProcessUpload: NSObject {
         guard !appDelegate.account.isEmpty else { return }
         guard !appDelegate.account.isEmpty else { return }
 
 
         let queue = DispatchQueue.global(qos: .background)
         let queue = DispatchQueue.global(qos: .background)
+        let applicationState = UIApplication.shared.applicationState
         var counterUpload: Int = 0
         var counterUpload: Int = 0
         let sessionSelectors = [NCGlobal.shared.selectorUploadFile, NCGlobal.shared.selectorUploadAutoUpload, NCGlobal.shared.selectorUploadAutoUploadAll]
         let sessionSelectors = [NCGlobal.shared.selectorUploadFile, NCGlobal.shared.selectorUploadAutoUpload, NCGlobal.shared.selectorUploadAutoUploadAll]
         let metadatasUpload = NCManageDatabase.shared.getMetadatas(predicate: NSPredicate(format: "status == %d OR status == %d", NCGlobal.shared.metadataStatusInUpload, NCGlobal.shared.metadataStatusUploading))
         let metadatasUpload = NCManageDatabase.shared.getMetadatas(predicate: NSPredicate(format: "status == %d OR status == %d", NCGlobal.shared.metadataStatusInUpload, NCGlobal.shared.metadataStatusUploading))
@@ -108,7 +109,7 @@ class NCNetworkingProcessUpload: NSObject {
 
 
                         // Upload
                         // Upload
                         if let metadata = metadataForUpload {
                         if let metadata = metadataForUpload {
-                            if (metadata.e2eEncrypted || metadata.chunk) && UIApplication.shared.applicationState != .active { continue }
+                            if (metadata.e2eEncrypted || metadata.chunk) && applicationState != .active { continue }
                             if let metadata = NCManageDatabase.shared.setMetadataStatus(ocId: metadata.ocId, status: NCGlobal.shared.metadataStatusInUpload) {
                             if let metadata = NCManageDatabase.shared.setMetadataStatus(ocId: metadata.ocId, status: NCGlobal.shared.metadataStatusInUpload) {
                                 NCNetworking.shared.upload(metadata: metadata)
                                 NCNetworking.shared.upload(metadata: metadata)
                             }
                             }

+ 10 - 3
iOSClient/Transfers/NCTransfers.swift

@@ -190,13 +190,20 @@ class NCTransfers: NCCollectionViewCommon, NCTransferCellDelegate {
 
 
         cell.progressView.progress = 0.0
         cell.progressView.progress = 0.0
 
 
-        let imagePath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!
+        let filePath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!
         let iconImagePath = CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag)!
         let iconImagePath = CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag)!
 
 
         if FileManager().fileExists(atPath: iconImagePath) {
         if FileManager().fileExists(atPath: iconImagePath) {
             cell.imageItem.image =  UIImage(contentsOfFile:iconImagePath)
             cell.imageItem.image =  UIImage(contentsOfFile:iconImagePath)
-        } else if metadata.classFile == NCCommunicationCommon.typeClassFile.image.rawValue, FileManager().fileExists(atPath: imagePath) {
-            if let image = UIImage(contentsOfFile: imagePath), let image = image.resizeImage(size: CGSize(width: NCGlobal.shared.sizeIcon, height: NCGlobal.shared.sizeIcon), isAspectRation: true), let data = image.jpegData(compressionQuality: 0.5) {
+        } else if metadata.classFile == NCCommunicationCommon.typeClassFile.image.rawValue, FileManager().fileExists(atPath: filePath) {
+            if let image = UIImage(contentsOfFile: filePath), let image = image.resizeImage(size: CGSize(width: NCGlobal.shared.sizeIcon, height: NCGlobal.shared.sizeIcon), isAspectRation: true), let data = image.jpegData(compressionQuality: 0.5) {
+                do {
+                    try data.write(to: URL.init(fileURLWithPath: iconImagePath), options: .atomic)
+                    cell.imageItem.image = image
+                } catch { }
+            }
+        } else if metadata.classFile == NCCommunicationCommon.typeClassFile.video.rawValue, FileManager().fileExists(atPath: filePath) {
+            if let image = NCUtility.shared.imageFromVideo(url: URL(fileURLWithPath: filePath), at: 0), let image = image.resizeImage(size: CGSize(width: NCGlobal.shared.sizeIcon, height: NCGlobal.shared.sizeIcon), isAspectRation: true), let data = image.jpegData(compressionQuality: 0.5) {
                 do {
                 do {
                     try data.write(to: URL.init(fileURLWithPath: iconImagePath), options: .atomic)
                     try data.write(to: URL.init(fileURLWithPath: iconImagePath), options: .atomic)
                     cell.imageItem.image = image
                     cell.imageItem.image = image

+ 24 - 22
iOSClient/Utility/NCContentPresenter.swift

@@ -137,29 +137,31 @@ class NCContentPresenter: NSObject {
 
 
         if SwiftEntryKit.isCurrentlyDisplaying(entryNamed: text) { return }
         if SwiftEntryKit.isCurrentlyDisplaying(entryNamed: text) { return }
 
 
-        var attributes = EKAttributes.topNote
-
-        attributes.windowLevel = .normal
-        attributes.displayDuration = delay
-        attributes.name = text
-        if let color = color {
-            attributes.entryBackground = .color(color: EKColor(color))
-        }
-        if let type = type {
-            attributes.entryBackground = .color(color: EKColor(getBackgroundColorFromType(type)))
-        }
-        attributes.precedence = .override(priority: priority, dropEnqueuedEntries: dropEnqueuedEntries)
-
-        let style = EKProperty.LabelStyle(font: MainFont.light.with(size: 14), color: .white, alignment: .center)
-        let labelContent = EKProperty.LabelContent(text: text, style: style)
+        DispatchQueue.main.async {
+            var attributes = EKAttributes.topNote
 
 
-        if let image = image {
-            let imageContent = EKProperty.ImageContent(image: image, size: CGSize(width: 17, height: 17))
-            let contentView = EKImageNoteMessageView(with: labelContent, imageContent: imageContent)
-            DispatchQueue.main.async { SwiftEntryKit.display(entry: contentView, using: attributes) }
-        } else {
-            let contentView = EKNoteMessageView(with: labelContent)
-            DispatchQueue.main.async { SwiftEntryKit.display(entry: contentView, using: attributes) }
+            attributes.windowLevel = .normal
+            attributes.displayDuration = delay
+            attributes.name = text
+            if let color = color {
+                attributes.entryBackground = .color(color: EKColor(color))
+            }
+            if let type = type {
+                attributes.entryBackground = .color(color: EKColor(self.getBackgroundColorFromType(type)))
+            }
+            attributes.precedence = .override(priority: priority, dropEnqueuedEntries: dropEnqueuedEntries)
+
+            let style = EKProperty.LabelStyle(font: MainFont.light.with(size: 14), color: .white, alignment: .center)
+            let labelContent = EKProperty.LabelContent(text: text, style: style)
+
+            if let image = image {
+                let imageContent = EKProperty.ImageContent(image: image, size: CGSize(width: 17, height: 17))
+                let contentView = EKImageNoteMessageView(with: labelContent, imageContent: imageContent)
+                SwiftEntryKit.display(entry: contentView, using: attributes)
+            } else {
+                let contentView = EKNoteMessageView(with: labelContent)
+                SwiftEntryKit.display(entry: contentView, using: attributes)
+            }
         }
         }
     }
     }