Ver Fonte

fix saved Live Photo

marinofaggiana há 4 anos atrás
pai
commit
717fafdaa9

+ 2 - 1
iOSClient/Brand/NCBrand.swift

@@ -415,6 +415,8 @@ class NCBrandColor: NSObject {
     @objc let selectorUploadAutoUploadAll           = "uploadAutoUploadAll"
     @objc let selectorUploadFile                    = "uploadFile"
     @objc let selectorSaveAlbum                     = "saveAlbum"
+    @objc let selectorSaveAlbumLivePhotoIMG         = "saveAlbumLivePhotoIMG"
+    @objc let selectorSaveAlbumLivePhotoMOV         = "saveAlbumLivePhotoMOV"
 
     // Metadata : Status
     //
@@ -475,7 +477,6 @@ class NCBrandColor: NSObject {
     @objc let notificationCenterFavoriteFile                    = "favoriteFile"                     // userInfo: ocId
 
     @objc let notificationCenterMenuSearchTextPDF               = "menuSearchTextPDF"
-    @objc let notificationCenterMenuSaveLivePhoto               = "menuSaveLivePhoto"                // userInfo: ocId, ocIdMov
     @objc let notificationCenterMenuDetailClose                 = "menuDetailClose"
 }
 

+ 17 - 6
iOSClient/Main/Colleaction Common/NCCollectionViewCommon.swift

@@ -1061,9 +1061,9 @@ extension NCCollectionViewCommon: UICollectionViewDelegate {
             var titleDeleteConfirmFile = NSLocalizedString("_delete_file_", comment: "")
             if metadata.directory { titleDeleteConfirmFile = NSLocalizedString("_delete_folder_", comment: "") }
             var discoverabilityTitleSave: String?
-            let metadataMov = NCManageDatabase.shared.isLivePhoto(metadata: metadata)
-            if metadataMov != nil {
-                discoverabilityTitleSave = NSLocalizedString("_livephoto_save_disco_", comment: "")
+            let metadataMOV = NCManageDatabase.shared.isLivePhoto(metadata: metadata)
+            if metadataMOV != nil {
+                discoverabilityTitleSave = NSLocalizedString("_livephoto_save_", comment: "")
             }
             
             let copy = UIAction(title: NSLocalizedString("_copy_file_", comment: ""), image: UIImage(systemName: "doc.on.doc") ) { action in
@@ -1075,9 +1075,20 @@ extension NCCollectionViewCommon: UICollectionViewDelegate {
             }
             
             let save = UIAction(title: NSLocalizedString("_save_selected_files_", comment: ""), image: UIImage(systemName: "square.and.arrow.down"), discoverabilityTitle: discoverabilityTitleSave) { action in
-                
-                if metadataMov != nil && CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) && CCUtility.fileProviderStorageExists(metadataMov!.ocId, fileNameView: metadataMov!.fileNameView)  {
-                    NCCollectionCommon.shared.saveLivePhoto(metadata: metadata, metadataMov: metadataMov!, progressView: nil, viewActivity: self.view)
+                if metadataMOV != nil {
+                    
+                    if !CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
+                        NCOperationQueue.shared.download(metadata: metadata, selector: NCBrandGlobal.shared.selectorSaveAlbumLivePhotoIMG, setFavorite: false)
+                    }
+                    
+                    if !CCUtility.fileProviderStorageExists(metadataMOV!.ocId, fileNameView: metadataMOV!.fileNameView) {
+                        NCOperationQueue.shared.download(metadata: metadataMOV!, selector: NCBrandGlobal.shared.selectorSaveAlbumLivePhotoMOV, setFavorite: false)
+                    }
+                    
+                    if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) && CCUtility.fileProviderStorageExists(metadataMOV!.ocId, fileNameView: metadataMOV!.fileNameView) {
+                        NCCollectionCommon.shared.saveLivePhoto(metadata: metadata, metadataMov: metadataMOV!, progressView: nil, viewActivity: self.appDelegate.window.rootViewController?.view)
+                    }
+                    
                 } else {
                     NCOperationQueue.shared.download(metadata: metadata, selector: NCBrandGlobal.shared.selectorSaveAlbum, setFavorite: false)
                 }

+ 22 - 15
iOSClient/Main/Menu/NCViewer+Menu.swift

@@ -272,22 +272,29 @@ extension NCViewer {
             }
         }
         
-        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) {
-                    actions.append(
-                        NCMenuAction(
-                            title: NSLocalizedString("_livephoto_save_", comment: ""),
-                            icon: UIImage(named: "livePhoto")!.image(color: NCBrandColor.shared.icon, size: 50),
-                            action: { menuAction in
-                                NotificationCenter.default.postOnMainThread(name: NCBrandGlobal.shared.notificationCenterMenuSaveLivePhoto, userInfo: ["ocId": metadata.ocId, "ocIdMov": metadataLive.ocId])
-                            }
-                        )
-                    )
-                }
-            }
+        if let metadataMOV = NCManageDatabase.shared.isLivePhoto(metadata: metadata) {
+            actions.append(
+                NCMenuAction(
+                    title: NSLocalizedString("_livephoto_save_", comment: ""),
+                    icon: UIImage(named: "livePhoto")!.image(color: NCBrandColor.shared.icon, size: 50),
+                    action: { menuAction in
+                        
+                        if !CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
+                            NCOperationQueue.shared.download(metadata: metadata, selector: NCBrandGlobal.shared.selectorSaveAlbumLivePhotoIMG, setFavorite: false)
+                        }
+                        
+                        if !CCUtility.fileProviderStorageExists(metadataMOV.ocId, fileNameView: metadataMOV.fileNameView) {
+                            NCOperationQueue.shared.download(metadata: metadataMOV, selector: NCBrandGlobal.shared.selectorSaveAlbumLivePhotoMOV, setFavorite: false)
+                        }
+                        
+                        if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) && CCUtility.fileProviderStorageExists(metadataMOV.ocId, fileNameView: metadataMOV.fileNameView) {
+                            NCCollectionCommon.shared.saveLivePhoto(metadata: metadata, metadataMov: metadataMOV, progressView: nil, viewActivity: self.appDelegate.window.rootViewController?.view)
+                        }
+                    }
+                )
+            )
         }
-         
+        
         return actions
     }
 }

+ 17 - 6
iOSClient/Media/NCMedia.swift

@@ -509,15 +509,26 @@ extension NCMedia: UICollectionViewDelegate {
             var titleDelete = NSLocalizedString("_delete_photo_", comment: "")
             if metadata.typeFile == NCBrandGlobal.shared.metadataTypeFileVideo { titleDelete = NSLocalizedString("_delete_video_", comment: "") }
             var discoverabilityTitleSave: String?
-            let metadataMov = NCManageDatabase.shared.isLivePhoto(metadata: metadata)
-            if metadataMov != nil {
-                discoverabilityTitleSave = NSLocalizedString("_livephoto_save_disco_", comment: "")
+            let metadataMOV = NCManageDatabase.shared.isLivePhoto(metadata: metadata)
+            if metadataMOV != nil {
+                discoverabilityTitleSave = NSLocalizedString("_livephoto_save_", comment: "")
             }
             
             let save = UIAction(title: NSLocalizedString("_save_selected_files_", comment: ""), image: UIImage(systemName: "square.and.arrow.down"), discoverabilityTitle: discoverabilityTitleSave) { action in
-                
-                if metadataMov != nil && CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) && CCUtility.fileProviderStorageExists(metadataMov!.ocId, fileNameView: metadataMov!.fileNameView)  {
-                    NCCollectionCommon.shared.saveLivePhoto(metadata: metadata, metadataMov: metadataMov!, progressView: nil, viewActivity: self.view)
+                if metadataMOV != nil {
+                    
+                    if !CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
+                        NCOperationQueue.shared.download(metadata: metadata, selector: NCBrandGlobal.shared.selectorSaveAlbumLivePhotoIMG, setFavorite: false)
+                    }
+                    
+                    if !CCUtility.fileProviderStorageExists(metadataMOV!.ocId, fileNameView: metadataMOV!.fileNameView) {
+                        NCOperationQueue.shared.download(metadata: metadataMOV!, selector: NCBrandGlobal.shared.selectorSaveAlbumLivePhotoMOV, setFavorite: false)
+                    }
+                    
+                    if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) && CCUtility.fileProviderStorageExists(metadataMOV!.ocId, fileNameView: metadataMOV!.fileNameView) {
+                        NCCollectionCommon.shared.saveLivePhoto(metadata: metadata, metadataMov: metadataMOV!, progressView: nil, viewActivity: self.appDelegate.window.rootViewController?.view)
+                    }
+                    
                 } else {
                     NCOperationQueue.shared.download(metadata: metadata, selector: NCBrandGlobal.shared.selectorSaveAlbum, setFavorite: false)
                 }

+ 18 - 0
iOSClient/Networking/NCNetworkingNotificationCenter.swift

@@ -141,6 +141,24 @@ import Foundation
                             NCContentPresenter.shared.messageNotification("_access_photo_not_enabled_", description: "_access_photo_not_enabled_msg_", delay: NCBrandGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: NCBrandGlobal.shared.ErrorFileNotSaved)
                         }
                         
+                    case NCBrandGlobal.shared.selectorSaveAlbumLivePhotoIMG, NCBrandGlobal.shared.selectorSaveAlbumLivePhotoMOV:
+                        
+                        var metadata = metadata
+                        var metadataMOV = metadata
+                        guard let metadataTMP = NCManageDatabase.shared.isLivePhoto(metadata: metadata) else { break }
+                        
+                        if selector == NCBrandGlobal.shared.selectorSaveAlbumLivePhotoIMG {
+                            metadataMOV = metadataTMP
+                        }
+                        
+                        if selector == NCBrandGlobal.shared.selectorSaveAlbumLivePhotoMOV {
+                            metadata = metadataTMP
+                        }
+                            
+                        if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) && CCUtility.fileProviderStorageExists(metadataMOV.ocId, fileNameView: metadataMOV.fileNameView) {
+                            NCCollectionCommon.shared.saveLivePhoto(metadata: metadata, metadataMov: metadataMOV, progressView: nil, viewActivity: self.appDelegate.window.rootViewController?.view)
+                        }
+                        
                     default:
                         
                         break

+ 0 - 1
iOSClient/Supporting Files/en.lproj/Localizable.strings

@@ -127,7 +127,6 @@
 "_download_image_max_"      = "Download the image in full resolution";
 "_livephoto_save_"          = "Save Live Photo to photo album";
 "_livephoto_save_error_"    = "Error during save of Live Photo";
-"_livephoto_save_disco_"    = "If possible, save as Live Photo";
 "_file_conflict_num_"       = "file conflict";
 "_file_conflicts_num_"      = "file conflicts";
 "_file_conflict_desc_"      = "Which files do you want to keep?\nIf you select both versions, the copied file will have a number added to its name.";

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

@@ -97,8 +97,7 @@ class NCViewerImage: UIViewController {
         NotificationCenter.default.addObserver(self, selector: #selector(deleteFile(_:)), name: NSNotification.Name(rawValue: NCBrandGlobal.shared.notificationCenterDeleteFile), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(renameFile(_:)), name: NSNotification.Name(rawValue: NCBrandGlobal.shared.notificationCenterRenameFile), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(moveFile(_:)), name: NSNotification.Name(rawValue: NCBrandGlobal.shared.notificationCenterMoveFile), object: nil)
-        NotificationCenter.default.addObserver(self, selector: #selector(saveLivePhoto(_:)), name: NSNotification.Name(rawValue: NCBrandGlobal.shared.notificationCenterMenuSaveLivePhoto), object: nil)
-        
+       
         NotificationCenter.default.addObserver(self, selector: #selector(viewUnload), name: NSNotification.Name(rawValue: NCBrandGlobal.shared.notificationCenterMenuDetailClose), object: nil)
         
         progressView.tintColor = NCBrandColor.shared.brandElement
@@ -218,17 +217,6 @@ class NCViewerImage: UIViewController {
         }
     }
     
-    @objc func saveLivePhoto(_ notification: NSNotification) {
-        if self.view?.window == nil { return }
-        
-        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) {
-                
-                NCCollectionCommon.shared.saveLivePhoto(metadata: metadata, metadataMov: metadataMov, progressView: self.progressView, viewActivity: nil)
-            }
-        }
-    }
-    
     @objc func changeTheming() {
         
         if currentMode == .normal {