From 8108198338f94948f12aaebda644f256a19de9ad Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Sat, 13 Jul 2024 12:40:43 +0200 Subject: [PATCH 01/27] build 4 Signed-off-by: Marino Faggiana --- Nextcloud.xcodeproj/project.pbxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Nextcloud.xcodeproj/project.pbxproj b/Nextcloud.xcodeproj/project.pbxproj index d3e84b2eaa..a724c8ec16 100644 --- a/Nextcloud.xcodeproj/project.pbxproj +++ b/Nextcloud.xcodeproj/project.pbxproj @@ -5370,7 +5370,7 @@ CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 3; + CURRENT_PROJECT_VERSION = 4; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = NKUJUXUJ3B; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -5436,7 +5436,7 @@ CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 3; + CURRENT_PROJECT_VERSION = 4; DEVELOPMENT_TEAM = NKUJUXUJ3B; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; From 5ac6339d1135f5ab7deff02191921310c55dd076 Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Sat, 13 Jul 2024 13:34:06 +0200 Subject: [PATCH 02/27] coding Signed-off-by: Marino Faggiana --- Nextcloud.xcodeproj/project.pbxproj | 12 + Share/NCShareExtension+Files.swift | 5 - iOSClient/Files/NCFiles.swift | 4 +- .../Collection Common/Cell/NCPhotoCell.swift | 235 ++++++++++++++++++ .../Collection Common/Cell/NCPhotoCell.xib | 81 ++++++ ...nViewCommon+CollectionViewDataSource.swift | 7 +- ...ionViewCommon+CollectionViewDelegate.swift | 2 + .../NCCollectionViewCommon+DragDrop.swift | 3 +- ...ctionViewCommon+SelectTabBarDelegate.swift | 23 +- .../NCCollectionViewCommon.swift | 31 +-- iOSClient/NCGlobal.swift | 1 + 11 files changed, 379 insertions(+), 25 deletions(-) create mode 100644 iOSClient/Main/Collection Common/Cell/NCPhotoCell.swift create mode 100644 iOSClient/Main/Collection Common/Cell/NCPhotoCell.xib diff --git a/Nextcloud.xcodeproj/project.pbxproj b/Nextcloud.xcodeproj/project.pbxproj index a724c8ec16..eaf6903c1d 100644 --- a/Nextcloud.xcodeproj/project.pbxproj +++ b/Nextcloud.xcodeproj/project.pbxproj @@ -467,6 +467,10 @@ F74DE14425135B6800917068 /* NCTransfers.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F74DE14225135B6800917068 /* NCTransfers.storyboard */; }; F7501C322212E57500FB1415 /* NCMedia.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F7501C302212E57400FB1415 /* NCMedia.storyboard */; }; F7501C332212E57500FB1415 /* NCMedia.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7501C312212E57400FB1415 /* NCMedia.swift */; }; + F751247C2C42919C00E63DB8 /* NCPhotoCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = F751247A2C42919C00E63DB8 /* NCPhotoCell.swift */; }; + F751247D2C42919C00E63DB8 /* NCPhotoCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = F751247A2C42919C00E63DB8 /* NCPhotoCell.swift */; }; + F751247E2C42919C00E63DB8 /* NCPhotoCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = F751247B2C42919C00E63DB8 /* NCPhotoCell.xib */; }; + F751247F2C42919C00E63DB8 /* NCPhotoCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = F751247B2C42919C00E63DB8 /* NCPhotoCell.xib */; }; F75379202AE2AD9400C0250E /* JGProgressHUD in Frameworks */ = {isa = PBXBuildFile; productRef = F753791F2AE2AD9400C0250E /* JGProgressHUD */; }; F75379222AE2ADA100C0250E /* JGProgressHUD in Frameworks */ = {isa = PBXBuildFile; productRef = F75379212AE2ADA100C0250E /* JGProgressHUD */; }; F753BA93281FD8020015BFB6 /* EasyTipView in Frameworks */ = {isa = PBXBuildFile; productRef = F753BA92281FD8020015BFB6 /* EasyTipView */; }; @@ -1319,6 +1323,8 @@ F74DE14225135B6800917068 /* NCTransfers.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = NCTransfers.storyboard; sourceTree = ""; }; F7501C302212E57400FB1415 /* NCMedia.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = NCMedia.storyboard; sourceTree = ""; }; F7501C312212E57400FB1415 /* NCMedia.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCMedia.swift; sourceTree = ""; }; + F751247A2C42919C00E63DB8 /* NCPhotoCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCPhotoCell.swift; sourceTree = ""; }; + F751247B2C42919C00E63DB8 /* NCPhotoCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NCPhotoCell.xib; sourceTree = ""; }; F75153232226920200323DDC /* FastScroll.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = FastScroll.framework; path = Carthage/Build/iOS/FastScroll.framework; sourceTree = ""; }; F753701822723D620041C76C /* gl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = gl; path = gl.lproj/Localizable.strings; sourceTree = ""; }; F753701922723E0D0041C76C /* ca */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ca; path = ca.lproj/Localizable.strings; sourceTree = ""; }; @@ -2257,6 +2263,8 @@ isa = PBXGroup; children = ( 370D26AE248A3D7A00121797 /* NCCellProtocol.swift */, + F751247A2C42919C00E63DB8 /* NCPhotoCell.swift */, + F751247B2C42919C00E63DB8 /* NCPhotoCell.xib */, F78ACD3F21903CC20088454D /* NCGridCell.swift */, F78ACD4521903D010088454D /* NCGridCell.xib */, F78ACD4121903CE00088454D /* NCListCell.swift */, @@ -3635,6 +3643,7 @@ F7145A231D12E3B700CAFEEC /* Localizable.strings in Resources */, F746EC51273906C40052598D /* NCViewCertificateDetails.storyboard in Resources */, F76C26A62850D3A500E42BDF /* Images.xcassets in Resources */, + F751247F2C42919C00E63DB8 /* NCPhotoCell.xib in Resources */, F79EC784263161BA004E59D6 /* NCRenameFile.storyboard in Resources */, F714804F262ED4F900693E51 /* NCGridCell.xib in Resources */, F714805E262ED52900693E51 /* NCSectionFooter.xib in Resources */, @@ -3725,6 +3734,7 @@ F7C9555321F0C4CA0024296E /* NCActivity.storyboard in Resources */, F7BC287E26663F6C004D46C5 /* NCViewCertificateDetails.storyboard in Resources */, F78ACD54219047D40088454D /* NCSectionFooter.xib in Resources */, + F751247E2C42919C00E63DB8 /* NCPhotoCell.xib in Resources */, F704B5E32430AA6F00632F5F /* NCCreateFormUploadConflict.storyboard in Resources */, F7EDE509262DA9D600414FE6 /* NCSelectCommandViewSelect.xib in Resources */, F732D23327CF8AED000B0F1B /* NCPlayerToolBar.xib in Resources */, @@ -3990,6 +4000,7 @@ F7327E232B73A42F00A462C7 /* NCNetworking+Download.swift in Sources */, F749B64D297B0CBB00087535 /* NCManageDatabase+Share.swift in Sources */, F72FD3B8297ED49A00075D28 /* NCManageDatabase+E2EE.swift in Sources */, + F751247D2C42919C00E63DB8 /* NCPhotoCell.swift in Sources */, F7EDE4E0262D7BAF00414FE6 /* NCGridCell.swift in Sources */, F7A76DC8256A71CD00119AB3 /* UIImage+Extension.swift in Sources */, F711A4E52AF9310500095DD8 /* NCUtility+Image.swift in Sources */, @@ -4337,6 +4348,7 @@ F7145610296433C80038D028 /* NCDocumentCamera.swift in Sources */, F76882312C0DD1E7001CF441 /* NCFileNameView.swift in Sources */, F7381EE1218218C9000B1560 /* NCOffline.swift in Sources */, + F751247C2C42919C00E63DB8 /* NCPhotoCell.swift in Sources */, F7A509252C26BD5D00326106 /* NCCreateDocument.swift in Sources */, F7FA80002C0F4F3B0072FC60 /* NCUploadAssetsModel.swift in Sources */, F719D9E2288D396100762E33 /* NCColorPicker.swift in Sources */, diff --git a/Share/NCShareExtension+Files.swift b/Share/NCShareExtension+Files.swift index 6b66df2a22..abd838b78c 100644 --- a/Share/NCShareExtension+Files.swift +++ b/Share/NCShareExtension+Files.swift @@ -25,9 +25,7 @@ import Foundation import UniformTypeIdentifiers extension NCShareExtension { - @objc func reloadDatasource(withLoadFolder: Bool) { - var groupByField = "name" layoutForView = NCManageDatabase.shared.setLayoutForView(account: activeAccount.account, key: keyLayout, serverUrl: serverUrl) @@ -52,12 +50,10 @@ extension NCShareExtension { } else { self.refreshControl.endRefreshing() } - collectionView.reloadData() } @objc func didCreateFolder(_ notification: NSNotification) { - guard let userInfo = notification.userInfo as NSDictionary?, let ocId = userInfo["ocId"] as? String, let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) @@ -69,7 +65,6 @@ extension NCShareExtension { } func loadFolder() { - NCNetworking.shared.readFolder(serverUrl: serverUrl, account: activeAccount.account) { task in self.dataSourceTask = task self.collectionView.reloadData() diff --git a/iOSClient/Files/NCFiles.swift b/iOSClient/Files/NCFiles.swift index d5084f6a1c..e6d21be110 100644 --- a/iOSClient/Files/NCFiles.swift +++ b/iOSClient/Files/NCFiles.swift @@ -61,8 +61,10 @@ class NCFiles: NCCollectionViewCommon { self.gridLayout.itemForLine = CGFloat(self.layoutForView?.itemForLine ?? 3) if self.layoutForView?.layout == NCGlobal.shared.layoutList { self.collectionView?.collectionViewLayout = self.listLayout - } else { + } else if self.layoutForView?.layout == NCGlobal.shared.layoutGrid { self.collectionView?.collectionViewLayout = self.gridLayout + } else if self.layoutForView?.layout == NCGlobal.shared.layoutPhoto { + self.collectionView?.collectionViewLayout = self.photoLayout } self.titleCurrentFolder = self.getNavigationTitle() diff --git a/iOSClient/Main/Collection Common/Cell/NCPhotoCell.swift b/iOSClient/Main/Collection Common/Cell/NCPhotoCell.swift new file mode 100644 index 0000000000..4fbee6fba3 --- /dev/null +++ b/iOSClient/Main/Collection Common/Cell/NCPhotoCell.swift @@ -0,0 +1,235 @@ +// +// NCPhotoCell.swift +// Nextcloud +// +// Created by Marino Faggiana on 13/07/2024. +// Copyright © 2024 Marino Faggiana. All rights reserved. +// +// Author Marino Faggiana +// +// 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 . +// + +import UIKit + +class NCPhotoCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProtocol { + + @IBOutlet weak var imageItem: UIImageView! + @IBOutlet weak var imageSelect: UIImageView! + @IBOutlet weak var imageStatus: UIImageView! + @IBOutlet weak var imageVisualEffect: UIVisualEffectView! + + var objectId = "" + var indexPath = IndexPath() + private var user = "" + + weak var photoCellDelegate: NCPhotoCellDelegate? + var namedButtonMore = "" + + var fileObjectId: String? { + get { return objectId } + set { objectId = newValue ?? "" } + } + var filePreviewImageView: UIImageView? { + get { return imageItem } + set { imageItem = newValue } + } + var fileUser: String? { + get { return user } + set { user = newValue ?? "" } + } + + var fileTitleLabel: UILabel? { + get { return nil } + set { } + } + var fileInfoLabel: UILabel? { + get { return nil } + set { } + } + + var fileSubinfoLabel: UILabel? { + get { return nil } + set { } + } + var fileSelectImage: UIImageView? { + get { return imageSelect } + set { imageSelect = newValue } + } + var fileStatusImage: UIImageView? { + get { return imageStatus } + set { imageStatus = newValue } + } + var fileLocalImage: UIImageView? { + get { return nil } + set { } + } + var fileFavoriteImage: UIImageView? { + get { return nil } + set { } + } + + override func awakeFromNib() { + super.awakeFromNib() + + // use entire cell as accessibility element + accessibilityHint = nil + accessibilityLabel = nil + accessibilityValue = nil + isAccessibilityElement = true + + imageItem.layer.cornerRadius = 6 + imageItem.layer.masksToBounds = true + + imageVisualEffect.layer.cornerRadius = 6 + imageVisualEffect.clipsToBounds = true + imageVisualEffect.alpha = 0.5 + + let longPressedGesture = UILongPressGestureRecognizer(target: self, action: #selector(longPress(gestureRecognizer:))) + longPressedGesture.minimumPressDuration = 0.5 + longPressedGesture.delegate = self + longPressedGesture.delaysTouchesBegan = true + self.addGestureRecognizer(longPressedGesture) + } + + override func prepareForReuse() { + super.prepareForReuse() + imageItem.backgroundColor = nil + accessibilityHint = nil + accessibilityLabel = nil + accessibilityValue = nil + } + + override func snapshotView(afterScreenUpdates afterUpdates: Bool) -> UIView? { + return nil + } + + @objc func longPress(gestureRecognizer: UILongPressGestureRecognizer) { + photoCellDelegate?.longPressGridItem(with: objectId, indexPath: indexPath, gestureRecognizer: gestureRecognizer) + } + + func selectMode(_ status: Bool) { + if status { + imageSelect.isHidden = false + accessibilityCustomActions = nil + } else { + imageSelect.isHidden = true + imageVisualEffect.isHidden = true + } + } + + 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 + imageVisualEffect.isHidden = false + } else { + imageSelect.isHidden = true + imageVisualEffect.isHidden = true + } + } + + func setAccessibility(label: String, value: String) { + accessibilityLabel = label + accessibilityValue = value + } + + func setIconOutlines() { + if imageStatus.image != nil { + imageStatus.makeCircularBackground(withColor: .systemBackground) + } else { + imageStatus.backgroundColor = .clear + } + } +} + +protocol NCPhotoCellDelegate: 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 NCPhotoCellDelegate { + 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: - Photo Layout + +class NCPhotoLayout: UICollectionViewFlowLayout { + + var heightLabelPlusButton: CGFloat = 60 + var marginLeftRight: CGFloat = 10 + var itemForLine: CGFloat = 3 + var itemWidthDefault: CGFloat = 140 + + // MARK: - View Life Cycle + + override init() { + super.init() + + sectionHeadersPinToVisibleBounds = false + + minimumInteritemSpacing = 1 + minimumLineSpacing = marginLeftRight + + self.scrollDirection = .vertical + self.sectionInset = UIEdgeInsets(top: 10, left: marginLeftRight, bottom: 0, right: marginLeftRight) + } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override var itemSize: CGSize { + get { + if let collectionView = collectionView { + + if collectionView.frame.width < 400 { + itemForLine = 3 + } else { + itemForLine = collectionView.frame.width / itemWidthDefault + } + + let itemWidth: CGFloat = (collectionView.frame.width - marginLeftRight * 2 - marginLeftRight * (itemForLine - 1)) / itemForLine + let itemHeight: CGFloat = itemWidth + heightLabelPlusButton + + return CGSize(width: itemWidth, height: itemHeight) + } + + // Default fallback + return CGSize(width: itemWidthDefault, height: itemWidthDefault) + } + set { + super.itemSize = newValue + } + } + + override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint) -> CGPoint { + return proposedContentOffset + } +} diff --git a/iOSClient/Main/Collection Common/Cell/NCPhotoCell.xib b/iOSClient/Main/Collection Common/Cell/NCPhotoCell.xib new file mode 100644 index 0000000000..21ee4f8534 --- /dev/null +++ b/iOSClient/Main/Collection Common/Cell/NCPhotoCell.xib @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift index 5e6307c8eb..d28b61f4f7 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift @@ -138,11 +138,16 @@ extension NCCollectionViewCommon: UICollectionViewDataSource { guard let listCell = collectionView.dequeueReusableCell(withReuseIdentifier: "listCell", for: indexPath) as? NCListCell else { return NCListCell() } listCell.listCellDelegate = self cell = listCell - } else { + } else if layoutForView?.layout == NCGlobal.shared.layoutGrid { // LAYOUT GRID guard let gridCell = collectionView.dequeueReusableCell(withReuseIdentifier: "gridCell", for: indexPath) as? NCGridCell else { return NCGridCell() } gridCell.gridCellDelegate = self cell = gridCell + } else { + // LAYOUT PHOTO + guard let photoCell = collectionView.dequeueReusableCell(withReuseIdentifier: "photoCell", for: indexPath) as? NCPhotoCell else { return NCPhotoCell() } + photoCell.photoCellDelegate = self + cell = photoCell } guard let metadata = dataSource.cellForItemAt(indexPath: indexPath) else { return cell } diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDelegate.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDelegate.swift index 9a0c006e7b..b57e30a253 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDelegate.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDelegate.swift @@ -94,6 +94,8 @@ extension NCCollectionViewCommon: UICollectionViewDelegate { image = (cell as? NCListCell)?.imageItem.image } else if cell is NCGridCell { image = (cell as? NCGridCell)?.imageItem.image + } else if cell is NCPhotoCell { + image = (cell as? NCPhotoCell)?.imageItem.image } return UIContextMenuConfiguration(identifier: identifier, previewProvider: { diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon+DragDrop.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon+DragDrop.swift index 1f290adcc6..21cda765a9 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon+DragDrop.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon+DragDrop.swift @@ -42,7 +42,8 @@ extension NCCollectionViewCommon: UICollectionViewDragDelegate { func collectionView(_ collectionView: UICollectionView, dragPreviewParametersForItemAt indexPath: IndexPath) -> UIDragPreviewParameters? { let previewParameters = UIDragPreviewParameters() - if layoutForView?.layout == NCGlobal.shared.layoutList, let cell = collectionView.cellForItem(at: indexPath) as? NCListCell { + if layoutForView?.layout == NCGlobal.shared.layoutList, + let cell = collectionView.cellForItem(at: indexPath) as? NCListCell { let width = (collectionView.frame.width / 3) * 2 previewParameters.visiblePath = UIBezierPath(roundedRect: CGRect(x: 0, y: 0, width: width, height: cell.frame.height), cornerRadius: 10) return previewParameters diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon+SelectTabBarDelegate.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon+SelectTabBarDelegate.swift index f948f61602..f6da857db9 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon+SelectTabBarDelegate.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon+SelectTabBarDelegate.swift @@ -27,7 +27,7 @@ import NextcloudKit extension NCCollectionViewCommon: NCCollectionViewCommonSelectTabBarDelegate { func onListSelected() { - if layoutForView?.layout == NCGlobal.shared.layoutGrid { + if layoutForView?.layout != NCGlobal.shared.layoutList { layoutForView?.layout = NCGlobal.shared.layoutList NCManageDatabase.shared.setLayoutForView(account: appDelegate.account, key: layoutKey, serverUrl: serverUrl, layout: layoutForView?.layout) self.groupByField = "name" @@ -42,7 +42,7 @@ extension NCCollectionViewCommon: NCCollectionViewCommonSelectTabBarDelegate { } func onGridSelected() { - if layoutForView?.layout == NCGlobal.shared.layoutList { + if layoutForView?.layout != NCGlobal.shared.layoutGrid { layoutForView?.layout = NCGlobal.shared.layoutGrid NCManageDatabase.shared.setLayoutForView(account: appDelegate.account, key: layoutKey, serverUrl: serverUrl, layout: layoutForView?.layout) if isSearchingMode { @@ -60,6 +60,25 @@ extension NCCollectionViewCommon: NCCollectionViewCommonSelectTabBarDelegate { } } + func onPhotoSelected() { + if layoutForView?.layout != NCGlobal.shared.layoutPhoto { + layoutForView?.layout = NCGlobal.shared.layoutPhoto + NCManageDatabase.shared.setLayoutForView(account: appDelegate.account, key: layoutKey, serverUrl: serverUrl, layout: layoutForView?.layout) + if isSearchingMode { + self.groupByField = "name" + } else { + self.groupByField = "classFile" + } + if self.dataSource.groupByField != self.groupByField { + self.dataSource.changeGroupByField(self.groupByField) + } + + self.collectionView.reloadData() + self.collectionView.collectionViewLayout.invalidateLayout() + self.collectionView.setCollectionViewLayout(self.gridLayout, animated: true) {_ in self.isTransitioning = false } + } + } + func selectAll() { if !selectOcId.isEmpty, dataSource.getMetadataSourceForAllSections().count == selectOcId.count { selectOcId = [] diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift index 476ebfdf41..8128aece6f 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift @@ -28,7 +28,7 @@ import NextcloudKit import EasyTipView import JGProgressHUD -class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UISearchResultsUpdating, UISearchControllerDelegate, UISearchBarDelegate, NCListCellDelegate, NCGridCellDelegate, NCSectionHeaderMenuDelegate, NCSectionFooterDelegate, NCSectionHeaderEmptyDataDelegate, NCAccountSettingsModelDelegate, UIAdaptivePresentationControllerDelegate, UIContextMenuInteractionDelegate { +class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UISearchResultsUpdating, UISearchControllerDelegate, UISearchBarDelegate, NCListCellDelegate, NCGridCellDelegate, NCPhotoCellDelegate, NCSectionHeaderMenuDelegate, NCSectionFooterDelegate, NCSectionHeaderEmptyDataDelegate, NCAccountSettingsModelDelegate, UIAdaptivePresentationControllerDelegate, UIContextMenuInteractionDelegate { @IBOutlet weak var collectionView: UICollectionView! @@ -57,6 +57,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS var searchResults: [NKSearchResult]? var listLayout: NCListLayout! var gridLayout: NCGridLayout! + var photoLayout: NCPhotoLayout! var literalSearch: String? var tabBarSelect: NCCollectionViewCommonSelectTabBar! var timerNotificationCenter: Timer? @@ -96,6 +97,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS collectionView.alwaysBounceVertical = true listLayout = NCListLayout() gridLayout = NCGridLayout() + photoLayout = NCPhotoLayout() // Color view.backgroundColor = .systemBackground @@ -116,6 +118,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS // Cell collectionView.register(UINib(nibName: "NCListCell", bundle: nil), forCellWithReuseIdentifier: "listCell") collectionView.register(UINib(nibName: "NCGridCell", bundle: nil), forCellWithReuseIdentifier: "gridCell") + collectionView.register(UINib(nibName: "NCPhotoCell", bundle: nil), forCellWithReuseIdentifier: "photoCell") collectionView.register(UINib(nibName: "NCTransferCell", bundle: nil), forCellWithReuseIdentifier: "transferCell") // Header @@ -168,8 +171,10 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS gridLayout.itemForLine = CGFloat(layoutForView?.itemForLine ?? 3) if layoutForView?.layout == NCGlobal.shared.layoutList { collectionView?.collectionViewLayout = listLayout - } else { + } else if layoutForView?.layout == NCGlobal.shared.layoutGrid { collectionView?.collectionViewLayout = gridLayout + } else if layoutForView?.layout == NCGlobal.shared.layoutPhoto { + collectionView?.collectionViewLayout = photoLayout } // FIXME: iPAD PDF landscape mode iOS 16 @@ -602,7 +607,6 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS if !accounts.isEmpty, !NCBrandOptions.shared.disable_multiaccount { let accountActions: [UIAction] = accounts.map { account in let image = utility.loadUserImage(for: account.user, displayName: account.displayName, userBaseUrl: account) - var name: String = "" var url: String = "" @@ -621,7 +625,6 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS } action.subtitle = url - return action } @@ -680,7 +683,12 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS self.setNavigationRightItems() } - let viewStyleSubmenu = UIMenu(title: "", options: .displayInline, children: [list, grid]) + let photo = UIAction(title: NSLocalizedString("_photo_", comment: ""), image: utility.loadImage(named: "photo"), state: layoutForView.layout == NCGlobal.shared.layoutPhoto ? .on : .off) { _ in + self.onPhotoSelected() + self.setNavigationRightItems() + } + + let viewStyleSubmenu = UIMenu(title: "", options: .displayInline, children: [list, grid, photo]) let ascending = layoutForView.ascending let ascendingChevronImage = utility.loadImage(named: ascending ? "chevron.up" : "chevron.down") @@ -960,8 +968,8 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS // get layout for view layoutForView = NCManageDatabase.shared.getLayoutForView(account: appDelegate.account, key: layoutKey, serverUrl: serverUrl) - // set GroupField for Grid - if !isSearchingMode && layoutForView?.layout == NCGlobal.shared.layoutGrid { + // set GroupField for Grid / Photo + if !isSearchingMode && (layoutForView?.layout == NCGlobal.shared.layoutGrid || layoutForView?.layout == NCGlobal.shared.layoutPhoto) { groupByField = "classFile" } else { groupByField = "name" @@ -1039,7 +1047,6 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS } func unifiedSearchMore(metadataForSection: NCMetadataForSection?) { - guard let metadataForSection = metadataForSection, let lastSearchResult = metadataForSection.lastSearchResult, let cursor = lastSearchResult.cursor, let term = literalSearch else { return } metadataForSection.unifiedSearchInProgress = true @@ -1087,7 +1094,6 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS // MARK: - E2EE extension NCCollectionViewCommon: NCEndToEndInitializeDelegate { - func endToEndInitializeSuccess(metadata: tableMetadata?) { if let metadata { pushMetadata(metadata) @@ -1096,7 +1102,6 @@ extension NCCollectionViewCommon: NCEndToEndInitializeDelegate { } extension NCCollectionViewCommon: UICollectionViewDelegateFlowLayout { - func isHeaderMenuTransferViewEnabled() -> Bool { if headerMenuTransferView, let metadata = NCManageDatabase.shared.getMetadataFromOcId(NCNetworking.shared.transferInForegorund?.ocId), metadata.isTransferInForeground { return true @@ -1114,7 +1119,6 @@ extension NCCollectionViewCommon: UICollectionViewDelegateFlowLayout { } else { NCNetworking.shared.transferInForegorund = nil } - return size } @@ -1128,7 +1132,7 @@ extension NCCollectionViewCommon: UICollectionViewDelegateFlowLayout { } } - if isSearchingMode || layoutForView?.layout == NCGlobal.shared.layoutGrid || dataSource.numberOfSections() > 1 { + if isSearchingMode || layoutForView?.layout == NCGlobal.shared.layoutGrid || layoutForView?.layout == NCGlobal.shared.layoutPhoto || dataSource.numberOfSections() > 1 { if section == 0 { return (getHeaderHeight(), headerRichWorkspace, NCGlobal.shared.heightSection) } else { @@ -1168,7 +1172,6 @@ extension NCCollectionViewCommon: UICollectionViewDelegateFlowLayout { if isSearchingMode && isPaginated && metadatasCount > 0 { size.height += NCGlobal.shared.heightFooterButton } - return size } } @@ -1218,9 +1221,7 @@ extension NCCollectionViewCommon: EasyTipViewDelegate { } extension NCCollectionViewCommon { - func getAvatarFromIconUrl(metadata: tableMetadata) -> String? { - var ownerId: String? if metadata.iconUrl.contains("http") && metadata.iconUrl.contains("avatar") { let splitIconUrl = metadata.iconUrl.components(separatedBy: "/") diff --git a/iOSClient/NCGlobal.swift b/iOSClient/NCGlobal.swift index c9e20b7641..c587ebbc1c 100644 --- a/iOSClient/NCGlobal.swift +++ b/iOSClient/NCGlobal.swift @@ -167,6 +167,7 @@ class NCGlobal: NSObject { // let layoutList = "typeLayoutList" let layoutGrid = "typeLayoutGrid" + let layoutPhoto = "typeLayoutPhoto" let layoutViewTrash = "LayoutTrash" let layoutViewOffline = "LayoutOffline" From 7d2890083cc92fb588143b77df15917b9177bbca Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Sat, 13 Jul 2024 15:09:44 +0200 Subject: [PATCH 03/27] coding Signed-off-by: Marino Faggiana --- .../Collection Common/Cell/NCPhotoCell.swift | 37 ++++--------------- .../Collection Common/Cell/NCPhotoCell.xib | 16 ++++++-- ...nViewCommon+CollectionViewDataSource.swift | 29 ++++++++++----- 3 files changed, 40 insertions(+), 42 deletions(-) diff --git a/iOSClient/Main/Collection Common/Cell/NCPhotoCell.swift b/iOSClient/Main/Collection Common/Cell/NCPhotoCell.swift index 4fbee6fba3..b07a8182ee 100644 --- a/iOSClient/Main/Collection Common/Cell/NCPhotoCell.swift +++ b/iOSClient/Main/Collection Common/Cell/NCPhotoCell.swift @@ -29,6 +29,7 @@ class NCPhotoCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProt @IBOutlet weak var imageSelect: UIImageView! @IBOutlet weak var imageStatus: UIImageView! @IBOutlet weak var imageVisualEffect: UIVisualEffectView! + @IBOutlet weak var labelTitle: UILabel! var objectId = "" var indexPath = IndexPath() @@ -49,16 +50,14 @@ class NCPhotoCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProt get { return user } set { user = newValue ?? "" } } - var fileTitleLabel: UILabel? { - get { return nil } - set { } + get { return labelTitle } + set { labelTitle = newValue } } var fileInfoLabel: UILabel? { get { return nil } set { } } - var fileSubinfoLabel: UILabel? { get { return nil } set { } @@ -89,9 +88,6 @@ class NCPhotoCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProt accessibilityValue = nil isAccessibilityElement = true - imageItem.layer.cornerRadius = 6 - imageItem.layer.masksToBounds = true - imageVisualEffect.layer.cornerRadius = 6 imageVisualEffect.clipsToBounds = true imageVisualEffect.alpha = 0.5 @@ -182,10 +178,8 @@ extension NCPhotoCellDelegate { class NCPhotoLayout: UICollectionViewFlowLayout { - var heightLabelPlusButton: CGFloat = 60 - var marginLeftRight: CGFloat = 10 + var marginLeftRight: CGFloat = 2 var itemForLine: CGFloat = 3 - var itemWidthDefault: CGFloat = 140 // MARK: - View Life Cycle @@ -193,12 +187,10 @@ class NCPhotoLayout: UICollectionViewFlowLayout { super.init() sectionHeadersPinToVisibleBounds = false - - minimumInteritemSpacing = 1 + minimumInteritemSpacing = 0 minimumLineSpacing = marginLeftRight - self.scrollDirection = .vertical - self.sectionInset = UIEdgeInsets(top: 10, left: marginLeftRight, bottom: 0, right: marginLeftRight) + self.sectionInset = UIEdgeInsets(top: 0, left: marginLeftRight, bottom: 0, right: marginLeftRight) } required init?(coder aDecoder: NSCoder) { @@ -208,28 +200,15 @@ class NCPhotoLayout: UICollectionViewFlowLayout { override var itemSize: CGSize { get { if let collectionView = collectionView { - - if collectionView.frame.width < 400 { - itemForLine = 3 - } else { - itemForLine = collectionView.frame.width / itemWidthDefault - } - let itemWidth: CGFloat = (collectionView.frame.width - marginLeftRight * 2 - marginLeftRight * (itemForLine - 1)) / itemForLine - let itemHeight: CGFloat = itemWidth + heightLabelPlusButton - + let itemHeight: CGFloat = itemWidth return CGSize(width: itemWidth, height: itemHeight) } - // Default fallback - return CGSize(width: itemWidthDefault, height: itemWidthDefault) + return CGSize(width: 100, height: 100) } set { super.itemSize = newValue } } - - override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint) -> CGPoint { - return proposedContentOffset - } } diff --git a/iOSClient/Main/Collection Common/Cell/NCPhotoCell.xib b/iOSClient/Main/Collection Common/Cell/NCPhotoCell.xib index 21ee4f8534..90e9ef6097 100644 --- a/iOSClient/Main/Collection Common/Cell/NCPhotoCell.xib +++ b/iOSClient/Main/Collection Common/Cell/NCPhotoCell.xib @@ -16,7 +16,7 @@ - + @@ -41,12 +41,21 @@ + + + + @@ -63,10 +72,10 @@ - - + + @@ -74,6 +83,7 @@ + diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift index d28b61f4f7..f108f2480f 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift @@ -49,7 +49,7 @@ extension NCCollectionViewCommon: UICollectionViewDataSource { } /// CONTENT MODE cell.filePreviewImageView?.layer.borderWidth = 0 - if existsIcon { + if existsIcon || layoutForView?.layout == NCGlobal.shared.layoutPhoto { cell.filePreviewImageView?.contentMode = .scaleAspectFill } else { cell.filePreviewImageView?.contentMode = .scaleAspectFit @@ -133,21 +133,21 @@ extension NCCollectionViewCommon: UICollectionViewDataSource { var isMounted = false var a11yValues: [String] = [] - // LAYOUT LIST - if layoutForView?.layout == NCGlobal.shared.layoutList { - guard let listCell = collectionView.dequeueReusableCell(withReuseIdentifier: "listCell", for: indexPath) as? NCListCell else { return NCListCell() } - listCell.listCellDelegate = self - cell = listCell + // LAYOUT PHOTO + if layoutForView?.layout == NCGlobal.shared.layoutPhoto { + guard let photoCell = collectionView.dequeueReusableCell(withReuseIdentifier: "photoCell", for: indexPath) as? NCPhotoCell else { return NCPhotoCell() } + photoCell.photoCellDelegate = self + cell = photoCell } else if layoutForView?.layout == NCGlobal.shared.layoutGrid { // LAYOUT GRID guard let gridCell = collectionView.dequeueReusableCell(withReuseIdentifier: "gridCell", for: indexPath) as? NCGridCell else { return NCGridCell() } gridCell.gridCellDelegate = self cell = gridCell } else { - // LAYOUT PHOTO - guard let photoCell = collectionView.dequeueReusableCell(withReuseIdentifier: "photoCell", for: indexPath) as? NCPhotoCell else { return NCPhotoCell() } - photoCell.photoCellDelegate = self - cell = photoCell + // LAYOUT LIST + guard let listCell = collectionView.dequeueReusableCell(withReuseIdentifier: "listCell", for: indexPath) as? NCListCell else { return NCListCell() } + listCell.listCellDelegate = self + cell = listCell } guard let metadata = dataSource.cellForItemAt(indexPath: indexPath) else { return cell } @@ -351,6 +351,15 @@ extension NCCollectionViewCommon: UICollectionViewDataSource { cell.fileTitleLabel?.attributedText = attributedString } + // LAYOUT PHOTO + if layoutForView?.layout == NCGlobal.shared.layoutPhoto { + if metadata.isImage || metadata.isVideo { + cell.fileTitleLabel?.text = "" + } else { + cell.fileTitleLabel?.text = metadata.fileName + } + } + // Add TAGS cell.setTags(tags: Array(metadata.tags)) From d12533f43bf27389baccf5dc00b6f561d83c384b Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Sat, 13 Jul 2024 15:25:41 +0200 Subject: [PATCH 04/27] coding Signed-off-by: Marino Faggiana --- .../NCCollectionViewCommon+CollectionViewDataSource.swift | 4 ++-- .../NCCollectionViewCommon+SelectTabBarDelegate.swift | 8 ++------ .../Main/Collection Common/NCCollectionViewCommon.swift | 6 +++--- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift index f108f2480f..06ceecd0d5 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift @@ -49,7 +49,7 @@ extension NCCollectionViewCommon: UICollectionViewDataSource { } /// CONTENT MODE cell.filePreviewImageView?.layer.borderWidth = 0 - if existsIcon || layoutForView?.layout == NCGlobal.shared.layoutPhoto { + if existsIcon { cell.filePreviewImageView?.contentMode = .scaleAspectFill } else { cell.filePreviewImageView?.contentMode = .scaleAspectFit @@ -351,7 +351,7 @@ extension NCCollectionViewCommon: UICollectionViewDataSource { cell.fileTitleLabel?.attributedText = attributedString } - // LAYOUT PHOTO + // Layout photo if layoutForView?.layout == NCGlobal.shared.layoutPhoto { if metadata.isImage || metadata.isVideo { cell.fileTitleLabel?.text = "" diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon+SelectTabBarDelegate.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon+SelectTabBarDelegate.swift index f6da857db9..cf7c1ca9a3 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon+SelectTabBarDelegate.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon+SelectTabBarDelegate.swift @@ -64,18 +64,14 @@ extension NCCollectionViewCommon: NCCollectionViewCommonSelectTabBarDelegate { if layoutForView?.layout != NCGlobal.shared.layoutPhoto { layoutForView?.layout = NCGlobal.shared.layoutPhoto NCManageDatabase.shared.setLayoutForView(account: appDelegate.account, key: layoutKey, serverUrl: serverUrl, layout: layoutForView?.layout) - if isSearchingMode { - self.groupByField = "name" - } else { - self.groupByField = "classFile" - } + self.groupByField = "name" if self.dataSource.groupByField != self.groupByField { self.dataSource.changeGroupByField(self.groupByField) } self.collectionView.reloadData() self.collectionView.collectionViewLayout.invalidateLayout() - self.collectionView.setCollectionViewLayout(self.gridLayout, animated: true) {_ in self.isTransitioning = false } + self.collectionView.setCollectionViewLayout(self.photoLayout, animated: true) {_ in self.isTransitioning = false } } } diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift index 8128aece6f..8e05675aac 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift @@ -968,8 +968,8 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS // get layout for view layoutForView = NCManageDatabase.shared.getLayoutForView(account: appDelegate.account, key: layoutKey, serverUrl: serverUrl) - // set GroupField for Grid / Photo - if !isSearchingMode && (layoutForView?.layout == NCGlobal.shared.layoutGrid || layoutForView?.layout == NCGlobal.shared.layoutPhoto) { + // set GroupField for Grid + if !isSearchingMode && layoutForView?.layout == NCGlobal.shared.layoutGrid { groupByField = "classFile" } else { groupByField = "name" @@ -1132,7 +1132,7 @@ extension NCCollectionViewCommon: UICollectionViewDelegateFlowLayout { } } - if isSearchingMode || layoutForView?.layout == NCGlobal.shared.layoutGrid || layoutForView?.layout == NCGlobal.shared.layoutPhoto || dataSource.numberOfSections() > 1 { + if isSearchingMode || layoutForView?.layout == NCGlobal.shared.layoutGrid || dataSource.numberOfSections() > 1 { if section == 0 { return (getHeaderHeight(), headerRichWorkspace, NCGlobal.shared.heightSection) } else { From 9369cfbf43558a6dc3f02c26400d2a12ba2e3822 Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Sat, 13 Jul 2024 15:43:10 +0200 Subject: [PATCH 05/27] coding Signed-off-by: Marino Faggiana --- .../Collection Common/Cell/NCPhotoCell.xib | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/iOSClient/Main/Collection Common/Cell/NCPhotoCell.xib b/iOSClient/Main/Collection Common/Cell/NCPhotoCell.xib index 90e9ef6097..4002347765 100644 --- a/iOSClient/Main/Collection Common/Cell/NCPhotoCell.xib +++ b/iOSClient/Main/Collection Common/Cell/NCPhotoCell.xib @@ -20,10 +20,10 @@ - + - - + + - + - - + + @@ -51,9 +51,9 @@ - + - + diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift index 06ceecd0d5..67805cf9b8 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift @@ -352,15 +352,11 @@ extension NCCollectionViewCommon: UICollectionViewDataSource { } // Layout photo - if layoutForView?.layout == NCGlobal.shared.layoutPhoto { - if metadata.isImage || metadata.isVideo { - cell.fileTitleLabel?.text = "" - } else { - cell.fileTitleLabel?.text = metadata.fileName - } + if layoutForView?.layout == NCGlobal.shared.layoutPhoto && !metadata.directory { + cell.fileTitleLabel?.text = "" } - // Add TAGS + // TAGS cell.setTags(tags: Array(metadata.tags)) // Hide buttons From feffd8b37826028d31e98ea57d871726ecf7b433 Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Sat, 13 Jul 2024 16:26:14 +0200 Subject: [PATCH 07/27] coding Signed-off-by: Marino Faggiana --- Nextcloud.xcodeproj/project.pbxproj | 10 + .../Collection Common/Cell/NCPhotoCell.swift | 39 --- .../Cell/NCPhotoLayout.swift | 330 ++++++++++++++++++ ...ectionViewCommon+PhotoLayoutDelegate.swift | 42 +++ .../NCCollectionViewCommon.swift | 10 +- iOSClient/Media/NCMedia.swift | 4 +- iOSClient/Media/NCMediaLayout.swift | 4 +- 7 files changed, 389 insertions(+), 50 deletions(-) create mode 100644 iOSClient/Main/Collection Common/Cell/NCPhotoLayout.swift create mode 100644 iOSClient/Main/Collection Common/NCCollectionViewCommon+PhotoLayoutDelegate.swift diff --git a/Nextcloud.xcodeproj/project.pbxproj b/Nextcloud.xcodeproj/project.pbxproj index eaf6903c1d..8ea34ea63b 100644 --- a/Nextcloud.xcodeproj/project.pbxproj +++ b/Nextcloud.xcodeproj/project.pbxproj @@ -600,6 +600,9 @@ F77444F522281649000D5EB0 /* NCGridMediaCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = F77444F322281649000D5EB0 /* NCGridMediaCell.swift */; }; F77444F622281649000D5EB0 /* NCGridMediaCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = F77444F422281649000D5EB0 /* NCGridMediaCell.xib */; }; F77444F8222816D5000D5EB0 /* NCPickerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F77444F7222816D5000D5EB0 /* NCPickerViewController.swift */; }; + F778231B2C42BDEB001BB94F /* NCPhotoLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = F778231A2C42BDEB001BB94F /* NCPhotoLayout.swift */; }; + F778231C2C42BDEB001BB94F /* NCPhotoLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = F778231A2C42BDEB001BB94F /* NCPhotoLayout.swift */; }; + F778231E2C42C07C001BB94F /* NCCollectionViewCommon+PhotoLayoutDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F778231D2C42C07C001BB94F /* NCCollectionViewCommon+PhotoLayoutDelegate.swift */; }; F77A697D250A0FBC00FF1708 /* NCCollectionViewCommon+Menu.swift in Sources */ = {isa = PBXBuildFile; fileRef = F77A697C250A0FBC00FF1708 /* NCCollectionViewCommon+Menu.swift */; }; F77B0F631D118A16002130FE /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = F7E70DE91A24DE4100E1B66A /* Localizable.strings */; }; F77B0F7D1D118A16002130FE /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F7F67BB81A24D27800EE80DA /* Images.xcassets */; }; @@ -1439,6 +1442,8 @@ F77444F322281649000D5EB0 /* NCGridMediaCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCGridMediaCell.swift; sourceTree = ""; }; F77444F422281649000D5EB0 /* NCGridMediaCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NCGridMediaCell.xib; sourceTree = ""; }; F77444F7222816D5000D5EB0 /* NCPickerViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCPickerViewController.swift; sourceTree = ""; }; + F778231A2C42BDEB001BB94F /* NCPhotoLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCPhotoLayout.swift; sourceTree = ""; }; + F778231D2C42C07C001BB94F /* NCCollectionViewCommon+PhotoLayoutDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCCollectionViewCommon+PhotoLayoutDelegate.swift"; sourceTree = ""; }; F7792DE429EEE02D005930CE /* MobileVLCKit.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = MobileVLCKit.xcframework; path = Carthage/Build/MobileVLCKit.xcframework; sourceTree = ""; }; F77A697C250A0FBC00FF1708 /* NCCollectionViewCommon+Menu.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NCCollectionViewCommon+Menu.swift"; sourceTree = ""; }; F77BB745289984CA0090FC19 /* UIViewController+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIViewController+Extension.swift"; sourceTree = ""; }; @@ -2263,6 +2268,7 @@ isa = PBXGroup; children = ( 370D26AE248A3D7A00121797 /* NCCellProtocol.swift */, + F778231A2C42BDEB001BB94F /* NCPhotoLayout.swift */, F751247A2C42919C00E63DB8 /* NCPhotoCell.swift */, F751247B2C42919C00E63DB8 /* NCPhotoCell.xib */, F78ACD3F21903CC20088454D /* NCGridCell.swift */, @@ -2281,6 +2287,7 @@ F70D7C3525FFBF81002B9E34 /* NCCollectionViewCommon.swift */, F7743A132C33F13A0034F670 /* NCCollectionViewCommon+CollectionViewDataSource.swift */, F7743A112C33F0A20034F670 /* NCCollectionViewCommon+CollectionViewDelegate.swift */, + F778231D2C42C07C001BB94F /* NCCollectionViewCommon+PhotoLayoutDelegate.swift */, F7D890742BD25C570050B8A6 /* NCCollectionViewCommon+DragDrop.swift */, F36E64F62B9245210085ABB5 /* NCCollectionViewCommon+SelectTabBarDelegate.swift */, F38F71242B6BBDC300473CDC /* NCCollectionViewCommonSelectTabBar.swift */, @@ -3945,6 +3952,7 @@ F7BF9D852934CA21009EE9A6 /* NCManageDatabase+LayoutForView.swift in Sources */, F79EC78926316AC4004E59D6 /* NCPopupViewController.swift in Sources */, F7C30DFB291BCF790017149B /* NCNetworkingE2EECreateFolder.swift in Sources */, + F778231C2C42BDEB001BB94F /* NCPhotoLayout.swift in Sources */, F73EF7DA2B0226080087E6E9 /* NCManageDatabase+Tip.swift in Sources */, F7817CFB29801A3500FFBC65 /* Data+Extension.swift in Sources */, F72429362AFE39860040AEF3 /* NCLivePhoto.swift in Sources */, @@ -4322,6 +4330,7 @@ F75DD765290ABB25002EB562 /* Intent.intentdefinition in Sources */, F74B6D952A7E239A00F03C5F /* NCManageDatabase+Chunk.swift in Sources */, F310B1EF2BA862F1001C42F5 /* NCViewerMedia+VisionKit.swift in Sources */, + F778231B2C42BDEB001BB94F /* NCPhotoLayout.swift in Sources */, F702F2F725EE5CED008F8E80 /* NCLogin.swift in Sources */, F7EB9B132BBC12F300EDF036 /* UIApplication+Extension.swift in Sources */, F7E98C1627E0D0FC001F9F19 /* NCManageDatabase+Video.swift in Sources */, @@ -4330,6 +4339,7 @@ AF93471A27E2361E002537EE /* NCShareHeader.swift in Sources */, F7F878AE1FB9E3B900599E4F /* NCEndToEndMetadata.swift in Sources */, F7A7FDDD2C2DBD6200E9A93A /* NCDeepLinkHandler.swift in Sources */, + F778231E2C42C07C001BB94F /* NCCollectionViewCommon+PhotoLayoutDelegate.swift in Sources */, 3781B9B023DB2B7E006B4B1D /* AppDelegate+Menu.swift in Sources */, F710D1F52405770F00A6033D /* NCViewerPDF.swift in Sources */, F7B6B70427C4E7FA00A7F6EB /* NCScan+CollectionView.swift in Sources */, diff --git a/iOSClient/Main/Collection Common/Cell/NCPhotoCell.swift b/iOSClient/Main/Collection Common/Cell/NCPhotoCell.swift index b07a8182ee..21dda909e8 100644 --- a/iOSClient/Main/Collection Common/Cell/NCPhotoCell.swift +++ b/iOSClient/Main/Collection Common/Cell/NCPhotoCell.swift @@ -173,42 +173,3 @@ extension NCPhotoCellDelegate { func longPressMoreGridItem(with objectId: String, namedButtonMore: String, indexPath: IndexPath, gestureRecognizer: UILongPressGestureRecognizer) {} func longPressGridItem(with objectId: String, indexPath: IndexPath, gestureRecognizer: UILongPressGestureRecognizer) {} } - -// MARK: - Photo Layout - -class NCPhotoLayout: UICollectionViewFlowLayout { - - var marginLeftRight: CGFloat = 2 - var itemForLine: CGFloat = 3 - - // MARK: - View Life Cycle - - override init() { - super.init() - - sectionHeadersPinToVisibleBounds = false - minimumInteritemSpacing = 0 - minimumLineSpacing = marginLeftRight - self.scrollDirection = .vertical - self.sectionInset = UIEdgeInsets(top: 0, left: marginLeftRight, bottom: 0, right: marginLeftRight) - } - - required init?(coder aDecoder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - override var itemSize: CGSize { - get { - if let collectionView = collectionView { - let itemWidth: CGFloat = (collectionView.frame.width - marginLeftRight * 2 - marginLeftRight * (itemForLine - 1)) / itemForLine - let itemHeight: CGFloat = itemWidth - return CGSize(width: itemWidth, height: itemHeight) - } - // Default fallback - return CGSize(width: 100, height: 100) - } - set { - super.itemSize = newValue - } - } -} diff --git a/iOSClient/Main/Collection Common/Cell/NCPhotoLayout.swift b/iOSClient/Main/Collection Common/Cell/NCPhotoLayout.swift new file mode 100644 index 0000000000..0a4af288de --- /dev/null +++ b/iOSClient/Main/Collection Common/Cell/NCPhotoLayout.swift @@ -0,0 +1,330 @@ +// +// NCPhotoLayout.swift +// +// Created by Marino Faggiana on 26/02/24. +// Based on CHTCollectionViewWaterfallLayout by Nelson Tai +// Copyright © 2024 Marino Faggiana. All rights reserved. +// +// 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 . +// + +import UIKit + +public let collectionViewPhotoElementKindSectionHeader = "collectionViewPhotoElementKindSectionHeader" +public let collectionViewPhotoElementKindSectionFooter = "collectionViewPhotoElementKindSectionFooter" + +protocol NCPhotoLayoutDelegate: UICollectionViewDelegate { + func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath, columnCount: Int, typeLayout: String) -> CGSize + func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, heightForHeaderInSection section: Int) -> Float + func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, heightForFooterInSection section: Int) -> Float + func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, insetForSection section: Int) -> UIEdgeInsets + func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, insetForHeaderInSection section: Int) -> UIEdgeInsets + func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, insetForFooterInSection section: Int) -> UIEdgeInsets + func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, minimumInteritemSpacingForSection section: Int) -> Float +} + +public class NCPhotoLayout: UICollectionViewLayout { + + // MARK: - Private constants + /// How many items to be union into a single rectangle + private let unionSize = 20 + + // MARK: - Public Properties + public var columnCount: Int = 0 { + didSet { + invalidateIfNotEqual(oldValue, newValue: columnCount) + } + } + public var minimumColumnSpacing: Float = 2.0 { + didSet { + invalidateIfNotEqual(oldValue, newValue: minimumColumnSpacing) + } + } + public var minimumInteritemSpacing: Float = 2.0 { + didSet { + invalidateIfNotEqual(oldValue, newValue: minimumInteritemSpacing) + } + } + public var headerHeight: Float = 0.0 { + didSet { + invalidateIfNotEqual(oldValue, newValue: headerHeight) + } + } + public var footerHeight: Float = 0.0 { + didSet { + invalidateIfNotEqual(oldValue, newValue: footerHeight) + } + } + public var headerInset: UIEdgeInsets = .zero { + didSet { + invalidateIfNotEqual(oldValue, newValue: headerInset) + } + } + public var footerInset: UIEdgeInsets = .zero { + didSet { + invalidateIfNotEqual(oldValue, newValue: footerInset) + } + } + public var sectionInset: UIEdgeInsets = .zero { + didSet { + invalidateIfNotEqual(oldValue, newValue: sectionInset) + } + } + var photoLayout = "" + + public override var collectionViewContentSize: CGSize { + let numberOfSections = collectionView?.numberOfSections + if numberOfSections == 0 { + return CGSize.zero + } + + var contentSize = collectionView?.bounds.size + contentSize?.height = CGFloat(columnHeights[0]) + + return contentSize! + } + + // MARK: - Private Properties + private weak var delegate: NCPhotoLayoutDelegate? { + return collectionView?.delegate as? NCPhotoLayoutDelegate + } + private var columnHeights = [Float]() + private var sectionItemAttributes = [[UICollectionViewLayoutAttributes]]() + private var allItemAttributes = [UICollectionViewLayoutAttributes]() + private var headersAttribute = [Int: UICollectionViewLayoutAttributes]() + private var footersAttribute = [Int: UICollectionViewLayoutAttributes]() + private var unionRects = [CGRect]() + + // MARK: - UICollectionViewLayout Methods + public override func prepare() { + super.prepare() + + guard let numberOfSections = collectionView?.numberOfSections, + let collectionView = collectionView, + let delegate = delegate else { return } + + //mediaLayout = NCKeychain().mediaTypeLayout + columnCount = NCKeychain().mediaColumnCount + //mediaViewController?.buildMediaPhotoVideo(columnCount: columnCount) + if UIDevice.current.userInterfaceIdiom == .phone, + (UIDevice.current.orientation == .landscapeLeft || UIDevice.current.orientation == .landscapeRight) { + columnCount += 2 + } + + // Initialize variables + headersAttribute.removeAll(keepingCapacity: false) + footersAttribute.removeAll(keepingCapacity: false) + unionRects.removeAll(keepingCapacity: false) + columnHeights.removeAll(keepingCapacity: false) + allItemAttributes.removeAll(keepingCapacity: false) + sectionItemAttributes.removeAll(keepingCapacity: false) + + for _ in 0.. 0 { + attributes = UICollectionViewLayoutAttributes(forSupplementaryViewOfKind: collectionViewPhotoElementKindSectionHeader, with: NSIndexPath(item: 0, section: section) as IndexPath) + attributes.frame = CGRect(x: headerInset.left, y: CGFloat(top), width: collectionView.frame.size.width - (headerInset.left + headerInset.right), height: CGFloat(headerHeight)) + + headersAttribute[section] = attributes + allItemAttributes.append(attributes) + + top = Float(attributes.frame.maxY) + Float(headerInset.bottom) + } + + top += Float(sectionInset.top) + for idx in 0.. 0 && itemSize.width > 0 { + itemHeight = Float(itemSize.height) * itemWidth / Float(itemSize.width) + } + + attributes = UICollectionViewLayoutAttributes(forCellWith: indexPath as IndexPath) + attributes.frame = CGRect(x: CGFloat(xOffset), y: CGFloat(yOffset), width: CGFloat(itemWidth), height: CGFloat(itemHeight)) + itemAttributes.append(attributes) + allItemAttributes.append(attributes) + columnHeights[columnIndex] = Float(attributes.frame.maxY) + minimumInteritemSpacing + } + + sectionItemAttributes.append(itemAttributes) + + /* + * 4. Section footer + */ + let columnIndex = longestColumnIndex() + top = columnHeights[columnIndex] - minimumInteritemSpacing + Float(sectionInset.bottom) + top += Float(footerInset.top) + + if footerHeight > 0 { + attributes = UICollectionViewLayoutAttributes(forSupplementaryViewOfKind: collectionViewPhotoElementKindSectionFooter, with: NSIndexPath(item: 0, section: section) as IndexPath) + attributes.frame = CGRect(x: footerInset.left, y: CGFloat(top), width: collectionView.frame.size.width - (footerInset.left + footerInset.right), height: CGFloat(footerHeight)) + + footersAttribute[section] = attributes + allItemAttributes.append(attributes) + + top = Float(attributes.frame.maxY) + Float(footerInset.bottom) + } + + for idx in 0.. UICollectionViewLayoutAttributes? { + if indexPath.section >= sectionItemAttributes.count { + return nil + } + + if indexPath.item >= sectionItemAttributes[indexPath.section].count { + return nil + } + + return sectionItemAttributes[indexPath.section][indexPath.item] + } + + public override func layoutAttributesForSupplementaryView(ofKind elementKind: String, at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? { + var attribute: UICollectionViewLayoutAttributes? + + if elementKind == collectionViewPhotoElementKindSectionHeader { + attribute = headersAttribute[indexPath.section] + } else if elementKind == collectionViewPhotoElementKindSectionFooter { + attribute = footersAttribute[indexPath.section] + } + + return attribute + } + + public override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { + var begin: Int = 0 + var end: Int = unionRects.count + var attrs = [UICollectionViewLayoutAttributes]() + + for i in 0.. Bool { + let oldBounds = collectionView?.bounds + if newBounds.width != oldBounds?.width { + return true + } + + return false + } +} + +// MARK: - Private Methods +private extension NCPhotoLayout { + func shortestColumnIndex() -> Int { + var index: Int = 0 + var shortestHeight = MAXFLOAT + + for (idx, height) in columnHeights.enumerated() { + if height < shortestHeight { + shortestHeight = height + index = idx + } + } + + return index + } + + func longestColumnIndex() -> Int { + var index: Int = 0 + var longestHeight: Float = 0 + for (idx, height) in columnHeights.enumerated() { + if height > longestHeight { + longestHeight = height + index = idx + } + } + return index + } + + func invalidateIfNotEqual(_ oldValue: T, newValue: T) { + if oldValue != newValue { + invalidateLayout() + } + } +} diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon+PhotoLayoutDelegate.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon+PhotoLayoutDelegate.swift new file mode 100644 index 0000000000..6b62a87900 --- /dev/null +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon+PhotoLayoutDelegate.swift @@ -0,0 +1,42 @@ +// +// File.swift +// Nextcloud +// +// Created by Marino Faggiana on 13/07/24. +// Copyright © 2024 Marino Faggiana. All rights reserved. +// + +import Foundation +import UIKit +import NextcloudKit + +extension NCCollectionViewCommon: NCPhotoLayoutDelegate { + func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, heightForHeaderInSection section: Int) -> Float { + return .zero + } + + func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, heightForFooterInSection section: Int) -> Float { + return .zero + } + + func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, insetForSection section: Int) -> UIEdgeInsets { + return .zero + } + + func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, insetForHeaderInSection section: Int) -> UIEdgeInsets { + return .zero + } + + func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, insetForFooterInSection section: Int) -> UIEdgeInsets { + return .zero + } + + func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, minimumInteritemSpacingForSection section: Int) -> Float { + return .zero + } + + func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath, columnCount: Int, typeLayout: String) -> CGSize { + let size = CGSize(width: collectionView.frame.width / CGFloat(columnCount), height: collectionView.frame.width / CGFloat(columnCount)) + return size + } +} diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift index 8e05675aac..d8aa53e233 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift @@ -55,9 +55,9 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS var groupByField = "name" var providers: [NKSearchProvider]? var searchResults: [NKSearchResult]? - var listLayout: NCListLayout! - var gridLayout: NCGridLayout! - var photoLayout: NCPhotoLayout! + var listLayout = NCListLayout() + var gridLayout = NCGridLayout() + var photoLayout = NCPhotoLayout() var literalSearch: String? var tabBarSelect: NCCollectionViewCommonSelectTabBar! var timerNotificationCenter: Timer? @@ -93,11 +93,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS tabBarSelect = NCCollectionViewCommonSelectTabBar(controller: tabBarController as? NCMainTabBarController, delegate: self) self.navigationController?.presentationController?.delegate = self - // CollectionView & layout collectionView.alwaysBounceVertical = true - listLayout = NCListLayout() - gridLayout = NCGridLayout() - photoLayout = NCPhotoLayout() // Color view.backgroundColor = .systemBackground diff --git a/iOSClient/Media/NCMedia.swift b/iOSClient/Media/NCMedia.swift index 2d8169bc80..d9fbd8b36a 100644 --- a/iOSClient/Media/NCMedia.swift +++ b/iOSClient/Media/NCMedia.swift @@ -511,9 +511,9 @@ extension NCMedia: NCMediaLayoutDelegate { return .zero } - func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath, columnCount: Int, mediaLayout: String) -> CGSize { + func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath, columnCount: Int, typeLayout: String) -> CGSize { let size = CGSize(width: collectionView.frame.width / CGFloat(columnCount), height: collectionView.frame.width / CGFloat(columnCount)) - if mediaLayout == NCGlobal.shared.mediaLayoutRatio { + if typeLayout == NCGlobal.shared.mediaLayoutRatio { guard let metadatas = self.metadatas, let metadata = metadatas[indexPath.row] else { return size } diff --git a/iOSClient/Media/NCMediaLayout.swift b/iOSClient/Media/NCMediaLayout.swift index c7aa6243ff..70b7c272e0 100644 --- a/iOSClient/Media/NCMediaLayout.swift +++ b/iOSClient/Media/NCMediaLayout.swift @@ -25,7 +25,7 @@ public let collectionViewMediaElementKindSectionHeader = "collectionViewMediaEle public let collectionViewMediaElementKindSectionFooter = "collectionViewMediaElementKindSectionFooter" protocol NCMediaLayoutDelegate: UICollectionViewDelegate { - func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath, columnCount: Int, mediaLayout: String) -> CGSize + func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath, columnCount: Int, typeLayout: String) -> CGSize func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, heightForHeaderInSection section: Int) -> Float func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, heightForFooterInSection section: Int) -> Float func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, insetForSection section: Int) -> UIEdgeInsets @@ -184,7 +184,7 @@ public class NCMediaLayout: UICollectionViewLayout { let xOffset = Float(sectionInset.left) + Float(itemWidth + minimumColumnSpacing) * Float(columnIndex) let yOffset = columnHeights[columnIndex] - let itemSize = delegate.collectionView(collectionView, layout: self, sizeForItemAtIndexPath: indexPath, columnCount: self.columnCount, mediaLayout: self.mediaLayout) + let itemSize = delegate.collectionView(collectionView, layout: self, sizeForItemAtIndexPath: indexPath, columnCount: self.columnCount, typeLayout: self.mediaLayout) var itemHeight: Float = 0.0 if itemSize.height > 0 && itemSize.width > 0 { itemHeight = Float(itemSize.height) * itemWidth / Float(itemSize.width) From d1ceb9238d068723a5ceb73c3cdd415dba86b7ae Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Sun, 14 Jul 2024 11:09:09 +0200 Subject: [PATCH 08/27] coding Signed-off-by: Marino Faggiana --- Nextcloud.xcodeproj/project.pbxproj | 6 ------ iOSClient/Files/NCFiles.swift | 2 +- .../Cell/NCPhotoLayout.swift | 14 ++++++++----- ...nViewCommon+CollectionViewDataSource.swift | 5 +++-- ...ectionViewCommon+PhotoLayoutDelegate.swift | 11 +++++++++- ...ctionViewCommon+SelectTabBarDelegate.swift | 6 +++--- .../NCCollectionViewCommon.swift | 20 ++++++++++++------- iOSClient/Media/NCMedia.swift | 2 +- iOSClient/Media/NCMediaLayout.swift | 4 ++-- iOSClient/NCGlobal.swift | 3 ++- 10 files changed, 44 insertions(+), 29 deletions(-) diff --git a/Nextcloud.xcodeproj/project.pbxproj b/Nextcloud.xcodeproj/project.pbxproj index 8ea34ea63b..0d91211deb 100644 --- a/Nextcloud.xcodeproj/project.pbxproj +++ b/Nextcloud.xcodeproj/project.pbxproj @@ -468,9 +468,7 @@ F7501C322212E57500FB1415 /* NCMedia.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F7501C302212E57400FB1415 /* NCMedia.storyboard */; }; F7501C332212E57500FB1415 /* NCMedia.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7501C312212E57400FB1415 /* NCMedia.swift */; }; F751247C2C42919C00E63DB8 /* NCPhotoCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = F751247A2C42919C00E63DB8 /* NCPhotoCell.swift */; }; - F751247D2C42919C00E63DB8 /* NCPhotoCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = F751247A2C42919C00E63DB8 /* NCPhotoCell.swift */; }; F751247E2C42919C00E63DB8 /* NCPhotoCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = F751247B2C42919C00E63DB8 /* NCPhotoCell.xib */; }; - F751247F2C42919C00E63DB8 /* NCPhotoCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = F751247B2C42919C00E63DB8 /* NCPhotoCell.xib */; }; F75379202AE2AD9400C0250E /* JGProgressHUD in Frameworks */ = {isa = PBXBuildFile; productRef = F753791F2AE2AD9400C0250E /* JGProgressHUD */; }; F75379222AE2ADA100C0250E /* JGProgressHUD in Frameworks */ = {isa = PBXBuildFile; productRef = F75379212AE2ADA100C0250E /* JGProgressHUD */; }; F753BA93281FD8020015BFB6 /* EasyTipView in Frameworks */ = {isa = PBXBuildFile; productRef = F753BA92281FD8020015BFB6 /* EasyTipView */; }; @@ -601,7 +599,6 @@ F77444F622281649000D5EB0 /* NCGridMediaCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = F77444F422281649000D5EB0 /* NCGridMediaCell.xib */; }; F77444F8222816D5000D5EB0 /* NCPickerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F77444F7222816D5000D5EB0 /* NCPickerViewController.swift */; }; F778231B2C42BDEB001BB94F /* NCPhotoLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = F778231A2C42BDEB001BB94F /* NCPhotoLayout.swift */; }; - F778231C2C42BDEB001BB94F /* NCPhotoLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = F778231A2C42BDEB001BB94F /* NCPhotoLayout.swift */; }; F778231E2C42C07C001BB94F /* NCCollectionViewCommon+PhotoLayoutDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F778231D2C42C07C001BB94F /* NCCollectionViewCommon+PhotoLayoutDelegate.swift */; }; F77A697D250A0FBC00FF1708 /* NCCollectionViewCommon+Menu.swift in Sources */ = {isa = PBXBuildFile; fileRef = F77A697C250A0FBC00FF1708 /* NCCollectionViewCommon+Menu.swift */; }; F77B0F631D118A16002130FE /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = F7E70DE91A24DE4100E1B66A /* Localizable.strings */; }; @@ -3650,7 +3647,6 @@ F7145A231D12E3B700CAFEEC /* Localizable.strings in Resources */, F746EC51273906C40052598D /* NCViewCertificateDetails.storyboard in Resources */, F76C26A62850D3A500E42BDF /* Images.xcassets in Resources */, - F751247F2C42919C00E63DB8 /* NCPhotoCell.xib in Resources */, F79EC784263161BA004E59D6 /* NCRenameFile.storyboard in Resources */, F714804F262ED4F900693E51 /* NCGridCell.xib in Resources */, F714805E262ED52900693E51 /* NCSectionFooter.xib in Resources */, @@ -3952,7 +3948,6 @@ F7BF9D852934CA21009EE9A6 /* NCManageDatabase+LayoutForView.swift in Sources */, F79EC78926316AC4004E59D6 /* NCPopupViewController.swift in Sources */, F7C30DFB291BCF790017149B /* NCNetworkingE2EECreateFolder.swift in Sources */, - F778231C2C42BDEB001BB94F /* NCPhotoLayout.swift in Sources */, F73EF7DA2B0226080087E6E9 /* NCManageDatabase+Tip.swift in Sources */, F7817CFB29801A3500FFBC65 /* Data+Extension.swift in Sources */, F72429362AFE39860040AEF3 /* NCLivePhoto.swift in Sources */, @@ -4008,7 +4003,6 @@ F7327E232B73A42F00A462C7 /* NCNetworking+Download.swift in Sources */, F749B64D297B0CBB00087535 /* NCManageDatabase+Share.swift in Sources */, F72FD3B8297ED49A00075D28 /* NCManageDatabase+E2EE.swift in Sources */, - F751247D2C42919C00E63DB8 /* NCPhotoCell.swift in Sources */, F7EDE4E0262D7BAF00414FE6 /* NCGridCell.swift in Sources */, F7A76DC8256A71CD00119AB3 /* UIImage+Extension.swift in Sources */, F711A4E52AF9310500095DD8 /* NCUtility+Image.swift in Sources */, diff --git a/iOSClient/Files/NCFiles.swift b/iOSClient/Files/NCFiles.swift index e6d21be110..ba769e4a38 100644 --- a/iOSClient/Files/NCFiles.swift +++ b/iOSClient/Files/NCFiles.swift @@ -63,7 +63,7 @@ class NCFiles: NCCollectionViewCommon { self.collectionView?.collectionViewLayout = self.listLayout } else if self.layoutForView?.layout == NCGlobal.shared.layoutGrid { self.collectionView?.collectionViewLayout = self.gridLayout - } else if self.layoutForView?.layout == NCGlobal.shared.layoutPhoto { + } else if (self.layoutForView?.layout == NCGlobal.shared.layoutPhotoSquare || self.layoutForView?.layout == NCGlobal.shared.layoutPhotoRatio) { self.collectionView?.collectionViewLayout = self.photoLayout } diff --git a/iOSClient/Main/Collection Common/Cell/NCPhotoLayout.swift b/iOSClient/Main/Collection Common/Cell/NCPhotoLayout.swift index 0a4af288de..451372861f 100644 --- a/iOSClient/Main/Collection Common/Cell/NCPhotoLayout.swift +++ b/iOSClient/Main/Collection Common/Cell/NCPhotoLayout.swift @@ -82,6 +82,7 @@ public class NCPhotoLayout: UICollectionViewLayout { } } var photoLayout = "" + var viewController: NCCollectionViewCommon? public override var collectionViewContentSize: CGSize { let numberOfSections = collectionView?.numberOfSections @@ -110,13 +111,16 @@ public class NCPhotoLayout: UICollectionViewLayout { public override func prepare() { super.prepare() - guard let numberOfSections = collectionView?.numberOfSections, + guard let appDelegate = (UIApplication.shared.delegate as? AppDelegate), + let numberOfSections = collectionView?.numberOfSections, let collectionView = collectionView, - let delegate = delegate else { return } + let delegate = delegate, + let serverUrl = viewController?.serverUrl, + let layoutForView = NCManageDatabase.shared.getLayoutForView(account: appDelegate.account, key: NCGlobal.shared.layoutViewFiles, serverUrl: serverUrl) + else { return } - //mediaLayout = NCKeychain().mediaTypeLayout - columnCount = NCKeychain().mediaColumnCount - //mediaViewController?.buildMediaPhotoVideo(columnCount: columnCount) + photoLayout = layoutForView.layout + columnCount = 3 // NCKeychain().mediaColumnCount if UIDevice.current.userInterfaceIdiom == .phone, (UIDevice.current.orientation == .landscapeLeft || UIDevice.current.orientation == .landscapeRight) { columnCount += 2 diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift index 67805cf9b8..8f38ecbfdc 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift @@ -134,7 +134,7 @@ extension NCCollectionViewCommon: UICollectionViewDataSource { var a11yValues: [String] = [] // LAYOUT PHOTO - if layoutForView?.layout == NCGlobal.shared.layoutPhoto { + if layoutForView?.layout == NCGlobal.shared.layoutPhotoRatio || layoutForView?.layout == NCGlobal.shared.layoutPhotoSquare { guard let photoCell = collectionView.dequeueReusableCell(withReuseIdentifier: "photoCell", for: indexPath) as? NCPhotoCell else { return NCPhotoCell() } photoCell.photoCellDelegate = self cell = photoCell @@ -352,7 +352,8 @@ extension NCCollectionViewCommon: UICollectionViewDataSource { } // Layout photo - if layoutForView?.layout == NCGlobal.shared.layoutPhoto && !metadata.directory { + if (layoutForView?.layout == NCGlobal.shared.layoutPhotoRatio || layoutForView?.layout == NCGlobal.shared.layoutPhotoSquare), + !metadata.directory { cell.fileTitleLabel?.text = "" } diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon+PhotoLayoutDelegate.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon+PhotoLayoutDelegate.swift index 6b62a87900..50062e0c82 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon+PhotoLayoutDelegate.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon+PhotoLayoutDelegate.swift @@ -36,7 +36,16 @@ extension NCCollectionViewCommon: NCPhotoLayoutDelegate { } func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath, columnCount: Int, typeLayout: String) -> CGSize { - let size = CGSize(width: collectionView.frame.width / CGFloat(columnCount), height: collectionView.frame.width / CGFloat(columnCount)) + var size = CGSize(width: collectionView.frame.width / CGFloat(columnCount), height: collectionView.frame.width / CGFloat(columnCount)) + if typeLayout == NCGlobal.shared.layoutPhotoRatio { + let metadata = self.dataSource.metadatas[indexPath.row] + if metadata.imageSize != CGSize.zero { + return metadata.imageSize + } else if utilityFileSystem.fileProviderStoragePreviewIconExists(metadata.ocId, etag: metadata.etag), + let image = utility.createFilePreviewImage(ocId: metadata.ocId, etag: metadata.etag, fileNameView: metadata.fileNameView, classFile: metadata.classFile, status: metadata.status, createPreviewMedia: !metadata.hasPreview) { + size = image.size + } + } return size } } diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon+SelectTabBarDelegate.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon+SelectTabBarDelegate.swift index cf7c1ca9a3..11c0ac498c 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon+SelectTabBarDelegate.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon+SelectTabBarDelegate.swift @@ -60,9 +60,9 @@ extension NCCollectionViewCommon: NCCollectionViewCommonSelectTabBarDelegate { } } - func onPhotoSelected() { - if layoutForView?.layout != NCGlobal.shared.layoutPhoto { - layoutForView?.layout = NCGlobal.shared.layoutPhoto + func onPhotoSelected(layout: String) { + if layoutForView?.layout != layout { + layoutForView?.layout = layout NCManageDatabase.shared.setLayoutForView(account: appDelegate.account, key: layoutKey, serverUrl: serverUrl, layout: layoutForView?.layout) self.groupByField = "name" if self.dataSource.groupByField != self.groupByField { diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift index d8aa53e233..0d42cf69ee 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift @@ -92,8 +92,8 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS tabBarSelect = NCCollectionViewCommonSelectTabBar(controller: tabBarController as? NCMainTabBarController, delegate: self) self.navigationController?.presentationController?.delegate = self - collectionView.alwaysBounceVertical = true + photoLayout.viewController = self // Color view.backgroundColor = .systemBackground @@ -169,7 +169,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS collectionView?.collectionViewLayout = listLayout } else if layoutForView?.layout == NCGlobal.shared.layoutGrid { collectionView?.collectionViewLayout = gridLayout - } else if layoutForView?.layout == NCGlobal.shared.layoutPhoto { + } else if (layoutForView?.layout == NCGlobal.shared.layoutPhotoRatio || layoutForView?.layout == NCGlobal.shared.layoutPhotoSquare) { collectionView?.collectionViewLayout = photoLayout } @@ -679,12 +679,18 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS self.setNavigationRightItems() } - let photo = UIAction(title: NSLocalizedString("_photo_", comment: ""), image: utility.loadImage(named: "photo"), state: layoutForView.layout == NCGlobal.shared.layoutPhoto ? .on : .off) { _ in - self.onPhotoSelected() - self.setNavigationRightItems() - } + let menuPhoto = UIMenu(title: "", options: .displayInline, children: [ + UIAction(title: NSLocalizedString("_media_square_", comment: ""), image: utility.loadImage(named: "square.grid.3x3"), state: layoutForView.layout == NCGlobal.shared.layoutPhotoSquare ? .on : .off) { _ in + self.onPhotoSelected(layout: NCGlobal.shared.layoutPhotoSquare) + self.setNavigationRightItems() + }, + UIAction(title: NSLocalizedString("_media_ratio_", comment: ""), image: utility.loadImage(named: "rectangle.grid.3x2"), state: layoutForView.layout == NCGlobal.shared.layoutPhotoRatio ? .on : .off) { _ in + self.onPhotoSelected(layout: NCGlobal.shared.layoutPhotoRatio) + self.setNavigationRightItems() + } + ]) - let viewStyleSubmenu = UIMenu(title: "", options: .displayInline, children: [list, grid, photo]) + let viewStyleSubmenu = UIMenu(title: "", options: .displayInline, children: [list, grid, UIMenu(title: NSLocalizedString("_photo_", comment: ""), children: [menuPhoto])]) let ascending = layoutForView.ascending let ascendingChevronImage = utility.loadImage(named: ascending ? "chevron.up" : "chevron.down") diff --git a/iOSClient/Media/NCMedia.swift b/iOSClient/Media/NCMedia.swift index d9fbd8b36a..f4870bbc15 100644 --- a/iOSClient/Media/NCMedia.swift +++ b/iOSClient/Media/NCMedia.swift @@ -87,7 +87,7 @@ class NCMedia: UIViewController { collectionView.dropDelegate = self layout.sectionInset = UIEdgeInsets(top: 0, left: 2, bottom: 0, right: 2) - layout.mediaViewController = self + layout.viewController = self collectionView.collectionViewLayout = layout tabBarSelect = NCMediaSelectTabBar(tabBarController: self.tabBarController, delegate: self) diff --git a/iOSClient/Media/NCMediaLayout.swift b/iOSClient/Media/NCMediaLayout.swift index 70b7c272e0..23e430b017 100644 --- a/iOSClient/Media/NCMediaLayout.swift +++ b/iOSClient/Media/NCMediaLayout.swift @@ -81,7 +81,7 @@ public class NCMediaLayout: UICollectionViewLayout { invalidateIfNotEqual(oldValue, newValue: sectionInset) } } - var mediaViewController: NCMedia? + var viewController: NCMedia? var mediaLayout = "" public override var collectionViewContentSize: CGSize { @@ -117,7 +117,7 @@ public class NCMediaLayout: UICollectionViewLayout { mediaLayout = NCKeychain().mediaTypeLayout columnCount = NCKeychain().mediaColumnCount - mediaViewController?.buildMediaPhotoVideo(columnCount: columnCount) + viewController?.buildMediaPhotoVideo(columnCount: columnCount) if UIDevice.current.userInterfaceIdiom == .phone, (UIDevice.current.orientation == .landscapeLeft || UIDevice.current.orientation == .landscapeRight) { columnCount += 2 diff --git a/iOSClient/NCGlobal.swift b/iOSClient/NCGlobal.swift index c587ebbc1c..b91aae260a 100644 --- a/iOSClient/NCGlobal.swift +++ b/iOSClient/NCGlobal.swift @@ -167,7 +167,8 @@ class NCGlobal: NSObject { // let layoutList = "typeLayoutList" let layoutGrid = "typeLayoutGrid" - let layoutPhoto = "typeLayoutPhoto" + let layoutPhotoRatio = "typeLayoutPhotoRatio" + let layoutPhotoSquare = "typeLayoutPhotoSquare" let layoutViewTrash = "LayoutTrash" let layoutViewOffline = "LayoutOffline" From b41e605f7c177e7e139f9c757737df1c4754940e Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Sun, 14 Jul 2024 12:10:03 +0200 Subject: [PATCH 09/27] coding Signed-off-by: Marino Faggiana --- .../Cell/NCPhotoLayout.swift | 2 +- ...nViewCommon+CollectionViewDataSource.swift | 6 ++-- .../NCCollectionViewCommon.swift | 36 +++++++++++++++++-- iOSClient/Settings/NCKeychain.swift | 12 +++++++ 4 files changed, 51 insertions(+), 5 deletions(-) diff --git a/iOSClient/Main/Collection Common/Cell/NCPhotoLayout.swift b/iOSClient/Main/Collection Common/Cell/NCPhotoLayout.swift index 451372861f..5b47a5c84c 100644 --- a/iOSClient/Main/Collection Common/Cell/NCPhotoLayout.swift +++ b/iOSClient/Main/Collection Common/Cell/NCPhotoLayout.swift @@ -120,7 +120,7 @@ public class NCPhotoLayout: UICollectionViewLayout { else { return } photoLayout = layoutForView.layout - columnCount = 3 // NCKeychain().mediaColumnCount + columnCount = NCKeychain().photoColumnCount if UIDevice.current.userInterfaceIdiom == .phone, (UIDevice.current.orientation == .landscapeLeft || UIDevice.current.orientation == .landscapeRight) { columnCount += 2 diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift index 8f38ecbfdc..aaac98f22b 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift @@ -353,8 +353,10 @@ extension NCCollectionViewCommon: UICollectionViewDataSource { // Layout photo if (layoutForView?.layout == NCGlobal.shared.layoutPhotoRatio || layoutForView?.layout == NCGlobal.shared.layoutPhotoSquare), - !metadata.directory { - cell.fileTitleLabel?.text = "" + let layout = collectionView.collectionViewLayout as? NCPhotoLayout { + //if !metadata.directory || layout.columnCount > 3 { + cell.fileTitleLabel?.text = "" + //} } // TAGS diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift index 0d42cf69ee..ff0e58d88b 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift @@ -63,6 +63,9 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS var timerNotificationCenter: Timer? var notificationReloadDataSource: Int = 0 var notificationReloadDataSourceNetwork: Int = 0 + var attributesZoomIn: UIMenuElement.Attributes = [] + var attributesZoomOut: UIMenuElement.Attributes = [] + let maxImageGrid: CGFloat = 7 // DECLARE var layoutKey = "" @@ -169,7 +172,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS collectionView?.collectionViewLayout = listLayout } else if layoutForView?.layout == NCGlobal.shared.layoutGrid { collectionView?.collectionViewLayout = gridLayout - } else if (layoutForView?.layout == NCGlobal.shared.layoutPhotoRatio || layoutForView?.layout == NCGlobal.shared.layoutPhotoSquare) { + } else if (layoutForView?.layout == NCGlobal.shared.layoutPhotoRatio || layoutForView?.layout == NCGlobal.shared.layoutPhotoSquare) { collectionView?.collectionViewLayout = photoLayout } @@ -661,10 +664,22 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS guard layoutKey != NCGlobal.shared.layoutViewTransfers else { return } let isTabBarHidden = self.tabBarController?.tabBar.isHidden ?? true let isTabBarSelectHidden = tabBarSelect.isHidden() + let columnCount = NCKeychain().photoColumnCount func createMenuActions() -> [UIMenuElement] { guard let layoutForView = NCManageDatabase.shared.getLayoutForView(account: appDelegate.account, key: layoutKey, serverUrl: serverUrl) else { return [] } + if CGFloat(columnCount) >= maxImageGrid - 1 { + self.attributesZoomIn = [] + self.attributesZoomOut = .disabled + } else if columnCount <= 1 { + self.attributesZoomIn = .disabled + self.attributesZoomOut = [] + } else { + self.attributesZoomIn = [] + self.attributesZoomOut = [] + } + let select = UIAction(title: NSLocalizedString("_select_", comment: ""), image: utility.loadImage(named: "checkmark.circle"), attributes: self.dataSource.getMetadataSourceForAllSections().isEmpty ? .disabled : []) { _ in self.setEditMode(true) } @@ -690,7 +705,24 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS } ]) - let viewStyleSubmenu = UIMenu(title: "", options: .displayInline, children: [list, grid, UIMenu(title: NSLocalizedString("_photo_", comment: ""), children: [menuPhoto])]) + let menuZoom = UIMenu(title: "", options: .displayInline, children: [ + UIAction(title: NSLocalizedString("_zoom_out_", comment: ""), image: utility.loadImage(named: "minus.magnifyingglass"), attributes: self.attributesZoomOut) { _ in + UIView.animate(withDuration: 0.0, animations: { + NCKeychain().photoColumnCount = columnCount + 1 + self.collectionView.reloadData() + self.setNavigationRightItems() + }) + }, + UIAction(title: NSLocalizedString("_zoom_in_", comment: ""), image: utility.loadImage(named: "plus.magnifyingglass"), attributes: self.attributesZoomIn) { _ in + UIView.animate(withDuration: 0.0, animations: { + NCKeychain().photoColumnCount = columnCount - 1 + self.collectionView.reloadData() + self.setNavigationRightItems() + }) + } + ]) + + let viewStyleSubmenu = UIMenu(title: "", options: .displayInline, children: [list, grid, UIMenu(title: NSLocalizedString("_photo_", comment: ""), children: [menuPhoto, menuZoom])]) let ascending = layoutForView.ascending let ascendingChevronImage = utility.loadImage(named: ascending ? "chevron.up" : "chevron.down") diff --git a/iOSClient/Settings/NCKeychain.swift b/iOSClient/Settings/NCKeychain.swift index 7d2e1d28d4..3459827da6 100644 --- a/iOSClient/Settings/NCKeychain.swift +++ b/iOSClient/Settings/NCKeychain.swift @@ -296,6 +296,18 @@ import KeychainAccess } } + var photoColumnCount: Int { + get { + if let value = try? keychain.get("photoColumnCount"), let result = Int(value) { + return result + } + return 3 + } + set { + keychain["photoColumnCount"] = String(newValue) + } + } + var mediaTypeLayout: String { get { if let value = try? keychain.get("mediaTypeLayout") { From d9b9a224667dfab0e21107018de09411292456dd Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Sun, 14 Jul 2024 12:33:26 +0200 Subject: [PATCH 10/27] coding Signed-off-by: Marino Faggiana --- Nextcloud.xcodeproj/project.pbxproj | 4 ---- .../Collection Common/Cell/NCPhotoLayout.swift | 15 +++++---------- ...CollectionViewCommon+PhotoLayoutDelegate.swift | 4 ++++ .../NCCollectionViewCommon.swift | 1 - iOSClient/Media/NCMedia.swift | 5 ++++- iOSClient/Media/NCMediaLayout.swift | 10 ++++------ 6 files changed, 17 insertions(+), 22 deletions(-) diff --git a/Nextcloud.xcodeproj/project.pbxproj b/Nextcloud.xcodeproj/project.pbxproj index 0d91211deb..a3934f10b5 100644 --- a/Nextcloud.xcodeproj/project.pbxproj +++ b/Nextcloud.xcodeproj/project.pbxproj @@ -227,7 +227,6 @@ F7145A231D12E3B700CAFEEC /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = F7E70DE91A24DE4100E1B66A /* Localizable.strings */; }; F714803B262EBE3900693E51 /* MainInterface.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F714803A262EBE3900693E51 /* MainInterface.storyboard */; }; F7148041262EBE4000693E51 /* NCShareExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7148040262EBE4000693E51 /* NCShareExtension.swift */; }; - F714804F262ED4F900693E51 /* NCGridCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = F78ACD4521903D010088454D /* NCGridCell.xib */; }; F7148054262ED51000693E51 /* NCListCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = F78ACD4321903CF20088454D /* NCListCell.xib */; }; F714805E262ED52900693E51 /* NCSectionFooter.xib in Resources */ = {isa = PBXBuildFile; fileRef = F78ACD53219047D40088454D /* NCSectionFooter.xib */; }; F7160A7D2BE931DE0034DCB3 /* RealmSwift in Frameworks */ = {isa = PBXBuildFile; productRef = F7160A7C2BE931DE0034DCB3 /* RealmSwift */; }; @@ -851,7 +850,6 @@ F7EDE4D1262D7B8400414FE6 /* NCDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7C1EEA425053A9C00866ACC /* NCDataSource.swift */; }; F7EDE4D6262D7B9600414FE6 /* NCListCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = F78ACD4121903CE00088454D /* NCListCell.swift */; }; F7EDE4DB262D7BA200414FE6 /* NCCellProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 370D26AE248A3D7A00121797 /* NCCellProtocol.swift */; }; - F7EDE4E0262D7BAF00414FE6 /* NCGridCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = F78ACD3F21903CC20088454D /* NCGridCell.swift */; }; F7EDE4E5262D7BBE00414FE6 /* NCSectionHeaderMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = F78ACD51219046DC0088454D /* NCSectionHeaderMenu.swift */; }; F7EDE509262DA9D600414FE6 /* NCSelectCommandViewSelect.xib in Resources */ = {isa = PBXBuildFile; fileRef = F7EDE508262DA9D600414FE6 /* NCSelectCommandViewSelect.xib */; }; F7EDE514262DC2CD00414FE6 /* NCSelectCommandViewSelect+CreateFolder.xib in Resources */ = {isa = PBXBuildFile; fileRef = F7EDE513262DC2CD00414FE6 /* NCSelectCommandViewSelect+CreateFolder.xib */; }; @@ -3648,7 +3646,6 @@ F746EC51273906C40052598D /* NCViewCertificateDetails.storyboard in Resources */, F76C26A62850D3A500E42BDF /* Images.xcassets in Resources */, F79EC784263161BA004E59D6 /* NCRenameFile.storyboard in Resources */, - F714804F262ED4F900693E51 /* NCGridCell.xib in Resources */, F714805E262ED52900693E51 /* NCSectionFooter.xib in Resources */, F700222D1EC479840080073F /* Custom.xcassets in Resources */, ); @@ -4003,7 +4000,6 @@ F7327E232B73A42F00A462C7 /* NCNetworking+Download.swift in Sources */, F749B64D297B0CBB00087535 /* NCManageDatabase+Share.swift in Sources */, F72FD3B8297ED49A00075D28 /* NCManageDatabase+E2EE.swift in Sources */, - F7EDE4E0262D7BAF00414FE6 /* NCGridCell.swift in Sources */, F7A76DC8256A71CD00119AB3 /* UIImage+Extension.swift in Sources */, F711A4E52AF9310500095DD8 /* NCUtility+Image.swift in Sources */, F73EF7AA2B0223900087E6E9 /* NCManageDatabase+Comments.swift in Sources */, diff --git a/iOSClient/Main/Collection Common/Cell/NCPhotoLayout.swift b/iOSClient/Main/Collection Common/Cell/NCPhotoLayout.swift index 5b47a5c84c..7b115e1ab2 100644 --- a/iOSClient/Main/Collection Common/Cell/NCPhotoLayout.swift +++ b/iOSClient/Main/Collection Common/Cell/NCPhotoLayout.swift @@ -32,6 +32,7 @@ protocol NCPhotoLayoutDelegate: UICollectionViewDelegate { func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, insetForHeaderInSection section: Int) -> UIEdgeInsets func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, insetForFooterInSection section: Int) -> UIEdgeInsets func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, minimumInteritemSpacingForSection section: Int) -> Float + func getLayout() -> String? } public class NCPhotoLayout: UICollectionViewLayout { @@ -81,9 +82,6 @@ public class NCPhotoLayout: UICollectionViewLayout { invalidateIfNotEqual(oldValue, newValue: sectionInset) } } - var photoLayout = "" - var viewController: NCCollectionViewCommon? - public override var collectionViewContentSize: CGSize { let numberOfSections = collectionView?.numberOfSections if numberOfSections == 0 { @@ -111,15 +109,11 @@ public class NCPhotoLayout: UICollectionViewLayout { public override func prepare() { super.prepare() - guard let appDelegate = (UIApplication.shared.delegate as? AppDelegate), - let numberOfSections = collectionView?.numberOfSections, + guard let numberOfSections = collectionView?.numberOfSections, let collectionView = collectionView, - let delegate = delegate, - let serverUrl = viewController?.serverUrl, - let layoutForView = NCManageDatabase.shared.getLayoutForView(account: appDelegate.account, key: NCGlobal.shared.layoutViewFiles, serverUrl: serverUrl) + let delegate = delegate else { return } - photoLayout = layoutForView.layout columnCount = NCKeychain().photoColumnCount if UIDevice.current.userInterfaceIdiom == .phone, (UIDevice.current.orientation == .landscapeLeft || UIDevice.current.orientation == .landscapeRight) { @@ -187,7 +181,8 @@ public class NCPhotoLayout: UICollectionViewLayout { let xOffset = Float(sectionInset.left) + Float(itemWidth + minimumColumnSpacing) * Float(columnIndex) let yOffset = columnHeights[columnIndex] - let itemSize = delegate.collectionView(collectionView, layout: self, sizeForItemAtIndexPath: indexPath, columnCount: self.columnCount, typeLayout: self.photoLayout) + let typeLayout = delegate.getLayout() ?? NCGlobal.shared.layoutPhotoRatio + let itemSize = delegate.collectionView(collectionView, layout: self, sizeForItemAtIndexPath: indexPath, columnCount: self.columnCount, typeLayout: typeLayout) var itemHeight: Float = 0.0 if itemSize.height > 0 && itemSize.width > 0 { itemHeight = Float(itemSize.height) * itemWidth / Float(itemSize.width) diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon+PhotoLayoutDelegate.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon+PhotoLayoutDelegate.swift index 50062e0c82..d8c438492d 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon+PhotoLayoutDelegate.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon+PhotoLayoutDelegate.swift @@ -11,6 +11,10 @@ import UIKit import NextcloudKit extension NCCollectionViewCommon: NCPhotoLayoutDelegate { + func getLayout() -> String? { + return NCManageDatabase.shared.getLayoutForView(account: appDelegate.account, key: NCGlobal.shared.layoutViewFiles, serverUrl: serverUrl)?.layout + } + func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, heightForHeaderInSection section: Int) -> Float { return .zero } diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift index ff0e58d88b..15324a0219 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift @@ -96,7 +96,6 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS tabBarSelect = NCCollectionViewCommonSelectTabBar(controller: tabBarController as? NCMainTabBarController, delegate: self) self.navigationController?.presentationController?.delegate = self collectionView.alwaysBounceVertical = true - photoLayout.viewController = self // Color view.backgroundColor = .systemBackground diff --git a/iOSClient/Media/NCMedia.swift b/iOSClient/Media/NCMedia.swift index f4870bbc15..50226f31fb 100644 --- a/iOSClient/Media/NCMedia.swift +++ b/iOSClient/Media/NCMedia.swift @@ -87,7 +87,6 @@ class NCMedia: UIViewController { collectionView.dropDelegate = self layout.sectionInset = UIEdgeInsets(top: 0, left: 2, bottom: 0, right: 2) - layout.viewController = self collectionView.collectionViewLayout = layout tabBarSelect = NCMediaSelectTabBar(tabBarController: self.tabBarController, delegate: self) @@ -483,6 +482,10 @@ extension NCMedia: UICollectionViewDataSource { // MARK: - extension NCMedia: NCMediaLayoutDelegate { + func getLayout() -> String? { + return NCKeychain().mediaTypeLayout + } + func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, heightForHeaderInSection section: Int) -> Float { var height: Double = 0 if metadatas?.count ?? 0 == 0 { diff --git a/iOSClient/Media/NCMediaLayout.swift b/iOSClient/Media/NCMediaLayout.swift index 23e430b017..1055405a43 100644 --- a/iOSClient/Media/NCMediaLayout.swift +++ b/iOSClient/Media/NCMediaLayout.swift @@ -32,6 +32,7 @@ protocol NCMediaLayoutDelegate: UICollectionViewDelegate { func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, insetForHeaderInSection section: Int) -> UIEdgeInsets func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, insetForFooterInSection section: Int) -> UIEdgeInsets func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, minimumInteritemSpacingForSection section: Int) -> Float + func getLayout() -> String? } public class NCMediaLayout: UICollectionViewLayout { @@ -81,9 +82,6 @@ public class NCMediaLayout: UICollectionViewLayout { invalidateIfNotEqual(oldValue, newValue: sectionInset) } } - var viewController: NCMedia? - var mediaLayout = "" - public override var collectionViewContentSize: CGSize { let numberOfSections = collectionView?.numberOfSections if numberOfSections == 0 { @@ -115,9 +113,8 @@ public class NCMediaLayout: UICollectionViewLayout { let collectionView = collectionView, let delegate = delegate else { return } - mediaLayout = NCKeychain().mediaTypeLayout columnCount = NCKeychain().mediaColumnCount - viewController?.buildMediaPhotoVideo(columnCount: columnCount) + (delegate as? NCMedia)?.buildMediaPhotoVideo(columnCount: columnCount) if UIDevice.current.userInterfaceIdiom == .phone, (UIDevice.current.orientation == .landscapeLeft || UIDevice.current.orientation == .landscapeRight) { columnCount += 2 @@ -184,7 +181,8 @@ public class NCMediaLayout: UICollectionViewLayout { let xOffset = Float(sectionInset.left) + Float(itemWidth + minimumColumnSpacing) * Float(columnIndex) let yOffset = columnHeights[columnIndex] - let itemSize = delegate.collectionView(collectionView, layout: self, sizeForItemAtIndexPath: indexPath, columnCount: self.columnCount, typeLayout: self.mediaLayout) + let typeLayout = delegate.getLayout() ?? NCGlobal.shared.mediaLayoutRatio + let itemSize = delegate.collectionView(collectionView, layout: self, sizeForItemAtIndexPath: indexPath, columnCount: self.columnCount, typeLayout: typeLayout) var itemHeight: Float = 0.0 if itemSize.height > 0 && itemSize.width > 0 { itemHeight = Float(itemSize.height) * itemWidth / Float(itemSize.width) From 128aa7c91520c3a69a3c710eec04c1b6abbb49a0 Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Sun, 14 Jul 2024 12:43:55 +0200 Subject: [PATCH 11/27] coding Signed-off-by: Marino Faggiana --- Nextcloud.xcodeproj/project.pbxproj | 4 - iOSClient/Files/NCFiles.swift | 4 +- .../Cell/NCPhotoLayout.swift | 329 ------------------ ...nViewCommon+CollectionViewDataSource.swift | 7 +- ...ectionViewCommon+PhotoLayoutDelegate.swift | 8 +- ...ctionViewCommon+SelectTabBarDelegate.swift | 2 +- .../NCCollectionViewCommon.swift | 6 +- iOSClient/Media/NCMedia.swift | 4 + iOSClient/Media/NCMediaLayout.swift | 6 +- 9 files changed, 21 insertions(+), 349 deletions(-) delete mode 100644 iOSClient/Main/Collection Common/Cell/NCPhotoLayout.swift diff --git a/Nextcloud.xcodeproj/project.pbxproj b/Nextcloud.xcodeproj/project.pbxproj index a3934f10b5..0a9bcf5463 100644 --- a/Nextcloud.xcodeproj/project.pbxproj +++ b/Nextcloud.xcodeproj/project.pbxproj @@ -597,7 +597,6 @@ F77444F522281649000D5EB0 /* NCGridMediaCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = F77444F322281649000D5EB0 /* NCGridMediaCell.swift */; }; F77444F622281649000D5EB0 /* NCGridMediaCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = F77444F422281649000D5EB0 /* NCGridMediaCell.xib */; }; F77444F8222816D5000D5EB0 /* NCPickerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F77444F7222816D5000D5EB0 /* NCPickerViewController.swift */; }; - F778231B2C42BDEB001BB94F /* NCPhotoLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = F778231A2C42BDEB001BB94F /* NCPhotoLayout.swift */; }; F778231E2C42C07C001BB94F /* NCCollectionViewCommon+PhotoLayoutDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F778231D2C42C07C001BB94F /* NCCollectionViewCommon+PhotoLayoutDelegate.swift */; }; F77A697D250A0FBC00FF1708 /* NCCollectionViewCommon+Menu.swift in Sources */ = {isa = PBXBuildFile; fileRef = F77A697C250A0FBC00FF1708 /* NCCollectionViewCommon+Menu.swift */; }; F77B0F631D118A16002130FE /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = F7E70DE91A24DE4100E1B66A /* Localizable.strings */; }; @@ -1437,7 +1436,6 @@ F77444F322281649000D5EB0 /* NCGridMediaCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCGridMediaCell.swift; sourceTree = ""; }; F77444F422281649000D5EB0 /* NCGridMediaCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NCGridMediaCell.xib; sourceTree = ""; }; F77444F7222816D5000D5EB0 /* NCPickerViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCPickerViewController.swift; sourceTree = ""; }; - F778231A2C42BDEB001BB94F /* NCPhotoLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCPhotoLayout.swift; sourceTree = ""; }; F778231D2C42C07C001BB94F /* NCCollectionViewCommon+PhotoLayoutDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCCollectionViewCommon+PhotoLayoutDelegate.swift"; sourceTree = ""; }; F7792DE429EEE02D005930CE /* MobileVLCKit.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = MobileVLCKit.xcframework; path = Carthage/Build/MobileVLCKit.xcframework; sourceTree = ""; }; F77A697C250A0FBC00FF1708 /* NCCollectionViewCommon+Menu.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NCCollectionViewCommon+Menu.swift"; sourceTree = ""; }; @@ -2263,7 +2261,6 @@ isa = PBXGroup; children = ( 370D26AE248A3D7A00121797 /* NCCellProtocol.swift */, - F778231A2C42BDEB001BB94F /* NCPhotoLayout.swift */, F751247A2C42919C00E63DB8 /* NCPhotoCell.swift */, F751247B2C42919C00E63DB8 /* NCPhotoCell.xib */, F78ACD3F21903CC20088454D /* NCGridCell.swift */, @@ -4320,7 +4317,6 @@ F75DD765290ABB25002EB562 /* Intent.intentdefinition in Sources */, F74B6D952A7E239A00F03C5F /* NCManageDatabase+Chunk.swift in Sources */, F310B1EF2BA862F1001C42F5 /* NCViewerMedia+VisionKit.swift in Sources */, - F778231B2C42BDEB001BB94F /* NCPhotoLayout.swift in Sources */, F702F2F725EE5CED008F8E80 /* NCLogin.swift in Sources */, F7EB9B132BBC12F300EDF036 /* UIApplication+Extension.swift in Sources */, F7E98C1627E0D0FC001F9F19 /* NCManageDatabase+Video.swift in Sources */, diff --git a/iOSClient/Files/NCFiles.swift b/iOSClient/Files/NCFiles.swift index ba769e4a38..573c07553b 100644 --- a/iOSClient/Files/NCFiles.swift +++ b/iOSClient/Files/NCFiles.swift @@ -63,8 +63,8 @@ class NCFiles: NCCollectionViewCommon { self.collectionView?.collectionViewLayout = self.listLayout } else if self.layoutForView?.layout == NCGlobal.shared.layoutGrid { self.collectionView?.collectionViewLayout = self.gridLayout - } else if (self.layoutForView?.layout == NCGlobal.shared.layoutPhotoSquare || self.layoutForView?.layout == NCGlobal.shared.layoutPhotoRatio) { - self.collectionView?.collectionViewLayout = self.photoLayout + } else if self.layoutForView?.layout == NCGlobal.shared.layoutPhotoSquare || self.layoutForView?.layout == NCGlobal.shared.layoutPhotoRatio { + self.collectionView?.collectionViewLayout = self.mediaLayout } self.titleCurrentFolder = self.getNavigationTitle() diff --git a/iOSClient/Main/Collection Common/Cell/NCPhotoLayout.swift b/iOSClient/Main/Collection Common/Cell/NCPhotoLayout.swift deleted file mode 100644 index 7b115e1ab2..0000000000 --- a/iOSClient/Main/Collection Common/Cell/NCPhotoLayout.swift +++ /dev/null @@ -1,329 +0,0 @@ -// -// NCPhotoLayout.swift -// -// Created by Marino Faggiana on 26/02/24. -// Based on CHTCollectionViewWaterfallLayout by Nelson Tai -// Copyright © 2024 Marino Faggiana. All rights reserved. -// -// 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 . -// - -import UIKit - -public let collectionViewPhotoElementKindSectionHeader = "collectionViewPhotoElementKindSectionHeader" -public let collectionViewPhotoElementKindSectionFooter = "collectionViewPhotoElementKindSectionFooter" - -protocol NCPhotoLayoutDelegate: UICollectionViewDelegate { - func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath, columnCount: Int, typeLayout: String) -> CGSize - func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, heightForHeaderInSection section: Int) -> Float - func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, heightForFooterInSection section: Int) -> Float - func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, insetForSection section: Int) -> UIEdgeInsets - func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, insetForHeaderInSection section: Int) -> UIEdgeInsets - func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, insetForFooterInSection section: Int) -> UIEdgeInsets - func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, minimumInteritemSpacingForSection section: Int) -> Float - func getLayout() -> String? -} - -public class NCPhotoLayout: UICollectionViewLayout { - - // MARK: - Private constants - /// How many items to be union into a single rectangle - private let unionSize = 20 - - // MARK: - Public Properties - public var columnCount: Int = 0 { - didSet { - invalidateIfNotEqual(oldValue, newValue: columnCount) - } - } - public var minimumColumnSpacing: Float = 2.0 { - didSet { - invalidateIfNotEqual(oldValue, newValue: minimumColumnSpacing) - } - } - public var minimumInteritemSpacing: Float = 2.0 { - didSet { - invalidateIfNotEqual(oldValue, newValue: minimumInteritemSpacing) - } - } - public var headerHeight: Float = 0.0 { - didSet { - invalidateIfNotEqual(oldValue, newValue: headerHeight) - } - } - public var footerHeight: Float = 0.0 { - didSet { - invalidateIfNotEqual(oldValue, newValue: footerHeight) - } - } - public var headerInset: UIEdgeInsets = .zero { - didSet { - invalidateIfNotEqual(oldValue, newValue: headerInset) - } - } - public var footerInset: UIEdgeInsets = .zero { - didSet { - invalidateIfNotEqual(oldValue, newValue: footerInset) - } - } - public var sectionInset: UIEdgeInsets = .zero { - didSet { - invalidateIfNotEqual(oldValue, newValue: sectionInset) - } - } - public override var collectionViewContentSize: CGSize { - let numberOfSections = collectionView?.numberOfSections - if numberOfSections == 0 { - return CGSize.zero - } - - var contentSize = collectionView?.bounds.size - contentSize?.height = CGFloat(columnHeights[0]) - - return contentSize! - } - - // MARK: - Private Properties - private weak var delegate: NCPhotoLayoutDelegate? { - return collectionView?.delegate as? NCPhotoLayoutDelegate - } - private var columnHeights = [Float]() - private var sectionItemAttributes = [[UICollectionViewLayoutAttributes]]() - private var allItemAttributes = [UICollectionViewLayoutAttributes]() - private var headersAttribute = [Int: UICollectionViewLayoutAttributes]() - private var footersAttribute = [Int: UICollectionViewLayoutAttributes]() - private var unionRects = [CGRect]() - - // MARK: - UICollectionViewLayout Methods - public override func prepare() { - super.prepare() - - guard let numberOfSections = collectionView?.numberOfSections, - let collectionView = collectionView, - let delegate = delegate - else { return } - - columnCount = NCKeychain().photoColumnCount - if UIDevice.current.userInterfaceIdiom == .phone, - (UIDevice.current.orientation == .landscapeLeft || UIDevice.current.orientation == .landscapeRight) { - columnCount += 2 - } - - // Initialize variables - headersAttribute.removeAll(keepingCapacity: false) - footersAttribute.removeAll(keepingCapacity: false) - unionRects.removeAll(keepingCapacity: false) - columnHeights.removeAll(keepingCapacity: false) - allItemAttributes.removeAll(keepingCapacity: false) - sectionItemAttributes.removeAll(keepingCapacity: false) - - for _ in 0.. 0 { - attributes = UICollectionViewLayoutAttributes(forSupplementaryViewOfKind: collectionViewPhotoElementKindSectionHeader, with: NSIndexPath(item: 0, section: section) as IndexPath) - attributes.frame = CGRect(x: headerInset.left, y: CGFloat(top), width: collectionView.frame.size.width - (headerInset.left + headerInset.right), height: CGFloat(headerHeight)) - - headersAttribute[section] = attributes - allItemAttributes.append(attributes) - - top = Float(attributes.frame.maxY) + Float(headerInset.bottom) - } - - top += Float(sectionInset.top) - for idx in 0.. 0 && itemSize.width > 0 { - itemHeight = Float(itemSize.height) * itemWidth / Float(itemSize.width) - } - - attributes = UICollectionViewLayoutAttributes(forCellWith: indexPath as IndexPath) - attributes.frame = CGRect(x: CGFloat(xOffset), y: CGFloat(yOffset), width: CGFloat(itemWidth), height: CGFloat(itemHeight)) - itemAttributes.append(attributes) - allItemAttributes.append(attributes) - columnHeights[columnIndex] = Float(attributes.frame.maxY) + minimumInteritemSpacing - } - - sectionItemAttributes.append(itemAttributes) - - /* - * 4. Section footer - */ - let columnIndex = longestColumnIndex() - top = columnHeights[columnIndex] - minimumInteritemSpacing + Float(sectionInset.bottom) - top += Float(footerInset.top) - - if footerHeight > 0 { - attributes = UICollectionViewLayoutAttributes(forSupplementaryViewOfKind: collectionViewPhotoElementKindSectionFooter, with: NSIndexPath(item: 0, section: section) as IndexPath) - attributes.frame = CGRect(x: footerInset.left, y: CGFloat(top), width: collectionView.frame.size.width - (footerInset.left + footerInset.right), height: CGFloat(footerHeight)) - - footersAttribute[section] = attributes - allItemAttributes.append(attributes) - - top = Float(attributes.frame.maxY) + Float(footerInset.bottom) - } - - for idx in 0.. UICollectionViewLayoutAttributes? { - if indexPath.section >= sectionItemAttributes.count { - return nil - } - - if indexPath.item >= sectionItemAttributes[indexPath.section].count { - return nil - } - - return sectionItemAttributes[indexPath.section][indexPath.item] - } - - public override func layoutAttributesForSupplementaryView(ofKind elementKind: String, at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? { - var attribute: UICollectionViewLayoutAttributes? - - if elementKind == collectionViewPhotoElementKindSectionHeader { - attribute = headersAttribute[indexPath.section] - } else if elementKind == collectionViewPhotoElementKindSectionFooter { - attribute = footersAttribute[indexPath.section] - } - - return attribute - } - - public override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { - var begin: Int = 0 - var end: Int = unionRects.count - var attrs = [UICollectionViewLayoutAttributes]() - - for i in 0.. Bool { - let oldBounds = collectionView?.bounds - if newBounds.width != oldBounds?.width { - return true - } - - return false - } -} - -// MARK: - Private Methods -private extension NCPhotoLayout { - func shortestColumnIndex() -> Int { - var index: Int = 0 - var shortestHeight = MAXFLOAT - - for (idx, height) in columnHeights.enumerated() { - if height < shortestHeight { - shortestHeight = height - index = idx - } - } - - return index - } - - func longestColumnIndex() -> Int { - var index: Int = 0 - var longestHeight: Float = 0 - for (idx, height) in columnHeights.enumerated() { - if height > longestHeight { - longestHeight = height - index = idx - } - } - return index - } - - func invalidateIfNotEqual(_ oldValue: T, newValue: T) { - if oldValue != newValue { - invalidateLayout() - } - } -} diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift index aaac98f22b..fadbb58e35 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift @@ -134,7 +134,7 @@ extension NCCollectionViewCommon: UICollectionViewDataSource { var a11yValues: [String] = [] // LAYOUT PHOTO - if layoutForView?.layout == NCGlobal.shared.layoutPhotoRatio || layoutForView?.layout == NCGlobal.shared.layoutPhotoSquare { + if layoutForView?.layout == NCGlobal.shared.layoutPhotoRatio || layoutForView?.layout == NCGlobal.shared.layoutPhotoSquare { guard let photoCell = collectionView.dequeueReusableCell(withReuseIdentifier: "photoCell", for: indexPath) as? NCPhotoCell else { return NCPhotoCell() } photoCell.photoCellDelegate = self cell = photoCell @@ -352,11 +352,8 @@ extension NCCollectionViewCommon: UICollectionViewDataSource { } // Layout photo - if (layoutForView?.layout == NCGlobal.shared.layoutPhotoRatio || layoutForView?.layout == NCGlobal.shared.layoutPhotoSquare), - let layout = collectionView.collectionViewLayout as? NCPhotoLayout { - //if !metadata.directory || layout.columnCount > 3 { + if layoutForView?.layout == NCGlobal.shared.layoutPhotoRatio || layoutForView?.layout == NCGlobal.shared.layoutPhotoSquare { cell.fileTitleLabel?.text = "" - //} } // TAGS diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon+PhotoLayoutDelegate.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon+PhotoLayoutDelegate.swift index d8c438492d..2d99de15c8 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon+PhotoLayoutDelegate.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon+PhotoLayoutDelegate.swift @@ -10,11 +10,15 @@ import Foundation import UIKit import NextcloudKit -extension NCCollectionViewCommon: NCPhotoLayoutDelegate { +extension NCCollectionViewCommon: NCMediaLayoutDelegate { + func getColumnCount() -> Int { + NCKeychain().photoColumnCount + } + func getLayout() -> String? { return NCManageDatabase.shared.getLayoutForView(account: appDelegate.account, key: NCGlobal.shared.layoutViewFiles, serverUrl: serverUrl)?.layout } - + func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, heightForHeaderInSection section: Int) -> Float { return .zero } diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon+SelectTabBarDelegate.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon+SelectTabBarDelegate.swift index 11c0ac498c..def1bd6da2 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon+SelectTabBarDelegate.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon+SelectTabBarDelegate.swift @@ -71,7 +71,7 @@ extension NCCollectionViewCommon: NCCollectionViewCommonSelectTabBarDelegate { self.collectionView.reloadData() self.collectionView.collectionViewLayout.invalidateLayout() - self.collectionView.setCollectionViewLayout(self.photoLayout, animated: true) {_ in self.isTransitioning = false } + self.collectionView.setCollectionViewLayout(self.mediaLayout, animated: true) {_ in self.isTransitioning = false } } } diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift index 15324a0219..63eae63d49 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift @@ -57,7 +57,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS var searchResults: [NKSearchResult]? var listLayout = NCListLayout() var gridLayout = NCGridLayout() - var photoLayout = NCPhotoLayout() + var mediaLayout = NCMediaLayout() var literalSearch: String? var tabBarSelect: NCCollectionViewCommonSelectTabBar! var timerNotificationCenter: Timer? @@ -171,8 +171,8 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS collectionView?.collectionViewLayout = listLayout } else if layoutForView?.layout == NCGlobal.shared.layoutGrid { collectionView?.collectionViewLayout = gridLayout - } else if (layoutForView?.layout == NCGlobal.shared.layoutPhotoRatio || layoutForView?.layout == NCGlobal.shared.layoutPhotoSquare) { - collectionView?.collectionViewLayout = photoLayout + } else if layoutForView?.layout == NCGlobal.shared.layoutPhotoRatio || layoutForView?.layout == NCGlobal.shared.layoutPhotoSquare { + collectionView?.collectionViewLayout = mediaLayout } // FIXME: iPAD PDF landscape mode iOS 16 diff --git a/iOSClient/Media/NCMedia.swift b/iOSClient/Media/NCMedia.swift index 50226f31fb..77402c1bc8 100644 --- a/iOSClient/Media/NCMedia.swift +++ b/iOSClient/Media/NCMedia.swift @@ -482,6 +482,10 @@ extension NCMedia: UICollectionViewDataSource { // MARK: - extension NCMedia: NCMediaLayoutDelegate { + func getColumnCount() -> Int { + return NCKeychain().mediaColumnCount + } + func getLayout() -> String? { return NCKeychain().mediaTypeLayout } diff --git a/iOSClient/Media/NCMediaLayout.swift b/iOSClient/Media/NCMediaLayout.swift index 1055405a43..2ca454816d 100644 --- a/iOSClient/Media/NCMediaLayout.swift +++ b/iOSClient/Media/NCMediaLayout.swift @@ -33,6 +33,7 @@ protocol NCMediaLayoutDelegate: UICollectionViewDelegate { func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, insetForFooterInSection section: Int) -> UIEdgeInsets func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, minimumInteritemSpacingForSection section: Int) -> Float func getLayout() -> String? + func getColumnCount() -> Int } public class NCMediaLayout: UICollectionViewLayout { @@ -87,10 +88,9 @@ public class NCMediaLayout: UICollectionViewLayout { if numberOfSections == 0 { return CGSize.zero } - var contentSize = collectionView?.bounds.size + contentSize?.height = CGFloat(columnHeights[0]) - return contentSize! } @@ -113,7 +113,7 @@ public class NCMediaLayout: UICollectionViewLayout { let collectionView = collectionView, let delegate = delegate else { return } - columnCount = NCKeychain().mediaColumnCount + columnCount = delegate.getColumnCount() (delegate as? NCMedia)?.buildMediaPhotoVideo(columnCount: columnCount) if UIDevice.current.userInterfaceIdiom == .phone, (UIDevice.current.orientation == .landscapeLeft || UIDevice.current.orientation == .landscapeRight) { From 6b6a2527597d8ee6a9e164b5068c5d14f76dbeec Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Sun, 14 Jul 2024 14:53:53 +0200 Subject: [PATCH 12/27] coding Signed-off-by: Marino Faggiana --- .../NCCollectionViewCommon+PhotoLayoutDelegate.swift | 2 +- iOSClient/Media/NCMediaLayout.swift | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon+PhotoLayoutDelegate.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon+PhotoLayoutDelegate.swift index 2d99de15c8..d774d13ce9 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon+PhotoLayoutDelegate.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon+PhotoLayoutDelegate.swift @@ -14,7 +14,7 @@ extension NCCollectionViewCommon: NCMediaLayoutDelegate { func getColumnCount() -> Int { NCKeychain().photoColumnCount } - + func getLayout() -> String? { return NCManageDatabase.shared.getLayoutForView(account: appDelegate.account, key: NCGlobal.shared.layoutViewFiles, serverUrl: serverUrl)?.layout } diff --git a/iOSClient/Media/NCMediaLayout.swift b/iOSClient/Media/NCMediaLayout.swift index 2ca454816d..e675aa98ad 100644 --- a/iOSClient/Media/NCMediaLayout.swift +++ b/iOSClient/Media/NCMediaLayout.swift @@ -48,22 +48,22 @@ public class NCMediaLayout: UICollectionViewLayout { invalidateIfNotEqual(oldValue, newValue: columnCount) } } - public var minimumColumnSpacing: Float = 2.0 { + public var minimumColumnSpacing: Float = .zero { didSet { invalidateIfNotEqual(oldValue, newValue: minimumColumnSpacing) } } - public var minimumInteritemSpacing: Float = 2.0 { + public var minimumInteritemSpacing: Float = .zero { didSet { invalidateIfNotEqual(oldValue, newValue: minimumInteritemSpacing) } } - public var headerHeight: Float = 0.0 { + public var headerHeight: Float = .zero { didSet { invalidateIfNotEqual(oldValue, newValue: headerHeight) } } - public var footerHeight: Float = 0.0 { + public var footerHeight: Float = .zero { didSet { invalidateIfNotEqual(oldValue, newValue: footerHeight) } @@ -89,7 +89,7 @@ public class NCMediaLayout: UICollectionViewLayout { return CGSize.zero } var contentSize = collectionView?.bounds.size - + contentSize?.height = CGFloat(columnHeights[0]) return contentSize! } From 8fad17b83d6f9163d12de00e3bc578a57a014600 Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Sun, 14 Jul 2024 15:06:56 +0200 Subject: [PATCH 13/27] coding Signed-off-by: Marino Faggiana --- .../NCCollectionViewCommon+PhotoLayoutDelegate.swift | 2 +- iOSClient/Media/NCMedia.swift | 4 ++-- iOSClient/Media/NCMediaLayout.swift | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon+PhotoLayoutDelegate.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon+PhotoLayoutDelegate.swift index d774d13ce9..38354930f5 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon+PhotoLayoutDelegate.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon+PhotoLayoutDelegate.swift @@ -40,7 +40,7 @@ extension NCCollectionViewCommon: NCMediaLayoutDelegate { } func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, minimumInteritemSpacingForSection section: Int) -> Float { - return .zero + return 1.0 } func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath, columnCount: Int, typeLayout: String) -> CGSize { diff --git a/iOSClient/Media/NCMedia.swift b/iOSClient/Media/NCMedia.swift index 77402c1bc8..2361ef5904 100644 --- a/iOSClient/Media/NCMedia.swift +++ b/iOSClient/Media/NCMedia.swift @@ -485,7 +485,7 @@ extension NCMedia: NCMediaLayoutDelegate { func getColumnCount() -> Int { return NCKeychain().mediaColumnCount } - + func getLayout() -> String? { return NCKeychain().mediaTypeLayout } @@ -515,7 +515,7 @@ extension NCMedia: NCMediaLayoutDelegate { } func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, minimumInteritemSpacingForSection section: Int) -> Float { - return .zero + return 1.0 } func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath, columnCount: Int, typeLayout: String) -> CGSize { diff --git a/iOSClient/Media/NCMediaLayout.swift b/iOSClient/Media/NCMediaLayout.swift index e675aa98ad..07a2e95e42 100644 --- a/iOSClient/Media/NCMediaLayout.swift +++ b/iOSClient/Media/NCMediaLayout.swift @@ -48,7 +48,7 @@ public class NCMediaLayout: UICollectionViewLayout { invalidateIfNotEqual(oldValue, newValue: columnCount) } } - public var minimumColumnSpacing: Float = .zero { + public var minimumColumnSpacing: Float = 1.0 { didSet { invalidateIfNotEqual(oldValue, newValue: minimumColumnSpacing) } From e4aa11567d6fc8729367569a17ceaa2005afce2a Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Sun, 14 Jul 2024 15:26:34 +0200 Subject: [PATCH 14/27] cod Signed-off-by: Marino Faggiana --- iOSClient/Main/Collection Common/Cell/NCCellProtocol.swift | 6 +++++- iOSClient/Main/Collection Common/Cell/NCPhotoCell.swift | 5 +++++ iOSClient/Main/Collection Common/Cell/NCPhotoCell.xib | 3 ++- .../NCCollectionViewCommon+CollectionViewDataSource.swift | 6 ++++++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/iOSClient/Main/Collection Common/Cell/NCCellProtocol.swift b/iOSClient/Main/Collection Common/Cell/NCCellProtocol.swift index 9dd1c4ac4e..6f05714517 100644 --- a/iOSClient/Main/Collection Common/Cell/NCCellProtocol.swift +++ b/iOSClient/Main/Collection Common/Cell/NCCellProtocol.swift @@ -24,10 +24,10 @@ import UIKit protocol NCCellProtocol { - var fileAvatarImageView: UIImageView? { get } var fileObjectId: String? { get set } var filePreviewImageView: UIImageView? { get set } + var filePreviewImageBottom: NSLayoutConstraint? { get set } var fileUser: String? { get set } var fileTitleLabel: UILabel? { get set } var fileInfoLabel: UILabel? { get set } @@ -68,6 +68,10 @@ extension NCCellProtocol { get { return nil } set {} } + var filePreviewImageBottom: NSLayoutConstraint? { + get { return nil } + set {} + } var fileTitleLabel: UILabel? { get { return nil } set {} diff --git a/iOSClient/Main/Collection Common/Cell/NCPhotoCell.swift b/iOSClient/Main/Collection Common/Cell/NCPhotoCell.swift index 21dda909e8..22d1c8ca60 100644 --- a/iOSClient/Main/Collection Common/Cell/NCPhotoCell.swift +++ b/iOSClient/Main/Collection Common/Cell/NCPhotoCell.swift @@ -30,6 +30,7 @@ class NCPhotoCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProt @IBOutlet weak var imageStatus: UIImageView! @IBOutlet weak var imageVisualEffect: UIVisualEffectView! @IBOutlet weak var labelTitle: UILabel! + @IBOutlet weak var imageItemBottom: NSLayoutConstraint! var objectId = "" var indexPath = IndexPath() @@ -46,6 +47,10 @@ class NCPhotoCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProt get { return imageItem } set { imageItem = newValue } } + var filePreviewImageBottom: NSLayoutConstraint? { + get { return imageItemBottom } + set { imageItemBottom = newValue} + } var fileUser: String? { get { return user } set { user = newValue ?? "" } diff --git a/iOSClient/Main/Collection Common/Cell/NCPhotoCell.xib b/iOSClient/Main/Collection Common/Cell/NCPhotoCell.xib index bab02b6316..30aae5009c 100644 --- a/iOSClient/Main/Collection Common/Cell/NCPhotoCell.xib +++ b/iOSClient/Main/Collection Common/Cell/NCPhotoCell.xib @@ -80,12 +80,13 @@ + - + diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift index fadbb58e35..b8851f4efb 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift @@ -353,7 +353,13 @@ extension NCCollectionViewCommon: UICollectionViewDataSource { // Layout photo if layoutForView?.layout == NCGlobal.shared.layoutPhotoRatio || layoutForView?.layout == NCGlobal.shared.layoutPhotoSquare { + if metadata.directory { + cell.filePreviewImageBottom?.constant = 10 + cell.fileTitleLabel?.text = metadata.fileNameView + } else { + cell.filePreviewImageBottom?.constant = 0 cell.fileTitleLabel?.text = "" + } } // TAGS From 2cde0585d50ab5061002f226096a3580fd1d8434 Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Sun, 14 Jul 2024 15:47:04 +0200 Subject: [PATCH 15/27] coding Signed-off-by: Marino Faggiana --- .../NCCollectionViewCommon+PhotoLayoutDelegate.swift | 2 +- iOSClient/Media/NCMedia.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon+PhotoLayoutDelegate.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon+PhotoLayoutDelegate.swift index 38354930f5..94ec10141e 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon+PhotoLayoutDelegate.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon+PhotoLayoutDelegate.swift @@ -45,7 +45,7 @@ extension NCCollectionViewCommon: NCMediaLayoutDelegate { func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath, columnCount: Int, typeLayout: String) -> CGSize { var size = CGSize(width: collectionView.frame.width / CGFloat(columnCount), height: collectionView.frame.width / CGFloat(columnCount)) - if typeLayout == NCGlobal.shared.layoutPhotoRatio { + if typeLayout == NCGlobal.shared.layoutPhotoSquare { let metadata = self.dataSource.metadatas[indexPath.row] if metadata.imageSize != CGSize.zero { return metadata.imageSize diff --git a/iOSClient/Media/NCMedia.swift b/iOSClient/Media/NCMedia.swift index 2361ef5904..f189136b84 100644 --- a/iOSClient/Media/NCMedia.swift +++ b/iOSClient/Media/NCMedia.swift @@ -520,7 +520,7 @@ extension NCMedia: NCMediaLayoutDelegate { func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath, columnCount: Int, typeLayout: String) -> CGSize { let size = CGSize(width: collectionView.frame.width / CGFloat(columnCount), height: collectionView.frame.width / CGFloat(columnCount)) - if typeLayout == NCGlobal.shared.mediaLayoutRatio { + if typeLayout == NCGlobal.shared.mediaLayoutSquare { guard let metadatas = self.metadatas, let metadata = metadatas[indexPath.row] else { return size } From f6639ac65dea21c2473b345c01ad47c8c4abc188 Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Sun, 14 Jul 2024 15:49:49 +0200 Subject: [PATCH 16/27] coding Signed-off-by: Marino Faggiana --- .../NCCollectionViewCommon+PhotoLayoutDelegate.swift | 2 +- iOSClient/Media/NCMedia.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon+PhotoLayoutDelegate.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon+PhotoLayoutDelegate.swift index 94ec10141e..38354930f5 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon+PhotoLayoutDelegate.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon+PhotoLayoutDelegate.swift @@ -45,7 +45,7 @@ extension NCCollectionViewCommon: NCMediaLayoutDelegate { func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath, columnCount: Int, typeLayout: String) -> CGSize { var size = CGSize(width: collectionView.frame.width / CGFloat(columnCount), height: collectionView.frame.width / CGFloat(columnCount)) - if typeLayout == NCGlobal.shared.layoutPhotoSquare { + if typeLayout == NCGlobal.shared.layoutPhotoRatio { let metadata = self.dataSource.metadatas[indexPath.row] if metadata.imageSize != CGSize.zero { return metadata.imageSize diff --git a/iOSClient/Media/NCMedia.swift b/iOSClient/Media/NCMedia.swift index f189136b84..2361ef5904 100644 --- a/iOSClient/Media/NCMedia.swift +++ b/iOSClient/Media/NCMedia.swift @@ -520,7 +520,7 @@ extension NCMedia: NCMediaLayoutDelegate { func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath, columnCount: Int, typeLayout: String) -> CGSize { let size = CGSize(width: collectionView.frame.width / CGFloat(columnCount), height: collectionView.frame.width / CGFloat(columnCount)) - if typeLayout == NCGlobal.shared.mediaLayoutSquare { + if typeLayout == NCGlobal.shared.mediaLayoutRatio { guard let metadatas = self.metadatas, let metadata = metadatas[indexPath.row] else { return size } From 981b81267860ba02e1cd71f314f1c947dd4bf51d Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Sun, 14 Jul 2024 18:24:26 +0200 Subject: [PATCH 17/27] coding Signed-off-by: Marino Faggiana --- ...onViewCommon+CollectionViewDataSource.swift | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift index b8851f4efb..027dfc8bf0 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift @@ -62,11 +62,20 @@ extension NCCollectionViewCommon: UICollectionViewDataSource { cell.filePreviewImageView?.layer.borderColor = UIColor.lightGray.cgColor } if metadata.name == NCGlobal.shared.appName { - if let image = NCImageCache.shared.getIconImage(ocId: metadata.ocId, etag: metadata.etag) { - cell.filePreviewImageView?.image = image - } else if let image = utility.createFilePreviewImage(ocId: metadata.ocId, etag: metadata.etag, fileNameView: metadata.fileNameView, classFile: metadata.classFile, status: metadata.status, createPreviewMedia: !metadata.hasPreview) { - cell.filePreviewImageView?.image = image + if layoutForView?.layout == NCGlobal.shared.layoutPhotoRatio || layoutForView?.layout == NCGlobal.shared.layoutPhotoSquare { + if let image = NCImageCache.shared.getMediaImage(ocId: metadata.ocId, etag: metadata.etag) { + cell.filePreviewImageView?.image = image + } else { + cell.filePreviewImageView?.image = UIImage(contentsOfFile: self.utilityFileSystem.getDirectoryProviderStoragePreviewOcId(metadata.ocId, etag: metadata.etag)) + } } else { + if let image = NCImageCache.shared.getIconImage(ocId: metadata.ocId, etag: metadata.etag) { + cell.filePreviewImageView?.image = image + } else if let image = utility.createFilePreviewImage(ocId: metadata.ocId, etag: metadata.etag, fileNameView: metadata.fileNameView, classFile: metadata.classFile, status: metadata.status, createPreviewMedia: !metadata.hasPreview) { + cell.filePreviewImageView?.image = image + } + } + if cell.filePreviewImageView?.image == nil { if metadata.iconName.isEmpty { cell.filePreviewImageView?.image = NCImageCache.images.file } else { @@ -107,7 +116,6 @@ extension NCCollectionViewCommon: UICollectionViewDataSource { } } } - /// AVATAR if !metadata.ownerId.isEmpty, metadata.ownerId != appDelegate.userId, From dd72951dbd8f8e746cdbc12c97f77ff7fd5ce0e8 Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Sun, 14 Jul 2024 18:30:07 +0200 Subject: [PATCH 18/27] cod Signed-off-by: Marino Faggiana --- .../NCCollectionViewCommon+PhotoLayoutDelegate.swift | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon+PhotoLayoutDelegate.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon+PhotoLayoutDelegate.swift index 38354930f5..d1f5a7303b 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon+PhotoLayoutDelegate.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon+PhotoLayoutDelegate.swift @@ -49,9 +49,13 @@ extension NCCollectionViewCommon: NCMediaLayoutDelegate { let metadata = self.dataSource.metadatas[indexPath.row] if metadata.imageSize != CGSize.zero { return metadata.imageSize - } else if utilityFileSystem.fileProviderStoragePreviewIconExists(metadata.ocId, etag: metadata.etag), - let image = utility.createFilePreviewImage(ocId: metadata.ocId, etag: metadata.etag, fileNameView: metadata.fileNameView, classFile: metadata.classFile, status: metadata.status, createPreviewMedia: !metadata.hasPreview) { + } else { + let existsIcon = utilityFileSystem.fileProviderStoragePreviewIconExists(metadata.ocId, etag: metadata.etag) + if let image = NCImageCache.shared.getMediaImage(ocId: metadata.ocId, etag: metadata.etag) { size = image.size + } else if let image = UIImage(contentsOfFile: self.utilityFileSystem.getDirectoryProviderStoragePreviewOcId(metadata.ocId, etag: metadata.etag)) { + size = image.size + } } } return size From 1905fc189bfb2fa9ad60fe0556e521fe7475fd86 Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Mon, 15 Jul 2024 12:03:19 +0200 Subject: [PATCH 19/27] coding Signed-off-by: Marino Faggiana --- iOSClient/Media/NCMedia.swift | 4 +- .../Media/NCMediaDownloadThumbnaill.swift | 2 +- iOSClient/NCImageCache.swift | 45 ++++++++++--------- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/iOSClient/Media/NCMedia.swift b/iOSClient/Media/NCMedia.swift index 2361ef5904..68c6d83cc3 100644 --- a/iOSClient/Media/NCMedia.swift +++ b/iOSClient/Media/NCMedia.swift @@ -284,7 +284,7 @@ class NCMedia: UIViewController { func getImage(metadata: tableMetadata) -> UIImage? { let fileNamePathPreview = utilityFileSystem.getDirectoryProviderStoragePreviewOcId(metadata.ocId, etag: metadata.etag) - if let image = imageCache.getMediaImage(ocId: metadata.ocId, etag: metadata.etag) { + if let image = imageCache.getPreviewImageCache(ocId: metadata.ocId, etag: metadata.etag) { return image } else if FileManager().fileExists(atPath: fileNamePathPreview), let image = UIImage(contentsOfFile: fileNamePathPreview) { return image @@ -526,7 +526,7 @@ extension NCMedia: NCMediaLayoutDelegate { if metadata.imageSize != CGSize.zero { return metadata.imageSize - } else if let size = imageCache.getMediaSize(ocId: metadata.ocId, etag: metadata.etag) { + } else if let size = imageCache.getPreviewSizeCache(ocId: metadata.ocId, etag: metadata.etag) { return size } } diff --git a/iOSClient/Media/NCMediaDownloadThumbnaill.swift b/iOSClient/Media/NCMediaDownloadThumbnaill.swift index 93e9fb3a37..a526a499f6 100644 --- a/iOSClient/Media/NCMediaDownloadThumbnaill.swift +++ b/iOSClient/Media/NCMediaDownloadThumbnaill.swift @@ -73,7 +73,7 @@ class NCMediaDownloadThumbnaill: ConcurrentOperation { } } } - NCImageCache.shared.setMediaSize(ocId: self.metadata.ocId, etag: self.metadata.etag, size: imagePreview.size) + NCImageCache.shared.setPreviewSizeCache(ocId: self.metadata.ocId, etag: self.metadata.etag, size: imagePreview.size) } self.finish() } diff --git a/iOSClient/NCImageCache.swift b/iOSClient/NCImageCache.swift index 771f931da6..552d5725bd 100644 --- a/iOSClient/NCImageCache.swift +++ b/iOSClient/NCImageCache.swift @@ -174,51 +174,54 @@ class NCImageCache: NSObject { return self.metadatas } + func getMediaMetadatas(account: String, predicate: NSPredicate? = nil) -> ThreadSafeArray? { + guard let tableAccount = NCManageDatabase.shared.getAccount(predicate: NSPredicate(format: "account == %@", account)) else { return nil } + let startServerUrl = NCUtilityFileSystem().getHomeServer(urlBase: tableAccount.urlBase, userId: tableAccount.userId) + tableAccount.mediaPath + let predicateBoth = NSPredicate(format: showBothPredicateMediaString, account, startServerUrl) + return NCManageDatabase.shared.getMediaMetadatas(predicate: predicate ?? predicateBoth) + } + /// - /// MEDIA PREVIEW CACHE + /// PREVIEW CACHE /// - func setMediaImage(ocId: String, etag: String, image: UIImage, date: Date) { + func setPreviewImageCache(ocId: String, etag: String, image: UIImage, date: Date) { cacheImagePreview.setValue(imageInfo(image: image, size: image.size, date: date), forKey: ocId + etag) + cacheSizePreview.setValue(image.size, forKey: ocId + etag) } - func getMediaImage(ocId: String, etag: String) -> UIImage? { + func getPreviewImageCache(ocId: String, etag: String) -> UIImage? { if let cache = cacheImagePreview.value(forKey: ocId + etag) { return cache.image } return nil } - func hasMediaImageEnoughSpace() -> Bool { - return limitCacheImagePreview > cacheImagePreview.count - } - /// - /// MEDIA SIZE CACHE + /// SIZE CACHE /// - func setMediaSize(ocId: String, etag: String, size: CGSize) { + func setPreviewSizeCache(ocId: String, etag: String, size: CGSize) { cacheSizePreview.setValue(size, forKey: ocId + etag) } - func getMediaSize(ocId: String, etag: String) -> CGSize? { - return cacheSizePreview.value(forKey: ocId + etag) ?? nil - } - - func getMediaMetadatas(account: String, predicate: NSPredicate? = nil) -> ThreadSafeArray? { - guard let tableAccount = NCManageDatabase.shared.getAccount(predicate: NSPredicate(format: "account == %@", account)) else { return nil } - let startServerUrl = NCUtilityFileSystem().getHomeServer(urlBase: tableAccount.urlBase, userId: tableAccount.userId) + tableAccount.mediaPath - let predicateBoth = NSPredicate(format: showBothPredicateMediaString, account, startServerUrl) - return NCManageDatabase.shared.getMediaMetadatas(predicate: predicate ?? predicateBoth) + func getPreviewSizeCache(ocId: String, etag: String) -> CGSize? { + if let size = cacheSizePreview.value(forKey: ocId + etag) { + return size + } else { + if let image = UIImage(contentsOfFile: NCUtilityFileSystem().getDirectoryProviderStoragePreviewOcId(ocId, etag: etag)) { + return image.size + } + } + return nil } /// /// ICON CACHE /// - - func setIconImage(ocId: String, etag: String, image: UIImage) { + func setIconImageCache(ocId: String, etag: String, image: UIImage) { cacheImageIcon.setValue(image, forKey: ocId + etag) } - func getIconImage(ocId: String, etag: String) -> UIImage? { + func getIconImageCache(ocId: String, etag: String) -> UIImage? { return cacheImageIcon.value(forKey: ocId + etag) } From 90fb5db0629ba1bfc409addc9706a961ed3a0451 Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Mon, 15 Jul 2024 12:04:16 +0200 Subject: [PATCH 20/27] coding Signed-off-by: Marino Faggiana --- ...nViewCommon+CollectionViewDataSource.swift | 13 +-- ...ectionViewCommon+PhotoLayoutDelegate.swift | 12 +-- .../NCSectionHeaderEmptyData.swift | 2 +- .../NCSectionHeaderMenu.swift | 2 +- iOSClient/Transfers/NCTransfers.swift | 2 +- iOSClient/Utility/NCUtility+Image.swift | 86 ++++++++++++------- 6 files changed, 67 insertions(+), 50 deletions(-) diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift index 027dfc8bf0..f98dccb370 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift @@ -63,16 +63,17 @@ extension NCCollectionViewCommon: UICollectionViewDataSource { } if metadata.name == NCGlobal.shared.appName { if layoutForView?.layout == NCGlobal.shared.layoutPhotoRatio || layoutForView?.layout == NCGlobal.shared.layoutPhotoSquare { - if let image = NCImageCache.shared.getMediaImage(ocId: metadata.ocId, etag: metadata.etag) { + if let image = NCImageCache.shared.getPreviewImageCache(ocId: metadata.ocId, etag: metadata.etag) { cell.filePreviewImageView?.image = image - } else { - cell.filePreviewImageView?.image = UIImage(contentsOfFile: self.utilityFileSystem.getDirectoryProviderStoragePreviewOcId(metadata.ocId, etag: metadata.etag)) + } else if let image = UIImage(contentsOfFile: self.utilityFileSystem.getDirectoryProviderStoragePreviewOcId(metadata.ocId, etag: metadata.etag)) { + cell.filePreviewImageView?.image = image + NCImageCache.shared.setPreviewImageCache(ocId: metadata.ocId, etag: metadata.etag, image: image, date: metadata.date as Date) } } else { - if let image = NCImageCache.shared.getIconImage(ocId: metadata.ocId, etag: metadata.etag) { - cell.filePreviewImageView?.image = image - } else if let image = utility.createFilePreviewImage(ocId: metadata.ocId, etag: metadata.etag, fileNameView: metadata.fileNameView, classFile: metadata.classFile, status: metadata.status, createPreviewMedia: !metadata.hasPreview) { + if let image = NCImageCache.shared.getIconImageCache(ocId: metadata.ocId, etag: metadata.etag) { cell.filePreviewImageView?.image = image + } else if metadata.hasPreview { + cell.filePreviewImageView?.image = utility.createImage(metadata: metadata).icon } } if cell.filePreviewImageView?.image == nil { diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon+PhotoLayoutDelegate.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon+PhotoLayoutDelegate.swift index d1f5a7303b..4e7eebe48f 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon+PhotoLayoutDelegate.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon+PhotoLayoutDelegate.swift @@ -44,18 +44,14 @@ extension NCCollectionViewCommon: NCMediaLayoutDelegate { } func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath, columnCount: Int, typeLayout: String) -> CGSize { - var size = CGSize(width: collectionView.frame.width / CGFloat(columnCount), height: collectionView.frame.width / CGFloat(columnCount)) + let size = CGSize(width: collectionView.frame.width / CGFloat(columnCount), height: collectionView.frame.width / CGFloat(columnCount)) if typeLayout == NCGlobal.shared.layoutPhotoRatio { let metadata = self.dataSource.metadatas[indexPath.row] + if metadata.imageSize != CGSize.zero { return metadata.imageSize - } else { - let existsIcon = utilityFileSystem.fileProviderStoragePreviewIconExists(metadata.ocId, etag: metadata.etag) - if let image = NCImageCache.shared.getMediaImage(ocId: metadata.ocId, etag: metadata.etag) { - size = image.size - } else if let image = UIImage(contentsOfFile: self.utilityFileSystem.getDirectoryProviderStoragePreviewOcId(metadata.ocId, etag: metadata.etag)) { - size = image.size - } + } else if let size = NCImageCache.shared.getPreviewSizeCache(ocId: metadata.ocId, etag: metadata.etag) { + return size } } return size diff --git a/iOSClient/Main/Collection Common/Section Header Footer/NCSectionHeaderEmptyData.swift b/iOSClient/Main/Collection Common/Section Header Footer/NCSectionHeaderEmptyData.swift index 50a30b2b97..6f09ad1ee9 100644 --- a/iOSClient/Main/Collection Common/Section Header Footer/NCSectionHeaderEmptyData.swift +++ b/iOSClient/Main/Collection Common/Section Header Footer/NCSectionHeaderEmptyData.swift @@ -94,7 +94,7 @@ class NCSectionHeaderEmptyData: UICollectionReusableView { var image: UIImage? if let ocId, let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) { - image = NCUtility().createFilePreviewImage(ocId: metadata.ocId, etag: metadata.etag, fileNameView: metadata.fileNameView, classFile: metadata.classFile, status: metadata.status, createPreviewMedia: true)?.darken() + image = NCUtility().createImage(metadata: metadata).icon?.darken() if image == nil { image = NCUtility().loadImage(named: metadata.iconName, useTypeIconFile: true) buttonTransfer.backgroundColor = .lightGray diff --git a/iOSClient/Main/Collection Common/Section Header Footer/NCSectionHeaderMenu.swift b/iOSClient/Main/Collection Common/Section Header Footer/NCSectionHeaderMenu.swift index 40f1cf1e63..f83fd81429 100644 --- a/iOSClient/Main/Collection Common/Section Header Footer/NCSectionHeaderMenu.swift +++ b/iOSClient/Main/Collection Common/Section Header Footer/NCSectionHeaderMenu.swift @@ -143,7 +143,7 @@ class NCSectionHeaderMenu: UICollectionReusableView, UIGestureRecognizerDelegate var image: UIImage? if let ocId, let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) { - image = utility.createFilePreviewImage(ocId: metadata.ocId, etag: metadata.etag, fileNameView: metadata.fileNameView, classFile: metadata.classFile, status: metadata.status, createPreviewMedia: true)?.darken() + image = utility.createImage(metadata: metadata).icon?.darken() if image == nil { image = utility.loadImage(named: metadata.iconName, useTypeIconFile: true) buttonTransfer.backgroundColor = .lightGray diff --git a/iOSClient/Transfers/NCTransfers.swift b/iOSClient/Transfers/NCTransfers.swift index 16ff380d78..42ec1f470d 100644 --- a/iOSClient/Transfers/NCTransfers.swift +++ b/iOSClient/Transfers/NCTransfers.swift @@ -207,7 +207,7 @@ class NCTransfers: NCCollectionViewCommon, NCTransferCellDelegate { cell.labelPath.text = pathText cell.setButtonMore(named: NCGlobal.shared.buttonMoreStop, image: NCImageCache.images.buttonStop) cell.progressView.progress = 0.0 - if let image = utility.createFilePreviewImage(ocId: metadata.ocId, etag: metadata.etag, fileNameView: metadata.fileNameView, classFile: metadata.classFile, status: metadata.status, createPreviewMedia: true) { + if let image = utility.createImage(metadata: metadata).icon { cell.imageItem.image = image } else if !metadata.iconName.isEmpty { cell.imageItem.image = utility.loadImage(named: metadata.iconName, useTypeIconFile: true) diff --git a/iOSClient/Utility/NCUtility+Image.swift b/iOSClient/Utility/NCUtility+Image.swift index 2feedab716..a1e5a7cfbd 100644 --- a/iOSClient/Utility/NCUtility+Image.swift +++ b/iOSClient/Utility/NCUtility+Image.swift @@ -228,45 +228,65 @@ extension NCUtility { } } - func createFilePreviewImage(ocId: String, etag: String, fileNameView: String, classFile: String, status: Int, createPreviewMedia: Bool) -> UIImage? { - var imagePreview: UIImage? - let filePath = self.utilityFileSystem.getDirectoryProviderStorageOcId(ocId, fileNameView: fileNameView) - let iconImagePath = self.utilityFileSystem.getDirectoryProviderStorageIconOcId(ocId, etag: etag) - - if FileManager.default.fileExists(atPath: iconImagePath) { - imagePreview = UIImage(contentsOfFile: iconImagePath) - } else if !createPreviewMedia { - return nil - } else if createPreviewMedia && status >= NCGlobal.shared.metadataStatusNormal && classFile == NKCommon.TypeClassFile.image.rawValue && FileManager().fileExists(atPath: filePath) { - if let image = UIImage(contentsOfFile: filePath), let image = image.resizeImage(size: CGSize(width: NCGlobal.shared.sizeIcon, height: NCGlobal.shared.sizeIcon)), let data = image.jpegData(compressionQuality: 0.5) { - do { - try data.write(to: URL(fileURLWithPath: iconImagePath), options: .atomic) - imagePreview = image - } catch { } - } - } else if createPreviewMedia && status >= NCGlobal.shared.metadataStatusNormal && classFile == NKCommon.TypeClassFile.video.rawValue && FileManager().fileExists(atPath: filePath) { - if let image = self.imageFromVideo(url: URL(fileURLWithPath: filePath), at: 0), let image = image.resizeImage(size: CGSize(width: NCGlobal.shared.sizeIcon, height: NCGlobal.shared.sizeIcon)), let data = image.jpegData(compressionQuality: 0.5) { - do { - try data.write(to: URL(fileURLWithPath: iconImagePath), options: .atomic) - imagePreview = image - } catch { } + func createImage(metadata: tableMetadata) -> (icon: UIImage?, preview: UIImage?) { + let iconPath = self.utilityFileSystem.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag) + let previewPath = self.utilityFileSystem.getDirectoryProviderStoragePreviewOcId(metadata.ocId, etag: metadata.etag) + let filePath = self.utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView) + var icon: UIImage?, preview: UIImage? + + if FileManager.default.fileExists(atPath: iconPath) { + icon = UIImage(contentsOfFile: iconPath) + if let size = icon?.size { + if Int(size.width) > NCGlobal.shared.sizeIcon, Int(size.height) > NCGlobal.shared.sizeIcon { + icon = icon?.resizeImage(size: CGSize(width: NCGlobal.shared.sizeIcon, height: NCGlobal.shared.sizeIcon)) + do { + if let data = icon?.jpegData(compressionQuality: 0.5) { + try data.write(to: URL(fileURLWithPath: iconPath), options: .atomic) + } + } catch { } + } } } - // better to check that the size is NCGlobal.shared.sizeIcon isAspectRation true - if let size = imagePreview?.size { - if Int(size.width) > NCGlobal.shared.sizeIcon, Int(size.height) > NCGlobal.shared.sizeIcon { - imagePreview = imagePreview?.resizeImage(size: CGSize(width: NCGlobal.shared.sizeIcon, height: NCGlobal.shared.sizeIcon)) - do { - if let imagePreview, let data = imagePreview.jpegData(compressionQuality: 0.5) { - try data.write(to: URL(fileURLWithPath: iconImagePath), options: .atomic) - } - } catch { } + if FileManager.default.fileExists(atPath: previewPath) { + preview = UIImage(contentsOfFile: previewPath) + } + if let icon, let preview { + return (icon, preview) + } + + let width = metadata.width == 0 ? NCGlobal.shared.sizePreview : metadata.width + let height = metadata.height == 0 ? NCGlobal.shared.sizePreview : metadata.height + + if FileManager().fileExists(atPath: filePath), metadata.status >= NCGlobal.shared.metadataStatusNormal { + var image: UIImage? + /// Create from IMAGE + if metadata.classFile == NKCommon.TypeClassFile.image.rawValue { + image = UIImage(contentsOfFile: filePath) + } else if metadata.classFile == NKCommon.TypeClassFile.video.rawValue { + image = self.imageFromVideo(url: URL(fileURLWithPath: filePath), at: 0) + } + if let image { + let icon = image.resizeImage(size: CGSize(width: NCGlobal.shared.sizeIcon, height: NCGlobal.shared.sizeIcon)) + let preview = image.resizeImage(size: CGSize(width: width, height: height)) + if let data = icon?.jpegData(compressionQuality: 0.5) { + do { + try data.write(to: URL(fileURLWithPath: iconPath), options: .atomic) + } catch { } + } + if let data = preview?.jpegData(compressionQuality: 0.5) { + do { + try data.write(to: URL(fileURLWithPath: previewPath), options: .atomic) + } catch { } + } + return (icon, preview) + } else { + return (nil, nil) } } - return imagePreview + return (icon, preview) } - @objc func pdfThumbnail(url: URL, width: CGFloat = 240) -> UIImage? { + func pdfThumbnail(url: URL, width: CGFloat = 240) -> UIImage? { guard let data = try? Data(contentsOf: url), let page = PDFDocument(data: data)?.page(at: 0) else { return nil } From 3ba2eee5d345cfd632895cebc69470cb4b328f19 Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Mon, 15 Jul 2024 12:09:35 +0200 Subject: [PATCH 21/27] coding Signed-off-by: Marino Faggiana --- iOSClient/Utility/NCUtility+Image.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iOSClient/Utility/NCUtility+Image.swift b/iOSClient/Utility/NCUtility+Image.swift index a1e5a7cfbd..1c73fe2ec2 100644 --- a/iOSClient/Utility/NCUtility+Image.swift +++ b/iOSClient/Utility/NCUtility+Image.swift @@ -257,7 +257,7 @@ extension NCUtility { let width = metadata.width == 0 ? NCGlobal.shared.sizePreview : metadata.width let height = metadata.height == 0 ? NCGlobal.shared.sizePreview : metadata.height - if FileManager().fileExists(atPath: filePath), metadata.status >= NCGlobal.shared.metadataStatusNormal { + if NCUtilityFileSystem().fileProviderStorageExists(metadata), metadata.status >= NCGlobal.shared.metadataStatusNormal { var image: UIImage? /// Create from IMAGE if metadata.classFile == NKCommon.TypeClassFile.image.rawValue { From f7ac3b7a854d8cba7726e71f2c0f7623ab12b849 Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Mon, 15 Jul 2024 12:20:14 +0200 Subject: [PATCH 22/27] cod Signed-off-by: Marino Faggiana --- iOSClient/Data/NCManageDatabase.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/iOSClient/Data/NCManageDatabase.swift b/iOSClient/Data/NCManageDatabase.swift index f4555e5738..a4281e7d3e 100644 --- a/iOSClient/Data/NCManageDatabase.swift +++ b/iOSClient/Data/NCManageDatabase.swift @@ -219,7 +219,6 @@ class NCManageDatabase: NSObject { self.clearTable(tableGPS.self, account: nil) self.clearTable(TableGroupfolders.self, account: account) self.clearTable(TableGroupfoldersGroups.self, account: account) - self.clearTable(NCDBLayoutForView.self, account: account) self.clearTable(tableLocalFile.self, account: account) self.clearTable(tableMetadata.self, account: account) self.clearTable(tablePhotoLibrary.self, account: account) From bdb65e1e18f9a8204091028969cd9af2f4246d6b Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Mon, 15 Jul 2024 12:32:47 +0200 Subject: [PATCH 23/27] coding Signed-off-by: Marino Faggiana --- iOSClient/Media/NCMediaDataSource.swift | 4 +++- iOSClient/NCImageCache.swift | 14 ++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/iOSClient/Media/NCMediaDataSource.swift b/iOSClient/Media/NCMediaDataSource.swift index a2dfd82d7b..111fa0e748 100644 --- a/iOSClient/Media/NCMediaDataSource.swift +++ b/iOSClient/Media/NCMediaDataSource.swift @@ -27,7 +27,9 @@ import NextcloudKit extension NCMedia { func reloadDataSource() { - self.metadatas = imageCache.getMediaMetadatas(account: activeAccount.account, predicate: self.getPredicate()) + let startServerUrl = NCUtilityFileSystem().getHomeServer(urlBase: activeAccount.urlBase, userId: activeAccount.userId) + activeAccount.mediaPath + let predicateBoth = NSPredicate(format: NCImageCache.shared.showBothPredicateMediaString, activeAccount.account, startServerUrl) + self.metadatas = NCManageDatabase.shared.getMediaMetadatas(predicate: self.getPredicate()) self.collectionViewReloadData() } diff --git a/iOSClient/NCImageCache.swift b/iOSClient/NCImageCache.swift index 552d5725bd..ee236c6e05 100644 --- a/iOSClient/NCImageCache.swift +++ b/iOSClient/NCImageCache.swift @@ -84,6 +84,13 @@ class NCImageCache: NSObject { } createMediaCacheInProgress = true + func getMediaMetadatas(account: String, predicate: NSPredicate? = nil) -> ThreadSafeArray? { + guard let tableAccount = NCManageDatabase.shared.getAccount(predicate: NSPredicate(format: "account == %@", account)) else { return nil } + let startServerUrl = NCUtilityFileSystem().getHomeServer(urlBase: tableAccount.urlBase, userId: tableAccount.userId) + tableAccount.mediaPath + let predicateBoth = NSPredicate(format: showBothPredicateMediaString, account, startServerUrl) + return NCManageDatabase.shared.getMediaMetadatas(predicate: predicate ?? predicateBoth) + } + self.metadatasInfo.removeAll() self.metadatas = nil self.metadatas = getMediaMetadatas(account: account) @@ -174,12 +181,7 @@ class NCImageCache: NSObject { return self.metadatas } - func getMediaMetadatas(account: String, predicate: NSPredicate? = nil) -> ThreadSafeArray? { - guard let tableAccount = NCManageDatabase.shared.getAccount(predicate: NSPredicate(format: "account == %@", account)) else { return nil } - let startServerUrl = NCUtilityFileSystem().getHomeServer(urlBase: tableAccount.urlBase, userId: tableAccount.userId) + tableAccount.mediaPath - let predicateBoth = NSPredicate(format: showBothPredicateMediaString, account, startServerUrl) - return NCManageDatabase.shared.getMediaMetadatas(predicate: predicate ?? predicateBoth) - } + /// /// PREVIEW CACHE From 9b8e473fee7d075019096e88e35740220c36e3b7 Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Mon, 15 Jul 2024 15:05:35 +0200 Subject: [PATCH 24/27] coding Signed-off-by: Marino Faggiana --- ...nViewCommon+CollectionViewDataSource.swift | 2 +- .../NCSectionHeaderEmptyData.swift | 2 +- .../NCSectionHeaderMenu.swift | 2 +- iOSClient/Transfers/NCTransfers.swift | 2 +- iOSClient/Utility/NCUtility+Image.swift | 62 +++---------------- 5 files changed, 14 insertions(+), 56 deletions(-) diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift index f98dccb370..46f133f3d1 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift @@ -73,7 +73,7 @@ extension NCCollectionViewCommon: UICollectionViewDataSource { if let image = NCImageCache.shared.getIconImageCache(ocId: metadata.ocId, etag: metadata.etag) { cell.filePreviewImageView?.image = image } else if metadata.hasPreview { - cell.filePreviewImageView?.image = utility.createImage(metadata: metadata).icon + cell.filePreviewImageView?.image = utility.getIcon(metadata: metadata) } } if cell.filePreviewImageView?.image == nil { diff --git a/iOSClient/Main/Collection Common/Section Header Footer/NCSectionHeaderEmptyData.swift b/iOSClient/Main/Collection Common/Section Header Footer/NCSectionHeaderEmptyData.swift index 6f09ad1ee9..66f09c6fde 100644 --- a/iOSClient/Main/Collection Common/Section Header Footer/NCSectionHeaderEmptyData.swift +++ b/iOSClient/Main/Collection Common/Section Header Footer/NCSectionHeaderEmptyData.swift @@ -94,7 +94,7 @@ class NCSectionHeaderEmptyData: UICollectionReusableView { var image: UIImage? if let ocId, let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) { - image = NCUtility().createImage(metadata: metadata).icon?.darken() + image = NCUtility().getIcon(metadata: metadata)?.darken() if image == nil { image = NCUtility().loadImage(named: metadata.iconName, useTypeIconFile: true) buttonTransfer.backgroundColor = .lightGray diff --git a/iOSClient/Main/Collection Common/Section Header Footer/NCSectionHeaderMenu.swift b/iOSClient/Main/Collection Common/Section Header Footer/NCSectionHeaderMenu.swift index f83fd81429..b75d9b9dc9 100644 --- a/iOSClient/Main/Collection Common/Section Header Footer/NCSectionHeaderMenu.swift +++ b/iOSClient/Main/Collection Common/Section Header Footer/NCSectionHeaderMenu.swift @@ -143,7 +143,7 @@ class NCSectionHeaderMenu: UICollectionReusableView, UIGestureRecognizerDelegate var image: UIImage? if let ocId, let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) { - image = utility.createImage(metadata: metadata).icon?.darken() + image = utility.getIcon(metadata: metadata)?.darken() if image == nil { image = utility.loadImage(named: metadata.iconName, useTypeIconFile: true) buttonTransfer.backgroundColor = .lightGray diff --git a/iOSClient/Transfers/NCTransfers.swift b/iOSClient/Transfers/NCTransfers.swift index 42ec1f470d..fd5cb18201 100644 --- a/iOSClient/Transfers/NCTransfers.swift +++ b/iOSClient/Transfers/NCTransfers.swift @@ -207,7 +207,7 @@ class NCTransfers: NCCollectionViewCommon, NCTransferCellDelegate { cell.labelPath.text = pathText cell.setButtonMore(named: NCGlobal.shared.buttonMoreStop, image: NCImageCache.images.buttonStop) cell.progressView.progress = 0.0 - if let image = utility.createImage(metadata: metadata).icon { + if let image = utility.getIcon(metadata: metadata) { cell.imageItem.image = image } else if !metadata.iconName.isEmpty { cell.imageItem.image = utility.loadImage(named: metadata.iconName, useTypeIconFile: true) diff --git a/iOSClient/Utility/NCUtility+Image.swift b/iOSClient/Utility/NCUtility+Image.swift index 1c73fe2ec2..c6e60dc8b6 100644 --- a/iOSClient/Utility/NCUtility+Image.swift +++ b/iOSClient/Utility/NCUtility+Image.swift @@ -228,62 +228,20 @@ extension NCUtility { } } - func createImage(metadata: tableMetadata) -> (icon: UIImage?, preview: UIImage?) { + func getIcon(metadata: tableMetadata) -> UIImage? { let iconPath = self.utilityFileSystem.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag) - let previewPath = self.utilityFileSystem.getDirectoryProviderStoragePreviewOcId(metadata.ocId, etag: metadata.etag) - let filePath = self.utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView) - var icon: UIImage?, preview: UIImage? - - if FileManager.default.fileExists(atPath: iconPath) { - icon = UIImage(contentsOfFile: iconPath) - if let size = icon?.size { - if Int(size.width) > NCGlobal.shared.sizeIcon, Int(size.height) > NCGlobal.shared.sizeIcon { - icon = icon?.resizeImage(size: CGSize(width: NCGlobal.shared.sizeIcon, height: NCGlobal.shared.sizeIcon)) - do { - if let data = icon?.jpegData(compressionQuality: 0.5) { - try data.write(to: URL(fileURLWithPath: iconPath), options: .atomic) - } - } catch { } - } - } - } - if FileManager.default.fileExists(atPath: previewPath) { - preview = UIImage(contentsOfFile: previewPath) - } - if let icon, let preview { - return (icon, preview) - } + guard let icon = UIImage(contentsOfFile: iconPath) else { return nil } - let width = metadata.width == 0 ? NCGlobal.shared.sizePreview : metadata.width - let height = metadata.height == 0 ? NCGlobal.shared.sizePreview : metadata.height - - if NCUtilityFileSystem().fileProviderStorageExists(metadata), metadata.status >= NCGlobal.shared.metadataStatusNormal { - var image: UIImage? - /// Create from IMAGE - if metadata.classFile == NKCommon.TypeClassFile.image.rawValue { - image = UIImage(contentsOfFile: filePath) - } else if metadata.classFile == NKCommon.TypeClassFile.video.rawValue { - image = self.imageFromVideo(url: URL(fileURLWithPath: filePath), at: 0) - } - if let image { - let icon = image.resizeImage(size: CGSize(width: NCGlobal.shared.sizeIcon, height: NCGlobal.shared.sizeIcon)) - let preview = image.resizeImage(size: CGSize(width: width, height: height)) - if let data = icon?.jpegData(compressionQuality: 0.5) { - do { - try data.write(to: URL(fileURLWithPath: iconPath), options: .atomic) - } catch { } - } - if let data = preview?.jpegData(compressionQuality: 0.5) { - do { - try data.write(to: URL(fileURLWithPath: previewPath), options: .atomic) - } catch { } + if Int(icon.size.width) > NCGlobal.shared.sizeIcon, Int(icon.size.height) > NCGlobal.shared.sizeIcon, + let iconResize = icon.resizeImage(size: CGSize(width: NCGlobal.shared.sizeIcon, height: NCGlobal.shared.sizeIcon)) { + do { + if let data = iconResize.jpegData(compressionQuality: 0.5) { + try data.write(to: URL(fileURLWithPath: iconPath), options: .atomic) } - return (icon, preview) - } else { - return (nil, nil) - } + } catch { } + return iconResize } - return (icon, preview) + return icon } func pdfThumbnail(url: URL, width: CGFloat = 240) -> UIImage? { From 25f8b0e1d2a482abdb4b205552d0ff094571db00 Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Mon, 15 Jul 2024 15:12:11 +0200 Subject: [PATCH 25/27] coding Signed-off-by: Marino Faggiana --- iOSClient/Media/NCMediaDataSource.swift | 4 +--- iOSClient/NCImageCache.swift | 14 ++++++-------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/iOSClient/Media/NCMediaDataSource.swift b/iOSClient/Media/NCMediaDataSource.swift index 111fa0e748..a2dfd82d7b 100644 --- a/iOSClient/Media/NCMediaDataSource.swift +++ b/iOSClient/Media/NCMediaDataSource.swift @@ -27,9 +27,7 @@ import NextcloudKit extension NCMedia { func reloadDataSource() { - let startServerUrl = NCUtilityFileSystem().getHomeServer(urlBase: activeAccount.urlBase, userId: activeAccount.userId) + activeAccount.mediaPath - let predicateBoth = NSPredicate(format: NCImageCache.shared.showBothPredicateMediaString, activeAccount.account, startServerUrl) - self.metadatas = NCManageDatabase.shared.getMediaMetadatas(predicate: self.getPredicate()) + self.metadatas = imageCache.getMediaMetadatas(account: activeAccount.account, predicate: self.getPredicate()) self.collectionViewReloadData() } diff --git a/iOSClient/NCImageCache.swift b/iOSClient/NCImageCache.swift index ee236c6e05..552d5725bd 100644 --- a/iOSClient/NCImageCache.swift +++ b/iOSClient/NCImageCache.swift @@ -84,13 +84,6 @@ class NCImageCache: NSObject { } createMediaCacheInProgress = true - func getMediaMetadatas(account: String, predicate: NSPredicate? = nil) -> ThreadSafeArray? { - guard let tableAccount = NCManageDatabase.shared.getAccount(predicate: NSPredicate(format: "account == %@", account)) else { return nil } - let startServerUrl = NCUtilityFileSystem().getHomeServer(urlBase: tableAccount.urlBase, userId: tableAccount.userId) + tableAccount.mediaPath - let predicateBoth = NSPredicate(format: showBothPredicateMediaString, account, startServerUrl) - return NCManageDatabase.shared.getMediaMetadatas(predicate: predicate ?? predicateBoth) - } - self.metadatasInfo.removeAll() self.metadatas = nil self.metadatas = getMediaMetadatas(account: account) @@ -181,7 +174,12 @@ class NCImageCache: NSObject { return self.metadatas } - + func getMediaMetadatas(account: String, predicate: NSPredicate? = nil) -> ThreadSafeArray? { + guard let tableAccount = NCManageDatabase.shared.getAccount(predicate: NSPredicate(format: "account == %@", account)) else { return nil } + let startServerUrl = NCUtilityFileSystem().getHomeServer(urlBase: tableAccount.urlBase, userId: tableAccount.userId) + tableAccount.mediaPath + let predicateBoth = NSPredicate(format: showBothPredicateMediaString, account, startServerUrl) + return NCManageDatabase.shared.getMediaMetadatas(predicate: predicate ?? predicateBoth) + } /// /// PREVIEW CACHE From af9d9f20004e84c54eb674587fd62bfbad55fd55 Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Mon, 15 Jul 2024 15:15:28 +0200 Subject: [PATCH 26/27] coding Signed-off-by: Marino Faggiana --- .../NCCollectionViewCommon+CollectionViewDataSource.swift | 2 +- iOSClient/Media/NCMediaDownloadThumbnaill.swift | 2 +- iOSClient/NCImageCache.swift | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift index 46f133f3d1..c7097c31f6 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift @@ -67,7 +67,7 @@ extension NCCollectionViewCommon: UICollectionViewDataSource { cell.filePreviewImageView?.image = image } else if let image = UIImage(contentsOfFile: self.utilityFileSystem.getDirectoryProviderStoragePreviewOcId(metadata.ocId, etag: metadata.etag)) { cell.filePreviewImageView?.image = image - NCImageCache.shared.setPreviewImageCache(ocId: metadata.ocId, etag: metadata.etag, image: image, date: metadata.date as Date) + NCImageCache.shared.addPreviewImageCache(ocId: metadata.ocId, etag: metadata.etag, image: image, date: metadata.date as Date) } } else { if let image = NCImageCache.shared.getIconImageCache(ocId: metadata.ocId, etag: metadata.etag) { diff --git a/iOSClient/Media/NCMediaDownloadThumbnaill.swift b/iOSClient/Media/NCMediaDownloadThumbnaill.swift index a526a499f6..36019f5406 100644 --- a/iOSClient/Media/NCMediaDownloadThumbnaill.swift +++ b/iOSClient/Media/NCMediaDownloadThumbnaill.swift @@ -73,7 +73,7 @@ class NCMediaDownloadThumbnaill: ConcurrentOperation { } } } - NCImageCache.shared.setPreviewSizeCache(ocId: self.metadata.ocId, etag: self.metadata.etag, size: imagePreview.size) + NCImageCache.shared.addPreviewSizeCache(ocId: self.metadata.ocId, etag: self.metadata.etag, size: imagePreview.size) } self.finish() } diff --git a/iOSClient/NCImageCache.swift b/iOSClient/NCImageCache.swift index 552d5725bd..c80919ab8d 100644 --- a/iOSClient/NCImageCache.swift +++ b/iOSClient/NCImageCache.swift @@ -184,7 +184,7 @@ class NCImageCache: NSObject { /// /// PREVIEW CACHE /// - func setPreviewImageCache(ocId: String, etag: String, image: UIImage, date: Date) { + func addPreviewImageCache(ocId: String, etag: String, image: UIImage, date: Date) { cacheImagePreview.setValue(imageInfo(image: image, size: image.size, date: date), forKey: ocId + etag) cacheSizePreview.setValue(image.size, forKey: ocId + etag) } @@ -199,7 +199,7 @@ class NCImageCache: NSObject { /// /// SIZE CACHE /// - func setPreviewSizeCache(ocId: String, etag: String, size: CGSize) { + func addPreviewSizeCache(ocId: String, etag: String, size: CGSize) { cacheSizePreview.setValue(size, forKey: ocId + etag) } From 729ec410be81b9691bd4b45bb81182ffc6f88b26 Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Mon, 15 Jul 2024 15:26:40 +0200 Subject: [PATCH 27/27] coding Signed-off-by: Marino Faggiana --- ...NCCollectionViewCommon+CollectionViewDataSource.swift | 2 +- iOSClient/Media/NCMediaDownloadThumbnaill.swift | 3 +-- iOSClient/NCImageCache.swift | 9 +++------ 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift index c7097c31f6..1eaf602dea 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift @@ -67,7 +67,7 @@ extension NCCollectionViewCommon: UICollectionViewDataSource { cell.filePreviewImageView?.image = image } else if let image = UIImage(contentsOfFile: self.utilityFileSystem.getDirectoryProviderStoragePreviewOcId(metadata.ocId, etag: metadata.etag)) { cell.filePreviewImageView?.image = image - NCImageCache.shared.addPreviewImageCache(ocId: metadata.ocId, etag: metadata.etag, image: image, date: metadata.date as Date) + NCImageCache.shared.addPreviewImageCache(metadata: metadata, image: image) } } else { if let image = NCImageCache.shared.getIconImageCache(ocId: metadata.ocId, etag: metadata.etag) { diff --git a/iOSClient/Media/NCMediaDownloadThumbnaill.swift b/iOSClient/Media/NCMediaDownloadThumbnaill.swift index 36019f5406..ab07816aaf 100644 --- a/iOSClient/Media/NCMediaDownloadThumbnaill.swift +++ b/iOSClient/Media/NCMediaDownloadThumbnaill.swift @@ -26,7 +26,6 @@ import NextcloudKit import Queuer class NCMediaDownloadThumbnaill: ConcurrentOperation { - var metadata: tableMetadata var media: NCMedia var fileNamePreviewLocalPath: String @@ -73,7 +72,7 @@ class NCMediaDownloadThumbnaill: ConcurrentOperation { } } } - NCImageCache.shared.addPreviewSizeCache(ocId: self.metadata.ocId, etag: self.metadata.etag, size: imagePreview.size) + NCImageCache.shared.addPreviewImageCache(metadata: self.metadata, image: imagePreview) } self.finish() } diff --git a/iOSClient/NCImageCache.swift b/iOSClient/NCImageCache.swift index c80919ab8d..f79f4814f4 100644 --- a/iOSClient/NCImageCache.swift +++ b/iOSClient/NCImageCache.swift @@ -184,9 +184,9 @@ class NCImageCache: NSObject { /// /// PREVIEW CACHE /// - func addPreviewImageCache(ocId: String, etag: String, image: UIImage, date: Date) { - cacheImagePreview.setValue(imageInfo(image: image, size: image.size, date: date), forKey: ocId + etag) - cacheSizePreview.setValue(image.size, forKey: ocId + etag) + func addPreviewImageCache(metadata: tableMetadata, image: UIImage) { + cacheImagePreview.setValue(imageInfo(image: image, size: image.size, date: metadata.date as Date), forKey: metadata.ocId + metadata.etag) + cacheSizePreview.setValue(image.size, forKey: metadata.ocId + metadata.etag) } func getPreviewImageCache(ocId: String, etag: String) -> UIImage? { @@ -199,9 +199,6 @@ class NCImageCache: NSObject { /// /// SIZE CACHE /// - func addPreviewSizeCache(ocId: String, etag: String, size: CGSize) { - cacheSizePreview.setValue(size, forKey: ocId + etag) - } func getPreviewSizeCache(ocId: String, etag: String) -> CGSize? { if let size = cacheSizePreview.value(forKey: ocId + etag) {