NCCollectionCommon.swift 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. //
  2. // NCCollectionCommon.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 08/09/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 TLPhotoPicker
  25. import ZIPFoundation
  26. import NCCommunication
  27. class NCCollectionCommon: NSObject {
  28. @objc static let shared: NCCollectionCommon = {
  29. let instance = NCCollectionCommon()
  30. instance.createImagesThemingColor()
  31. return instance
  32. }()
  33. struct NCCollectionCommonImages {
  34. static var cellSharedImage = UIImage()
  35. static var cellCanShareImage = UIImage()
  36. static var cellShareByLinkImage = UIImage()
  37. static var cellFavouriteImage = UIImage()
  38. static var cellMoreImage = UIImage()
  39. static var cellCommentImage = UIImage()
  40. static var cellLivePhotoImage = UIImage()
  41. static var cellFolderEncryptedImage = UIImage()
  42. static var cellFolderSharedWithMeImage = UIImage()
  43. static var cellFolderPublicImage = UIImage()
  44. static var cellFolderGroupImage = UIImage()
  45. static var cellFolderExternalImage = UIImage()
  46. static var cellFolderAutomaticUploadImage = UIImage()
  47. static var cellFolderImage = UIImage()
  48. static var cellPlayImage = UIImage()
  49. }
  50. @objc func createImagesThemingColor() {
  51. NCCollectionCommonImages.cellSharedImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "share"), width: 100, height: 100, color: NCBrandColor.sharedInstance.textView)
  52. NCCollectionCommonImages.cellCanShareImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "share"), width: 100, height: 100, color: NCBrandColor.sharedInstance.optionItem)
  53. NCCollectionCommonImages.cellShareByLinkImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "sharebylink"), width: 100, height: 100, color: NCBrandColor.sharedInstance.optionItem)
  54. NCCollectionCommonImages.cellFavouriteImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "favorite"), width: 100, height: 100, color: NCBrandColor.sharedInstance.yellowFavorite)
  55. NCCollectionCommonImages.cellMoreImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "more"), width: 50, height: 50, color: NCBrandColor.sharedInstance.optionItem)
  56. NCCollectionCommonImages.cellCommentImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "comment"), width: 30, height: 30, color: NCBrandColor.sharedInstance.graySoft)
  57. NCCollectionCommonImages.cellLivePhotoImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "livePhoto"), width: 100, height: 100, color: NCBrandColor.sharedInstance.textView)
  58. NCCollectionCommonImages.cellFolderEncryptedImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "folderEncrypted"), width: 600, height: 600, color: NCBrandColor.sharedInstance.brandElement)
  59. NCCollectionCommonImages.cellFolderSharedWithMeImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "folder_shared_with_me"), width: 600, height: 600, color: NCBrandColor.sharedInstance.brandElement)
  60. NCCollectionCommonImages.cellFolderPublicImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "folder_public"), width: 600, height: 600, color: NCBrandColor.sharedInstance.brandElement)
  61. NCCollectionCommonImages.cellFolderGroupImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "folder_group"), width: 600, height: 600, color: NCBrandColor.sharedInstance.brandElement)
  62. NCCollectionCommonImages.cellFolderExternalImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "folder_external"), width: 600, height: 600, color: NCBrandColor.sharedInstance.brandElement)
  63. NCCollectionCommonImages.cellFolderAutomaticUploadImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "folderAutomaticUpload"), width: 600, height: 600, color: NCBrandColor.sharedInstance.brandElement)
  64. NCCollectionCommonImages.cellFolderImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "folder"), width: 600, height: 600, color: NCBrandColor.sharedInstance.brandElement)
  65. NCCollectionCommonImages.cellPlayImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "play"), width: 100, height: 100, color: .white)
  66. }
  67. // MARK -
  68. func cellForItemAt(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) {
  69. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  70. var tableShare: tableShare?
  71. // Share
  72. if shares != nil {
  73. for share in shares! {
  74. if share.fileName == metadata.fileName {
  75. tableShare = share
  76. break
  77. }
  78. }
  79. }
  80. // Download preview
  81. if downloadThumbnail {
  82. NCOperationQueue.shared.downloadThumbnail(metadata: metadata, urlBase: appDelegate.urlBase, view: collectionView, indexPath: indexPath)
  83. }
  84. var isShare = false
  85. var isMounted = false
  86. if metadataFolder != nil {
  87. isShare = metadata.permissions.contains(k_permission_shared) && !metadataFolder!.permissions.contains(k_permission_shared)
  88. isMounted = metadata.permissions.contains(k_permission_mounted) && !metadataFolder!.permissions.contains(k_permission_mounted)
  89. }
  90. if cell is NCListCell {
  91. let cell = cell as! NCListCell
  92. cell.delegate = source as? NCListCellDelegate
  93. cell.objectId = metadata.ocId
  94. cell.indexPath = indexPath
  95. cell.labelTitle.text = metadata.fileNameView
  96. cell.labelTitle.textColor = NCBrandColor.sharedInstance.textView
  97. cell.imageStatus.image = nil
  98. cell.imageLocal.image = nil
  99. cell.imageFavorite.image = nil
  100. cell.imageShared.image = nil
  101. if metadata.directory {
  102. if metadata.e2eEncrypted {
  103. cell.imageItem.image = NCCollectionCommonImages.cellFolderEncryptedImage
  104. } else if isShare {
  105. cell.imageItem.image = NCCollectionCommonImages.cellFolderSharedWithMeImage
  106. } else if (tableShare != nil && tableShare!.shareType != 3) {
  107. cell.imageItem.image = NCCollectionCommonImages.cellFolderSharedWithMeImage
  108. } else if (tableShare != nil && tableShare!.shareType == 3) {
  109. cell.imageItem.image = NCCollectionCommonImages.cellFolderPublicImage
  110. } else if metadata.mountType == "group" {
  111. cell.imageItem.image = NCCollectionCommonImages.cellFolderGroupImage
  112. } else if isMounted {
  113. cell.imageItem.image = NCCollectionCommonImages.cellFolderExternalImage
  114. } else if metadata.fileName == autoUploadFileName && serverUrl == autoUploadDirectory {
  115. cell.imageItem.image = NCCollectionCommonImages.cellFolderAutomaticUploadImage
  116. } else {
  117. cell.imageItem.image = NCCollectionCommonImages.cellFolderImage
  118. }
  119. cell.labelInfo.text = CCUtility.dateDiff(metadata.date as Date)
  120. let lockServerUrl = CCUtility.stringAppendServerUrl(serverUrl, addFileName: metadata.fileName)!
  121. let tableDirectory = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.account, lockServerUrl))
  122. // Local image: offline
  123. if tableDirectory != nil && tableDirectory!.offline {
  124. cell.imageLocal.image = UIImage.init(named: "offlineFlag")
  125. }
  126. } else {
  127. if FileManager().fileExists(atPath: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag)) {
  128. cell.imageItem.image = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag))
  129. } else if(!metadata.hasPreview) {
  130. if metadata.iconName.count > 0 {
  131. cell.imageItem.image = UIImage.init(named: metadata.iconName)
  132. } else {
  133. cell.imageItem.image = UIImage.init(named: "file")
  134. }
  135. }
  136. cell.labelInfo.text = CCUtility.dateDiff(metadata.date as Date) + " · " + CCUtility.transformedSize(metadata.size)
  137. // image local
  138. let size = CCUtility.fileProviderStorageSize(metadata.ocId, fileNameView: metadata.fileNameView)
  139. if size > 0 {
  140. let tableLocalFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
  141. if tableLocalFile == nil && size == metadata.size {
  142. NCManageDatabase.sharedInstance.addLocalFile(metadata: metadata)
  143. }
  144. if tableLocalFile?.offline ?? false {
  145. cell.imageLocal.image = UIImage.init(named: "offlineFlag")
  146. } else{
  147. cell.imageLocal.image = UIImage.init(named: "local")
  148. }
  149. }
  150. }
  151. // image Favorite
  152. if metadata.favorite {
  153. cell.imageFavorite.image = NCCollectionCommonImages.cellFavouriteImage
  154. }
  155. // Share image
  156. if (isShare) {
  157. cell.imageShared.image = NCCollectionCommonImages.cellSharedImage
  158. } else if (tableShare != nil && tableShare!.shareType == 3) {
  159. cell.imageShared.image = NCCollectionCommonImages.cellShareByLinkImage
  160. } else if (tableShare != nil && tableShare!.shareType != 3) {
  161. cell.imageShared.image = NCCollectionCommonImages.cellSharedImage
  162. } else {
  163. cell.imageShared.image = NCCollectionCommonImages.cellCanShareImage
  164. }
  165. if metadata.ownerId.count > 0 && metadata.ownerId != appDelegate.userID {
  166. // Load avatar
  167. let fileNameSource = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(appDelegate.user, urlBase: appDelegate.urlBase) + "-" + metadata.ownerId + ".png"
  168. let fileNameSourceAvatar = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(appDelegate.user, urlBase: appDelegate.urlBase) + "-avatar-" + metadata.ownerId + ".png"
  169. if FileManager.default.fileExists(atPath: fileNameSourceAvatar) {
  170. cell.imageShared.image = UIImage(contentsOfFile: fileNameSourceAvatar)
  171. } else if FileManager.default.fileExists(atPath: fileNameSource) {
  172. cell.imageShared.image = NCUtility.shared.createAvatar(fileNameSource: fileNameSource, fileNameSourceAvatar: fileNameSourceAvatar)
  173. } else {
  174. NCCommunication.shared.downloadAvatar(userID: metadata.ownerId, fileNameLocalPath: fileNameSource, size: Int(k_avatar_size)) { (account, data, errorCode, errorMessage) in
  175. if errorCode == 0 && account == appDelegate.account {
  176. cell.imageShared.image = NCUtility.shared.createAvatar(fileNameSource: fileNameSource, fileNameSourceAvatar: fileNameSourceAvatar)
  177. }
  178. }
  179. }
  180. }
  181. if isEditMode {
  182. cell.imageItemLeftConstraint.constant = 45
  183. cell.imageSelect.isHidden = false
  184. if selectocId.contains(metadata.ocId) {
  185. cell.imageSelect.image = CCGraphics.scale(UIImage.init(named: "checkedYes"), to: CGSize(width: 50, height: 50), isAspectRation: true)
  186. cell.backgroundView = NCUtility.shared.cellBlurEffect(with: cell.bounds)
  187. } else {
  188. cell.imageSelect.image = CCGraphics.scale(UIImage.init(named: "checkedNo"), to: CGSize(width: 50, height: 50), isAspectRation: true)
  189. cell.backgroundView = nil
  190. }
  191. } else {
  192. cell.imageItemLeftConstraint.constant = 10
  193. cell.imageSelect.isHidden = true
  194. cell.backgroundView = nil
  195. }
  196. // Transfer
  197. if metadata.status == k_metadataStatusInDownload || metadata.status == k_metadataStatusDownloading || metadata.status >= k_metadataStatusTypeUpload {
  198. cell.progressView.isHidden = false
  199. cell.setButtonMore(named: "stop")
  200. } else {
  201. cell.progressView.isHidden = true
  202. cell.progressView.progress = 0.0
  203. cell.setButtonMore(named: "more")
  204. }
  205. // Remove last separator
  206. if collectionView.numberOfItems(inSection: indexPath.section) == indexPath.row + 1 {
  207. cell.separator.isHidden = true
  208. } else {
  209. cell.separator.isHidden = false
  210. }
  211. } else if cell is NCGridCell {
  212. let cell = cell as! NCGridCell
  213. cell.delegate = source as? NCGridCellDelegate
  214. cell.objectId = metadata.ocId
  215. cell.indexPath = indexPath
  216. cell.labelTitle.text = metadata.fileNameView
  217. cell.labelTitle.textColor = NCBrandColor.sharedInstance.textView
  218. cell.imageStatus.image = nil
  219. cell.imageLocal.image = nil
  220. cell.imageFavorite.image = nil
  221. if metadata.directory {
  222. if metadata.e2eEncrypted {
  223. cell.imageItem.image = NCCollectionCommonImages.cellFolderEncryptedImage
  224. } else if isShare {
  225. cell.imageItem.image = NCCollectionCommonImages.cellFolderSharedWithMeImage
  226. } else if (tableShare != nil && tableShare!.shareType != 3) {
  227. cell.imageItem.image = NCCollectionCommonImages.cellFolderSharedWithMeImage
  228. } else if (tableShare != nil && tableShare!.shareType == 3) {
  229. cell.imageItem.image = NCCollectionCommonImages.cellFolderPublicImage
  230. } else if metadata.mountType == "group" {
  231. cell.imageItem.image = NCCollectionCommonImages.cellFolderGroupImage
  232. } else if isMounted {
  233. cell.imageItem.image = NCCollectionCommonImages.cellFolderExternalImage
  234. } else if metadata.fileName == autoUploadFileName && serverUrl == autoUploadDirectory {
  235. cell.imageItem.image = NCCollectionCommonImages.cellFolderAutomaticUploadImage
  236. } else {
  237. cell.imageItem.image = NCCollectionCommonImages.cellFolderImage
  238. }
  239. let lockServerUrl = CCUtility.stringAppendServerUrl(serverUrl, addFileName: metadata.fileName)!
  240. let tableDirectory = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.account, lockServerUrl))
  241. // Local image: offline
  242. if tableDirectory != nil && tableDirectory!.offline {
  243. cell.imageLocal.image = UIImage.init(named: "offlineFlag")
  244. }
  245. } else {
  246. if FileManager().fileExists(atPath: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag)) {
  247. cell.imageItem.image = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag))
  248. } else if(!metadata.hasPreview) {
  249. if metadata.iconName.count > 0 {
  250. cell.imageItem.image = UIImage.init(named: metadata.iconName)
  251. } else {
  252. cell.imageItem.image = UIImage.init(named: "file")
  253. }
  254. }
  255. // image Local
  256. let tableLocalFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
  257. if tableLocalFile != nil && CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
  258. if tableLocalFile!.offline { cell.imageLocal.image = UIImage.init(named: "offlineFlag") }
  259. else { cell.imageLocal.image = UIImage.init(named: "local") }
  260. }
  261. }
  262. // image Favorite
  263. if metadata.favorite {
  264. cell.imageFavorite.image = NCCollectionCommonImages.cellFavouriteImage
  265. }
  266. if isEditMode {
  267. cell.imageSelect.isHidden = false
  268. if selectocId.contains(metadata.ocId) {
  269. cell.imageSelect.image = CCGraphics.scale(UIImage.init(named: "checkedYes"), to: CGSize(width: 50, height: 50), isAspectRation: true)
  270. cell.backgroundView = NCUtility.shared.cellBlurEffect(with: cell.bounds)
  271. } else {
  272. cell.imageSelect.isHidden = true
  273. cell.backgroundView = nil
  274. }
  275. } else {
  276. cell.imageSelect.isHidden = true
  277. cell.backgroundView = nil
  278. }
  279. // Transfer
  280. if metadata.status == k_metadataStatusInDownload || metadata.status == k_metadataStatusDownloading || metadata.status >= k_metadataStatusTypeUpload {
  281. cell.progressView.isHidden = false
  282. cell.setButtonMore(named: "stop")
  283. } else {
  284. cell.progressView.isHidden = true
  285. cell.progressView.progress = 0.0
  286. cell.setButtonMore(named: "more")
  287. }
  288. }
  289. }
  290. // MARK -
  291. func notificationDeleteFile(collectionView: UICollectionView?, dataSource: NCDataSource?, metadata: tableMetadata, errorCode: Int, errorDescription: String ,onlyLocal: Bool) {
  292. if errorCode == 0 {
  293. if !onlyLocal {
  294. _ = dataSource?.deleteMetadata(ocId: metadata.ocId)
  295. }
  296. collectionView?.reloadData()
  297. } else {
  298. NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: errorCode)
  299. }
  300. }
  301. func notificationDownloadFileStart(collectionView: UICollectionView?, dataSource: NCDataSource?, metadata: tableMetadata) {
  302. if dataSource?.reloadMetadata(ocId: metadata.ocId) ?? false {
  303. collectionView?.reloadData()
  304. }
  305. }
  306. func notificationDownloadedFile(collectionView: UICollectionView?, dataSource: NCDataSource?, metadata: tableMetadata) {
  307. if dataSource?.reloadMetadata(ocId: metadata.ocId) ?? false {
  308. collectionView?.reloadData()
  309. }
  310. }
  311. func notificationUploadedFile(collectionView: UICollectionView?, dataSource: NCDataSource?, metadata: tableMetadata, serverUrl: String, account: String) {
  312. if metadata.serverUrl == serverUrl && metadata.account == account {
  313. if dataSource?.reloadMetadata(ocId: metadata.ocId) ?? false {
  314. collectionView?.reloadData()
  315. }
  316. }
  317. }
  318. func notificationUploadFileStart(collectionView: UICollectionView?, dataSource: NCDataSource?, metadata: tableMetadata, serverUrl: String, account: String) {
  319. if metadata.serverUrl == serverUrl && metadata.account == account {
  320. dataSource?.addMetadata(metadata)
  321. collectionView?.reloadData()
  322. }
  323. }
  324. func notificationTriggerProgressTask(collectionView: UICollectionView?, dataSource: NCDataSource?, ocId: String, progress: Float) {
  325. if let index = dataSource?.getIndexMetadata(ocId: ocId) {
  326. if let cell = collectionView?.cellForItem(at: IndexPath(row: index, section: 0)) {
  327. if cell is NCListCell {
  328. let cell = cell as! NCListCell
  329. if progress > 0 {
  330. cell.progressView?.isHidden = false
  331. cell.progressView?.progress = progress
  332. cell.setButtonMore(named: "stop")
  333. }
  334. } else if cell is NCGridCell {
  335. let cell = cell as! NCGridCell
  336. if progress > 0 {
  337. cell.progressView.isHidden = false
  338. cell.progressView.progress = progress
  339. cell.setButtonMore(named: "stop")
  340. }
  341. }
  342. }
  343. }
  344. }
  345. }
  346. // MARK: - List Layout
  347. class NCListLayout: UICollectionViewFlowLayout {
  348. let itemHeight: CGFloat = 60
  349. override init() {
  350. super.init()
  351. sectionHeadersPinToVisibleBounds = false
  352. minimumInteritemSpacing = 0
  353. minimumLineSpacing = 1
  354. self.scrollDirection = .vertical
  355. self.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
  356. }
  357. required init?(coder aDecoder: NSCoder) {
  358. fatalError("init(coder:) has not been implemented")
  359. }
  360. override var itemSize: CGSize {
  361. get {
  362. if let collectionView = collectionView {
  363. let itemWidth: CGFloat = collectionView.frame.width
  364. return CGSize(width: itemWidth, height: self.itemHeight)
  365. }
  366. // Default fallback
  367. return CGSize(width: 100, height: 100)
  368. }
  369. set {
  370. super.itemSize = newValue
  371. }
  372. }
  373. override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint) -> CGPoint {
  374. return proposedContentOffset
  375. }
  376. }
  377. // MARK: - Grid Layout
  378. class NCGridLayout: UICollectionViewFlowLayout {
  379. var heightLabelPlusButton: CGFloat = 45
  380. var marginLeftRight: CGFloat = 6
  381. var itemForLine: CGFloat = 3
  382. override init() {
  383. super.init()
  384. sectionHeadersPinToVisibleBounds = false
  385. minimumInteritemSpacing = 1
  386. minimumLineSpacing = marginLeftRight
  387. self.scrollDirection = .vertical
  388. self.sectionInset = UIEdgeInsets(top: 10, left: marginLeftRight, bottom: 0, right: marginLeftRight)
  389. }
  390. required init?(coder aDecoder: NSCoder) {
  391. fatalError("init(coder:) has not been implemented")
  392. }
  393. override var itemSize: CGSize {
  394. get {
  395. if let collectionView = collectionView {
  396. let itemWidth: CGFloat = (collectionView.frame.width - marginLeftRight * 2 - marginLeftRight * (itemForLine - 1)) / itemForLine
  397. let itemHeight: CGFloat = itemWidth + heightLabelPlusButton
  398. return CGSize(width: itemWidth, height: itemHeight)
  399. }
  400. // Default fallback
  401. return CGSize(width: 100, height: 100)
  402. }
  403. set {
  404. super.itemSize = newValue
  405. }
  406. }
  407. override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint) -> CGPoint {
  408. return proposedContentOffset
  409. }
  410. }
  411. // MARK: - NCSelect
  412. extension NCCollectionCommon: NCSelectDelegate {
  413. func dismissSelect(serverUrl: String?, metadata: tableMetadata?, type: String, array: [Any], buttonType: String, overwrite: Bool) {
  414. if (serverUrl != nil && array.count > 0) {
  415. var move = true
  416. if buttonType == "done1" { move = false }
  417. for metadata in array as! [tableMetadata] {
  418. NCOperationQueue.shared.copyMove(metadata: metadata, serverUrl: serverUrl!, overwrite: overwrite, move: move)
  419. }
  420. }
  421. }
  422. func openSelectView(viewController: UIViewController, array: [Any]) {
  423. let navigationController = UIStoryboard.init(name: "NCSelect", bundle: nil).instantiateInitialViewController() as! UINavigationController
  424. let vc = navigationController.topViewController as! NCSelect
  425. vc.delegate = self
  426. vc.hideButtonCreateFolder = false
  427. vc.selectFile = false
  428. vc.includeDirectoryE2EEncryption = false
  429. vc.includeImages = false
  430. vc.type = ""
  431. vc.titleButtonDone = NSLocalizedString("_move_", comment: "")
  432. vc.titleButtonDone1 = NSLocalizedString("_copy_",comment: "")
  433. vc.isButtonDone1Hide = false
  434. vc.isOverwriteHide = false
  435. vc.keyLayout = k_layout_view_move
  436. vc.array = array
  437. navigationController.modalPresentationStyle = .fullScreen
  438. viewController.present(navigationController, animated: true, completion: nil)
  439. }
  440. }