NCDetailViewController.swift 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. //
  2. // NCDetailViewController.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 07/02/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 Foundation
  24. import WebKit
  25. import NCCommunication
  26. class NCDetailViewController: UIViewController {
  27. @IBOutlet weak var backgroundView: UIImageView!
  28. @objc var metadata: tableMetadata?
  29. @objc var selector: String?
  30. @objc var favoriteFilterImage: Bool = false
  31. @objc var mediaFilterImage: Bool = false
  32. @objc var offlineFilterImage: Bool = false
  33. private let appDelegate = UIApplication.shared.delegate as! AppDelegate
  34. private var mediaBrowser: MediaBrowserViewController?
  35. private var metadatas = [tableMetadata]()
  36. private var mediaBrowserIndexStart = 0
  37. //MARK: -
  38. required init?(coder: NSCoder) {
  39. super.init(coder: coder)
  40. appDelegate.activeDetail = self
  41. }
  42. override func viewDidLoad() {
  43. super.viewDidLoad()
  44. NotificationCenter.default.addObserver(self, selector: #selector(self.changeTheming), name: NSNotification.Name(rawValue: k_notificationCenter_changeTheming), object: nil)
  45. NotificationCenter.default.addObserver(self, selector: #selector(self.changeDisplayMode), name: NSNotification.Name(rawValue: k_notificationCenter_splitViewChangeDisplayMode), object: nil)
  46. NotificationCenter.default.addObserver(self, selector: #selector(self.deleteFile(_:)), name: NSNotification.Name(rawValue: k_notificationCenter_deleteFile), object: nil)
  47. NotificationCenter.default.addObserver(self, selector: #selector(self.uploadFile(_:)), name: NSNotification.Name(rawValue: k_notificationCenter_uploadFile), object: nil)
  48. NotificationCenter.default.addObserver(self, selector: #selector(self.renameFile(_:)), name: NSNotification.Name(rawValue: k_notificationCenter_renameFile), object: nil)
  49. NotificationCenter.default.addObserver(self, selector: #selector(self.moveFile(_:)), name: NSNotification.Name(rawValue: k_notificationCenter_moveFile), object: nil)
  50. changeTheming()
  51. if metadata != nil {
  52. viewFile(metadata: metadata!, selector: selector)
  53. }
  54. }
  55. override func viewDidDisappear(_ animated: Bool) {
  56. super.viewDidDisappear(animated)
  57. if appDelegate.player != nil && appDelegate.player.rate != 0 {
  58. appDelegate.player.pause()
  59. }
  60. if appDelegate.isMediaObserver {
  61. appDelegate.isMediaObserver = false
  62. NCViewerMedia.sharedInstance.removeObserver()
  63. }
  64. }
  65. override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
  66. super.viewWillTransition(to: size, with: coordinator)
  67. coordinator.animate(alongsideTransition: nil) { _ in
  68. }
  69. }
  70. //MARK: - Utility
  71. func subViewActive() -> UIView? {
  72. return backgroundView.subviews.first
  73. }
  74. func viewUnload() {
  75. metadata = nil
  76. selector = nil
  77. if let splitViewController = self.splitViewController as? NCSplitViewController {
  78. if splitViewController.isCollapsed {
  79. if let navigationController = splitViewController.viewControllers.last as? UINavigationController {
  80. navigationController.popToRootViewController(animated: true)
  81. }
  82. } else {
  83. for view in backgroundView.subviews {
  84. view.removeFromSuperview()
  85. }
  86. self.navigationController?.navigationBar.topItem?.title = ""
  87. }
  88. }
  89. self.splitViewController?.preferredDisplayMode = .allVisible
  90. self.navigationController?.isNavigationBarHidden = false
  91. view.backgroundColor = NCBrandColor.sharedInstance.backgroundView
  92. backgroundView.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "logo"), multiplier: 2, color: NCBrandColor.sharedInstance.brand.withAlphaComponent(0.4))
  93. }
  94. //MARK: - NotificationCenter
  95. @objc func changeTheming() {
  96. if backgroundView.image != nil {
  97. backgroundView.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "logo"), multiplier: 2, color: NCBrandColor.sharedInstance.brand.withAlphaComponent(0.4))
  98. }
  99. if navigationController?.isNavigationBarHidden == false {
  100. view.backgroundColor = NCBrandColor.sharedInstance.backgroundView
  101. }
  102. }
  103. @objc func changeDisplayMode() {
  104. guard let mediaBrowser = self.mediaBrowser else { return }
  105. var image: UIImage?
  106. var contentViewSaved : MediaContentView?
  107. for contentView in mediaBrowser.contentViews {
  108. if contentView.position == 0 && contentView.isLoading == false {
  109. image = contentView.image
  110. contentViewSaved = contentView
  111. contentView.image = nil
  112. }
  113. }
  114. DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(150)) {
  115. self.mediaBrowser?.changeInViewSize(to: self.backgroundView.frame.size)
  116. if image != nil {
  117. contentViewSaved?.image = image
  118. }
  119. }
  120. }
  121. @objc func moveFile(_ notification: NSNotification) {
  122. if let userInfo = notification.userInfo as NSDictionary? {
  123. if let metadata = userInfo["metadata"] as? tableMetadata, let errorCode = userInfo["errorCode"] as? Int {
  124. if errorCode != 0 || metadata.serverUrl != self.metadata?.serverUrl { return }
  125. self.deleteFile(notification)
  126. }
  127. }
  128. }
  129. @objc func deleteFile(_ notification: NSNotification) {
  130. if let userInfo = notification.userInfo as NSDictionary? {
  131. if let metadata = userInfo["metadata"] as? tableMetadata, let errorCode = userInfo["errorCode"] as? Int {
  132. if errorCode != 0 { return }
  133. // IMAGE
  134. if mediaBrowser != nil && metadata.account == self.metadata?.account && metadata.serverUrl == self.metadata?.serverUrl && metadata.typeFile == k_metadataTypeFile_image {
  135. if let metadatas = getMetadatasMediaBrowser() {
  136. var index = mediaBrowser!.index - 1
  137. if index < 0 { index = 0}
  138. self.metadata = metadatas[index]
  139. viewImage()
  140. } else {
  141. viewUnload()
  142. }
  143. // OTHER SINGLE FILE TYPE
  144. } else if metadata.ocId == self.metadata?.ocId {
  145. viewUnload()
  146. }
  147. }
  148. }
  149. }
  150. @objc func uploadFile(_ notification: NSNotification) {
  151. if let userInfo = notification.userInfo as NSDictionary? {
  152. if let metadata = userInfo["metadata"] as? tableMetadata, let errorCode = userInfo["errorCode"] as? Int {
  153. if errorCode != 0 { return }
  154. // IMAGE
  155. if mediaBrowser != nil && metadata.account == self.metadata?.account && metadata.serverUrl == self.metadata?.serverUrl && metadata.typeFile == k_metadataTypeFile_image {
  156. if getMetadatasMediaBrowser() != nil {
  157. viewImage()
  158. } else {
  159. viewUnload()
  160. }
  161. }
  162. }
  163. }
  164. }
  165. @objc func renameFile(_ notification: NSNotification) {
  166. if let userInfo = notification.userInfo as NSDictionary? {
  167. if let metadata = userInfo["metadata"] as? tableMetadata, let errorCode = userInfo["errorCode"] as? Int {
  168. if errorCode != 0 { return }
  169. // IMAGE
  170. if mediaBrowser != nil && metadata.account == self.metadata?.account && metadata.serverUrl == self.metadata?.serverUrl && metadata.typeFile == k_metadataTypeFile_image {
  171. if getMetadatasMediaBrowser() != nil {
  172. viewImage()
  173. } else {
  174. viewUnload()
  175. }
  176. // OTHER SINGLE FILE TYPE
  177. } else if metadata.ocId == self.metadata?.ocId {
  178. self.navigationController?.navigationBar.topItem?.title = metadata.fileNameView
  179. }
  180. }
  181. }
  182. }
  183. //MARK: -
  184. @objc func viewFile(metadata: tableMetadata, selector: String?) {
  185. self.metadata = metadata
  186. self.selector = selector
  187. self.backgroundView.image = nil
  188. for view in backgroundView.subviews { view.removeFromSuperview() }
  189. self.navigationController?.navigationBar.topItem?.title = metadata.fileNameView
  190. if FileManager().fileExists(atPath: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, fileNameView: metadata.fileNameView)) == false {
  191. CCGraphics.createNewImage(from: metadata.fileNameView, ocId: metadata.ocId, extension: (metadata.fileNameView as NSString).pathExtension, filterGrayScale: false, typeFile: metadata.typeFile, writeImage: true)
  192. }
  193. if appDelegate.isMediaObserver {
  194. appDelegate.isMediaObserver = false
  195. NCViewerMedia.sharedInstance.removeObserver()
  196. }
  197. // IMAGE
  198. if metadata.typeFile == k_metadataTypeFile_image {
  199. //self.extendedLayoutIncludesOpaqueBars = true
  200. //self.edgesForExtendedLayout = .all
  201. viewImage()
  202. return
  203. }
  204. // AUDIO VIDEO
  205. if metadata.typeFile == k_metadataTypeFile_audio || metadata.typeFile == k_metadataTypeFile_video {
  206. NCViewerMedia.sharedInstance.viewMedia(metadata, view: backgroundView)
  207. return
  208. }
  209. // DOCUMENT - INTERNAL VIEWER
  210. if metadata.typeFile == k_metadataTypeFile_document && selector != nil && selector == selectorLoadFileInternalView {
  211. NCViewerDocumentWeb.sharedInstance.viewDocumentWebAt(metadata, view: backgroundView)
  212. return
  213. }
  214. // DOCUMENT
  215. if metadata.typeFile == k_metadataTypeFile_document {
  216. // PDF
  217. if metadata.contentType == "application/pdf" {
  218. if #available(iOS 11.0, *) {
  219. let viewerPDF = NCViewerPDF.init(frame: backgroundView.frame)
  220. let filePath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!
  221. if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) == false {
  222. return
  223. }
  224. viewerPDF.setupPdfView(filePath: URL(fileURLWithPath: filePath), view: backgroundView)
  225. }
  226. return
  227. }
  228. // DirectEditinf: Nextcloud Text - OnlyOffice
  229. if NCUtility.sharedInstance.isDirectEditing(metadata) != nil && appDelegate.reachability.isReachable() {
  230. let editor = NCUtility.sharedInstance.isDirectEditing(metadata)!
  231. if editor == k_editor_text || editor == k_editor_onlyoffice {
  232. NCUtility.sharedInstance.startActivityIndicator(view: backgroundView, bottom: 0)
  233. if metadata.url == "" {
  234. var customUserAgent: String?
  235. let fileNamePath = CCUtility.returnFileNamePath(fromFileName: metadata.fileName, serverUrl: metadata.serverUrl, activeUrl: appDelegate.activeUrl)!
  236. if editor == k_editor_onlyoffice {
  237. customUserAgent = NCUtility.sharedInstance.getCustomUserAgentOnlyOffice()
  238. }
  239. NCCommunication.sharedInstance.NCTextOpenFile(urlString: appDelegate.activeUrl, fileNamePath: fileNamePath, editor: editor, customUserAgent: customUserAgent, account: appDelegate.activeAccount) { (account, url, errorCode, errorMessage) in
  240. if errorCode == 0 && account == self.appDelegate.activeAccount && url != nil {
  241. let nextcloudText = NCViewerNextcloudText.init(frame: self.backgroundView.frame, configuration: WKWebViewConfiguration())
  242. nextcloudText.viewerAt(url!, metadata: metadata, editor: editor, view: self.backgroundView, viewController: self)
  243. if editor == k_editor_text && self.splitViewController!.isCollapsed {
  244. self.navigationController?.navigationItem.hidesBackButton = true
  245. }
  246. } else if errorCode != 0 {
  247. NCContentPresenter.shared.messageNotification("_error_", description: errorMessage, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: errorCode)
  248. self.navigationController?.popViewController(animated: true)
  249. } else {
  250. self.navigationController?.popViewController(animated: true)
  251. }
  252. }
  253. } else {
  254. let nextcloudText = NCViewerNextcloudText.init(frame: backgroundView.frame, configuration: WKWebViewConfiguration())
  255. nextcloudText.viewerAt(metadata.url, metadata: metadata, editor: editor, view: backgroundView, viewController: self)
  256. if editor == k_editor_text && self.splitViewController!.isCollapsed {
  257. self.navigationController?.navigationItem.hidesBackButton = true
  258. }
  259. }
  260. }
  261. return
  262. }
  263. // RichDocument: Collabora
  264. if NCUtility.sharedInstance.isRichDocument(metadata) && appDelegate.reachability.isReachable() {
  265. NCUtility.sharedInstance.startActivityIndicator(view: backgroundView, bottom: 0)
  266. if metadata.url == "" {
  267. OCNetworking.sharedManager()?.createLinkRichdocuments(withAccount: appDelegate.activeAccount, fileId: metadata.fileId, completion: { (account, url, errorMessage, errorCode) in
  268. if errorCode == 0 && account == self.appDelegate.activeAccount && url != nil {
  269. let richDocument = NCViewerRichdocument.init(frame: self.backgroundView.frame, configuration: WKWebViewConfiguration())
  270. richDocument.viewRichDocumentAt(url!, metadata: metadata, view: self.backgroundView, viewController: self)
  271. if self.splitViewController != nil && self.splitViewController!.isCollapsed {
  272. self.navigationController?.navigationItem.hidesBackButton = true
  273. }
  274. } else if errorCode != 0 {
  275. NCContentPresenter.shared.messageNotification("_error_", description: errorMessage, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: errorCode)
  276. self.navigationController?.popViewController(animated: true)
  277. } else {
  278. self.navigationController?.popViewController(animated: true)
  279. }
  280. })
  281. } else {
  282. let richDocument = NCViewerRichdocument.init(frame: backgroundView.frame, configuration: WKWebViewConfiguration())
  283. richDocument.viewRichDocumentAt(metadata.url, metadata: metadata, view: backgroundView, viewController: self)
  284. if self.splitViewController != nil && self.splitViewController!.isCollapsed {
  285. self.navigationController?.navigationItem.hidesBackButton = true
  286. }
  287. }
  288. }
  289. }
  290. // OTHER
  291. NCViewerDocumentWeb.sharedInstance.viewDocumentWebAt(metadata, view: backgroundView)
  292. }
  293. }
  294. //MARK: - MediaBrowser - Delegate/DataSource
  295. extension NCDetailViewController: MediaBrowserViewControllerDelegate, MediaBrowserViewControllerDataSource {
  296. func viewImage() {
  297. for view in backgroundView.subviews { view.removeFromSuperview() }
  298. if let metadatas = getMetadatasMediaBrowser() {
  299. var counter = 0
  300. for metadata in metadatas {
  301. if metadata.ocId == self.metadata!.ocId { mediaBrowserIndexStart = counter }
  302. counter += 1
  303. }
  304. self.metadatas = metadatas
  305. mediaBrowser = MediaBrowserViewController(index: mediaBrowserIndexStart, dataSource: self, delegate: self)
  306. if mediaBrowser != nil {
  307. self.backgroundView.image = nil
  308. mediaBrowser!.view.isHidden = true
  309. mediaBrowser!.enableInteractiveDismissal = true
  310. addChild(mediaBrowser!)
  311. backgroundView.addSubview(mediaBrowser!.view)
  312. mediaBrowser!.view.frame = CGRect(x: 0, y: 0, width: backgroundView.frame.width, height: backgroundView.frame.height)
  313. mediaBrowser!.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
  314. mediaBrowser!.didMove(toParent: self)
  315. DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
  316. self.mediaBrowser!.changeInViewSize(to: self.backgroundView.frame.size)
  317. self.mediaBrowser!.view.isHidden = false
  318. }
  319. }
  320. }
  321. }
  322. func numberOfItems(in mediaBrowser: MediaBrowserViewController) -> Int {
  323. return metadatas.count
  324. }
  325. func mediaBrowser(_ mediaBrowser: MediaBrowserViewController, imageAt index: Int, completion: @escaping MediaBrowserViewControllerDataSource.CompletionBlock) {
  326. if index >= metadatas.count { return }
  327. let metadata = metadatas[index]
  328. // Refresh self metadata && title
  329. if mediaBrowser.index < metadatas.count {
  330. self.metadata = metadatas[mediaBrowser.index]
  331. self.navigationController?.navigationBar.topItem?.title = self.metadata!.fileNameView
  332. }
  333. // Original only for the first
  334. if CCUtility.fileProviderStorageSize(metadata.ocId, fileNameView: metadata.fileNameView) > 0 && index == mediaBrowserIndexStart {
  335. var image: UIImage?
  336. let imagePath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!
  337. let ext = CCUtility.getExtension(metadata.fileNameView)
  338. if ext == "GIF" { image = UIImage.animatedImage(withAnimatedGIFURL: URL(fileURLWithPath: imagePath)) }
  339. else { image = UIImage.init(contentsOfFile: imagePath) }
  340. if let image = image {
  341. completion(index, image, ZoomScale.default, nil)
  342. } else {
  343. completion(index, self.getImageOffOutline(), ZoomScale.default, nil)
  344. }
  345. // Preview
  346. } else if CCUtility.fileProviderStorageIconExists(metadata.ocId, fileNameView: metadata.fileNameView) {
  347. let imagePath = CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, fileNameView: metadata.fileNameView)!
  348. if let image = UIImage.init(contentsOfFile: imagePath) {
  349. completion(index, image, ZoomScale.default, nil)
  350. } else {
  351. completion(index, self.getImageOffOutline(), ZoomScale.default, nil)
  352. }
  353. } else {
  354. let fileNamePath = CCUtility.returnFileNamePath(fromFileName: metadata.fileName, serverUrl: metadata.serverUrl, activeUrl: appDelegate.activeUrl)!
  355. let fileNameLocalPath = CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, fileNameView: metadata.fileNameView)!
  356. NCCommunication.sharedInstance.downloadPreview(serverUrl: appDelegate.activeUrl, fileNamePath: fileNamePath, fileNameLocalPath: fileNameLocalPath, width: NCUtility.sharedInstance.getScreenWidthForPreview(), height: NCUtility.sharedInstance.getScreenHeightForPreview(), account: metadata.account) { (account, data, errorCode, errorMessage) in
  357. if errorCode == 0 && data != nil {
  358. do {
  359. let url = URL.init(fileURLWithPath: fileNameLocalPath)
  360. try data!.write(to: url, options: .atomic)
  361. completion(index, UIImage.init(data: data!), ZoomScale.default, nil)
  362. } catch {
  363. completion(index, self.getImageOffOutline(), ZoomScale.default, nil)
  364. }
  365. } else {
  366. completion(index, self.getImageOffOutline(), ZoomScale.default, nil)
  367. }
  368. }
  369. }
  370. }
  371. func mediaBrowser(_ mediaBrowser: MediaBrowserViewController, didChangeFocusTo index: Int, view: MediaContentView) {
  372. if index >= metadatas.count { return }
  373. let metadata = metadatas[index]
  374. DispatchQueue.global().async {
  375. if CCUtility.fileProviderStorageSize(metadata.ocId, fileNameView: metadata.fileNameView) > 0 {
  376. var image: UIImage?
  377. let imagePath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!
  378. let ext = CCUtility.getExtension(metadata.fileNameView)
  379. if ext == "GIF" { image = UIImage.animatedImage(withAnimatedGIFURL: URL(fileURLWithPath: imagePath)) }
  380. else { image = UIImage.init(contentsOfFile: imagePath) }
  381. if let image = image {
  382. DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(150)) {
  383. view.image = image
  384. }
  385. }
  386. }
  387. }
  388. }
  389. func mediaBrowserTap(_ mediaBrowser: MediaBrowserViewController) {
  390. guard let navigationController = self.navigationController else { return }
  391. if navigationController.isNavigationBarHidden {
  392. navigationController.isNavigationBarHidden = false
  393. view.backgroundColor = NCBrandColor.sharedInstance.backgroundView
  394. } else {
  395. navigationController.isNavigationBarHidden = true
  396. view.backgroundColor = .black
  397. }
  398. mediaBrowser.changeInViewSize(to: self.backgroundView.frame.size)
  399. }
  400. func mediaBrowserDismiss() {
  401. viewUnload()
  402. }
  403. func getMetadatasMediaBrowser() -> [tableMetadata]? {
  404. guard let metadata = self.metadata else { return nil }
  405. if favoriteFilterImage {
  406. return NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND favorite == 1 AND typeFile == %@", metadata.account, k_metadataTypeFile_image), sorted: CCUtility.getOrderSettings(), ascending: CCUtility.getAscendingSettings())
  407. } else if mediaFilterImage {
  408. return NCManageDatabase.sharedInstance.getMedias(account: metadata.account, predicate: NSPredicate(format: "account == %@ AND typeFile == %@", metadata.account, k_metadataTypeFile_image))
  409. } else if offlineFilterImage {
  410. var datasourceSorted = ""
  411. var datasourceAscending = true
  412. (_, datasourceSorted, datasourceAscending, _, _) = NCUtility.sharedInstance.getLayoutForView(key: k_layout_view_offline)
  413. if let files = NCManageDatabase.sharedInstance.getTableLocalFiles(predicate: NSPredicate(format: "account == %@ AND offline == true", appDelegate.activeAccount), sorted: datasourceSorted, ascending: datasourceAscending) {
  414. var ocIds = [String]()
  415. for file: tableLocalFile in files {
  416. ocIds.append(file.ocId)
  417. }
  418. return NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND ocId IN %@", appDelegate.activeAccount, ocIds), sorted: datasourceSorted, ascending: datasourceAscending)
  419. }
  420. } else {
  421. return NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND typeFile == %@", metadata.account, metadata.serverUrl, k_metadataTypeFile_image), sorted: CCUtility.getOrderSettings(), ascending: CCUtility.getAscendingSettings())
  422. }
  423. return nil
  424. }
  425. func getImageOffOutline() -> UIImage {
  426. let image = CCGraphics.changeThemingColorImage(UIImage.init(named: "imageOffOutline"), width: self.view.frame.width, height: self.view.frame.width, color: NCBrandColor.sharedInstance.brand)
  427. return image!
  428. }
  429. }