Browse Source

Update NCViewerMediaPage.swift

Marino Faggiana 1 year ago
parent
commit
ebeafe6752
1 changed files with 34 additions and 3 deletions
  1. 34 3
      iOSClient/Viewer/NCViewerMedia/NCViewerMediaPage.swift

+ 34 - 3
iOSClient/Viewer/NCViewerMedia/NCViewerMediaPage.swift

@@ -65,6 +65,17 @@ class NCViewerMediaPage: UIViewController {
     var nextTrackCommand: Any?
     var previousTrackCommand: Any?
 
+    private var timerAutoHide: Timer?
+    private var timerAutoHideSeconds: Double {
+        get {
+            if NCUtility.shared.isSimulator() {
+                return 5
+            } else {
+                return 4
+            }
+        }
+    }
+
     // MARK: - View Life Cycle
 
     override func viewDidLoad() {
@@ -95,6 +106,8 @@ class NCViewerMediaPage: UIViewController {
         progressView.trackTintColor = .clear
         progressView.progress = 0
 
+        startTimerAutoHide()
+
         NotificationCenter.default.addObserver(self, selector: #selector(deleteFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterDeleteFile), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(renameFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterRenameFile), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(moveFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMoveFile), object: nil)
@@ -110,6 +123,8 @@ class NCViewerMediaPage: UIViewController {
 
     deinit {
 
+        timerAutoHide?.invalidate()
+
         NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterDeleteFile), object: nil)
         NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterRenameFile), object: nil)
         NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMoveFile), object: nil)
@@ -174,7 +189,7 @@ class NCViewerMediaPage: UIViewController {
         NCViewer.shared.toggleMenu(viewController: self, metadata: currentViewController.metadata, webView: false, imageIcon: imageIcon)
     }
 
-    func changeScreenMode(mode: ScreenMode, toggleToolbar: Bool) {
+    func changeScreenMode(mode: ScreenMode) {
 
         if mode == .normal {
 
@@ -206,11 +221,25 @@ class NCViewerMediaPage: UIViewController {
 
         viewerMediaScreenMode = mode
 
+        startTimerAutoHide()
         setNeedsStatusBarAppearanceUpdate()
         setNeedsUpdateOfHomeIndicatorAutoHidden()
         currentViewController.reloadDetail()
     }
 
+    func startTimerAutoHide() {
+
+        timerAutoHide?.invalidate()
+        timerAutoHide = Timer.scheduledTimer(timeInterval: timerAutoHideSeconds, target: self, selector: #selector(autoHide), userInfo: nil, repeats: true)
+    }
+
+    @objc func autoHide() {
+
+        if metadatas[currentIndex].classFile == NKCommon.TypeClassFile.video.rawValue || metadatas[currentIndex].classFile == NKCommon.TypeClassFile.audio.rawValue, viewerMediaScreenMode == .normal {
+            changeScreenMode(mode: .full)
+        }
+    }
+
     // MARK: - NotificationCenter
 
     @objc func downloadedFile(_ notification: NSNotification) {
@@ -505,6 +534,8 @@ extension NCViewerMediaPage: UIPageViewControllerDelegate, UIPageViewControllerD
 
         guard let nextViewController = pendingViewControllers.first as? NCViewerMedia else { return }
         nextIndex = nextViewController.index
+
+        startTimerAutoHide()
     }
 
     // END TRANSITION
@@ -565,9 +596,9 @@ extension NCViewerMediaPage: UIGestureRecognizerDelegate {
     @objc func didSingleTapWith(gestureRecognizer: UITapGestureRecognizer) {
 
         if viewerMediaScreenMode == .full {
-            changeScreenMode(mode: .normal, toggleToolbar: true)
+            changeScreenMode(mode: .normal)
         } else {
-            changeScreenMode(mode: .full, toggleToolbar: true)
+            changeScreenMode(mode: .full)
         }
     }