marinofaggiana 5 жил өмнө
parent
commit
6bcb8a89da

+ 4 - 0
iOSClient/CCGlobal.h

@@ -342,6 +342,10 @@
 #define k_notificationCenter_moveFile                   @"moveFile"
 
 #define k_notificationCenter_menuSearchTextPDF          @"menuSearchTextPDF"
+#define k_notificationCenter_menuDownloadImage          @"menuDownloadImage"
+#define k_notificationCenter_menuSaveLivePhoto          @"menuSaveLivePhoto"
+#define k_notificationCenter_menuDetailClose            @"menuDetailClose"
+
 
 // -----------------------------------------------------------------------------------------------------------
 // INTERNAL

+ 4 - 3
iOSClient/Main/Menu/NCDetailNavigationController+Menu.swift

@@ -92,7 +92,7 @@ extension NCDetailNavigationController {
                 NCMenuAction(title: NSLocalizedString("_download_image_max_", comment: ""),
                     icon: CCGraphics.changeThemingColorImage(UIImage(named: "downloadImageFullRes"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
                     action: { menuAction in
-                        self.appDelegate.activeDetail.downloadImage()
+                        NotificationCenter.default.post(name: Notification.Name.init(rawValue: k_notificationCenter_menuDownloadImage), object: nil)
                     }
                 )
             )
@@ -105,7 +105,8 @@ extension NCDetailNavigationController {
                         NCMenuAction(title: NSLocalizedString("_livephoto_save_", comment: ""),
                             icon: CCGraphics.changeThemingColorImage(UIImage(named: "livePhoto"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
                             action: { menuAction in
-                                self.appDelegate.activeDetail.saveLivePhoto(metadata: metadata, metadataMov: metadataMov)
+                                let userInfo: [String : Any] = ["metadata": metadata, "metadataMov": metadataMov]
+                                NotificationCenter.default.post(name: Notification.Name.init(rawValue: k_notificationCenter_menuSaveLivePhoto), object: nil, userInfo: userInfo)
                             }
                         )
                     )
@@ -137,7 +138,7 @@ extension NCDetailNavigationController {
             NCMenuAction(title: NSLocalizedString("_close_", comment: ""),
                 icon: CCGraphics.changeThemingColorImage(UIImage(named: "exit"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
                 action: { menuAction in
-                    self.appDelegate.activeDetail.viewUnload()
+                    NotificationCenter.default.post(name: Notification.Name.init(rawValue: k_notificationCenter_menuDetailClose), object: nil)
                 }
             )
         )

+ 73 - 66
iOSClient/Main/NCDetailViewController.swift

@@ -68,6 +68,10 @@ class NCDetailViewController: UIViewController {
         NotificationCenter.default.addObserver(self, selector: #selector(moveFile(_:)), name: NSNotification.Name(rawValue: k_notificationCenter_moveFile), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(triggerProgressTask(_:)), name: NSNotification.Name(rawValue: k_notificationCenter_progressTask), object:nil)
         
+        NotificationCenter.default.addObserver(self, selector: #selector(downloadImage), name: NSNotification.Name(rawValue: k_notificationCenter_menuDownloadImage), object: nil)
+        NotificationCenter.default.addObserver(self, selector: #selector(saveLivePhoto(_:)), name: NSNotification.Name(rawValue: k_notificationCenter_menuSaveLivePhoto), object: nil)
+        NotificationCenter.default.addObserver(self, selector: #selector(viewUnload), name: NSNotification.Name(rawValue: k_notificationCenter_menuDetailClose), object: nil)
+        
         changeTheming()
 
         if metadata != nil  {
@@ -136,33 +140,6 @@ class NCDetailViewController: UIViewController {
         return backgroundView.subviews.first
     }
     
-    @objc func viewUnload() {
-        
-        metadata = nil
-        selector = nil
-        
-        if let splitViewController = self.splitViewController as? NCSplitViewController {
-            if splitViewController.isCollapsed {
-                if let navigationController = splitViewController.viewControllers.last as? UINavigationController {
-                    navigationController.popToRootViewController(animated: true)
-                }
-            } else {
-                if backgroundView != nil {
-                    for view in backgroundView.subviews {
-                        view.removeFromSuperview()
-                    }
-                }
-                self.navigationController?.navigationBar.topItem?.title = ""
-            }
-        }
-        
-        self.splitViewController?.preferredDisplayMode = .allVisible
-        self.navigationController?.isNavigationBarHidden = false
-        view.backgroundColor = NCBrandColor.sharedInstance.backgroundView
-        
-        backgroundView.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "logo"), multiplier: 2, color: NCBrandColor.sharedInstance.brand.withAlphaComponent(0.4))
-    }
-    
     @objc func navigateControllerBarHidden(_ state: Bool) {
         
         if state  {
@@ -306,6 +283,75 @@ class NCDetailViewController: UIViewController {
         }
     }
     
+    @objc func downloadImage() {
+        
+        guard let metadata = self.metadata else {return }
+        
+        metadata.session = k_download_session
+        metadata.sessionError = ""
+        metadata.sessionSelector = ""
+        metadata.status = Int(k_metadataStatusWaitDownload)
+        
+        self.metadata = NCManageDatabase.sharedInstance.addMetadata(metadata)
+        
+        if let index = metadatas.firstIndex(where: { $0.ocId == metadata.ocId }) {
+            metadatas[index] = self.metadata!
+        }
+        
+        appDelegate.startLoadAutoDownloadUpload()
+    }
+    
+    @objc func saveLivePhoto(_ notification: NSNotification) {
+        if let userInfo = notification.userInfo as NSDictionary? {
+            if let metadata = userInfo["metadata"] as? tableMetadata, let metadataMov = userInfo["metadataMov"] as? tableMetadata {
+                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
+                    self.progress(Float(progress))
+                }, completion: { livePhoto, resources in
+                    self.progress(0)
+                    if resources != nil {
+                        NCLivePhoto.saveToLibrary(resources!) { (result) in
+                            if !result {
+                                NCContentPresenter.shared.messageNotification("_error_", description: "_livephoto_save_error_", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: Int(k_CCErrorInternalError))
+                            }
+                        }
+                    } else {
+                        NCContentPresenter.shared.messageNotification("_error_", description: "_livephoto_save_error_", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: Int(k_CCErrorInternalError))
+                    }
+                })
+            }
+        }
+    }
+    
+    @objc func viewUnload() {
+        
+        metadata = nil
+        selector = nil
+        
+        if let splitViewController = self.splitViewController as? NCSplitViewController {
+            if splitViewController.isCollapsed {
+                if let navigationController = splitViewController.viewControllers.last as? UINavigationController {
+                    navigationController.popToRootViewController(animated: true)
+                }
+            } else {
+                if backgroundView != nil {
+                    for view in backgroundView.subviews {
+                        view.removeFromSuperview()
+                    }
+                }
+                self.navigationController?.navigationBar.topItem?.title = ""
+            }
+        }
+        
+        self.splitViewController?.preferredDisplayMode = .allVisible
+        self.navigationController?.isNavigationBarHidden = false
+        view.backgroundColor = NCBrandColor.sharedInstance.backgroundView
+        
+        backgroundView.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "logo"), multiplier: 2, color: NCBrandColor.sharedInstance.brand.withAlphaComponent(0.4))
+    }
+    
     //MARK: - View File
     
     @objc func viewFile(metadata: tableMetadata, selector: String?) {
@@ -686,45 +732,6 @@ extension NCDetailViewController: NCViewerImageViewControllerDelegate, NCViewerI
         viewUnload()
     }
     
-    @objc func downloadImage() {
-        
-        guard let metadata = self.metadata else {return }
-        
-        metadata.session = k_download_session
-        metadata.sessionError = ""
-        metadata.sessionSelector = ""
-        metadata.status = Int(k_metadataStatusWaitDownload)
-        
-        self.metadata = NCManageDatabase.sharedInstance.addMetadata(metadata)
-        
-        if let index = metadatas.firstIndex(where: { $0.ocId == metadata.ocId }) {
-            metadatas[index] = self.metadata!
-        }
-        
-        appDelegate.startLoadAutoDownloadUpload()
-    }
-    
-    func saveLivePhoto(metadata: tableMetadata, metadataMov: tableMetadata) {
-        
-        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
-            self.progress(Float(progress))
-        }, completion: { livePhoto, resources in
-            self.progress(0)
-            if resources != nil {
-                NCLivePhoto.saveToLibrary(resources!) { (result) in
-                    if !result {
-                        NCContentPresenter.shared.messageNotification("_error_", description: "_livephoto_save_error_", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: Int(k_CCErrorInternalError))
-                    }
-                }
-            } else {
-                NCContentPresenter.shared.messageNotification("_error_", description: "_livephoto_save_error_", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: Int(k_CCErrorInternalError))
-            }
-        })
-    }
-    
     func statusViewImage(metadata: tableMetadata, viewerImageViewController: NCViewerImageViewController) {
         
         var colorStatus: UIColor = UIColor.white.withAlphaComponent(0.8)