123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641 |
- //
- // NCMainCommon.swift
- // Nextcloud
- //
- // Created by Marino Faggiana on 18/07/18.
- // Copyright © 2018 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 TLPhotoPicker
- import ZIPFoundation
- import NCCommunication
- //MARK: - Main Common
- class NCMainCommon: NSObject, PhotoEditorDelegate, NCAudioRecorderViewControllerDelegate, UIDocumentInteractionControllerDelegate {
-
- @objc static let sharedInstance: NCMainCommon = {
- let instance = NCMainCommon()
- instance.createImagesThemingColor()
- return instance
- }()
-
- let appDelegate = UIApplication.shared.delegate as! AppDelegate
- var metadataEditPhoto: tableMetadata?
- var docController: UIDocumentInteractionController?
- lazy var operationQueueReloadDatasource: OperationQueue = {
- let queue = OperationQueue()
- queue.name = "Reload main datasource queue"
- queue.maxConcurrentOperationCount = 1
- return queue
- }()
-
- //MARK: -
-
- struct NCMainCommonImages {
- static var cellSharedImage = UIImage()
- static var cellCanShareImage = UIImage()
- static var cellShareByLinkImage = UIImage()
- static var cellFavouriteImage = UIImage()
- static var cellMoreImage = UIImage()
- static var cellCommentImage = UIImage()
-
- static var cellFolderEncryptedImage = UIImage()
- static var cellFolderSharedWithMeImage = UIImage()
- static var cellFolderPublicImage = UIImage()
- static var cellFolderGroupImage = UIImage()
- static var cellFolderExternalImage = UIImage()
- static var cellFolderAutomaticUploadImage = UIImage()
- static var cellFolderImage = UIImage()
- }
-
- @objc func createImagesThemingColor() {
- NCMainCommonImages.cellSharedImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "share"), width: 100, height: 100, color: NCBrandColor.sharedInstance.textView)
- NCMainCommonImages.cellCanShareImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "share"), width: 100, height: 100, color: NCBrandColor.sharedInstance.graySoft)
- NCMainCommonImages.cellShareByLinkImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "sharebylink"), width: 100, height: 100, color: NCBrandColor.sharedInstance.textView)
- NCMainCommonImages.cellFavouriteImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "favorite"), width: 100, height: 100, color: NCBrandColor.sharedInstance.yellowFavorite)
- NCMainCommonImages.cellMoreImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "more"), width: 50, height: 50, color: NCBrandColor.sharedInstance.optionItem)
- NCMainCommonImages.cellCommentImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "comment"), width: 30, height: 30, color: NCBrandColor.sharedInstance.graySoft)
-
- NCMainCommonImages.cellFolderEncryptedImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "folderEncrypted"), width: 600, height: 600, color: NCBrandColor.sharedInstance.brandElement)
- NCMainCommonImages.cellFolderSharedWithMeImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "folder_shared_with_me"), width: 600, height: 600, color: NCBrandColor.sharedInstance.brandElement)
- NCMainCommonImages.cellFolderPublicImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "folder_public"), width: 600, height: 600, color: NCBrandColor.sharedInstance.brandElement)
- NCMainCommonImages.cellFolderGroupImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "folder_group"), width: 600, height: 600, color: NCBrandColor.sharedInstance.brandElement)
- NCMainCommonImages.cellFolderExternalImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "folder_external"), width: 600, height: 600, color: NCBrandColor.sharedInstance.brandElement)
- NCMainCommonImages.cellFolderAutomaticUploadImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "folderAutomaticUpload"), width: 600, height: 600, color: NCBrandColor.sharedInstance.brandElement)
- NCMainCommonImages.cellFolderImage = CCGraphics.changeThemingColorImage(UIImage.init(named: "folder"), width: 600, height: 600, color: NCBrandColor.sharedInstance.brandElement)
- }
-
- //MARK: -
-
- @objc func triggerProgressTask(_ notification: Notification, sectionDataSourceocIdIndexPath: NSDictionary, tableView: UITableView, viewController: UIViewController, serverUrlViewController: String?) {
-
- if viewController.viewIfLoaded?.window == nil {
- return
- }
-
- guard let dic = notification.userInfo else {
- return
- }
-
- let account = dic["account"] as? NSString ?? ""
- let ocId = dic["ocId"] as? NSString ?? ""
- let serverUrl = dic["serverUrl"] as? String ?? ""
- let status = dic["status"] as? Int ?? Int(k_taskIdentifierDone)
- let progress = dic["progress"] as? CGFloat ?? 0
- let totalBytes = dic["totalBytes"] as? Double ?? 0
- let totalBytesExpected = dic["totalBytesExpected"] as? Double ?? 0
-
- if (account != self.appDelegate.activeAccount! as NSString) && !(viewController is CCTransfers) {
- return
- }
-
- if serverUrlViewController != nil && serverUrlViewController! != serverUrl {
- return
- }
-
- appDelegate.listProgressMetadata.setObject([progress as NSNumber, totalBytes as NSNumber, totalBytesExpected as NSNumber], forKey: ocId)
-
- guard let indexPath = sectionDataSourceocIdIndexPath.object(forKey: ocId) else {
- return
- }
-
- if isValidIndexPath(indexPath as! IndexPath, view: tableView) {
-
- if let cell = tableView.cellForRow(at: indexPath as! IndexPath) as? CCCellMainTransfer {
-
- var image = ""
-
- if status == k_metadataStatusInDownload {
- image = "↓"
- } else if status == k_metadataStatusInUpload {
- image = "↑"
- }
-
- cell.labelInfoFile?.text = CCUtility.transformedSize(totalBytesExpected) + " - " + image + CCUtility.transformedSize(totalBytes)
- cell.transferButton?.progress = progress
- }
- }
- }
-
- @objc func cancelTransferMetadata(_ metadata: tableMetadata, reloadDatasource: Bool, uploadStatusForcedStart: Bool) {
-
- var actionReloadDatasource = k_action_NULL
- var metadata = metadata
-
- if metadata.session.count == 0 { return }
- guard let session = CCNetworking.shared().getSessionfromSessionDescription(metadata.session) else { return }
-
- session.getTasksWithCompletionHandler { (dataTasks, uploadTasks, downloadTasks) in
-
- var cancel = false
-
- // DOWNLOAD
- if metadata.session.count > 0 && metadata.session.contains("download") {
- for task in downloadTasks {
- if task.taskIdentifier == metadata.sessionTaskIdentifier {
- task.cancel()
- cancel = true
- }
- }
- if cancel == false {
- NCManageDatabase.sharedInstance.setMetadataSession("", sessionError: "", sessionSelector: "", sessionTaskIdentifier: Int(k_taskIdentifierDone), status: Int(k_metadataStatusNormal), predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
- }
- actionReloadDatasource = k_action_MOD
- }
-
- // UPLOAD
- if metadata.session.count > 0 && metadata.session.contains("upload") {
- for task in uploadTasks {
- if task.taskIdentifier == metadata.sessionTaskIdentifier {
- if uploadStatusForcedStart {
- metadata.status = Int(k_metadataStatusUploadForcedStart)
- metadata = NCManageDatabase.sharedInstance.addMetadata(metadata) ?? metadata
- }
- task.cancel()
- cancel = true
- }
- }
- if cancel == false {
- do {
- try FileManager.default.removeItem(atPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId))
- }
- catch { }
- NCManageDatabase.sharedInstance.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
- }
- actionReloadDatasource = k_action_DEL
- }
-
- DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
- self.reloadDatasource(ServerUrl: metadata.serverUrl, ocId: metadata.ocId, action: actionReloadDatasource)
- }
- }
- }
-
- @objc func cancelAllTransfer() {
-
- // Delete k_metadataStatusWaitUpload OR k_metadataStatusUploadError
- NCManageDatabase.sharedInstance.deleteMetadata(predicate: NSPredicate(format: "status == %d OR status == %d", appDelegate.activeAccount, k_metadataStatusWaitUpload, k_metadataStatusUploadError))
-
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
- if let metadatas = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "status != %d AND status != %d", k_metadataStatusNormal, k_metadataStatusHide), sorted: "fileName", ascending: true) {
-
- for metadata in metadatas {
-
- // Modify
- if (metadata.status == k_metadataStatusWaitDownload || metadata.status == k_metadataStatusDownloadError) {
- metadata.session = ""
- metadata.sessionSelector = ""
- metadata.status = Int(k_metadataStatusNormal)
-
- _ = NCManageDatabase.sharedInstance.addMetadata(metadata)
- }
-
- // Cancel Task
- if metadata.status == k_metadataStatusDownloading || metadata.status == k_metadataStatusUploading {
- self.cancelTransferMetadata(metadata, reloadDatasource: false, uploadStatusForcedStart: false)
- }
- }
- }
- }
-
- DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
- return
- }
- }
-
- //MARK: -
-
- func collectionViewCellForItemAt(_ indexPath: IndexPath, collectionView: UICollectionView, cell: UICollectionViewCell, metadata: tableMetadata, metadataFolder: tableMetadata?, serverUrl: String, isEditMode: Bool, selectocId: [String], autoUploadFileName: String, autoUploadDirectory: String, hideButtonMore: Bool, downloadThumbnail: Bool, shares: [tableShare]?, source: UIViewController) {
-
- var tableShare: tableShare?
-
- // Share
- if shares != nil {
- for share in shares! {
- if share.fileName == metadata.fileName {
- tableShare = share
- break
- }
- }
- }
-
- // Download preview
- if downloadThumbnail {
- NCNetworkingMain.sharedInstance.downloadThumbnail(with: metadata, view: collectionView, indexPath: indexPath)
- }
-
- var isShare = false
- var isMounted = false
-
- if metadataFolder != nil {
- isShare = metadata.permissions.contains(k_permission_shared) && !metadataFolder!.permissions.contains(k_permission_shared)
- isMounted = metadata.permissions.contains(k_permission_mounted) && !metadataFolder!.permissions.contains(k_permission_mounted)
- }
-
- if cell is NCListCell {
-
- let cell = cell as! NCListCell
-
- cell.delegate = source as? NCListCellDelegate
-
- cell.objectId = metadata.ocId
- cell.indexPath = indexPath
- cell.labelTitle.text = metadata.fileNameView
- cell.labelTitle.textColor = NCBrandColor.sharedInstance.textView
- cell.imageStatus.image = nil
- cell.imageLocal.image = nil
- cell.imageFavorite.image = nil
- cell.shared.image = nil
-
- if metadata.directory {
-
- if metadata.e2eEncrypted {
- cell.imageItem.image = NCMainCommonImages.cellFolderEncryptedImage
- } else if isShare {
- cell.imageItem.image = NCMainCommonImages.cellFolderSharedWithMeImage
- } else if (tableShare != nil && tableShare!.shareType != Int(shareTypeLink.rawValue)) {
- cell.imageItem.image = NCMainCommonImages.cellFolderSharedWithMeImage
- } else if (tableShare != nil && tableShare!.shareType == Int(shareTypeLink.rawValue)) {
- cell.imageItem.image = NCMainCommonImages.cellFolderPublicImage
- } else if metadata.mountType == "group" {
- cell.imageItem.image = NCMainCommonImages.cellFolderGroupImage
- } else if isMounted {
- cell.imageItem.image = NCMainCommonImages.cellFolderExternalImage
- } else if metadata.fileName == autoUploadFileName && serverUrl == autoUploadDirectory {
- cell.imageItem.image = NCMainCommonImages.cellFolderAutomaticUploadImage
- } else {
- cell.imageItem.image = NCMainCommonImages.cellFolderImage
- }
-
- cell.labelInfo.text = CCUtility.dateDiff(metadata.date as Date)
-
- let lockServerUrl = CCUtility.stringAppendServerUrl(serverUrl, addFileName: metadata.fileName)!
- let tableDirectory = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.activeAccount, lockServerUrl))
-
- // Status image: passcode
- if tableDirectory != nil && tableDirectory!.lock && CCUtility.getBlockCode() != nil {
- cell.imageStatus.image = UIImage.init(named: "passcode")
- }
-
- // Local image: offline
- if tableDirectory != nil && tableDirectory!.offline {
- cell.imageLocal.image = UIImage.init(named: "offlineFlag")
- }
-
- } else {
-
- if FileManager().fileExists(atPath: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, fileNameView: metadata.fileName)) {
- NCUtility.sharedInstance.loadImage(ocId: metadata.ocId, fileNameView: metadata.fileNameView) { (image) in
- cell.imageItem.image = image
- }
- } else {
- if metadata.iconName.count > 0 {
- cell.imageItem.image = UIImage.init(named: metadata.iconName)
- } else {
- cell.imageItem.image = UIImage.init(named: "file")
- }
- }
-
- cell.labelInfo.text = CCUtility.dateDiff(metadata.date as Date) + ", " + CCUtility.transformedSize(metadata.size)
-
- // image local
- let size = CCUtility.fileProviderStorageSize(metadata.ocId, fileNameView: metadata.fileNameView)
- if size > 0 {
- var tableLocalFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
- if tableLocalFile == nil && size == metadata.size {
- tableLocalFile = NCManageDatabase.sharedInstance.addLocalFile(metadata: metadata)
- }
- if tableLocalFile!.offline { cell.imageLocal.image = UIImage.init(named: "offlineFlag") }
- else { cell.imageLocal.image = UIImage.init(named: "local") }
- }
- }
-
- // image Favorite
- if metadata.favorite {
- cell.imageFavorite.image = NCMainCommonImages.cellFavouriteImage
- }
-
- // Share image
- if (isShare) {
- cell.shared.image = NCMainCommonImages.cellSharedImage
- } else if (tableShare != nil && tableShare!.shareType == Int(shareTypeLink.rawValue)) {
- cell.shared.image = NCMainCommonImages.cellShareByLinkImage
- } else if (tableShare != nil && tableShare!.shareType != Int(shareTypeLink.rawValue)) {
- cell.shared.image = NCMainCommonImages.cellSharedImage
- } else {
- cell.shared.image = NCMainCommonImages.cellCanShareImage
- }
- if metadata.ownerId != appDelegate.activeUserID {
- // Load avatar
- let fileNameSource = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(appDelegate.activeUser, activeUrl: appDelegate.activeUrl) + "-" + metadata.ownerId + ".png"
- let fileNameSourceAvatar = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(appDelegate.activeUser, activeUrl: appDelegate.activeUrl) + "-avatar-" + metadata.ownerId + ".png"
- if FileManager.default.fileExists(atPath: fileNameSourceAvatar) {
- cell.shared.image = UIImage(contentsOfFile: fileNameSourceAvatar)
- } else if FileManager.default.fileExists(atPath: fileNameSource) {
- cell.shared.image = NCUtility.sharedInstance.createAvatar(fileNameSource: fileNameSource, fileNameSourceAvatar: fileNameSourceAvatar)
- } else {
- NCCommunication.sharedInstance.downloadAvatar(urlString: appDelegate.activeUrl, userID: metadata.ownerId, fileNameLocalPath: fileNameSource, size: Int(k_avatar_size), account: appDelegate.activeAccount) { (account, data, errorCode, errorMessage) in
- if errorCode == 0 && account == self.appDelegate.activeAccount {
- cell.shared.image = NCUtility.sharedInstance.createAvatar(fileNameSource: fileNameSource, fileNameSourceAvatar: fileNameSourceAvatar)
- }
- }
- }
- }
-
- if isEditMode {
- cell.imageItemLeftConstraint.constant = 45
- cell.imageSelect.isHidden = false
-
- if selectocId.contains(metadata.ocId) {
- cell.imageSelect.image = CCGraphics.scale(UIImage.init(named: "checkedYes"), to: CGSize(width: 50, height: 50), isAspectRation: true)
- cell.backgroundView = NCUtility.sharedInstance.cellBlurEffect(with: cell.bounds)
- } else {
- cell.imageSelect.image = CCGraphics.scale(UIImage.init(named: "checkedNo"), to: CGSize(width: 50, height: 50), isAspectRation: true)
- cell.backgroundView = nil
- }
- } else {
- cell.imageItemLeftConstraint.constant = 10
- cell.imageSelect.isHidden = true
- cell.backgroundView = nil
- }
-
- // Remove last separator
- if collectionView.numberOfItems(inSection: indexPath.section) == indexPath.row + 1 {
- cell.separator.isHidden = true
- } else {
- cell.separator.isHidden = false
- }
-
- } else if cell is NCGridCell {
-
- let cell = cell as! NCGridCell
- cell.delegate = source as? NCGridCellDelegate
-
- cell.objectId = metadata.ocId
- cell.indexPath = indexPath
- cell.labelTitle.text = metadata.fileNameView
- cell.labelTitle.textColor = NCBrandColor.sharedInstance.textView
- cell.imageStatus.image = nil
- cell.imageLocal.image = nil
- cell.imageFavorite.image = nil
-
- if metadata.directory {
-
- if metadata.e2eEncrypted {
- cell.imageItem.image = NCMainCommonImages.cellFolderEncryptedImage
- } else if isShare {
- cell.imageItem.image = NCMainCommonImages.cellFolderSharedWithMeImage
- } else if (tableShare != nil && tableShare!.shareType != Int(shareTypeLink.rawValue)) {
- cell.imageItem.image = NCMainCommonImages.cellFolderSharedWithMeImage
- } else if (tableShare != nil && tableShare!.shareType == Int(shareTypeLink.rawValue)) {
- cell.imageItem.image = NCMainCommonImages.cellFolderPublicImage
- } else if metadata.mountType == "group" {
- cell.imageItem.image = NCMainCommonImages.cellFolderGroupImage
- } else if isMounted {
- cell.imageItem.image = NCMainCommonImages.cellFolderExternalImage
- } else if metadata.fileName == autoUploadFileName && serverUrl == autoUploadDirectory {
- cell.imageItem.image = NCMainCommonImages.cellFolderAutomaticUploadImage
- } else {
- cell.imageItem.image = NCMainCommonImages.cellFolderImage
- }
-
-
- let lockServerUrl = CCUtility.stringAppendServerUrl(serverUrl, addFileName: metadata.fileName)!
- let tableDirectory = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.activeAccount, lockServerUrl))
-
- // Status image: passcode
- if tableDirectory != nil && tableDirectory!.lock && CCUtility.getBlockCode() != nil {
- cell.imageStatus.image = UIImage.init(named: "passcode")
- }
-
- // Local image: offline
- if tableDirectory != nil && tableDirectory!.offline {
- cell.imageLocal.image = UIImage.init(named: "offlineFlag")
- }
-
- } else {
-
- if FileManager().fileExists(atPath: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, fileNameView: metadata.fileName)) {
- NCUtility.sharedInstance.loadImage(ocId: metadata.ocId, fileNameView: metadata.fileNameView) { (image) in
- cell.imageItem.image = image
- }
- } else {
- if metadata.iconName.count > 0 {
- cell.imageItem.image = UIImage.init(named: metadata.iconName)
- } else {
- cell.imageItem.image = UIImage.init(named: "file")
- }
- }
-
- // image Local
- let tableLocalFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
- if tableLocalFile != nil && CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
- if tableLocalFile!.offline { cell.imageLocal.image = UIImage.init(named: "offlineFlag") }
- else { cell.imageLocal.image = UIImage.init(named: "local") }
- }
- }
-
- // image Favorite
- if metadata.favorite {
- cell.imageFavorite.image = NCMainCommonImages.cellFavouriteImage
- }
-
- if isEditMode {
- cell.imageSelect.isHidden = false
- if selectocId.contains(metadata.ocId) {
- cell.imageSelect.image = CCGraphics.scale(UIImage.init(named: "checkedYes"), to: CGSize(width: 50, height: 50), isAspectRation: true)
- cell.backgroundView = NCUtility.sharedInstance.cellBlurEffect(with: cell.bounds)
- } else {
- cell.imageSelect.isHidden = true
- cell.backgroundView = nil
- }
- } else {
- cell.imageSelect.isHidden = true
- cell.backgroundView = nil
- }
-
- } else if cell is NCGridMediaCell {
-
- let cell = cell as! NCGridMediaCell
-
- cell.imageStatus.image = nil
- cell.imageLocal.image = nil
- cell.imageFavorite.image = nil
-
- if FileManager().fileExists(atPath: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, fileNameView: metadata.fileName)) {
- cell.imageItem.image = UIImage.init(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, fileNameView: metadata.fileName))
- // NCUtility.sharedInstance.loadImage(ocId: metadata.ocId, fileNameView: metadata.fileNameView) { (image) in
- // cell.imageItem.image = image
- // }
- } else {
- if metadata.iconName.count > 0 {
- cell.imageItem.image = UIImage.init(named: metadata.iconName)
- } else {
- cell.imageItem.image = UIImage.init(named: "file")
- }
- }
-
- // image Local
- let tableLocalFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
- if tableLocalFile != nil && CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
- if tableLocalFile!.offline { cell.imageLocal.image = UIImage.init(named: "offlineFlag") }
- else { cell.imageLocal.image = UIImage.init(named: "local") }
- }
-
- // image Favorite
- if metadata.favorite {
- cell.imageFavorite.image = NCMainCommonImages.cellFavouriteImage
- }
-
- if isEditMode {
- cell.imageSelect.isHidden = false
- if selectocId.contains(metadata.ocId) {
- cell.imageSelect.image = CCGraphics.scale(UIImage.init(named: "checkedYes"), to: CGSize(width: 50, height: 50), isAspectRation: true)
- cell.imageVisualEffect.isHidden = false
- cell.imageVisualEffect.alpha = 0.4
- } else {
- cell.imageSelect.isHidden = true
- cell.imageVisualEffect.isHidden = true
- }
- } else {
- cell.imageSelect.isHidden = true
- cell.imageVisualEffect.isHidden = true
- }
- }
- }
-
- @objc func cellForRowAtIndexPath(_ indexPath: IndexPath, tableView: UITableView ,metadata: tableMetadata, metadataFolder: tableMetadata?, serverUrl: String, autoUploadFileName: String, autoUploadDirectory: String, tableShare: tableShare?) -> UITableViewCell {
-
- // Create File System
- if metadata.directory {
- CCUtility.getDirectoryProviderStorageOcId(metadata.ocId)
- } else {
- CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)
- }
-
- // CCCell
- if metadata.status == k_metadataStatusNormal {
-
- // NORMAL
-
- let cell = tableView.dequeueReusableCell(withIdentifier: "CellMain", for: indexPath) as! CCCellMain
- cell.separatorInset = UIEdgeInsets.init(top: 0, left: 60, bottom: 0, right: 0)
- cell.accessoryType = UITableViewCell.AccessoryType.none
- cell.file.image = nil
- cell.status.image = nil
- cell.favorite.image = nil
- cell.shared.image = nil
- cell.local.image = nil
- cell.comment.image = nil
- cell.shared.isUserInteractionEnabled = false
- cell.viewShared.backgroundColor = NCBrandColor.sharedInstance.backgroundView
- cell.backgroundColor = NCBrandColor.sharedInstance.backgroundView
-
- // change color selection
- let selectionColor = UIView()
- selectionColor.backgroundColor = NCBrandColor.sharedInstance.select
- cell.selectedBackgroundView = selectionColor
- cell.tintColor = NCBrandColor.sharedInstance.brandElement
-
- cell.labelTitle.textColor = NCBrandColor.sharedInstance.textView
- cell.labelTitle.text = metadata.fileNameView
-
- // Download preview
- NCNetworkingMain.sharedInstance.downloadThumbnail(with: metadata, view: tableView, indexPath: indexPath)
-
- // Share
- var isShare = false
- var isMounted = false
-
- if metadataFolder != nil {
- isShare = metadata.permissions.contains(k_permission_shared) && !metadataFolder!.permissions.contains(k_permission_shared)
- isMounted = metadata.permissions.contains(k_permission_mounted) && !metadataFolder!.permissions.contains(k_permission_mounted)
- }
-
- if metadata.directory {
-
- // lable Info
- cell.labelInfoFile.text = CCUtility.dateDiff(metadata.date as Date)
-
- // File Image & Image Title Segue
- if metadata.e2eEncrypted {
- cell.file.image = NCMainCommonImages.cellFolderEncryptedImage
- } else if isShare {
- cell.file.image = NCMainCommonImages.cellFolderSharedWithMeImage
- } else if (tableShare != nil && tableShare!.shareType != Int(shareTypeLink.rawValue)) {
- cell.file.image = NCMainCommonImages.cellFolderSharedWithMeImage
- } else if (tableShare != nil && tableShare!.shareType == Int(shareTypeLink.rawValue)) {
- cell.file.image = NCMainCommonImages.cellFolderPublicImage
- } else if metadata.mountType == "group" {
- cell.file.image = NCMainCommonImages.cellFolderGroupImage
- } else if isMounted {
- cell.file.image = NCMainCommonImages.cellFolderExternalImage
- } else if metadata.fileName == autoUploadFileName && serverUrl == autoUploadDirectory {
- cell.file.image = NCMainCommonImages.cellFolderAutomaticUploadImage
- } else {
- cell.file.image = NCMainCommonImages.cellFolderImage
- }
-
- let lockServerUrl = CCUtility.stringAppendServerUrl(serverUrl, addFileName: metadata.fileName)!
- let tableDirectory = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.activeAccount, lockServerUrl))
- // Local image: offline
- if tableDirectory != nil && tableDirectory!.offline {
- cell.local.image = UIImage.init(named: "offlineFlag")
- }
- // Status image: passcode
- if tableDirectory != nil && tableDirectory!.lock && CCUtility.getBlockCode() != nil {
- cell.status.image = UIImage.init(named: "passcode")
- }
-
- } else {
-
- let iconFileExists = FileManager.default.fileExists(atPath: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, fileNameView: metadata.fileNameView))
-
- // Lable Info
- cell.labelInfoFile.text = CCUtility.dateDiff(metadata.date as Date) + ", " + CCUtility.transformedSize(metadata.size)
-
- // File Image
- if iconFileExists {
- NCUtility.sharedInstance.loadImage(ocId: metadata.ocId, fileNameView: metadata.fileNameView) { (image) in
- cell.file.image = image
- }
- } else {
- if metadata.iconName.count > 0 {
- cell.file.image = UIImage.init(named: metadata.iconName)
- } else {
- cell.file.image = UIImage.init(named: "file")
- }
- }
-
- // Local Image - Offline
- let size = CCUtility.fileProviderStorageSize(metadata.ocId, fileNameView: metadata.fileNameView)
- if size > 0 {
- var tableLocalFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
- if tableLocalFile == nil && size == metadata.size {
- tableLocalFile = NCManageDatabase.sharedInstance.addLocalFile(metadata: metadata)
- }
- if tableLocalFile != nil && tableLocalFile!.offline { cell.local.image = UIImage.init(named: "offlineFlag") }
- else { cell.local.image = UIImage.init(named: "local") }
- }
-
- // Status image: encrypted
- let tableE2eEncryption = NCManageDatabase.sharedInstance.getE2eEncryption(predicate: NSPredicate(format: "account == %@ AND fileNameIdentifier == %@", appDelegate.activeAccount, metadata.fileName))
- if tableE2eEncryption != nil && NCUtility.sharedInstance.isEncryptedMetadata(metadata) {
- cell.status.image = UIImage.init(named: "encrypted")
- }
- }
-
- //
- // File & Directory
- //
-
- // Favorite
- if metadata.favorite {
- cell.favorite.image = NCMainCommonImages.cellFavouriteImage
- }
-
- // Share image
- if (isShare) {
- cell.shared.image = NCMainCommonImages.cellSharedImage
- } else if (tableShare != nil && tableShare!.shareType == Int(shareTypeLink.rawValue)) {
- cell.shared.image = NCMainCommonImages.cellShareByLinkImage
- } else if (tableShare != nil && tableShare!.shareType != Int(shareTypeLink.rawValue)) {
- cell.shared.image = NCMainCommonImages.cellSharedImage
- } else {
- cell.shared.image = NCMainCommonImages.cellCanShareImage
- }
- if metadata.ownerId != appDelegate.activeUserID {
- // Load avatar
- let fileNameSource = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(appDelegate.activeUser, activeUrl: appDelegate.activeUrl) + "-" + metadata.ownerId + ".png"
- let fileNameSourceAvatar = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(appDelegate.activeUser, activeUrl: appDelegate.activeUrl) + "-avatar-" + metadata.ownerId + ".png"
- if FileManager.default.fileExists(atPath: fileNameSourceAvatar) {
- if let avatar = UIImage(contentsOfFile: fileNameSourceAvatar) {
- cell.shared.image = avatar
- }
- } else if FileManager.default.fileExists(atPath: fileNameSource) {
- if let avatar = NCUtility.sharedInstance.createAvatar(fileNameSource: fileNameSource, fileNameSourceAvatar: fileNameSourceAvatar) {
- cell.shared.image = avatar
- }
- } else {
- NCCommunication.sharedInstance.downloadAvatar(urlString: appDelegate.activeUrl, userID: metadata.ownerId, fileNameLocalPath: fileNameSource, size: Int(k_avatar_size), account: appDelegate.activeAccount) { (account, data, errorCode, errorMessage) in
- if errorCode == 0 && account == self.appDelegate.activeAccount {
- cell.shared.image = NCUtility.sharedInstance.createAvatar(fileNameSource: fileNameSource, fileNameSourceAvatar: fileNameSourceAvatar)
- }
- }
- }
- }
-
- // Comment
- if metadata.commentsUnread {
- cell.comment.image = NCMainCommonImages.cellCommentImage
- cell.labelTitleTrailingConstraint.constant = 160
- } else {
- cell.labelTitleTrailingConstraint.constant = 110
- }
-
- // More Image
- cell.more.image = NCMainCommonImages.cellMoreImage
-
- return cell
-
- } else {
-
- // TRASNFER
-
- let cell = tableView.dequeueReusableCell(withIdentifier: "CellMainTransfer", for: indexPath) as! CCCellMainTransfer
- cell.separatorInset = UIEdgeInsets.init(top: 0, left: 60, bottom: 0, right: 0)
- cell.accessoryType = UITableViewCell.AccessoryType.none
- cell.file.image = nil
- cell.status.image = nil
- cell.user.image = nil
-
- cell.backgroundColor = NCBrandColor.sharedInstance.backgroundView
- cell.labelTitle.text = metadata.fileNameView
- cell.labelTitle.textColor = NCBrandColor.sharedInstance.textView
-
- cell.transferButton.tintColor = NCBrandColor.sharedInstance.optionItem
-
- var progress: CGFloat = 0.0
- var totalBytes: Double = 0.0
- //var totalBytesExpected : Double = 0
- let progressArray = appDelegate.listProgressMetadata.object(forKey: metadata.ocId) as? NSArray
- if progressArray != nil && progressArray?.count == 3 {
- progress = progressArray?.object(at: 0) as! CGFloat
- totalBytes = progressArray?.object(at: 1) as! Double
- //totalBytesExpected = progressArray?.object(at: 2) as! Double
- }
-
- // Write status on Label Info
- switch metadata.status {
- case Int(k_metadataStatusWaitDownload):
- cell.labelInfoFile.text = CCUtility.transformedSize(metadata.size) + " - " + NSLocalizedString("_status_wait_download_", comment: "")
- progress = 0.0
- break
- case Int(k_metadataStatusInDownload):
- cell.labelInfoFile.text = CCUtility.transformedSize(metadata.size) + " - " + NSLocalizedString("_status_in_download_", comment: "")
- progress = 0.0
- break
- case Int(k_metadataStatusDownloading):
- cell.labelInfoFile.text = CCUtility.transformedSize(metadata.size) + " - ↓" + CCUtility.transformedSize(totalBytes)
- break
- case Int(k_metadataStatusWaitUpload):
- cell.labelInfoFile.text = CCUtility.transformedSize(metadata.size) + " - " + NSLocalizedString("_status_wait_upload_", comment: "")
- progress = 0.0
- break
- case Int(k_metadataStatusInUpload):
- cell.labelInfoFile.text = CCUtility.transformedSize(metadata.size) + " - " + NSLocalizedString("_status_in_upload_", comment: "")
- progress = 0.0
- break
- case Int(k_metadataStatusUploading):
- cell.labelInfoFile.text = CCUtility.transformedSize(metadata.size) + " - ↑" + CCUtility.transformedSize(totalBytes)
- break
- default:
- cell.labelInfoFile.text = CCUtility.transformedSize(metadata.size)
- progress = 0.0
- }
-
- let iconFileExists = FileManager.default.fileExists(atPath: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, fileNameView: metadata.fileNameView))
- if iconFileExists {
- NCUtility.sharedInstance.loadImage(ocId: metadata.ocId, fileNameView: metadata.fileNameView) { (image) in
- cell.file.image = image
- }
- } else {
- if metadata.iconName.count > 0 {
- cell.file.image = UIImage.init(named: metadata.iconName)
- } else {
- cell.file.image = UIImage.init(named: "file")
- }
- }
-
- // Session Upload Extension
- if metadata.session == k_upload_session_extension {
-
- cell.labelTitle.isEnabled = false
- cell.labelInfoFile.isEnabled = false
-
- } else {
-
- cell.labelTitle.isEnabled = true
- cell.labelInfoFile.isEnabled = true
- }
-
- // downloadFile
- if metadata.status == k_metadataStatusWaitDownload || metadata.status == k_metadataStatusInDownload || metadata.status == k_metadataStatusDownloading || metadata.status == k_metadataStatusDownloadError {
- //
- }
-
- // downloadFile Error
- if metadata.status == k_metadataStatusDownloadError {
-
- cell.status.image = UIImage.init(named: "statuserror")
-
- if metadata.sessionError.count == 0 {
- cell.labelInfoFile.text = NSLocalizedString("_error_", comment: "") + ", " + NSLocalizedString("_file_not_downloaded_", comment: "")
- } else {
- cell.labelInfoFile.text = metadata.sessionError
- }
- }
-
- // uploadFile
- if metadata.status == k_metadataStatusWaitUpload || metadata.status == k_metadataStatusInUpload || metadata.status == k_metadataStatusUploading || metadata.status == k_metadataStatusUploadError {
-
- if (!iconFileExists) {
- cell.file.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "uploadCloud"), multiplier: 2, color: NCBrandColor.sharedInstance.brandElement)
- }
-
- cell.labelTitle.isEnabled = false
- }
-
- // uploadFileError
- if metadata.status == k_metadataStatusUploadError {
-
- cell.labelTitle.isEnabled = false
- cell.status.image = UIImage.init(named: "statuserror")
-
- if !iconFileExists {
- cell.file.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "uploadCloud"), multiplier: 2, color: NCBrandColor.sharedInstance.brandElement)
- }
-
- if metadata.sessionError.count == 0 {
- cell.labelInfoFile.text = NSLocalizedString("_error_", comment: "") + ", " + NSLocalizedString("_file_not_uploaded_", comment: "")
- } else {
- cell.labelInfoFile.text = metadata.sessionError
- }
- }
-
- // Progress
- cell.transferButton.progress = progress
-
- // User
- if metadata.account != appDelegate.activeAccount {
- let tableAccount = NCManageDatabase.sharedInstance.getAccount(predicate: NSPredicate(format: "account == %@", metadata.account))
- if tableAccount != nil {
- let fileNamePath = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(tableAccount!.user, activeUrl: tableAccount!.url) + "-" + tableAccount!.user + ".png"
- var avatar = UIImage.init(contentsOfFile: fileNamePath)
- if avatar != nil {
- let avatarImageView = CCAvatar.init(image: avatar, borderColor: UIColor.black, borderWidth: 0.5)
- let imageSize = avatarImageView?.bounds.size
- UIGraphicsBeginImageContext(imageSize!)
- let context = UIGraphicsGetCurrentContext()
- avatarImageView?.layer.render(in: context!)
- avatar = UIGraphicsGetImageFromCurrentImageContext()
- UIGraphicsEndImageContext()
- cell.user.image = avatar
- }
- }
- }
-
- return cell
- }
- }
-
- @objc func getMetadataFromSectionDataSourceIndexPath(_ indexPath: IndexPath?, sectionDataSource: CCSectionDataSourceMetadata?) -> tableMetadata? {
-
- guard let indexPath = indexPath else {
- return nil
- }
-
- guard let sectionDataSource = sectionDataSource else {
- return nil
- }
-
- let section = indexPath.section + 1
- let row = indexPath.row + 1
- let totSections = sectionDataSource.sections.count
-
- if totSections < section || section > totSections {
- return nil
- }
-
- let valueSection = sectionDataSource.sections.object(at: indexPath.section)
- guard let filesID = sectionDataSource.sectionArrayRow.object(forKey: valueSection) as? NSArray else {
- return nil
- }
-
- let totRows = filesID.count
- if totRows < row || row > totRows {
- return nil
- }
-
- let ocId = filesID.object(at: indexPath.row)
- let metadata = sectionDataSource.allRecordsDataSource.object(forKey: ocId) as? tableMetadata
-
- return metadata
- }
-
- @objc func reloadDatasource(ServerUrl: String?, ocId: String?, action: Int32) {
-
- if operationQueueReloadDatasource.operationCount > 0 {
- return
- }
-
-
- if self.appDelegate.activeMain != nil && ServerUrl != nil && self.appDelegate.activeMain.serverUrl == ServerUrl {
- self.operationQueueReloadDatasource.addOperation {
- DispatchQueue.main.async {
- self.appDelegate.activeMain.reloadDatasource(ServerUrl, ocId: ocId, action: Int(action))
- }
- }
- }
- if self.appDelegate.activeFavorites != nil && self.appDelegate.activeFavorites.viewIfLoaded?.window != nil {
- self.operationQueueReloadDatasource.addOperation {
- DispatchQueue.main.async {
- self.appDelegate.activeFavorites.reloadDatasource(ocId, action: Int(action))
- }
- }
- }
- if self.appDelegate.activeTransfers != nil && self.appDelegate.activeTransfers.viewIfLoaded?.window != nil {
- self.operationQueueReloadDatasource.addOperation {
- DispatchQueue.main.async {
- self.appDelegate.activeTransfers.reloadDatasource(ocId, action: Int(action))
- }
- }
- }
- }
-
- @objc func isValidIndexPath(_ indexPath: IndexPath, view: Any) -> Bool {
-
- if view is UICollectionView {
- return indexPath.section < (view as! UICollectionView).numberOfSections && indexPath.row < (view as! UICollectionView).numberOfItems(inSection: indexPath.section)
- }
-
- if view is UITableView {
- return indexPath.section < (view as! UITableView).numberOfSections && indexPath.row < (view as! UITableView).numberOfRows(inSection: indexPath.section)
- }
-
- return true
- }
-
- //MARK: -
- /*
- @objc func deleteFile(metadatas: NSArray, e2ee: Bool, serverUrl: String, folderocId: String, completion: @escaping (_ errorCode: Int, _ message: String)->()) {
-
- var copyMetadatas = [tableMetadata]()
-
- for metadata in metadatas {
- copyMetadatas.append(tableMetadata.init(value: metadata))
- }
-
- if e2ee {
- DispatchQueue.global().async {
- let error = NCNetworkingEndToEnd.sharedManager().lockFolderEncrypted(onServerUrl: serverUrl, ocId: folderocId, user: self.appDelegate.activeUser, userID: self.appDelegate.activeUserID, password: self.appDelegate.activePassword, url: self.appDelegate.activeUrl)
- DispatchQueue.main.async {
- if error == nil {
- self.delete(metadatas: copyMetadatas, serverUrl:serverUrl, e2ee: e2ee, completion: completion)
- } else {
- NCContentPresenter.shared.messageNotification("_delete_", description: error?.localizedDescription, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: Int(k_CCErrorInternalError))
- return
- }
- }
- }
- } else {
- delete(metadatas: copyMetadatas, serverUrl: serverUrl, e2ee: e2ee) { (errorCode, message) in
- if errorCode != 0 {
- NCContentPresenter.shared.messageNotification("_delete_", description: message, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: errorCode)
- }
- completion(errorCode, message)
- }
- }
- }
-
- private func delete(metadatas: [tableMetadata], serverUrl: String, e2ee: Bool, completion: @escaping (_ errorCode: Int, _ message: String)->()) {
-
- var count: Int = 0
- var completionErrorCode: Int = 0
- var completionMessage = ""
-
- for metadata in metadatas {
-
- // verify permission
- let permission = NCUtility.sharedInstance.permissionsContainsString(metadata.permissions, permissions: k_permission_can_delete)
- if metadata.permissions != "" && permission == false {
- completion(Int(k_CCErrorInternalError), "_no_permission_delete_file_")
- return
- }
-
- self.appDelegate.filterocId.add(metadata.ocId)
-
- let serverUrlFileName = metadata.serverUrl + "/" + metadata.fileName
-
- NCCommunication.sharedInstance.deleteFileOrFolder(serverUrlFileName, account: appDelegate.activeAccount) { (account, errorCode, errorDescription) in
-
- if account == self.appDelegate.activeAccount {
-
- count += 1
- if errorCode == 0 || errorCode == kOCErrorServerPathNotFound {
-
- do {
- try FileManager.default.removeItem(atPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId))
- } catch { }
-
- NCManageDatabase.sharedInstance.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
- NCManageDatabase.sharedInstance.deleteLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
-
- if metadata.directory {
- NCManageDatabase.sharedInstance.deleteDirectoryAndSubDirectory(serverUrl: CCUtility.stringAppendServerUrl(serverUrl, addFileName: metadata.fileName), account: metadata.account)
- }
-
- if (e2ee) {
- NCManageDatabase.sharedInstance.deleteE2eEncryption(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileNameIdentifier == %@", metadata.account, serverUrl, metadata.fileName))
- }
-
- // Rich Workspace
- if metadata.fileNameView.lowercased() == k_fileNameRichWorkspace.lowercased() {
- self.appDelegate.activeMain.readFileReloadFolder()
- }
-
- self.appDelegate.filterocId.remove(metadata.ocId)
-
- } else {
-
- completionErrorCode = errorCode
- completionMessage = ""
- if errorDescription != nil {
- completionMessage = errorDescription!
- }
-
- self.appDelegate.filterocId.remove(metadata.ocId)
- }
-
- // Message
- let userInfo: [String : Any] = ["metadata": metadata, "errorCode": Int(errorCode), "errorDescription": completionMessage]
- NotificationCenter.default.post(name: Notification.Name.init(rawValue: k_notificationCenter_deleteFile), object: nil, userInfo: userInfo)
-
- if count == metadatas.count {
- if e2ee {
- DispatchQueue.global().async {
- NCNetworkingEndToEnd.sharedManager().rebuildAndSendMetadata(onServerUrl: serverUrl, account: self.appDelegate.activeAccount, user: self.appDelegate.activeUser, userID: self.appDelegate.activeUserID, password: self.appDelegate.activePassword, url: self.appDelegate.activeUrl)
- DispatchQueue.main.async {
- completion(completionErrorCode, completionMessage)
- }
- }
- } else {
- completion(completionErrorCode, completionMessage)
- }
- }
- }
- }
- }
-
- self.reloadDatasource(ServerUrl: serverUrl, ocId: nil, action: k_action_NULL)
- }
- */
-
- @objc func editPhoto(_ metadata: tableMetadata, viewController: UIViewController) {
- guard let path = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView) else {
- return
- }
- guard let image = UIImage(contentsOfFile: path) else {
- return
- }
-
- self.metadataEditPhoto = metadata
- let photoEditor = PhotoEditorViewController(nibName:"PhotoEditorViewController",bundle: Bundle(for: PhotoEditorViewController.self))
-
- photoEditor.image = image
- photoEditor.photoEditorDelegate = self
- photoEditor.hiddenControls = [.save, .share, .sticker]
-
- photoEditor.cancelButtonImage = CCGraphics.changeThemingColorImage(UIImage(named: "photoEditorCancel")!, multiplier:2, color: .white)
- photoEditor.cropButtonImage = CCGraphics.changeThemingColorImage(UIImage(named: "photoEditorCrop")!, multiplier:2, color: .white)
- photoEditor.drawButtonImage = CCGraphics.changeThemingColorImage(UIImage(named: "photoEditorDraw")!, multiplier:2, color: .white)
- photoEditor.textButtonImage = CCGraphics.changeThemingColorImage(UIImage(named: "photoEditorText")!, multiplier:2, color: .white)
- photoEditor.clearButtonImage = CCGraphics.changeThemingColorImage(UIImage(named: "photoEditorClear")!, multiplier:2, color: .white)
- photoEditor.continueButtonImage = CCGraphics.changeThemingColorImage(UIImage(named: "photoEditorDone")!, multiplier:2, color: .white)
-
- photoEditor.modalPresentationStyle = .fullScreen
- viewController.present(photoEditor, animated: true, completion: nil)
- }
-
- func doneEditing(image: UIImage) {
- guard let metadata = self.metadataEditPhoto else {
- return
- }
- guard let path = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView) else {
- return
- }
- guard let filetype = NCUtility.sharedInstance.isEditImage(metadata.fileNameView as NSString) else {
- return
- }
- if filetype == "PNG" {
- do {
- try image.pngData()?.write(to: NSURL(fileURLWithPath:path) as URL, options: .atomic)
- } catch { return }
- } else if filetype == "JPG" {
- let imageData = image.jpegData(compressionQuality: 1)
- do {
- try imageData?.write(to: NSURL(fileURLWithPath:path) as URL)
- } catch { return }
- }
- // write icon
- CCGraphics.createNewImage(from: metadata.fileNameView, ocId: metadata.ocId, extension: filetype, filterGrayScale: false, typeFile: metadata.typeFile, writeImage: true)
- // upload
- metadata.session = k_upload_session
- metadata.sessionSelector = selectorUploadFile
- metadata.status = Int(k_metadataStatusWaitUpload)
-
- _ = NCManageDatabase.sharedInstance.addMetadata(metadata)
- }
-
- func canceledEditing() {
- print("Canceled")
- }
-
- //MARK: - download Open Selector
-
- @objc func downloadOpen(metadata: tableMetadata, selector: String) {
-
- if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
-
- NCNetworkingMain.sharedInstance.downloadFileSuccessFailure(metadata.fileName, ocId: metadata.ocId, serverUrl: metadata.serverUrl, selector: selector, errorMessage: "", errorCode: 0)
-
- } else {
-
- metadata.session = k_download_session
- metadata.sessionError = ""
- metadata.sessionSelector = selector //selectorOpenIn
- metadata.status = Int(k_metadataStatusWaitDownload)
-
- _ = NCManageDatabase.sharedInstance.addMetadata(metadata)
- reloadDatasource(ServerUrl: metadata.serverUrl, ocId: metadata.ocId, action: k_action_MOD)
- }
- }
- //MARK: - OpenIn
-
- func openIn(metadata: tableMetadata, selector: String) {
-
- docController = UIDocumentInteractionController(url: NSURL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)) as URL)
- docController?.delegate = self
-
- if selector == selectorOpenInDetail {
- guard let barButtonItem = appDelegate.activeDetail.navigationItem.rightBarButtonItem else { return }
- guard let buttonItemView = barButtonItem.value(forKey: "view") as? UIView else { return }
-
- docController?.presentOptionsMenu(from: buttonItemView.frame, in: buttonItemView, animated: true)
-
- } else {
- guard let splitViewController = self.appDelegate.window?.rootViewController as? UISplitViewController, let view = splitViewController.viewControllers.first?.view, let frame = splitViewController.viewControllers.first?.view.frame else {
- return }
-
- docController?.presentOptionsMenu(from: frame, in: view, animated: true)
- }
- }
-
- //MARK: - OpenShare
- @objc func openShare(ViewController: UIViewController, metadata: tableMetadata, indexPage: Int) {
-
- let shareNavigationController = UIStoryboard(name: "NCShare", bundle: nil).instantiateInitialViewController() as! UINavigationController
- let shareViewController = shareNavigationController.topViewController as! NCSharePaging
-
- shareViewController.metadata = metadata
- shareViewController.indexPage = indexPage
-
- shareNavigationController.modalPresentationStyle = .formSheet
- ViewController.present(shareNavigationController, animated: true, completion: nil)
- }
-
- //MARK: - NCAudioRecorder
-
- func startAudioRecorder() {
-
- let fileName = CCUtility.createFileNameDate(NSLocalizedString("_voice_memo_filename_", comment: ""), extension: "m4a")!
- let viewController = UIStoryboard(name: "NCAudioRecorderViewController", bundle: nil).instantiateInitialViewController() as! NCAudioRecorderViewController
-
- viewController.delegate = self
- viewController.createRecorder(fileName: fileName)
- viewController.modalTransitionStyle = .crossDissolve
- viewController.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
-
- self.appDelegate.window.rootViewController?.present(viewController, animated: true, completion: nil)
- }
-
- func didFinishRecording(_ viewController: NCAudioRecorderViewController, fileName: String) {
-
- guard let navigationController = UIStoryboard(name: "NCCreateFormUploadVoiceNote", bundle: nil).instantiateInitialViewController() else { return }
- navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
-
- let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadVoiceNote
- viewController.setup(serverUrl: appDelegate.activeMain.serverUrl, fileNamePath: NSTemporaryDirectory() + fileName, fileName: fileName)
- self.appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
- }
-
- func didFinishWithoutRecording(_ viewController: NCAudioRecorderViewController, fileName: String) {
- }
- }
-
- //MARK: - Main TabBarController
- class CCMainTabBarController : UITabBarController, UITabBarControllerDelegate {
-
- override func viewDidLoad() {
-
- super.viewDidLoad()
- delegate = self
- }
-
- //Delegate methods
- func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
-
- let tabViewControllers = tabBarController.viewControllers!
- guard let toIndex = tabViewControllers.firstIndex(of: viewController) else {
-
- if let vc = viewController as? UINavigationController {
- vc.popToRootViewController(animated: true);
- }
-
- return false
- }
-
- animateToTab(toIndex: toIndex)
-
- return true
- }
-
- func animateToTab(toIndex: Int) {
-
- let tabViewControllers = viewControllers!
- let fromView = selectedViewController!.view!
- let toView = tabViewControllers[toIndex].view!
- let fromIndex = tabViewControllers.firstIndex(of: selectedViewController!)
-
- guard fromIndex != toIndex else {return}
-
- // Add the toView to the tab bar view
- fromView.superview?.addSubview(toView)
- fromView.superview?.backgroundColor = NCBrandColor.sharedInstance.backgroundView
-
- // Position toView off screen (to the left/right of fromView)
- let screenWidth = UIScreen.main.bounds.size.width;
- let scrollRight = toIndex > fromIndex!;
- let offset = (scrollRight ? screenWidth : -screenWidth)
- toView.center = CGPoint(x: (fromView.center.x) + offset, y: (toView.center.y))
-
- // Disable interaction during animation
- view.isUserInteractionEnabled = false
-
- UIView.animate(withDuration: 0.3, delay: 0.0, usingSpringWithDamping: 1, initialSpringVelocity: 0, options: UIView.AnimationOptions.curveEaseOut, animations: {
-
- // Slide the views by -offset
- fromView.center = CGPoint(x: fromView.center.x - offset, y: fromView.center.y);
- toView.center = CGPoint(x: toView.center.x - offset, y: toView.center.y);
-
- }, completion: { finished in
-
- // Remove the old view from the tabbar view.
- fromView.removeFromSuperview()
- self.selectedIndex = toIndex
- self.view.isUserInteractionEnabled = true
- })
- }
- }
- //
- // https://stackoverflow.com/questions/44822558/ios-11-uitabbar-uitabbaritem-positioning-issue/46348796#46348796
- //
- extension UITabBar {
- // Workaround for iOS 11's new UITabBar behavior where on iPad, the UITabBar inside
- // the Master view controller shows the UITabBarItem icon next to the text
- override open var traitCollection: UITraitCollection {
- if UIDevice.current.userInterfaceIdiom == .pad {
- return UITraitCollection(horizontalSizeClass: .compact)
- }
- return super.traitCollection
- }
- }
- //MARK: - Networking Main
- class NCNetworkingMain: NSObject, CCNetworkingDelegate, IMImagemeterViewerDelegate {
- @objc static let sharedInstance: NCNetworkingMain = {
- let instance = NCNetworkingMain()
- return instance
- }()
-
- lazy var operationQueueNetworkingMain: OperationQueue = {
- let queue = OperationQueue()
- queue.name = "com.nextcloud.operationQueueNetworkingMain"
- queue.maxConcurrentOperationCount = 1
- return queue
- }()
-
- let appDelegate = UIApplication.shared.delegate as! AppDelegate
- // DOWNLOAD
- func downloadStart(_ ocId: String!, account: String!, task: URLSessionDownloadTask!, serverUrl: String!) {
- NCMainCommon.sharedInstance.reloadDatasource(ServerUrl: serverUrl, ocId: ocId, action: Int32(k_action_MOD))
- appDelegate.updateApplicationIconBadgeNumber()
- }
-
- func downloadFileSuccessFailure(_ fileName: String!, ocId: String!, serverUrl: String!, selector: String!, errorMessage: String!, errorCode: Int) {
-
- guard let metadata = NCManageDatabase.sharedInstance.getMetadata(predicate: NSPredicate(format: "ocId == %@", ocId)) else {
- return
- }
-
- if metadata.account != appDelegate.activeAccount {
- NCMainCommon.sharedInstance.reloadDatasource(ServerUrl: serverUrl, ocId: ocId, action: Int32(k_action_MOD))
- return
- }
-
- if errorCode == 0 {
-
- NCMainCommon.sharedInstance.reloadDatasource(ServerUrl: serverUrl, ocId: ocId, action: Int32(k_action_MOD))
-
- // Synchronized
- if selector == selectorDownloadSynchronize {
- appDelegate.updateApplicationIconBadgeNumber()
- appDelegate.startLoadAutoDownloadUpload()
- return
- }
-
- // Modify Photo
- if selector == selectorDownloadEditPhoto {
- NCMainCommon.sharedInstance.editPhoto(metadata, viewController: appDelegate.activeMain)
- return
- }
-
- // open View File
- if (selector == selectorLoadFileView || selector == selectorLoadFileViewFavorite || selector == selectorLoadFileInternalView) && UIApplication.shared.applicationState == UIApplication.State.active {
-
- var uti = CCUtility.insertTypeFileIconName(metadata.fileNameView, metadata: metadata)
- if uti == nil {
- uti = ""
- } else if uti!.contains("opendocument") && !NCUtility.sharedInstance.isRichDocument(metadata) {
- metadata.typeFile = k_metadataTypeFile_unknown
- }
-
- #if HC
- if metadata.typeFile == k_metadataTypeFile_imagemeter {
-
- if !IMUtility.shared.IMUnzip(metadata: metadata) {
- NCContentPresenter.shared.messageNotification("_error_", description: "Bundle imagemeter error. 🤷♂️", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: 0)
- return
- }
-
- let storyboard = UIStoryboard(name: "IMImagemeter", bundle: nil)
- let imagemeterViewer = storyboard.instantiateInitialViewController() as! IMImagemeterViewer
- imagemeterViewer.metadata = metadata
- imagemeterViewer.modalPresentationStyle = UIModalPresentationStyle.fullScreen
- imagemeterViewer.imagemeterViewerDelegate = self
-
- self.appDelegate.window.rootViewController?.present(imagemeterViewer, animated: true, completion: nil)
-
- return
- }
- #endif
-
- if metadata.typeFile == k_metadataTypeFile_compress || metadata.typeFile == k_metadataTypeFile_unknown {
- NCMainCommon.sharedInstance.openIn(metadata: metadata, selector: selector)
-
- } else {
-
- if appDelegate.activeMain.view.window != nil {
- appDelegate.activeMain.shouldPerformSegue(metadata, selector: selector)
- }
- if appDelegate.activeFavorites.view.window != nil {
- appDelegate.activeFavorites.shouldPerformSegue(metadata, selector: selector)
- }
- }
- }
-
- // Open in...
- if (selector == selectorOpenIn || selector == selectorOpenInDetail) && UIApplication.shared.applicationState == UIApplication.State.active {
- NCMainCommon.sharedInstance.openIn(metadata: metadata, selector: selector)
- }
-
- // Save to Photo Album
- if selector == selectorSave {
-
- appDelegate.activeMain.save(toPhotoAlbum: metadata)
- }
-
- // Copy File
- if selector == selectorLoadCopy {
-
- appDelegate.activeMain.copyFile(toPasteboard: metadata)
- }
-
- // Set as available offline
- if selector == selectorLoadOffline {
-
- NCManageDatabase.sharedInstance.setLocalFile(ocId: metadata.ocId, offline: true)
- }
-
- appDelegate.startLoadAutoDownloadUpload()
-
- } else {
-
- // File do not exists on server, remove in local
- if (errorCode == kOCErrorServerPathNotFound || errorCode == -1011) { // - 1011 = kCFURLErrorBadServerResponse
-
- do {
- try FileManager.default.removeItem(atPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId))
- } catch { }
-
- NCManageDatabase.sharedInstance.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
- NCManageDatabase.sharedInstance.deleteLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
-
- NCMainCommon.sharedInstance.reloadDatasource(ServerUrl: serverUrl, ocId: ocId, action: Int32(k_action_DEL))
- }
- }
-
- appDelegate.startLoadAutoDownloadUpload()
- }
-
- #if HC
- // IMImagemeterViewerDelegate
- func closeImagemeterViewer(metadata: tableMetadata?, bundleDirectory: String) {
- guard let metadata = metadata else { return }
-
- let ocIdTemp = NSUUID().uuidString.lowercased()
- let fileNameLocalPath = CCUtility.getDirectoryProviderStorageOcId(ocIdTemp, fileNameView: metadata.fileName)!
- let bundleDirectoryURL = URL(fileURLWithPath: bundleDirectory)
- let fileNameZipUrl = URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(ocIdTemp, fileNameView: metadata.fileName))
-
- // Create IMI
- try? FileManager.default.removeItem(at: fileNameZipUrl)
- do {
- try FileManager().zipItem(at: bundleDirectoryURL, to:fileNameZipUrl)
- } catch {
- NCContentPresenter.shared.messageNotification("_error_", description: "Creation of IMI archive failed with error", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: Int(k_CCErrorInternalError))
- return
- }
-
- // Verify if is changed
- if IMUtility.shared.IMIsChange(metadata: metadata, fileNameZipUrl: fileNameZipUrl) {
- let com = IMCommunication.init()
- _ = com.uploadFileIMI(serverUrl: metadata.serverUrl, fileName: metadata.fileName, fileNameLocalPath: fileNameLocalPath, ocId: ocIdTemp)
- }
-
- // Remove bundle directory
- try? FileManager.default.removeItem(atPath: bundleDirectory)
- }
- #endif
-
- // UPLOAD
-
- func uploadStart(_ ocId: String!, account: String!, task: URLSessionUploadTask!, serverUrl: String!) {
- NCMainCommon.sharedInstance.reloadDatasource(ServerUrl: serverUrl, ocId: ocId, action: Int32(k_action_MOD))
- appDelegate.updateApplicationIconBadgeNumber()
- }
-
- func uploadFileSuccessFailure(_ fileName: String!, ocId: String!, assetLocalIdentifier: String!, serverUrl: String!, selector: String!, errorMessage: String!, errorCode: Int) {
-
- guard let metadata = NCManageDatabase.sharedInstance.getMetadata(predicate: NSPredicate(format: "ocId == %@", ocId)) else {
- return
- }
-
- if metadata.account != appDelegate.activeAccount {
- NCMainCommon.sharedInstance.reloadDatasource(ServerUrl: serverUrl, ocId: ocId, action: Int32(k_action_MOD))
- return
- }
-
- NCMainCommon.sharedInstance.reloadDatasource(ServerUrl: serverUrl, ocId: ocId, action: Int32(k_action_MOD))
-
- if errorCode == 0 {
- appDelegate.startLoadAutoDownloadUpload()
- } else {
- if errorCode != -999 && errorCode != kOCErrorServerUnauthorized && errorMessage != "" {
- NCContentPresenter.shared.messageNotification("_upload_file_", description: errorMessage, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: errorCode)
- }
- }
- }
-
- @objc func downloadThumbnail(with metadata: tableMetadata, view: Any, indexPath: IndexPath) {
- operationQueueNetworkingMain.addOperation(NCOperationNetworkingMain.init(metadata: metadata, view: view, indexPath: indexPath, networkingFunc: "downloadThumbnail"))
- }
-
- func downloadThumbnail(with metadata: tableMetadata, view: Any, indexPath: IndexPath, closure: @escaping () -> ()) {
-
- if !metadata.isInvalidated && metadata.hasPreview && (!CCUtility.fileProviderStorageIconExists(metadata.ocId, fileNameView: metadata.fileName) || metadata.typeFile == k_metadataTypeFile_document) {
-
- let width = NCUtility.sharedInstance.getScreenWidthForPreview()
- let height = NCUtility.sharedInstance.getScreenHeightForPreview()
-
- OCNetworking.sharedManager().downloadPreview(withAccount: metadata.account, metadata: metadata, withWidth: width, andHeight: height, completion: { (account, image, message, errorCode) in
-
- if errorCode == 0 && account == self.appDelegate.activeAccount && !metadata.isInvalidated && CCUtility.fileProviderStorageIconExists(metadata.ocId, fileNameView: metadata.fileName) {
-
- if view is UICollectionView && NCMainCommon.sharedInstance.isValidIndexPath(indexPath, view: view) {
- if let cell = (view as! UICollectionView).cellForItem(at: indexPath) {
- if cell is NCListCell {
- (cell as! NCListCell).imageItem.image = image
- } else if cell is NCGridCell {
- (cell as! NCGridCell).imageItem.image = image
- } else if cell is NCGridMediaCell {
- (cell as! NCGridMediaCell).imageItem.image = image
- }
- }
- }
-
- if view is UITableView && CCUtility.fileProviderStorageIconExists(metadata.ocId, fileNameView: metadata.fileName) && NCMainCommon.sharedInstance.isValidIndexPath(indexPath, view: view) {
- if let cell = (view as! UITableView).cellForRow(at: indexPath) {
- if cell is CCCellMainTransfer {
- (cell as! CCCellMainTransfer).file.image = image
- } else if cell is CCCellMain {
- (cell as! CCCellMain).file.image = image
- }
- }
- }
- }
-
- return closure()
- })
- }
-
- return closure()
- }
- }
- //MARK: - Operation Networking Main
- class NCOperationNetworkingMain: Operation {
-
- private var _executing : Bool = false
- override var isExecuting : Bool {
- get { return _executing }
- set {
- guard _executing != newValue else { return }
- willChangeValue(forKey: "isExecuting")
- _executing = newValue
- didChangeValue(forKey: "isExecuting")
- }
- }
- private var _finished : Bool = false
- override var isFinished : Bool {
- get { return _finished }
- set {
- guard _finished != newValue else { return }
- willChangeValue(forKey: "isFinished")
- _finished = newValue
- didChangeValue(forKey: "isFinished")
- }
- }
-
- private var metadata: tableMetadata?
- private var view: Any?
- private var indexPath: IndexPath?
- private var networkingFunc: String = ""
- init(metadata: tableMetadata?, view: Any?, indexPath: IndexPath?, networkingFunc: String) {
- super.init()
-
- if metadata != nil { self.metadata = metadata! }
- if view != nil { self.view = view! }
- if indexPath != nil { self.indexPath = indexPath! }
-
- self.networkingFunc = networkingFunc
- }
-
- override func start() {
- if !Thread.isMainThread {
-
- self.performSelector(onMainThread:#selector(start), with: nil, waitUntilDone: false)
-
- } else {
-
- isExecuting = true
-
- if isCancelled {
- finish()
- } else {
- poolNetworking()
- }
- }
- }
-
- func finish() {
- isExecuting = false
- isFinished = true
- }
-
- override func cancel() {
- super.cancel()
-
- if isExecuting {
- complete()
- }
- }
-
- func complete() {
- finish()
-
- UIApplication.shared.isNetworkActivityIndicatorVisible = false
- }
-
- func poolNetworking() {
- UIApplication.shared.isNetworkActivityIndicatorVisible = true
-
- switch networkingFunc {
- case "downloadThumbnail":
- NCNetworkingMain.sharedInstance.downloadThumbnail(with: metadata!, view: view!, indexPath: indexPath!) {
- self.complete()
- }
- default:
- print("error")
- }
- }
- }
- //MARK: - Function Main
- class NCFunctionMain: NSObject {
-
- @objc static let sharedInstance: NCFunctionMain = {
- let instance = NCFunctionMain()
- return instance
- }()
-
- let appDelegate = UIApplication.shared.delegate as! AppDelegate
-
- @objc func synchronizeOffline() {
-
- let directories = NCManageDatabase.sharedInstance.getTablesDirectory(predicate: NSPredicate(format: "account == %@ AND offline == true", appDelegate.activeAccount), sorted: "serverUrl", ascending: true)
- if (directories != nil) {
- for directory: tableDirectory in directories! {
- CCSynchronize.shared()?.readFolder(directory.serverUrl, selector: selectorReadFolderWithDownload, account: appDelegate.activeAccount)
- }
- }
-
- let files = NCManageDatabase.sharedInstance.getTableLocalFiles(predicate: NSPredicate(format: "account == %@ AND offline == true", appDelegate.activeAccount), sorted: "fileName", ascending: true)
- if (files != nil) {
- for file: tableLocalFile in files! {
- guard let metadata = NCManageDatabase.sharedInstance.getMetadata(predicate: NSPredicate(format: "ocId == %@", file.ocId)) else {
- continue
- }
- CCSynchronize.shared()?.readFile(metadata.ocId, fileName: metadata.fileName, serverUrl: metadata.serverUrl, selector: selectorReadFileWithDownload, account: appDelegate.activeAccount)
- }
- }
- }
- }
|