marinofaggiana 5 жил өмнө
parent
commit
965f25deb9

+ 2 - 64
iOSClient/Main/NCDetailNavigationController.swift

@@ -27,16 +27,11 @@ class NCDetailNavigationController: UINavigationController {
     
     let appDelegate = UIApplication.shared.delegate as! AppDelegate
     
-    var progressView: UIProgressView?
-    let progressHeight: CGFloat = 1
-
     override func viewDidLoad() {
         super.viewDidLoad()
         
         NotificationCenter.default.addObserver(self, selector: #selector(self.changeTheming), name: NSNotification.Name(rawValue: k_notificationCenter_changeTheming), object: nil)
-        NotificationCenter.default.addObserver(self, selector: #selector(self.triggerProgressTask(_:)), name: NSNotification.Name(rawValue: k_notificationCenter_progressTask), object:nil)
-        NotificationCenter.default.addObserver(self, selector: #selector(self.downloadFile(_:)), name: NSNotification.Name(rawValue: k_notificationCenter_downloadFile), object: nil)
-                
+        
         changeTheming()
     }
     
@@ -51,9 +46,7 @@ class NCDetailNavigationController: UINavigationController {
             if !splitViewController.isCollapsed {
                 topViewController?.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem
             }
-        }
-        
-        setProgressBar()
+        }        
     }
     
     //MARK: - NotificationCenter
@@ -64,33 +57,6 @@ class NCDetailNavigationController: UINavigationController {
         navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor:NCBrandColor.sharedInstance.brandText]
     }
     
-    @objc func triggerProgressTask(_ notification: NSNotification) {
-        guard let metadata = appDelegate.activeDetail.metadata else {
-            setProgressBar()
-            return
-        }
-        
-        if let userInfo = notification.userInfo as NSDictionary? {
-            if let account = userInfo["account"] as? String, let serverUrl = userInfo["serverUrl"] as? String, let progress = userInfo["progress"] as? Float {
-                if account == metadata.account && serverUrl == metadata.serverUrl {
-                    self.progress(progress)
-                }
-            }
-        }
-    }
-    
-    @objc func downloadFile(_ notification: NSNotification) {
-        guard let metadataDetail = appDelegate.activeDetail.metadata else { return }
-        
-        if let userInfo = notification.userInfo as NSDictionary? {
-            if let metadata = userInfo["metadata"] as? tableMetadata {
-                if metadataDetail.account == metadata.account && metadataDetail.serverUrl == metadata.serverUrl {
-                    setProgressBar()
-                }
-            }
-        }
-    }
-    
     //MARK: - Button
 
     @objc func openMenuMore() {
@@ -98,32 +64,4 @@ class NCDetailNavigationController: UINavigationController {
             self.toggleMoreMenu(viewController: self, metadata: metadata)
         }
     }
-    
-    //MARK: - ProgressBar
-
-    @objc func setProgressBar() {
-        if progressView != nil {
-            progressView?.removeFromSuperview()
-        }
-        
-        progressView = UIProgressView.init(progressViewStyle: .bar)
-        progressView!.frame = CGRect(x: 0, y: navigationBar.frame.height-progressHeight, width: navigationBar.frame.width, height: progressHeight)
-        progressView!.setProgress(0, animated: false)
-        progressView!.tintColor = NCBrandColor.sharedInstance.icon
-        progressView!.trackTintColor = .clear
-        navigationBar.addSubview(progressView!)
-        
-        NotificationCenter.default.addObserver(self, selector: #selector(self.orientationDidChange), name: UIDevice.orientationDidChangeNotification, object: nil)
-    }
-    
-    @objc func progress(_ progress: Float) {
-        guard let progressView = self.progressView else { return }
-        progressView.progress = progress
-    }
-    
-    @objc func orientationDidChange() {
-        guard let progressView = self.progressView else { return }
-        
-        progressView.frame = CGRect(x: 0, y: navigationBar.frame.height-progressHeight, width: navigationBar.frame.width, height: progressHeight)
-    }
 }

+ 48 - 3
iOSClient/Main/NCDetailViewController.swift

@@ -40,6 +40,8 @@ class NCDetailViewController: UIViewController {
     
     @objc  var viewerImageViewController: NCViewerImageViewController?
     private var metadatas = [tableMetadata]()
+    private var progressView: UIProgressView?
+    private let progressHeight: CGFloat = 2
         
     //MARK: -
 
@@ -60,9 +62,11 @@ class NCDetailViewController: UIViewController {
         NotificationCenter.default.addObserver(self, selector: #selector(self.uploadFile(_:)), name: NSNotification.Name(rawValue: k_notificationCenter_uploadFile), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(self.renameFile(_:)), name: NSNotification.Name(rawValue: k_notificationCenter_renameFile), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(self.moveFile(_:)), name: NSNotification.Name(rawValue: k_notificationCenter_moveFile), object: nil)
+        NotificationCenter.default.addObserver(self, selector: #selector(self.triggerProgressTask(_:)), name: NSNotification.Name(rawValue: k_notificationCenter_progressTask), object:nil)
         
         changeTheming()
-        
+        setProgressBar()
+
         if metadata != nil  {
             viewFile(metadata: metadata!, selector: selector)
         }
@@ -91,9 +95,34 @@ class NCDetailViewController: UIViewController {
         super.viewWillTransition(to: size, with: coordinator)
         
         coordinator.animate(alongsideTransition: nil) { _ in
+            
+            if let progressView = self.progressView, let navigationBar = self.navigationController?.navigationBar {
+                 progressView.frame = CGRect(x: 0, y: navigationBar.frame.height-self.progressHeight, width: navigationBar.frame.width, height: self.progressHeight)
+            }
         }
     }
     
+    //MARK: - ProgressBar
+
+    @objc func setProgressBar() {
+        
+        if progressView != nil { progressView?.removeFromSuperview() }
+        guard let navigationBar = self.navigationController?.navigationBar else { return }
+        
+        progressView = UIProgressView.init(progressViewStyle: .bar)
+        progressView!.frame = CGRect(x: 0, y: navigationBar.frame.height-progressHeight, width: navigationBar.frame.width, height: progressHeight)
+        progressView!.setProgress(0, animated: false)
+        progressView!.tintColor = NCBrandColor.sharedInstance.icon
+        progressView!.trackTintColor = .clear
+        progressView!.transform = CGAffineTransform(scaleX: 1, y: progressHeight)
+        navigationBar.addSubview(progressView!)
+    }
+    
+    @objc func progress(_ progress: Float) {
+        guard let progressView = self.progressView else { return }
+        progressView.progress = progress
+    }
+    
     //MARK: - Utility
 
     func subViewActive() -> UIView? {
@@ -155,13 +184,29 @@ class NCDetailViewController: UIViewController {
         NCViewerImageCommon.shared.imageChangeSizeView(viewerImageViewController: viewerImageViewController, size: self.backgroundView.frame.size, metadata: metadata)
     }
     
+    @objc func triggerProgressTask(_ notification: NSNotification) {
+        guard let metadata = self.metadata else { return }
+        
+        if let userInfo = notification.userInfo as NSDictionary? {
+            if let account = userInfo["account"] as? String, let serverUrl = userInfo["serverUrl"] as? String, let progress = userInfo["progress"] as? Float {
+                if account == metadata.account && serverUrl == metadata.serverUrl {
+                    self.progress(progress)
+                }
+            }
+        }
+    }
+    
     @objc func downloadFile(_ notification: NSNotification) {
         if let userInfo = notification.userInfo as NSDictionary? {
             if let metadata = userInfo["metadata"] as? tableMetadata, let errorCode = userInfo["errorCode"] as? Int {
                 
-                if errorCode == 0 && metadata.account == self.metadata?.account && metadata.serverUrl == self.metadata?.serverUrl && metadata.typeFile == k_metadataTypeFile_image && viewerImageViewController != nil {
+                if errorCode == 0 && metadata.account == self.metadata?.account && metadata.serverUrl == self.metadata?.serverUrl {
+                    
+                    if metadata.typeFile == k_metadataTypeFile_image && viewerImageViewController != nil {
+                        viewerImageViewController?.reloadContentViews()
+                    }
                     
-                    viewerImageViewController?.reloadContentViews()
+                    setProgressBar()
                 }
             }
         }