12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745 |
- //
- // NCCollectionViewCommon.swift
- // Nextcloud
- //
- // Created by Marino Faggiana on 12/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 UIKit
- import NCCommunication
- class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UISearchResultsUpdating, UISearchControllerDelegate, UISearchBarDelegate, NCListCellDelegate, NCGridCellDelegate, NCSectionHeaderMenuDelegate, UIAdaptivePresentationControllerDelegate, NCEmptyDataSetDelegate, UIContextMenuInteractionDelegate, NCAccountRequestDelegate, NCBackgroundImageColorDelegate {
-
- @IBOutlet weak var collectionView: UICollectionView!
- let appDelegate = UIApplication.shared.delegate as! AppDelegate
- internal let refreshControl = UIRefreshControl()
- internal var searchController: UISearchController?
- internal var emptyDataSet: NCEmptyDataSet?
- internal var backgroundImageView = UIImageView()
- internal var serverUrl: String = ""
- internal var isEncryptedFolder = false
- internal var isEditMode = false
- internal var selectOcId: [String] = []
- internal var metadatasSource: [tableMetadata] = []
- internal var metadataFolder: tableMetadata?
- internal var metadataTouch: tableMetadata?
- internal var dataSource = NCDataSource()
- internal var richWorkspaceText: String?
- internal var header: UIView?
-
- internal var layoutForView: NCGlobal.layoutForViewType?
- private var autoUploadFileName = ""
- private var autoUploadDirectory = ""
-
- internal var listLayout: NCListLayout!
- internal var gridLayout: NCGridLayout!
-
- private let headerHeight: CGFloat = 50
- private var headerRichWorkspaceHeight: CGFloat = 0
- private let footerHeight: CGFloat = 100
-
- private var timerInputSearch: Timer?
- internal var literalSearch: String?
- internal var isSearching: Bool = false
-
- internal var isReloadDataSourceNetworkInProgress: Bool = false
-
- var selectedIndexPath: IndexPath!
- private var pushed: Bool = false
-
- // DECLARE
- internal var layoutKey = ""
- internal var titleCurrentFolder = ""
- internal var enableSearchBar: Bool = false
- internal var emptyImage: UIImage?
- internal var emptyTitle: String = ""
- internal var emptyDescription: String = ""
-
- // MARK: - View Life Cycle
- required init?(coder aDecoder: NSCoder) {
- super.init(coder: aDecoder)
- }
-
- override func viewDidLoad() {
- super.viewDidLoad()
-
- self.navigationController?.presentationController?.delegate = self
-
- collectionView.alwaysBounceVertical = true
- if enableSearchBar {
- searchController = UISearchController(searchResultsController: nil)
- searchController?.searchResultsUpdater = self
- searchController?.obscuresBackgroundDuringPresentation = false
- searchController?.delegate = self
- searchController?.searchBar.delegate = self
- navigationItem.searchController = searchController
- navigationItem.hidesSearchBarWhenScrolling = false
- }
-
- // Cell
- collectionView.register(UINib.init(nibName: "NCListCell", bundle: nil), forCellWithReuseIdentifier: "listCell")
- collectionView.register(UINib.init(nibName: "NCGridCell", bundle: nil), forCellWithReuseIdentifier: "gridCell")
- collectionView.register(UINib.init(nibName: "NCTransferCell", bundle: nil), forCellWithReuseIdentifier: "transferCell")
- // Header
- collectionView.register(UINib.init(nibName: "NCSectionHeaderMenu", bundle: nil), forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "sectionHeaderMenu")
-
- // Footer
- collectionView.register(UINib.init(nibName: "NCSectionFooter", bundle: nil), forSupplementaryViewOfKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: "sectionFooter")
-
- listLayout = NCListLayout()
- gridLayout = NCGridLayout()
-
- // Refresh Control
- collectionView.addSubview(refreshControl)
- refreshControl.addTarget(self, action: #selector(reloadDataSourceNetworkRefreshControl), for: .valueChanged)
-
- // Empty
- emptyDataSet = NCEmptyDataSet.init(view: collectionView, offset: headerHeight, delegate: self)
-
- // Long Press on CollectionView
- let longPressedGesture = UILongPressGestureRecognizer(target: self, action: #selector(longPressCollecationView(_:)))
- longPressedGesture.minimumPressDuration = 0.5
- longPressedGesture.delegate = self
- longPressedGesture.delaysTouchesBegan = true
- collectionView.addGestureRecognizer(longPressedGesture)
-
- // Notification
-
- NotificationCenter.default.addObserver(self, selector: #selector(initialize), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterInitialize), object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(changeTheming), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterChangeTheming), object: nil)
- changeTheming()
- }
-
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- // ACTIVE
- appDelegate.activeViewController = self
- if serverUrl == "" {
- appDelegate.activeServerUrl = NCUtilityFileSystem.shared.getHomeServer(account: appDelegate.account)
- } else {
- appDelegate.activeServerUrl = serverUrl
- }
-
- navigationController?.navigationBar.prefersLargeTitles = true
- navigationController?.setNavigationBarHidden(false, animated: true)
- setNavigationItem()
-
- changeTheming()
- reloadDataSource()
- }
-
- override func viewDidAppear(_ animated: Bool) {
- super.viewDidAppear(animated)
-
- NotificationCenter.default.addObserver(self, selector: #selector(closeRichWorkspaceWebView), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterCloseRichWorkspaceWebView), object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(changeStatusFolderE2EE(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterChangeStatusFolderE2EE), object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(reloadDataSource(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterReloadDataSource), object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(reloadDataSourceNetworkForced(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterReloadDataSourceNetworkForced), object: nil)
-
- NotificationCenter.default.addObserver(self, selector: #selector(deleteFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterDeleteFile), object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(moveFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMoveFile), object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(copyFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterCopyFile), object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(renameFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterRenameFile), object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(createFolder(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterCreateFolder), object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(favoriteFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterFavoriteFile), object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(downloadStartFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterDownloadStartFile), object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(downloadedFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterDownloadedFile), object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(downloadCancelFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterDownloadCancelFile), object: nil)
-
- NotificationCenter.default.addObserver(self, selector: #selector(uploadStartFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterUploadStartFile), object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(uploadedFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterUploadedFile), object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(uploadCancelFile(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterUploadCancelFile), object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(triggerProgressTask(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterProgressTask), object:nil)
- reloadDataSourceNetwork()
- }
-
- override func viewDidDisappear(_ animated: Bool) {
- super.viewDidDisappear(animated)
-
- NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterCloseRichWorkspaceWebView), object: nil)
- NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterChangeStatusFolderE2EE), object: nil)
-
- NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterReloadDataSource), object: nil)
- NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterReloadDataSourceNetworkForced), object: nil)
-
- NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterDeleteFile), object: nil)
- NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMoveFile), object: nil)
- NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterCopyFile), object: nil)
- NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterRenameFile), object: nil)
- NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterCreateFolder), object: nil)
- NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterFavoriteFile), object: nil)
- NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterDownloadStartFile), object: nil)
- NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterDownloadedFile), object: nil)
- NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterDownloadCancelFile), object: nil)
- NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterUploadStartFile), object: nil)
- NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterUploadedFile), object: nil)
- NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterUploadCancelFile), object: nil)
- NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterProgressTask), object: nil)
- pushed = false
- }
-
- func presentationControllerDidDismiss( _ presentationController: UIPresentationController) {
- let viewController = presentationController.presentedViewController
- if viewController is NCViewerRichWorkspaceWebView {
- closeRichWorkspaceWebView()
- } else if viewController is UINavigationController {
- if (viewController as! UINavigationController).topViewController is NCFileViewInFolder {
- appDelegate.activeFileViewInFolder = nil
- }
- }
- }
-
- override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
- super.viewWillTransition(to: size, with: coordinator)
-
- coordinator.animate(alongsideTransition: nil) { _ in
- self.collectionView?.collectionViewLayout.invalidateLayout()
- }
- }
-
- override var canBecomeFirstResponder: Bool {
- return true
- }
-
- override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
- super.traitCollectionDidChange(previousTraitCollection)
-
- changeTheming()
- }
-
- // MARK: - NotificationCenter
- @objc func initialize() {
-
- if appDelegate.account == "" { return }
-
- // Search
- if searchController?.isActive ?? false {
- searchController?.isActive = false
- }
-
- // Select
- if isEditMode {
- isEditMode = !isEditMode
- selectOcId.removeAll()
- }
-
- if self.view?.window != nil {
- if serverUrl == "" {
- appDelegate.activeServerUrl = NCUtilityFileSystem.shared.getHomeServer(account: appDelegate.account)
- } else {
- appDelegate.activeServerUrl = serverUrl
- }
-
- appDelegate.listFilesVC.removeAll()
- appDelegate.listFavoriteVC.removeAll()
- appDelegate.listOfflineVC.removeAll()
- }
-
- if serverUrl != "" {
- self.navigationController?.popToRootViewController(animated: false)
- }
-
- setNavigationItem()
- reloadDataSource()
- changeTheming()
- }
-
- @objc func changeTheming() {
-
- view.backgroundColor = NCBrandColor.shared.systemBackground
- collectionView.backgroundColor = NCBrandColor.shared.systemBackground
- refreshControl.tintColor = .gray
-
- layoutForView = NCUtility.shared.getLayoutForView(key: layoutKey, serverUrl: serverUrl)
- gridLayout.itemForLine = CGFloat(layoutForView?.itemForLine ?? 3)
-
- if layoutForView?.layout == NCGlobal.shared.layoutList {
- collectionView?.collectionViewLayout = listLayout
- } else {
- collectionView?.collectionViewLayout = gridLayout
- }
-
- // IMAGE BACKGROUND
- if layoutForView?.imageBackgroud != "" {
- let imagePath = CCUtility.getDirectoryGroup().appendingPathComponent(NCGlobal.shared.appBackground).path + "/" + layoutForView!.imageBackgroud
- do {
- let data = try Data.init(contentsOf: URL(fileURLWithPath: imagePath))
- if let image = UIImage.init(data: data) {
- backgroundImageView.image = image
- backgroundImageView.contentMode = .scaleToFill
- collectionView.backgroundView = backgroundImageView
- }
- } catch { }
- } else {
- backgroundImageView.image = nil
- collectionView.backgroundView = nil
- }
-
- // COLOR BACKGROUND
- let activeAccount = NCManageDatabase.shared.getActiveAccount()
- if traitCollection.userInterfaceStyle == .dark {
- if activeAccount?.darkColorBackground != "" {
- collectionView.backgroundColor = UIColor.init(hex: activeAccount?.darkColorBackground ?? "")
- } else {
- collectionView.backgroundColor = NCBrandColor.shared.systemBackground
- }
- } else {
- if activeAccount?.lightColorBackground != "" {
- collectionView.backgroundColor = UIColor.init(hex: activeAccount?.lightColorBackground ?? "")
- } else {
- collectionView.backgroundColor = NCBrandColor.shared.systemBackground
- }
- }
-
- collectionView.reloadData()
- }
-
- @objc func reloadDataSource(_ notification: NSNotification) {
-
- reloadDataSource()
- }
-
- @objc func reloadDataSourceNetworkForced(_ notification: NSNotification) {
-
- if let userInfo = notification.userInfo as NSDictionary? {
- if let serverUrl = userInfo["serverUrl"] as? String {
- if serverUrl == self.serverUrl {
- reloadDataSourceNetwork(forced: true)
- }
- }
- } else {
- reloadDataSourceNetwork(forced: true)
- }
- }
-
- @objc func changeStatusFolderE2EE(_ notification: NSNotification) {
-
- reloadDataSource()
- }
-
- @objc func closeRichWorkspaceWebView() {
-
- reloadDataSourceNetwork()
- }
-
- @objc func deleteFile(_ notification: NSNotification) {
-
- if let userInfo = notification.userInfo as NSDictionary? {
- if let ocId = userInfo["ocId"] as? String, let fileNameView = userInfo["fileNameView"] as? String, let onlyLocal = userInfo["onlyLocal"] as? Bool {
- if onlyLocal {
- reloadDataSource()
- } else if fileNameView.lowercased() == NCGlobal.shared.fileNameRichWorkspace.lowercased() {
- reloadDataSourceNetwork(forced: true)
- } else {
- if let row = dataSource.deleteMetadata(ocId: ocId) {
- let indexPath = IndexPath(row: row, section: 0)
- collectionView?.performBatchUpdates({
- collectionView?.deleteItems(at: [indexPath])
- }, completion: { (_) in
- self.collectionView?.reloadData()
- })
- }
- }
- }
- }
- }
-
- @objc func moveFile(_ notification: NSNotification) {
-
- if let userInfo = notification.userInfo as NSDictionary? {
- if let ocId = userInfo["ocId"] as? String, let serverUrlFrom = userInfo["serverUrlFrom"] as? String, let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
-
- // DEL
- if serverUrlFrom == serverUrl && metadata.account == appDelegate.account {
- if let row = dataSource.deleteMetadata(ocId: ocId) {
- let indexPath = IndexPath(row: row, section: 0)
- collectionView?.performBatchUpdates({
- collectionView?.deleteItems(at: [indexPath])
- }, completion: { (_) in
- self.collectionView?.reloadData()
- })
- }
- // ADD
- } else if metadata.serverUrl == serverUrl && metadata.account == appDelegate.account {
- if let row = dataSource.addMetadata(metadata) {
- let indexPath = IndexPath(row: row, section: 0)
- collectionView?.performBatchUpdates({
- collectionView?.insertItems(at: [indexPath])
- }, completion: { (_) in
- self.collectionView?.reloadData()
- })
- }
- }
- }
- }
- }
-
- @objc func copyFile(_ notification: NSNotification) {
-
- if let userInfo = notification.userInfo as NSDictionary? {
- if let serverUrlTo = userInfo["serverUrlTo"] as? String {
-
- if serverUrlTo == self.serverUrl {
- reloadDataSource()
- }
- }
- }
- }
-
- @objc func renameFile(_ notification: NSNotification) {
-
- reloadDataSource()
- }
-
- @objc func createFolder(_ notification: NSNotification) {
-
- if let userInfo = notification.userInfo as NSDictionary? {
- if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
-
- if metadata.serverUrl == serverUrl && metadata.account == appDelegate.account {
- if let row = dataSource.addMetadata(metadata) {
- let indexPath = IndexPath(row: row, section: 0)
- collectionView?.performBatchUpdates({
- collectionView?.insertItems(at: [indexPath])
- }, completion: { (_) in
- self.collectionView?.reloadData()
- })
- }
- }
- }
- } else {
- reloadDataSourceNetwork()
- }
- }
-
- @objc func favoriteFile(_ notification: NSNotification) {
-
- if let userInfo = notification.userInfo as NSDictionary? {
- if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
-
- if dataSource.getIndexMetadata(ocId: metadata.ocId) != nil {
- reloadDataSource()
- }
- }
- }
- }
-
- @objc func downloadStartFile(_ notification: NSNotification) {
-
- if let userInfo = notification.userInfo as NSDictionary? {
- if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
- if let row = dataSource.reloadMetadata(ocId: metadata.ocId) {
- let indexPath = IndexPath(row: row, section: 0)
- if indexPath.section < collectionView.numberOfSections && indexPath.row < collectionView.numberOfItems(inSection: indexPath.section) {
- collectionView?.reloadItems(at: [indexPath])
- }
- }
- }
- }
- }
-
- @objc func downloadedFile(_ notification: NSNotification) {
-
- if let userInfo = notification.userInfo as NSDictionary? {
- if let ocId = userInfo["ocId"] as? String, let _ = userInfo["errorCode"] as? Int, let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
- if let row = dataSource.reloadMetadata(ocId: metadata.ocId) {
- let indexPath = IndexPath(row: row, section: 0)
- if indexPath.section < collectionView.numberOfSections && indexPath.row < collectionView.numberOfItems(inSection: indexPath.section) {
- collectionView?.reloadItems(at: [indexPath])
- }
- }
- }
- }
- }
-
- @objc func downloadCancelFile(_ notification: NSNotification) {
-
- if let userInfo = notification.userInfo as NSDictionary? {
- if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
- if let row = dataSource.reloadMetadata(ocId: metadata.ocId) {
- let indexPath = IndexPath(row: row, section: 0)
- if indexPath.section < collectionView.numberOfSections && indexPath.row < collectionView.numberOfItems(inSection: indexPath.section) {
- collectionView?.reloadItems(at: [indexPath])
- }
- }
- }
- }
- }
-
- @objc func uploadStartFile(_ notification: NSNotification) {
-
- if let userInfo = notification.userInfo as NSDictionary? {
- if let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
- if metadata.serverUrl == serverUrl && metadata.account == appDelegate.account {
- dataSource.addMetadata(metadata)
- self.collectionView?.reloadData()
- }
- }
- }
- }
-
- @objc func uploadedFile(_ notification: NSNotification) {
-
- if let userInfo = notification.userInfo as NSDictionary? {
- if let ocId = userInfo["ocId"] as? String, let ocIdTemp = userInfo["ocIdTemp"] as? String, let _ = userInfo["errorCode"] as? Int, let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) {
- if metadata.serverUrl == serverUrl && metadata.account == appDelegate.account {
- dataSource.reloadMetadata(ocId: metadata.ocId, ocIdTemp: ocIdTemp)
- collectionView?.reloadData()
- }
- }
- }
- }
-
- @objc func uploadCancelFile(_ notification: NSNotification) {
-
- if let userInfo = notification.userInfo as NSDictionary? {
- if let ocId = userInfo["ocId"] as? String, let serverUrl = userInfo["serverUrl"] as? String, let account = userInfo["account"] as? String {
-
- if serverUrl == self.serverUrl && account == appDelegate.account {
- if let row = dataSource.deleteMetadata(ocId: ocId) {
- let indexPath = IndexPath(row: row, section: 0)
- collectionView?.performBatchUpdates({
- if indexPath.section < (collectionView?.numberOfSections ?? 0) && indexPath.row < (collectionView?.numberOfItems(inSection: indexPath.section) ?? 0) {
- collectionView?.deleteItems(at: [indexPath])
- }
- }, completion: { (_) in
- self.collectionView?.reloadData()
- })
- } else {
- self.reloadDataSource()
- }
- }
- }
- }
- }
-
- @objc func triggerProgressTask(_ notification: NSNotification) {
-
- if let userInfo = notification.userInfo as NSDictionary?, let progressNumber = userInfo["progress"] as? NSNumber, let totalBytes = userInfo["totalBytes"] as? Int64, let totalBytesExpected = userInfo["totalBytesExpected"] as? Int64 {
- if let ocId = userInfo["ocId"] as? String {
-
- let progress = progressNumber.floatValue
- let status = userInfo["status"] as? Int ?? NCGlobal.shared.metadataStatusNormal
-
- let progressType = NCGlobal.progressType(progress: progress, totalBytes: totalBytes, totalBytesExpected: totalBytesExpected)
- appDelegate.listProgress[ocId] = progressType
-
- if let index = dataSource.getIndexMetadata(ocId: ocId) {
- if let cell = collectionView?.cellForItem(at: IndexPath(row: index, section: 0)) {
- if cell is NCListCell {
- let cell = cell as! NCListCell
- if progress > 0 {
- cell.progressView?.isHidden = false
- cell.progressView?.progress = progress
- cell.setButtonMore(named: NCGlobal.shared.buttonMoreStop, image: NCBrandColor.cacheImages.buttonStop)
- if status == NCGlobal.shared.metadataStatusInDownload {
- cell.labelInfo.text = CCUtility.transformedSize(totalBytesExpected) + " - ↓ " + CCUtility.transformedSize(totalBytes)
- } else if status == NCGlobal.shared.metadataStatusInUpload {
- cell.labelInfo.text = CCUtility.transformedSize(totalBytesExpected) + " - ↑ " + CCUtility.transformedSize(totalBytes)
- }
- }
- } else if cell is NCTransferCell {
- let cell = cell as! NCTransferCell
- if progress > 0 {
- cell.progressView?.isHidden = false
- cell.progressView?.progress = progress
- cell.setButtonMore(named: NCGlobal.shared.buttonMoreStop, image: NCBrandColor.cacheImages.buttonStop)
- if status == NCGlobal.shared.metadataStatusInDownload {
- cell.labelInfo.text = CCUtility.transformedSize(totalBytesExpected) + " - ↓ " + CCUtility.transformedSize(totalBytes)
- } else if status == NCGlobal.shared.metadataStatusInUpload {
- cell.labelInfo.text = CCUtility.transformedSize(totalBytesExpected) + " - ↑ " + CCUtility.transformedSize(totalBytes)
- }
- }
- } else if cell is NCGridCell {
- let cell = cell as! NCGridCell
- if progress > 0 {
- cell.progressView.isHidden = false
- cell.progressView.progress = progress
- cell.setButtonMore(named: NCGlobal.shared.buttonMoreStop, image: NCBrandColor.cacheImages.buttonStop)
- }
- }
- }
- }
- }
- }
- }
- // MARK: - Layout
-
- func setNavigationItem() {
-
- if isEditMode {
-
- navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage.init(named: "navigationMore"), style: .plain, target: self, action:#selector(tapSelectMenu(sender:)))
- navigationItem.leftBarButtonItem = UIBarButtonItem(title: NSLocalizedString("_cancel_", comment: ""), style: .plain, target: self, action: #selector(tapSelect(sender:)))
- navigationItem.title = NSLocalizedString("_selected_", comment: "") + " : \(selectOcId.count)" + " / \(dataSource.metadatas.count)"
-
- } else {
-
- navigationItem.rightBarButtonItem = UIBarButtonItem(title: NSLocalizedString("_select_", comment: ""), style: UIBarButtonItem.Style.plain, target: self, action: #selector(tapSelect(sender:)))
- navigationItem.leftBarButtonItem = nil
- navigationItem.title = titleCurrentFolder
-
- // PROFILE BUTTON
-
- if layoutKey == NCGlobal.shared.layoutViewFiles {
-
- var image = NCUtility.shared.loadImage(named: "person.crop.circle")
- let fileNamePath = String(CCUtility.getDirectoryUserData()) + "/" + String(CCUtility.getStringUser(appDelegate.user, urlBase: appDelegate.urlBase)) + "-" + appDelegate.user + ".png"
- if let userImage = UIImage(contentsOfFile: fileNamePath) {
- image = userImage
- }
-
- image = NCUtility.shared.createAvatar(image: image, size: 30)
-
- let button = UIButton(type: .custom)
- button.setImage(image, for: .normal)
-
- if serverUrl == NCUtilityFileSystem.shared.getHomeServer(account: appDelegate.account) {
-
- let activeAccount = NCManageDatabase.shared.getActiveAccount()
- var titleButton = " "
-
- if activeAccount?.alias == "" {
- titleButton = titleButton + (activeAccount?.user ?? "")
- } else {
- titleButton = titleButton + (activeAccount?.alias ?? "")
- }
-
- if getNavigationTitle() == activeAccount?.alias {
- titleButton = ""
- }
-
- button.setTitle(titleButton, for: .normal)
- button.setTitleColor(.systemBlue, for: .normal)
- }
-
- button.semanticContentAttribute = .forceLeftToRight
- button.sizeToFit()
- button.addTarget(self, action: #selector(profileButtonTapped(sender:)), for: .touchUpInside)
-
- navigationItem.setLeftBarButton(UIBarButtonItem(customView: button), animated: true)
- navigationItem.leftItemsSupplementBackButton = true
- }
- }
- }
-
- func getNavigationTitle() -> String {
-
- let activeAccount = NCManageDatabase.shared.getActiveAccount()
- if activeAccount?.alias == "" {
- return NCBrandOptions.shared.brand
- } else {
- return activeAccount?.alias ?? NCBrandOptions.shared.brand
- }
- }
-
- // MARK: - BackgroundImageColor Delegate
-
- func colorPickerCancel() {
- changeTheming()
- }
-
- func colorPickerWillChange(color: UIColor) {
- collectionView.backgroundColor = color
- }
-
- func colorPickerDidChange(lightColor: String, darkColor: String) {
- NCManageDatabase.shared.setAccountColorFiles(lightColorBackground: lightColor, darkColorBackground: darkColor)
-
- changeTheming()
- }
-
- // MARK: - Empty
-
- func emptyDataSetView(_ view: NCEmptyView) {
-
- if searchController?.isActive ?? false {
- view.emptyImage.image = UIImage.init(named: "search")?.image(color: .gray, size: UIScreen.main.bounds.width)
- if isReloadDataSourceNetworkInProgress {
- view.emptyTitle.text = NSLocalizedString("_search_in_progress_", comment: "")
- } else {
- view.emptyTitle.text = NSLocalizedString("_search_no_record_found_", comment: "")
- }
- view.emptyDescription.text = NSLocalizedString("_search_instruction_", comment: "")
- } else if isReloadDataSourceNetworkInProgress {
- view.emptyImage.image = UIImage.init(named: "networkInProgress")?.image(color: .gray, size: UIScreen.main.bounds.width)
- view.emptyTitle.text = NSLocalizedString("_request_in_progress_", comment: "")
- view.emptyDescription.text = ""
- } else {
- if serverUrl == "" {
- view.emptyImage.image = emptyImage
- view.emptyTitle.text = NSLocalizedString(emptyTitle, comment: "")
- view.emptyDescription.text = NSLocalizedString(emptyDescription, comment: "")
- } else {
- view.emptyImage.image = UIImage.init(named: "folder")?.image(color: NCBrandColor.shared.brandElement, size: UIScreen.main.bounds.width)
- view.emptyTitle.text = NSLocalizedString("_files_no_files_", comment: "")
- view.emptyDescription.text = NSLocalizedString("_no_file_pull_down_", comment: "")
- }
- }
- }
-
- // MARK: - SEARCH
-
- func updateSearchResults(for searchController: UISearchController) {
- timerInputSearch?.invalidate()
- timerInputSearch = Timer.scheduledTimer(timeInterval: 1.5, target: self, selector: #selector(reloadDataSourceNetwork), userInfo: nil, repeats: false)
- literalSearch = searchController.searchBar.text
- collectionView?.reloadData()
- }
-
- func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) {
-
- isSearching = true
- metadatasSource.removeAll()
- reloadDataSource()
- }
-
- func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
-
- isSearching = false
- literalSearch = ""
- reloadDataSource()
- }
-
- // MARK: - TAP EVENT
-
- @objc func tapSelect(sender: Any) {
-
- isEditMode = !isEditMode
-
- selectOcId.removeAll()
- setNavigationItem()
-
- self.collectionView.reloadData()
- }
-
- func accountRequestChangeAccount(account: String) {
- NCManageDatabase.shared.setAccountActive(account)
- if let activeAccount = NCManageDatabase.shared.getActiveAccount() {
-
- NCOperationQueue.shared.cancelAllQueue()
- NCNetworking.shared.cancelAllTask()
-
- appDelegate.settingAccount(activeAccount.account, urlBase: activeAccount.urlBase, user: activeAccount.user, userId: activeAccount.userId, password: CCUtility.getPassword(activeAccount.account))
-
- NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterInitialize)
- }
- }
-
- func accountRequestAddAccount() {
- appDelegate.openLogin(viewController: self, selector: NCGlobal.shared.introLogin, openLoginWeb: false)
- }
-
- @objc func profileButtonTapped(sender: Any) {
-
- let accounts = NCManageDatabase.shared.getAllAccountOrderAlias()
- if accounts.count > 0 {
-
- if let vcAccountRequest = UIStoryboard(name: "NCAccountRequest", bundle: nil).instantiateInitialViewController() as? NCAccountRequest {
-
- vcAccountRequest.activeAccount = NCManageDatabase.shared.getActiveAccount()
- vcAccountRequest.accounts = accounts
- vcAccountRequest.enableTimerProgress = false
- vcAccountRequest.enableAddAccount = true
- vcAccountRequest.delegate = self
- vcAccountRequest.dismissDidEnterBackground = true
- let screenHeighMax = UIScreen.main.bounds.height - (UIScreen.main.bounds.height/5)
- let numberCell = accounts.count + 1
- let height = min(CGFloat(numberCell * Int(vcAccountRequest.heightCell) + 45), screenHeighMax)
-
- let popup = NCPopupViewController(contentController: vcAccountRequest, popupWidth: 300, popupHeight: height)
-
- UIApplication.shared.keyWindow?.rootViewController?.present(popup, animated: true)
- }
- }
- }
-
- func tapSwitchHeader(sender: Any) {
-
- if collectionView.collectionViewLayout == gridLayout {
- // list layout
- UIView.animate(withDuration: 0.0, animations: {
- self.collectionView.collectionViewLayout.invalidateLayout()
- self.collectionView.setCollectionViewLayout(self.listLayout, animated: false, completion: { (_) in
- self.collectionView.reloadData()
- })
- })
- layoutForView?.layout = NCGlobal.shared.layoutList
- NCUtility.shared.setLayoutForView(key: layoutKey, serverUrl: serverUrl, layout: layoutForView?.layout)
- } else {
- // grid layout
- UIView.animate(withDuration: 0.0, animations: {
- self.collectionView.collectionViewLayout.invalidateLayout()
- self.collectionView.setCollectionViewLayout(self.gridLayout, animated: false, completion: { (_) in
- self.collectionView.reloadData()
- })
- })
- layoutForView?.layout = NCGlobal.shared.layoutGrid
- NCUtility.shared.setLayoutForView(key: layoutKey, serverUrl: serverUrl, layout: layoutForView?.layout)
- }
- }
-
- func tapOrderHeader(sender: Any) {
-
- let sortMenu = NCSortMenu()
- sortMenu.toggleMenu(viewController: self, key: layoutKey, sortButton: sender as? UIButton, serverUrl: serverUrl)
- }
-
- @objc func tapSelectMenu(sender: Any) {
-
- toggleMenuSelect()
- }
-
- func tapMoreHeader(sender: Any) { }
-
- func tapMoreListItem(with objectId: String, namedButtonMore: String, image: UIImage?, sender: Any) {
-
- tapMoreGridItem(with: objectId, namedButtonMore: namedButtonMore, image: image, sender: sender)
- }
-
- func tapShareListItem(with objectId: String, sender: Any) {
-
- if isEditMode { return }
- guard let metadata = NCManageDatabase.shared.getMetadataFromOcId(objectId) else { return }
-
- NCFunctionCenter.shared.openShare(ViewController: self, metadata: metadata, indexPage: 2)
- }
-
- func tapMoreGridItem(with objectId: String, namedButtonMore: String, image: UIImage?, sender: Any) {
-
- if isEditMode { return }
- guard let metadata = NCManageDatabase.shared.getMetadataFromOcId(objectId) else { return }
- if namedButtonMore == NCGlobal.shared.buttonMoreMore {
- toggleMenu(metadata: metadata, imageIcon: image)
- } else if namedButtonMore == NCGlobal.shared.buttonMoreStop {
- NCNetworking.shared.cancelTransferMetadata(metadata) { }
- }
- }
-
- func tapRichWorkspace(sender: Any) {
-
- if let navigationController = UIStoryboard(name: "NCViewerRichWorkspace", bundle: nil).instantiateInitialViewController() as? UINavigationController {
- if let viewerRichWorkspace = navigationController.topViewController as? NCViewerRichWorkspace {
- viewerRichWorkspace.richWorkspaceText = richWorkspaceText ?? ""
- viewerRichWorkspace.serverUrl = serverUrl
-
- navigationController.modalPresentationStyle = .fullScreen
- self.present(navigationController, animated: true, completion: nil)
- }
- }
- }
-
- func longPressListItem(with objectId: String, gestureRecognizer: UILongPressGestureRecognizer) {
- }
-
- func longPressGridItem(with objectId: String, gestureRecognizer: UILongPressGestureRecognizer) {
- }
-
- func longPressMoreListItem(with objectId: String, namedButtonMore: String, gestureRecognizer: UILongPressGestureRecognizer) {
- }
-
- func longPressMoreGridItem(with objectId: String, namedButtonMore: String, gestureRecognizer: UILongPressGestureRecognizer) {
- }
-
- @objc func longPressCollecationView(_ gestureRecognizer: UILongPressGestureRecognizer) {
-
- openMenuItems(with: nil, gestureRecognizer: gestureRecognizer)
- /*
- if #available(iOS 13.0, *) {
-
- let interaction = UIContextMenuInteraction(delegate: self)
- self.view.addInteraction(interaction)
- }
- */
- }
-
- @available(iOS 13.0, *)
- func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? {
-
- return UIContextMenuConfiguration(identifier: nil, previewProvider: {
-
- return nil
-
- }, actionProvider: { suggestedActions in
-
- //let share = UIAction(title: "Share Pupper", image: UIImage(systemName: "square.and.arrow.up")) { action in
- //}
- //return UIMenu(title: "Main Menu", children: [share])
- return nil
- })
- }
-
- func openMenuItems(with objectId: String?, gestureRecognizer: UILongPressGestureRecognizer) {
-
- if gestureRecognizer.state != .began { return }
-
- if let metadata = NCManageDatabase.shared.getMetadataFromOcId(objectId) {
- metadataTouch = metadata
- } else {
- metadataTouch = nil
- }
-
- var listMenuItems: [UIMenuItem] = []
- let touchPoint = gestureRecognizer.location(in: collectionView)
-
- becomeFirstResponder()
-
- if serverUrl != "" {
- listMenuItems.append(UIMenuItem.init(title: NSLocalizedString("_paste_file_", comment: ""), action: #selector(pasteFilesMenu)))
- }
- if #available(iOS 13.0, *) {
- if !NCBrandOptions.shared.disable_background_color {
- listMenuItems.append(UIMenuItem.init(title: NSLocalizedString("_background_", comment: ""), action: #selector(backgroundFilesMenu)))
- }
- }
-
- if listMenuItems.count > 0 {
- UIMenuController.shared.menuItems = listMenuItems
- UIMenuController.shared.setTargetRect(CGRect(x: touchPoint.x, y: touchPoint.y, width: 0, height: 0), in: collectionView)
- UIMenuController.shared.setMenuVisible(true, animated: true)
- }
- }
-
- // MARK: - Menu Item
-
- override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
-
- if (#selector(pasteFilesMenu) == action) {
- if UIPasteboard.general.items.count > 0 {
- return true
- }
- }
-
- if (#selector(backgroundFilesMenu) == action) {
- return true
- }
-
- return false
- }
-
- @objc func pasteFilesMenu() {
- NCFunctionCenter.shared.pastePasteboard(serverUrl: serverUrl)
- }
-
- @objc func backgroundFilesMenu() {
-
- if let vcBackgroundImageColor = UIStoryboard(name: "NCBackgroundImageColor", bundle: nil).instantiateInitialViewController() as? NCBackgroundImageColor {
-
- vcBackgroundImageColor.delegate = self
- vcBackgroundImageColor.setupColor = collectionView.backgroundColor
- if let activeAccount = NCManageDatabase.shared.getActiveAccount() {
- vcBackgroundImageColor.lightColor = activeAccount.lightColorBackground
- vcBackgroundImageColor.darkColor = activeAccount.darkColorBackground
- }
-
- let popup = NCPopupViewController(contentController: vcBackgroundImageColor, popupWidth: vcBackgroundImageColor.width, popupHeight: vcBackgroundImageColor.height)
- popup.backgroundAlpha = 0
-
- self.present(popup, animated: true)
- }
- }
-
- // MARK: - DataSource + NC Endpoint
-
- @objc func reloadDataSource() {
-
- if appDelegate.account == "" { return }
-
- // Get richWorkspace Text
- let directory = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.account, serverUrl))
- richWorkspaceText = directory?.richWorkspace
-
- // E2EE
- isEncryptedFolder = CCUtility.isFolderEncrypted(serverUrl, e2eEncrypted: metadataFolder?.e2eEncrypted ?? false, account: appDelegate.account, urlBase: appDelegate.urlBase)
- // get auto upload folder
- autoUploadFileName = NCManageDatabase.shared.getAccountAutoUploadFileName()
- autoUploadDirectory = NCManageDatabase.shared.getAccountAutoUploadDirectory(urlBase: appDelegate.urlBase, account: appDelegate.account)
-
- // get layout for view
- layoutForView = NCUtility.shared.getLayoutForView(key: layoutKey, serverUrl: serverUrl)
- }
-
- @objc func reloadDataSourceNetwork(forced: Bool = false) { }
-
- @objc func reloadDataSourceNetworkRefreshControl() {
- reloadDataSourceNetwork(forced: true)
- }
-
- @objc func networkSearch() {
-
- if appDelegate.account == "" { return }
-
- if literalSearch?.count ?? 0 > 1 {
-
- isReloadDataSourceNetworkInProgress = true
- collectionView?.reloadData()
-
- NCNetworking.shared.searchFiles(urlBase: appDelegate.urlBase, user: appDelegate.user, literal: literalSearch!) { (account, metadatas, errorCode, errorDescription) in
- if self.searchController?.isActive ?? false && errorCode == 0 {
- self.metadatasSource = metadatas!
- }
-
- self.refreshControl.endRefreshing()
- self.isReloadDataSourceNetworkInProgress = false
- self.reloadDataSource()
- }
- } else {
- self.refreshControl.endRefreshing()
- }
- }
-
- @objc func networkReadFolder(forced: Bool, completion: @escaping(_ tableDirectory: tableDirectory?, _ metadatas: [tableMetadata]?, _ metadatasUpdate: [tableMetadata]?, _ metadatasDelete: [tableMetadata]?, _ errorCode: Int, _ errorDescription: String)->()) {
-
- var tableDirectory: tableDirectory?
-
- NCNetworking.shared.readFile(serverUrlFileName: serverUrl, account: appDelegate.account) { (account, metadataFolder, errorCode, errorDescription) in
-
- if errorCode == 0 {
-
- if let metadataFolder = metadataFolder {
- tableDirectory = NCManageDatabase.shared.setDirectory(richWorkspace: metadataFolder.richWorkspace, serverUrl: self.serverUrl, account: account)
- }
-
- if forced || tableDirectory?.etag != metadataFolder?.etag || metadataFolder?.e2eEncrypted ?? false {
-
- NCNetworking.shared.readFolder(serverUrl: self.serverUrl, account: self.appDelegate.account) { (account, metadataFolder, metadatas, metadatasUpdate, metadatasLocalUpdate, metadatasDelete, errorCode, errorDescription) in
-
- if errorCode == 0 {
- self.metadataFolder = metadataFolder
-
- // E2EE
- if let metadataFolder = metadataFolder {
- if metadataFolder.e2eEncrypted && CCUtility.isEnd(toEndEnabled: self.appDelegate.account) {
-
- NCCommunication.shared.getE2EEMetadata(fileId: metadataFolder.ocId, e2eToken: nil) { (account, e2eMetadata, errorCode, errorDescription) in
- if errorCode == 0 && e2eMetadata != nil {
-
- if !NCEndToEndMetadata.shared.decoderMetadata(e2eMetadata!, privateKey: CCUtility.getEndToEndPrivateKey(account), serverUrl: self.serverUrl, account: account, urlBase: self.appDelegate.urlBase) {
-
- NCContentPresenter.shared.messageNotification("_error_e2ee_", description: "_e2e_error_decode_metadata_", delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: NCGlobal.shared.errorDecodeMetadata, forced: true)
- } else {
- self.reloadDataSource()
- }
-
- } else if errorCode != NCGlobal.shared.errorResourceNotFound {
-
- NCContentPresenter.shared.messageNotification("_error_e2ee_", description: "_e2e_error_decode_metadata_", delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: NCGlobal.shared.errorDecodeMetadata, forced: true)
- }
-
- completion(tableDirectory, metadatas, metadatasUpdate, metadatasDelete, errorCode, errorDescription)
- }
- } else {
- completion(tableDirectory, metadatas, metadatasUpdate, metadatasDelete, errorCode, errorDescription)
- }
- } else {
- completion(tableDirectory, metadatas, metadatasUpdate, metadatasDelete, errorCode, errorDescription)
- }
- } else {
- completion(tableDirectory, nil, nil, nil, errorCode, errorDescription)
- }
- }
- } else {
- completion(tableDirectory, nil, nil, nil, 0, "")
- }
- } else {
- completion(nil, nil, nil, nil, errorCode, errorDescription)
- }
- }
- }
- }
- // MARK: - Collection View
- extension NCCollectionViewCommon: UICollectionViewDelegate {
- func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
-
- guard let metadata = dataSource.cellForItemAt(indexPath: indexPath) else { return }
- metadataTouch = metadata
- selectedIndexPath = indexPath
- appDelegate.activeMetadata = metadata
-
- if isEditMode {
- if let index = selectOcId.firstIndex(of: metadata.ocId) {
- selectOcId.remove(at: index)
- } else {
- selectOcId.append(metadata.ocId)
- }
- collectionView.reloadItems(at: [indexPath])
- self.navigationItem.title = NSLocalizedString("_selected_", comment: "") + " : \(selectOcId.count)" + " / \(dataSource.metadatas.count)"
- return
- }
-
- if metadata.e2eEncrypted && !CCUtility.isEnd(toEndEnabled: appDelegate.account) {
- NCContentPresenter.shared.messageNotification("_info_", description: "_e2e_goto_settings_for_enable_", delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.info, errorCode: NCGlobal.shared.errorE2EENotEnabled, forced: true)
- return
- }
-
- if metadata.directory {
-
- guard let serverUrlPush = CCUtility.stringAppendServerUrl(metadataTouch!.serverUrl, addFileName: metadataTouch!.fileName) else { return }
-
- // FILES
- if layoutKey == NCGlobal.shared.layoutViewFiles && !pushed {
-
- if let viewController = appDelegate.listFilesVC[serverUrlPush] {
-
- if viewController.isViewLoaded {
- pushViewController(viewController: viewController)
- }
-
- } else {
-
- if let viewController:NCFiles = UIStoryboard(name: "NCFiles", bundle: nil).instantiateInitialViewController() as? NCFiles {
-
- viewController.isRoot = false
- viewController.serverUrl = serverUrlPush
- viewController.titleCurrentFolder = metadataTouch!.fileNameView
-
- appDelegate.listFilesVC[serverUrlPush] = viewController
-
- pushViewController(viewController: viewController)
- }
- }
- }
-
- // FAVORITE
- if layoutKey == NCGlobal.shared.layoutViewFavorite && !pushed {
-
- if let viewController = appDelegate.listFavoriteVC[serverUrlPush] {
-
- if viewController.isViewLoaded {
- pushViewController(viewController: viewController)
- }
- } else {
-
- if let viewController:NCFavorite = UIStoryboard(name: "NCFavorite", bundle: nil).instantiateInitialViewController() as? NCFavorite {
-
- viewController.serverUrl = serverUrlPush
- viewController.titleCurrentFolder = metadataTouch!.fileNameView
-
- appDelegate.listFavoriteVC[serverUrlPush] = viewController
-
- pushViewController(viewController: viewController)
- }
- }
- }
-
- // OFFLINE
- if layoutKey == NCGlobal.shared.layoutViewOffline && !pushed {
-
- if let viewController = appDelegate.listOfflineVC[serverUrlPush] {
-
- if viewController.isViewLoaded {
- pushViewController(viewController: viewController)
- }
-
- } else {
-
- if let viewController:NCOffline = UIStoryboard(name: "NCOffline", bundle: nil).instantiateInitialViewController() as? NCOffline {
-
- viewController.serverUrl = serverUrlPush
- viewController.titleCurrentFolder = metadataTouch!.fileNameView
-
- appDelegate.listOfflineVC[serverUrlPush] = viewController
-
- pushViewController(viewController: viewController)
- }
- }
- }
-
- // RECENT ( for push use Files ... he he he )
- if layoutKey == NCGlobal.shared.layoutViewRecent && !pushed {
-
- if let viewController = appDelegate.listFilesVC[serverUrlPush] {
-
- if viewController.isViewLoaded {
- pushViewController(viewController: viewController)
- }
-
- } else {
-
- if let viewController:NCFiles = UIStoryboard(name: "NCFiles", bundle: nil).instantiateInitialViewController() as? NCFiles {
-
- viewController.isRoot = false
- viewController.serverUrl = serverUrlPush
- viewController.titleCurrentFolder = metadataTouch!.fileNameView
-
- appDelegate.listFilesVC[serverUrlPush] = viewController
-
- pushViewController(viewController: viewController)
- }
- }
- }
-
- //VIEW IN FOLDER
- if layoutKey == NCGlobal.shared.layoutViewViewInFolder && !pushed {
-
- if let viewController:NCFileViewInFolder = UIStoryboard(name: "NCFileViewInFolder", bundle: nil).instantiateInitialViewController() as? NCFileViewInFolder {
-
- viewController.serverUrl = serverUrlPush
- viewController.titleCurrentFolder = metadataTouch!.fileNameView
-
- pushViewController(viewController: viewController)
- }
- }
-
- // SHARES ( for push use Files ... he he he )
- if layoutKey == NCGlobal.shared.layoutViewShares && !pushed {
-
- if let viewController = appDelegate.listFilesVC[serverUrlPush] {
-
- if viewController.isViewLoaded {
- pushViewController(viewController: viewController)
- }
-
- } else {
-
- if let viewController:NCFiles = UIStoryboard(name: "NCFiles", bundle: nil).instantiateInitialViewController() as? NCFiles {
-
- viewController.isRoot = false
- viewController.serverUrl = serverUrlPush
- viewController.titleCurrentFolder = metadataTouch!.fileNameView
-
- appDelegate.listFilesVC[serverUrlPush] = viewController
-
- pushViewController(viewController: viewController)
- }
- }
- }
-
- } else {
-
- guard let metadataTouch = metadataTouch else { return }
- let imageIcon = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag))
-
- if metadata.typeFile == NCGlobal.shared.metadataTypeFileImage || metadata.typeFile == NCGlobal.shared.metadataTypeFileVideo || metadata.typeFile == NCGlobal.shared.metadataTypeFileAudio {
- var metadatas: [tableMetadata] = []
- for metadata in dataSource.metadatas {
- if metadata.typeFile == NCGlobal.shared.metadataTypeFileImage || metadata.typeFile == NCGlobal.shared.metadataTypeFileVideo || metadata.typeFile == NCGlobal.shared.metadataTypeFileAudio {
- metadatas.append(metadata)
- }
- }
- NCViewer.shared.view(viewController: self, metadata: metadataTouch, metadatas: metadatas, imageIcon: imageIcon)
- return
- }
-
- if CCUtility.fileProviderStorageExists(metadataTouch.ocId, fileNameView: metadataTouch.fileNameView) {
- NCViewer.shared.view(viewController: self, metadata: metadataTouch, metadatas: [metadataTouch], imageIcon: imageIcon)
- } else if NCCommunication.shared.isNetworkReachable() {
- NCNetworking.shared.download(metadata: metadataTouch, selector: NCGlobal.shared.selectorLoadFileView) { (_) in }
- } else {
- NCContentPresenter.shared.messageNotification("_info_", description: "_go_online_", delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.info, errorCode: NCGlobal.shared.errorOffline, forced: true)
- }
- }
- }
-
- func pushViewController(viewController: UIViewController) {
- if pushed { return }
-
- pushed = true
- navigationController?.pushViewController(viewController, animated: true)
- }
-
- func collectionViewSelectAll() {
- selectOcId.removeAll()
- for metadata in metadatasSource {
- selectOcId.append(metadata.ocId)
- }
- collectionView.reloadData()
- }
-
- @available(iOS 13.0, *)
- func collectionView(_ collectionView: UICollectionView, contextMenuConfigurationForItemAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
-
- if isEditMode { return nil }
- guard let metadata = dataSource.cellForItemAt(indexPath: indexPath) else { return nil }
- metadataTouch = metadata
- let identifier = indexPath as NSCopying
- var image: UIImage?
- let cell = collectionView.cellForItem(at: indexPath)
- if cell is NCListCell {
- image = (cell as! NCListCell).imageItem.image
- } else if cell is NCGridCell {
- image = (cell as! NCGridCell).imageItem.image
- }
-
- return UIContextMenuConfiguration(identifier: identifier, previewProvider: {
-
- return NCViewerProviderContextMenu(metadata: metadata, image: image)
-
- }, actionProvider: { suggestedActions in
-
- return NCFunctionCenter.shared.contextMenuConfiguration(ocId: metadata.ocId, viewController: self, enableDeleteLocal: true, enableViewInFolder: false, image: image)
- })
- }
-
- @available(iOS 13.0, *)
- func collectionView(_ collectionView: UICollectionView, willPerformPreviewActionForMenuWith configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionCommitAnimating) {
- animator.addCompletion {
- if let indexPath = configuration.identifier as? IndexPath {
- self.collectionView(collectionView, didSelectItemAt: indexPath)
- }
- }
- }
- }
- extension NCCollectionViewCommon: UICollectionViewDataSource {
- func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
- guard let metadata = dataSource.cellForItemAt(indexPath: indexPath) else { return }
- NCOperationQueue.shared.downloadThumbnail(metadata: metadata, urlBase: appDelegate.urlBase, view: collectionView, indexPath: indexPath)
- }
-
- func collectionView(_ collectionView: UICollectionView, didEndDisplaying cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
- guard let metadata = dataSource.cellForItemAt(indexPath: indexPath) else { return }
- NCOperationQueue.shared.cancelDownloadThumbnail(metadata: metadata)
- }
-
- func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
-
- if kind == UICollectionView.elementKindSectionHeader {
-
- let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "sectionHeaderMenu", for: indexPath) as! NCSectionHeaderMenu
- self.header = header
-
- if collectionView.collectionViewLayout == gridLayout {
- header.buttonSwitch.setImage(UIImage.init(named: "switchList")!.image(color: NCBrandColor.shared.gray, size: 50), for: .normal)
- } else {
- header.buttonSwitch.setImage(UIImage.init(named: "switchGrid")!.image(color: NCBrandColor.shared.gray, size: 50), for: .normal)
- }
-
- header.delegate = self
- header.setStatusButton(count: dataSource.metadatas.count)
- header.setTitleSorted(datasourceTitleButton: layoutForView?.titleButtonHeader ?? "")
- header.viewRichWorkspaceHeightConstraint.constant = headerRichWorkspaceHeight
- header.setRichWorkspaceText(richWorkspaceText: richWorkspaceText)
-
- return header
-
- } else {
-
- let footer = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "sectionFooter", for: indexPath) as! NCSectionFooter
-
- let info = dataSource.getFilesInformation()
- footer.setTitleLabel(directories: info.directories, files: info.files, size: info.size )
-
- return footer
- }
- }
-
- func numberOfSections(in collectionView: UICollectionView) -> Int {
- return 1
- }
-
- func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
- let numberItems = dataSource.numberOfItems()
- emptyDataSet?.numberOfItemsInSection(numberItems, section: section)
- return numberItems
- }
-
- func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
-
- guard let metadata = dataSource.cellForItemAt(indexPath: indexPath) else {
- if layoutForView?.layout == NCGlobal.shared.layoutList {
- return collectionView.dequeueReusableCell(withReuseIdentifier: "listCell", for: indexPath) as! NCListCell
- } else {
- return collectionView.dequeueReusableCell(withReuseIdentifier: "gridCell", for: indexPath) as! NCGridCell
- }
- }
-
- var tableShare: tableShare?
- var isShare = false
- var isMounted = false
-
- if metadataFolder != nil {
- isShare = metadata.permissions.contains(NCGlobal.shared.permissionShared) && !metadataFolder!.permissions.contains(NCGlobal.shared.permissionShared)
- isMounted = metadata.permissions.contains(NCGlobal.shared.permissionMounted) && !metadataFolder!.permissions.contains(NCGlobal.shared.permissionMounted)
- }
-
- if dataSource.metadataShare[metadata.ocId] != nil {
- tableShare = dataSource.metadataShare[metadata.ocId]
- }
-
- //
- // LAYOUT LIST
- //
- if layoutForView?.layout == NCGlobal.shared.layoutList {
-
- let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "listCell", for: indexPath) as! NCListCell
- cell.delegate = self
-
- cell.objectId = metadata.ocId
- cell.indexPath = indexPath
- cell.labelTitle.text = metadata.fileNameView
- cell.labelTitle.textColor = NCBrandColor.shared.label
- cell.labelInfo.text = ""
- cell.labelInfo.textColor = NCBrandColor.shared.systemGray
-
- cell.imageSelect.image = nil
- cell.imageStatus.image = nil
- cell.imageLocal.image = nil
- cell.imageFavorite.image = nil
- cell.imageShared.image = nil
- cell.imageMore.image = nil
-
- cell.imageItem.image = nil
- cell.imageItem.backgroundColor = nil
-
- cell.progressView.progress = 0.0
-
- if metadata.directory {
-
- if metadata.e2eEncrypted {
- cell.imageItem.image = NCBrandColor.cacheImages.folderEncrypted
- } else if isShare {
- cell.imageItem.image = NCBrandColor.cacheImages.folderSharedWithMe
- } else if (tableShare != nil && tableShare?.shareType != 3) {
- cell.imageItem.image = NCBrandColor.cacheImages.folderSharedWithMe
- } else if (tableShare != nil && tableShare?.shareType == 3) {
- cell.imageItem.image = NCBrandColor.cacheImages.folderPublic
- } else if metadata.mountType == "group" {
- cell.imageItem.image = NCBrandColor.cacheImages.folderGroup
- } else if isMounted {
- cell.imageItem.image = NCBrandColor.cacheImages.folderExternal
- } else if metadata.fileName == autoUploadFileName && metadata.serverUrl == autoUploadDirectory {
- cell.imageItem.image = NCBrandColor.cacheImages.folderAutomaticUpload
- } else {
- cell.imageItem.image = NCBrandColor.cacheImages.folder
- }
-
- cell.labelInfo.text = CCUtility.dateDiff(metadata.date as Date)
-
- let lockServerUrl = CCUtility.stringAppendServerUrl(metadata.serverUrl, addFileName: metadata.fileName)!
- let tableDirectory = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.account, lockServerUrl))
-
- // Local image: offline
- if tableDirectory != nil && tableDirectory!.offline {
- cell.imageLocal.image = NCBrandColor.cacheImages.offlineFlag
- }
-
- } else {
-
- if FileManager().fileExists(atPath: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag)) {
- cell.imageItem.image = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag))
- } else {
- if metadata.hasPreview {
- cell.imageItem.backgroundColor = .lightGray
- } else {
- if metadata.iconName.count > 0 {
- cell.imageItem.image = UIImage.init(named: metadata.iconName)
- } else {
- cell.imageItem.image = NCBrandColor.cacheImages.file
- }
- }
- }
-
- cell.labelInfo.text = CCUtility.dateDiff(metadata.date as Date) + " · " + CCUtility.transformedSize(metadata.size)
-
- // image local
- if dataSource.metadataOffLine.contains(metadata.ocId) {
- cell.imageLocal.image = NCBrandColor.cacheImages.offlineFlag
- } else if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
- cell.imageLocal.image = NCBrandColor.cacheImages.local
- }
- }
-
- // image Favorite
- if metadata.favorite {
- cell.imageFavorite.image = NCBrandColor.cacheImages.favorite
- }
-
- // Share image
- if (isShare) {
- cell.imageShared.image = NCBrandColor.cacheImages.shared
- } else if (tableShare != nil && tableShare?.shareType == 3) {
- cell.imageShared.image = NCBrandColor.cacheImages.shareByLink
- } else if (tableShare != nil && tableShare?.shareType != 3) {
- cell.imageShared.image = NCBrandColor.cacheImages.shared
- } else {
- cell.imageShared.image = NCBrandColor.cacheImages.canShare
- }
- if appDelegate.account != metadata.account {
- cell.imageShared.image = NCBrandColor.cacheImages.shared
- }
- if metadata.ownerId.count > 0 && metadata.ownerId != appDelegate.userId && appDelegate.account == metadata.account {
- cell.imageShared.image = UIImage(named: "avatar")
- let fileNameUser = String(CCUtility.getDirectoryUserData()) + "/" + String(CCUtility.getStringUser(appDelegate.user, urlBase: appDelegate.urlBase)) + "-" + metadata.ownerId + ".png"
- if FileManager.default.fileExists(atPath: fileNameUser) {
- if let image = UIImage(contentsOfFile: fileNameUser) {
- cell.imageShared.image = NCUtility.shared.createAvatar(image: image, size: 30)
- }
- } else {
- NCCommunication.shared.downloadAvatar(userId: metadata.ownerId, fileNameLocalPath: fileNameUser, size: NCGlobal.shared.avatarSize) { (account, data, errorCode, errorMessage) in
- if errorCode == 0 && account == self.appDelegate.account {
- if let image = UIImage(contentsOfFile: fileNameUser) {
- cell.imageShared.image = NCUtility.shared.createAvatar(image: image, size: 30)
- }
- }
- }
- }
- }
-
- // Transfer
- var progress: Float = 0.0
- var totalBytes: Int64 = 0
- if let progressType = appDelegate.listProgress[metadata.ocId] {
- progress = progressType.progress
- totalBytes = progressType.totalBytes
- }
- if metadata.status == NCGlobal.shared.metadataStatusInDownload || metadata.status == NCGlobal.shared.metadataStatusDownloading || metadata.status >= NCGlobal.shared.metadataStatusTypeUpload {
- cell.progressView.isHidden = false
- cell.setButtonMore(named: NCGlobal.shared.buttonMoreStop, image: NCBrandColor.cacheImages.buttonStop)
- } else {
- cell.progressView.isHidden = true
- cell.progressView.progress = progress
- cell.setButtonMore(named: NCGlobal.shared.buttonMoreMore, image: NCBrandColor.cacheImages.buttonMore)
- }
-
- // Write status on Label Info
- switch metadata.status {
- case NCGlobal.shared.metadataStatusWaitDownload:
- cell.labelInfo.text = CCUtility.transformedSize(metadata.size) + " - " + NSLocalizedString("_status_wait_download_", comment: "")
- break
- case NCGlobal.shared.metadataStatusInDownload:
- cell.labelInfo.text = CCUtility.transformedSize(metadata.size) + " - " + NSLocalizedString("_status_in_download_", comment: "")
- break
- case NCGlobal.shared.metadataStatusDownloading:
- cell.labelInfo.text = CCUtility.transformedSize(metadata.size) + " - ↓ " + CCUtility.transformedSize(totalBytes)
- break
- case NCGlobal.shared.metadataStatusWaitUpload:
- cell.labelInfo.text = CCUtility.transformedSize(metadata.size) + " - " + NSLocalizedString("_status_wait_upload_", comment: "")
- break
- case NCGlobal.shared.metadataStatusInUpload:
- cell.labelInfo.text = CCUtility.transformedSize(metadata.size) + " - " + NSLocalizedString("_status_in_upload_", comment: "")
- break
- case NCGlobal.shared.metadataStatusUploading:
- cell.labelInfo.text = CCUtility.transformedSize(metadata.size) + " - ↑ " + CCUtility.transformedSize(totalBytes)
- break
- case NCGlobal.shared.metadataStatusUploadError:
- if metadata.sessionError != "" {
- cell.labelInfo.text = NSLocalizedString("_status_wait_upload_", comment: "") + " " + metadata.sessionError
- } else {
- cell.labelInfo.text = NSLocalizedString("_status_wait_upload_", comment: "")
- }
- break
- default:
- break
- }
-
- // Live Photo
- if metadata.livePhoto {
- cell.imageStatus.image = NCBrandColor.cacheImages.livePhoto
- }
-
- // E2EE
- if metadata.e2eEncrypted || isEncryptedFolder {
- cell.hideButtonShare(true)
- } else {
- cell.hideButtonShare(false)
- }
-
- // Remove last separator
- if collectionView.numberOfItems(inSection: indexPath.section) == indexPath.row + 1 {
- cell.separator.isHidden = true
- } else {
- cell.separator.isHidden = false
- }
-
- // Edit mode
- if isEditMode {
- cell.selectMode(true)
- if selectOcId.contains(metadata.ocId) {
- cell.selected(true)
- } else {
- cell.selected(false)
- }
- } else {
- cell.selectMode(false)
- }
-
- // Disable Share Button
- if appDelegate.disableSharesView {
- cell.hideButtonShare(true)
- }
-
- return cell
- }
-
- //
- // LAYOUT GRID
- //
- if layoutForView?.layout == NCGlobal.shared.layoutGrid {
-
- let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "gridCell", for: indexPath) as! NCGridCell
- cell.delegate = self
-
- cell.objectId = metadata.ocId
- cell.indexPath = indexPath
- cell.labelTitle.text = metadata.fileNameView
- cell.labelTitle.textColor = NCBrandColor.shared.label
-
- cell.imageSelect.image = nil
- cell.imageStatus.image = nil
- cell.imageLocal.image = nil
- cell.imageFavorite.image = nil
-
- cell.imageItem.image = nil
- cell.imageItem.backgroundColor = nil
-
- cell.progressView.progress = 0.0
- if metadata.directory {
-
- if metadata.e2eEncrypted {
- cell.imageItem.image = NCBrandColor.cacheImages.folderEncrypted
- } else if isShare {
- cell.imageItem.image = NCBrandColor.cacheImages.folderSharedWithMe
- } else if (tableShare != nil && tableShare!.shareType != 3) {
- cell.imageItem.image = NCBrandColor.cacheImages.folderSharedWithMe
- } else if (tableShare != nil && tableShare!.shareType == 3) {
- cell.imageItem.image = NCBrandColor.cacheImages.folderPublic
- } else if metadata.mountType == "group" {
- cell.imageItem.image = NCBrandColor.cacheImages.folderGroup
- } else if isMounted {
- cell.imageItem.image = NCBrandColor.cacheImages.folderExternal
- } else if metadata.fileName == autoUploadFileName && metadata.serverUrl == autoUploadDirectory {
- cell.imageItem.image = NCBrandColor.cacheImages.folderAutomaticUpload
- } else {
- cell.imageItem.image = NCBrandColor.cacheImages.folder
- }
-
- let lockServerUrl = CCUtility.stringAppendServerUrl(metadata.serverUrl, addFileName: metadata.fileName)!
- let tableDirectory = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.account, lockServerUrl))
-
- // Local image: offline
- if tableDirectory != nil && tableDirectory!.offline {
- cell.imageLocal.image = NCBrandColor.cacheImages.offlineFlag
- }
-
- } else {
-
- if FileManager().fileExists(atPath: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag)) {
- cell.imageItem.image = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag))
- } else {
- if metadata.hasPreview {
- cell.imageItem.backgroundColor = .lightGray
- } else {
- if metadata.iconName.count > 0 {
- cell.imageItem.image = UIImage.init(named: metadata.iconName)
- } else {
- cell.imageItem.image = NCBrandColor.cacheImages.file
- }
- }
- }
-
- // image Local
- if dataSource.metadataOffLine.contains(metadata.ocId) {
- cell.imageLocal.image = NCBrandColor.cacheImages.offlineFlag
- } else if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) {
- cell.imageLocal.image = NCBrandColor.cacheImages.local
- }
- }
-
- // image Favorite
- if metadata.favorite {
- cell.imageFavorite.image = NCBrandColor.cacheImages.favorite
- }
-
- // Transfer
- if metadata.status == NCGlobal.shared.metadataStatusInDownload || metadata.status == NCGlobal.shared.metadataStatusDownloading || metadata.status >= NCGlobal.shared.metadataStatusTypeUpload {
- cell.progressView.isHidden = false
- cell.setButtonMore(named: NCGlobal.shared.buttonMoreStop, image: NCBrandColor.cacheImages.buttonStop)
- } else {
- cell.progressView.isHidden = true
- cell.progressView.progress = 0.0
- cell.setButtonMore(named: NCGlobal.shared.buttonMoreMore, image: NCBrandColor.cacheImages.buttonMore)
- }
-
- // Live Photo
- if metadata.livePhoto {
- cell.imageStatus.image = NCBrandColor.cacheImages.livePhoto
- }
-
- // Edit mode
- if isEditMode {
- cell.selectMode(true)
- if selectOcId.contains(metadata.ocId) {
- cell.selected(true)
- } else {
- cell.selected(false)
- }
- } else {
- cell.selectMode(false)
- }
-
- return cell
- }
-
- return collectionView.dequeueReusableCell(withReuseIdentifier: "gridCell", for: indexPath) as! NCGridCell
- }
- }
- extension NCCollectionViewCommon: UICollectionViewDelegateFlowLayout {
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
-
- headerRichWorkspaceHeight = 0
-
- if let richWorkspaceText = richWorkspaceText {
- let trimmed = richWorkspaceText.trimmingCharacters(in: .whitespaces)
- if trimmed.count > 0 && !isSearching {
- headerRichWorkspaceHeight = UIScreen.main.bounds.size.height / 4
- }
- }
-
- return CGSize(width: collectionView.frame.width, height: headerHeight + headerRichWorkspaceHeight)
- }
-
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize {
- return CGSize(width: collectionView.frame.width, height: footerHeight)
- }
- }
|