NCViewerMedia.swift 23 KB

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