NCViewerMedia.swift 25 KB

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