marinofaggiana 4 жил өмнө
parent
commit
6acfd822d1

+ 25 - 0
iOSClient/Main/Colleaction Common/NCCollectionCommon.swift

@@ -208,6 +208,31 @@ class NCCollectionCommon: NSObject, NCSelectDelegate {
         appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
     }
     
+    // MARK: - Live Photo
+    
+    func saveLivePhoto(metadata: tableMetadata, metadataMov: tableMetadata, progressView: UIProgressView?) {
+        
+        let fileNameImage = URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!)
+        let fileNameMov = URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadataMov.ocId, fileNameView: metadataMov.fileNameView)!)
+        
+        NCLivePhoto.generate(from: fileNameImage, videoURL: fileNameMov, progress: { progress in
+            DispatchQueue.main.async {
+                progressView?.progress = Float(progress)
+            }
+        }, completion: { livePhoto, resources in
+            progressView?.progress = 0
+            if resources != nil {
+                NCLivePhoto.saveToLibrary(resources!) { (result) in
+                    if !result {
+                        NCContentPresenter.shared.messageNotification("_error_", description: "_livephoto_save_error_", delay: NCBrandGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: NCBrandGlobal.shared.ErrorInternalError)
+                    }
+                }
+            } else {
+                NCContentPresenter.shared.messageNotification("_error_", description: "_livephoto_save_error_", delay: NCBrandGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: NCBrandGlobal.shared.ErrorInternalError)
+            }
+        })
+    }
+    
     // MARK: - Copy & Paste
 
     func copyFile(ocIds: [String]) {

+ 13 - 1
iOSClient/Main/Colleaction Common/NCCollectionViewCommon.swift

@@ -1068,10 +1068,22 @@ extension NCCollectionViewCommon: UICollectionViewDelegate {
                 NCNetworkingNotificationCenter.shared.openShare(ViewController: self, metadata: metadata, indexPage: 0)
             }
             
-            let save = UIAction(title: NSLocalizedString("_save_selected_files_", comment: ""), image: UIImage(systemName: "square.and.arrow.down")) { action in
+            var save = UIAction(title: NSLocalizedString("_save_selected_files_", comment: ""), image: UIImage(systemName: "square.and.arrow.down")) { action in
                 NCOperationQueue.shared.download(metadata: metadata, selector: NCBrandGlobal.shared.selectorSaveAlbum, setFavorite: false)
             }
             
+            if metadata.typeFile == NCBrandGlobal.shared.metadataTypeFileImage || metadata.typeFile == NCBrandGlobal.shared.metadataTypeFileVideo || metadata.typeFile == NCBrandGlobal.shared.metadataTypeFileAudio {
+                if let metadataLive = NCManageDatabase.shared.isLivePhoto(metadata: metadata) {
+                    if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) && CCUtility.fileProviderStorageExists(metadataLive.ocId, fileNameView: metadataLive.fileNameView) {
+                        
+                        save = UIAction(title: NSLocalizedString("_livephoto_save_", comment: ""), image: UIImage(systemName: "square.and.arrow.down")) { action in
+                            
+                            NCCollectionCommon.shared.saveLivePhoto(metadata: metadata, metadataMov: metadataLive, progressView: nil)
+                        }
+                    }
+                }
+            }
+            
             let openQuickLook = UIAction(title: NSLocalizedString("_open_quicklook_", comment: ""), image: UIImage(systemName: "eye")) { action in
                 NCNetworkingNotificationCenter.shared.downloadOpen(metadata: metadata, selector: NCBrandGlobal.shared.selectorLoadFileQuickLook)
             }

+ 13 - 1
iOSClient/Media/NCMedia.swift

@@ -508,10 +508,22 @@ extension NCMedia: UICollectionViewDelegate {
             var titleDelete = NSLocalizedString("_delete_photo_", comment: "")
             if metadata.typeFile == NCBrandGlobal.shared.metadataTypeFileVideo { titleDelete = NSLocalizedString("_delete_video_", comment: "") }
             
-            let save = UIAction(title: NSLocalizedString("_save_selected_files_", comment: ""), image: UIImage(systemName: "square.and.arrow.down")) { action in
+            var save = UIAction(title: NSLocalizedString("_save_selected_files_", comment: ""), image: UIImage(systemName: "square.and.arrow.down")) { action in
                 NCOperationQueue.shared.download(metadata: metadata, selector: NCBrandGlobal.shared.selectorSaveAlbum, setFavorite: false)
             }
             
+            if metadata.typeFile == NCBrandGlobal.shared.metadataTypeFileImage || metadata.typeFile == NCBrandGlobal.shared.metadataTypeFileVideo || metadata.typeFile == NCBrandGlobal.shared.metadataTypeFileAudio {
+                if let metadataLive = NCManageDatabase.shared.isLivePhoto(metadata: metadata) {
+                    if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) && CCUtility.fileProviderStorageExists(metadataLive.ocId, fileNameView: metadataLive.fileNameView) {
+                        
+                        save = UIAction(title: NSLocalizedString("_livephoto_save_", comment: ""), image: UIImage(systemName: "square.and.arrow.down")) { action in
+                            
+                            NCCollectionCommon.shared.saveLivePhoto(metadata: metadata, metadataMov: metadataLive, progressView: nil)
+                        }
+                    }
+                }
+            }
+            
             let openIn = UIAction(title: NSLocalizedString("_open_in_", comment: ""), image: UIImage(systemName: "square.and.arrow.up") ) { action in
                 NCNetworkingNotificationCenter.shared.downloadOpen(metadata: metadata, selector: NCBrandGlobal.shared.selectorOpenIn)
             }

+ 1 - 19
iOSClient/Viewer/NCViewerImage/NCViewerImage.swift

@@ -224,25 +224,7 @@ class NCViewerImage: UIViewController {
         if let userInfo = notification.userInfo as NSDictionary? {
             if let ocId = userInfo["ocId"] as? String, let ocIdMov = userInfo["ocIdMov"] as? String, let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId), let metadataMov = NCManageDatabase.shared.getMetadataFromOcId(ocIdMov) {
                 
-                let fileNameImage = URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!)
-                let fileNameMov = URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadataMov.ocId, fileNameView: metadataMov.fileNameView)!)
-                
-                NCLivePhoto.generate(from: fileNameImage, videoURL: fileNameMov, progress: { progress in
-                    DispatchQueue.main.async {
-                        self.progressView.progress = Float(progress)
-                    }
-                }, completion: { livePhoto, resources in
-                    self.progressView.progress = 0
-                    if resources != nil {
-                        NCLivePhoto.saveToLibrary(resources!) { (result) in
-                            if !result {
-                                NCContentPresenter.shared.messageNotification("_error_", description: "_livephoto_save_error_", delay: NCBrandGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: NCBrandGlobal.shared.ErrorInternalError)
-                            }
-                        }
-                    } else {
-                        NCContentPresenter.shared.messageNotification("_error_", description: "_livephoto_save_error_", delay: NCBrandGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: NCBrandGlobal.shared.ErrorInternalError)
-                    }
-                })
+                NCCollectionCommon.shared.saveLivePhoto(metadata: metadata, metadataMov: metadataMov, progressView: self.progressView)
             }
         }
     }