NCCollectionCommon.swift 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  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 cellPlayImage = UIImage()
  48. }
  49. // MARK: -
  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. @objc func createFolder() {
  69. let serverUrl = appDelegate.activeServerUrl
  70. }
  71. /*
  72. - (void)createFolder
  73. {
  74. NSString *serverUrl = [appDelegate getTabBarControllerActiveServerUrl];
  75. NSString *message;
  76. UIAlertController *alertController;
  77. if ([serverUrl isEqualToString:[[NCUtility shared] getHomeServerWithUrlBase:appDelegate.urlBase account:appDelegate.account]]) {
  78. message = @"/";
  79. } else {
  80. message = [serverUrl lastPathComponent];
  81. }
  82. alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_create_folder_on_",nil) message:message preferredStyle:UIAlertControllerStyleAlert];
  83. [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  84. [textField addTarget:self action:@selector(minCharTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  85. textField.autocapitalizationType = UITextAutocapitalizationTypeSentences;
  86. }];
  87. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_",nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { }];
  88. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  89. UITextField *fileName = alertController.textFields.firstObject;
  90. [[NCNetworking shared] createFolderWithFileName:[fileName.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] serverUrl:serverUrl account:appDelegate.account urlBase:appDelegate.urlBase overwrite:false completion:^(NSInteger errorCode, NSString *errorDescription) {
  91. if (errorCode != 0){
  92. [[NCContentPresenter shared] messageNotification:@"_error_" description:errorDescription delay:k_dismissAfterSecond type:messageTypeError errorCode:errorCode forced:false];
  93. }
  94. }];
  95. }];
  96. okAction.enabled = NO;
  97. [alertController addAction:cancelAction];
  98. [alertController addAction:okAction];
  99. [self presentViewController:alertController animated:YES completion:nil];
  100. }
  101. */
  102. // MARK: -
  103. 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?) {
  104. var tableShare: tableShare?
  105. // Share
  106. if shares != nil {
  107. for share in shares! {
  108. if share.fileName == metadata.fileName {
  109. tableShare = share
  110. break
  111. }
  112. }
  113. }
  114. // Download preview
  115. if downloadThumbnail {
  116. NCOperationQueue.shared.downloadThumbnail(metadata: metadata, urlBase: appDelegate.urlBase, view: collectionView, indexPath: indexPath)
  117. }
  118. var isShare = false
  119. var isMounted = false
  120. if metadataFolder != nil {
  121. isShare = metadata.permissions.contains(k_permission_shared) && !metadataFolder!.permissions.contains(k_permission_shared)
  122. isMounted = metadata.permissions.contains(k_permission_mounted) && !metadataFolder!.permissions.contains(k_permission_mounted)
  123. }
  124. if cell is NCListCell {
  125. let cell = cell as! NCListCell
  126. cell.delegate = source as? NCListCellDelegate
  127. cell.objectId = metadata.ocId
  128. cell.indexPath = indexPath
  129. cell.labelTitle.text = metadata.fileNameView
  130. cell.labelTitle.textColor = NCBrandColor.sharedInstance.textView
  131. cell.imageStatus.image = nil
  132. cell.imageLocal.image = nil
  133. cell.imageFavorite.image = nil
  134. cell.imageShared.image = nil
  135. cell.imageItem.image = nil
  136. cell.imageItem.backgroundColor = nil
  137. if metadata.directory {
  138. if metadata.e2eEncrypted {
  139. cell.imageItem.image = NCCollectionCommonImages.cellFolderEncryptedImage
  140. } else if isShare {
  141. cell.imageItem.image = NCCollectionCommonImages.cellFolderSharedWithMeImage
  142. } else if (tableShare != nil && tableShare!.shareType != 3) {
  143. cell.imageItem.image = NCCollectionCommonImages.cellFolderSharedWithMeImage
  144. } else if (tableShare != nil && tableShare!.shareType == 3) {
  145. cell.imageItem.image = NCCollectionCommonImages.cellFolderPublicImage
  146. } else if metadata.mountType == "group" {
  147. cell.imageItem.image = NCCollectionCommonImages.cellFolderGroupImage
  148. } else if isMounted {
  149. cell.imageItem.image = NCCollectionCommonImages.cellFolderExternalImage
  150. } else if metadata.fileName == autoUploadFileName && serverUrl == autoUploadDirectory {
  151. cell.imageItem.image = NCCollectionCommonImages.cellFolderAutomaticUploadImage
  152. } else {
  153. cell.imageItem.image = NCCollectionCommonImages.cellFolderImage
  154. }
  155. cell.labelInfo.text = CCUtility.dateDiff(metadata.date as Date)
  156. let lockServerUrl = CCUtility.stringAppendServerUrl(serverUrl, addFileName: metadata.fileName)!
  157. let tableDirectory = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.account, lockServerUrl))
  158. // Local image: offline
  159. if tableDirectory != nil && tableDirectory!.offline {
  160. cell.imageLocal.image = UIImage.init(named: "offlineFlag")
  161. }
  162. } else {
  163. if FileManager().fileExists(atPath: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag)) {
  164. cell.imageItem.image = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag))
  165. } else {
  166. if metadata.hasPreview {
  167. cell.imageItem.backgroundColor = .lightGray
  168. } else {
  169. if metadata.iconName.count > 0 {
  170. cell.imageItem.image = UIImage.init(named: metadata.iconName)
  171. } else {
  172. cell.imageItem.image = UIImage.init(named: "file")
  173. }
  174. }
  175. }
  176. cell.labelInfo.text = CCUtility.dateDiff(metadata.date as Date) + " · " + CCUtility.transformedSize(metadata.size)
  177. // image local
  178. let size = CCUtility.fileProviderStorageSize(metadata.ocId, fileNameView: metadata.fileNameView)
  179. if size > 0 {
  180. let tableLocalFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
  181. if tableLocalFile == nil && size == metadata.size {
  182. NCManageDatabase.sharedInstance.addLocalFile(metadata: metadata)
  183. }
  184. if tableLocalFile?.offline ?? false {
  185. cell.imageLocal.image = UIImage.init(named: "offlineFlag")
  186. } else{
  187. cell.imageLocal.image = UIImage.init(named: "local")
  188. }
  189. }
  190. }
  191. // image Favorite
  192. if metadata.favorite {
  193. cell.imageFavorite.image = NCCollectionCommonImages.cellFavouriteImage
  194. }
  195. // Share image
  196. if (isShare) {
  197. cell.imageShared.image = NCCollectionCommonImages.cellSharedImage
  198. } else if (tableShare != nil && tableShare!.shareType == 3) {
  199. cell.imageShared.image = NCCollectionCommonImages.cellShareByLinkImage
  200. } else if (tableShare != nil && tableShare!.shareType != 3) {
  201. cell.imageShared.image = NCCollectionCommonImages.cellSharedImage
  202. } else {
  203. cell.imageShared.image = NCCollectionCommonImages.cellCanShareImage
  204. }
  205. if metadata.ownerId.count > 0 && metadata.ownerId != appDelegate.userID {
  206. // Load avatar
  207. let fileNameSource = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(appDelegate.user, urlBase: appDelegate.urlBase) + "-" + metadata.ownerId + ".png"
  208. let fileNameSourceAvatar = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(appDelegate.user, urlBase: appDelegate.urlBase) + "-avatar-" + metadata.ownerId + ".png"
  209. if FileManager.default.fileExists(atPath: fileNameSourceAvatar) {
  210. cell.imageShared.image = UIImage(contentsOfFile: fileNameSourceAvatar)
  211. } else if FileManager.default.fileExists(atPath: fileNameSource) {
  212. cell.imageShared.image = NCUtility.shared.createAvatar(fileNameSource: fileNameSource, fileNameSourceAvatar: fileNameSourceAvatar)
  213. } else {
  214. NCCommunication.shared.downloadAvatar(userID: metadata.ownerId, fileNameLocalPath: fileNameSource, size: Int(k_avatar_size)) { (account, data, errorCode, errorMessage) in
  215. if errorCode == 0 && account == self.appDelegate.account {
  216. cell.imageShared.image = NCUtility.shared.createAvatar(fileNameSource: fileNameSource, fileNameSourceAvatar: fileNameSourceAvatar)
  217. }
  218. }
  219. }
  220. }
  221. if isEditMode {
  222. cell.imageItemLeftConstraint.constant = 45
  223. cell.imageSelect.isHidden = false
  224. if selectocId.contains(metadata.ocId) {
  225. cell.imageSelect.image = CCGraphics.scale(UIImage.init(named: "checkedYes"), to: CGSize(width: 50, height: 50), isAspectRation: true)
  226. cell.backgroundView = NCUtility.shared.cellBlurEffect(with: cell.bounds)
  227. } else {
  228. cell.imageSelect.image = CCGraphics.scale(UIImage.init(named: "checkedNo"), to: CGSize(width: 50, height: 50), isAspectRation: true)
  229. cell.backgroundView = nil
  230. }
  231. } else {
  232. cell.imageItemLeftConstraint.constant = 10
  233. cell.imageSelect.isHidden = true
  234. cell.backgroundView = nil
  235. }
  236. // Transfer
  237. if metadata.status == k_metadataStatusInDownload || metadata.status == k_metadataStatusDownloading || metadata.status >= k_metadataStatusTypeUpload {
  238. cell.progressView.isHidden = false
  239. cell.setButtonMore(named: "stop")
  240. } else {
  241. cell.progressView.isHidden = true
  242. cell.progressView.progress = 0.0
  243. cell.setButtonMore(named: "more")
  244. }
  245. // Remove last separator
  246. if collectionView.numberOfItems(inSection: indexPath.section) == indexPath.row + 1 {
  247. cell.separator.isHidden = true
  248. } else {
  249. cell.separator.isHidden = false
  250. }
  251. } else if cell is NCGridCell {
  252. let cell = cell as! NCGridCell
  253. cell.delegate = source as? NCGridCellDelegate
  254. cell.objectId = metadata.ocId
  255. cell.indexPath = indexPath
  256. cell.labelTitle.text = metadata.fileNameView
  257. cell.labelTitle.textColor = NCBrandColor.sharedInstance.textView
  258. cell.imageStatus.image = nil
  259. cell.imageLocal.image = nil
  260. cell.imageFavorite.image = nil
  261. cell.imageItem.image = nil
  262. cell.imageItem.backgroundColor = nil
  263. if metadata.directory {
  264. if metadata.e2eEncrypted {
  265. cell.imageItem.image = NCCollectionCommonImages.cellFolderEncryptedImage
  266. } else if isShare {
  267. cell.imageItem.image = NCCollectionCommonImages.cellFolderSharedWithMeImage
  268. } else if (tableShare != nil && tableShare!.shareType != 3) {
  269. cell.imageItem.image = NCCollectionCommonImages.cellFolderSharedWithMeImage
  270. } else if (tableShare != nil && tableShare!.shareType == 3) {
  271. cell.imageItem.image = NCCollectionCommonImages.cellFolderPublicImage
  272. } else if metadata.mountType == "group" {
  273. cell.imageItem.image = NCCollectionCommonImages.cellFolderGroupImage
  274. } else if isMounted {
  275. cell.imageItem.image = NCCollectionCommonImages.cellFolderExternalImage
  276. } else if metadata.fileName == autoUploadFileName && serverUrl == autoUploadDirectory {
  277. cell.imageItem.image = NCCollectionCommonImages.cellFolderAutomaticUploadImage
  278. } else {
  279. cell.imageItem.image = NCCollectionCommonImages.cellFolderImage
  280. }
  281. let lockServerUrl = CCUtility.stringAppendServerUrl(serverUrl, addFileName: metadata.fileName)!
  282. let tableDirectory = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.account, lockServerUrl))
  283. // Local image: offline
  284. if tableDirectory != nil && tableDirectory!.offline {
  285. cell.imageLocal.image = UIImage.init(named: "offlineFlag")
  286. }
  287. } else {
  288. if FileManager().fileExists(atPath: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag)) {
  289. cell.imageItem.image = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag))
  290. } else {
  291. if metadata.hasPreview {
  292. cell.imageItem.backgroundColor = .lightGray
  293. } else {
  294. if metadata.iconName.count > 0 {
  295. cell.imageItem.image = UIImage.init(named: metadata.iconName)
  296. } else {
  297. cell.imageItem.image = UIImage.init(named: "file")
  298. }
  299. }
  300. }
  301. // image Local
  302. let tableLocalFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
  303. if tableLocalFile != nil && CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
  304. if tableLocalFile!.offline { cell.imageLocal.image = UIImage.init(named: "offlineFlag") }
  305. else { cell.imageLocal.image = UIImage.init(named: "local") }
  306. }
  307. }
  308. // image Favorite
  309. if metadata.favorite {
  310. cell.imageFavorite.image = NCCollectionCommonImages.cellFavouriteImage
  311. }
  312. if isEditMode {
  313. cell.imageSelect.isHidden = false
  314. if selectocId.contains(metadata.ocId) {
  315. cell.imageSelect.image = CCGraphics.scale(UIImage.init(named: "checkedYes"), to: CGSize(width: 50, height: 50), isAspectRation: true)
  316. cell.backgroundView = NCUtility.shared.cellBlurEffect(with: cell.bounds)
  317. } else {
  318. cell.imageSelect.isHidden = true
  319. cell.backgroundView = nil
  320. }
  321. } else {
  322. cell.imageSelect.isHidden = true
  323. cell.backgroundView = nil
  324. }
  325. // Transfer
  326. if metadata.status == k_metadataStatusInDownload || metadata.status == k_metadataStatusDownloading || metadata.status >= k_metadataStatusTypeUpload {
  327. cell.progressView.isHidden = false
  328. cell.setButtonMore(named: "stop")
  329. } else {
  330. cell.progressView.isHidden = true
  331. cell.progressView.progress = 0.0
  332. cell.setButtonMore(named: "more")
  333. }
  334. }
  335. }
  336. }
  337. // MARK: - List Layout
  338. class NCListLayout: UICollectionViewFlowLayout {
  339. let itemHeight: CGFloat = 60
  340. override init() {
  341. super.init()
  342. sectionHeadersPinToVisibleBounds = false
  343. minimumInteritemSpacing = 0
  344. minimumLineSpacing = 1
  345. self.scrollDirection = .vertical
  346. self.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
  347. }
  348. required init?(coder aDecoder: NSCoder) {
  349. fatalError("init(coder:) has not been implemented")
  350. }
  351. override var itemSize: CGSize {
  352. get {
  353. if let collectionView = collectionView {
  354. let itemWidth: CGFloat = collectionView.frame.width
  355. return CGSize(width: itemWidth, height: self.itemHeight)
  356. }
  357. // Default fallback
  358. return CGSize(width: 100, height: 100)
  359. }
  360. set {
  361. super.itemSize = newValue
  362. }
  363. }
  364. override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint) -> CGPoint {
  365. return proposedContentOffset
  366. }
  367. }
  368. // MARK: - Grid Layout
  369. class NCGridLayout: UICollectionViewFlowLayout {
  370. var heightLabelPlusButton: CGFloat = 45
  371. var marginLeftRight: CGFloat = 6
  372. var itemForLine: CGFloat = 3
  373. override init() {
  374. super.init()
  375. sectionHeadersPinToVisibleBounds = false
  376. minimumInteritemSpacing = 1
  377. minimumLineSpacing = marginLeftRight
  378. self.scrollDirection = .vertical
  379. self.sectionInset = UIEdgeInsets(top: 10, left: marginLeftRight, bottom: 0, right: marginLeftRight)
  380. }
  381. required init?(coder aDecoder: NSCoder) {
  382. fatalError("init(coder:) has not been implemented")
  383. }
  384. override var itemSize: CGSize {
  385. get {
  386. if let collectionView = collectionView {
  387. let itemWidth: CGFloat = (collectionView.frame.width - marginLeftRight * 2 - marginLeftRight * (itemForLine - 1)) / itemForLine
  388. let itemHeight: CGFloat = itemWidth + heightLabelPlusButton
  389. return CGSize(width: itemWidth, height: itemHeight)
  390. }
  391. // Default fallback
  392. return CGSize(width: 100, height: 100)
  393. }
  394. set {
  395. super.itemSize = newValue
  396. }
  397. }
  398. override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint) -> CGPoint {
  399. return proposedContentOffset
  400. }
  401. }
  402. // MARK: - NCSelect + Delegate
  403. extension NCCollectionCommon: NCSelectDelegate {
  404. func dismissSelect(serverUrl: String?, metadata: tableMetadata?, type: String, array: [Any], buttonType: String, overwrite: Bool) {
  405. if (serverUrl != nil && array.count > 0) {
  406. var move = true
  407. if buttonType == "done1" { move = false }
  408. for metadata in array as! [tableMetadata] {
  409. NCOperationQueue.shared.copyMove(metadata: metadata, serverUrl: serverUrl!, overwrite: overwrite, move: move)
  410. }
  411. }
  412. }
  413. func openSelectView(viewController: UIViewController, array: [Any]) {
  414. let navigationController = UIStoryboard.init(name: "NCSelect", bundle: nil).instantiateInitialViewController() as! UINavigationController
  415. let vc = navigationController.topViewController as! NCSelect
  416. vc.delegate = self
  417. vc.hideButtonCreateFolder = false
  418. vc.selectFile = false
  419. vc.includeDirectoryE2EEncryption = false
  420. vc.includeImages = false
  421. vc.type = ""
  422. vc.titleButtonDone = NSLocalizedString("_move_", comment: "")
  423. vc.titleButtonDone1 = NSLocalizedString("_copy_",comment: "")
  424. vc.isButtonDone1Hide = false
  425. vc.isOverwriteHide = false
  426. vc.keyLayout = k_layout_view_move
  427. vc.array = array
  428. navigationController.modalPresentationStyle = .fullScreen
  429. viewController.present(navigationController, animated: true, completion: nil)
  430. }
  431. }