diff --git a/Brand/Database.swift b/Brand/Database.swift index 3ebd98e62a..1420ad8872 100644 --- a/Brand/Database.swift +++ b/Brand/Database.swift @@ -26,4 +26,4 @@ import Foundation // Database Realm // let databaseName = "nextcloud.realm" -let databaseSchemaVersion: UInt64 = 349 +let databaseSchemaVersion: UInt64 = 350 diff --git a/Nextcloud.xcodeproj/project.pbxproj b/Nextcloud.xcodeproj/project.pbxproj index 0a9bcf5463..5732bf3a63 100644 --- a/Nextcloud.xcodeproj/project.pbxproj +++ b/Nextcloud.xcodeproj/project.pbxproj @@ -772,6 +772,9 @@ F7BB7E4727A18C56009B9F29 /* Parchment in Frameworks */ = {isa = PBXBuildFile; productRef = F7BB7E4627A18C56009B9F29 /* Parchment */; }; F7BC287E26663F6C004D46C5 /* NCViewCertificateDetails.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F7BC287D26663F6C004D46C5 /* NCViewCertificateDetails.storyboard */; }; F7BC288026663F85004D46C5 /* NCViewCertificateDetails.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7BC287F26663F85004D46C5 /* NCViewCertificateDetails.swift */; }; + F7BD0A002C468925003A4A6D /* NCMedia+CollectionViewDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7BD09FF2C468925003A4A6D /* NCMedia+CollectionViewDataSource.swift */; }; + F7BD0A022C4689A4003A4A6D /* NCMedia+CollectionViewDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7BD0A012C4689A4003A4A6D /* NCMedia+CollectionViewDelegate.swift */; }; + F7BD0A042C4689E9003A4A6D /* NCMedia+MediaLayoutDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7BD0A032C4689E9003A4A6D /* NCMedia+MediaLayoutDelegate.swift */; }; F7BD71E62636EAFC00643C34 /* NCNetworkingE2EE.swift in Sources */ = {isa = PBXBuildFile; fileRef = F785EE9C246196DF00B3F945 /* NCNetworkingE2EE.swift */; }; F7BF9D822934CA21009EE9A6 /* NCManageDatabase+LayoutForView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7BF9D812934CA21009EE9A6 /* NCManageDatabase+LayoutForView.swift */; }; F7BF9D832934CA21009EE9A6 /* NCManageDatabase+LayoutForView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7BF9D812934CA21009EE9A6 /* NCManageDatabase+LayoutForView.swift */; }; @@ -1564,6 +1567,9 @@ F7BB04851FD58ACB00BBFD2A /* cs-CZ */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "cs-CZ"; path = "cs-CZ.lproj/Localizable.strings"; sourceTree = ""; }; F7BC287D26663F6C004D46C5 /* NCViewCertificateDetails.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = NCViewCertificateDetails.storyboard; sourceTree = ""; }; F7BC287F26663F85004D46C5 /* NCViewCertificateDetails.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCViewCertificateDetails.swift; sourceTree = ""; }; + F7BD09FF2C468925003A4A6D /* NCMedia+CollectionViewDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCMedia+CollectionViewDataSource.swift"; sourceTree = ""; }; + F7BD0A012C4689A4003A4A6D /* NCMedia+CollectionViewDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCMedia+CollectionViewDelegate.swift"; sourceTree = ""; }; + F7BD0A032C4689E9003A4A6D /* NCMedia+MediaLayoutDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCMedia+MediaLayoutDelegate.swift"; sourceTree = ""; }; F7BE7C25290AC8C9002ABB61 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Intent.strings; sourceTree = ""; }; F7BE7C27290ADEFD002ABB61 /* eu */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = eu; path = eu.lproj/Intent.strings; sourceTree = ""; }; F7BE7C29290ADEFD002ABB61 /* ca */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ca; path = ca.lproj/Intent.strings; sourceTree = ""; }; @@ -2848,8 +2854,11 @@ F720B5B72507B9A5008C94E5 /* Cell */, F7501C302212E57400FB1415 /* NCMedia.storyboard */, F7501C312212E57400FB1415 /* NCMedia.swift */, + F7BD09FF2C468925003A4A6D /* NCMedia+CollectionViewDataSource.swift */, + F7BD0A012C4689A4003A4A6D /* NCMedia+CollectionViewDelegate.swift */, F72408322B8A27C900F128E2 /* NCMedia+Command.swift */, F7802B312BD5584F00D74270 /* NCMedia+DragDrop.swift */, + F7BD0A032C4689E9003A4A6D /* NCMedia+MediaLayoutDelegate.swift */, F78B87E62B62527100C65ADC /* NCMediaDataSource.swift */, F78B87E82B62550800C65ADC /* NCMediaDownloadThumbnaill.swift */, F755CB3F2B8CB13C00CE27E9 /* NCMediaLayout.swift */, @@ -4213,6 +4222,7 @@ F790110E21415BF600D7B136 /* NCViewerRichDocument.swift in Sources */, F78ACD4021903CC20088454D /* NCGridCell.swift in Sources */, F7D890752BD25C570050B8A6 /* NCCollectionViewCommon+DragDrop.swift in Sources */, + F7BD0A042C4689E9003A4A6D /* NCMedia+MediaLayoutDelegate.swift in Sources */, F761856B29E98543006EB3B0 /* NCIntroViewController.swift in Sources */, F7743A142C33F13A0034F670 /* NCCollectionViewCommon+CollectionViewDataSource.swift in Sources */, F75B0ABD244C4DBB00E58DCA /* NCActionCenter.swift in Sources */, @@ -4224,6 +4234,7 @@ F7802B322BD5584F00D74270 /* NCMedia+DragDrop.swift in Sources */, F7EE66AD2A20B226009AE765 /* UILabel+Extension.swift in Sources */, F78ACD4221903CE00088454D /* NCListCell.swift in Sources */, + F7BD0A002C468925003A4A6D /* NCMedia+CollectionViewDataSource.swift in Sources */, F76D3CF12428B40E005DFA87 /* NCViewerPDFSearch.swift in Sources */, F7245924289BB50C00474787 /* ThreadSafeDictionary.swift in Sources */, F73F537F1E929C8500F8678D /* NCMore.swift in Sources */, @@ -4368,6 +4379,7 @@ F76882302C0DD1E7001CF441 /* NCFileNameModel.swift in Sources */, F72FD3B5297ED49A00075D28 /* NCManageDatabase+E2EE.swift in Sources */, F73EF7CF2B0225BA0087E6E9 /* NCManageDatabase+Tag.swift in Sources */, + F7BD0A022C4689A4003A4A6D /* NCMedia+CollectionViewDelegate.swift in Sources */, F3A047982BD2668800658E7B /* NCAssistantCreateNewTask.swift in Sources */, AF93471227E2341B002537EE /* NCShare+Menu.swift in Sources */, F7EFA47825ADBA500083159A /* NCViewerProviderContextMenu.swift in Sources */, diff --git a/Share/NCShareExtension+DataSource.swift b/Share/NCShareExtension+DataSource.swift index 883a8b6e9e..42921b7b7f 100644 --- a/Share/NCShareExtension+DataSource.swift +++ b/Share/NCShareExtension+DataSource.swift @@ -80,7 +80,6 @@ extension NCShareExtension: UICollectionViewDataSource { } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - guard let metadata = dataSource.cellForItemAt(indexPath: indexPath), let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "listCell", for: indexPath) as? NCListCell else { return UICollectionViewCell() } @@ -92,7 +91,6 @@ extension NCShareExtension: UICollectionViewDataSource { cell.fileUser = metadata.ownerId cell.labelTitle.text = metadata.fileNameView cell.labelTitle.textColor = NCBrandColor.shared.textColor - cell.imageSelect.image = nil cell.imageStatus.image = nil cell.imageLocal.image = nil @@ -101,7 +99,6 @@ extension NCShareExtension: UICollectionViewDataSource { cell.imageMore.image = nil cell.imageItem.image = nil cell.imageItem.backgroundColor = nil - cell.progressView.progress = 0.0 if metadata.directory { @@ -117,7 +114,6 @@ extension NCShareExtension: UICollectionViewDataSource { cell.backgroundView = nil cell.hideButtonMore(true) cell.hideButtonShare(true) - cell.selectMode(false) // Live Photo if metadata.isLivePhoto { diff --git a/Share/NCShareExtension+Files.swift b/Share/NCShareExtension+Files.swift index abd838b78c..3d8565c827 100644 --- a/Share/NCShareExtension+Files.swift +++ b/Share/NCShareExtension+Files.swift @@ -26,24 +26,9 @@ import UniformTypeIdentifiers extension NCShareExtension { @objc func reloadDatasource(withLoadFolder: Bool) { - var groupByField = "name" - layoutForView = NCManageDatabase.shared.setLayoutForView(account: activeAccount.account, key: keyLayout, serverUrl: serverUrl) - - // set GroupField for Grid - if layoutForView?.layout == NCGlobal.shared.layoutGrid { - groupByField = "classFile" - } - let metadatas = NCManageDatabase.shared.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND directory == true", activeAccount.account, serverUrl)) - self.dataSource = NCDataSource( - metadatas: metadatas, - account: activeAccount.account, - sort: layoutForView?.sort, - ascending: layoutForView?.ascending, - directoryOnTop: layoutForView?.directoryOnTop, - favoriteOnTop: true, - groupByField: groupByField) + self.dataSource = NCDataSource(metadatas: metadatas, account: activeAccount.account, layoutForView: layoutForView) if withLoadFolder { loadFolder() diff --git a/Share/NCShareExtension+NCDelegate.swift b/Share/NCShareExtension+NCDelegate.swift index 6c4db67854..d13e00f681 100644 --- a/Share/NCShareExtension+NCDelegate.swift +++ b/Share/NCShareExtension+NCDelegate.swift @@ -97,7 +97,6 @@ extension NCShareExtension: NCAccountRequestDelegate { } extension NCShareExtension: NCShareCellDelegate, NCRenameFileDelegate, NCListCellDelegate { - func removeFile(named fileName: String) { guard let index = self.filesName.firstIndex(of: fileName) else { return showAlert(title: "_file_not_found_", description: fileName) @@ -139,6 +138,15 @@ extension NCShareExtension: NCShareCellDelegate, NCRenameFileDelegate, NCListCel filesName[fileIx] = fileNameNew tableView.reloadData() } + + func tapShareListItem(with objectId: String, indexPath: IndexPath, sender: Any) { + } + + func tapMoreListItem(with objectId: String, namedButtonMore: String, image: UIImage?, indexPath: IndexPath, sender: Any) { + } + + func longPressListItem(with objectId: String, indexPath: IndexPath, gestureRecognizer: UILongPressGestureRecognizer) { + } } extension NCShareExtension: NCCreateFormUploadConflictDelegate { diff --git a/iOSClient/Data/NCDataSource.swift b/iOSClient/Data/NCDataSource.swift index b5fc697114..5575aca838 100644 --- a/iOSClient/Data/NCDataSource.swift +++ b/iOSClient/Data/NCDataSource.swift @@ -28,8 +28,10 @@ class NCDataSource: NSObject { var metadatas: [tableMetadata] = [] var metadatasForSection: [NCMetadataForSection] = [] var directory: tableDirectory? - var groupByField: String = "" + var groupBy: String? + var layout: String? + private let utilityFileSystem = NCUtilityFileSystem() private var sectionsValue: [String] = [] private var providers: [NKSearchProvider]? private var searchResults: [NKSearchResult]? @@ -43,18 +45,25 @@ class NCDataSource: NSObject { super.init() } - init(metadatas: [tableMetadata], account: String, directory: tableDirectory? = nil, sort: String? = "none", ascending: Bool? = false, directoryOnTop: Bool? = true, favoriteOnTop: Bool? = true, groupByField: String = "name", providers: [NKSearchProvider]? = nil, searchResults: [NKSearchResult]? = nil) { + init(metadatas: [tableMetadata], + account: String, + directory: tableDirectory? = nil, + layoutForView: NCDBLayoutForView?, + favoriteOnTop: Bool = true, + providers: [NKSearchProvider]? = nil, + searchResults: [NKSearchResult]? = nil) { super.init() self.metadatas = metadatas.filter({ !(NCGlobal.shared.includeHiddenFiles.contains($0.fileNameView) || $0.isTransferInForeground) }) self.directory = directory - self.sort = sort ?? "none" - self.ascending = ascending ?? false - self.directoryOnTop = directoryOnTop ?? true - self.favoriteOnTop = favoriteOnTop ?? true - self.groupByField = groupByField + self.sort = layoutForView?.sort ?? "none" + self.ascending = layoutForView?.ascending ?? false + self.directoryOnTop = layoutForView?.directoryOnTop ?? true + self.favoriteOnTop = favoriteOnTop + self.groupBy = layoutForView?.groupBy ?? "none" + self.layout = layoutForView?.layout // unified search self.providers = providers self.searchResults = searchResults @@ -77,9 +86,9 @@ class NCDataSource: NSObject { self.directory = nil } - func changeGroupByField(_ groupByField: String) { - self.groupByField = groupByField - print("DATASOURCE: set group by filed " + groupByField) + func changeGroupByField(_ groupBy: String) { + self.groupBy = groupBy + print("DATASOURCE: set group by filed " + groupBy) self.metadatasForSection.removeAll() self.sectionsValue.removeAll() print("DATASOURCE: remove all sections") @@ -108,8 +117,14 @@ class NCDataSource: NSObject { if !self.sectionsValue.contains(section) { self.sectionsValue.append(section) } + // image Cache + if (layout == NCGlobal.shared.layoutPhotoRatio || layout == NCGlobal.shared.layoutPhotoSquare), + (metadata.isVideo || metadata.isImage), + NCImageCache.shared.getPreviewImageCache(ocId: metadata.ocId, etag: metadata.etag) == nil, + let image = UIImage(contentsOfFile: self.utilityFileSystem.getDirectoryProviderStoragePreviewOcId(metadata.ocId, etag: metadata.etag)) { + NCImageCache.shared.addPreviewImageCache(metadata: metadata, image: image) + } } - // Unified search if let providers = self.providers, !providers.isEmpty { let sectionsDictionary = ThreadSafeDictionary() @@ -248,13 +263,13 @@ class NCDataSource: NSObject { } internal func getSectionValue(metadata: tableMetadata) -> String { - switch self.groupByField { - case "name": + switch self.groupBy { + case "name", "none": return NSLocalizedString(metadata.name, comment: "") case "classFile": return NSLocalizedString(metadata.classFile, comment: "").lowercased().firstUppercased default: - return NSLocalizedString(metadata.classFile, comment: "") + return NSLocalizedString(metadata.name, comment: "") } } @@ -339,7 +354,6 @@ class NCMetadataForSection: NSObject { // if sort != "none" && !sort.isEmpty { metadatasSorted = metadatas.sorted { - switch sort { case "date": if ascending { diff --git a/iOSClient/Data/NCManageDatabase+LayoutForView.swift b/iOSClient/Data/NCManageDatabase+LayoutForView.swift index d868626828..4286a84695 100644 --- a/iOSClient/Data/NCManageDatabase+LayoutForView.swift +++ b/iOSClient/Data/NCManageDatabase+LayoutForView.swift @@ -35,12 +35,23 @@ class NCDBLayoutForView: Object { @Persisted var groupBy: String = "none" @Persisted var directoryOnTop: Bool = true @Persisted var titleButtonHeader: String = "_sorted_by_name_a_z_" - @Persisted var itemForLine: Int = 3 + @Persisted var columnGrid: Int = 3 + @Persisted var columnPhoto: Int = 3 } extension NCManageDatabase { @discardableResult - func setLayoutForView(account: String, key: String, serverUrl: String, layout: String? = nil, sort: String? = nil, ascending: Bool? = nil, groupBy: String? = nil, directoryOnTop: Bool? = nil, titleButtonHeader: String? = nil, itemForLine: Int? = nil) -> NCDBLayoutForView? { + func setLayoutForView(account: String, + key: String, + serverUrl: String, + layout: String? = nil, + sort: String? = nil, + ascending: Bool? = nil, + groupBy: String? = nil, + directoryOnTop: Bool? = nil, + titleButtonHeader: String? = nil, + columnGrid: Int? = nil, + columnPhoto: Int? = nil) -> NCDBLayoutForView? { var keyStore = key if !serverUrl.isEmpty { keyStore = serverUrl} let index = account + " " + keyStore @@ -56,29 +67,32 @@ extension NCManageDatabase { } addObject.account = account addObject.keyStore = keyStore - if let layout = layout { + if let layout { addObject.layout = layout } - if let sort = sort { + if let sort { addObject.sort = sort } - if let sort = sort { + if let sort { addObject.sort = sort } - if let ascending = ascending { + if let ascending { addObject.ascending = ascending } - if let groupBy = groupBy { + if let groupBy { addObject.groupBy = groupBy } - if let directoryOnTop = directoryOnTop { + if let directoryOnTop { addObject.directoryOnTop = directoryOnTop } - if let titleButtonHeader = titleButtonHeader { + if let titleButtonHeader { addObject.titleButtonHeader = titleButtonHeader } - if let itemForLine = itemForLine { - addObject.itemForLine = itemForLine + if let columnGrid { + addObject.columnGrid = columnGrid + } + if let columnPhoto { + addObject.columnPhoto = columnPhoto } realm.add(addObject, update: .all) } diff --git a/iOSClient/Favorites/NCFavorite.swift b/iOSClient/Favorites/NCFavorite.swift index ff2b5f39ea..f7b79bc8cd 100644 --- a/iOSClient/Favorites/NCFavorite.swift +++ b/iOSClient/Favorites/NCFavorite.swift @@ -62,15 +62,7 @@ class NCFavorite: NCCollectionViewCommon { metadatas = NCManageDatabase.shared.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", self.appDelegate.account, self.serverUrl)) } - self.dataSource = NCDataSource(metadatas: metadatas, - account: self.appDelegate.account, - sort: self.layoutForView?.sort, - ascending: self.layoutForView?.ascending, - directoryOnTop: self.layoutForView?.directoryOnTop, - favoriteOnTop: true, - groupByField: self.groupByField, - providers: self.providers, - searchResults: self.searchResults) + self.dataSource = NCDataSource(metadatas: metadatas, account: self.appDelegate.account, layoutForView: layoutForView, providers: self.providers, searchResults: self.searchResults) } override func reloadDataSourceNetwork(withQueryDB: Bool = false) { diff --git a/iOSClient/Files/NCFiles.swift b/iOSClient/Files/NCFiles.swift index 573c07553b..69ef84747e 100644 --- a/iOSClient/Files/NCFiles.swift +++ b/iOSClient/Files/NCFiles.swift @@ -58,7 +58,6 @@ class NCFiles: NCCollectionViewCommon { self.selectOcId.removeAll() self.layoutForView = NCManageDatabase.shared.getLayoutForView(account: self.appDelegate.account, key: self.layoutKey, serverUrl: self.serverUrl) - self.gridLayout.itemForLine = CGFloat(self.layoutForView?.itemForLine ?? 3) if self.layoutForView?.layout == NCGlobal.shared.layoutList { self.collectionView?.collectionViewLayout = self.listLayout } else if self.layoutForView?.layout == NCGlobal.shared.layoutGrid { @@ -113,17 +112,7 @@ class NCFiles: NCCollectionViewCommon { } self.richWorkspaceText = directory?.richWorkspace - self.dataSource = NCDataSource( - metadatas: metadatas, - account: self.appDelegate.account, - directory: directory, - sort: self.layoutForView?.sort, - ascending: self.layoutForView?.ascending, - directoryOnTop: self.layoutForView?.directoryOnTop, - favoriteOnTop: true, - groupByField: self.groupByField, - providers: self.providers, - searchResults: self.searchResults) + self.dataSource = NCDataSource(metadatas: metadatas, account: self.appDelegate.account, layoutForView: layoutForView, providers: self.providers, searchResults: self.searchResults) } override func reloadDataSource(withQueryDB: Bool = true) { diff --git a/iOSClient/Groupfolders/NCGroupfolders.swift b/iOSClient/Groupfolders/NCGroupfolders.swift index acfc27e956..b067e4aac4 100644 --- a/iOSClient/Groupfolders/NCGroupfolders.swift +++ b/iOSClient/Groupfolders/NCGroupfolders.swift @@ -62,16 +62,7 @@ class NCGroupfolders: NCCollectionViewCommon { metadatas = NCManageDatabase.shared.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", self.appDelegate.account, self.serverUrl)) } - self.dataSource = NCDataSource( - metadatas: metadatas, - account: self.appDelegate.account, - sort: self.layoutForView?.sort, - ascending: self.layoutForView?.ascending, - directoryOnTop: self.layoutForView?.directoryOnTop, - favoriteOnTop: true, - groupByField: self.groupByField, - providers: self.providers, - searchResults: self.searchResults) + self.dataSource = NCDataSource(metadatas: metadatas, account: self.appDelegate.account, layoutForView: layoutForView, providers: self.providers, searchResults: self.searchResults) } override func reloadDataSourceNetwork(withQueryDB: Bool = false) { diff --git a/iOSClient/Main/Collection Common/Cell/NCCellProtocol.swift b/iOSClient/Main/Collection Common/Cell/NCCellProtocol.swift index 6f05714517..8a315baa1d 100644 --- a/iOSClient/Main/Collection Common/Cell/NCCellProtocol.swift +++ b/iOSClient/Main/Collection Common/Cell/NCCellProtocol.swift @@ -33,7 +33,6 @@ protocol NCCellProtocol { var fileInfoLabel: UILabel? { get set } var fileSubinfoLabel: UILabel? { get set } var fileProgressView: UIProgressView? { get set } - var fileSelectImage: UIImageView? { get set } var fileStatusImage: UIImageView? { get set } var fileLocalImage: UIImageView? { get set } var fileFavoriteImage: UIImageView? { get set } @@ -48,8 +47,7 @@ protocol NCCellProtocol { func setButtonMore(named: String, image: UIImage) func hideButtonShare(_ status: Bool) func hideButtonMore(_ status: Bool) - func selectMode(_ status: Bool) - func selected(_ status: Bool) + func selected(_ status: Bool, isEditMode: Bool) func setAccessibility(label: String, value: String) func setTags(tags: [String]) func setIconOutlines() @@ -88,10 +86,6 @@ extension NCCellProtocol { get { return nil } set {} } - var fileSelectImage: UIImageView? { - get { return nil } - set {} - } var fileStatusImage: UIImageView? { get { return nil } set {} @@ -123,8 +117,7 @@ extension NCCellProtocol { func setButtonMore(named: String, image: UIImage) {} func hideButtonShare(_ status: Bool) {} func hideButtonMore(_ status: Bool) {} - func selectMode(_ status: Bool) {} - func selected(_ status: Bool) {} + func selected(_ status: Bool, isEditMode: Bool) {} func setAccessibility(label: String, value: String) {} func setTags(tags: [String]) {} func setIconOutlines() {} diff --git a/iOSClient/Main/Collection Common/Cell/NCGridCell.swift b/iOSClient/Main/Collection Common/Cell/NCGridCell.swift index 7198938b74..2e262ed129 100644 --- a/iOSClient/Main/Collection Common/Cell/NCGridCell.swift +++ b/iOSClient/Main/Collection Common/Cell/NCGridCell.swift @@ -24,7 +24,6 @@ import UIKit class NCGridCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProtocol { - @IBOutlet weak var imageItem: UIImageView! @IBOutlet weak var imageSelect: UIImageView! @IBOutlet weak var imageStatus: UIImageView! @@ -67,10 +66,6 @@ class NCGridCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProto get { return labelSubinfo } set { labelSubinfo = newValue } } - var fileSelectImage: UIImageView? { - get { return imageSelect } - set { imageSelect = newValue } - } var fileStatusImage: UIImageView? { get { return imageStatus } set { imageStatus = newValue } @@ -86,8 +81,15 @@ class NCGridCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProto override func awakeFromNib() { super.awakeFromNib() + initCell() + } + + override func prepareForReuse() { + super.prepareForReuse() + initCell() + } - // use entire cell as accessibility element + func initCell() { accessibilityHint = nil accessibilityLabel = nil accessibilityValue = nil @@ -100,31 +102,20 @@ class NCGridCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProto imageVisualEffect.clipsToBounds = true imageVisualEffect.alpha = 0.5 + imageSelect.isHidden = true + imageSelect.image = NCImageCache.images.checkedYes + let longPressedGesture = UILongPressGestureRecognizer(target: self, action: #selector(longPress(gestureRecognizer:))) longPressedGesture.minimumPressDuration = 0.5 longPressedGesture.delegate = self longPressedGesture.delaysTouchesBegan = true self.addGestureRecognizer(longPressedGesture) - let longPressedGestureMore = UILongPressGestureRecognizer(target: self, action: #selector(longPressInsideMore(gestureRecognizer:))) - longPressedGestureMore.minimumPressDuration = 0.5 - longPressedGestureMore.delegate = self - longPressedGestureMore.delaysTouchesBegan = true - buttonMore.addGestureRecognizer(longPressedGestureMore) - labelTitle.text = "" labelInfo.text = "" labelSubinfo.text = "" } - override func prepareForReuse() { - super.prepareForReuse() - imageItem.backgroundColor = nil - accessibilityHint = nil - accessibilityLabel = nil - accessibilityValue = nil - } - override func snapshotView(afterScreenUpdates afterUpdates: Bool) -> UIView? { return nil } @@ -133,10 +124,6 @@ class NCGridCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProto gridCellDelegate?.tapMoreGridItem(with: objectId, namedButtonMore: namedButtonMore, image: imageItem.image, indexPath: indexPath, sender: sender) } - @objc func longPressInsideMore(gestureRecognizer: UILongPressGestureRecognizer) { - gridCellDelegate?.longPressMoreGridItem(with: objectId, namedButtonMore: namedButtonMore, indexPath: indexPath, gestureRecognizer: gestureRecognizer) - } - @objc func longPress(gestureRecognizer: UILongPressGestureRecognizer) { gridCellDelegate?.longPressGridItem(with: objectId, indexPath: indexPath, gestureRecognizer: gestureRecognizer) } @@ -162,34 +149,16 @@ class NCGridCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProto buttonMore.isHidden = status } - func selectMode(_ status: Bool) { - if status { - imageSelect.isHidden = false + func selected(_ status: Bool, isEditMode: Bool) { + if isEditMode { buttonMore.isHidden = true accessibilityCustomActions = nil } else { - imageSelect.isHidden = true - imageVisualEffect.isHidden = true buttonMore.isHidden = false setA11yActions() } - } - - func selected(_ status: Bool) { - guard let metadata = NCManageDatabase.shared.getMetadataFromOcId(objectId), !metadata.isInTransfer else { - imageSelect.isHidden = true - imageVisualEffect.isHidden = true - return - } if status { - if traitCollection.userInterfaceStyle == .dark { - imageVisualEffect.effect = UIBlurEffect(style: .dark) - imageVisualEffect.backgroundColor = .black - } else { - imageVisualEffect.effect = UIBlurEffect(style: .extraLight) - imageVisualEffect.backgroundColor = .lightGray - } - imageSelect.image = NCImageCache.images.checkedYes + imageSelect.isHidden = false imageVisualEffect.isHidden = false } else { imageSelect.isHidden = true @@ -198,7 +167,6 @@ class NCGridCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProto } func writeInfoDateSize(date: NSDate, size: Int64) { - let dateFormatter = DateFormatter() dateFormatter.dateStyle = .short dateFormatter.timeStyle = .none @@ -224,28 +192,17 @@ class NCGridCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProto protocol NCGridCellDelegate: AnyObject { func tapMoreGridItem(with objectId: String, namedButtonMore: String, image: UIImage?, indexPath: IndexPath, sender: Any) - func longPressMoreGridItem(with objectId: String, namedButtonMore: String, indexPath: IndexPath, gestureRecognizer: UILongPressGestureRecognizer) func longPressGridItem(with objectId: String, indexPath: IndexPath, gestureRecognizer: UILongPressGestureRecognizer) } -// optional func -extension NCGridCellDelegate { - func tapMoreGridItem(with objectId: String, namedButtonMore: String, image: UIImage?, indexPath: IndexPath, sender: Any) {} - func longPressMoreGridItem(with objectId: String, namedButtonMore: String, indexPath: IndexPath, gestureRecognizer: UILongPressGestureRecognizer) {} - func longPressGridItem(with objectId: String, indexPath: IndexPath, gestureRecognizer: UILongPressGestureRecognizer) {} -} - // MARK: - Grid Layout class NCGridLayout: UICollectionViewFlowLayout { - var heightLabelPlusButton: CGFloat = 60 var marginLeftRight: CGFloat = 10 - var itemForLine: CGFloat = 3 + var column: CGFloat = 3 var itemWidthDefault: CGFloat = 140 - // MARK: - View Life Cycle - override init() { super.init() @@ -265,20 +222,15 @@ class NCGridLayout: UICollectionViewFlowLayout { override var itemSize: CGSize { get { if let collectionView = collectionView { - if collectionView.frame.width < 400 { - itemForLine = 3 + column = 3 } else { - itemForLine = collectionView.frame.width / itemWidthDefault + column = collectionView.frame.width / itemWidthDefault } - - let itemWidth: CGFloat = (collectionView.frame.width - marginLeftRight * 2 - marginLeftRight * (itemForLine - 1)) / itemForLine + let itemWidth: CGFloat = (collectionView.frame.width - marginLeftRight * 2 - marginLeftRight * (column - 1)) / column let itemHeight: CGFloat = itemWidth + heightLabelPlusButton - return CGSize(width: itemWidth, height: itemHeight) } - - // Default fallback return CGSize(width: itemWidthDefault, height: itemWidthDefault) } set { diff --git a/iOSClient/Main/Collection Common/Cell/NCGridCell.xib b/iOSClient/Main/Collection Common/Cell/NCGridCell.xib index a69853c857..8a2beec3a7 100644 --- a/iOSClient/Main/Collection Common/Cell/NCGridCell.xib +++ b/iOSClient/Main/Collection Common/Cell/NCGridCell.xib @@ -18,43 +18,18 @@ + - - - - - - - - - - - - - - - - - - - @@ -77,14 +52,6 @@ - @@ -92,6 +59,32 @@ + + + + + + + + + + +