NCViewerMediaPage.swift 23 KB

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