NCMedia.swift 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. //
  2. // NCMedia.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 12/02/2019.
  6. // Copyright © 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 Foundation
  24. import Sheeeeeeeeet
  25. class NCMedia: UIViewController ,UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout, UIGestureRecognizerDelegate, NCListCellDelegate, NCSectionHeaderMenuDelegate, DropdownMenuDelegate, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate {
  26. @IBOutlet fileprivate weak var collectionView: UICollectionView!
  27. private let appDelegate = UIApplication.shared.delegate as! AppDelegate
  28. private var metadataPush: tableMetadata?
  29. private var isEditMode = false
  30. private var selectFileID = [String]()
  31. private var filterTypeFileImage = false;
  32. private var filterTypeFileVideo = false;
  33. private var sectionDatasource = CCSectionDataSourceMetadata()
  34. private var autoUploadFileName = ""
  35. private var autoUploadDirectory = ""
  36. private var gridLayout: NCGridLayout!
  37. private var actionSheet: ActionSheet?
  38. private let headerMenuHeight: CGFloat = 50
  39. private let sectionHeaderHeight: CGFloat = 20
  40. private let footerHeight: CGFloat = 50
  41. private var addWidth: CGFloat = 10
  42. private var readRetry = 0
  43. private let refreshControl = UIRefreshControl()
  44. required init?(coder aDecoder: NSCoder) {
  45. super.init(coder: aDecoder)
  46. appDelegate.activeMedia = self
  47. }
  48. override func viewDidLoad() {
  49. super.viewDidLoad()
  50. // Cell
  51. collectionView.register(UINib.init(nibName: "NCGridMediaCell", bundle: nil), forCellWithReuseIdentifier: "gridCell")
  52. // Header
  53. collectionView.register(UINib.init(nibName: "NCSectionHeaderMenu", bundle: nil), forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "sectionHeaderMenu")
  54. collectionView.register(UINib.init(nibName: "NCSectionHeader", bundle: nil), forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "sectionHeader")
  55. // Footer
  56. collectionView.register(UINib.init(nibName: "NCSectionFooter", bundle: nil), forSupplementaryViewOfKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: "sectionFooter")
  57. collectionView.alwaysBounceVertical = true
  58. gridLayout = NCGridLayout()
  59. gridLayout.heightLabelPlusButton = 0
  60. gridLayout.preferenceWidth = 80
  61. gridLayout.sectionInset = UIEdgeInsets(top: 10, left: 1, bottom: 10, right: 1)
  62. collectionView.collectionViewLayout = gridLayout
  63. // Add Refresh Control
  64. collectionView.refreshControl = refreshControl
  65. // Configure Refresh Control
  66. refreshControl.tintColor = NCBrandColor.sharedInstance.brandText
  67. refreshControl.backgroundColor = NCBrandColor.sharedInstance.brand
  68. //refreshControl.addTarget(self, action: #selector(loadDatasource), for: .valueChanged)
  69. // empty Data Source
  70. self.collectionView.emptyDataSetDelegate = self;
  71. self.collectionView.emptyDataSetSource = self;
  72. }
  73. override func viewWillAppear(_ animated: Bool) {
  74. super.viewWillAppear(animated)
  75. // Color
  76. appDelegate.aspectNavigationControllerBar(self.navigationController?.navigationBar, online: appDelegate.reachability.isReachable(), hidden: false)
  77. appDelegate.aspectTabBar(self.tabBarController?.tabBar, hidden: false)
  78. self.navigationItem.title = NSLocalizedString("_media_", comment: "")
  79. // get auto upload folder
  80. autoUploadFileName = NCManageDatabase.sharedInstance.getAccountAutoUploadFileName()
  81. autoUploadDirectory = NCManageDatabase.sharedInstance.getAccountAutoUploadDirectory(appDelegate.activeUrl)
  82. loadDatasource()
  83. }
  84. override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
  85. super.viewWillTransition(to: size, with: coordinator)
  86. coordinator.animate(alongsideTransition: nil) { _ in
  87. self.collectionView.collectionViewLayout.invalidateLayout()
  88. self.actionSheet?.viewDidLayoutSubviews()
  89. }
  90. }
  91. // MARK: DZNEmpty
  92. func backgroundColor(forEmptyDataSet scrollView: UIScrollView) -> UIColor? {
  93. return NCBrandColor.sharedInstance.backgroundView
  94. }
  95. func image(forEmptyDataSet scrollView: UIScrollView) -> UIImage? {
  96. return CCGraphics.changeThemingColorImage(UIImage.init(named: "filesNoFiles"), multiplier: 2, color: NCBrandColor.sharedInstance.brandElement)
  97. }
  98. func title(forEmptyDataSet scrollView: UIScrollView) -> NSAttributedString? {
  99. let text = "\n"+NSLocalizedString("_files_no_files_", comment: "")
  100. let attributes = [NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 20), NSAttributedString.Key.foregroundColor: UIColor.lightGray]
  101. return NSAttributedString.init(string: text, attributes: attributes)
  102. }
  103. func emptyDataSetShouldAllowScroll(_ scrollView: UIScrollView) -> Bool {
  104. return true
  105. }
  106. // MARK: TAP EVENT
  107. func tapSwitchHeader(sender: Any) {
  108. let itemSizeStart = self.gridLayout.itemSize
  109. UIView.animate(withDuration: 0.0, animations: {
  110. if self.gridLayout.numItems == 1 && self.addWidth > 0 {
  111. self.addWidth = -10
  112. } else if itemSizeStart.width < 50 {
  113. self.addWidth = 10
  114. }
  115. repeat {
  116. self.gridLayout.preferenceWidth = self.gridLayout.preferenceWidth + self.addWidth
  117. } while (self.gridLayout.itemSize == itemSizeStart)
  118. self.collectionView.collectionViewLayout.invalidateLayout()
  119. })
  120. }
  121. func tapOrderHeader(sender: Any) {
  122. }
  123. func tapMoreHeader(sender: Any) {
  124. var menuView: DropdownMenu?
  125. if isEditMode {
  126. //let item0 = DropdownItem(image: CCGraphics.changeThemingColorImage(UIImage.init(named: "checkedNo"), multiplier: 2, color: NCBrandColor.sharedInstance.icon), title: NSLocalizedString("_cancel_", comment: ""))
  127. //let item1 = DropdownItem(image: CCGraphics.changeThemingColorImage(UIImage.init(named: "restore"), multiplier: 1, color: NCBrandColor.sharedInstance.icon), title: NSLocalizedString("_trash_restore_selected_", comment: ""))
  128. let item2 = DropdownItem(image: CCGraphics.changeThemingColorImage(UIImage.init(named: "trash"), multiplier: 2, color: NCBrandColor.sharedInstance.icon), title: NSLocalizedString("_trash_delete_selected_", comment: ""))
  129. menuView = DropdownMenu(navigationController: self.navigationController!, items: [item2], selectedRow: -1)
  130. menuView?.token = "tapMoreHeaderMenuSelect"
  131. } else {
  132. let item0 = DropdownItem(image: CCGraphics.changeThemingColorImage(UIImage.init(named: "select"), multiplier: 2, color: NCBrandColor.sharedInstance.icon), title: NSLocalizedString("_select_", comment: ""))
  133. let item1 = DropdownItem(image: CCGraphics.changeThemingColorImage(UIImage.init(named: "folderMedia"), multiplier: 2, color: NCBrandColor.sharedInstance.icon), title: NSLocalizedString("_select_media_folder_", comment: ""))
  134. var item2: DropdownItem
  135. if filterTypeFileImage {
  136. item2 = DropdownItem(image: CCGraphics.changeThemingColorImage(UIImage.init(named: "imageno"), multiplier: 2, color: NCBrandColor.sharedInstance.icon), title: NSLocalizedString("_media_viewimage_show_", comment: ""))
  137. } else {
  138. item2 = DropdownItem(image: CCGraphics.changeThemingColorImage(UIImage.init(named: "imageyes"), multiplier: 2, color: NCBrandColor.sharedInstance.icon), title: NSLocalizedString("_media_viewimage_hide_", comment: ""))
  139. }
  140. var item3: DropdownItem
  141. if filterTypeFileVideo {
  142. item3 = DropdownItem(image: CCGraphics.changeThemingColorImage(UIImage.init(named: "videono"), multiplier: 2, color: NCBrandColor.sharedInstance.icon), title: NSLocalizedString("_media_viewvideo_show_", comment: ""))
  143. } else {
  144. item3 = DropdownItem(image: CCGraphics.changeThemingColorImage(UIImage.init(named: "videoyes"), multiplier: 2, color: NCBrandColor.sharedInstance.icon), title: NSLocalizedString("_media_viewvideo_hide_", comment: ""))
  145. }
  146. menuView = DropdownMenu(navigationController: self.navigationController!, items: [item0,item1,item2,item3], selectedRow: -1)
  147. menuView?.token = "tapMoreHeaderMenu"
  148. }
  149. menuView?.delegate = self
  150. menuView?.rowHeight = 45
  151. menuView?.highlightColor = NCBrandColor.sharedInstance.brand
  152. menuView?.tableView.alwaysBounceVertical = false
  153. menuView?.tableViewBackgroundColor = UIColor.white
  154. let header = (sender as? UIButton)?.superview
  155. let headerRect = self.collectionView.convert(header!.bounds, from: self.view)
  156. let menuOffsetY = headerRect.height - headerRect.origin.y - 2
  157. menuView?.topOffsetY = CGFloat(menuOffsetY)
  158. menuView?.showMenu()
  159. }
  160. func tapMoreListItem(with fileID: String, sender: Any) {
  161. tapMoreGridItem(with: fileID, sender: sender)
  162. }
  163. func tapMoreGridItem(with fileID: String, sender: Any) {
  164. guard let metadata = NCManageDatabase.sharedInstance.getMetadata(predicate: NSPredicate(format: "fileID == %@", fileID)) else {
  165. return
  166. }
  167. if !isEditMode {
  168. var items = [ActionSheetItem]()
  169. let appearanceDelete = ActionSheetItemAppearance.init()
  170. appearanceDelete.textColor = UIColor.red
  171. // 0 == CCMore, 1 = first NCOffline ....
  172. if (self == self.navigationController?.viewControllers[1]) {
  173. items.append(ActionSheetItem(title: NSLocalizedString("_remove_available_offline_", comment: ""), value: 0, image: CCGraphics.changeThemingColorImage(UIImage.init(named: "offline"), multiplier: 2, color: NCBrandColor.sharedInstance.icon)))
  174. }
  175. items.append(ActionSheetItem(title: NSLocalizedString("_share_", comment: ""), value: 1, image: CCGraphics.changeThemingColorImage(UIImage.init(named: "share"), multiplier: 2, color: NCBrandColor.sharedInstance.icon)))
  176. let itemDelete = ActionSheetItem(title: NSLocalizedString("_delete_", comment: ""), value: 2, image: CCGraphics.changeThemingColorImage(UIImage.init(named: "trash"), multiplier: 2, color: UIColor.red))
  177. itemDelete.customAppearance = appearanceDelete
  178. items.append(itemDelete)
  179. items.append(ActionSheetCancelButton(title: NSLocalizedString("_cancel_", comment: "")))
  180. actionSheet = ActionSheet(items: items) { sheet, item in
  181. if item.value as? Int == 0 {
  182. if metadata.directory {
  183. NCManageDatabase.sharedInstance.setDirectory(serverUrl: CCUtility.stringAppendServerUrl(metadata.serverUrl, addFileName: metadata.fileName)!, offline: false, account: self.appDelegate.activeAccount)
  184. } else {
  185. NCManageDatabase.sharedInstance.setLocalFile(fileID: metadata.fileID, offline: false)
  186. }
  187. self.loadDatasource()
  188. }
  189. if item.value as? Int == 1 { self.appDelegate.activeMain.readShare(withAccount: self.appDelegate.activeAccount, openWindow: true, metadata: metadata) }
  190. if item.value as? Int == 2 { self.deleteItem(with: metadata, sender: sender) }
  191. if item is ActionSheetCancelButton { print("Cancel buttons has the value `true`") }
  192. }
  193. let headerView = NCActionSheetHeader.sharedInstance.actionSheetHeader(isDirectory: metadata.directory, iconName: metadata.iconName, fileID: metadata.fileID, fileNameView: metadata.fileNameView, text: metadata.fileNameView)
  194. actionSheet?.headerView = headerView
  195. actionSheet?.headerView?.frame.size.height = 50
  196. actionSheet?.present(in: self, from: sender as! UIButton)
  197. } else {
  198. let buttonPosition:CGPoint = (sender as! UIButton).convert(CGPoint.zero, to:collectionView)
  199. let indexPath = collectionView.indexPathForItem(at: buttonPosition)
  200. collectionView(self.collectionView, didSelectItemAt: indexPath!)
  201. }
  202. }
  203. // MARK: DROP-DOWN-MENU
  204. func dropdownMenu(_ dropdownMenu: DropdownMenu, didSelectRowAt indexPath: IndexPath) {
  205. if dropdownMenu.token == "tapMoreHeaderMenu" {
  206. }
  207. if dropdownMenu.token == "tapMoreHeaderMenuSelect" {
  208. }
  209. }
  210. // MARK: NC API
  211. func deleteItem(with metadata: tableMetadata, sender: Any) {
  212. var items = [ActionSheetItem]()
  213. guard let tableDirectory = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == serverUrl", appDelegate.activeAccount, metadata.serverUrl)) else {
  214. return
  215. }
  216. items.append(ActionSheetDangerButton(title: NSLocalizedString("_delete_", comment: "")))
  217. items.append(ActionSheetCancelButton(title: NSLocalizedString("_cancel_", comment: "")))
  218. actionSheet = ActionSheet(items: items) { sheet, item in
  219. if item is ActionSheetDangerButton {
  220. NCMainCommon.sharedInstance.deleteFile(metadatas: [metadata], e2ee: tableDirectory.e2eEncrypted, serverUrl: tableDirectory.serverUrl, folderFileID: tableDirectory.fileID) { (errorCode, message) in
  221. self.loadDatasource()
  222. }
  223. }
  224. if item is ActionSheetCancelButton { print("Cancel buttons has the value `true`") }
  225. }
  226. let headerView = NCActionSheetHeader.sharedInstance.actionSheetHeader(isDirectory: metadata.directory, iconName: metadata.iconName, fileID: metadata.fileID, fileNameView: metadata.fileNameView, text: metadata.fileNameView)
  227. actionSheet?.headerView = headerView
  228. actionSheet?.headerView?.frame.size.height = 50
  229. actionSheet?.present(in: self, from: sender as! UIButton)
  230. }
  231. func search(_ lteDate: Date, gteDate: Date, reiteration: Bool) {
  232. if appDelegate.activeAccount.count == 0 {
  233. return
  234. }
  235. let startDirectory = NCManageDatabase.sharedInstance.getAccountStartDirectoryMediaTabView(CCUtility.getHomeServerUrlActiveUrl(appDelegate.activeUrl))
  236. OCNetworking.sharedManager()?.search(withAccount: appDelegate.activeAccount, fileName: "", serverUrl: startDirectory, contentType: ["image/%", "video/%"], lteDateLastModified: lteDate, gteDateLastModified: gteDate, depth: "infinity", completion: { (account, metadatas, message, errorCode) in
  237. if errorCode == 0 && account == self.appDelegate.activeAccount {
  238. if metadatas != nil && metadatas!.count > 0 {
  239. NCManageDatabase.sharedInstance.createTablePhotos(metadatas as! [tableMetadata], lteDate: lteDate, gteDate: gteDate, account: account!)
  240. self.loadDatasource()
  241. } else if reiteration {
  242. let newGteDate = Calendar.current.date(byAdding: .day, value: -60, to: gteDate)!
  243. self.readRetry += 1
  244. self.search(lteDate, gteDate: newGteDate, reiteration: reiteration)
  245. }
  246. }
  247. self.refreshControl.endRefreshing()
  248. })
  249. }
  250. // MARK: DATASOURCE
  251. @objc func loadDatasource() {
  252. if appDelegate.activeAccount.count == 0 {
  253. return
  254. }
  255. DispatchQueue.global().async {
  256. if let metadatas = NCManageDatabase.sharedInstance.getTablePhotos(predicate: NSPredicate(format: "account == %@", self.appDelegate.activeAccount)) {
  257. self.sectionDatasource = CCSectionMetadata.creataDataSourseSectionMetadata(metadatas, listProgressMetadata: nil, groupByField: "date", filterFileID: nil, filterTypeFileImage: self.filterTypeFileImage, filterTypeFileVideo: self.filterTypeFileVideo, activeAccount: self.appDelegate.activeAccount)
  258. } else {
  259. self.sectionDatasource = CCSectionDataSourceMetadata()
  260. let gteDate = Calendar.current.date(byAdding: .day, value: -1, to: Date())!
  261. self.search(Date(), gteDate: gteDate, reiteration: true)
  262. }
  263. DispatchQueue.main.async {
  264. self.collectionView?.reloadData()
  265. }
  266. }
  267. }
  268. // MARK: COLLECTIONVIEW METHODS
  269. public func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
  270. //caused by user
  271. print("SCROLL scrollViewDidEndDecelerating")
  272. }
  273. public func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
  274. if (!decelerate) {
  275. //cause by user
  276. print("SCROLL scrollViewDidEndDragging")
  277. }
  278. }
  279. func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
  280. if (indexPath.section == 0) {
  281. if kind == UICollectionView.elementKindSectionHeader {
  282. let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "sectionHeaderMenu", for: indexPath) as! NCSectionHeaderMenu
  283. header.buttonSwitch.setImage(CCGraphics.changeThemingColorImage(UIImage.init(named: "switchGridChange"), multiplier: 2, color: NCBrandColor.sharedInstance.icon), for: .normal)
  284. header.viewLabelSection.backgroundColor = .clear
  285. header.delegate = self
  286. header.setStatusButton(count: sectionDatasource.allFileID.count)
  287. header.buttonOrder.isHidden = true
  288. header.labelSection.isHidden = false
  289. header.buttonMore.isHidden = false
  290. header.setTitleLabel(sectionDatasource: sectionDatasource, section: indexPath.section)
  291. header.labelSectionHeightConstraint.constant = sectionHeaderHeight
  292. return header
  293. } else {
  294. let footer = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "sectionFooter", for: indexPath) as! NCSectionFooter
  295. footer.setTitleLabel(sectionDatasource: sectionDatasource)
  296. return footer
  297. }
  298. } else {
  299. if kind == UICollectionView.elementKindSectionHeader {
  300. let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "sectionHeader", for: indexPath) as! NCSectionHeader
  301. header.backgroundColor = .clear
  302. header.setTitleLabel(sectionDatasource: sectionDatasource, section: indexPath.section)
  303. return header
  304. } else {
  305. let footer = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "sectionFooter", for: indexPath) as! NCSectionFooter
  306. footer.setTitleLabel(sectionDatasource: sectionDatasource)
  307. return footer
  308. }
  309. }
  310. }
  311. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
  312. if section == 0 {
  313. return CGSize(width: collectionView.frame.width, height: headerMenuHeight + sectionHeaderHeight)
  314. } else {
  315. return CGSize(width: collectionView.frame.width, height: sectionHeaderHeight)
  316. }
  317. }
  318. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize {
  319. let sections = sectionDatasource.sectionArrayRow.allKeys.count
  320. if (section == sections - 1) {
  321. return CGSize(width: collectionView.frame.width, height: footerHeight)
  322. } else {
  323. return CGSize(width: collectionView.frame.width, height: 0)
  324. }
  325. }
  326. func numberOfSections(in collectionView: UICollectionView) -> Int {
  327. let sections = sectionDatasource.sectionArrayRow.allKeys.count
  328. return sections
  329. }
  330. func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  331. let key = sectionDatasource.sections.object(at: section)
  332. let datasource = sectionDatasource.sectionArrayRow.object(forKey: key) as! [tableMetadata]
  333. return datasource.count
  334. }
  335. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  336. guard let metadata = NCMainCommon.sharedInstance.getMetadataFromSectionDataSourceIndexPath(indexPath, sectionDataSource: sectionDatasource) else {
  337. return collectionView.dequeueReusableCell(withReuseIdentifier: "gridCell", for: indexPath) as! NCGridMediaCell
  338. }
  339. let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "gridCell", for: indexPath) as! NCGridMediaCell
  340. NCMainCommon.sharedInstance.collectionViewCellForItemAt(indexPath, collectionView: collectionView, cell: cell, metadata: metadata, metadataFolder: nil, serverUrl: metadata.serverUrl, isEditMode: isEditMode, selectFileID: selectFileID, autoUploadFileName: autoUploadFileName, autoUploadDirectory: autoUploadDirectory, hideButtonMore: true, source: self)
  341. return cell
  342. }
  343. func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
  344. guard let metadata = NCMainCommon.sharedInstance.getMetadataFromSectionDataSourceIndexPath(indexPath, sectionDataSource: sectionDatasource) else {
  345. return
  346. }
  347. metadataPush = metadata
  348. if isEditMode {
  349. if let index = selectFileID.index(of: metadata.fileID) {
  350. selectFileID.remove(at: index)
  351. } else {
  352. selectFileID.append(metadata.fileID)
  353. }
  354. collectionView.reloadItems(at: [indexPath])
  355. return
  356. }
  357. performSegue(withIdentifier: "segueDetail", sender: self)
  358. }
  359. // MARK: SEGUE
  360. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  361. let photoDataSource: NSMutableArray = []
  362. for fileID: String in sectionDatasource.allFileID as! [String] {
  363. let metadata = sectionDatasource.allRecordsDataSource.object(forKey: fileID) as! tableMetadata
  364. if metadata.typeFile == k_metadataTypeFile_image {
  365. photoDataSource.add(metadata)
  366. }
  367. }
  368. if let segueNavigationController = segue.destination as? UINavigationController {
  369. if let segueViewController = segueNavigationController.topViewController as? CCDetail {
  370. segueViewController.metadataDetail = metadataPush
  371. segueViewController.dateFilterQuery = nil
  372. segueViewController.photoDataSource = photoDataSource
  373. segueViewController.title = metadataPush!.fileNameView
  374. }
  375. }
  376. }
  377. }