NCViewerMedia.swift 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. //
  2. // NCViewerMedia.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 SVGKit
  25. import NCCommunication
  26. class NCViewerMedia: UIViewController {
  27. @IBOutlet weak var detailViewTopConstraint: NSLayoutConstraint!
  28. @IBOutlet weak var detailViewHeighConstraint: NSLayoutConstraint!
  29. @IBOutlet weak var imageViewTopConstraint: NSLayoutConstraint!
  30. @IBOutlet weak var imageViewBottomConstraint: NSLayoutConstraint!
  31. @IBOutlet weak var scrollView: UIScrollView!
  32. @IBOutlet weak var imageVideoContainer: imageVideoContainerView!
  33. @IBOutlet weak var statusViewImage: UIImageView!
  34. @IBOutlet weak var statusLabel: UILabel!
  35. @IBOutlet weak var detailView: NCViewerMediaDetailView!
  36. @IBOutlet weak var playerToolBar: NCPlayerToolBar!
  37. private var _autoPlay: Bool = false
  38. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  39. weak var viewerMediaPage: NCViewerMediaPage?
  40. var ncplayer: NCPlayer?
  41. var image: UIImage?
  42. var metadata: tableMetadata = tableMetadata()
  43. var index: Int = 0
  44. var doubleTapGestureRecognizer: UITapGestureRecognizer = UITapGestureRecognizer()
  45. var imageViewConstraint: CGFloat = 0
  46. var isDetailViewInitializze: Bool = false
  47. var autoPlay: Bool {
  48. get {
  49. let temp = _autoPlay
  50. _autoPlay = false
  51. return temp
  52. }
  53. set(newVal) {
  54. _autoPlay = newVal
  55. }
  56. }
  57. // MARK: - View Life Cycle
  58. required init?(coder aDecoder: NSCoder) {
  59. super.init(coder: aDecoder)
  60. doubleTapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(didDoubleTapWith(gestureRecognizer:)))
  61. doubleTapGestureRecognizer.numberOfTapsRequired = 2
  62. }
  63. deinit {
  64. print("deinit NCViewerMedia")
  65. NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterOpenMediaDetail), object: nil)
  66. }
  67. override func viewDidLoad() {
  68. super.viewDidLoad()
  69. scrollView.delegate = self
  70. scrollView.maximumZoomScale = 4
  71. scrollView.minimumZoomScale = 1
  72. view.addGestureRecognizer(doubleTapGestureRecognizer)
  73. if NCManageDatabase.shared.getMetadataLivePhoto(metadata: metadata) != nil {
  74. statusViewImage.image = NCUtility.shared.loadImage(named: "livephoto", color: .gray)
  75. statusLabel.text = "LIVE"
  76. } else {
  77. statusViewImage.image = nil
  78. statusLabel.text = ""
  79. }
  80. playerToolBar.viewerMediaPage = viewerMediaPage
  81. detailViewTopConstraint.constant = 0
  82. detailView.hide()
  83. self.image = nil
  84. self.imageVideoContainer.image = nil
  85. reloadImage()
  86. }
  87. override func viewWillAppear(_ animated: Bool) {
  88. super.viewWillAppear(animated)
  89. viewerMediaPage?.navigationController?.navigationBar.prefersLargeTitles = false
  90. viewerMediaPage?.navigationItem.title = metadata.fileNameView
  91. if metadata.classFile == NCCommunicationCommon.typeClassFile.image.rawValue, let viewerMediaPage = self.viewerMediaPage {
  92. viewerMediaPage.currentScreenMode = viewerMediaPage.saveScreenModeImage
  93. if viewerMediaPage.modifiedOcId.contains(metadata.ocId) {
  94. viewerMediaPage.modifiedOcId.removeAll(where: { $0 == metadata.ocId })
  95. reloadImage()
  96. }
  97. }
  98. if viewerMediaPage?.currentScreenMode == .full {
  99. viewerMediaPage?.navigationController?.setNavigationBarHidden(true, animated: true)
  100. NCUtility.shared.colorNavigationController(viewerMediaPage?.navigationController, backgroundColor: .black, titleColor: .white, tintColor: nil, withoutShadow: false)
  101. viewerMediaPage?.view.backgroundColor = .black
  102. viewerMediaPage?.textColor = .white
  103. viewerMediaPage?.progressView.isHidden = true
  104. } else {
  105. viewerMediaPage?.navigationController?.setNavigationBarHidden(false, animated: true)
  106. NCUtility.shared.colorNavigationController(viewerMediaPage?.navigationController, backgroundColor: NCBrandColor.shared.systemBackground, titleColor: NCBrandColor.shared.label, tintColor: nil, withoutShadow: false)
  107. viewerMediaPage?.view.backgroundColor = NCBrandColor.shared.systemBackground
  108. viewerMediaPage?.textColor = NCBrandColor.shared.label
  109. viewerMediaPage?.progressView.isHidden = false
  110. }
  111. }
  112. override func viewDidAppear(_ animated: Bool) {
  113. super.viewDidAppear(animated)
  114. if metadata.classFile == NCCommunicationCommon.typeClassFile.video.rawValue || metadata.classFile == NCCommunicationCommon.typeClassFile.audio.rawValue {
  115. NCKTVHTTPCache.shared.restartProxy(user: appDelegate.user, password: appDelegate.password)
  116. if ncplayer == nil, let url = NCKTVHTTPCache.shared.getVideoURL(metadata: metadata) {
  117. self.ncplayer = NCPlayer.init(url: url, autoPlay: self.autoPlay, imageVideoContainer: self.imageVideoContainer, playerToolBar: self.playerToolBar, metadata: self.metadata, detailView: self.detailView, viewController: self)
  118. } else {
  119. self.ncplayer?.activateObserver(playerToolBar: self.playerToolBar)
  120. if detailView.isShow() == false && ncplayer?.isPlay() == false {
  121. NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterShowPlayerToolBar, userInfo: ["ocId": metadata.ocId, "enableTimerAutoHide": false])
  122. }
  123. }
  124. if let ncplayer = self.ncplayer {
  125. self.viewerMediaPage?.updateCommandCenter(ncplayer: ncplayer, metadata: self.metadata)
  126. }
  127. #if MFFFLIB
  128. MFFF.shared.setDelegate = self.ncplayer
  129. #endif
  130. } else if metadata.classFile == NCCommunicationCommon.typeClassFile.image.rawValue {
  131. viewerMediaPage?.clearCommandCenter()
  132. }
  133. NotificationCenter.default.addObserver(self, selector: #selector(openDetail(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterOpenMediaDetail), object: nil)
  134. }
  135. override func viewDidDisappear(_ animated: Bool) {
  136. super.viewDidDisappear(animated)
  137. }
  138. override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
  139. super.viewWillTransition(to: size, with: coordinator)
  140. coordinator.animate(alongsideTransition: { context in
  141. // back to the original size
  142. self.scrollView.zoom(to: CGRect(x: 0, y: 0, width: self.scrollView.bounds.width, height: self.scrollView.bounds.height), animated: false)
  143. self.view.layoutIfNeeded()
  144. UIView.animate(withDuration: context.transitionDuration) {
  145. if self.detailView.isShow() {
  146. self.openDetail()
  147. }
  148. }
  149. }) { _ in }
  150. }
  151. // MARK: - Image
  152. func reloadImage() {
  153. loadImage(metadata: metadata) { _, image in
  154. self.image = image
  155. // do not update if is present the videoLayer
  156. let numSublayers = self.imageVideoContainer.layer.sublayers?.count
  157. if numSublayers == nil {
  158. self.imageVideoContainer.image = image
  159. }
  160. }
  161. }
  162. func loadImage(metadata: tableMetadata, completion: @escaping (_ ocId: String, _ image: UIImage?) -> Void) {
  163. // Download preview
  164. if metadata.hasPreview && !CCUtility.fileProviderStoragePreviewIconExists(metadata.ocId, etag: metadata.etag) {
  165. var etagResource: String?
  166. let fileNamePath = CCUtility.returnFileNamePath(fromFileName: metadata.fileName, serverUrl: metadata.serverUrl, urlBase: metadata.urlBase, account: metadata.account)!
  167. let fileNamePreviewLocalPath = CCUtility.getDirectoryProviderStoragePreviewOcId(metadata.ocId, etag: metadata.etag)!
  168. let fileNameIconLocalPath = CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag)!
  169. if FileManager.default.fileExists(atPath: fileNameIconLocalPath) && FileManager.default.fileExists(atPath: fileNamePreviewLocalPath) {
  170. etagResource = metadata.etagResource
  171. }
  172. NCCommunication.shared.downloadPreview(
  173. fileNamePathOrFileId: fileNamePath,
  174. fileNamePreviewLocalPath: fileNamePreviewLocalPath,
  175. widthPreview: NCGlobal.shared.sizePreview,
  176. heightPreview: NCGlobal.shared.sizePreview,
  177. fileNameIconLocalPath: fileNameIconLocalPath,
  178. sizeIcon: NCGlobal.shared.sizeIcon, etag: etagResource,
  179. queue: NCCommunicationCommon.shared.backgroundQueue) { _, _, imageIcon, _, etag, errorCode, _ in
  180. if errorCode == 0 && imageIcon != nil {
  181. NCManageDatabase.shared.setMetadataEtagResource(ocId: metadata.ocId, etagResource: etag)
  182. }
  183. // Download file max resolution
  184. downloadFile(metadata: metadata)
  185. // Download file live photo
  186. if metadata.livePhoto { downloadFileLivePhoto(metadata: metadata) }
  187. }
  188. } else {
  189. // Download file max resolution
  190. downloadFile(metadata: metadata)
  191. // Download file live photo
  192. if metadata.livePhoto { downloadFileLivePhoto(metadata: metadata) }
  193. }
  194. // Download file max resolution
  195. func downloadFile(metadata: tableMetadata) {
  196. let isFolderEncrypted = CCUtility.isFolderEncrypted(metadata.serverUrl, e2eEncrypted: metadata.e2eEncrypted, account: metadata.account, urlBase: metadata.urlBase)
  197. let ext = CCUtility.getExtension(metadata.fileNameView)
  198. if (CCUtility.getAutomaticDownloadImage() || (metadata.contentType == "image/heic" && metadata.hasPreview == false) || ext == "GIF" || ext == "SVG" || isFolderEncrypted) && (metadata.classFile == NCCommunicationCommon.typeClassFile.image.rawValue && !CCUtility.fileProviderStorageExists(metadata) && metadata.session == "") {
  199. NCNetworking.shared.download(metadata: metadata, selector: "") { _ in
  200. DispatchQueue.main.async {
  201. let image = getImageMetadata(metadata)
  202. completion(metadata.ocId, image)
  203. }
  204. }
  205. } else {
  206. DispatchQueue.main.async {
  207. let image = getImageMetadata(metadata)
  208. completion(metadata.ocId, image)
  209. }
  210. }
  211. }
  212. // Download Live Photo
  213. func downloadFileLivePhoto(metadata: tableMetadata) {
  214. let fileName = (metadata.fileNameView as NSString).deletingPathExtension + ".mov"
  215. if let metadata = NCManageDatabase.shared.getMetadata(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileNameView LIKE[c] %@", metadata.account, metadata.serverUrl, fileName)), !CCUtility.fileProviderStorageExists(metadata) {
  216. NCNetworking.shared.download(metadata: metadata, selector: "") { _ in }
  217. }
  218. }
  219. func getImageMetadata(_ metadata: tableMetadata) -> UIImage? {
  220. if let image = getImage(metadata: metadata) {
  221. return image
  222. }
  223. if metadata.classFile == NCCommunicationCommon.typeClassFile.video.rawValue && !metadata.hasPreview {
  224. NCUtility.shared.createImageFrom(fileName: metadata.fileNameView, ocId: metadata.ocId, etag: metadata.etag, classFile: metadata.classFile)
  225. }
  226. if CCUtility.fileProviderStoragePreviewIconExists(metadata.ocId, etag: metadata.etag) {
  227. if let imagePreviewPath = CCUtility.getDirectoryProviderStoragePreviewOcId(metadata.ocId, etag: metadata.etag) {
  228. return UIImage(contentsOfFile: imagePreviewPath)
  229. }
  230. }
  231. if metadata.classFile == NCCommunicationCommon.typeClassFile.video.rawValue {
  232. return UIImage(named: "noPreviewVideo")!.image(color: .gray, size: view.frame.width)
  233. } else if metadata.classFile == NCCommunicationCommon.typeClassFile.audio.rawValue {
  234. return UIImage(named: "noPreviewAudio")!.image(color: .gray, size: view.frame.width)
  235. } else {
  236. return UIImage(named: "noPreview")!.image(color: .gray, size: view.frame.width)
  237. }
  238. }
  239. func getImage(metadata: tableMetadata) -> UIImage? {
  240. let ext = CCUtility.getExtension(metadata.fileNameView)
  241. var image: UIImage?
  242. if CCUtility.fileProviderStorageExists(metadata) && metadata.classFile == NCCommunicationCommon.typeClassFile.image.rawValue {
  243. let previewPath = CCUtility.getDirectoryProviderStoragePreviewOcId(metadata.ocId, etag: metadata.etag)!
  244. let imagePath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!
  245. if ext == "GIF" {
  246. if !FileManager().fileExists(atPath: previewPath) {
  247. NCUtility.shared.createImageFrom(fileName: metadata.fileNameView, ocId: metadata.ocId, etag: metadata.etag, classFile: metadata.classFile)
  248. }
  249. image = UIImage.animatedImage(withAnimatedGIFURL: URL(fileURLWithPath: imagePath))
  250. } else if ext == "SVG" {
  251. if let svgImage = SVGKImage(contentsOfFile: imagePath) {
  252. svgImage.size = CGSize(width: NCGlobal.shared.sizePreview, height: NCGlobal.shared.sizePreview)
  253. if let image = svgImage.uiImage {
  254. if !FileManager().fileExists(atPath: previewPath) {
  255. do {
  256. try image.pngData()?.write(to: URL(fileURLWithPath: previewPath), options: .atomic)
  257. } catch { }
  258. }
  259. return image
  260. } else {
  261. return nil
  262. }
  263. } else {
  264. return nil
  265. }
  266. } else {
  267. NCUtility.shared.createImageFrom(fileName: metadata.fileNameView, ocId: metadata.ocId, etag: metadata.etag, classFile: metadata.classFile)
  268. image = UIImage(contentsOfFile: imagePath)
  269. }
  270. }
  271. return image
  272. }
  273. }
  274. // MARK: - Gesture
  275. @objc func didDoubleTapWith(gestureRecognizer: UITapGestureRecognizer) {
  276. if detailView.isShow() { return }
  277. // NO ZOOM for Audio
  278. if metadata.classFile == NCCommunicationCommon.typeClassFile.audio.rawValue { return }
  279. let pointInView = gestureRecognizer.location(in: self.imageVideoContainer)
  280. var newZoomScale = self.scrollView.maximumZoomScale
  281. if self.scrollView.zoomScale >= newZoomScale || abs(self.scrollView.zoomScale - newZoomScale) <= 0.01 {
  282. newZoomScale = self.scrollView.minimumZoomScale
  283. }
  284. let width = self.scrollView.bounds.width / newZoomScale
  285. let height = self.scrollView.bounds.height / newZoomScale
  286. let originX = pointInView.x - (width / 2.0)
  287. let originY = pointInView.y - (height / 2.0)
  288. let rectToZoomTo = CGRect(x: originX, y: originY, width: width, height: height)
  289. self.scrollView.zoom(to: rectToZoomTo, animated: true)
  290. }
  291. @objc func didPanWith(gestureRecognizer: UIPanGestureRecognizer) {
  292. let currentLocation = gestureRecognizer.translation(in: self.view)
  293. switch gestureRecognizer.state {
  294. case .began:
  295. // let velocity = gestureRecognizer.velocity(in: self.view)
  296. // gesture moving Up
  297. // if velocity.y < 0 {
  298. // }
  299. break
  300. case .ended:
  301. if detailView.isShow() {
  302. self.imageViewTopConstraint.constant = -imageViewConstraint
  303. self.imageViewBottomConstraint.constant = imageViewConstraint
  304. } else {
  305. self.imageViewTopConstraint.constant = 0
  306. self.imageViewBottomConstraint.constant = 0
  307. }
  308. case .changed:
  309. imageViewTopConstraint.constant = (currentLocation.y - imageViewConstraint)
  310. imageViewBottomConstraint.constant = -(currentLocation.y - imageViewConstraint)
  311. // DISMISS VIEW
  312. if detailView.isHidden && (currentLocation.y > 20) {
  313. viewerMediaPage?.navigationController?.popViewController(animated: true)
  314. gestureRecognizer.state = .ended
  315. }
  316. // CLOSE DETAIL
  317. if !detailView.isHidden && (currentLocation.y > 20) {
  318. self.closeDetail()
  319. gestureRecognizer.state = .ended
  320. }
  321. // OPEN DETAIL
  322. if detailView.isHidden && (currentLocation.y < -20) {
  323. self.openDetail()
  324. gestureRecognizer.state = .ended
  325. }
  326. default:
  327. break
  328. }
  329. }
  330. }
  331. // MARK: -
  332. extension NCViewerMedia {
  333. @objc func openDetail(_ notification: NSNotification) {
  334. if let userInfo = notification.userInfo as NSDictionary?, let ocId = userInfo["ocId"] as? String, ocId == metadata.ocId {
  335. openDetail()
  336. }
  337. }
  338. private func openDetail() {
  339. CCUtility.setExif(metadata) { latitude, longitude, location, date, lensModel in
  340. if latitude != -1 && latitude != 0 && longitude != -1 && longitude != 0 {
  341. self.detailViewHeighConstraint.constant = self.view.bounds.height / 2
  342. } else {
  343. self.detailViewHeighConstraint.constant = 170
  344. }
  345. self.view.layoutIfNeeded()
  346. self.detailView.show(
  347. metadata: self.metadata,
  348. image: self.image,
  349. textColor: self.viewerMediaPage?.textColor,
  350. mediaMetadata: (latitude: latitude, longitude: longitude, location: location, date: date, lensModel: lensModel),
  351. ncplayer: self.ncplayer,
  352. delegate: self)
  353. if let image = self.imageVideoContainer.image {
  354. let ratioW = self.imageVideoContainer.frame.width / image.size.width
  355. let ratioH = self.imageVideoContainer.frame.height / image.size.height
  356. let ratio = ratioW < ratioH ? ratioW : ratioH
  357. let imageHeight = image.size.height * ratio
  358. self.imageViewConstraint = self.detailView.frame.height - ((self.view.frame.height - imageHeight) / 2) + self.view.safeAreaInsets.bottom
  359. if self.imageViewConstraint < 0 { self.imageViewConstraint = 0 }
  360. }
  361. UIView.animate(withDuration: 0.3) {
  362. self.imageViewTopConstraint.constant = -self.imageViewConstraint
  363. self.imageViewBottomConstraint.constant = self.imageViewConstraint
  364. self.detailViewTopConstraint.constant = self.detailViewHeighConstraint.constant
  365. self.view.layoutIfNeeded()
  366. } completion: { _ in
  367. }
  368. self.scrollView.pinchGestureRecognizer?.isEnabled = false
  369. self.playerToolBar.hide()
  370. }
  371. }
  372. private func closeDetail() {
  373. self.detailView.hide()
  374. imageViewConstraint = 0
  375. UIView.animate(withDuration: 0.3) {
  376. self.imageViewTopConstraint.constant = 0
  377. self.imageViewBottomConstraint.constant = 0
  378. self.detailViewTopConstraint.constant = 0
  379. self.view.layoutIfNeeded()
  380. } completion: { _ in
  381. }
  382. scrollView.pinchGestureRecognizer?.isEnabled = true
  383. if metadata.classFile == NCCommunicationCommon.typeClassFile.video.rawValue && !metadata.livePhoto && ncplayer?.player?.timeControlStatus == .paused {
  384. NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterShowPlayerToolBar, userInfo: ["ocId": metadata.ocId, "enableTimerAutoHide": false])
  385. }
  386. }
  387. func reloadDetail() {
  388. if self.detailView.isShow() {
  389. CCUtility.setExif(metadata) { (latitude, longitude, location, date, lensModel) in
  390. self.detailView.show(
  391. metadata: self.metadata,
  392. image: self.image,
  393. textColor: self.viewerMediaPage?.textColor,
  394. mediaMetadata: (latitude: latitude, longitude: longitude, location: location, date: date, lensModel: lensModel),
  395. ncplayer: self.ncplayer,
  396. delegate: self)
  397. }
  398. }
  399. }
  400. }
  401. // MARK: -
  402. extension NCViewerMedia: UIScrollViewDelegate {
  403. func viewForZooming(in scrollView: UIScrollView) -> UIView? {
  404. return imageVideoContainer
  405. }
  406. func scrollViewDidZoom(_ scrollView: UIScrollView) {
  407. if scrollView.zoomScale > 1 {
  408. if let image = imageVideoContainer.image {
  409. let ratioW = imageVideoContainer.frame.width / image.size.width
  410. let ratioH = imageVideoContainer.frame.height / image.size.height
  411. let ratio = ratioW < ratioH ? ratioW : ratioH
  412. let newWidth = image.size.width * ratio
  413. let newHeight = image.size.height * ratio
  414. let conditionLeft = newWidth*scrollView.zoomScale > imageVideoContainer.frame.width
  415. let left = 0.5 * (conditionLeft ? newWidth - imageVideoContainer.frame.width : (scrollView.frame.width - scrollView.contentSize.width))
  416. let conditioTop = newHeight*scrollView.zoomScale > imageVideoContainer.frame.height
  417. let top = 0.5 * (conditioTop ? newHeight - imageVideoContainer.frame.height : (scrollView.frame.height - scrollView.contentSize.height))
  418. scrollView.contentInset = UIEdgeInsets(top: top, left: left, bottom: top, right: left)
  419. }
  420. } else {
  421. scrollView.contentInset = .zero
  422. }
  423. }
  424. func scrollViewDidScroll(_ scrollView: UIScrollView) {
  425. }
  426. }
  427. extension NCViewerMedia: NCViewerMediaDetailViewDelegate {
  428. func downloadFullResolution() {
  429. closeDetail()
  430. NCNetworking.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorOpenDetail) { _ in }
  431. }
  432. }
  433. // MARK: -
  434. class imageVideoContainerView: UIImageView {
  435. var playerLayer: CALayer?
  436. var metadata: tableMetadata?
  437. override func layoutSublayers(of layer: CALayer) {
  438. super.layoutSublayers(of: layer)
  439. playerLayer?.frame = self.bounds
  440. }
  441. }