Răsfoiți Sursa

improved code

marinofaggiana 4 ani în urmă
părinte
comite
0a3ee6c736

+ 1 - 1
iOSClient/CCGlobal.h

@@ -339,5 +339,5 @@
 #define k_notificationCenter_favoriteFile                   @"favoriteFile"                     // userInfo: ocId
 
 #define k_notificationCenter_menuSearchTextPDF              @"menuSearchTextPDF"
-#define k_notificationCenter_menuSaveLivePhoto              @"menuSaveLivePhoto"                // userInfo: ocId, metadataMov
+#define k_notificationCenter_menuSaveLivePhoto              @"menuSaveLivePhoto"                // userInfo: ocId, ocIdMov
 #define k_notificationCenter_menuDetailClose                @"menuDetailClose"

+ 83 - 97
iOSClient/Main/Colleaction Common/NCCollectionViewCommon.swift

@@ -300,21 +300,20 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let ocId = userInfo["ocId"] as? String, let onlyLocal = userInfo["onlyLocal"] as? Bool {
-                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
-                    if onlyLocal {
-                        reloadDataSource()
-                    } else if metadata.fileNameView.lowercased() == k_fileNameRichWorkspace.lowercased() {
-                        reloadDataSourceNetwork(forced: true)
-                    } else {
-                        if let row = dataSource.deleteMetadata(ocId: metadata.ocId) {
-                            let indexPath = IndexPath(row: row, section: 0)
-                            collectionView?.performBatchUpdates({
-                                collectionView?.deleteItems(at: [indexPath])
-                            }, completion: { (_) in
-                                self.collectionView?.reloadData()
-                            })
-                        }
+            if let ocId = userInfo["ocId"] as? String, let onlyLocal = userInfo["onlyLocal"] as? Bool, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                
+                if onlyLocal {
+                    reloadDataSource()
+                } else if metadata.fileNameView.lowercased() == k_fileNameRichWorkspace.lowercased() {
+                    reloadDataSourceNetwork(forced: true)
+                } else {
+                    if let row = dataSource.deleteMetadata(ocId: metadata.ocId) {
+                        let indexPath = IndexPath(row: row, section: 0)
+                        collectionView?.performBatchUpdates({
+                            collectionView?.deleteItems(at: [indexPath])
+                        }, completion: { (_) in
+                            self.collectionView?.reloadData()
+                        })
                     }
                 }
             }
@@ -325,26 +324,25 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let ocId = userInfo["ocId"] as? String, let ocIdNew = userInfo["ocIdNew"] as? String {
-                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId), let metadataNew = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocIdNew) {
-                    if metadata.serverUrl == serverUrl && metadata.account == appDelegate.account {
-                        if let row = dataSource.deleteMetadata(ocId: metadata.ocId) {
-                            let indexPath = IndexPath(row: row, section: 0)
-                            collectionView?.performBatchUpdates({
-                                collectionView?.deleteItems(at: [indexPath])
-                            }, completion: { (_) in
-                                self.collectionView?.reloadData()
-                            })
-                        }
-                    } else if metadataNew.serverUrl == serverUrl && metadata.account == appDelegate.account {
-                        if let row = dataSource.addMetadata(metadataNew) {
-                            let indexPath = IndexPath(row: row, section: 0)
-                            collectionView?.performBatchUpdates({
-                                collectionView?.insertItems(at: [indexPath])
-                            }, completion: { (_) in
-                                self.collectionView?.reloadData()
-                            })
-                        }
+            if let ocId = userInfo["ocId"] as? String, let ocIdNew = userInfo["ocIdNew"] as? String, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId), let metadataNew = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocIdNew) {
+                
+                if metadata.serverUrl == serverUrl && metadata.account == appDelegate.account {
+                    if let row = dataSource.deleteMetadata(ocId: metadata.ocId) {
+                        let indexPath = IndexPath(row: row, section: 0)
+                        collectionView?.performBatchUpdates({
+                            collectionView?.deleteItems(at: [indexPath])
+                        }, completion: { (_) in
+                            self.collectionView?.reloadData()
+                        })
+                    }
+                } else if metadataNew.serverUrl == serverUrl && metadata.account == appDelegate.account {
+                    if let row = dataSource.addMetadata(metadataNew) {
+                        let indexPath = IndexPath(row: row, section: 0)
+                        collectionView?.performBatchUpdates({
+                            collectionView?.insertItems(at: [indexPath])
+                        }, completion: { (_) in
+                            self.collectionView?.reloadData()
+                        })
                     }
                 }
             }
@@ -356,6 +354,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         
         if let userInfo = notification.userInfo as NSDictionary? {
             if let serverUrlTo = userInfo["serverUrlTo"] as? String {
+                
                 if serverUrlTo == self.serverUrl {
                     reloadDataSource()
                 }
@@ -373,17 +372,16 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let ocId = userInfo["ocId"] as? String {
-                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
-                    if metadata.serverUrl == serverUrl && metadata.account == appDelegate.account {
-                        if let row = dataSource.addMetadata(metadata) {
-                            let indexPath = IndexPath(row: row, section: 0)
-                            collectionView?.performBatchUpdates({
-                                collectionView?.insertItems(at: [indexPath])
-                            }, completion: { (_) in
-                                self.collectionView?.reloadData()
-                            })
-                        }
+            if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                
+                if metadata.serverUrl == serverUrl && metadata.account == appDelegate.account {
+                    if let row = dataSource.addMetadata(metadata) {
+                        let indexPath = IndexPath(row: row, section: 0)
+                        collectionView?.performBatchUpdates({
+                            collectionView?.insertItems(at: [indexPath])
+                        }, completion: { (_) in
+                            self.collectionView?.reloadData()
+                        })
                     }
                 }
             }
@@ -397,6 +395,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         
         if let userInfo = notification.userInfo as NSDictionary? {
             if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                
                 if dataSource.getIndexMetadata(ocId: metadata.ocId) != nil {
                     reloadDataSource()
                 }
@@ -408,12 +407,10 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let ocId = userInfo["ocId"] as? String {
-                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
-                    if let row = dataSource.reloadMetadata(ocId: metadata.ocId) {
-                        let indexPath = IndexPath(row: row, section: 0)
-                        collectionView?.reloadItems(at: [indexPath])
-                    }
+            if let ocId = userInfo["ocId"] as? String , let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                if let row = dataSource.reloadMetadata(ocId: metadata.ocId) {
+                    let indexPath = IndexPath(row: row, section: 0)
+                    collectionView?.reloadItems(at: [indexPath])
                 }
             }
         }
@@ -423,13 +420,11 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let ocId = userInfo["ocId"] as? String, let _ = userInfo["errorCode"] as? Int {
-                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
-                   if let row = dataSource.reloadMetadata(ocId: metadata.ocId) {
-                       let indexPath = IndexPath(row: row, section: 0)
-                       collectionView?.reloadItems(at: [indexPath])
-                   }
-                }
+            if let ocId = userInfo["ocId"] as? String, let _ = userInfo["errorCode"] as? Int, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+               if let row = dataSource.reloadMetadata(ocId: metadata.ocId) {
+                   let indexPath = IndexPath(row: row, section: 0)
+                   collectionView?.reloadItems(at: [indexPath])
+               }
             }
         }
     }
@@ -438,12 +433,10 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let ocId = userInfo["ocId"] as? String {
-                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
-                    if let row = dataSource.reloadMetadata(ocId: metadata.ocId) {
-                        let indexPath = IndexPath(row: row, section: 0)
-                        collectionView?.reloadItems(at: [indexPath])
-                    }
+            if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                if let row = dataSource.reloadMetadata(ocId: metadata.ocId) {
+                    let indexPath = IndexPath(row: row, section: 0)
+                    collectionView?.reloadItems(at: [indexPath])
                 }
             }
         }
@@ -453,18 +446,15 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let ocId = userInfo["ocId"] as? String {
-                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
-                    if metadata.serverUrl == serverUrl && metadata.account == appDelegate.account {
-                        
-                        if let row = dataSource.addMetadata(metadata) {
-                            let indexPath = IndexPath(row: row, section: 0)
-                            collectionView?.performBatchUpdates({
-                                collectionView?.insertItems(at: [indexPath])
-                            }, completion: { (_) in
-                                self.collectionView?.reloadData()
-                            })
-                        }
+            if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                if metadata.serverUrl == serverUrl && metadata.account == appDelegate.account {
+                    if let row = dataSource.addMetadata(metadata) {
+                        let indexPath = IndexPath(row: row, section: 0)
+                        collectionView?.performBatchUpdates({
+                            collectionView?.insertItems(at: [indexPath])
+                        }, completion: { (_) in
+                            self.collectionView?.reloadData()
+                        })
                     }
                 }
             }
@@ -475,12 +465,10 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let ocId = userInfo["ocId"] as? String, let ocIdTemp = userInfo["ocIdTemp"] as? String, let _ = userInfo["errorCode"] as? Int {
-                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
-                    if metadata.serverUrl == serverUrl && metadata.account == appDelegate.account {
-                        dataSource.reloadMetadata(ocId: metadata.ocId, ocIdTemp: ocIdTemp)
-                        collectionView?.reloadData()
-                    }
+        if let ocId = userInfo["ocId"] as? String, let ocIdTemp = userInfo["ocIdTemp"] as? String, let _ = userInfo["errorCode"] as? Int, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                if metadata.serverUrl == serverUrl && metadata.account == appDelegate.account {
+                    dataSource.reloadMetadata(ocId: metadata.ocId, ocIdTemp: ocIdTemp)
+                    collectionView?.reloadData()
                 }
             }
         }
@@ -490,20 +478,18 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let ocId = userInfo["ocId"] as? String {
-                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
-                    if metadata.serverUrl == serverUrl && metadata.account == appDelegate.account {
-                        
-                        if let row = dataSource.deleteMetadata(ocId: metadata.ocId) {
-                            let indexPath = IndexPath(row: row, section: 0)
-                            collectionView?.performBatchUpdates({
-                                collectionView?.deleteItems(at: [indexPath])
-                            }, completion: { (_) in
-                                self.collectionView?.reloadData()
-                            })
-                        } else {
-                            self.reloadDataSource()
-                        }
+            if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                
+                if metadata.serverUrl == serverUrl && metadata.account == appDelegate.account {
+                    if let row = dataSource.deleteMetadata(ocId: metadata.ocId) {
+                        let indexPath = IndexPath(row: row, section: 0)
+                        collectionView?.performBatchUpdates({
+                            collectionView?.deleteItems(at: [indexPath])
+                        }, completion: { (_) in
+                            self.collectionView?.reloadData()
+                        })
+                    } else {
+                        self.reloadDataSource()
                     }
                 }
             }

+ 34 - 37
iOSClient/Media/NCMedia.swift

@@ -405,23 +405,22 @@ class NCMedia: UIViewController, NCEmptyDataSetDelegate, NCSelectDelegate {
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let ocId = userInfo["ocId"] as? String {
-                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
-                    if metadata.account == appDelegate.account {
-                        
-                        let indexes = self.metadatas.indices.filter { self.metadatas[$0].ocId == metadata.ocId }
-                        let metadatas = self.metadatas.filter { $0.ocId != metadata.ocId }
-                        self.metadatas = metadatas
-                        
-                        if self.metadatas.count == 0 {
-                            collectionView?.reloadData()
-                        } else if let row = indexes.first {
-                            let indexPath = IndexPath(row: row, section: 0)
-                            collectionView?.deleteItems(at: [indexPath])
-                        }
-                        
-                        self.updateMediaControlVisibility()
+            if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                
+                if metadata.account == appDelegate.account {
+                    
+                    let indexes = self.metadatas.indices.filter { self.metadatas[$0].ocId == metadata.ocId }
+                    let metadatas = self.metadatas.filter { $0.ocId != metadata.ocId }
+                    self.metadatas = metadatas
+                    
+                    if self.metadatas.count == 0 {
+                        collectionView?.reloadData()
+                    } else if let row = indexes.first {
+                        let indexPath = IndexPath(row: row, section: 0)
+                        collectionView?.deleteItems(at: [indexPath])
                     }
+                    
+                    self.updateMediaControlVisibility()
                 }
             }
         }
@@ -431,23 +430,22 @@ class NCMedia: UIViewController, NCEmptyDataSetDelegate, NCSelectDelegate {
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let ocId = userInfo["ocId"] as? String {
-                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
-                    if metadata.account == appDelegate.account {
-                        
-                        let indexes = self.metadatas.indices.filter { self.metadatas[$0].ocId == metadata.ocId }
-                        let metadatas = self.metadatas.filter { $0.ocId != metadata.ocId }
-                        self.metadatas = metadatas
-                        
-                        if self.metadatas.count == 0 {
-                            collectionView?.reloadData()
-                        } else if let row = indexes.first {
-                            let indexPath = IndexPath(row: row, section: 0)
-                            collectionView?.deleteItems(at: [indexPath])
-                        }
-                        
-                        self.updateMediaControlVisibility()
+            if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                
+                if metadata.account == appDelegate.account {
+                    
+                    let indexes = self.metadatas.indices.filter { self.metadatas[$0].ocId == metadata.ocId }
+                    let metadatas = self.metadatas.filter { $0.ocId != metadata.ocId }
+                    self.metadatas = metadatas
+                    
+                    if self.metadatas.count == 0 {
+                        collectionView?.reloadData()
+                    } else if let row = indexes.first {
+                        let indexPath = IndexPath(row: row, section: 0)
+                        collectionView?.deleteItems(at: [indexPath])
                     }
+                    
+                    self.updateMediaControlVisibility()
                 }
             }
         }
@@ -457,11 +455,10 @@ class NCMedia: UIViewController, NCEmptyDataSetDelegate, NCSelectDelegate {
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let ocId = userInfo["ocId"] as? String {
-                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
-                    if metadata.account == appDelegate.account {
-                        self.reloadDataSource()
-                    }
+            if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                
+                if metadata.account == appDelegate.account {
+                    self.reloadDataSource()
                 }
             }
         }

+ 102 - 104
iOSClient/Networking/NCNetworkingNotificationCenter.swift

@@ -42,126 +42,125 @@ import Foundation
     @objc func downloadedFile(_ notification: NSNotification) {
             
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let ocId = userInfo["ocId"] as? String, let selector = userInfo["selector"] as? String, let errorCode = userInfo["errorCode"] as? Int, let errorDescription = userInfo["errorDescription"] as? String {
-                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
-                    if metadata.account != appDelegate.account { return }
+            if let ocId = userInfo["ocId"] as? String, let selector = userInfo["selector"] as? String, let errorCode = userInfo["errorCode"] as? Int, let errorDescription = userInfo["errorDescription"] as? String, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                
+                if metadata.account != appDelegate.account { return }
+                
+                if errorCode == 0 {
                     
-                    if errorCode == 0 {
-                        
-                        let fileURL = URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView))
-                        documentController = UIDocumentInteractionController(url: fileURL)
-                        documentController?.delegate = self
-
-                        switch selector {
-                        case selectorLoadFileQuickLook:
-                            
-                            let fileNamePath = NSTemporaryDirectory() + metadata.fileNameView
-                            CCUtility.copyFile(atPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView), toPath: fileNamePath)
+                    let fileURL = URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView))
+                    documentController = UIDocumentInteractionController(url: fileURL)
+                    documentController?.delegate = self
 
-                            viewerQuickLook = NCViewerQuickLook.init()
-                            viewerQuickLook?.quickLook(url: URL(fileURLWithPath: fileNamePath))
-                            
-                        case selectorLoadFileView:
-                            
-                            if UIApplication.shared.applicationState == UIApplication.State.active {
-                                                            
-                                if metadata.contentType.contains("opendocument") && !NCUtility.shared.isRichDocument(metadata) {
-                                    
-                                    if let view = appDelegate.window?.rootViewController?.view {
-                                        documentController?.presentOptionsMenu(from: CGRect.zero, in: view, animated: true)
-                                    }
-                                    
-                                } else if metadata.typeFile == k_metadataTypeFile_compress || metadata.typeFile == k_metadataTypeFile_unknown {
+                    switch selector {
+                    case selectorLoadFileQuickLook:
+                        
+                        let fileNamePath = NSTemporaryDirectory() + metadata.fileNameView
+                        CCUtility.copyFile(atPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView), toPath: fileNamePath)
 
-                                    if let view = appDelegate.window?.rootViewController?.view {
-                                        documentController?.presentOptionsMenu(from: CGRect.zero, in: view, animated: true)
-                                    }
-                                    
-                                } else if metadata.typeFile == k_metadataTypeFile_imagemeter {
-                                    
-                                    if let view = appDelegate.window?.rootViewController?.view {
-                                        documentController?.presentOptionsMenu(from: CGRect.zero, in: view, animated: true)
-                                    }
-                                    
-                                } else {
-                                    
-                                    NCViewer.shared.view(viewController: self.appDelegate.activeViewController, metadata: metadata, metadatas: [metadata])
-                                }
-                            }
-                            
-                        case selectorOpenIn:
-                            
-                            if UIApplication.shared.applicationState == UIApplication.State.active {
+                        viewerQuickLook = NCViewerQuickLook.init()
+                        viewerQuickLook?.quickLook(url: URL(fileURLWithPath: fileNamePath))
+                        
+                    case selectorLoadFileView:
+                        
+                        if UIApplication.shared.applicationState == UIApplication.State.active {
+                                                        
+                            if metadata.contentType.contains("opendocument") && !NCUtility.shared.isRichDocument(metadata) {
                                 
                                 if let view = appDelegate.window?.rootViewController?.view {
                                     documentController?.presentOptionsMenu(from: CGRect.zero, in: view, animated: true)
                                 }
-                            }
-                            
-                        case selectorLoadCopy:
-                            
-                            var items = UIPasteboard.general.items
-                            
-                            do {
-                                let etagPasteboard = try NSKeyedArchiver.archivedData(withRootObject: metadata.ocId, requiringSecureCoding: false)
-                                items.append([k_metadataKeyedUnarchiver:etagPasteboard])
-                            } catch {
-                                print("error")
-                            }
-                            
-                            UIPasteboard.general.setItems(items, options: [:])
-                            
-                        case selectorLoadOffline:
-                            
-                            NCManageDatabase.sharedInstance.setLocalFile(ocId: metadata.ocId, offline: true)
-                           
-                        case selectorSaveAlbum:
-                            
-                            let fileNamePath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!
-                            let status = PHPhotoLibrary.authorizationStatus()
-
-                            if metadata.typeFile == k_metadataTypeFile_image && status == PHAuthorizationStatus.authorized {
                                 
-                                if let image = UIImage.init(contentsOfFile: fileNamePath) {
-                                    UIImageWriteToSavedPhotosAlbum(image, self, #selector(SaveAlbum(_:didFinishSavingWithError:contextInfo:)), nil)
-                                } else {
-                                    NCContentPresenter.shared.messageNotification("_save_selected_files_", description: "_file_not_saved_cameraroll_", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: Int(k_CCErrorFileNotSaved))
+                            } else if metadata.typeFile == k_metadataTypeFile_compress || metadata.typeFile == k_metadataTypeFile_unknown {
+
+                                if let view = appDelegate.window?.rootViewController?.view {
+                                    documentController?.presentOptionsMenu(from: CGRect.zero, in: view, animated: true)
                                 }
                                 
-                            } else if metadata.typeFile == k_metadataTypeFile_video && status == PHAuthorizationStatus.authorized {
+                            } else if metadata.typeFile == k_metadataTypeFile_imagemeter {
                                 
-                                if UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(fileNamePath) {
-                                    UISaveVideoAtPathToSavedPhotosAlbum(fileNamePath, self, #selector(SaveAlbum(_:didFinishSavingWithError:contextInfo:)), nil)
-                                } else {
-                                    NCContentPresenter.shared.messageNotification("_save_selected_files_", description: "_file_not_saved_cameraroll_", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: Int(k_CCErrorFileNotSaved))
+                                if let view = appDelegate.window?.rootViewController?.view {
+                                    documentController?.presentOptionsMenu(from: CGRect.zero, in: view, animated: true)
                                 }
                                 
-                            } else if status != PHAuthorizationStatus.authorized {
+                            } else {
                                 
-                                NCContentPresenter.shared.messageNotification("_access_photo_not_enabled_", description: "_access_photo_not_enabled_msg_", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: Int(k_CCErrorFileNotSaved))
+                                NCViewer.shared.view(viewController: self.appDelegate.activeViewController, metadata: metadata, metadatas: [metadata])
                             }
+                        }
+                        
+                    case selectorOpenIn:
+                        
+                        if UIApplication.shared.applicationState == UIApplication.State.active {
                             
-                        default:
-                            
-                            break
+                            if let view = appDelegate.window?.rootViewController?.view {
+                                documentController?.presentOptionsMenu(from: CGRect.zero, in: view, animated: true)
+                            }
                         }
-                                
-                    } else {
                         
-                        // File do not exists on server, remove in local
-                        if (errorCode == k_CCErrorResourceNotFound || errorCode == k_CCErrorBadServerResponse) {
+                    case selectorLoadCopy:
+                        
+                        var items = UIPasteboard.general.items
+                        
+                        do {
+                            let etagPasteboard = try NSKeyedArchiver.archivedData(withRootObject: metadata.ocId, requiringSecureCoding: false)
+                            items.append([k_metadataKeyedUnarchiver:etagPasteboard])
+                        } catch {
+                            print("error")
+                        }
+                        
+                        UIPasteboard.general.setItems(items, options: [:])
+                        
+                    case selectorLoadOffline:
+                        
+                        NCManageDatabase.sharedInstance.setLocalFile(ocId: metadata.ocId, offline: true)
+                       
+                    case selectorSaveAlbum:
+                        
+                        let fileNamePath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!
+                        let status = PHPhotoLibrary.authorizationStatus()
+
+                        if metadata.typeFile == k_metadataTypeFile_image && status == PHAuthorizationStatus.authorized {
+                            
+                            if let image = UIImage.init(contentsOfFile: fileNamePath) {
+                                UIImageWriteToSavedPhotosAlbum(image, self, #selector(SaveAlbum(_:didFinishSavingWithError:contextInfo:)), nil)
+                            } else {
+                                NCContentPresenter.shared.messageNotification("_save_selected_files_", description: "_file_not_saved_cameraroll_", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: Int(k_CCErrorFileNotSaved))
+                            }
                             
-                            do {
-                                try FileManager.default.removeItem(atPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId))
-                            } catch { }
+                        } else if metadata.typeFile == k_metadataTypeFile_video && status == PHAuthorizationStatus.authorized {
                             
-                            NCManageDatabase.sharedInstance.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
-                            NCManageDatabase.sharedInstance.deleteLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
+                            if UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(fileNamePath) {
+                                UISaveVideoAtPathToSavedPhotosAlbum(fileNamePath, self, #selector(SaveAlbum(_:didFinishSavingWithError:contextInfo:)), nil)
+                            } else {
+                                NCContentPresenter.shared.messageNotification("_save_selected_files_", description: "_file_not_saved_cameraroll_", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: Int(k_CCErrorFileNotSaved))
+                            }
                             
-                        } else {
+                        } else if status != PHAuthorizationStatus.authorized {
                             
-                            NCContentPresenter.shared.messageNotification("_download_file_", description: errorDescription, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: errorCode)
+                            NCContentPresenter.shared.messageNotification("_access_photo_not_enabled_", description: "_access_photo_not_enabled_msg_", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: Int(k_CCErrorFileNotSaved))
                         }
+                        
+                    default:
+                        
+                        break
+                    }
+                            
+                } else {
+                    
+                    // File do not exists on server, remove in local
+                    if (errorCode == k_CCErrorResourceNotFound || errorCode == k_CCErrorBadServerResponse) {
+                        
+                        do {
+                            try FileManager.default.removeItem(atPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId))
+                        } catch { }
+                        
+                        NCManageDatabase.sharedInstance.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
+                        NCManageDatabase.sharedInstance.deleteLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
+                        
+                    } else {
+                        
+                        NCContentPresenter.shared.messageNotification("_download_file_", description: errorDescription, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: errorCode)
                     }
                 }
             }
@@ -204,13 +203,12 @@ import Foundation
     @objc func uploadedFile(_ notification: NSNotification) {
     
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let ocId = userInfo["ocId"] as? String, let errorCode = userInfo["errorCode"] as? Int, let errorDescription = userInfo["errorDescription"] as? String {
-                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
-                    if metadata.account == appDelegate.account {
-                        if errorCode != 0 {
-                            if errorCode != -999 && errorCode != 401 && errorDescription != "" {
-                                NCContentPresenter.shared.messageNotification("_upload_file_", description: errorDescription, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: errorCode)
-                            }
+            if let ocId = userInfo["ocId"] as? String, let errorCode = userInfo["errorCode"] as? Int, let errorDescription = userInfo["errorDescription"] as? String, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                
+                if metadata.account == appDelegate.account {
+                    if errorCode != 0 {
+                        if errorCode != -999 && errorCode != 401 && errorDescription != "" {
+                            NCContentPresenter.shared.messageNotification("_upload_file_", description: errorDescription, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: errorCode)
                         }
                     }
                 }

+ 46 - 49
iOSClient/Transfers/NCTransfers.swift

@@ -85,16 +85,15 @@ class NCTransfers: NCCollectionViewCommon, NCTransferCellDelegate  {
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let ocId = userInfo["ocId"] as? String {
-                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
-                    if let row = dataSource.addMetadata(metadata) {
-                        let indexPath = IndexPath(row: row, section: 0)
-                        collectionView?.performBatchUpdates({
-                            collectionView?.insertItems(at: [indexPath])
-                        }, completion: { (_) in
-                            self.reloadDataSource()
-                        })
-                    }
+            if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+            
+                if let row = dataSource.addMetadata(metadata) {
+                    let indexPath = IndexPath(row: row, section: 0)
+                    collectionView?.performBatchUpdates({
+                        collectionView?.insertItems(at: [indexPath])
+                    }, completion: { (_) in
+                        self.reloadDataSource()
+                    })
                 }
             }
         }
@@ -104,33 +103,32 @@ class NCTransfers: NCCollectionViewCommon, NCTransferCellDelegate  {
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let ocId = userInfo["ocId"] as? String, let ocIdTemp = userInfo["ocIdTemp"] as? String, let errorCode = userInfo["errorCode"] as? Int {
-                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
-                    if  errorCode == 0 {
-                        
-                        if let row = dataSource.deleteMetadata(ocId: metadata.ocId) {
-                            let indexPath = IndexPath(row: row, section: 0)
-                            collectionView?.performBatchUpdates({
-                                collectionView?.deleteItems(at: [indexPath])
-                            }, completion: { (_) in
-                                self.collectionView?.reloadData()
-                            })
-                        } else {
-                            reloadDataSource()
-                        }
-                        
-                    } else if errorCode != NSURLErrorCancelled {
-                        
-                        if let row = dataSource.reloadMetadata(ocId: metadata.ocId, ocIdTemp: ocIdTemp) {
-                            let indexPath = IndexPath(row: row, section: 0)
-                            collectionView?.performBatchUpdates({
-                                collectionView?.reloadItems(at: [indexPath])
-                            }, completion: { (_) in
-                                self.collectionView?.reloadData()
-                            })
-                        } else {
-                            reloadDataSource()
-                        }
+            if let ocId = userInfo["ocId"] as? String, let ocIdTemp = userInfo["ocIdTemp"] as? String, let errorCode = userInfo["errorCode"] as? Int, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                
+                if errorCode == 0 {
+                    
+                    if let row = dataSource.deleteMetadata(ocId: metadata.ocId) {
+                        let indexPath = IndexPath(row: row, section: 0)
+                        collectionView?.performBatchUpdates({
+                            collectionView?.deleteItems(at: [indexPath])
+                        }, completion: { (_) in
+                            self.collectionView?.reloadData()
+                        })
+                    } else {
+                        reloadDataSource()
+                    }
+                    
+                } else if errorCode != NSURLErrorCancelled {
+                    
+                    if let row = dataSource.reloadMetadata(ocId: metadata.ocId, ocIdTemp: ocIdTemp) {
+                        let indexPath = IndexPath(row: row, section: 0)
+                        collectionView?.performBatchUpdates({
+                            collectionView?.reloadItems(at: [indexPath])
+                        }, completion: { (_) in
+                            self.collectionView?.reloadData()
+                        })
+                    } else {
+                        reloadDataSource()
                     }
                 }
             }
@@ -141,18 +139,17 @@ class NCTransfers: NCCollectionViewCommon, NCTransferCellDelegate  {
         if self.view?.window == nil { return }
         
         if let userInfo = notification.userInfo as NSDictionary? {
-            if let ocId = userInfo["ocId"] as? String {
-                if let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
-                    if let row = dataSource.deleteMetadata(ocId: metadata.ocId) {
-                        let indexPath = IndexPath(row: row, section: 0)
-                        collectionView?.performBatchUpdates({
-                            collectionView?.deleteItems(at: [indexPath])
-                        }, completion: { (_) in
-                            self.collectionView?.reloadData()
-                        })
-                    } else {
-                        self.reloadDataSource()
-                    }
+            if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+            
+                if let row = dataSource.deleteMetadata(ocId: metadata.ocId) {
+                    let indexPath = IndexPath(row: row, section: 0)
+                    collectionView?.performBatchUpdates({
+                        collectionView?.deleteItems(at: [indexPath])
+                    }, completion: { (_) in
+                        self.collectionView?.reloadData()
+                    })
+                } else {
+                    self.reloadDataSource()
                 }
             }
         }

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

@@ -97,7 +97,6 @@ class NCViewerImage: UIViewController {
         NotificationCenter.default.addObserver(self, selector: #selector(deleteFile(_:)), name: NSNotification.Name(rawValue: k_notificationCenter_deleteFile), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(renameFile(_:)), name: NSNotification.Name(rawValue: k_notificationCenter_renameFile), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(moveFile(_:)), name: NSNotification.Name(rawValue: k_notificationCenter_moveFile), object: nil)
-        //NotificationCenter.default.addObserver(self, selector: #selector(favoriteFile(_:)), name: NSNotification.Name(rawValue: k_notificationCenter_favoriteFile), 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)
@@ -174,6 +173,7 @@ class NCViewerImage: UIViewController {
         
         if let userInfo = notification.userInfo as NSDictionary? {
             if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                
                 let metadatas = self.metadatas.filter { $0.ocId != metadata.ocId }
                 if self.metadatas.count == metadatas.count { return }
                 self.metadatas = metadatas
@@ -192,6 +192,7 @@ class NCViewerImage: UIViewController {
         
         if let userInfo = notification.userInfo as NSDictionary? {
             if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                
                 if let index = metadatas.firstIndex(where: {$0.ocId == metadata.ocId}) {
                     metadatas[index] = metadata
                     if index == currentIndex {
@@ -209,6 +210,7 @@ class NCViewerImage: UIViewController {
         
         if let userInfo = notification.userInfo as NSDictionary? {
             if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                
                 if metadatas.firstIndex(where: {$0.ocId == metadata.ocId}) != nil {
                     deleteFile(notification)
                 }
@@ -221,6 +223,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.sharedInstance.getMetadataFromOcId(ocId), let metadataMov = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocIdMov) {
+                
                 let fileNameImage = URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!)
                 let fileNameMov = URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadataMov.ocId, fileNameView: metadataMov.fileNameView)!)
                 

+ 1 - 0
iOSClient/Viewer/NCViewerNextcloudText/NCViewerNextcloudText.swift

@@ -110,6 +110,7 @@ class NCViewerNextcloudText: UIViewController, WKNavigationDelegate, WKScriptMes
         
         if let userInfo = notification.userInfo as NSDictionary? {
             if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                
                 if metadata.ocId == self.metadata.ocId {
                     self.metadata = metadata
                 }

+ 3 - 0
iOSClient/Viewer/NCViewerPDF/NCViewerPDF.swift

@@ -144,6 +144,7 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
         
         if let userInfo = notification.userInfo as NSDictionary? {
             if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                
                 if metadata.ocId == self.metadata.ocId {
                     self.metadata = metadata
                 }
@@ -155,6 +156,7 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
         
         if let userInfo = notification.userInfo as NSDictionary? {
             if let ocId = userInfo["ocId"] as? String, let ocIdNew = userInfo["ocIdNew"] as? String, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId), let metadataNew = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocIdNew) {
+                
                 if metadata.ocId == self.metadata.ocId {
                     self.metadata = metadataNew
                 }
@@ -176,6 +178,7 @@ class NCViewerPDF: UIViewController, NCViewerPDFSearchDelegate {
     @objc func renameFile(_ notification: NSNotification) {
         if let userInfo = notification.userInfo as NSDictionary? {
             if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                
                 if metadata.ocId == self.metadata.ocId {
                     self.metadata = metadata
                     navigationItem.title = metadata.fileNameView

+ 1 - 0
iOSClient/Viewer/NCViewerRichdocument/NCViewerRichdocument.swift

@@ -113,6 +113,7 @@ class NCViewerRichdocument: UIViewController, WKNavigationDelegate, WKScriptMess
         
         if let userInfo = notification.userInfo as NSDictionary? {
             if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.sharedInstance.getMetadataFromOcId(ocId) {
+                
                 if metadata.ocId == self.metadata.ocId {
                     self.metadata = metadata
                 }