NCMedia.swift 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. //
  2. // NCMedia.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 12/02/2019.
  6. // Copyright © 2019 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. import UIKit
  24. import NextcloudKit
  25. import RealmSwift
  26. class NCMedia: UIViewController {
  27. @IBOutlet weak var collectionView: UICollectionView!
  28. @IBOutlet weak var titleDate: UILabel!
  29. @IBOutlet weak var activityIndicator: UIActivityIndicatorView!
  30. @IBOutlet weak var activityIndicatorTrailing: NSLayoutConstraint!
  31. @IBOutlet weak var selectOrCancelButton: UIButton!
  32. @IBOutlet weak var selectOrCancelButtonTrailing: NSLayoutConstraint!
  33. @IBOutlet weak var menuButton: UIButton!
  34. @IBOutlet weak var gradientView: UIView!
  35. let layout = NCMediaLayout()
  36. var activeAccount = tableAccount()
  37. var documentPickerViewController: NCDocumentPickerViewController?
  38. var tabBarSelect: NCMediaSelectTabBar!
  39. let appDelegate = (UIApplication.shared.delegate as? AppDelegate)!
  40. let utilityFileSystem = NCUtilityFileSystem()
  41. let utility = NCUtility()
  42. let imageCache = NCImageCache.shared
  43. var metadatas: ThreadSafeArray<tableMetadata>?
  44. let refreshControl = UIRefreshControl()
  45. var loadingTask: Task<Void, any Error>?
  46. var isTop: Bool = true
  47. var isEditMode = false
  48. var selectOcId: [String] = []
  49. var attributesZoomIn: UIMenuElement.Attributes = []
  50. var attributesZoomOut: UIMenuElement.Attributes = []
  51. let gradient: CAGradientLayer = CAGradientLayer()
  52. var showOnlyImages = false
  53. var showOnlyVideos = false
  54. var lastContentOffsetY: CGFloat = 0
  55. var timeIntervalSearchNewMedia: TimeInterval = 2.0
  56. var timerSearchNewMedia: Timer?
  57. let insetsTop: CGFloat = 75
  58. let maxImageGrid: CGFloat = 7
  59. var livePhotoImage = UIImage()
  60. var playImage = UIImage()
  61. var photoImage = UIImage()
  62. var videoImage = UIImage()
  63. // MARK: - View Life Cycle
  64. override func viewDidLoad() {
  65. super.viewDidLoad()
  66. view.backgroundColor = .systemBackground
  67. collectionView.register(UINib(nibName: "NCSectionHeaderEmptyData", bundle: nil), forSupplementaryViewOfKind: collectionViewMediaElementKindSectionHeader, withReuseIdentifier: "sectionHeaderEmptyData")
  68. collectionView.register(UINib(nibName: "NCGridMediaCell", bundle: nil), forCellWithReuseIdentifier: "gridCell")
  69. collectionView.alwaysBounceVertical = true
  70. collectionView.contentInset = UIEdgeInsets(top: insetsTop, left: 0, bottom: 50, right: 0)
  71. collectionView.backgroundColor = .systemBackground
  72. collectionView.prefetchDataSource = self
  73. layout.sectionInset = UIEdgeInsets(top: 0, left: 2, bottom: 0, right: 2)
  74. layout.mediaViewController = self
  75. collectionView.collectionViewLayout = layout
  76. tabBarSelect = NCMediaSelectTabBar(tabBarController: self.tabBarController, delegate: self)
  77. livePhotoImage = utility.loadImage(named: "livephoto", color: .white)
  78. playImage = utility.loadImage(named: "play.fill", color: .white)
  79. titleDate.text = ""
  80. selectOrCancelButton.backgroundColor = .clear
  81. selectOrCancelButton.layer.cornerRadius = 15
  82. selectOrCancelButton.layer.masksToBounds = true
  83. selectOrCancelButton.setTitle( NSLocalizedString("_select_", comment: ""), for: .normal)
  84. selectOrCancelButton.addBlur(style: .systemThinMaterial)
  85. menuButton.backgroundColor = .clear
  86. menuButton.layer.cornerRadius = 15
  87. menuButton.layer.masksToBounds = true
  88. menuButton.showsMenuAsPrimaryAction = true
  89. menuButton.configuration = UIButton.Configuration.plain()
  90. menuButton.setImage(UIImage(systemName: "ellipsis"), for: .normal)
  91. menuButton.changesSelectionAsPrimaryAction = false
  92. menuButton.addBlur(style: .systemThinMaterial)
  93. gradient.startPoint = CGPoint(x: 0, y: 0.1)
  94. gradient.endPoint = CGPoint(x: 0, y: 1)
  95. gradient.colors = [UIColor.black.withAlphaComponent(UIAccessibility.isReduceTransparencyEnabled ? 0.8 : 0.4).cgColor, UIColor.clear.cgColor]
  96. gradientView.layer.insertSublayer(gradient, at: 0)
  97. activeAccount = NCManageDatabase.shared.getActiveAccount() ?? tableAccount()
  98. collectionView.refreshControl = refreshControl
  99. refreshControl.action(for: .valueChanged) { _ in
  100. DispatchQueue.global().async {
  101. self.reloadDataSource()
  102. }
  103. self.refreshControl.endRefreshing()
  104. }
  105. NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterChangeUser), object: nil, queue: nil) { _ in
  106. self.activeAccount = NCManageDatabase.shared.getActiveAccount() ?? tableAccount()
  107. if let metadatas = self.metadatas,
  108. let metadata = metadatas.first {
  109. if metadata.account != self.activeAccount.account {
  110. self.metadatas = nil
  111. self.collectionViewReloadData()
  112. }
  113. }
  114. }
  115. NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterCreateMediaCacheEnded), object: nil, queue: nil) { _ in
  116. if let metadatas = self.imageCache.initialMetadatas() {
  117. self.metadatas = metadatas
  118. }
  119. self.collectionViewReloadData()
  120. }
  121. }
  122. override func viewWillAppear(_ animated: Bool) {
  123. super.viewWillAppear(animated)
  124. navigationController?.setMediaAppreance()
  125. }
  126. override func viewDidAppear(_ animated: Bool) {
  127. super.viewDidAppear(animated)
  128. appDelegate.activeViewController = self
  129. NotificationCenter.default.addObserver(self, selector: #selector(deleteFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterDeleteFile), object: nil)
  130. NotificationCenter.default.addObserver(self, selector: #selector(enterForeground(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterApplicationWillEnterForeground), object: nil)
  131. startTimer()
  132. createMenu()
  133. if imageCache.createMediaCacheInProgress {
  134. self.metadatas = nil
  135. self.collectionViewReloadData()
  136. } else if let metadatas = imageCache.initialMetadatas() {
  137. self.metadatas = metadatas
  138. self.collectionViewReloadData()
  139. } else {
  140. DispatchQueue.global().async {
  141. self.reloadDataSource()
  142. }
  143. }
  144. }
  145. override func viewDidDisappear(_ animated: Bool) {
  146. super.viewDidDisappear(animated)
  147. NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterDeleteFile), object: nil)
  148. NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterApplicationWillEnterForeground), object: nil)
  149. }
  150. override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
  151. super.viewWillTransition(to: size, with: coordinator)
  152. coordinator.animate(alongsideTransition: nil) { _ in
  153. self.setTitleDate()
  154. }
  155. }
  156. override var preferredStatusBarStyle: UIStatusBarStyle {
  157. if self.traitCollection.userInterfaceStyle == .dark {
  158. return .lightContent
  159. } else if isTop {
  160. return .darkContent
  161. } else {
  162. return .lightContent
  163. }
  164. }
  165. override func viewWillLayoutSubviews() {
  166. super.viewWillLayoutSubviews()
  167. if let frame = tabBarController?.tabBar.frame {
  168. tabBarSelect.hostingController.view.frame = frame
  169. }
  170. gradient.frame = gradientView.bounds
  171. }
  172. func startTimer() {
  173. // don't start if media chage is in progress
  174. if imageCache.createMediaCacheInProgress {
  175. return
  176. }
  177. timerSearchNewMedia?.invalidate()
  178. timerSearchNewMedia = Timer.scheduledTimer(timeInterval: timeIntervalSearchNewMedia, target: self, selector: #selector(searchMediaUI), userInfo: nil, repeats: false)
  179. }
  180. // MARK: - NotificationCenter
  181. @objc func deleteFile(_ notification: NSNotification) {
  182. guard let userInfo = notification.userInfo as NSDictionary?,
  183. let error = userInfo["error"] as? NKError else { return }
  184. self.reloadDataSource()
  185. if error != .success {
  186. NCContentPresenter().showError(error: error)
  187. }
  188. }
  189. @objc func enterForeground(_ notification: NSNotification) {
  190. startTimer()
  191. }
  192. // MARK: - Image
  193. func getImage(metadata: tableMetadata) -> UIImage? {
  194. if let image = imageCache.getMediaImage(ocId: metadata.ocId, etag: metadata.etag) {
  195. return image
  196. } else if FileManager().fileExists(atPath: utilityFileSystem.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag)),
  197. let image = UIImage(contentsOfFile: utilityFileSystem.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag)) {
  198. imageCache.setMediaSize(ocId: metadata.ocId, etag: metadata.etag, size: image.size)
  199. if imageCache.hasMediaImageEnoughSpace() {
  200. imageCache.setMediaImage(ocId: metadata.ocId, etag: metadata.etag, image: image, date: metadata.date as Date)
  201. }
  202. return image
  203. } else if metadata.hasPreview && metadata.status == NCGlobal.shared.metadataStatusNormal,
  204. (!utilityFileSystem.fileProviderStoragePreviewIconExists(metadata.ocId, etag: metadata.etag)),
  205. NCNetworking.shared.downloadThumbnailQueue.operations.filter({ ($0 as? NCMediaDownloadThumbnaill)?.metadata.ocId == metadata.ocId }).isEmpty {
  206. NCNetworking.shared.downloadThumbnailQueue.addOperation(NCMediaDownloadThumbnaill(metadata: metadata, media: self))
  207. }
  208. return nil
  209. }
  210. func buildMediaPhotoVideo(columnCount: Int) {
  211. var pointSize: CGFloat = 0
  212. switch columnCount {
  213. case 0...1: pointSize = 60
  214. case 2...3: pointSize = 30
  215. case 4...5: pointSize = 25
  216. case 6...Int(maxImageGrid): pointSize = 20
  217. default: pointSize = 20
  218. }
  219. if let image = UIImage(systemName: "photo.fill", withConfiguration: UIImage.SymbolConfiguration(pointSize: pointSize))?.withTintColor(.systemGray4, renderingMode: .alwaysOriginal) {
  220. photoImage = image
  221. }
  222. if let image = UIImage(systemName: "video.fill", withConfiguration: UIImage.SymbolConfiguration(pointSize: pointSize))?.withTintColor(.systemGray4, renderingMode: .alwaysOriginal) {
  223. videoImage = image
  224. }
  225. }
  226. }
  227. // MARK: - Collection View
  228. extension NCMedia: UICollectionViewDelegate {
  229. func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
  230. var mediaCell: NCGridMediaCell?
  231. if let metadata = self.metadatas?[indexPath.row] {
  232. if let visibleCells = self.collectionView?.indexPathsForVisibleItems.compactMap({ self.collectionView?.cellForItem(at: $0) }) {
  233. for case let cell as NCGridMediaCell in visibleCells {
  234. if cell.ocId == metadata.ocId {
  235. mediaCell = cell
  236. }
  237. }
  238. }
  239. if isEditMode {
  240. if let index = selectOcId.firstIndex(of: metadata.ocId) {
  241. selectOcId.remove(at: index)
  242. mediaCell?.selected(false)
  243. } else {
  244. selectOcId.append(metadata.ocId)
  245. mediaCell?.selected(true)
  246. }
  247. tabBarSelect.selectCount = selectOcId.count
  248. } else {
  249. // ACTIVE SERVERURL
  250. appDelegate.activeServerUrl = metadata.serverUrl
  251. if let metadatas = self.metadatas?.getArray() {
  252. NCViewer().view(viewController: self, metadata: metadata, metadatas: metadatas, imageIcon: getImage(metadata: metadata))
  253. }
  254. }
  255. }
  256. }
  257. func collectionView(_ collectionView: UICollectionView, contextMenuConfigurationForItemAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
  258. guard let cell = collectionView.cellForItem(at: indexPath) as? NCGridMediaCell,
  259. let metadata = self.metadatas?[indexPath.row] else { return nil }
  260. let identifier = indexPath as NSCopying
  261. let image = cell.imageItem.image
  262. return UIContextMenuConfiguration(identifier: identifier, previewProvider: {
  263. return NCViewerProviderContextMenu(metadata: metadata, image: image)
  264. }, actionProvider: { _ in
  265. return NCContextMenu().viewMenu(ocId: metadata.ocId, viewController: self, image: image)
  266. })
  267. }
  268. func collectionView(_ collectionView: UICollectionView, willPerformPreviewActionForMenuWith configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionCommitAnimating) {
  269. animator.addCompletion {
  270. if let indexPath = configuration.identifier as? IndexPath {
  271. self.collectionView(collectionView, didSelectItemAt: indexPath)
  272. }
  273. }
  274. }
  275. }
  276. extension NCMedia: UICollectionViewDataSourcePrefetching {
  277. func collectionView(_ collectionView: UICollectionView, prefetchItemsAt indexPaths: [IndexPath]) {
  278. // print("[INFO] n. " + String(indexPaths.count))
  279. }
  280. }
  281. extension NCMedia: UICollectionViewDataSource {
  282. func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
  283. if kind == "collectionViewMediaElementKindSectionHeader" {
  284. guard let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "sectionHeaderEmptyData", for: indexPath) as? NCSectionHeaderEmptyData else { return NCSectionHeaderEmptyData() }
  285. header.emptyImage.image = UIImage(named: "media")?.image(color: .gray, size: UIScreen.main.bounds.width)
  286. if loadingTask != nil || imageCache.createMediaCacheInProgress {
  287. header.emptyTitle.text = NSLocalizedString("_search_in_progress_", comment: "")
  288. } else {
  289. header.emptyTitle.text = NSLocalizedString("_tutorial_photo_view_", comment: "")
  290. }
  291. header.emptyDescription.text = ""
  292. return header
  293. }
  294. return UICollectionReusableView()
  295. }
  296. func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  297. var numberOfItemsInSection = 0
  298. if let metadatas { numberOfItemsInSection = metadatas.count }
  299. if numberOfItemsInSection == 0 {
  300. selectOrCancelButton.isHidden = true
  301. menuButton.isHidden = false
  302. gradientView.isHidden = true
  303. activityIndicatorTrailing.constant = 50
  304. } else if isEditMode {
  305. selectOrCancelButton.isHidden = false
  306. menuButton.isHidden = true
  307. activityIndicatorTrailing.constant = 150
  308. } else {
  309. selectOrCancelButton.isHidden = false
  310. menuButton.isHidden = false
  311. activityIndicatorTrailing.constant = 150
  312. }
  313. DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) { self.setTitleDate() }
  314. return numberOfItemsInSection
  315. }
  316. func collectionView(_ collectionView: UICollectionView, didEndDisplaying cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
  317. guard let metadatas else { return }
  318. if !collectionView.indexPathsForVisibleItems.contains(indexPath) && indexPath.row < metadatas.count {
  319. guard let metadata = metadatas[indexPath.row] else { return }
  320. for case let operation as NCMediaDownloadThumbnaill in NCNetworking.shared.downloadThumbnailQueue.operations where operation.metadata.ocId == metadata.ocId {
  321. operation.cancel()
  322. }
  323. for case let operation as NCOperationConvertLivePhoto in NCNetworking.shared.convertLivePhotoQueue.operations where operation.ocId == metadata.ocId {
  324. operation.cancel()
  325. }
  326. }
  327. }
  328. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  329. guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "gridCell", for: indexPath) as? NCGridMediaCell,
  330. let metadatas = self.metadatas,
  331. let metadata = metadatas[indexPath.row]
  332. else {
  333. return NCGridMediaCell()
  334. }
  335. cell.date = metadata.date as Date
  336. cell.ocId = metadata.ocId
  337. cell.indexPath = indexPath
  338. cell.user = metadata.ownerId
  339. cell.imageStatus.image = nil
  340. cell.imageItem.contentMode = .scaleAspectFill
  341. if let image = getImage(metadata: metadata) {
  342. cell.imageItem.image = image
  343. } else if !metadata.hasPreview {
  344. cell.imageItem.backgroundColor = .clear
  345. cell.imageItem.contentMode = .center
  346. if metadata.isImage {
  347. cell.imageItem.image = photoImage
  348. } else {
  349. cell.imageItem.image = videoImage
  350. }
  351. }
  352. // Convert OLD Live Photo
  353. if NCGlobal.shared.isLivePhotoServerAvailable, metadata.isLivePhoto, metadata.isNotFlaggedAsLivePhotoByServer {
  354. NCNetworking.shared.convertLivePhoto(metadata: metadata)
  355. }
  356. if metadata.isAudioOrVideo {
  357. cell.imageStatus.image = playImage
  358. } else if metadata.isLivePhoto {
  359. cell.imageStatus.image = livePhotoImage
  360. } else {
  361. cell.imageStatus.image = nil
  362. }
  363. if isEditMode, selectOcId.contains(metadata.ocId) {
  364. cell.selected(true)
  365. } else {
  366. cell.selected(false)
  367. }
  368. return cell
  369. }
  370. }
  371. // MARK: -
  372. extension NCMedia: NCMediaLayoutDelegate {
  373. func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, heightForHeaderInSection section: Int) -> Float {
  374. var height: Double = 0
  375. if metadatas?.count ?? 0 == 0 {
  376. height = NCGlobal.shared.getHeightHeaderEmptyData(view: view, portraitOffset: 0, landscapeOffset: -20)
  377. }
  378. return Float(height)
  379. }
  380. func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, heightForFooterInSection section: Int) -> Float {
  381. return .zero
  382. }
  383. func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, insetForSection section: Int) -> UIEdgeInsets {
  384. return .zero
  385. }
  386. func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, insetForHeaderInSection section: Int) -> UIEdgeInsets {
  387. return .zero
  388. }
  389. func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, insetForFooterInSection section: Int) -> UIEdgeInsets {
  390. return .zero
  391. }
  392. func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, minimumInteritemSpacingForSection section: Int) -> Float {
  393. return .zero
  394. }
  395. func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath, columnCount: Int, mediaLayout: String) -> CGSize {
  396. let size = CGSize(width: collectionView.frame.width / CGFloat(columnCount), height: collectionView.frame.width / CGFloat(columnCount))
  397. if mediaLayout == NCGlobal.shared.mediaLayoutRatio {
  398. guard let metadatas = self.metadatas,
  399. let metadata = metadatas[indexPath.row] else { return size }
  400. if metadata.imageSize != CGSize.zero {
  401. return metadata.imageSize
  402. } else if let size = imageCache.getMediaSize(ocId: metadata.ocId, etag: metadata.etag) {
  403. return size
  404. }
  405. }
  406. return size
  407. }
  408. }
  409. // MARK: -
  410. extension NCMedia: UIScrollViewDelegate {
  411. func scrollViewDidScroll(_ scrollView: UIScrollView) {
  412. if let metadatas, !metadatas.isEmpty {
  413. isTop = scrollView.contentOffset.y <= -(insetsTop + view.safeAreaInsets.top - 25)
  414. setColor()
  415. setNeedsStatusBarAppearanceUpdate()
  416. if lastContentOffsetY == 0 || lastContentOffsetY / 2 <= scrollView.contentOffset.y || lastContentOffsetY / 2 >= scrollView.contentOffset.y {
  417. setTitleDate()
  418. lastContentOffsetY = scrollView.contentOffset.y
  419. }
  420. } else {
  421. setColor()
  422. }
  423. }
  424. func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
  425. }
  426. func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
  427. if !decelerate {
  428. if !decelerate {
  429. startTimer()
  430. }
  431. }
  432. }
  433. func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
  434. startTimer()
  435. }
  436. func scrollViewDidScrollToTop(_ scrollView: UIScrollView) {
  437. let y = view.safeAreaInsets.top
  438. scrollView.contentOffset.y = -(insetsTop + y)
  439. }
  440. }
  441. // MARK: -
  442. extension NCMedia: NCSelectDelegate {
  443. func dismissSelect(serverUrl: String?, metadata: tableMetadata?, type: String, items: [Any], overwrite: Bool, copy: Bool, move: Bool) {
  444. guard let serverUrl = serverUrl else { return }
  445. let home = utilityFileSystem.getHomeServer(urlBase: appDelegate.urlBase, userId: appDelegate.userId)
  446. let mediaPath = serverUrl.replacingOccurrences(of: home, with: "")
  447. NCManageDatabase.shared.setAccountMediaPath(mediaPath, account: activeAccount.account)
  448. activeAccount = NCManageDatabase.shared.getActiveAccount() ?? tableAccount()
  449. reloadDataSource()
  450. startTimer()
  451. }
  452. }