NCViewerMedia.swift 23 KB

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