NCViewerMediaPage.swift 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  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 NextcloudKit
  25. import MediaPlayer
  26. import JGProgressHUD
  27. import Alamofire
  28. class NCViewerMediaPage: UIViewController {
  29. @IBOutlet weak var progressView: UIProgressView!
  30. enum ScreenMode {
  31. case full, normal
  32. }
  33. var currentScreenMode: ScreenMode = .normal
  34. var saveScreenModeImage: ScreenMode = .normal
  35. var pageViewController: UIPageViewController {
  36. return self.children[0] as! UIPageViewController
  37. }
  38. var currentViewController: NCViewerMedia {
  39. return self.pageViewController.viewControllers![0] as! NCViewerMedia
  40. }
  41. private var hideStatusBar: Bool = false {
  42. didSet {
  43. setNeedsStatusBarAppearanceUpdate()
  44. }
  45. }
  46. var metadatas: [tableMetadata] = []
  47. var modifiedOcId: [String] = []
  48. var currentIndex = 0
  49. var nextIndex: Int?
  50. var panGestureRecognizer: UIPanGestureRecognizer!
  51. var singleTapGestureRecognizer: UITapGestureRecognizer!
  52. var longtapGestureRecognizer: UILongPressGestureRecognizer!
  53. var textColor: UIColor = .label
  54. var playCommand: Any?
  55. var pauseCommand: Any?
  56. var skipForwardCommand: Any?
  57. var skipBackwardCommand: Any?
  58. var nextTrackCommand: Any?
  59. var previousTrackCommand: Any?
  60. // MARK: - View Life Cycle
  61. override func viewDidLoad() {
  62. super.viewDidLoad()
  63. navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(named: "more")!.image(color: .label, size: 25), style: .plain, target: self, action: #selector(self.openMenuMore))
  64. singleTapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(didSingleTapWith(gestureRecognizer:)))
  65. panGestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(didPanWith(gestureRecognizer:)))
  66. longtapGestureRecognizer = UILongPressGestureRecognizer()
  67. longtapGestureRecognizer.delaysTouchesBegan = true
  68. longtapGestureRecognizer.minimumPressDuration = 0.3
  69. longtapGestureRecognizer.delegate = self
  70. longtapGestureRecognizer.addTarget(self, action: #selector(didLongpressGestureEvent(gestureRecognizer:)))
  71. pageViewController.delegate = self
  72. pageViewController.dataSource = self
  73. pageViewController.view.addGestureRecognizer(panGestureRecognizer)
  74. pageViewController.view.addGestureRecognizer(singleTapGestureRecognizer)
  75. pageViewController.view.addGestureRecognizer(longtapGestureRecognizer)
  76. let viewerMedia = getViewerMedia(index: currentIndex, metadata: metadatas[currentIndex])
  77. pageViewController.setViewControllers([viewerMedia], direction: .forward, animated: true, completion: nil)
  78. NotificationCenter.default.addObserver(self, selector: #selector(viewUnload), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMenuDetailClose), object: nil)
  79. progressView.tintColor = NCBrandColor.shared.brandElement
  80. progressView.trackTintColor = .clear
  81. progressView.progress = 0
  82. NotificationCenter.default.addObserver(self, selector: #selector(deleteFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterDeleteFile), object: nil)
  83. NotificationCenter.default.addObserver(self, selector: #selector(renameFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterRenameFile), object: nil)
  84. NotificationCenter.default.addObserver(self, selector: #selector(moveFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMoveFile), object: nil)
  85. NotificationCenter.default.addObserver(self, selector: #selector(downloadedFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterDownloadedFile), object: nil)
  86. NotificationCenter.default.addObserver(self, selector: #selector(triggerProgressTask(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterProgressTask), object: nil)
  87. NotificationCenter.default.addObserver(self, selector: #selector(uploadStartFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterUploadStartFile), object: nil)
  88. NotificationCenter.default.addObserver(self, selector: #selector(uploadedFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterUploadedFile), object: nil)
  89. NotificationCenter.default.addObserver(self, selector: #selector(applicationDidBecomeActive(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterApplicationDidBecomeActive), object: nil)
  90. }
  91. deinit {
  92. NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterDeleteFile), object: nil)
  93. NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterRenameFile), object: nil)
  94. NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMoveFile), object: nil)
  95. NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterDownloadedFile), object: nil)
  96. NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterProgressTask), object: nil)
  97. NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterUploadStartFile), object: nil)
  98. NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterUploadedFile), object: nil)
  99. NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterApplicationDidBecomeActive), object: nil)
  100. }
  101. override func viewDidDisappear(_ animated: Bool) {
  102. super.viewDidDisappear(animated)
  103. if let ncplayer = currentViewController.ncplayer, ncplayer.isPlay() {
  104. ncplayer.playerPause()
  105. }
  106. currentViewController.playerToolBar?.stopTimerAutoHide()
  107. clearCommandCenter()
  108. }
  109. override var preferredStatusBarStyle: UIStatusBarStyle {
  110. if currentScreenMode == .normal {
  111. return .default
  112. } else {
  113. return .lightContent
  114. }
  115. }
  116. override var prefersHomeIndicatorAutoHidden: Bool {
  117. return currentScreenMode == .full
  118. }
  119. override var prefersStatusBarHidden: Bool {
  120. return hideStatusBar
  121. }
  122. // MARK: -
  123. func getViewerMedia(index: Int, metadata: tableMetadata) -> NCViewerMedia {
  124. let viewerMedia = UIStoryboard(name: "NCViewerMediaPage", bundle: nil).instantiateViewController(withIdentifier: "NCViewerMedia") as! NCViewerMedia
  125. viewerMedia.index = index
  126. viewerMedia.metadata = metadata
  127. viewerMedia.viewerMediaPage = self
  128. singleTapGestureRecognizer.require(toFail: viewerMedia.doubleTapGestureRecognizer)
  129. return viewerMedia
  130. }
  131. @objc func viewUnload() {
  132. navigationController?.popViewController(animated: true)
  133. }
  134. @objc func openMenuMore() {
  135. let imageIcon = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(currentViewController.metadata.ocId, etag: currentViewController.metadata.etag))
  136. NCViewer.shared.toggleMenu(viewController: self, metadata: currentViewController.metadata, webView: false, imageIcon: imageIcon)
  137. }
  138. func changeScreenMode(mode: ScreenMode, toggleToolbar: Bool) {
  139. if mode == .normal {
  140. navigationController?.setNavigationBarHidden(false, animated: true)
  141. hideStatusBar = false
  142. progressView.isHidden = false
  143. if toggleToolbar && (metadatas[currentIndex].classFile == NKCommon.TypeClassFile.video.rawValue || metadatas[currentIndex].classFile == NKCommon.TypeClassFile.audio.rawValue) {
  144. currentViewController.playerToolBar?.show()
  145. }
  146. NCUtility.shared.colorNavigationController(navigationController, backgroundColor: .systemBackground, titleColor: .label, tintColor: nil, withoutShadow: false)
  147. view.backgroundColor = .systemBackground
  148. textColor = .label
  149. } else {
  150. navigationController?.setNavigationBarHidden(true, animated: true)
  151. hideStatusBar = true
  152. progressView.isHidden = true
  153. if toggleToolbar && (metadatas[currentIndex].classFile == NKCommon.TypeClassFile.video.rawValue || metadatas[currentIndex].classFile == NKCommon.TypeClassFile.audio.rawValue) {
  154. currentViewController.playerToolBar?.hide()
  155. }
  156. view.backgroundColor = .black
  157. textColor = .white
  158. }
  159. currentScreenMode = mode
  160. if currentViewController.metadata.classFile == NKCommon.TypeClassFile.image.rawValue {
  161. saveScreenModeImage = mode
  162. }
  163. setNeedsStatusBarAppearanceUpdate()
  164. setNeedsUpdateOfHomeIndicatorAutoHidden()
  165. currentViewController.reloadDetail()
  166. }
  167. // MARK: - NotificationCenter
  168. @objc func downloadedFile(_ notification: NSNotification) {
  169. guard let userInfo = notification.userInfo as NSDictionary?,
  170. let ocId = userInfo["ocId"] as? String
  171. else {
  172. return
  173. }
  174. progressView.progress = 0
  175. let metadata = metadatas[currentIndex]
  176. if metadata.ocId == ocId,
  177. (metadata.classFile == NKCommon.TypeClassFile.video.rawValue || metadata.classFile == NKCommon.TypeClassFile.audio.rawValue),
  178. CCUtility.fileProviderStorageExists(metadata),
  179. let ncplayer = currentViewController.ncplayer {
  180. let url = URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!)
  181. if ncplayer.isPlay() {
  182. ncplayer.playerPause()
  183. DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
  184. ncplayer.openAVPlayer(url: url)
  185. ncplayer.playerPlay()
  186. }
  187. } else {
  188. ncplayer.openAVPlayer(url: url)
  189. }
  190. }
  191. }
  192. @objc func triggerProgressTask(_ notification: NSNotification) {
  193. guard let userInfo = notification.userInfo as NSDictionary?,
  194. let progressNumber = userInfo["progress"] as? NSNumber
  195. else { return }
  196. let progress = progressNumber.floatValue
  197. if progress == 1 {
  198. self.progressView.progress = 0
  199. } else {
  200. self.progressView.progress = progress
  201. }
  202. }
  203. @objc func uploadStartFile(_ notification: NSNotification) {
  204. /*
  205. guard let userInfo = notification.userInfo as NSDictionary?,
  206. let serverUrl = userInfo["serverUrl"] as? String,
  207. let fileName = userInfo["fileName"] as? String,
  208. let sessionSelector = userInfo["sessionSelector"] as? String
  209. else { return }
  210. */
  211. }
  212. @objc func uploadedFile(_ notification: NSNotification) {
  213. guard let userInfo = notification.userInfo as NSDictionary?,
  214. let ocId = userInfo["ocId"] as? String,
  215. let error = userInfo["error"] as? NKError,
  216. error == .success,
  217. let index = metadatas.firstIndex(where: {$0.ocId == ocId}),
  218. let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId)
  219. else {
  220. return
  221. }
  222. metadatas[index] = metadata
  223. if currentViewController.metadata.ocId == ocId {
  224. currentViewController.reloadImage()
  225. } else {
  226. modifiedOcId.append(ocId)
  227. }
  228. }
  229. @objc func deleteFile(_ notification: NSNotification) {
  230. guard let userInfo = notification.userInfo as NSDictionary?,
  231. let ocId = userInfo["ocId"] as? String
  232. else { return }
  233. // Stop media
  234. if let ncplayer = currentViewController.ncplayer, ncplayer.isPlay() {
  235. ncplayer.playerPause()
  236. }
  237. let metadatas = self.metadatas.filter { $0.ocId != ocId }
  238. if self.metadatas.count == metadatas.count { return }
  239. self.metadatas = metadatas
  240. if ocId == currentViewController.metadata.ocId {
  241. shiftCurrentPage()
  242. }
  243. }
  244. @objc func renameFile(_ notification: NSNotification) {
  245. guard let userInfo = notification.userInfo as NSDictionary?,
  246. let ocId = userInfo["ocId"] as? String,
  247. let index = metadatas.firstIndex(where: {$0.ocId == ocId}),
  248. let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId)
  249. else { return }
  250. // Stop media
  251. if let ncplayer = currentViewController.ncplayer, ncplayer.isPlay() {
  252. ncplayer.playerPause()
  253. }
  254. metadatas[index] = metadata
  255. if index == currentIndex {
  256. navigationItem.title = metadata.fileNameView
  257. currentViewController.metadata = metadata
  258. self.currentViewController.metadata = metadata
  259. }
  260. }
  261. @objc func moveFile(_ notification: NSNotification) {
  262. guard let userInfo = notification.userInfo as NSDictionary?,
  263. let ocId = userInfo["ocId"] as? String
  264. else { return }
  265. // Stop media
  266. if let ncplayer = currentViewController.ncplayer, ncplayer.isPlay() {
  267. ncplayer.playerPause()
  268. }
  269. if metadatas.firstIndex(where: {$0.ocId == ocId}) != nil {
  270. deleteFile(notification)
  271. }
  272. }
  273. @objc func applicationDidBecomeActive(_ notification: NSNotification) {
  274. progressView.progress = 0
  275. }
  276. // MARK: - Command Center
  277. func updateCommandCenter(ncplayer: NCPlayer, metadata: tableMetadata) {
  278. var nowPlayingInfo = [String: Any]()
  279. // Clear
  280. clearCommandCenter()
  281. UIApplication.shared.beginReceivingRemoteControlEvents()
  282. // Add handler for Play Command
  283. MPRemoteCommandCenter.shared().playCommand.isEnabled = true
  284. playCommand = MPRemoteCommandCenter.shared().playCommand.addTarget { _ in
  285. if !ncplayer.isPlay() {
  286. ncplayer.playerPlay()
  287. return .success
  288. }
  289. return .commandFailed
  290. }
  291. // Add handler for Pause Command
  292. MPRemoteCommandCenter.shared().pauseCommand.isEnabled = true
  293. pauseCommand = MPRemoteCommandCenter.shared().pauseCommand.addTarget { _ in
  294. if ncplayer.isPlay() {
  295. ncplayer.playerPause()
  296. return .success
  297. }
  298. return .commandFailed
  299. }
  300. // VIDEO / AUDIO () ()
  301. if metadata.classFile == NKCommon.TypeClassFile.video.rawValue || metadata.classFile == NKCommon.TypeClassFile.audio.rawValue {
  302. MPRemoteCommandCenter.shared().skipForwardCommand.isEnabled = true
  303. skipForwardCommand = MPRemoteCommandCenter.shared().skipForwardCommand.addTarget { event in
  304. let seconds = Int32((event as! MPSkipIntervalCommandEvent).interval)
  305. ncplayer.player?.jumpForward(seconds)
  306. return.success
  307. }
  308. MPRemoteCommandCenter.shared().skipBackwardCommand.isEnabled = true
  309. skipBackwardCommand = MPRemoteCommandCenter.shared().skipBackwardCommand.addTarget { event in
  310. let seconds = Int32((event as! MPSkipIntervalCommandEvent).interval)
  311. ncplayer.player?.jumpBackward(seconds)
  312. return.success
  313. }
  314. }
  315. nowPlayingInfo[MPMediaItemPropertyTitle] = metadata.fileNameView
  316. if let image = currentViewController.image {
  317. nowPlayingInfo[MPMediaItemPropertyArtwork] = MPMediaItemArtwork(boundsSize: image.size) { _ in
  318. return image
  319. }
  320. }
  321. MPNowPlayingInfoCenter.default().nowPlayingInfo = nowPlayingInfo
  322. }
  323. func clearCommandCenter() {
  324. UIApplication.shared.endReceivingRemoteControlEvents()
  325. MPNowPlayingInfoCenter.default().nowPlayingInfo = [:]
  326. MPRemoteCommandCenter.shared().playCommand.isEnabled = false
  327. MPRemoteCommandCenter.shared().pauseCommand.isEnabled = false
  328. MPRemoteCommandCenter.shared().skipForwardCommand.isEnabled = false
  329. MPRemoteCommandCenter.shared().skipBackwardCommand.isEnabled = false
  330. MPRemoteCommandCenter.shared().nextTrackCommand.isEnabled = false
  331. MPRemoteCommandCenter.shared().previousTrackCommand.isEnabled = false
  332. if let playCommand = playCommand {
  333. MPRemoteCommandCenter.shared().playCommand.removeTarget(playCommand)
  334. self.playCommand = nil
  335. }
  336. if let pauseCommand = pauseCommand {
  337. MPRemoteCommandCenter.shared().pauseCommand.removeTarget(pauseCommand)
  338. self.pauseCommand = nil
  339. }
  340. if let skipForwardCommand = skipForwardCommand {
  341. MPRemoteCommandCenter.shared().skipForwardCommand.removeTarget(skipForwardCommand)
  342. self.skipForwardCommand = nil
  343. }
  344. if let skipBackwardCommand = skipBackwardCommand {
  345. MPRemoteCommandCenter.shared().skipBackwardCommand.removeTarget(skipBackwardCommand)
  346. self.skipBackwardCommand = nil
  347. }
  348. if let nextTrackCommand = nextTrackCommand {
  349. MPRemoteCommandCenter.shared().nextTrackCommand.removeTarget(nextTrackCommand)
  350. self.nextTrackCommand = nil
  351. }
  352. if let previousTrackCommand = previousTrackCommand {
  353. MPRemoteCommandCenter.shared().previousTrackCommand.removeTarget(previousTrackCommand)
  354. self.previousTrackCommand = nil
  355. }
  356. }
  357. }
  358. // MARK: - UIPageViewController Delegate Datasource
  359. extension NCViewerMediaPage: UIPageViewControllerDelegate, UIPageViewControllerDataSource {
  360. func shiftCurrentPage() {
  361. if metadatas.count == 0 {
  362. self.viewUnload()
  363. return
  364. }
  365. var direction: UIPageViewController.NavigationDirection = .forward
  366. if currentIndex == metadatas.count {
  367. currentIndex -= 1
  368. direction = .reverse
  369. }
  370. let viewerMedia = getViewerMedia(index: currentIndex, metadata: metadatas[currentIndex])
  371. pageViewController.setViewControllers([viewerMedia], direction: direction, animated: true, completion: nil)
  372. }
  373. func reloadCurrentPage() {
  374. let viewerMedia = getViewerMedia(index: currentIndex, metadata: metadatas[currentIndex])
  375. pageViewController.setViewControllers([viewerMedia], direction: .forward, animated: false, completion: nil)
  376. }
  377. func goTo(index: Int, direction: UIPageViewController.NavigationDirection, autoPlay: Bool) {
  378. currentIndex = index
  379. let viewerMedia = getViewerMedia(index: currentIndex, metadata: metadatas[currentIndex])
  380. pageViewController.setViewControllers([viewerMedia], direction: direction, animated: true, completion: nil)
  381. }
  382. func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
  383. if currentIndex == 0 { return nil }
  384. let viewerMedia = getViewerMedia(index: currentIndex - 1, metadata: metadatas[currentIndex - 1])
  385. return viewerMedia
  386. }
  387. func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
  388. if currentIndex == metadatas.count - 1 { return nil }
  389. let viewerMedia = getViewerMedia(index: currentIndex + 1, metadata: metadatas[currentIndex + 1])
  390. return viewerMedia
  391. }
  392. // START TRANSITION
  393. func pageViewController(_ pageViewController: UIPageViewController, willTransitionTo pendingViewControllers: [UIViewController]) {
  394. guard let nextViewController = pendingViewControllers.first as? NCViewerMedia else { return }
  395. nextIndex = nextViewController.index
  396. }
  397. // END TRANSITION
  398. func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
  399. if completed && nextIndex != nil {
  400. previousViewControllers.forEach { viewController in
  401. let viewerMedia = viewController as! NCViewerMedia
  402. viewerMedia.ncplayer?.playerStop()
  403. }
  404. currentIndex = nextIndex!
  405. }
  406. self.nextIndex = nil
  407. }
  408. }
  409. // MARK: - UIGestureRecognizerDelegate
  410. extension NCViewerMediaPage: UIGestureRecognizerDelegate {
  411. func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
  412. if let gestureRecognizer = gestureRecognizer as? UIPanGestureRecognizer {
  413. let velocity = gestureRecognizer.velocity(in: self.view)
  414. var velocityCheck: Bool = false
  415. if UIDevice.current.orientation.isLandscape {
  416. velocityCheck = velocity.x < 0
  417. } else {
  418. velocityCheck = velocity.y < 0
  419. }
  420. if velocityCheck {
  421. return false
  422. }
  423. }
  424. return true
  425. }
  426. func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
  427. if otherGestureRecognizer == currentViewController.scrollView.panGestureRecognizer {
  428. if self.currentViewController.scrollView.contentOffset.y == 0 {
  429. return true
  430. }
  431. }
  432. return false
  433. }
  434. @objc func didPanWith(gestureRecognizer: UIPanGestureRecognizer) {
  435. currentViewController.didPanWith(gestureRecognizer: gestureRecognizer)
  436. }
  437. @objc func didSingleTapWith(gestureRecognizer: UITapGestureRecognizer) {
  438. if currentScreenMode == .full {
  439. changeScreenMode(mode: .normal, toggleToolbar: true)
  440. } else {
  441. changeScreenMode(mode: .full, toggleToolbar: true)
  442. }
  443. }
  444. //
  445. // LIVE PHOTO
  446. //
  447. @objc func didLongpressGestureEvent(gestureRecognizer: UITapGestureRecognizer) {
  448. if !currentViewController.metadata.livePhoto { return }
  449. if gestureRecognizer.state == .began {
  450. let fileName = (currentViewController.metadata.fileNameView as NSString).deletingPathExtension + ".mov"
  451. 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) {
  452. AudioServicesPlaySystemSound(1519) // peek feedback
  453. currentViewController.playLivePhoto(filePath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!)
  454. }
  455. } else if gestureRecognizer.state == .ended {
  456. currentViewController.stopLivePhoto()
  457. }
  458. }
  459. }