marinofaggiana 3 năm trước cách đây
mục cha
commit
ef9749cc21

+ 1 - 0
iOSClient/AppDelegate.swift

@@ -49,6 +49,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
     var activeServerUrl: String = ""
     @objc var activeViewController: UIViewController?
     var activeViewerVideo: NCViewerVideo?
+    var mainTabBar: NCMainTabBar?
     
     var listFilesVC: [String:NCFiles] = [:]
     var listFavoriteVC: [String:NCFavorite] = [:]

+ 21 - 21
iOSClient/Main/NCFunctionCenter.swift

@@ -50,10 +50,6 @@ import Queuer
                 
                 if errorCode == 0 {
                     
-                    let fileURL = URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView))
-                    documentController = UIDocumentInteractionController(url: fileURL)
-                    documentController?.delegate = self
-
                     switch selector {
                     case NCGlobal.shared.selectorLoadFileQuickLook:
                         
@@ -69,21 +65,15 @@ import Queuer
                                                         
                             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)
-                                }
+                                self.openDocumentController(metadata: metadata)
                                 
                             } else if metadata.typeFile == NCGlobal.shared.metadataTypeFileCompress || metadata.typeFile == NCGlobal.shared.metadataTypeFileUnknown {
 
-                                if let view = appDelegate.window?.rootViewController?.view {
-                                    documentController?.presentOptionsMenu(from: CGRect.zero, in: view, animated: true)
-                                }
+                                self.openDocumentController(metadata: metadata)
                                 
                             } else if metadata.typeFile == NCGlobal.shared.metadataTypeFileImagemeter {
                                 
-                                if let view = appDelegate.window?.rootViewController?.view {
-                                    documentController?.presentOptionsMenu(from: CGRect.zero, in: view, animated: true)
-                                }
+                                self.openDocumentController(metadata: metadata)
                                 
                             } else {
                                 
@@ -98,9 +88,7 @@ import Queuer
                         
                         if UIApplication.shared.applicationState == UIApplication.State.active {
                             
-                            if let view = appDelegate.window?.rootViewController?.view {
-                                documentController?.presentOptionsMenu(from: CGRect.zero, in: view, animated: true)
-                            }
+                            self.openDocumentController(metadata: metadata)
                         }
                         
                     case NCGlobal.shared.selectorLoadCopy:
@@ -213,9 +201,18 @@ import Queuer
         }
     }
     
-    // MARK: - Open in (files)
+    // MARK: - Open in ...
     
-    func openActivityViewController(viewController: UIViewController, selectOcId: [String]) {
+    func openDocumentController(metadata: tableMetadata) {
+        
+        guard let mainTabBar = self.appDelegate.mainTabBar else { return }
+        let fileURL = URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView))
+        
+        documentController = UIDocumentInteractionController(url: fileURL)
+        documentController?.presentOptionsMenu(from: mainTabBar.menuRect, in: mainTabBar, animated: true)
+    }
+    
+    func openActivityViewController(selectOcId: [String]) {
         
         DispatchQueue.global().async {
             
@@ -244,13 +241,16 @@ import Queuer
             }
             if error == 0 && items.count > 0 {
                 DispatchQueue.main.async {
+                    
+                    guard let mainTabBar = self.appDelegate.mainTabBar else { return }
+                            
                     let activityViewController = UIActivityViewController.init(activityItems: items, applicationActivities: nil)
 
                     activityViewController.popoverPresentationController?.permittedArrowDirections = .any
-                    activityViewController.popoverPresentationController?.sourceView = viewController.view
-                    activityViewController.popoverPresentationController?.sourceRect = CGRect.zero
+                    activityViewController.popoverPresentationController?.sourceView = mainTabBar
+                    activityViewController.popoverPresentationController?.sourceRect = mainTabBar.menuRect
                     
-                    viewController.present(activityViewController, animated: true)
+                    self.appDelegate.window?.rootViewController?.present(activityViewController, animated: true)
                 }
             }
         }

+ 10 - 0
iOSClient/Main/NCMainTabBar.swift

@@ -30,11 +30,21 @@ class NCMainTabBar: UITabBar {
     private let appDelegate = UIApplication.shared.delegate as! AppDelegate
     private var timer: Timer?
     
+    public var menuRect: CGRect {
+        get {
+            let tabBarItemWidth = Int(self.frame.size.width) / (self.items?.count ?? 0)
+            let rect = CGRect(x: 0, y: -5, width: tabBarItemWidth, height: Int(self.frame.size.height))
+            
+            return rect
+        }
+    }
+    
     // MARK: - Life Cycle
 
     required init?(coder: NSCoder) {
         super.init(coder: coder)
         
+        appDelegate.mainTabBar = self
         timer = Timer.scheduledTimer(timeInterval: 3, target: self, selector: (#selector(updateBadgeNumber)), userInfo: nil, repeats: true)
             
         NotificationCenter.default.addObserver(self, selector: #selector(changeTheming), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterChangeTheming), object: nil)

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

@@ -412,7 +412,7 @@ extension NCCollectionViewCommon {
                 title: NSLocalizedString("_open_in_", comment: ""),
                 icon: NCUtility.shared.loadImage(named: "square.and.arrow.up"),
                 action: { menuAction in
-                    NCFunctionCenter.shared.openActivityViewController(viewController: self, selectOcId: self.selectOcId)
+                    NCFunctionCenter.shared.openActivityViewController(selectOcId: self.selectOcId)
                     self.tapSelect(sender: self)
                 }
             )

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

@@ -154,7 +154,7 @@ extension NCMedia {
                     icon: NCUtility.shared.loadImage(named: "square.and.arrow.up"),
                     action: { menuAction in
                         self.isEditMode = false
-                        NCFunctionCenter.shared.openActivityViewController(viewController: self, selectOcId: self.selectOcId)
+                        NCFunctionCenter.shared.openActivityViewController(selectOcId: self.selectOcId)
                         self.selectOcId.removeAll()
                         self.reloadDataThenPerform { }
                     }