diff --git a/iOSClient/NCGlobal.swift b/iOSClient/NCGlobal.swift index 295ffb83ec..67e1a3474e 100644 --- a/iOSClient/NCGlobal.swift +++ b/iOSClient/NCGlobal.swift @@ -337,6 +337,9 @@ class NCGlobal: NSObject { let notificationCenterEnableSwipeGesture = "enableSwipeGesture" let notificationCenterDisableSwipeGesture = "disableSwipeGesture" + let notificationCenterPlayerIsPlaying = "playerIsPlaying" + let notificationCenterPlayerStoppedPlaying = "playerStoppedPlaying" + // TIP // let tipNCViewerPDFThumbnail = "tipncviewerpdfthumbnail" diff --git a/iOSClient/Networking/NCNetworkingProcess.swift b/iOSClient/Networking/NCNetworkingProcess.swift index 7aefe4da44..3b39d48bb8 100644 --- a/iOSClient/Networking/NCNetworkingProcess.swift +++ b/iOSClient/Networking/NCNetworkingProcess.swift @@ -37,10 +37,21 @@ class NCNetworkingProcess { private var hasRun: Bool = false private let lockQueue = DispatchQueue(label: "com.nextcloud.networkingprocess.lockqueue") private var timerProcess: Timer? + private var enableControllingScreenAwake = true private init() { self.startTimer() self.startObserveTableMetadata() + + NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterPlayerIsPlaying), object: nil, queue: nil) { _ in + + self.enableControllingScreenAwake = false + } + + NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterPlayerStoppedPlaying), object: nil, queue: nil) { _ in + + self.enableControllingScreenAwake = true + } } private func startObserveTableMetadata() { @@ -85,23 +96,24 @@ class NCNetworkingProcess { let results = self.database.getResultsMetadatas(predicate: NSPredicate(format: "status != %d", self.global.metadataStatusNormal))?.freeze() else { return } self.hasRun = true - + /// Keep screen awake /// - /* Task { let tasks = await self.networking.getAllDataTask() let hasSynchronizationTask = tasks.contains { $0.taskDescription == NCGlobal.shared.taskDescriptionSynchronization } let resultsTransfer = results.filter { self.global.metadataStatusInTransfer.contains($0.status) } - + + + if !self.enableControllingScreenAwake { return } + if resultsTransfer.isEmpty && !hasSynchronizationTask { ScreenAwakeManager.shared.mode = .off } else { ScreenAwakeManager.shared.mode = NCKeychain().screenAwakeMode } } - */ - + if results.isEmpty { /// Remove Photo CameraRoll diff --git a/iOSClient/Settings/Display/NCDisplayView.swift b/iOSClient/Settings/Display/NCDisplayView.swift index 19b0574e90..d045d99d67 100644 --- a/iOSClient/Settings/Display/NCDisplayView.swift +++ b/iOSClient/Settings/Display/NCDisplayView.swift @@ -67,7 +67,6 @@ struct NCDisplayView: View { } .font(.system(size: 16)) - /* Section(header: Text(NSLocalizedString("_additional_options_", comment: ""))) { Picker(NSLocalizedString("_keep_screen_awake_", comment: ""), @@ -79,7 +78,6 @@ struct NCDisplayView: View { .frame(height: 50) } .pickerStyle(.menu) - */ } .navigationBarTitle(NSLocalizedString("_display_", comment: "")) .defaultViewModifier(model) diff --git a/iOSClient/Supporting Files/en.lproj/Localizable.strings b/iOSClient/Supporting Files/en.lproj/Localizable.strings index fe9ee97227..9895169301 100644 --- a/iOSClient/Supporting Files/en.lproj/Localizable.strings +++ b/iOSClient/Supporting Files/en.lproj/Localizable.strings @@ -1007,7 +1007,7 @@ "_additional_view_options_" = "Additional view options"; "_while_charging_" = "While charging"; "_additional_options_" = "Additional options"; -"_keep_screen_awake_" = "Keep screen awake while transferring files"; +"_keep_screen_awake_" = "Keep screen awake\n while transferring files"; "_error_not_found_" = "The requested resource could not be found"; "_error_conflict_" = "The request could not be completed due to a conflict with the current state of the resource"; "_error_precondition_" = "The server does not meet one of the preconditions that the requester"; diff --git a/iOSClient/Utility/ScreenAwakeManager/ScreenAwakeManager.swift b/iOSClient/Utility/ScreenAwakeManager/ScreenAwakeManager.swift index 43af39ecf6..28d17bab31 100644 --- a/iOSClient/Utility/ScreenAwakeManager/ScreenAwakeManager.swift +++ b/iOSClient/Utility/ScreenAwakeManager/ScreenAwakeManager.swift @@ -9,13 +9,6 @@ // Modified from https://github.com/ochococo/Insomnia import UIKit -/** - - Sometimes you want your iPhone to stay active a little bit longer is it an import or just game interface. - - This simple class aims to simplify the code and give you a well tested solution. - - */ class ScreenAwakeManager { static let shared: ScreenAwakeManager = { let instance = ScreenAwakeManager() diff --git a/iOSClient/Viewer/NCViewerMedia/NCPlayer/NCPlayer.swift b/iOSClient/Viewer/NCViewerMedia/NCPlayer/NCPlayer.swift index c3aac0db24..1c89774f70 100644 --- a/iOSClient/Viewer/NCViewerMedia/NCPlayer/NCPlayer.swift +++ b/iOSClient/Viewer/NCViewerMedia/NCPlayer/NCPlayer.swift @@ -74,6 +74,7 @@ class NCPlayer: NSObject { player.stop() print("deinit NCPlayer with ocId \(metadata.ocId)") NotificationCenter.default.removeObserver(self, name: UIApplication.didEnterBackgroundNotification, object: nil) + NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterPlayerStoppedPlaying) } func openAVPlayer(url: URL, autoplay: Bool = false) { @@ -166,7 +167,7 @@ class NCPlayer: NSObject { // MARK: - - func isPlay() -> Bool { + func isPlaying() -> Bool { return player.isPlaying } @@ -201,7 +202,7 @@ class NCPlayer: NSObject { } func savePosition() { - guard metadata.isVideo, isPlay() else { return } + guard metadata.isVideo, isPlaying() else { return } self.database.addVideo(metadata: metadata, position: player.position) } @@ -228,6 +229,9 @@ extension NCPlayer: VLCMediaPlayerDelegate { switch player.state { case .stopped: playerToolBar?.playButtonPlay() + + NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterPlayerStoppedPlaying) + print("Played mode: STOPPED") case .opening: print("Played mode: OPENING") @@ -273,8 +277,13 @@ extension NCPlayer: VLCMediaPlayerDelegate { self.height = Int(size.height) playerToolBar.updateTopToolBar(videoSubTitlesIndexes: player.videoSubTitlesIndexes, audioTrackIndexes: player.audioTrackIndexes) self.database.addVideo(metadata: metadata, width: self.width, height: self.height, length: self.length) + + NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterPlayerIsPlaying) + print("Played mode: PLAYING") case .paused: + NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterPlayerStoppedPlaying) + playerToolBar?.playButtonPlay() print("Played mode: PAUSED") default: break diff --git a/iOSClient/Viewer/NCViewerMedia/NCPlayer/NCPlayerToolBar.swift b/iOSClient/Viewer/NCViewerMedia/NCPlayer/NCPlayerToolBar.swift index 4aa84be3d5..fafdec1b8b 100644 --- a/iOSClient/Viewer/NCViewerMedia/NCPlayer/NCPlayerToolBar.swift +++ b/iOSClient/Viewer/NCViewerMedia/NCPlayer/NCPlayerToolBar.swift @@ -277,7 +277,7 @@ class NCPlayerToolBar: UIView { @IBAction func tapPlayerPause(_ sender: Any) { guard let ncplayer = ncplayer else { return } - if ncplayer.isPlay() { + if ncplayer.isPlaying() { ncplayer.playerPause() } else { ncplayer.playerPlay() diff --git a/iOSClient/Viewer/NCViewerMedia/NCViewerMedia.swift b/iOSClient/Viewer/NCViewerMedia/NCViewerMedia.swift index 84a1b2bfa8..2d3bd71414 100644 --- a/iOSClient/Viewer/NCViewerMedia/NCViewerMedia.swift +++ b/iOSClient/Viewer/NCViewerMedia/NCViewerMedia.swift @@ -211,7 +211,7 @@ class NCViewerMedia: UIViewController { override func viewDidDisappear(_ animated: Bool) { super.viewDidDisappear(animated) - if let ncplayer = ncplayer, ncplayer.isPlay() { + if let ncplayer = ncplayer, ncplayer.isPlaying() { ncplayer.playerPause() } } diff --git a/iOSClient/Viewer/NCViewerMedia/NCViewerMediaPage.swift b/iOSClient/Viewer/NCViewerMedia/NCViewerMediaPage.swift index 44d1f2e8db..1361b05bdb 100644 --- a/iOSClient/Viewer/NCViewerMedia/NCViewerMediaPage.swift +++ b/iOSClient/Viewer/NCViewerMedia/NCViewerMediaPage.swift @@ -335,7 +335,7 @@ class NCViewerMediaPage: UIViewController { if metadata.isAudioOrVideo, let ncplayer = self.currentViewController.ncplayer { let url = URL(fileURLWithPath: self.utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)) - if ncplayer.isPlay() { + if ncplayer.isPlaying() { ncplayer.playerPause() DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { ncplayer.openAVPlayer(url: url) @@ -386,7 +386,7 @@ class NCViewerMediaPage: UIViewController { NCContentPresenter().showError(error: error) } - if let ncplayer = currentViewController.ncplayer, ncplayer.isPlay() { + if let ncplayer = currentViewController.ncplayer, ncplayer.isPlaying() { ncplayer.playerPause() } @@ -410,7 +410,7 @@ class NCViewerMediaPage: UIViewController { MPRemoteCommandCenter.shared().playCommand.isEnabled = true playCommand = MPRemoteCommandCenter.shared().playCommand.addTarget { _ in - if !ncplayer.isPlay() { + if !ncplayer.isPlaying() { ncplayer.playerPlay() return .success } @@ -421,7 +421,7 @@ class NCViewerMediaPage: UIViewController { MPRemoteCommandCenter.shared().pauseCommand.isEnabled = true pauseCommand = MPRemoteCommandCenter.shared().pauseCommand.addTarget { _ in - if ncplayer.isPlay() { + if ncplayer.isPlaying() { ncplayer.playerPause() return .success }