浏览代码

fix autohide

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana 1 年之前
父节点
当前提交
c42ca78fb8

+ 0 - 2
iOSClient/NCGlobal.swift

@@ -365,8 +365,6 @@ class NCGlobal: NSObject {
 
     let notificationCenterOpenMediaDetail                       = "openMediaDetail"                 // userInfo: ocId
     
-    let notificationCenterStartTimerAutoHideMediaPage           = "startTimerAutoHideMediaPage"
-
     let notificationCenterDismissScanDocument                   = "dismissScanDocument"
     let notificationCenterDismissUploadAssets                   = "dismissUploadAssets"
 

+ 1 - 1
iOSClient/Viewer/NCViewerMedia/NCPlayer/NCPlayer.swift

@@ -93,7 +93,7 @@ class NCPlayer: NSObject {
             view.addGestureRecognizer(singleTapGestureRecognizer)
         }
 
-        playerToolBar?.setBarPlayer(ncplayer: self, position: position, metadata: metadata)
+        playerToolBar?.setBarPlayer(ncplayer: self, position: position, metadata: metadata, viewerMediaPage: viewerMediaPage)
 
         if let media = player?.media {
             thumbnailer = VLCMediaThumbnailer(media: media, andDelegate: self)

+ 10 - 6
iOSClient/Viewer/NCViewerMedia/NCPlayer/NCPlayerToolBar.swift

@@ -52,6 +52,8 @@ class NCPlayerToolBar: UIView {
     private var metadata: tableMetadata?
     private var wasInPlay: Bool = false
 
+    private weak var viewerMediaPage: NCViewerMediaPage?
+
     // MARK: - View Life Cycle
 
     override func awakeFromNib() {
@@ -105,10 +107,11 @@ class NCPlayerToolBar: UIView {
 
     // MARK: -
 
-    func setBarPlayer(ncplayer: NCPlayer, position: Float, metadata: tableMetadata) {
+    func setBarPlayer(ncplayer: NCPlayer, position: Float, metadata: tableMetadata, viewerMediaPage: NCViewerMediaPage?) {
 
         self.ncplayer = ncplayer
         self.metadata = metadata
+        self.viewerMediaPage = viewerMediaPage
 
         playButton.setImage(NCUtility.shared.loadImage(named: "play.fill", color: .white, symbolConfiguration: UIImage.SymbolConfiguration(pointSize: 30)), for: .normal)
         MPNowPlayingInfoCenter.default().nowPlayingInfo?[MPNowPlayingInfoPropertyPlaybackRate] = 0
@@ -196,15 +199,16 @@ class NCPlayerToolBar: UIView {
 
         switch touchEvent.phase {
         case .began:
+            viewerMediaPage?.timerAutoHide?.invalidate()
             playbackSliderEvent = .began
         case .moved:
             ncplayer.playerPosition(newPosition)
-            NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterStartTimerAutoHideMediaPage)
             playbackSliderEvent = .moved
         case .ended:
             ncplayer.playerPosition(newPosition)
             DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
                 self.playbackSliderEvent = .ended
+                self.viewerMediaPage?.startTimerAutoHide()
             }
         default:
             break
@@ -226,7 +230,7 @@ class NCPlayerToolBar: UIView {
             ncplayer.playerPlay()
         }
 
-        NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterStartTimerAutoHideMediaPage)
+        self.viewerMediaPage?.startTimerAutoHide()
     }
 
     @IBAction func tapMute(_ sender: Any) {
@@ -243,7 +247,7 @@ class NCPlayerToolBar: UIView {
             muteButton.setImage(NCUtility.shared.loadImage(named: "audioOn", color: .white), for: .normal)
         }
 
-        NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterStartTimerAutoHideMediaPage)
+        self.viewerMediaPage?.startTimerAutoHide()
     }
 
     @IBAction func tapForward(_ sender: Any) {
@@ -252,7 +256,7 @@ class NCPlayerToolBar: UIView {
 
         ncplayer.jumpForward(10)
 
-        NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterStartTimerAutoHideMediaPage)
+        self.viewerMediaPage?.startTimerAutoHide()
     }
 
     @IBAction func tapBack(_ sender: Any) {
@@ -261,6 +265,6 @@ class NCPlayerToolBar: UIView {
 
         ncplayer.jumpBackward(10)
 
-        NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterStartTimerAutoHideMediaPage)
+        self.viewerMediaPage?.startTimerAutoHide()
     }
 }

+ 2 - 6
iOSClient/Viewer/NCViewerMedia/NCViewerMediaPage.swift

@@ -65,8 +65,8 @@ class NCViewerMediaPage: UIViewController {
     var nextTrackCommand: Any?
     var previousTrackCommand: Any?
 
-    private var timerAutoHide: Timer?
-    private var timerAutoHideSeconds: Double {
+    var timerAutoHide: Timer?
+    var timerAutoHideSeconds: Double {
         get {
             if NCUtility.shared.isSimulator() {
                 return 5
@@ -131,8 +131,6 @@ class NCViewerMediaPage: UIViewController {
         NotificationCenter.default.addObserver(self, selector: #selector(uploadedFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterUploadedFile), object: nil)
 
         NotificationCenter.default.addObserver(self, selector: #selector(applicationDidBecomeActive(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterApplicationDidBecomeActive), object: nil)
-
-        NotificationCenter.default.addObserver(self, selector: #selector(startTimerAutoHide), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterStartTimerAutoHideMediaPage), object: nil)
     }
 
     deinit {
@@ -150,8 +148,6 @@ class NCViewerMediaPage: UIViewController {
         NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterUploadedFile), object: nil)
 
         NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterApplicationDidBecomeActive), object: nil)
-
-        NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterStartTimerAutoHideMediaPage), object: nil)
     }
 
     override func viewDidDisappear(_ animated: Bool) {