NCViewerMediaPage.swift 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. //
  2. // NCViewerMediaPage.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 24/10/2020.
  6. // Copyright © 2020 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. import UIKit
  24. import NCCommunication
  25. import MediaPlayer
  26. class NCViewerMediaPage: UIViewController {
  27. @IBOutlet weak var progressView: UIProgressView!
  28. enum ScreenMode {
  29. case full, normal
  30. }
  31. var currentScreenMode: ScreenMode = .normal
  32. var saveScreenModeImage: ScreenMode = .normal
  33. var pageViewController: UIPageViewController {
  34. return self.children[0] as! UIPageViewController
  35. }
  36. var currentViewController: NCViewerMedia {
  37. return self.pageViewController.viewControllers![0] as! NCViewerMedia
  38. }
  39. var metadatas: [tableMetadata] = []
  40. var currentIndex = 0
  41. var nextIndex: Int?
  42. var ncplayerLivePhoto: NCPlayer?
  43. var panGestureRecognizer: UIPanGestureRecognizer!
  44. var singleTapGestureRecognizer: UITapGestureRecognizer!
  45. var longtapGestureRecognizer: UILongPressGestureRecognizer!
  46. var textColor: UIColor = NCBrandColor.shared.label
  47. var playCommand: Any?
  48. var pauseCommand: Any?
  49. var skipForwardCommand: Any?
  50. var skipBackwardCommand: Any?
  51. var nextTrackCommand: Any?
  52. var previousTrackCommand: Any?
  53. // MARK: - View Life Cycle
  54. override func viewDidLoad() {
  55. super.viewDidLoad()
  56. navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(named: "more")!.image(color: NCBrandColor.shared.label, size: 25), style: .plain, target: self, action: #selector(self.openMenuMore))
  57. singleTapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(didSingleTapWith(gestureRecognizer:)))
  58. panGestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(didPanWith(gestureRecognizer:)))
  59. longtapGestureRecognizer = UILongPressGestureRecognizer()
  60. longtapGestureRecognizer.delaysTouchesBegan = true
  61. longtapGestureRecognizer.minimumPressDuration = 0.3
  62. longtapGestureRecognizer.delegate = self
  63. longtapGestureRecognizer.addTarget(self, action: #selector(didLongpressGestureEvent(gestureRecognizer:)))
  64. pageViewController.delegate = self
  65. pageViewController.dataSource = self
  66. pageViewController.view.addGestureRecognizer(panGestureRecognizer)
  67. pageViewController.view.addGestureRecognizer(singleTapGestureRecognizer)
  68. pageViewController.view.addGestureRecognizer(longtapGestureRecognizer)
  69. let viewerMedia = getViewerMedia(index: currentIndex, metadata: metadatas[currentIndex])
  70. pageViewController.setViewControllers([viewerMedia], direction: .forward, animated: true, completion: nil)
  71. NotificationCenter.default.addObserver(self, selector: #selector(changeTheming), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterChangeTheming), object: nil)
  72. NotificationCenter.default.addObserver(self, selector: #selector(viewUnload), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMenuDetailClose), object: nil)
  73. progressView.tintColor = NCBrandColor.shared.brandElement
  74. progressView.trackTintColor = .clear
  75. progressView.progress = 0
  76. NotificationCenter.default.addObserver(self, selector: #selector(deleteFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterDeleteFile), object: nil)
  77. NotificationCenter.default.addObserver(self, selector: #selector(renameFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterRenameFile), object: nil)
  78. NotificationCenter.default.addObserver(self, selector: #selector(moveFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMoveFile), object: nil)
  79. NotificationCenter.default.addObserver(self, selector: #selector(downloadedFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterDownloadedFile), object: nil)
  80. NotificationCenter.default.addObserver(self, selector: #selector(triggerProgressTask(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterProgressTask), object: nil)
  81. NotificationCenter.default.addObserver(self, selector: #selector(hidePlayerToolBar(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterHidePlayerToolBar), object: nil)
  82. NotificationCenter.default.addObserver(self, selector: #selector(showPlayerToolBar(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterShowPlayerToolBar), object: nil)
  83. NotificationCenter.default.addObserver(self, selector: #selector(reloadMediaPage(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterReloadMediaPage), object: nil)
  84. NotificationCenter.default.addObserver(self, selector: #selector(applicationDidBecomeActive(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterApplicationDidBecomeActive), object: nil)
  85. }
  86. override func viewDidDisappear(_ animated: Bool) {
  87. super.viewDidDisappear(animated)
  88. // Clear
  89. if let ncplayer = currentViewController.ncplayer, ncplayer.isPlay() {
  90. ncplayer.playerPause()
  91. ncplayer.saveCurrentTime()
  92. }
  93. currentViewController.playerToolBar.stopTimerAutoHide()
  94. clearCommandCenter()
  95. metadatas.removeAll()
  96. ncplayerLivePhoto = nil
  97. #if MFFFLIB
  98. MFFF.shared.dismissMessage()
  99. #endif
  100. // Remove Observer
  101. NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterDeleteFile), object: nil)
  102. NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterRenameFile), object: nil)
  103. NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMoveFile), object: nil)
  104. NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterDownloadedFile), object: nil)
  105. NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterProgressTask), object: nil)
  106. NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterHidePlayerToolBar), object: nil)
  107. NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterShowPlayerToolBar), object: nil)
  108. NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterReloadMediaPage), object: nil)
  109. NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterApplicationDidBecomeActive), object: nil)
  110. }
  111. override var preferredStatusBarStyle: UIStatusBarStyle {
  112. if currentScreenMode == .normal {
  113. return .default
  114. } else {
  115. return .lightContent
  116. }
  117. }
  118. // MARK: -
  119. func getViewerMedia(index: Int, metadata: tableMetadata) -> NCViewerMedia {
  120. let viewerMedia = UIStoryboard(name: "NCViewerMediaPage", bundle: nil).instantiateViewController(withIdentifier: "NCViewerMedia") as! NCViewerMedia
  121. viewerMedia.index = index
  122. viewerMedia.metadata = metadata
  123. viewerMedia.viewerMediaPage = self
  124. singleTapGestureRecognizer.require(toFail: viewerMedia.doubleTapGestureRecognizer)
  125. return viewerMedia
  126. }
  127. @objc func viewUnload() {
  128. navigationController?.popViewController(animated: true)
  129. }
  130. @objc func openMenuMore() {
  131. let imageIcon = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(currentViewController.metadata.ocId, etag: currentViewController.metadata.etag))
  132. NCViewer.shared.toggleMenu(viewController: self, metadata: currentViewController.metadata, webView: false, imageIcon: imageIcon)
  133. }
  134. func changeScreenMode(mode: ScreenMode, enableTimerAutoHide: Bool = false) {
  135. if mode == .normal {
  136. navigationController?.setNavigationBarHidden(false, animated: true)
  137. progressView.isHidden = false
  138. if !currentViewController.detailView.isShow() {
  139. currentViewController.playerToolBar.show(enableTimerAutoHide: enableTimerAutoHide)
  140. }
  141. NCUtility.shared.colorNavigationController(navigationController, backgroundColor: NCBrandColor.shared.systemBackground, titleColor: NCBrandColor.shared.label, tintColor: nil, withoutShadow: false)
  142. view.backgroundColor = NCBrandColor.shared.systemBackground
  143. textColor = NCBrandColor.shared.label
  144. } else {
  145. navigationController?.setNavigationBarHidden(true, animated: true)
  146. progressView.isHidden = true
  147. currentViewController.playerToolBar.hide()
  148. view.backgroundColor = .black
  149. textColor = .white
  150. }
  151. currentScreenMode = mode
  152. if currentViewController.metadata.classFile == NCCommunicationCommon.typeClassFile.image.rawValue {
  153. saveScreenModeImage = mode
  154. }
  155. setNeedsStatusBarAppearanceUpdate()
  156. currentViewController.reloadDetail()
  157. }
  158. // MARK: - NotificationCenter
  159. @objc func downloadedFile(_ notification: NSNotification) {
  160. progressView.progress = 0
  161. }
  162. @objc func triggerProgressTask(_ notification: NSNotification) {
  163. if let userInfo = notification.userInfo as NSDictionary? {
  164. if let progressNumber = userInfo["progress"] as? NSNumber {
  165. let progress = progressNumber.floatValue
  166. if progress == 1 {
  167. self.progressView.progress = 0
  168. } else {
  169. self.progressView.progress = progress
  170. }
  171. }
  172. }
  173. }
  174. @objc func deleteFile(_ notification: NSNotification) {
  175. if let userInfo = notification.userInfo as NSDictionary? {
  176. if let ocId = userInfo["ocId"] as? String {
  177. let metadatas = self.metadatas.filter { $0.ocId != ocId }
  178. if self.metadatas.count == metadatas.count { return }
  179. self.metadatas = metadatas
  180. if ocId == currentViewController.metadata.ocId {
  181. shiftCurrentPage()
  182. }
  183. }
  184. }
  185. }
  186. @objc func renameFile(_ notification: NSNotification) {
  187. if let userInfo = notification.userInfo as NSDictionary? {
  188. if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
  189. if let index = metadatas.firstIndex(where: {$0.ocId == metadata.ocId}) {
  190. metadatas[index] = metadata
  191. if index == currentIndex {
  192. navigationItem.title = metadata.fileNameView
  193. currentViewController.metadata = metadata
  194. self.currentViewController.metadata = metadata
  195. }
  196. }
  197. }
  198. }
  199. }
  200. @objc func moveFile(_ notification: NSNotification) {
  201. if let userInfo = notification.userInfo as NSDictionary? {
  202. if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
  203. if metadatas.firstIndex(where: {$0.ocId == metadata.ocId}) != nil {
  204. deleteFile(notification)
  205. }
  206. }
  207. }
  208. }
  209. @objc func changeTheming() {
  210. }
  211. @objc func hidePlayerToolBar(_ notification: NSNotification) {
  212. if let userInfo = notification.userInfo as NSDictionary?, let ocId = userInfo["ocId"] as? String {
  213. if currentViewController.metadata.ocId == ocId {
  214. changeScreenMode(mode: .full)
  215. }
  216. }
  217. }
  218. @objc func showPlayerToolBar(_ notification: NSNotification) {
  219. if let userInfo = notification.userInfo as NSDictionary?, let ocId = userInfo["ocId"] as? String, let enableTimerAutoHide = userInfo["enableTimerAutoHide"] as? Bool {
  220. if currentViewController.metadata.ocId == ocId, let playerToolBar = currentViewController.playerToolBar, !playerToolBar.isPictureInPictureActive() {
  221. changeScreenMode(mode: .normal, enableTimerAutoHide: enableTimerAutoHide)
  222. }
  223. }
  224. }
  225. @objc func reloadMediaPage(_ notification: NSNotification) {
  226. self.reloadCurrentPage()
  227. }
  228. @objc func applicationDidBecomeActive(_ notification: NSNotification) {
  229. progressView.progress = 0
  230. }
  231. // MARK: - Command Center
  232. func updateCommandCenter(ncplayer: NCPlayer, metadata: tableMetadata) {
  233. var nowPlayingInfo = [String: Any]()
  234. // Clear
  235. clearCommandCenter()
  236. UIApplication.shared.beginReceivingRemoteControlEvents()
  237. // Add handler for Play Command
  238. MPRemoteCommandCenter.shared().playCommand.isEnabled = true
  239. playCommand = MPRemoteCommandCenter.shared().playCommand.addTarget { _ in
  240. if !ncplayer.isPlay() {
  241. ncplayer.playerPlay()
  242. return .success
  243. }
  244. return .commandFailed
  245. }
  246. // Add handler for Pause Command
  247. MPRemoteCommandCenter.shared().pauseCommand.isEnabled = true
  248. pauseCommand = MPRemoteCommandCenter.shared().pauseCommand.addTarget { _ in
  249. if ncplayer.isPlay() {
  250. ncplayer.playerPause()
  251. return .success
  252. }
  253. return .commandFailed
  254. }
  255. // VIDEO / AUDIO () ()
  256. if metadata.classFile == NCCommunicationCommon.typeClassFile.video.rawValue || metadata.classFile == NCCommunicationCommon.typeClassFile.audio.rawValue {
  257. MPRemoteCommandCenter.shared().skipForwardCommand.isEnabled = true
  258. skipForwardCommand = MPRemoteCommandCenter.shared().skipForwardCommand.addTarget { event in
  259. let seconds = Float64((event as! MPSkipIntervalCommandEvent).interval)
  260. self.currentViewController.playerToolBar.skip(seconds: seconds)
  261. return.success
  262. }
  263. MPRemoteCommandCenter.shared().skipBackwardCommand.isEnabled = true
  264. skipBackwardCommand = MPRemoteCommandCenter.shared().skipBackwardCommand.addTarget { event in
  265. let seconds = Float64((event as! MPSkipIntervalCommandEvent).interval)
  266. self.currentViewController.playerToolBar.skip(seconds: -seconds)
  267. return.success
  268. }
  269. }
  270. // AUDIO < >
  271. /*
  272. if metadata?.classFile == NCCommunicationCommon.typeClassFile.audio.rawValue {
  273. MPRemoteCommandCenter.shared().nextTrackCommand.isEnabled = true
  274. appDelegate.nextTrackCommand = MPRemoteCommandCenter.shared().nextTrackCommand.addTarget { event in
  275. self.forward()
  276. return .success
  277. }
  278. MPRemoteCommandCenter.shared().previousTrackCommand.isEnabled = true
  279. appDelegate.previousTrackCommand = MPRemoteCommandCenter.shared().previousTrackCommand.addTarget { event in
  280. self.backward()
  281. return .success
  282. }
  283. }
  284. */
  285. nowPlayingInfo[MPMediaItemPropertyTitle] = metadata.fileNameView
  286. nowPlayingInfo[MPMediaItemPropertyPlaybackDuration] = ncplayer.durationTime.seconds
  287. if let image = currentViewController.image {
  288. nowPlayingInfo[MPMediaItemPropertyArtwork] = MPMediaItemArtwork(boundsSize: image.size) { _ in
  289. return image
  290. }
  291. }
  292. MPNowPlayingInfoCenter.default().nowPlayingInfo = nowPlayingInfo
  293. }
  294. func clearCommandCenter() {
  295. UIApplication.shared.endReceivingRemoteControlEvents()
  296. MPNowPlayingInfoCenter.default().nowPlayingInfo = [:]
  297. MPRemoteCommandCenter.shared().playCommand.isEnabled = false
  298. MPRemoteCommandCenter.shared().pauseCommand.isEnabled = false
  299. MPRemoteCommandCenter.shared().skipForwardCommand.isEnabled = false
  300. MPRemoteCommandCenter.shared().skipBackwardCommand.isEnabled = false
  301. MPRemoteCommandCenter.shared().nextTrackCommand.isEnabled = false
  302. MPRemoteCommandCenter.shared().previousTrackCommand.isEnabled = false
  303. if let playCommand = playCommand {
  304. MPRemoteCommandCenter.shared().playCommand.removeTarget(playCommand)
  305. self.playCommand = nil
  306. }
  307. if let pauseCommand = pauseCommand {
  308. MPRemoteCommandCenter.shared().pauseCommand.removeTarget(pauseCommand)
  309. self.pauseCommand = nil
  310. }
  311. if let skipForwardCommand = skipForwardCommand {
  312. MPRemoteCommandCenter.shared().skipForwardCommand.removeTarget(skipForwardCommand)
  313. self.skipForwardCommand = nil
  314. }
  315. if let skipBackwardCommand = skipBackwardCommand {
  316. MPRemoteCommandCenter.shared().skipBackwardCommand.removeTarget(skipBackwardCommand)
  317. self.skipBackwardCommand = nil
  318. }
  319. if let nextTrackCommand = nextTrackCommand {
  320. MPRemoteCommandCenter.shared().nextTrackCommand.removeTarget(nextTrackCommand)
  321. self.nextTrackCommand = nil
  322. }
  323. if let previousTrackCommand = previousTrackCommand {
  324. MPRemoteCommandCenter.shared().previousTrackCommand.removeTarget(previousTrackCommand)
  325. self.previousTrackCommand = nil
  326. }
  327. }
  328. }
  329. // MARK: - UIPageViewController Delegate Datasource
  330. extension NCViewerMediaPage: UIPageViewControllerDelegate, UIPageViewControllerDataSource {
  331. func shiftCurrentPage() {
  332. if metadatas.count == 0 {
  333. self.viewUnload()
  334. return
  335. }
  336. var direction: UIPageViewController.NavigationDirection = .forward
  337. if currentIndex == metadatas.count {
  338. currentIndex -= 1
  339. direction = .reverse
  340. }
  341. currentViewController.ncplayer?.deactivateObserver()
  342. let viewerMedia = getViewerMedia(index: currentIndex, metadata: metadatas[currentIndex])
  343. pageViewController.setViewControllers([viewerMedia], direction: direction, animated: true, completion: nil)
  344. }
  345. func reloadCurrentPage() {
  346. currentViewController.ncplayer?.deactivateObserver()
  347. let viewerMedia = getViewerMedia(index: currentIndex, metadata: metadatas[currentIndex])
  348. viewerMedia.autoPlay = false
  349. pageViewController.setViewControllers([viewerMedia], direction: .forward, animated: false, completion: nil)
  350. }
  351. func goTo(index: Int, direction: UIPageViewController.NavigationDirection, autoPlay: Bool) {
  352. currentIndex = index
  353. currentViewController.ncplayer?.deactivateObserver()
  354. let viewerMedia = getViewerMedia(index: currentIndex, metadata: metadatas[currentIndex])
  355. viewerMedia.autoPlay = autoPlay
  356. pageViewController.setViewControllers([viewerMedia], direction: direction, animated: true, completion: nil)
  357. }
  358. func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
  359. if currentIndex == 0 { return nil }
  360. let viewerMedia = getViewerMedia(index: currentIndex-1, metadata: metadatas[currentIndex-1])
  361. return viewerMedia
  362. }
  363. func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
  364. if currentIndex == metadatas.count-1 { return nil }
  365. let viewerMedia = getViewerMedia(index: currentIndex+1, metadata: metadatas[currentIndex+1])
  366. return viewerMedia
  367. }
  368. // START TRANSITION
  369. func pageViewController(_ pageViewController: UIPageViewController, willTransitionTo pendingViewControllers: [UIViewController]) {
  370. // Save time video
  371. if let ncplayer = currentViewController.ncplayer, ncplayer.isPlay() {
  372. ncplayer.saveCurrentTime()
  373. }
  374. guard let nextViewController = pendingViewControllers.first as? NCViewerMedia else { return }
  375. nextIndex = nextViewController.index
  376. }
  377. // END TRANSITION
  378. func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
  379. if completed && nextIndex != nil {
  380. previousViewControllers.forEach { viewController in
  381. let viewerMedia = viewController as! NCViewerMedia
  382. viewerMedia.ncplayer?.deactivateObserver()
  383. }
  384. currentIndex = nextIndex!
  385. }
  386. self.nextIndex = nil
  387. }
  388. }
  389. // MARK: - UIGestureRecognizerDelegate
  390. extension NCViewerMediaPage: UIGestureRecognizerDelegate {
  391. func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
  392. if let gestureRecognizer = gestureRecognizer as? UIPanGestureRecognizer {
  393. let velocity = gestureRecognizer.velocity(in: self.view)
  394. var velocityCheck: Bool = false
  395. if UIDevice.current.orientation.isLandscape {
  396. velocityCheck = velocity.x < 0
  397. } else {
  398. velocityCheck = velocity.y < 0
  399. }
  400. if velocityCheck {
  401. return false
  402. }
  403. }
  404. return true
  405. }
  406. func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
  407. if otherGestureRecognizer == currentViewController.scrollView.panGestureRecognizer {
  408. if self.currentViewController.scrollView.contentOffset.y == 0 {
  409. return true
  410. }
  411. }
  412. return false
  413. }
  414. @objc func didPanWith(gestureRecognizer: UIPanGestureRecognizer) {
  415. currentViewController.didPanWith(gestureRecognizer: gestureRecognizer)
  416. }
  417. @objc func didSingleTapWith(gestureRecognizer: UITapGestureRecognizer) {
  418. if let playerToolBar = currentViewController.playerToolBar, playerToolBar.isPictureInPictureActive() {
  419. playerToolBar.pictureInPictureController?.stopPictureInPicture()
  420. }
  421. if currentScreenMode == .full {
  422. changeScreenMode(mode: .normal, enableTimerAutoHide: true)
  423. } else {
  424. changeScreenMode(mode: .full)
  425. }
  426. }
  427. //
  428. // LIVE PHOTO
  429. //
  430. @objc func didLongpressGestureEvent(gestureRecognizer: UITapGestureRecognizer) {
  431. if !currentViewController.metadata.livePhoto { return }
  432. if gestureRecognizer.state == .began {
  433. currentViewController.updateViewConstraints()
  434. currentViewController.statusViewImage.isHidden = true
  435. currentViewController.statusLabel.isHidden = true
  436. let fileName = (currentViewController.metadata.fileNameView as NSString).deletingPathExtension + ".mov"
  437. if let metadata = NCManageDatabase.shared.getMetadata(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileNameView LIKE[c] %@", currentViewController.metadata.account, currentViewController.metadata.serverUrl, fileName)), CCUtility.fileProviderStorageExists(metadata) {
  438. AudioServicesPlaySystemSound(1519) // peek feedback
  439. if let url = NCKTVHTTPCache.shared.getVideoURL(metadata: metadata) {
  440. self.ncplayerLivePhoto = NCPlayer.init(url: url, autoPlay: true, imageVideoContainer: self.currentViewController.imageVideoContainer, playerToolBar: nil, metadata: metadata, detailView: nil, viewController: self)
  441. }
  442. }
  443. } else if gestureRecognizer.state == .ended {
  444. currentViewController.statusViewImage.isHidden = false
  445. currentViewController.statusLabel.isHidden = false
  446. currentViewController.imageVideoContainer.image = currentViewController.image
  447. ncplayerLivePhoto?.videoLayer?.removeFromSuperlayer()
  448. ncplayerLivePhoto?.deactivateObserver()
  449. }
  450. }
  451. }