NCCollectionCommon.swift 26 KB

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