123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591 |
- //
- // NCCollectionCommon.swift
- // Nextcloud
- //
- // Created by Marino Faggiana on 08/09/2020.
- // Copyright © 2020 Marino Faggiana. All rights reserved.
- //
- // Author Marino Faggiana <marino.faggiana@nextcloud.com>
- //
- // This program is free software: you can redistribute it and/or modify
- // it under the terms of the GNU General Public License as published by
- // the Free Software Foundation, either version 3 of the License, or
- // (at your option) any later version.
- //
- // This program is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU General Public License for more details.
- //
- // You should have received a copy of the GNU General Public License
- // along with this program. If not, see <http://www.gnu.org/licenses/>.
- //
- import Foundation
- import NCCommunication
- class NCCollectionCommon: NSObject, NCSelectDelegate {
- @objc static let shared: NCCollectionCommon = {
- let instance = NCCollectionCommon()
- instance.createImagesThemingColor()
- return instance
- }()
-
- let appDelegate = UIApplication.shared.delegate as! AppDelegate
- struct images {
- static var file = UIImage()
- static var shared = UIImage()
- static var canShare = UIImage()
- static var shareByLink = UIImage()
-
- static var favorite = UIImage()
- static var comment = UIImage()
- static var livePhoto = UIImage()
- static var offlineFlag = UIImage()
- static var local = UIImage()
- static var folderEncrypted = UIImage()
- static var folderSharedWithMe = UIImage()
- static var folderPublic = UIImage()
- static var folderGroup = UIImage()
- static var folderExternal = UIImage()
- static var folderAutomaticUpload = UIImage()
- static var folder = UIImage()
-
- static var checkedYes = UIImage()
- static var checkedNo = UIImage()
-
- static var buttonMore = UIImage()
- static var buttonStop = UIImage()
- }
-
- // MARK: -
-
- @objc func createImagesThemingColor() {
-
- images.file = UIImage.init(named: "file")!
-
- images.shared = UIImage(named: "share")!.image(color: NCBrandColor.shared.graySoft, size: 50)
- images.canShare = UIImage(named: "share")!.image(color: NCBrandColor.shared.graySoft, size: 50)
- images.shareByLink = UIImage(named: "sharebylink")!.image(color: NCBrandColor.shared.graySoft, size: 50)
-
- images.favorite = UIImage(named: "favorite")!.image(color: NCBrandColor.shared.yellowFavorite, size: 50)
- images.comment = UIImage(named: "comment")!.image(color: NCBrandColor.shared.graySoft, size: 50)
- images.livePhoto = UIImage(named: "livePhoto")!.image(color: NCBrandColor.shared.textView, size: 50)
- images.offlineFlag = UIImage.init(named: "offlineFlag")!
- images.local = UIImage.init(named: "local")!
-
- let folderWidth: CGFloat = UIScreen.main.bounds.width / 3
- images.folderEncrypted = UIImage(named: "folderEncrypted")!.image(color: NCBrandColor.shared.brandElement, size: folderWidth)
- images.folderSharedWithMe = UIImage(named: "folder_shared_with_me")!.image(color: NCBrandColor.shared.brandElement, size: folderWidth)
- images.folderPublic = UIImage(named: "folder_public")!.image(color: NCBrandColor.shared.brandElement, size: folderWidth)
- images.folderGroup = UIImage(named: "folder_group")!.image(color: NCBrandColor.shared.brandElement, size: folderWidth)
- images.folderExternal = UIImage(named: "folder_external")!.image(color: NCBrandColor.shared.brandElement, size: folderWidth)
- images.folderAutomaticUpload = UIImage(named: "folderAutomaticUpload")!.image(color: NCBrandColor.shared.brandElement, size: folderWidth)
- images.folder = UIImage(named: "folder")!.image(color: NCBrandColor.shared.brandElement, size: folderWidth)
-
- images.checkedYes = UIImage(named: "checkedYes")!.image(color: .darkGray, size: 50)
- images.checkedNo = UIImage(named: "checkedNo")!.image(color: NCBrandColor.shared.graySoft, size: 50)
-
- images.buttonMore = UIImage(named: "more")!.image(color: NCBrandColor.shared.graySoft, size: 50)
- images.buttonStop = UIImage(named: "stop")!.image(color: NCBrandColor.shared.graySoft, size: 50)
- }
-
- func loadImage(named: String, color: UIColor = NCBrandColor.shared.icon, size: CGFloat = 50) -> UIImage {
-
- var image: UIImage?
-
- if #available(iOS 13.0, *) {
- image = UIImage(systemName: named)
- if image == nil {
- image = UIImage(named: named)
- }
- } else {
- image = UIImage(named: named)
- }
-
- if image != nil {
- return image!.image(color: color, size: size)
- }
-
- return UIImage(named: "file")!.image(color: color, size: size)
- }
-
- // MARK: - NCSelect + Delegate
-
- func dismissSelect(serverUrl: String?, metadata: tableMetadata?, type: String, items: [Any], buttonType: String, overwrite: Bool) {
- if (serverUrl != nil && items.count > 0) {
- var move = true
- if buttonType == "done1" { move = false }
-
- for metadata in items as! [tableMetadata] {
- NCOperationQueue.shared.copyMove(metadata: metadata, serverUrl: serverUrl!, overwrite: overwrite, move: move)
- }
- }
- }
- func openSelectView(items: [Any], viewController: UIViewController) {
-
- let navigationController = UIStoryboard.init(name: "NCSelect", bundle: nil).instantiateInitialViewController() as! UINavigationController
- let topViewController = navigationController.topViewController as! NCSelect
- var listViewController = [NCSelect]()
-
- var copyItems: [Any] = []
- for item in items {
- copyItems.append(item)
- }
-
- let homeUrl = NCUtilityFileSystem.shared.getHomeServer(urlBase: appDelegate.urlBase, account: appDelegate.account)
- var serverUrl = (copyItems[0] as! Nextcloud.tableMetadata).serverUrl
-
- // Setup view controllers such that the current view is of the same directory the items to be copied are in
- while true {
- // If not in the topmost directory, create a new view controller and set correct title.
- // If in the topmost directory, use the default view controller as the base.
- var viewController: NCSelect?
- if serverUrl != homeUrl {
- viewController = UIStoryboard(name: "NCSelect", bundle: nil).instantiateViewController(withIdentifier: "NCSelect.storyboard") as? NCSelect
- if viewController == nil {
- return
- }
- viewController!.titleCurrentFolder = (serverUrl as NSString).lastPathComponent
- } else {
- viewController = topViewController
- }
- guard let vc = viewController else { return }
- vc.delegate = self
- vc.hideButtonCreateFolder = false
- vc.selectFile = false
- vc.includeDirectoryE2EEncryption = false
- vc.includeImages = false
- vc.type = ""
- vc.titleButtonDone = NSLocalizedString("_move_", comment: "")
- vc.titleButtonDone1 = NSLocalizedString("_copy_",comment: "")
- vc.isButtonDone1Hide = false
- vc.isOverwriteHide = false
- vc.items = copyItems
- vc.serverUrl = serverUrl
-
- vc.navigationItem.backButtonTitle = vc.titleCurrentFolder
- listViewController.insert(vc, at: 0)
-
- if serverUrl != homeUrl {
- serverUrl = NCUtilityFileSystem.shared.deletingLastPathComponent(serverUrl: serverUrl, urlBase: appDelegate.urlBase, account: appDelegate.account)
- } else {
- break
- }
- }
-
- navigationController.setViewControllers(listViewController, animated: false)
- navigationController.modalPresentationStyle = .formSheet
-
- viewController.present(navigationController, animated: true, completion: nil)
- }
-
- @objc func openFileViewInFolder(serverUrl: String, fileName: String) {
-
- let viewController = UIStoryboard(name: "NCFileViewInFolder", bundle: nil).instantiateInitialViewController() as! NCFileViewInFolder
- let navigationController = UINavigationController.init(rootViewController: viewController)
- let topViewController = viewController
- var listViewController = [NCFileViewInFolder]()
- var serverUrl = serverUrl
- let homeUrl = NCUtilityFileSystem.shared.getHomeServer(urlBase: appDelegate.urlBase, account: appDelegate.account)
-
- while true {
-
- var viewController: NCFileViewInFolder?
- if serverUrl != homeUrl {
- viewController = UIStoryboard(name: "NCFileViewInFolder", bundle: nil).instantiateInitialViewController() as? NCFileViewInFolder
- if viewController == nil {
- return
- }
- viewController!.titleCurrentFolder = (serverUrl as NSString).lastPathComponent
- } else {
- viewController = topViewController
- }
- guard let vc = viewController else { return }
-
- vc.serverUrl = serverUrl
- vc.fileName = fileName
-
- vc.navigationItem.backButtonTitle = vc.titleCurrentFolder
- listViewController.insert(vc, at: 0)
-
- if serverUrl != homeUrl {
- serverUrl = NCUtilityFileSystem.shared.deletingLastPathComponent(serverUrl: serverUrl, urlBase: appDelegate.urlBase, account: appDelegate.account)
- } else {
- break
- }
- }
-
- navigationController.setViewControllers(listViewController, animated: false)
- navigationController.modalPresentationStyle = .formSheet
-
- appDelegate.window?.rootViewController?.present(navigationController, animated: true, completion: nil)
- }
-
- // MARK: - Save Photo - Video - Live Photo
-
- func saveAlbum(metadata: tableMetadata) {
-
- let fileNamePath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!
- let status = PHPhotoLibrary.authorizationStatus()
- if metadata.typeFile == NCGlobal.shared.metadataTypeFileImage && status == PHAuthorizationStatus.authorized {
-
- if let image = UIImage.init(contentsOfFile: fileNamePath) {
- UIImageWriteToSavedPhotosAlbum(image, self, #selector(SaveAlbum(_:didFinishSavingWithError:contextInfo:)), nil)
- } else {
- NCContentPresenter.shared.messageNotification("_save_selected_files_", description: "_file_not_saved_cameraroll_", delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: NCGlobal.shared.ErrorFileNotSaved)
- }
-
- } else if metadata.typeFile == NCGlobal.shared.metadataTypeFileVideo && status == PHAuthorizationStatus.authorized {
-
- if UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(fileNamePath) {
- UISaveVideoAtPathToSavedPhotosAlbum(fileNamePath, self, #selector(SaveAlbum(_:didFinishSavingWithError:contextInfo:)), nil)
- } else {
- NCContentPresenter.shared.messageNotification("_save_selected_files_", description: "_file_not_saved_cameraroll_", delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: NCGlobal.shared.ErrorFileNotSaved)
- }
-
- } else if status != PHAuthorizationStatus.authorized {
-
- NCContentPresenter.shared.messageNotification("_access_photo_not_enabled_", description: "_access_photo_not_enabled_msg_", delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: NCGlobal.shared.ErrorFileNotSaved)
- }
- }
-
- @objc private func SaveAlbum(_ image: UIImage, didFinishSavingWithError error: Error?, contextInfo: UnsafeRawPointer) {
-
- if error != nil {
- NCContentPresenter.shared.messageNotification("_save_selected_files_", description: "_file_not_saved_cameraroll_", delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: NCGlobal.shared.ErrorFileNotSaved)
- }
- }
-
- func saveLivePhoto(metadata: tableMetadata, metadataMOV: tableMetadata) {
-
- if !CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
- NCOperationQueue.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorSaveAlbumLivePhotoIMG)
- }
-
- if !CCUtility.fileProviderStorageExists(metadataMOV.ocId, fileNameView: metadataMOV.fileNameView) {
- NCOperationQueue.shared.download(metadata: metadataMOV, selector: NCGlobal.shared.selectorSaveAlbumLivePhotoMOV)
- }
-
- if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) && CCUtility.fileProviderStorageExists(metadataMOV.ocId, fileNameView: metadataMOV.fileNameView) {
- saveLivePhotoToDisk(metadata: metadata, metadataMov: metadataMOV, progressView: nil, viewActivity: self.appDelegate.window?.rootViewController?.view)
- }
- }
-
- func saveLivePhotoToDisk(metadata: tableMetadata, metadataMov: tableMetadata, progressView: UIProgressView?, viewActivity: UIView?) {
-
- let fileNameImage = URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!)
- let fileNameMov = URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadataMov.ocId, fileNameView: metadataMov.fileNameView)!)
-
- if let view = viewActivity {
- NCUtility.shared.startActivityIndicator(view: view)
- }
-
- NCLivePhoto.generate(from: fileNameImage, videoURL: fileNameMov, progress: { progress in
- DispatchQueue.main.async {
- progressView?.progress = Float(progress)
- }
- }, completion: { livePhoto, resources in
- NCUtility.shared.stopActivityIndicator()
- progressView?.progress = 0
- if resources != nil {
- NCLivePhoto.saveToLibrary(resources!) { (result) in
- if !result {
- NCContentPresenter.shared.messageNotification("_error_", description: "_livephoto_save_error_", delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: NCGlobal.shared.ErrorInternalError)
- }
- }
- } else {
- NCContentPresenter.shared.messageNotification("_error_", description: "_livephoto_save_error_", delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: NCGlobal.shared.ErrorInternalError)
- }
- })
- }
-
- // MARK: - Print
-
- func printDocument(metadata: tableMetadata) {
-
- let fileNameURL = URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!)
-
- if UIPrintInteractionController.canPrint(fileNameURL) {
-
- let printInfo = UIPrintInfo(dictionary: nil)
- printInfo.jobName = fileNameURL.lastPathComponent
- printInfo.outputType = .photo
- let printController = UIPrintInteractionController.shared
- printController.printInfo = printInfo
- printController.showsNumberOfCopies = true
- printController.printingItem = fileNameURL
- printController.present(animated: true, completionHandler: nil)
- }
- }
-
- // MARK: - Context Menu COnfiguration
-
- @available(iOS 13.0, *)
- func contextMenuConfiguration(metadata: tableMetadata, viewController: UIViewController, enableDeleteLocal: Bool, enableViewInFolder: Bool) -> UIMenu {
-
- var titleDeleteConfirmFile = NSLocalizedString("_delete_file_", comment: "")
- if metadata.directory { titleDeleteConfirmFile = NSLocalizedString("_delete_folder_", comment: "") }
- var titleSave: String = NSLocalizedString("_save_selected_files_", comment: "")
- let metadataMOV = NCManageDatabase.shared.getMetadataLivePhoto(metadata: metadata)
- if metadataMOV != nil {
- titleSave = NSLocalizedString("_livephoto_save_", comment: "")
- }
-
- let copy = UIAction(title: NSLocalizedString("_copy_file_", comment: ""), image: UIImage(systemName: "doc.on.doc") ) { action in
- self.appDelegate.pasteboardOcIds = [metadata.ocId]
- self.copyPasteboard()
- }
-
- let detail = UIAction(title: NSLocalizedString("_details_", comment: ""), image: UIImage(systemName: "info") ) { action in
- NCNetworkingNotificationCenter.shared.openShare(ViewController: viewController, metadata: metadata, indexPage: 0)
- }
-
- let save = UIAction(title: titleSave, image: UIImage(systemName: "square.and.arrow.down")) { action in
- if metadataMOV != nil {
- NCCollectionCommon.shared.saveLivePhoto(metadata: metadata, metadataMOV: metadataMOV!)
- } else {
- if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
- self.saveAlbum(metadata: metadata)
- } else {
- NCOperationQueue.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorSaveAlbum)
- }
- }
- }
-
- let viewInFolder = UIAction(title: NSLocalizedString("_view_in_folder_", comment: ""), image: UIImage(systemName: "arrow.forward.square")) { action in
- NCCollectionCommon.shared.openFileViewInFolder(serverUrl: metadata.serverUrl, fileName: metadata.fileName)
- }
-
- let openIn = UIAction(title: NSLocalizedString("_open_in_", comment: ""), image: UIImage(systemName: "square.and.arrow.up") ) { action in
- NCNetworkingNotificationCenter.shared.downloadOpen(metadata: metadata, selector: NCGlobal.shared.selectorOpenIn)
- }
-
- let openQuickLook = UIAction(title: NSLocalizedString("_open_quicklook_", comment: ""), image: UIImage(systemName: "eye")) { action in
- NCNetworkingNotificationCenter.shared.downloadOpen(metadata: metadata, selector: NCGlobal.shared.selectorLoadFileQuickLook)
- }
-
- let open = UIMenu(title: NSLocalizedString("_open_", comment: ""), image: UIImage(systemName: "square.and.arrow.up"), children: [openIn, openQuickLook])
-
- let moveCopy = UIAction(title: NSLocalizedString("_move_or_copy_", comment: ""), image: UIImage(systemName: "arrow.up.right.square")) { action in
- NCCollectionCommon.shared.openSelectView(items: [metadata], viewController: viewController)
- }
-
- let deleteConfirmFile = UIAction(title: titleDeleteConfirmFile, image: UIImage(systemName: "trash"), attributes: .destructive) { action in
- NCNetworking.shared.deleteMetadata(metadata, account: self.appDelegate.account, urlBase: self.appDelegate.urlBase, onlyLocal: false) { (errorCode, errorDescription) in
- if errorCode != 0 {
- NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
- }
- }
- }
-
- let deleteConfirmLocal = UIAction(title: NSLocalizedString("_remove_local_file_", comment: ""), image: UIImage(systemName: "trash"), attributes: .destructive) { action in
- NCNetworking.shared.deleteMetadata(metadata, account: self.appDelegate.account, urlBase: self.appDelegate.urlBase, onlyLocal: true) { (errorCode, errorDescription) in
- }
- }
-
- var delete = UIMenu(title: NSLocalizedString("_delete_file_", comment: ""), image: UIImage(systemName: "trash"), options: .destructive, children: [deleteConfirmLocal, deleteConfirmFile])
-
- if !enableDeleteLocal {
- delete = UIMenu(title: NSLocalizedString("_delete_file_", comment: ""), image: UIImage(systemName: "trash"), options: .destructive, children: [deleteConfirmFile])
- }
-
- if metadata.directory {
- delete = UIMenu(title: NSLocalizedString("_delete_folder_", comment: ""), image: UIImage(systemName: "trash"), options: .destructive, children: [deleteConfirmFile])
- }
-
- // ------ MENU -----
-
- if metadata.directory {
- return UIMenu(title: "", children: [detail, moveCopy, delete])
- }
-
- var children: [UIMenuElement] = [detail, open, moveCopy, copy, delete]
- if metadata.typeFile == NCGlobal.shared.metadataTypeFileImage || metadata.typeFile == NCGlobal.shared.metadataTypeFileVideo {
- children.insert(save, at: 2)
- }
-
- if enableViewInFolder {
- children.insert(viewInFolder, at: 5)
- }
-
- return UIMenu(title: "", image: nil, identifier: nil, children: children)
- }
-
- // MARK: - Copy & Paste
- func copyPasteboard() {
-
- var metadatas: [tableMetadata] = []
- var items = [[String : Any]]()
-
- for ocId in appDelegate.pasteboardOcIds {
- if let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
- metadatas.append(metadata)
- }
- }
-
- for metadata in metadatas {
-
- if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
- do {
- // Get Data
- let data = try Data.init(contentsOf: URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)))
- // Pasteboard item
- if let unmanagedFileUTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (metadata.fileNameView as NSString).pathExtension as CFString, nil) {
- let fileUTI = unmanagedFileUTI.takeRetainedValue() as String
- items.append([fileUTI:data])
- }
- } catch {
- print("error")
- }
- } else {
- NCNetworking.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorLoadCopy) { (_) in }
- }
- }
-
- UIPasteboard.general.setItems(items, options: [:])
- }
- func pastePasteboard(serverUrl: String) {
-
- for (index, items) in UIPasteboard.general.items.enumerated() {
- for item in items {
- let pasteboardType = item.key
- if let data = UIPasteboard.general.data(forPasteboardType: pasteboardType, inItemSet: IndexSet([index]))?.first {
- let results = NCCommunicationCommon.shared.getDescriptionFile(inUTI: pasteboardType as CFString)
- if results.resultTypeFile != NCCommunicationCommon.typeFile.unknow.rawValue {
- uploadPasteFile(fileName: results.resultFilename, ext: results.resultExtension, contentType: pasteboardType, serverUrl: serverUrl, data: data)
- }
- }
- }
- }
- }
- private func uploadPasteFile(fileName: String, ext: String, contentType: String, serverUrl: String, data: Data) {
-
- do {
- let fileNameView = fileName + "_" + CCUtility.getIncrementalNumber() + "." + ext
- let ocId = UUID().uuidString
- let filePath = CCUtility.getDirectoryProviderStorageOcId(ocId, fileNameView: fileNameView)!
-
- try data.write(to: URL(fileURLWithPath: filePath))
-
- let metadataForUpload = NCManageDatabase.shared.createMetadata(account: appDelegate.account, fileName: fileNameView, ocId: ocId, serverUrl: serverUrl, urlBase: appDelegate.urlBase, url: "", contentType: contentType, livePhoto: false)
-
- metadataForUpload.session = NCNetworking.shared.sessionIdentifierBackground
- metadataForUpload.sessionSelector = NCGlobal.shared.selectorUploadFile
- metadataForUpload.size = NCUtilityFileSystem.shared.getFileSize(filePath: filePath)
- metadataForUpload.status = NCGlobal.shared.metadataStatusWaitUpload
-
- NCManageDatabase.shared.addMetadata(metadataForUpload)
-
- } catch { }
- }
- }
- // MARK: - List Layout
- class NCListLayout: UICollectionViewFlowLayout {
-
- var itemHeight: CGFloat = 60
-
- override init() {
- super.init()
-
- sectionHeadersPinToVisibleBounds = false
-
- minimumInteritemSpacing = 0
- minimumLineSpacing = 1
-
- self.scrollDirection = .vertical
- self.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
- }
-
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
- override var itemSize: CGSize {
- get {
- if let collectionView = collectionView {
- let itemWidth: CGFloat = collectionView.frame.width
- return CGSize(width: itemWidth, height: self.itemHeight)
- }
-
- // Default fallback
- return CGSize(width: 100, height: 100)
- }
- set {
- super.itemSize = newValue
- }
- }
-
- override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint) -> CGPoint {
- return proposedContentOffset
- }
- }
- // MARK: - Grid Layout
- class NCGridLayout: UICollectionViewFlowLayout {
-
- var heightLabelPlusButton: CGFloat = 45
- var marginLeftRight: CGFloat = 6
- var itemForLine: CGFloat = 3
- var itemWidthDefault: CGFloat = 120
- override init() {
- super.init()
-
- sectionHeadersPinToVisibleBounds = false
-
- minimumInteritemSpacing = 1
- minimumLineSpacing = marginLeftRight
-
- self.scrollDirection = .vertical
- self.sectionInset = UIEdgeInsets(top: 10, left: marginLeftRight, bottom: 0, right: marginLeftRight)
- }
-
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
- override var itemSize: CGSize {
- get {
- if let collectionView = collectionView {
-
- if collectionView.frame.width < 400 {
- itemForLine = 3
- } else {
- itemForLine = collectionView.frame.width / itemWidthDefault
- }
-
- let itemWidth: CGFloat = (collectionView.frame.width - marginLeftRight * 2 - marginLeftRight * (itemForLine - 1)) / itemForLine
- let itemHeight: CGFloat = itemWidth + heightLabelPlusButton
-
- return CGSize(width: itemWidth, height: itemHeight)
- }
-
- // Default fallback
- return CGSize(width: itemWidthDefault, height: itemWidthDefault)
- }
- set {
- super.itemSize = newValue
- }
- }
-
- override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint) -> CGPoint {
- return proposedContentOffset
- }
- }
|