NCMainCommon.swift 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971
  1. //
  2. // NCMainCommon.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 18/07/18.
  6. // Copyright © 2018 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 TLPhotoPicker
  25. import ZIPFoundation
  26. import NCCommunication
  27. //MARK: - Main Common
  28. class NCMainCommon: NSObject, NCAudioRecorderViewControllerDelegate, UIDocumentInteractionControllerDelegate {
  29. @objc static let sharedInstance: NCMainCommon = {
  30. let instance = NCMainCommon()
  31. instance.createImagesThemingColor()
  32. return instance
  33. }()
  34. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  35. var metadataEditPhoto: tableMetadata?
  36. var docController: UIDocumentInteractionController?
  37. //MARK: -
  38. struct NCMainCommonImages {
  39. static var cellSharedImage = UIImage()
  40. static var cellCanShareImage = UIImage()
  41. static var cellShareByLinkImage = UIImage()
  42. static var cellFavouriteImage = UIImage()
  43. static var cellMoreImage = UIImage()
  44. static var cellCommentImage = UIImage()
  45. static var cellFolderEncryptedImage = UIImage()
  46. static var cellFolderSharedWithMeImage = UIImage()
  47. static var cellFolderPublicImage = UIImage()
  48. static var cellFolderGroupImage = UIImage()
  49. static var cellFolderExternalImage = UIImage()
  50. static var cellFolderAutomaticUploadImage = UIImage()
  51. static var cellFolderImage = UIImage()
  52. static var cellPlayImage = UIImage()
  53. }
  54. @objc func createImagesThemingColor() {
  55. NCMainCommonImages.cellSharedImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "share"), width: 100, height: 100, color: NCBrandColor.sharedInstance.textView)
  56. NCMainCommonImages.cellCanShareImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "share"), width: 100, height: 100, color: NCBrandColor.sharedInstance.optionItem)
  57. NCMainCommonImages.cellShareByLinkImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "sharebylink"), width: 100, height: 100, color: NCBrandColor.sharedInstance.optionItem)
  58. NCMainCommonImages.cellFavouriteImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "favorite"), width: 100, height: 100, color: NCBrandColor.sharedInstance.yellowFavorite)
  59. NCMainCommonImages.cellMoreImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "more"), width: 50, height: 50, color: NCBrandColor.sharedInstance.optionItem)
  60. NCMainCommonImages.cellCommentImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "comment"), width: 30, height: 30, color: NCBrandColor.sharedInstance.graySoft)
  61. NCMainCommonImages.cellFolderEncryptedImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "folderEncrypted"), width: 600, height: 600, color: NCBrandColor.sharedInstance.brandElement)
  62. NCMainCommonImages.cellFolderSharedWithMeImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "folder_shared_with_me"), width: 600, height: 600, color: NCBrandColor.sharedInstance.brandElement)
  63. NCMainCommonImages.cellFolderPublicImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "folder_public"), width: 600, height: 600, color: NCBrandColor.sharedInstance.brandElement)
  64. NCMainCommonImages.cellFolderGroupImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "folder_group"), width: 600, height: 600, color: NCBrandColor.sharedInstance.brandElement)
  65. NCMainCommonImages.cellFolderExternalImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "folder_external"), width: 600, height: 600, color: NCBrandColor.sharedInstance.brandElement)
  66. NCMainCommonImages.cellFolderAutomaticUploadImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "folderAutomaticUpload"), width: 600, height: 600, color: NCBrandColor.sharedInstance.brandElement)
  67. NCMainCommonImages.cellFolderImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "folder"), width: 600, height: 600, color: NCBrandColor.sharedInstance.brandElement)
  68. NCMainCommonImages.cellPlayImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "play"), width: 100, height: 100, color: .white)
  69. }
  70. //MARK: -
  71. @objc func triggerProgressTask(_ notification: Notification, sectionDataSourceocIdIndexPath: NSDictionary, tableView: UITableView, viewController: UIViewController, serverUrlViewController: String?) {
  72. if viewController.viewIfLoaded?.window == nil {
  73. return
  74. }
  75. guard let dic = notification.userInfo else {
  76. return
  77. }
  78. let account = dic["account"] as? NSString ?? ""
  79. let ocId = dic["ocId"] as? NSString ?? ""
  80. let serverUrl = dic["serverUrl"] as? String ?? ""
  81. let status = dic["status"] as? Int ?? Int(k_metadataStatusNormal)
  82. let progress = dic["progress"] as? CGFloat ?? 0
  83. let totalBytes = dic["totalBytes"] as? Double ?? 0
  84. let totalBytesExpected = dic["totalBytesExpected"] as? Double ?? 0
  85. if (account != self.appDelegate.activeAccount! as NSString) && !(viewController is CCTransfers) {
  86. return
  87. }
  88. if serverUrlViewController != nil && serverUrlViewController! != serverUrl {
  89. return
  90. }
  91. appDelegate.listProgressMetadata.setObject([progress as NSNumber, totalBytes as NSNumber, totalBytesExpected as NSNumber], forKey: ocId)
  92. guard let indexPath = sectionDataSourceocIdIndexPath.object(forKey: ocId) else {
  93. return
  94. }
  95. if isValidIndexPath(indexPath as! IndexPath, view: tableView) {
  96. if let cell = tableView.cellForRow(at: indexPath as! IndexPath) as? CCCellMainTransfer {
  97. var image = ""
  98. if status == k_metadataStatusInDownload {
  99. image = "↓"
  100. } else if status == k_metadataStatusInUpload {
  101. image = "↑"
  102. }
  103. cell.labelInfoFile?.text = CCUtility.transformedSize(totalBytesExpected) + " - " + image + CCUtility.transformedSize(totalBytes)
  104. cell.transferButton?.progress = progress
  105. }
  106. }
  107. }
  108. @objc func cancelTransferMetadata(_ metadata: tableMetadata, reloadDatasource: Bool, uploadStatusForcedStart: Bool) {
  109. if metadata.session.count == 0 { return }
  110. if metadata.session == NCCommunicationCommon.shared.sessionIdentifierDownload {
  111. NCNetworking.shared.cancelDownload(metadata: metadata)
  112. } else if metadata.session == NCCommunicationCommon.shared.sessionIdentifierUpload {
  113. NCNetworking.shared.cancelUpload(metadata: metadata)
  114. } else {
  115. guard let session = CCNetworking.shared().getSessionfromSessionDescription(metadata.session) else { return }
  116. var metadata = metadata
  117. session.getTasksWithCompletionHandler { (dataTasks, uploadTasks, downloadTasks) in
  118. var cancel = false
  119. if metadata.session.count > 0 && metadata.session.contains("upload") {
  120. for task in uploadTasks {
  121. if task.taskIdentifier == metadata.sessionTaskIdentifier {
  122. if uploadStatusForcedStart {
  123. metadata.status = Int(k_metadataStatusUploadForcedStart)
  124. metadata = NCManageDatabase.sharedInstance.addMetadata(metadata) ?? metadata
  125. }
  126. task.cancel()
  127. cancel = true
  128. }
  129. }
  130. if cancel == false {
  131. do {
  132. try FileManager.default.removeItem(atPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId))
  133. }
  134. catch { }
  135. NCManageDatabase.sharedInstance.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
  136. }
  137. }
  138. }
  139. }
  140. }
  141. @objc func cancelAllTransfer() {
  142. // Delete k_metadataStatusWaitUpload OR k_metadataStatusUploadError
  143. NCManageDatabase.sharedInstance.deleteMetadata(predicate: NSPredicate(format: "status == %d OR status == %d", appDelegate.activeAccount, k_metadataStatusWaitUpload, k_metadataStatusUploadError))
  144. DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
  145. if let metadatas = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "status != %d", k_metadataStatusNormal), sorted: "fileName", ascending: true) {
  146. for metadata in metadatas {
  147. // Modify
  148. if (metadata.status == k_metadataStatusWaitDownload || metadata.status == k_metadataStatusDownloadError) {
  149. metadata.session = ""
  150. metadata.sessionSelector = ""
  151. metadata.status = Int(k_metadataStatusNormal)
  152. NCManageDatabase.sharedInstance.addMetadata(metadata)
  153. }
  154. // Cancel Task
  155. if metadata.status == k_metadataStatusDownloading || metadata.status == k_metadataStatusUploading {
  156. self.cancelTransferMetadata(metadata, reloadDatasource: false, uploadStatusForcedStart: false)
  157. }
  158. }
  159. }
  160. }
  161. }
  162. //MARK: -
  163. func collectionViewCellForItemAt(_ indexPath: IndexPath, collectionView: UICollectionView, cell: UICollectionViewCell, metadata: tableMetadata, metadataFolder: tableMetadata?, serverUrl: String, isEditMode: Bool, selectocId: [String], autoUploadFileName: String, autoUploadDirectory: String, hideButtonMore: Bool, downloadThumbnail: Bool, shares: [tableShare]?, source: UIViewController) {
  164. var tableShare: tableShare?
  165. // Share
  166. if shares != nil {
  167. for share in shares! {
  168. if share.fileName == metadata.fileName {
  169. tableShare = share
  170. break
  171. }
  172. }
  173. }
  174. // Download preview
  175. if downloadThumbnail {
  176. NCOperationQueue.shared.downloadThumbnail(metadata: metadata, activeUrl: appDelegate.activeUrl, view: collectionView, indexPath: indexPath)
  177. }
  178. var isShare = false
  179. var isMounted = false
  180. if metadataFolder != nil {
  181. isShare = metadata.permissions.contains(k_permission_shared) && !metadataFolder!.permissions.contains(k_permission_shared)
  182. isMounted = metadata.permissions.contains(k_permission_mounted) && !metadataFolder!.permissions.contains(k_permission_mounted)
  183. }
  184. if cell is NCListCell {
  185. let cell = cell as! NCListCell
  186. cell.delegate = source as? NCListCellDelegate
  187. cell.objectId = metadata.ocId
  188. cell.indexPath = indexPath
  189. cell.labelTitle.text = metadata.fileNameView
  190. cell.labelTitle.textColor = NCBrandColor.sharedInstance.textView
  191. cell.imageStatus.image = nil
  192. cell.imageLocal.image = nil
  193. cell.imageFavorite.image = nil
  194. cell.shared.image = nil
  195. if metadata.directory {
  196. if metadata.e2eEncrypted {
  197. cell.imageItem.image = NCMainCommonImages.cellFolderEncryptedImage
  198. } else if isShare {
  199. cell.imageItem.image = NCMainCommonImages.cellFolderSharedWithMeImage
  200. } else if (tableShare != nil && tableShare!.shareType != Int(shareTypeLink.rawValue)) {
  201. cell.imageItem.image = NCMainCommonImages.cellFolderSharedWithMeImage
  202. } else if (tableShare != nil && tableShare!.shareType == Int(shareTypeLink.rawValue)) {
  203. cell.imageItem.image = NCMainCommonImages.cellFolderPublicImage
  204. } else if metadata.mountType == "group" {
  205. cell.imageItem.image = NCMainCommonImages.cellFolderGroupImage
  206. } else if isMounted {
  207. cell.imageItem.image = NCMainCommonImages.cellFolderExternalImage
  208. } else if metadata.fileName == autoUploadFileName && serverUrl == autoUploadDirectory {
  209. cell.imageItem.image = NCMainCommonImages.cellFolderAutomaticUploadImage
  210. } else {
  211. cell.imageItem.image = NCMainCommonImages.cellFolderImage
  212. }
  213. cell.labelInfo.text = CCUtility.dateDiff(metadata.date as Date)
  214. let lockServerUrl = CCUtility.stringAppendServerUrl(serverUrl, addFileName: metadata.fileName)!
  215. let tableDirectory = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.activeAccount, lockServerUrl))
  216. // Local image: offline
  217. if tableDirectory != nil && tableDirectory!.offline {
  218. cell.imageLocal.image = UIImage.init(named: "offlineFlag")
  219. }
  220. } else {
  221. if FileManager().fileExists(atPath: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, fileNameView: metadata.fileNameView)) {
  222. cell.imageItem.image = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, fileNameView: metadata.fileNameView))
  223. } else {
  224. if metadata.iconName.count > 0 {
  225. cell.imageItem.image = UIImage.init(named: metadata.iconName)
  226. } else {
  227. cell.imageItem.image = UIImage.init(named: "file")
  228. }
  229. }
  230. cell.labelInfo.text = CCUtility.dateDiff(metadata.date as Date) + " · " + CCUtility.transformedSize(metadata.size)
  231. // image local
  232. let size = CCUtility.fileProviderStorageSize(metadata.ocId, fileNameView: metadata.fileNameView)
  233. if size > 0 {
  234. var tableLocalFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
  235. if tableLocalFile == nil && size == metadata.size {
  236. tableLocalFile = NCManageDatabase.sharedInstance.addLocalFile(metadata: metadata)
  237. }
  238. if tableLocalFile!.offline { cell.imageLocal.image = UIImage.init(named: "offlineFlag") }
  239. else { cell.imageLocal.image = UIImage.init(named: "local") }
  240. }
  241. }
  242. // image Favorite
  243. if metadata.favorite {
  244. cell.imageFavorite.image = NCMainCommonImages.cellFavouriteImage
  245. }
  246. // Share image
  247. if (isShare) {
  248. cell.shared.image = NCMainCommonImages.cellSharedImage
  249. } else if (tableShare != nil && tableShare!.shareType == Int(shareTypeLink.rawValue)) {
  250. cell.shared.image = NCMainCommonImages.cellShareByLinkImage
  251. } else if (tableShare != nil && tableShare!.shareType != Int(shareTypeLink.rawValue)) {
  252. cell.shared.image = NCMainCommonImages.cellSharedImage
  253. } else {
  254. cell.shared.image = NCMainCommonImages.cellCanShareImage
  255. }
  256. if metadata.ownerId != appDelegate.activeUserID {
  257. // Load avatar
  258. let fileNameSource = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(appDelegate.activeUser, activeUrl: appDelegate.activeUrl) + "-" + metadata.ownerId + ".png"
  259. let fileNameSourceAvatar = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(appDelegate.activeUser, activeUrl: appDelegate.activeUrl) + "-avatar-" + metadata.ownerId + ".png"
  260. if FileManager.default.fileExists(atPath: fileNameSourceAvatar) {
  261. cell.shared.image = UIImage(contentsOfFile: fileNameSourceAvatar)
  262. } else if FileManager.default.fileExists(atPath: fileNameSource) {
  263. cell.shared.image = NCUtility.sharedInstance.createAvatar(fileNameSource: fileNameSource, fileNameSourceAvatar: fileNameSourceAvatar)
  264. } else {
  265. NCCommunication.shared.downloadAvatar(userID: metadata.ownerId, fileNameLocalPath: fileNameSource, size: Int(k_avatar_size)) { (account, data, errorCode, errorMessage) in
  266. if errorCode == 0 && account == self.appDelegate.activeAccount {
  267. cell.shared.image = NCUtility.sharedInstance.createAvatar(fileNameSource: fileNameSource, fileNameSourceAvatar: fileNameSourceAvatar)
  268. }
  269. }
  270. }
  271. }
  272. if isEditMode {
  273. cell.imageItemLeftConstraint.constant = 45
  274. cell.imageSelect.isHidden = false
  275. if selectocId.contains(metadata.ocId) {
  276. cell.imageSelect.image = CCGraphics.scale(UIImage.init(named: "checkedYes"), to: CGSize(width: 50, height: 50), isAspectRation: true)
  277. cell.backgroundView = NCUtility.sharedInstance.cellBlurEffect(with: cell.bounds)
  278. } else {
  279. cell.imageSelect.image = CCGraphics.scale(UIImage.init(named: "checkedNo"), to: CGSize(width: 50, height: 50), isAspectRation: true)
  280. cell.backgroundView = nil
  281. }
  282. } else {
  283. cell.imageItemLeftConstraint.constant = 10
  284. cell.imageSelect.isHidden = true
  285. cell.backgroundView = nil
  286. }
  287. // Remove last separator
  288. if collectionView.numberOfItems(inSection: indexPath.section) == indexPath.row + 1 {
  289. cell.separator.isHidden = true
  290. } else {
  291. cell.separator.isHidden = false
  292. }
  293. } else if cell is NCGridCell {
  294. let cell = cell as! NCGridCell
  295. cell.delegate = source as? NCGridCellDelegate
  296. cell.objectId = metadata.ocId
  297. cell.indexPath = indexPath
  298. cell.labelTitle.text = metadata.fileNameView
  299. cell.labelTitle.textColor = NCBrandColor.sharedInstance.textView
  300. cell.imageStatus.image = nil
  301. cell.imageLocal.image = nil
  302. cell.imageFavorite.image = nil
  303. if metadata.directory {
  304. if metadata.e2eEncrypted {
  305. cell.imageItem.image = NCMainCommonImages.cellFolderEncryptedImage
  306. } else if isShare {
  307. cell.imageItem.image = NCMainCommonImages.cellFolderSharedWithMeImage
  308. } else if (tableShare != nil && tableShare!.shareType != Int(shareTypeLink.rawValue)) {
  309. cell.imageItem.image = NCMainCommonImages.cellFolderSharedWithMeImage
  310. } else if (tableShare != nil && tableShare!.shareType == Int(shareTypeLink.rawValue)) {
  311. cell.imageItem.image = NCMainCommonImages.cellFolderPublicImage
  312. } else if metadata.mountType == "group" {
  313. cell.imageItem.image = NCMainCommonImages.cellFolderGroupImage
  314. } else if isMounted {
  315. cell.imageItem.image = NCMainCommonImages.cellFolderExternalImage
  316. } else if metadata.fileName == autoUploadFileName && serverUrl == autoUploadDirectory {
  317. cell.imageItem.image = NCMainCommonImages.cellFolderAutomaticUploadImage
  318. } else {
  319. cell.imageItem.image = NCMainCommonImages.cellFolderImage
  320. }
  321. let lockServerUrl = CCUtility.stringAppendServerUrl(serverUrl, addFileName: metadata.fileName)!
  322. let tableDirectory = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.activeAccount, lockServerUrl))
  323. // Local image: offline
  324. if tableDirectory != nil && tableDirectory!.offline {
  325. cell.imageLocal.image = UIImage.init(named: "offlineFlag")
  326. }
  327. } else {
  328. if FileManager().fileExists(atPath: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, fileNameView: metadata.fileNameView)) {
  329. cell.imageItem.image = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, fileNameView: metadata.fileNameView))
  330. } else {
  331. if metadata.iconName.count > 0 {
  332. cell.imageItem.image = UIImage.init(named: metadata.iconName)
  333. } else {
  334. cell.imageItem.image = UIImage.init(named: "file")
  335. }
  336. }
  337. // image Local
  338. let tableLocalFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
  339. if tableLocalFile != nil && CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
  340. if tableLocalFile!.offline { cell.imageLocal.image = UIImage.init(named: "offlineFlag") }
  341. else { cell.imageLocal.image = UIImage.init(named: "local") }
  342. }
  343. }
  344. // image Favorite
  345. if metadata.favorite {
  346. cell.imageFavorite.image = NCMainCommonImages.cellFavouriteImage
  347. }
  348. if isEditMode {
  349. cell.imageSelect.isHidden = false
  350. if selectocId.contains(metadata.ocId) {
  351. cell.imageSelect.image = CCGraphics.scale(UIImage.init(named: "checkedYes"), to: CGSize(width: 50, height: 50), isAspectRation: true)
  352. cell.backgroundView = NCUtility.sharedInstance.cellBlurEffect(with: cell.bounds)
  353. } else {
  354. cell.imageSelect.isHidden = true
  355. cell.backgroundView = nil
  356. }
  357. } else {
  358. cell.imageSelect.isHidden = true
  359. cell.backgroundView = nil
  360. }
  361. }
  362. }
  363. @objc func cellForRowAtIndexPath(_ indexPath: IndexPath, tableView: UITableView ,metadata: tableMetadata, metadataFolder: tableMetadata?, serverUrl: String, autoUploadFileName: String, autoUploadDirectory: String, tableShare: tableShare?) -> UITableViewCell {
  364. // Create File System
  365. if metadata.directory {
  366. CCUtility.getDirectoryProviderStorageOcId(metadata.ocId)
  367. } else {
  368. CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)
  369. }
  370. // CCCell
  371. if metadata.status == k_metadataStatusNormal || metadata.status == k_metadataStatusDownloadError {
  372. // NORMAL
  373. let cell = tableView.dequeueReusableCell(withIdentifier: "CellMain", for: indexPath) as! CCCellMain
  374. cell.separatorInset = UIEdgeInsets.init(top: 0, left: 60, bottom: 0, right: 0)
  375. cell.accessoryType = UITableViewCell.AccessoryType.none
  376. cell.file.image = nil
  377. cell.status.image = nil
  378. cell.favorite.image = nil
  379. cell.shared.image = nil
  380. cell.local.image = nil
  381. cell.comment.image = nil
  382. cell.shared.isUserInteractionEnabled = false
  383. cell.backgroundColor = NCBrandColor.sharedInstance.backgroundView
  384. // change color selection
  385. let selectionColor = UIView()
  386. selectionColor.backgroundColor = NCBrandColor.sharedInstance.select
  387. cell.selectedBackgroundView = selectionColor
  388. cell.tintColor = NCBrandColor.sharedInstance.brandElement
  389. cell.labelTitle.textColor = NCBrandColor.sharedInstance.textView
  390. cell.labelTitle.text = metadata.fileNameView
  391. // Download preview
  392. NCOperationQueue.shared.downloadThumbnail(metadata: metadata, activeUrl: appDelegate.activeUrl, view: tableView, indexPath: indexPath)
  393. // Share
  394. var isShare = false
  395. var isMounted = false
  396. if metadataFolder != nil {
  397. isShare = metadata.permissions.contains(k_permission_shared) && !metadataFolder!.permissions.contains(k_permission_shared)
  398. isMounted = metadata.permissions.contains(k_permission_mounted) && !metadataFolder!.permissions.contains(k_permission_mounted)
  399. }
  400. if metadata.directory {
  401. // lable Info
  402. cell.labelInfoFile.text = CCUtility.dateDiff(metadata.date as Date)
  403. // File Image & Image Title Segue
  404. if metadata.e2eEncrypted {
  405. cell.file.image = NCMainCommonImages.cellFolderEncryptedImage
  406. } else if isShare {
  407. cell.file.image = NCMainCommonImages.cellFolderSharedWithMeImage
  408. } else if (tableShare != nil && tableShare!.shareType != Int(shareTypeLink.rawValue)) {
  409. cell.file.image = NCMainCommonImages.cellFolderSharedWithMeImage
  410. } else if (tableShare != nil && tableShare!.shareType == Int(shareTypeLink.rawValue)) {
  411. cell.file.image = NCMainCommonImages.cellFolderPublicImage
  412. } else if metadata.mountType == "group" {
  413. cell.file.image = NCMainCommonImages.cellFolderGroupImage
  414. } else if isMounted {
  415. cell.file.image = NCMainCommonImages.cellFolderExternalImage
  416. } else if metadata.fileName == autoUploadFileName && serverUrl == autoUploadDirectory {
  417. cell.file.image = NCMainCommonImages.cellFolderAutomaticUploadImage
  418. } else {
  419. cell.file.image = NCMainCommonImages.cellFolderImage
  420. }
  421. let lockServerUrl = CCUtility.stringAppendServerUrl(serverUrl, addFileName: metadata.fileName)!
  422. let tableDirectory = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.activeAccount, lockServerUrl))
  423. // Local image: offline
  424. if tableDirectory != nil && tableDirectory!.offline {
  425. cell.local.image = UIImage.init(named: "offlineFlag")
  426. }
  427. } else {
  428. let iconFileExists = FileManager.default.fileExists(atPath: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, fileNameView: metadata.fileNameView))
  429. // Lable Info
  430. cell.labelInfoFile.text = CCUtility.dateDiff(metadata.date as Date) + " · " + CCUtility.transformedSize(metadata.size)
  431. // File Image
  432. if iconFileExists {
  433. cell.file.image = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, fileNameView: metadata.fileNameView))
  434. } else {
  435. if metadata.iconName.count > 0 {
  436. cell.file.image = UIImage.init(named: metadata.iconName)
  437. } else {
  438. cell.file.image = UIImage.init(named: "file")
  439. }
  440. }
  441. // Local Image - Offline
  442. let size = CCUtility.fileProviderStorageSize(metadata.ocId, fileNameView: metadata.fileNameView)
  443. if size > 0 {
  444. var tableLocalFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
  445. if tableLocalFile == nil && size == metadata.size {
  446. tableLocalFile = NCManageDatabase.sharedInstance.addLocalFile(metadata: metadata)
  447. }
  448. if tableLocalFile != nil && tableLocalFile!.offline { cell.local.image = UIImage.init(named: "offlineFlag") }
  449. else { cell.local.image = UIImage.init(named: "local") }
  450. }
  451. // Status image: encrypted
  452. let tableE2eEncryption = NCManageDatabase.sharedInstance.getE2eEncryption(predicate: NSPredicate(format: "account == %@ AND fileNameIdentifier == %@", appDelegate.activeAccount, metadata.fileName))
  453. if tableE2eEncryption != nil && NCUtility.sharedInstance.isEncryptedMetadata(metadata) {
  454. cell.status.image = UIImage.init(named: "encrypted")
  455. }
  456. }
  457. //
  458. // File & Directory
  459. //
  460. // Favorite
  461. if metadata.favorite {
  462. cell.favorite.image = NCMainCommonImages.cellFavouriteImage
  463. }
  464. // Share image
  465. if !(metadataFolder?.e2eEncrypted ?? false) && !metadata.e2eEncrypted {
  466. if (isShare) {
  467. cell.shared.image = NCMainCommonImages.cellSharedImage
  468. } else if (tableShare != nil && tableShare!.shareType == Int(shareTypeLink.rawValue)) {
  469. cell.shared.image = NCMainCommonImages.cellShareByLinkImage
  470. } else if (tableShare != nil && tableShare!.shareType != Int(shareTypeLink.rawValue)) {
  471. cell.shared.image = NCMainCommonImages.cellSharedImage
  472. } else {
  473. cell.shared.image = NCMainCommonImages.cellCanShareImage
  474. }
  475. if metadata.ownerId != appDelegate.activeUserID {
  476. // Load avatar
  477. let fileNameSource = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(appDelegate.activeUser, activeUrl: appDelegate.activeUrl) + "-" + metadata.ownerId + ".png"
  478. let fileNameSourceAvatar = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(appDelegate.activeUser, activeUrl: appDelegate.activeUrl) + "-avatar-" + metadata.ownerId + ".png"
  479. if FileManager.default.fileExists(atPath: fileNameSourceAvatar) {
  480. if let avatar = UIImage(contentsOfFile: fileNameSourceAvatar) {
  481. cell.shared.image = avatar
  482. }
  483. } else if FileManager.default.fileExists(atPath: fileNameSource) {
  484. if let avatar = NCUtility.sharedInstance.createAvatar(fileNameSource: fileNameSource, fileNameSourceAvatar: fileNameSourceAvatar) {
  485. cell.shared.image = avatar
  486. }
  487. } else {
  488. NCCommunication.shared.downloadAvatar(userID: metadata.ownerId, fileNameLocalPath: fileNameSource, size: Int(k_avatar_size)) { (account, data, errorCode, errorMessage) in
  489. if errorCode == 0 && account == self.appDelegate.activeAccount {
  490. cell.shared.image = NCUtility.sharedInstance.createAvatar(fileNameSource: fileNameSource, fileNameSourceAvatar: fileNameSourceAvatar)
  491. }
  492. }
  493. }
  494. }
  495. }
  496. // Comment
  497. if metadata.commentsUnread {
  498. cell.comment.image = NCMainCommonImages.cellCommentImage
  499. cell.labelTitleTrailingConstraint.constant = 160
  500. } else {
  501. cell.labelTitleTrailingConstraint.constant = 110
  502. }
  503. // More Image
  504. cell.more.image = NCMainCommonImages.cellMoreImage
  505. // downloadFile Error
  506. if metadata.status == k_metadataStatusDownloadError {
  507. cell.status.image = UIImage.init(named: "statuserror")
  508. if metadata.sessionError.count == 0 {
  509. cell.labelInfoFile.text = NSLocalizedString("_error_", comment: "") + ", " + NSLocalizedString("_file_not_downloaded_", comment: "")
  510. } else {
  511. cell.labelInfoFile.text = metadata.sessionError
  512. }
  513. }
  514. return cell
  515. } else {
  516. // TRASNFER
  517. let cell = tableView.dequeueReusableCell(withIdentifier: "CellMainTransfer", for: indexPath) as! CCCellMainTransfer
  518. cell.separatorInset = UIEdgeInsets.init(top: 0, left: 60, bottom: 0, right: 0)
  519. cell.accessoryType = UITableViewCell.AccessoryType.none
  520. cell.file.image = nil
  521. cell.status.image = nil
  522. cell.user.image = nil
  523. cell.backgroundColor = NCBrandColor.sharedInstance.backgroundView
  524. cell.labelTitle.text = metadata.fileNameView
  525. cell.labelTitle.textColor = NCBrandColor.sharedInstance.textView
  526. cell.transferButton.tintColor = NCBrandColor.sharedInstance.optionItem
  527. cell.labelTitle.isEnabled = true
  528. cell.labelInfoFile.isEnabled = true
  529. var progress: CGFloat = 0.0
  530. var totalBytes: Double = 0.0
  531. //var totalBytesExpected : Double = 0
  532. let progressArray = appDelegate.listProgressMetadata.object(forKey: metadata.ocId) as? NSArray
  533. if progressArray != nil && progressArray?.count == 3 {
  534. progress = progressArray?.object(at: 0) as! CGFloat
  535. totalBytes = progressArray?.object(at: 1) as! Double
  536. //totalBytesExpected = progressArray?.object(at: 2) as! Double
  537. }
  538. // Write status on Label Info
  539. switch metadata.status {
  540. case Int(k_metadataStatusWaitDownload):
  541. cell.labelInfoFile.text = CCUtility.transformedSize(metadata.size) + " - " + NSLocalizedString("_status_wait_download_", comment: "")
  542. progress = 0.0
  543. break
  544. case Int(k_metadataStatusInDownload):
  545. cell.labelInfoFile.text = CCUtility.transformedSize(metadata.size) + " - " + NSLocalizedString("_status_in_download_", comment: "")
  546. progress = 0.0
  547. break
  548. case Int(k_metadataStatusDownloading):
  549. cell.labelInfoFile.text = CCUtility.transformedSize(metadata.size) + " - ↓" + CCUtility.transformedSize(totalBytes)
  550. break
  551. case Int(k_metadataStatusWaitUpload):
  552. cell.labelInfoFile.text = CCUtility.transformedSize(metadata.size) + " - " + NSLocalizedString("_status_wait_upload_", comment: "")
  553. progress = 0.0
  554. break
  555. case Int(k_metadataStatusInUpload):
  556. cell.labelInfoFile.text = CCUtility.transformedSize(metadata.size) + " - " + NSLocalizedString("_status_in_upload_", comment: "")
  557. progress = 0.0
  558. break
  559. case Int(k_metadataStatusUploading):
  560. cell.labelInfoFile.text = CCUtility.transformedSize(metadata.size) + " - ↑" + CCUtility.transformedSize(totalBytes)
  561. break
  562. default:
  563. cell.labelInfoFile.text = CCUtility.transformedSize(metadata.size)
  564. progress = 0.0
  565. }
  566. let iconFileExists = FileManager.default.fileExists(atPath: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, fileNameView: metadata.fileNameView))
  567. if iconFileExists {
  568. cell.file.image = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, fileNameView: metadata.fileNameView))
  569. } else {
  570. if metadata.iconName.count > 0 {
  571. cell.file.image = UIImage.init(named: metadata.iconName)
  572. } else {
  573. cell.file.image = UIImage.init(named: "file")
  574. }
  575. }
  576. // uploadFile
  577. if metadata.status == k_metadataStatusWaitUpload || metadata.status == k_metadataStatusInUpload || metadata.status == k_metadataStatusUploading || metadata.status == k_metadataStatusUploadError {
  578. if (!iconFileExists) {
  579. cell.file.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "uploadCloud"), multiplier: 2, color: NCBrandColor.sharedInstance.brandElement)
  580. }
  581. cell.labelTitle.isEnabled = false
  582. }
  583. // uploadFileError
  584. if metadata.status == k_metadataStatusUploadError {
  585. cell.labelTitle.isEnabled = false
  586. cell.status.image = UIImage.init(named: "statuserror")
  587. if !iconFileExists {
  588. cell.file.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "uploadCloud"), multiplier: 2, color: NCBrandColor.sharedInstance.brandElement)
  589. }
  590. if metadata.sessionError.count == 0 {
  591. cell.labelInfoFile.text = NSLocalizedString("_error_", comment: "") + ", " + NSLocalizedString("_file_not_uploaded_", comment: "")
  592. } else {
  593. cell.labelInfoFile.text = metadata.sessionError
  594. }
  595. }
  596. // Progress
  597. cell.transferButton.progress = progress
  598. // User
  599. if metadata.account != appDelegate.activeAccount {
  600. let tableAccount = NCManageDatabase.sharedInstance.getAccount(predicate: NSPredicate(format: "account == %@", metadata.account))
  601. if tableAccount != nil {
  602. let fileNamePath = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(tableAccount!.user, activeUrl: tableAccount!.url) + "-" + tableAccount!.user + ".png"
  603. var avatar = UIImage.init(contentsOfFile: fileNamePath)
  604. if avatar != nil {
  605. let avatarImageView = CCAvatar.init(image: avatar, borderColor: UIColor.black, borderWidth: 0.5)
  606. let imageSize = avatarImageView?.bounds.size
  607. UIGraphicsBeginImageContext(imageSize!)
  608. let context = UIGraphicsGetCurrentContext()
  609. avatarImageView?.layer.render(in: context!)
  610. avatar = UIGraphicsGetImageFromCurrentImageContext()
  611. UIGraphicsEndImageContext()
  612. cell.user.image = avatar
  613. }
  614. }
  615. }
  616. return cell
  617. }
  618. }
  619. @objc func getMetadataFromSectionDataSourceIndexPath(_ indexPath: IndexPath?, sectionDataSource: CCSectionDataSourceMetadata?) -> tableMetadata? {
  620. guard let indexPath = indexPath else {
  621. return nil
  622. }
  623. guard let sectionDataSource = sectionDataSource else {
  624. return nil
  625. }
  626. let section = indexPath.section + 1
  627. let row = indexPath.row + 1
  628. let totSections = sectionDataSource.sections.count
  629. if totSections < section || section > totSections {
  630. return nil
  631. }
  632. let valueSection = sectionDataSource.sections.object(at: indexPath.section)
  633. guard let filesID = sectionDataSource.sectionArrayRow.object(forKey: valueSection) as? NSArray else {
  634. return nil
  635. }
  636. let totRows = filesID.count
  637. if totRows < row || row > totRows {
  638. return nil
  639. }
  640. let ocId = filesID.object(at: indexPath.row)
  641. let metadata = sectionDataSource.allRecordsDataSource.object(forKey: ocId) as? tableMetadata
  642. return metadata
  643. }
  644. @objc func isValidIndexPath(_ indexPath: IndexPath, view: Any) -> Bool {
  645. if view is UICollectionView {
  646. return indexPath.section < (view as! UICollectionView).numberOfSections && indexPath.row < (view as! UICollectionView).numberOfItems(inSection: indexPath.section)
  647. }
  648. if view is UITableView {
  649. return indexPath.section < (view as! UITableView).numberOfSections && indexPath.row < (view as! UITableView).numberOfRows(inSection: indexPath.section)
  650. }
  651. return true
  652. }
  653. //MARK: - download Open Selector
  654. @objc func downloadOpen(metadata: tableMetadata, selector: String) {
  655. if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
  656. NotificationCenter.default.post(name: Notification.Name.init(rawValue: k_notificationCenter_downloadedFile), object: nil, userInfo: ["metadata": metadata, "selector": selector, "errorCode": 0, "errorDescription": "" ])
  657. } else {
  658. NCNetworking.shared.download(metadata: metadata, selector: selector) { (_) in }
  659. }
  660. }
  661. //MARK: - OpenIn
  662. func openIn(metadata: tableMetadata, selector: String) {
  663. docController = UIDocumentInteractionController(url: NSURL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)) as URL)
  664. docController?.delegate = self
  665. if selector == selectorOpenInDetail {
  666. guard let barButtonItem = appDelegate.activeDetail.navigationItem.rightBarButtonItem else { return }
  667. guard let buttonItemView = barButtonItem.value(forKey: "view") as? UIView else { return }
  668. docController?.presentOptionsMenu(from: buttonItemView.frame, in: buttonItemView, animated: true)
  669. } else {
  670. guard let splitViewController = self.appDelegate.window?.rootViewController as? UISplitViewController, let view = splitViewController.viewControllers.first?.view, let frame = splitViewController.viewControllers.first?.view.frame else {
  671. return }
  672. docController?.presentOptionsMenu(from: frame, in: view, animated: true)
  673. }
  674. }
  675. //MARK: - OpenShare
  676. @objc func openShare(ViewController: UIViewController, metadata: tableMetadata, indexPage: Int) {
  677. let shareNavigationController = UIStoryboard(name: "NCShare", bundle: nil).instantiateInitialViewController() as! UINavigationController
  678. let shareViewController = shareNavigationController.topViewController as! NCSharePaging
  679. shareViewController.metadata = metadata
  680. shareViewController.indexPage = indexPage
  681. shareNavigationController.modalPresentationStyle = .formSheet
  682. ViewController.present(shareNavigationController, animated: true, completion: nil)
  683. }
  684. //MARK: - NCAudioRecorder
  685. func startAudioRecorder() {
  686. let fileName = CCUtility.createFileNameDate(NSLocalizedString("_voice_memo_filename_", comment: ""), extension: "m4a")!
  687. let viewController = UIStoryboard(name: "NCAudioRecorderViewController", bundle: nil).instantiateInitialViewController() as! NCAudioRecorderViewController
  688. viewController.delegate = self
  689. viewController.createRecorder(fileName: fileName)
  690. viewController.modalTransitionStyle = .crossDissolve
  691. viewController.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
  692. self.appDelegate.window.rootViewController?.present(viewController, animated: true, completion: nil)
  693. }
  694. func didFinishRecording(_ viewController: NCAudioRecorderViewController, fileName: String) {
  695. guard let navigationController = UIStoryboard(name: "NCCreateFormUploadVoiceNote", bundle: nil).instantiateInitialViewController() else { return }
  696. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  697. let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadVoiceNote
  698. viewController.setup(serverUrl: appDelegate.activeMain.serverUrl, fileNamePath: NSTemporaryDirectory() + fileName, fileName: fileName)
  699. self.appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
  700. }
  701. func didFinishWithoutRecording(_ viewController: NCAudioRecorderViewController, fileName: String) {
  702. }
  703. }
  704. //MARK: - Main TabBarController
  705. class CCMainTabBarController : UITabBarController, UITabBarControllerDelegate {
  706. override func viewDidLoad() {
  707. super.viewDidLoad()
  708. delegate = self
  709. }
  710. //Delegate methods
  711. func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
  712. let tabViewControllers = tabBarController.viewControllers!
  713. guard let toIndex = tabViewControllers.firstIndex(of: viewController) else {
  714. if let vc = viewController as? UINavigationController {
  715. vc.popToRootViewController(animated: true);
  716. }
  717. return false
  718. }
  719. animateToTab(toIndex: toIndex)
  720. return true
  721. }
  722. func animateToTab(toIndex: Int) {
  723. let tabViewControllers = viewControllers!
  724. let fromView = selectedViewController!.view!
  725. let toView = tabViewControllers[toIndex].view!
  726. let fromIndex = tabViewControllers.firstIndex(of: selectedViewController!)
  727. guard fromIndex != toIndex else {return}
  728. // Add the toView to the tab bar view
  729. fromView.superview?.addSubview(toView)
  730. fromView.superview?.backgroundColor = NCBrandColor.sharedInstance.backgroundView
  731. // Position toView off screen (to the left/right of fromView)
  732. let screenWidth = UIScreen.main.bounds.size.width;
  733. let scrollRight = toIndex > fromIndex!;
  734. let offset = (scrollRight ? screenWidth : -screenWidth)
  735. toView.center = CGPoint(x: (fromView.center.x) + offset, y: (toView.center.y))
  736. // Disable interaction during animation
  737. view.isUserInteractionEnabled = false
  738. UIView.animate(withDuration: 0.3, delay: 0.0, usingSpringWithDamping: 1, initialSpringVelocity: 0, options: UIView.AnimationOptions.curveEaseOut, animations: {
  739. // Slide the views by -offset
  740. fromView.center = CGPoint(x: fromView.center.x - offset, y: fromView.center.y);
  741. toView.center = CGPoint(x: toView.center.x - offset, y: toView.center.y);
  742. }, completion: { finished in
  743. // Remove the old view from the tabbar view.
  744. fromView.removeFromSuperview()
  745. self.selectedIndex = toIndex
  746. self.view.isUserInteractionEnabled = true
  747. })
  748. }
  749. }
  750. //MARK: - Function Main
  751. class NCFunctionMain: NSObject {
  752. @objc static let sharedInstance: NCFunctionMain = {
  753. let instance = NCFunctionMain()
  754. return instance
  755. }()
  756. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  757. @objc func synchronizeOffline() {
  758. let directories = NCManageDatabase.sharedInstance.getTablesDirectory(predicate: NSPredicate(format: "account == %@ AND offline == true", appDelegate.activeAccount), sorted: "serverUrl", ascending: true)
  759. if (directories != nil) {
  760. for directory: tableDirectory in directories! {
  761. CCSynchronize.shared()?.readFolder(directory.serverUrl, selector: selectorReadFolderWithDownload, account: appDelegate.activeAccount)
  762. }
  763. }
  764. let files = NCManageDatabase.sharedInstance.getTableLocalFiles(predicate: NSPredicate(format: "account == %@ AND offline == true", appDelegate.activeAccount), sorted: "fileName", ascending: true)
  765. if (files != nil) {
  766. for file: tableLocalFile in files! {
  767. guard let metadata = NCManageDatabase.sharedInstance.getMetadata(predicate: NSPredicate(format: "ocId == %@", file.ocId)) else {
  768. continue
  769. }
  770. CCSynchronize.shared()?.readFile(metadata.ocId, fileName: metadata.fileName, serverUrl: metadata.serverUrl, selector: selectorReadFileWithDownload, account: appDelegate.activeAccount)
  771. }
  772. }
  773. }
  774. }