Эх сурвалжийг харах

the nextcloud://open-file now open the file and not the blink

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana 2 жил өмнө
parent
commit
d27d9f95c4

+ 1 - 1
iOSClient/AppDelegate.swift

@@ -895,7 +895,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
                         }
 
                         DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
-                            NCFunctionCenter.shared.openFileViewInFolder(serverUrl: serverUrl, fileNameBlink: fileName)
+                            NCFunctionCenter.shared.openFileViewInFolder(serverUrl: serverUrl, fileNameBlink: nil, fileNameOpen: fileName)
                         }
 
                     } else {

+ 20 - 6
iOSClient/Files/NCFiles.swift

@@ -28,6 +28,7 @@ class NCFiles: NCCollectionViewCommon {
 
     internal var isRoot: Bool = true
     internal var fileNameBlink: String?
+    internal var fileNameOpen: String?
 
     // MARK: - View Life Cycle
 
@@ -60,6 +61,7 @@ class NCFiles: NCCollectionViewCommon {
         super.viewWillDisappear(animated)
 
         fileNameBlink = nil
+        fileNameOpen = nil
     }
 
     // MARK: - NotificationCenter
@@ -101,7 +103,7 @@ class NCFiles: NCCollectionViewCommon {
             self.richWorkspaceText = directory?.richWorkspace
 
             // FORCED false: test the directory.etag
-            if !forced, let directory = directory, directory.etag == self.dataSource.directory?.etag, metadataTransfer == nil, self.fileNameBlink == nil {
+            if !forced, let directory = directory, directory.etag == self.dataSource.directory?.etag, metadataTransfer == nil, self.fileNameBlink == nil, self.fileNameOpen == nil {
                 return
             }
 
@@ -122,7 +124,9 @@ class NCFiles: NCCollectionViewCommon {
                 self.collectionView.reloadData()
                 if !self.dataSource.metadatas.isEmpty {
                     self.blinkCell(fileName: self.fileNameBlink)
+                    self.openFile(fileName: self.fileNameOpen)
                     self.fileNameBlink = nil
+                    self.fileNameOpen = nil
                 }
             }
         }
@@ -139,10 +143,8 @@ class NCFiles: NCCollectionViewCommon {
 
         networkReadFolder(forced: forced) { tableDirectory, metadatas, metadatasUpdate, metadatasDelete, error in
             if error == .success {
-                for metadata in metadatas ?? [] {
-                    if !metadata.directory, NCManageDatabase.shared.isDownloadMetadata(metadata, download: false) {
-                        NCOperationQueue.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorDownloadFile)
-                    }
+                for metadata in metadatas ?? [] where !metadata.directory && NCManageDatabase.shared.isDownloadMetadata(metadata, download: false) {
+                    NCOperationQueue.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorDownloadFile)
                 }
             }
 
@@ -164,7 +166,7 @@ class NCFiles: NCCollectionViewCommon {
         if let fileName = fileName, let metadata = NCManageDatabase.shared.getMetadata(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileName == %@", self.appDelegate.account, self.serverUrl, fileName)) {
             let (indexPath, _) = self.dataSource.getIndexPathMetadata(ocId: metadata.ocId)
             if let indexPath = indexPath {
-                DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
+                DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
                     UIView.animate(withDuration: 0.3) {
                         self.collectionView.scrollToItem(at: indexPath, at: .centeredVertically, animated: false)
                     } completion: { _ in
@@ -179,4 +181,16 @@ class NCFiles: NCCollectionViewCommon {
             }
         }
     }
+
+    func openFile(fileName: String?) {
+
+        if let fileName = fileName, let metadata = NCManageDatabase.shared.getMetadata(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileName == %@", self.appDelegate.account, self.serverUrl, fileName)) {
+            let (indexPath, _) = self.dataSource.getIndexPathMetadata(ocId: metadata.ocId)
+            if let indexPath = indexPath {
+                DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
+                    self.collectionView(self.collectionView, didSelectItemAt: indexPath)
+                }
+            }
+        }
+    }
 }

+ 8 - 4
iOSClient/Main/NCFunctionCenter.swift

@@ -460,18 +460,20 @@ import Photos
 
     // MARK: -
 
-    func openFileViewInFolder(serverUrl: String, fileNameBlink: String?) {
+    func openFileViewInFolder(serverUrl: String, fileNameBlink: String?, fileNameOpen: String?) {
 
         appDelegate.isSearchingMode = false
         
         DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
             var topNavigationController: UINavigationController?
             var pushServerUrl = NCUtilityFileSystem.shared.getHomeServer(account: self.appDelegate.account)
-            var mostViewController = UIApplication.shared.keyWindow!.rootViewController!.topMostViewController()
+            guard var mostViewController = self.appDelegate.window?.rootViewController?.topMostViewController() else { return }
 
             if mostViewController.isModal {
                 mostViewController.dismiss(animated: false)
-                mostViewController = UIApplication.shared.keyWindow!.rootViewController!.topMostViewController()
+                if let viewController = self.appDelegate.window?.rootViewController?.topMostViewController() {
+                    mostViewController = viewController
+                }
             }
             mostViewController.navigationController?.popToRootViewController(animated: false)
 
@@ -485,6 +487,7 @@ import Photos
             if pushServerUrl == serverUrl {
                 let viewController = topNavigationController?.topViewController as? NCFiles
                 viewController?.blinkCell(fileName: fileNameBlink)
+                viewController?.openFile(fileName: fileNameOpen)
                 return
             }
             guard let topNavigationController = topNavigationController else { return }
@@ -502,6 +505,7 @@ import Photos
                 viewController.titleCurrentFolder = String(dir)
                 if pushServerUrl == serverUrl {
                     viewController.fileNameBlink = fileNameBlink
+                    viewController.fileNameOpen = fileNameOpen
                 }
                 self.appDelegate.listFilesVC[serverUrl] = viewController
 
@@ -650,7 +654,7 @@ import Photos
         }
 
         let viewInFolder = UIAction(title: NSLocalizedString("_view_in_folder_", comment: ""), image: UIImage(systemName: "arrow.forward.square")) { _ in
-            self.openFileViewInFolder(serverUrl: metadata.serverUrl, fileNameBlink: metadata.fileName)
+            self.openFileViewInFolder(serverUrl: metadata.serverUrl, fileNameBlink: metadata.fileName, fileNameOpen: nil)
         }
 
         let openIn = UIAction(title: NSLocalizedString("_open_in_", comment: ""), image: UIImage(systemName: "square.and.arrow.up") ) { _ in

+ 1 - 1
iOSClient/Menu/NCViewer+Menu.swift

@@ -190,7 +190,7 @@ extension NCViewer {
                     title: NSLocalizedString("_view_in_folder_", comment: ""),
                     icon: NCUtility.shared.loadImage(named: "arrow.forward.square"),
                     action: { menuAction in
-                        NCFunctionCenter.shared.openFileViewInFolder(serverUrl: metadata.serverUrl, fileNameBlink: metadata.fileName)
+                        NCFunctionCenter.shared.openFileViewInFolder(serverUrl: metadata.serverUrl, fileNameBlink: metadata.fileName, fileNameOpen: nil)
                     }
                 )
             )