ScanCollectionView.swift 25 KB

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