NCScanCollectionView.swift 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. //
  2. // NCScanCollectionView.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 21/08/18.
  6. // Copyright (c) 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 UIKit
  24. @available(iOS 13.0, *)
  25. class NCScanCollectionView: UIViewController {
  26. // Data Source for collectionViewSource
  27. private var itemsSource: [String] = []
  28. // Data Source for collectionViewDestination
  29. private var imagesDestination: [UIImage] = []
  30. private var itemsDestination: [String] = []
  31. private let appDelegate = (UIApplication.shared.delegate as? AppDelegate)!
  32. // MARK: Outlets
  33. @IBOutlet weak var collectionViewSource: UICollectionView!
  34. @IBOutlet weak var collectionViewDestination: UICollectionView!
  35. @IBOutlet weak var cancel: UIBarButtonItem!
  36. @IBOutlet weak var save: UIBarButtonItem!
  37. @IBOutlet weak var add: UIButton!
  38. @IBOutlet weak var transferDown: UIButton!
  39. @IBOutlet weak var labelTitlePDFzone: UILabel!
  40. @IBOutlet weak var segmentControlFilter: UISegmentedControl!
  41. // filter
  42. enum TypeFilter {
  43. case original
  44. case grayScale
  45. case bn
  46. }
  47. private var filter: TypeFilter = TypeFilter.original
  48. override var canBecomeFirstResponder: Bool { return true }
  49. // MARK: - View Life Cycle
  50. override func viewDidLoad() {
  51. super.viewDidLoad()
  52. view.backgroundColor = NCBrandColor.shared.secondarySystemGroupedBackground
  53. navigationItem.title = NSLocalizedString("_scanned_images_", comment: "")
  54. collectionViewSource.dragInteractionEnabled = true
  55. collectionViewSource.dragDelegate = self
  56. collectionViewSource.dropDelegate = self
  57. collectionViewSource.backgroundColor = NCBrandColor.shared.secondarySystemGroupedBackground
  58. collectionViewDestination.dragInteractionEnabled = true
  59. collectionViewDestination.dropDelegate = self
  60. collectionViewDestination.dragDelegate = self
  61. collectionViewDestination.reorderingCadence = .fast // default value - .immediate
  62. collectionViewDestination.backgroundColor = NCBrandColor.shared.secondarySystemGroupedBackground
  63. cancel.title = NSLocalizedString("_cancel_", comment: "")
  64. save.title = NSLocalizedString("_save_", comment: "")
  65. labelTitlePDFzone.text = NSLocalizedString("_scan_label_document_zone_", comment: "")
  66. labelTitlePDFzone.backgroundColor = NCBrandColor.shared.systemGray6
  67. labelTitlePDFzone.textColor = NCBrandColor.shared.label
  68. segmentControlFilter.setTitle(NSLocalizedString("_filter_original_", comment: ""), forSegmentAt: 0)
  69. segmentControlFilter.setTitle(NSLocalizedString("_filter_grayscale_", comment: ""), forSegmentAt: 1)
  70. segmentControlFilter.setTitle(NSLocalizedString("_filter_bn_", comment: ""), forSegmentAt: 2)
  71. add.setImage(UIImage(named: "plus")?.image(color: NCBrandColor.shared.label, size: 25), for: .normal)
  72. transferDown.setImage(UIImage(named: "transferDown")?.image(color: NCBrandColor.shared.label, size: 25), for: .normal)
  73. let longPressRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(handleLongPressGesture(recognizer:)))
  74. collectionViewSource.addGestureRecognizer(longPressRecognizer)
  75. let longPressRecognizerPlus = UILongPressGestureRecognizer(target: self, action: #selector(handleLongPressGesture(recognizer:)))
  76. add.addGestureRecognizer(longPressRecognizerPlus)
  77. collectionViewSource.reloadData()
  78. collectionViewDestination.reloadData()
  79. loadImage()
  80. }
  81. override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
  82. super.traitCollectionDidChange(previousTraitCollection)
  83. add.setImage(UIImage(named: "plus")?.image(color: NCBrandColor.shared.label, size: 25), for: .normal)
  84. transferDown.setImage(UIImage(named: "transferDown")?.image(color: NCBrandColor.shared.label, size: 25), for: .normal)
  85. }
  86. // MARK: Button Action
  87. @IBAction func cancelAction(sender: UIBarButtonItem) {
  88. self.dismiss(animated: true, completion: nil)
  89. }
  90. @IBAction func saveAction(sender: UIBarButtonItem) {
  91. if imagesDestination.count > 0 {
  92. var images: [UIImage] = []
  93. let serverUrl = appDelegate.activeServerUrl
  94. for image in imagesDestination {
  95. images.append(filter(image: image)!)
  96. }
  97. // if let directory = CCUtility.getDirectoryScanDocuments() {
  98. // serverUrl = directory
  99. // }
  100. let formViewController = NCCreateFormUploadScanDocument(serverUrl: serverUrl, arrayImages: images)
  101. self.navigationController?.pushViewController(formViewController, animated: true)
  102. }
  103. }
  104. @IBAction func add(sender: UIButton) {
  105. NCCreateScanDocument.shared.openScannerDocument(viewController: self)
  106. }
  107. @IBAction func transferDown(sender: UIButton) {
  108. for fileName in itemsSource {
  109. if !itemsDestination.contains(fileName) {
  110. let fileNamePathAt = CCUtility.getDirectoryScan() + "/" + fileName
  111. guard let data = try? Data(contentsOf: URL(fileURLWithPath: fileNamePathAt)) else { return }
  112. guard let image = UIImage(data: data) else { return }
  113. imagesDestination.append(image)
  114. itemsDestination.append(fileName)
  115. }
  116. }
  117. // Save button
  118. if imagesDestination.count == 0 {
  119. save.isEnabled = false
  120. } else {
  121. save.isEnabled = true
  122. }
  123. collectionViewDestination.reloadData()
  124. }
  125. @IBAction func indexChanged(_ sender: AnyObject) {
  126. switch segmentControlFilter.selectedSegmentIndex {
  127. case 0:
  128. filter = .original
  129. case 1:
  130. filter = .grayScale
  131. case 2:
  132. filter = .bn
  133. default:
  134. break
  135. }
  136. collectionViewDestination.reloadData()
  137. }
  138. func loadImage() {
  139. itemsSource.removeAll()
  140. do {
  141. let atPath = CCUtility.getDirectoryScan()!
  142. let directoryContents = try FileManager.default.contentsOfDirectory(atPath: atPath)
  143. for fileName in directoryContents {
  144. if fileName.first != "." {
  145. itemsSource.append(fileName)
  146. }
  147. }
  148. } catch {
  149. print(error.localizedDescription)
  150. }
  151. itemsSource = itemsSource.sorted()
  152. collectionViewSource.reloadData()
  153. // Save button
  154. if imagesDestination.count == 0 {
  155. save.isEnabled = false
  156. } else {
  157. save.isEnabled = true
  158. }
  159. }
  160. // MARK: Private Methods
  161. func filter(image: UIImage) -> UIImage? {
  162. var inputContrast: Double = 0
  163. if filter == .original {
  164. return image
  165. }
  166. if filter == .grayScale {
  167. inputContrast = 1
  168. }
  169. if filter == .bn {
  170. inputContrast = 4
  171. }
  172. let ciImage = CIImage(image: image)!
  173. let imageFilter = ciImage.applyingFilter("CIColorControls", parameters: ["inputSaturation": 0, "inputContrast": inputContrast])
  174. let context: CIContext = CIContext(options: nil)
  175. let cgImage: CGImage = context.createCGImage(imageFilter, from: imageFilter.extent)!
  176. let image: UIImage = UIImage(cgImage: cgImage)
  177. return image
  178. }
  179. /// This method moves a cell from source indexPath to destination indexPath within the same collection view. It works for only 1 item. If multiple items selected, no reordering happens.
  180. ///
  181. /// - Parameters:
  182. /// - coordinator: coordinator obtained from performDropWith: UICollectionViewDropDelegate method
  183. /// - destinationIndexPath: indexpath of the collection view where the user drops the element
  184. /// - collectionView: collectionView in which reordering needs to be done.
  185. private func reorderItems(coordinator: UICollectionViewDropCoordinator, destinationIndexPath: IndexPath, collectionView: UICollectionView) {
  186. let items = coordinator.items
  187. if items.count == 1, let item = items.first, let sourceIndexPath = item.sourceIndexPath {
  188. var dIndexPath = destinationIndexPath
  189. if dIndexPath.row >= collectionView.numberOfItems(inSection: 0) {
  190. dIndexPath.row = collectionView.numberOfItems(inSection: 0) - 1
  191. }
  192. collectionView.performBatchUpdates({
  193. if collectionView === collectionViewDestination {
  194. imagesDestination.remove(at: sourceIndexPath.row)
  195. imagesDestination.insert((item.dragItem.localObject as? UIImage)!, at: dIndexPath.row)
  196. let fileName = itemsDestination[sourceIndexPath.row]
  197. itemsDestination.remove(at: sourceIndexPath.row)
  198. itemsDestination.insert(fileName, at: dIndexPath.row)
  199. } else {
  200. itemsSource.remove(at: sourceIndexPath.row)
  201. itemsSource.insert((item.dragItem.localObject as? String)!, at: dIndexPath.row)
  202. }
  203. collectionView.deleteItems(at: [sourceIndexPath])
  204. collectionView.insertItems(at: [dIndexPath])
  205. })
  206. coordinator.drop(items.first!.dragItem, toItemAt: dIndexPath)
  207. }
  208. }
  209. /// This method copies a cell from source indexPath in 1st collection view to destination indexPath in 2nd collection view. It works for multiple items.
  210. ///
  211. /// - Parameters:
  212. /// - coordinator: coordinator obtained from performDropWith: UICollectionViewDropDelegate method
  213. /// - destinationIndexPath: indexpath of the collection view where the user drops the element
  214. /// - collectionView: collectionView in which reordering needs to be done.
  215. private func copyItems(coordinator: UICollectionViewDropCoordinator, destinationIndexPath: IndexPath, collectionView: UICollectionView) {
  216. collectionView.performBatchUpdates({
  217. var indexPaths: [IndexPath] = []
  218. for (index, item) in coordinator.items.enumerated() {
  219. let indexPath = IndexPath(row: destinationIndexPath.row + index, section: destinationIndexPath.section)
  220. if collectionView === collectionViewDestination {
  221. let fileName = (item.dragItem.localObject as? String)!
  222. let fileNamePathAt = CCUtility.getDirectoryScan() + "/" + fileName
  223. guard let data = try? Data(contentsOf: URL(fileURLWithPath: fileNamePathAt)) else {
  224. return
  225. }
  226. guard let image = UIImage(data: data) else {
  227. return
  228. }
  229. imagesDestination.insert(image, at: indexPath.row)
  230. itemsDestination.insert(fileName, at: indexPath.row)
  231. } else {
  232. // NOT PERMITTED
  233. return
  234. }
  235. indexPaths.append(indexPath)
  236. }
  237. collectionView.insertItems(at: indexPaths)
  238. })
  239. }
  240. // MARK: - UIGestureRecognizerv - Paste
  241. @objc func handleLongPressGesture(recognizer: UIGestureRecognizer) {
  242. if recognizer.state == UIGestureRecognizer.State.began {
  243. self.becomeFirstResponder()
  244. let pasteboard = UIPasteboard.general
  245. if let recognizerView = recognizer.view, let recognizerSuperView = recognizerView.superview, pasteboard.hasImages {
  246. UIMenuController.shared.menuItems = [UIMenuItem(title: "Paste", action: #selector(pasteImage))]
  247. UIMenuController.shared.setTargetRect(recognizerView.frame, in: recognizerSuperView)
  248. UIMenuController.shared.setMenuVisible(true, animated: true)
  249. }
  250. }
  251. }
  252. override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
  253. if action == #selector(pasteImage) {
  254. return true
  255. }
  256. return false
  257. }
  258. @objc func pasteImage() {
  259. let pasteboard = UIPasteboard.general
  260. if pasteboard.hasImages {
  261. let fileName = CCUtility.createFileName("scan.png", fileDate: Date(),
  262. fileType: PHAssetMediaType.image,
  263. keyFileName: NCGlobal.shared.keyFileNameMask,
  264. keyFileNameType: NCGlobal.shared.keyFileNameType,
  265. keyFileNameOriginal: NCGlobal.shared.keyFileNameOriginal,
  266. forcedNewFileName: true)!
  267. let fileNamePath = CCUtility.getDirectoryScan() + "/" + fileName
  268. guard let image = pasteboard.image?.fixedOrientation() else {
  269. return
  270. }
  271. do {
  272. try image.pngData()?.write(to: NSURL.fileURL(withPath: fileNamePath), options: .atomic)
  273. } catch {
  274. return
  275. }
  276. loadImage()
  277. }
  278. }
  279. }
  280. // MARK: - Methods
  281. @available(iOS 13.0, *)
  282. extension NCScanCollectionView: UICollectionViewDataSource {
  283. func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  284. return collectionView == collectionViewSource ? itemsSource.count : imagesDestination.count
  285. }
  286. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  287. if collectionView == collectionViewSource {
  288. let cell = (collectionView.dequeueReusableCell(withReuseIdentifier: "cell1", for: indexPath) as? NCScanCell)!
  289. let fileNamePath = CCUtility.getDirectoryScan() + "/" + itemsSource[indexPath.row]
  290. guard let data = try? Data(contentsOf: URL(fileURLWithPath: fileNamePath)) else {
  291. return cell
  292. }
  293. guard var image = UIImage(data: data) else {
  294. return cell
  295. }
  296. let imageWidthInPixels = image.size.width * image.scale
  297. let imageHeightInPixels = image.size.height * image.scale
  298. // 72 DPI
  299. if imageWidthInPixels > 595 || imageHeightInPixels > 842 {
  300. image = image.resizeImage(size: CGSize(width: 595, height: 842), isAspectRation: true) ?? image
  301. }
  302. cell.customImageView?.image = image
  303. cell.delete.action(for: .touchUpInside) { sender in
  304. let buttonPosition: CGPoint = (sender as? UIButton)!.convert(.zero, to: self.collectionViewSource)
  305. if let indexPath = self.collectionViewSource.indexPathForItem(at: buttonPosition) {
  306. let fileNameAtPath = CCUtility.getDirectoryScan() + "/" + self.itemsSource[indexPath.row]
  307. CCUtility.removeFile(atPath: fileNameAtPath)
  308. self.itemsSource.remove(at: indexPath.row)
  309. self.collectionViewSource.deleteItems(at: [indexPath])
  310. }
  311. }
  312. return cell
  313. } else {
  314. let cell = (collectionView.dequeueReusableCell(withReuseIdentifier: "cell2", for: indexPath) as? NCScanCell)!
  315. var image = imagesDestination[indexPath.row]
  316. let imageWidthInPixels = image.size.width * image.scale
  317. let imageHeightInPixels = image.size.height * image.scale
  318. // 72 DPI
  319. if imageWidthInPixels > 595 || imageHeightInPixels > 842 {
  320. image = image.resizeImage(size: CGSize(width: 595, height: 842), isAspectRation: true) ?? image
  321. }
  322. cell.customImageView?.image = self.filter(image: image)
  323. cell.customLabel.text = NSLocalizedString("_scan_document_pdf_page_", comment: "") + " " + "\(indexPath.row+1)"
  324. cell.delete.action(for: .touchUpInside) { sender in
  325. let buttonPosition: CGPoint = (sender as? UIButton)!.convert(.zero, to: self.collectionViewDestination)
  326. if let indexPath = self.collectionViewDestination.indexPathForItem(at: buttonPosition) {
  327. self.imagesDestination.remove(at: indexPath.row)
  328. self.itemsDestination.remove(at: indexPath.row)
  329. self.collectionViewDestination.deleteItems(at: [indexPath])
  330. // Save button
  331. if self.imagesDestination.count == 0 {
  332. self.save.isEnabled = false
  333. } else {
  334. self.save.isEnabled = true
  335. }
  336. }
  337. }
  338. cell.rotate.action(for: .touchUpInside) { sender in
  339. let buttonPosition: CGPoint = (sender as? UIButton)!.convert(.zero, to: self.collectionViewDestination)
  340. if let indexPath = self.collectionViewDestination.indexPathForItem(at: buttonPosition), let cell = self.collectionViewDestination.cellForItem(at: indexPath) as? NCScanCell {
  341. var image = self.imagesDestination[indexPath.row]
  342. image = image.rotate(radians: .pi/2)!
  343. self.imagesDestination[indexPath.row] = image
  344. cell.customImageView.image = image
  345. }
  346. }
  347. return cell
  348. }
  349. }
  350. }
  351. extension UIImage {
  352. func rotate(radians: Float) -> UIImage? {
  353. var newSize = CGRect(origin: CGPoint.zero, size: self.size).applying(CGAffineTransform(rotationAngle: CGFloat(radians))).size
  354. // Trim off the extremely small float value to prevent core graphics from rounding it up
  355. newSize.width = floor(newSize.width)
  356. newSize.height = floor(newSize.height)
  357. UIGraphicsBeginImageContextWithOptions(newSize, true, self.scale)
  358. let context = UIGraphicsGetCurrentContext()!
  359. // Move origin to middle
  360. context.translateBy(x: newSize.width/2, y: newSize.height/2)
  361. // Rotate around middle
  362. context.rotate(by: CGFloat(radians))
  363. // Draw the image at its center
  364. self.draw(in: CGRect(x: -self.size.width/2, y: -self.size.height/2, width: self.size.width, height: self.size.height))
  365. let newImage = UIGraphicsGetImageFromCurrentImageContext()
  366. UIGraphicsEndImageContext()
  367. return newImage
  368. }
  369. }
  370. // MARK: -
  371. @available(iOS 13.0, *)
  372. extension NCScanCollectionView: UICollectionViewDragDelegate {
  373. func collectionView(_ collectionView: UICollectionView, itemsForBeginning session: UIDragSession, at indexPath: IndexPath) -> [UIDragItem] {
  374. if collectionView == collectionViewSource {
  375. let item = itemsSource[indexPath.row]
  376. let itemProvider = NSItemProvider(object: item as NSString)
  377. let dragItem = UIDragItem(itemProvider: itemProvider)
  378. dragItem.localObject = item
  379. return [dragItem]
  380. } else {
  381. let item = imagesDestination[indexPath.row]
  382. let itemProvider = NSItemProvider(object: item as UIImage)
  383. let dragItem = UIDragItem(itemProvider: itemProvider)
  384. dragItem.localObject = item
  385. return [dragItem]
  386. }
  387. }
  388. func collectionView(_ collectionView: UICollectionView, itemsForAddingTo session: UIDragSession, at indexPath: IndexPath, point: CGPoint) -> [UIDragItem] {
  389. if collectionView == collectionViewSource {
  390. let item = itemsSource[indexPath.row]
  391. let itemProvider = NSItemProvider(object: item as NSString)
  392. let dragItem = UIDragItem(itemProvider: itemProvider)
  393. dragItem.localObject = item
  394. return [dragItem]
  395. } else {
  396. let item = imagesDestination[indexPath.row]
  397. let itemProvider = NSItemProvider(object: item as UIImage)
  398. let dragItem = UIDragItem(itemProvider: itemProvider)
  399. dragItem.localObject = item
  400. return [dragItem]
  401. }
  402. }
  403. func collectionView(_ collectionView: UICollectionView, dragPreviewParametersForItemAt indexPath: IndexPath) -> UIDragPreviewParameters? {
  404. let previewParameters = UIDragPreviewParameters()
  405. if collectionView == collectionViewSource {
  406. previewParameters.visiblePath = UIBezierPath(rect: CGRect(x: 20, y: 20, width: 100, height: 100))
  407. } else {
  408. previewParameters.visiblePath = UIBezierPath(rect: CGRect(x: 20, y: 20, width: 80, height: 80))
  409. }
  410. return previewParameters
  411. }
  412. }
  413. // MARK: -
  414. @available(iOS 13.0, *)
  415. extension NCScanCollectionView: UICollectionViewDropDelegate {
  416. func collectionView(_ collectionView: UICollectionView, canHandle session: UIDropSession) -> Bool {
  417. return true // session.canLoadObjects(ofClass: NSString.self)
  418. }
  419. func collectionView(_ collectionView: UICollectionView, dropSessionDidUpdate session: UIDropSession, withDestinationIndexPath destinationIndexPath: IndexPath?) -> UICollectionViewDropProposal {
  420. if collectionView == collectionViewSource {
  421. if collectionView.hasActiveDrag {
  422. return UICollectionViewDropProposal(operation: .move, intent: .insertAtDestinationIndexPath)
  423. } else {
  424. return UICollectionViewDropProposal(operation: .forbidden)
  425. }
  426. } else {
  427. if collectionView.hasActiveDrag {
  428. return UICollectionViewDropProposal(operation: .move, intent: .insertAtDestinationIndexPath)
  429. } else {
  430. return UICollectionViewDropProposal(operation: .copy, intent: .insertAtDestinationIndexPath)
  431. }
  432. }
  433. }
  434. func collectionView(_ collectionView: UICollectionView, performDropWith coordinator: UICollectionViewDropCoordinator) {
  435. let destinationIndexPath: IndexPath
  436. switch coordinator.proposal.operation {
  437. case .move:
  438. if let indexPath = coordinator.destinationIndexPath {
  439. destinationIndexPath = indexPath
  440. } else {
  441. // Get last index path of table view.
  442. let section = collectionView.numberOfSections - 1
  443. let row = collectionView.numberOfItems(inSection: section)
  444. destinationIndexPath = IndexPath(row: row, section: section)
  445. }
  446. self.reorderItems(coordinator: coordinator, destinationIndexPath: destinationIndexPath, collectionView: collectionView)
  447. break
  448. case .copy:
  449. // Get last index path of table view.
  450. let section = collectionView.numberOfSections - 1
  451. let row = collectionView.numberOfItems(inSection: section)
  452. destinationIndexPath = IndexPath(row: row, section: section)
  453. self.copyItems(coordinator: coordinator, destinationIndexPath: destinationIndexPath, collectionView: collectionView)
  454. break
  455. default:
  456. return
  457. }
  458. }
  459. func collectionView(_ collectionView: UICollectionView, dropSessionDidEnd session: UIDropSession) {
  460. collectionViewDestination.reloadData()
  461. // Save button
  462. if imagesDestination.count == 0 {
  463. save.isEnabled = false
  464. } else {
  465. save.isEnabled = true
  466. }
  467. }
  468. }