From 17dd9ddd52e92d362356b6f37ddede3b55434cfc Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Tue, 17 Sep 2024 10:33:27 +0200 Subject: [PATCH 1/4] revert Signed-off-by: Marino Faggiana --- Brand/NCBrand.swift | 3 +- ...nViewCommon+CollectionViewDataSource.swift | 204 +++++++++--------- iOSClient/NCGlobal.swift | 4 +- 3 files changed, 102 insertions(+), 109 deletions(-) diff --git a/Brand/NCBrand.swift b/Brand/NCBrand.swift index 82b64682ed..819c0ce2c1 100755 --- a/Brand/NCBrand.swift +++ b/Brand/NCBrand.swift @@ -39,7 +39,8 @@ let userAgent: String = { var textCopyrightNextcloudiOS: String = "Nextcloud Hydrogen for iOS %@ © 2024" var textCopyrightNextcloudServer: String = "Nextcloud Server %@" var loginBaseUrl: String = "https://cloud.nextcloud.com" - @objc var pushNotificationServerProxy: String = "https://push-notifications.nextcloud.com" + // @objc var pushNotificationServerProxy: String = "https://push-notifications.nextcloud.com" +@objc var pushNotificationServerProxy: String = "https://c0004.customerpush.nextcloud.com" var linkLoginHost: String = "https://nextcloud.com/install" var linkloginPreferredProviders: String = "https://nextcloud.com/signup-ios" var webLoginAutenticationProtocol: String = "nc://" // example "abc://" diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift index d8896382ad..1a1a2ab83c 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift @@ -34,6 +34,101 @@ extension NCCollectionViewCommon: UICollectionViewDataSource { return self.dataSource.numberOfItemsInSection(section) } + func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) { + guard let metadata = self.dataSource.getMetadata(indexPath: indexPath), + let cell = (cell as? NCCellProtocol) else { return } + let existsPreview = utility.existsImage(ocId: metadata.ocId, etag: metadata.etag, ext: NCGlobal.shared.previewExt1024) + let ext = global.getSizeExtension(width: self.sizeImage.width) + + func downloadAvatar(fileName: String, user: String, dispalyName: String?) { + if let image = database.getImageAvatarLoaded(fileName: fileName) { + cell.fileAvatarImageView?.contentMode = .scaleAspectFill + cell.fileAvatarImageView?.image = image + } else { + NCNetworking.shared.downloadAvatar(user: user, dispalyName: dispalyName, fileName: fileName, account: metadata.account, cell: cell, view: collectionView) + } + } + /// CONTENT MODE + cell.filePreviewImageView?.layer.borderWidth = 0 + if isLayoutPhoto { + if metadata.isImageOrVideo, existsPreview { + cell.filePreviewImageView?.contentMode = .scaleAspectFill + } else { + cell.filePreviewImageView?.contentMode = .scaleAspectFit + } + } else { + if existsPreview { + cell.filePreviewImageView?.contentMode = .scaleAspectFill + } else { + cell.filePreviewImageView?.contentMode = .scaleAspectFit + } + } + cell.fileAvatarImageView?.contentMode = .center + /// THUMBNAIL + if !metadata.directory { + if metadata.hasPreviewBorder { + cell.filePreviewImageView?.layer.borderWidth = 0.2 + cell.filePreviewImageView?.layer.borderColor = UIColor.lightGray.cgColor + } + + if metadata.name == global.appName { + + if let image = NCImageCache.shared.getImageCache(ocId: metadata.ocId, etag: metadata.etag, ext: ext) { + cell.filePreviewImageView?.image = image + } else if let image = utility.getImage(ocId: metadata.ocId, etag: metadata.etag, ext: ext) { + cell.filePreviewImageView?.image = image + } + + if cell.filePreviewImageView?.image == nil { + if metadata.iconName.isEmpty { + cell.filePreviewImageView?.image = NCImageCache.shared.getImageFile() + } else { + cell.filePreviewImageView?.image = utility.loadImage(named: metadata.iconName, useTypeIconFile: true, account: metadata.account) + } + if metadata.hasPreview && metadata.status == global.metadataStatusNormal && !existsPreview { + for case let operation as NCCollectionViewDownloadThumbnail in NCNetworking.shared.downloadThumbnailQueue.operations where operation.metadata.ocId == metadata.ocId { return } + NCNetworking.shared.downloadThumbnailQueue.addOperation(NCCollectionViewDownloadThumbnail(metadata: metadata, collectionView: collectionView, ext: NCGlobal.shared.getSizeExtension(width: self.sizeImage.width))) + } + } + } else { + /// APP NAME - UNIFIED SEARCH + switch metadata.iconName { + case let str where str.contains("contacts"): + cell.filePreviewImageView?.image = utility.loadImage(named: "person.crop.rectangle.stack", colors: [NCBrandColor.shared.iconImageColor]) + case let str where str.contains("conversation"): + cell.filePreviewImageView?.image = UIImage(named: "talk-template")!.image(color: NCBrandColor.shared.getElement(account: metadata.account)) + case let str where str.contains("calendar"): + cell.filePreviewImageView?.image = utility.loadImage(named: "calendar", colors: [NCBrandColor.shared.iconImageColor]) + case let str where str.contains("deck"): + cell.filePreviewImageView?.image = utility.loadImage(named: "square.stack.fill", colors: [NCBrandColor.shared.iconImageColor]) + case let str where str.contains("mail"): + cell.filePreviewImageView?.image = utility.loadImage(named: "mail", colors: [NCBrandColor.shared.iconImageColor]) + case let str where str.contains("talk"): + cell.filePreviewImageView?.image = UIImage(named: "talk-template")!.image(color: NCBrandColor.shared.getElement(account: metadata.account)) + case let str where str.contains("confirm"): + cell.filePreviewImageView?.image = utility.loadImage(named: "arrow.right", colors: [NCBrandColor.shared.iconImageColor]) + case let str where str.contains("pages"): + cell.filePreviewImageView?.image = utility.loadImage(named: "doc.richtext", colors: [NCBrandColor.shared.iconImageColor]) + default: + cell.filePreviewImageView?.image = utility.loadImage(named: "doc", colors: [NCBrandColor.shared.iconImageColor]) + } + if !metadata.iconUrl.isEmpty { + if let ownerId = getAvatarFromIconUrl(metadata: metadata) { + let fileName = NCSession.shared.getFileName(urlBase: metadata.urlBase, user: ownerId) + downloadAvatar(fileName: fileName, user: ownerId, dispalyName: nil) + } + } + } + } + /// AVATAR + if !metadata.ownerId.isEmpty, + metadata.ownerId != metadata.userId { + // appDelegate.account == metadata.account { + let fileName = NCSession.shared.getFileName(urlBase: metadata.urlBase, user: metadata.ownerId) + downloadAvatar(fileName: fileName, user: metadata.ownerId, dispalyName: metadata.ownerDisplayName) + } + } + func collectionView(_ collectionView: UICollectionView, didEndDisplaying cell: UICollectionViewCell, forItemAt indexPath: IndexPath) { if !collectionView.indexPathsForVisibleItems.contains(indexPath) { guard let metadata = self.dataSource.getMetadata(indexPath: indexPath) else { return } @@ -49,18 +144,7 @@ extension NCCollectionViewCommon: UICollectionViewDataSource { var isShare = false var isMounted = false var a11yValues: [String] = [] - let ext = NCGlobal.shared.getSizeExtension(width: self.sizeImage.width) let metadata = self.dataSource.getMetadata(indexPath: indexPath) ?? tableMetadata() - let existsPreview = utility.existsImage(ocId: metadata.ocId, etag: metadata.etag, ext: NCGlobal.shared.previewExt1024) - - func downloadAvatar(fileName: String, user: String, dispalyName: String?) { - if let image = database.getImageAvatarLoaded(fileName: fileName) { - cell.fileAvatarImageView?.contentMode = .scaleAspectFill - cell.fileAvatarImageView?.image = image - } else { - NCNetworking.shared.downloadAvatar(user: user, dispalyName: dispalyName, fileName: fileName, account: metadata.account, cell: cell, view: collectionView) - } - } // LAYOUT PHOTO if isLayoutPhoto { @@ -84,8 +168,7 @@ extension NCCollectionViewCommon: UICollectionViewDataSource { listCell.listCellDelegate = self cell = listCell } - guard let metadata = self.dataSource.getMetadata(indexPath: indexPath), - let filePreviewImageView = cell.filePreviewImageView else { return cell } + guard let metadata = self.dataSource.getMetadata(indexPath: indexPath) else { return cell } defer { if !metadata.isSharable() || NCCapabilities.shared.disableSharesView(account: metadata.account) { @@ -103,6 +186,8 @@ extension NCCollectionViewCommon: UICollectionViewDataSource { cell.fileFavoriteImage?.image = nil cell.fileSharedImage?.image = nil cell.fileMoreImage?.image = nil + cell.filePreviewImageView?.image = nil + cell.filePreviewImageView?.backgroundColor = nil cell.fileAccount = metadata.account cell.fileOcId = metadata.ocId cell.fileOcIdTransfer = metadata.ocIdTransfer @@ -120,23 +205,6 @@ extension NCCollectionViewCommon: UICollectionViewDataSource { cell.titleInfoTrailingDefault() - /// CONTENT MODE - /// - filePreviewImageView.layer.borderWidth = 0 - if isLayoutPhoto { - if metadata.isImageOrVideo, existsPreview { - filePreviewImageView.contentMode = .scaleAspectFill - } else { - filePreviewImageView.contentMode = .scaleAspectFit - } - } else { - if existsPreview { - filePreviewImageView.contentMode = .scaleAspectFill - } else { - filePreviewImageView.contentMode = .scaleAspectFit - } - } - if isSearchingMode { cell.fileTitleLabel?.text = metadata.fileName cell.fileTitleLabel?.lineBreakMode = .byTruncatingTail @@ -191,73 +259,6 @@ extension NCCollectionViewCommon: UICollectionViewDataSource { // color folder cell.filePreviewImageView?.image = cell.filePreviewImageView?.image?.colorizeFolder(metadata: metadata, tableDirectory: tableDirectory) } else { - - /// THUMBNAIL - /// - filePreviewImageView.image = nil - - if metadata.hasPreviewBorder { - filePreviewImageView.layer.borderWidth = 0.2 - filePreviewImageView.layer.borderColor = UIColor.lightGray.cgColor - } - - if metadata.name == global.appName { - var image = self.imageCache.getImageCache(ocId: metadata.ocId, etag: metadata.etag, ext: ext) - - if image == nil { - image = self.utility.getImage(ocId: metadata.ocId, etag: metadata.etag, ext: ext) - if let image { - self.imageCache.addImageCache(ocId: metadata.ocId, etag: metadata.etag, image: image, ext: ext) - } else { - if metadata.iconName.isEmpty { - image = self.imageCache.getImageFile() - } else { - image = self.utility.loadImage(named: metadata.iconName, useTypeIconFile: true, account: metadata.account) - } - if metadata.hasPreview, - metadata.status == self.global.metadataStatusNormal, - !existsPreview, - NCNetworking.shared.downloadThumbnailQueue.operations.filter({ ($0 as? NCMediaDownloadThumbnail)?.metadata.ocId == metadata.ocId }).isEmpty { - - NCNetworking.shared.downloadThumbnailQueue.addOperation(NCCollectionViewDownloadThumbnail(metadata: metadata, collectionView: collectionView, ext: ext)) - } - } - } - - filePreviewImageView.image = image - - } else { - - /// APP NAME - UNIFIED SEARCH - /// - switch metadata.iconName { - case let str where str.contains("contacts"): - filePreviewImageView.image = utility.loadImage(named: "person.crop.rectangle.stack", colors: [NCBrandColor.shared.iconImageColor]) - case let str where str.contains("conversation"): - filePreviewImageView.image = UIImage(named: "talk-template")!.image(color: NCBrandColor.shared.getElement(account: metadata.account)) - case let str where str.contains("calendar"): - filePreviewImageView.image = utility.loadImage(named: "calendar", colors: [NCBrandColor.shared.iconImageColor]) - case let str where str.contains("deck"): - filePreviewImageView.image = utility.loadImage(named: "square.stack.fill", colors: [NCBrandColor.shared.iconImageColor]) - case let str where str.contains("mail"): - filePreviewImageView.image = utility.loadImage(named: "mail", colors: [NCBrandColor.shared.iconImageColor]) - case let str where str.contains("talk"): - filePreviewImageView.image = UIImage(named: "talk-template")!.image(color: NCBrandColor.shared.getElement(account: metadata.account)) - case let str where str.contains("confirm"): - filePreviewImageView.image = utility.loadImage(named: "arrow.right", colors: [NCBrandColor.shared.iconImageColor]) - case let str where str.contains("pages"): - filePreviewImageView.image = utility.loadImage(named: "doc.richtext", colors: [NCBrandColor.shared.iconImageColor]) - default: - filePreviewImageView.image = utility.loadImage(named: "doc", colors: [NCBrandColor.shared.iconImageColor]) - } - if !metadata.iconUrl.isEmpty { - if let ownerId = getAvatarFromIconUrl(metadata: metadata) { - let fileName = NCSession.shared.getFileName(urlBase: metadata.urlBase, user: ownerId) - downloadAvatar(fileName: fileName, user: ownerId, dispalyName: nil) - } - } - } - let tableLocalFile = database.getResultsTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))?.first // image local if let tableLocalFile, tableLocalFile.offline { @@ -268,15 +269,6 @@ extension NCCollectionViewCommon: UICollectionViewDataSource { } } - // avatar - cell.fileAvatarImageView?.contentMode = .center - if !metadata.ownerId.isEmpty, - metadata.ownerId != metadata.userId { - // appDelegate.account == metadata.account { - let fileName = NCSession.shared.getFileName(urlBase: metadata.urlBase, user: metadata.ownerId) - downloadAvatar(fileName: fileName, user: metadata.ownerId, dispalyName: metadata.ownerDisplayName) - } - // image Favorite if metadata.favorite { cell.fileFavoriteImage?.image = imageCache.getImageFavorite() diff --git a/iOSClient/NCGlobal.swift b/iOSClient/NCGlobal.swift index 9692cbc0fa..9c13c2f2b8 100644 --- a/iOSClient/NCGlobal.swift +++ b/iOSClient/NCGlobal.swift @@ -102,9 +102,9 @@ class NCGlobal: NSObject { guard let width else { return previewExt512 } switch (width * 3) { - case 0...120: + case 0...119: return previewExt64 - case 121...192: + case 120...192: return previewExt128 case 193...384: return previewExt256 From d2166462c88d465a4c6b05c44e37e1782e8d1303 Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Tue, 17 Sep 2024 10:42:31 +0200 Subject: [PATCH 2/4] fix Signed-off-by: Marino Faggiana --- ...tionViewCommon+CollectionViewDataSourcePrefetching.swift | 5 ++--- .../Main/Collection Common/NCCollectionViewDataSource.swift | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSourcePrefetching.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSourcePrefetching.swift index 9368d2ea55..9fcfb24b85 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSourcePrefetching.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSourcePrefetching.swift @@ -13,11 +13,10 @@ extension NCCollectionViewCommon: UICollectionViewDataSourcePrefetching { func collectionView(_ collectionView: UICollectionView, prefetchItemsAt indexPaths: [IndexPath]) { guard !isSearchingMode else { return } let ext = global.getSizeExtension(width: self.sizeImage.width) + let metadatas = self.dataSource.getMetadatas(indexPaths: indexPaths) DispatchQueue.global(qos: .userInteractive).async { - let metadatas = self.dataSource.getResultMetadatas(indexPaths: indexPaths) - - metadatas.forEach { metadata in + for metadata in metadatas where metadata.isImageOrVideo { if self.imageCache.getImageCache(ocId: metadata.ocId, etag: metadata.etag, ext: ext) == nil, let image = self.utility.getImage(ocId: metadata.ocId, etag: metadata.etag, ext: ext) { self.imageCache.addImageCache(ocId: metadata.ocId, etag: metadata.etag, image: image, ext: ext) diff --git a/iOSClient/Main/Collection Common/NCCollectionViewDataSource.swift b/iOSClient/Main/Collection Common/NCCollectionViewDataSource.swift index 54de1cc132..bca7d8d527 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewDataSource.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewDataSource.swift @@ -255,13 +255,13 @@ class NCCollectionViewDataSource: NSObject { return nil } - func getResultMetadatas(indexPaths: [IndexPath]) -> [tableMetadata] { + func getMetadatas(indexPaths: [IndexPath]) -> [tableMetadata] { var metadatas: [tableMetadata] = [] - let validMetadatas = metadatas.filter { !$0.isInvalidated } + let validMetadatas = self.metadatas.filter { !$0.isInvalidated } for indexPath in indexPaths { if indexPath.row < validMetadatas.count { - metadatas.append(validMetadatas[indexPath.row]) + metadatas.append(tableMetadata(value: validMetadatas[indexPath.row])) } } return metadatas From ba20cf2e5a6bab66ca85cdfd8781a820c8aaf9d3 Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Tue, 17 Sep 2024 10:53:08 +0200 Subject: [PATCH 3/4] licence Signed-off-by: Marino Faggiana --- ...mmon+CollectionViewDataSourcePrefetching.swift | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSourcePrefetching.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSourcePrefetching.swift index 9fcfb24b85..2bb9a3e211 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSourcePrefetching.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSourcePrefetching.swift @@ -5,6 +5,21 @@ // Created by Marino Faggiana on 16/09/24. // 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 Foundation import UIKit From 4ee44d2b1d079929c33366756d25092c79bdc1d4 Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Tue, 17 Sep 2024 11:33:22 +0200 Subject: [PATCH 4/4] cod Signed-off-by: Marino Faggiana --- Brand/NCBrand.swift | 3 +-- iOSClient/Data/NCManageDatabase.swift | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Brand/NCBrand.swift b/Brand/NCBrand.swift index 819c0ce2c1..82b64682ed 100755 --- a/Brand/NCBrand.swift +++ b/Brand/NCBrand.swift @@ -39,8 +39,7 @@ let userAgent: String = { var textCopyrightNextcloudiOS: String = "Nextcloud Hydrogen for iOS %@ © 2024" var textCopyrightNextcloudServer: String = "Nextcloud Server %@" var loginBaseUrl: String = "https://cloud.nextcloud.com" - // @objc var pushNotificationServerProxy: String = "https://push-notifications.nextcloud.com" -@objc var pushNotificationServerProxy: String = "https://c0004.customerpush.nextcloud.com" + @objc var pushNotificationServerProxy: String = "https://push-notifications.nextcloud.com" var linkLoginHost: String = "https://nextcloud.com/install" var linkloginPreferredProviders: String = "https://nextcloud.com/signup-ios" var webLoginAutenticationProtocol: String = "nc://" // example "abc://" diff --git a/iOSClient/Data/NCManageDatabase.swift b/iOSClient/Data/NCManageDatabase.swift index 273031ca34..a273692e5f 100644 --- a/iOSClient/Data/NCManageDatabase.swift +++ b/iOSClient/Data/NCManageDatabase.swift @@ -63,7 +63,8 @@ class NCManageDatabase: NSObject { let bundlePathExtension: String = bundleUrl.pathExtension let bundleFileName: String = (bundleUrl.path as NSString).lastPathComponent let isAppex: Bool = bundlePathExtension == "appex" - var objectTypesAppex = [tableMetadata.self, + var objectTypesAppex = [NCKeyValue.self, + tableMetadata.self, tableLocalFile.self, tableDirectory.self, tableTag.self,