diff --git a/Nextcloud.xcodeproj/project.pbxproj b/Nextcloud.xcodeproj/project.pbxproj index 7821d41ee7..4b68394076 100644 --- a/Nextcloud.xcodeproj/project.pbxproj +++ b/Nextcloud.xcodeproj/project.pbxproj @@ -12,7 +12,7 @@ 2C33C48223E2C475005F963B /* NotificationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C33C48123E2C475005F963B /* NotificationService.swift */; }; 2C33C48623E2C475005F963B /* Notification Service Extension.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = 2C33C47F23E2C475005F963B /* Notification Service Extension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; 2F96A1BAFB10ACFEAC68EF1C /* NCContextMenuPlayerTracks.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4C7A5B36D1ED178FB6B76CB /* NCContextMenuPlayerTracks.swift */; }; - 370D26AF248A3D7A00121797 /* NCCellProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 370D26AE248A3D7A00121797 /* NCCellProtocol.swift */; }; + 370D26AF248A3D7A00121797 /* NCCellMain.swift in Sources */ = {isa = PBXBuildFile; fileRef = 370D26AE248A3D7A00121797 /* NCCellMain.swift */; }; A5A87F9E4B0E4441A6A4BC20 /* NCContextMenuProfile.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB7697C94BA14450A0867940 /* NCContextMenuProfile.swift */; }; AA3C85E82D36B08C00F74F12 /* UITestBackend.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA3C85E72D36B08C00F74F12 /* UITestBackend.swift */; }; AA3C85EB2D36BBFB00F74F12 /* OCSResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA3C85EA2D36BBF400F74F12 /* OCSResponse.swift */; }; @@ -871,7 +871,7 @@ F7EB9B132BBC12F300EDF036 /* UIApplication+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7EB9B122BBC12F300EDF036 /* UIApplication+Extension.swift */; }; F7ED547C25EEA65400956C55 /* QRCodeReader in Frameworks */ = {isa = PBXBuildFile; productRef = F7ED547B25EEA65400956C55 /* QRCodeReader */; }; F7EDE4D6262D7B9600414FE6 /* NCListCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = F78ACD4121903CE00088454D /* NCListCell.swift */; }; - F7EDE4DB262D7BA200414FE6 /* NCCellProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 370D26AE248A3D7A00121797 /* NCCellProtocol.swift */; }; + F7EDE4DB262D7BA200414FE6 /* NCCellMain.swift in Sources */ = {isa = PBXBuildFile; fileRef = 370D26AE248A3D7A00121797 /* NCCellMain.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 */; }; F7EDE51B262DD0C400414FE6 /* NCSelectCommandViewCopyMove.xib in Resources */ = {isa = PBXBuildFile; fileRef = F7EDE51A262DD0C400414FE6 /* NCSelectCommandViewCopyMove.xib */; }; @@ -1106,7 +1106,7 @@ 2C33C47F23E2C475005F963B /* Notification Service Extension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = "Notification Service Extension.appex"; sourceTree = BUILT_PRODUCTS_DIR; }; 2C33C48123E2C475005F963B /* NotificationService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationService.swift; sourceTree = ""; }; 2C33C48A23E2CC26005F963B /* Notification_Service_Extension-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Notification_Service_Extension-Bridging-Header.h"; sourceTree = ""; }; - 370D26AE248A3D7A00121797 /* NCCellProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCCellProtocol.swift; sourceTree = ""; }; + 370D26AE248A3D7A00121797 /* NCCellMain.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCCellMain.swift; sourceTree = ""; }; 8932E90EC4278026D86CCCC9 /* NCContextMenuComment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCContextMenuComment.swift; sourceTree = ""; }; AA3C85E72D36B08C00F74F12 /* UITestBackend.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UITestBackend.swift; sourceTree = ""; }; AA3C85EA2D36BBF400F74F12 /* OCSResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OCSResponse.swift; sourceTree = ""; }; @@ -2457,12 +2457,12 @@ F75FE06B2BB01D0D00A0EFEF /* Cell */ = { isa = PBXGroup; children = ( - 370D26AE248A3D7A00121797 /* NCCellProtocol.swift */, + 370D26AE248A3D7A00121797 /* NCCellMain.swift */, + F78ACD4121903CE00088454D /* NCListCell.swift */, F78ACD3F21903CC20088454D /* NCGridCell.swift */, + F751247A2C42919C00E63DB8 /* NCPhotoCell.swift */, F78ACD4521903D010088454D /* NCGridCell.xib */, - F78ACD4121903CE00088454D /* NCListCell.swift */, F78ACD4321903CF20088454D /* NCListCell.xib */, - F751247A2C42919C00E63DB8 /* NCPhotoCell.swift */, F751247B2C42919C00E63DB8 /* NCPhotoCell.xib */, F75D901E2D2BE12E003E740B /* NCRecommendationsCell.xib */, F75D90202D2BE26C003E740B /* NCRecommendationsCell.swift */, @@ -2475,7 +2475,6 @@ isa = PBXGroup; children = ( F75FE06B2BB01D0D00A0EFEF /* Cell */, - F78ACD50219046AC0088454D /* Section Header Footer */, F70D7C3525FFBF81002B9E34 /* NCCollectionViewCommon.swift */, F7CAFE172F164B9200DB35A5 /* NCCollectionViewCommon+CellDelegate.swift */, F7743A132C33F13A0034F670 /* NCCollectionViewCommon+CollectionViewDataSource.swift */, @@ -2485,14 +2484,15 @@ F7D890742BD25C570050B8A6 /* NCCollectionViewCommon+DragDrop.swift */, F799DF872C4B83CC003410B5 /* NCCollectionViewCommon+EasyTipView.swift */, F799DF8A2C4B84EB003410B5 /* NCCollectionViewCommon+EndToEndInitialize.swift */, - F7865FF02F39D32500D09AE4 /* NCCollectionViewCommon+Search.swift */, - F7CCAB502ECF315F00F8E68B /* NCCollectionViewCommon+SyncMetadata.swift */, F778231D2C42C07C001BB94F /* NCCollectionViewCommon+MediaLayout.swift */, + F7865FF02F39D32500D09AE4 /* NCCollectionViewCommon+Search.swift */, F36E64F62B9245210085ABB5 /* NCCollectionViewCommon+SelectTabBarDelegate.swift */, + F7CCAB502ECF315F00F8E68B /* NCCollectionViewCommon+SyncMetadata.swift */, F7D4BF002CA1831600A5E746 /* NCCollectionViewCommonPinchGesture.swift */, F38F71242B6BBDC300473CDC /* NCCollectionViewCommonSelectTabBar.swift */, F7C1EEA425053A9C00866ACC /* NCCollectionViewDataSource.swift */, F7E7AEA42BA32C6500512E52 /* NCCollectionViewDownloadThumbnail.swift */, + F78ACD50219046AC0088454D /* Section Header Footer */, ); path = "Collection Common"; sourceTree = ""; @@ -4244,7 +4244,7 @@ F799DF862C4B7E56003410B5 /* NCSectionHeader.swift in Sources */, F702F2D025EE5B5C008F8E80 /* NCGlobal.swift in Sources */, F72437802C10B92400C7C68D /* NCSharePermissions.swift in Sources */, - F7EDE4DB262D7BA200414FE6 /* NCCellProtocol.swift in Sources */, + F7EDE4DB262D7BA200414FE6 /* NCCellMain.swift in Sources */, F72944F62A8424F800246839 /* NCEndToEndMetadataV1.swift in Sources */, F73EF7BA2B0224AB0087E6E9 /* NCManageDatabase+ExternalSites.swift in Sources */, F711A4EB2AF9327D00095DD8 /* UIImage+animatedGIF.m in Sources */, @@ -4414,7 +4414,7 @@ F702F30825EE5D47008F8E80 /* NCPopupViewController.swift in Sources */, F76340FC2EBDF64D0056F538 /* NCManageDatabase+Tag.swift in Sources */, F733598125C1C188002ABA72 /* NCAskAuthorization.swift in Sources */, - 370D26AF248A3D7A00121797 /* NCCellProtocol.swift in Sources */, + 370D26AF248A3D7A00121797 /* NCCellMain.swift in Sources */, F32FADA92D1176E3007035E2 /* UIButton+Extension.swift in Sources */, F7DF7B3F2F1A2EF900514020 /* BannerView.swift in Sources */, F768822C2C0DD1E7001CF441 /* NCPreferences.swift in Sources */, @@ -5747,7 +5747,7 @@ CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 4; + CURRENT_PROJECT_VERSION = 5; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = NKUJUXUJ3B; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -5813,7 +5813,7 @@ CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 4; + CURRENT_PROJECT_VERSION = 5; DEVELOPMENT_TEAM = NKUJUXUJ3B; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; diff --git a/Share/NCShareExtension+DataSource.swift b/Share/NCShareExtension+DataSource.swift index f45ca5e0a0..5cb80c8e74 100644 --- a/Share/NCShareExtension+DataSource.swift +++ b/Share/NCShareExtension+DataSource.swift @@ -86,7 +86,7 @@ extension NCShareExtension: UICollectionViewDataSource { cell.labelTitle.textColor = NCBrandColor.shared.textColor cell.imageSelect.image = nil cell.imageStatus.image = nil - cell.imageLocal.image = nil + cell.imageLocal?.image = nil cell.imageFavorite.image = nil cell.imageShared.image = nil cell.imageMore.image = nil @@ -153,7 +153,7 @@ extension NCShareExtension: UICollectionViewDataSource { // Local image: offline if tableDirectory != nil && tableDirectory!.offline { - cell.imageLocal.image = NCImageCache.shared.getImageOfflineFlag() + cell.imageLocal?.image = NCImageCache.shared.getImageOfflineFlag() } } } diff --git a/iOSClient/Account/Account Request/NCShareAccounts.swift b/iOSClient/Account/Account Request/NCShareAccounts.swift index fd1a286695..c0c2142aea 100644 --- a/iOSClient/Account/Account Request/NCShareAccounts.swift +++ b/iOSClient/Account/Account Request/NCShareAccounts.swift @@ -65,7 +65,6 @@ extension NCShareAccounts: UITableViewDelegate { } extension NCShareAccounts: UITableViewDataSource { - func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return accounts.count } diff --git a/iOSClient/Activity/NCActivity.swift b/iOSClient/Activity/NCActivity.swift index 9959cf54c6..2dc793228a 100644 --- a/iOSClient/Activity/NCActivity.swift +++ b/iOSClient/Activity/NCActivity.swift @@ -223,9 +223,9 @@ extension NCActivity: UITableViewDataSource { let results = NCManageDatabase.shared.getImageAvatarLoaded(fileName: fileName) if results.image == nil { - cell.avatarImageView?.image = utility.loadUserImage(for: comment.actorId, displayName: comment.actorDisplayName, urlBase: NCSession.shared.getSession(account: account).urlBase) + cell.avatarImage?.image = utility.loadUserImage(for: comment.actorId, displayName: comment.actorDisplayName, urlBase: NCSession.shared.getSession(account: account).urlBase) } else { - cell.avatarImageView?.image = results.image + cell.avatarImage?.image = results.image } if let tblAvatar = results.tblAvatar, @@ -264,7 +264,7 @@ extension NCActivity: UITableViewDataSource { cell.idActivity = activity.idActivity cell.account = activity.account - cell.indexPath = indexPath + cell.index = indexPath cell.avatar.image = nil cell.avatar.isHidden = true cell.didSelectItemEnable = self.didSelectItemEnable @@ -288,7 +288,7 @@ extension NCActivity: UITableViewDataSource { // avatar if !activity.user.isEmpty && activity.user != session.userId { cell.avatar.isHidden = false - cell.fileUser = activity.user + cell.user = activity.user cell.subjectLeadingConstraint.constant = 15 cell.configureAvatarMenu() @@ -296,9 +296,9 @@ extension NCActivity: UITableViewDataSource { let results = NCManageDatabase.shared.getImageAvatarLoaded(fileName: fileName) if results.image == nil { - cell.avatarImageView?.image = utility.loadUserImage(for: activity.user, displayName: nil, urlBase: session.urlBase) + cell.avatar?.image = utility.loadUserImage(for: activity.user, displayName: nil, urlBase: session.urlBase) } else { - cell.avatarImageView?.image = results.image + cell.avatar?.image = results.image } if !(results.tblAvatar?.loaded ?? false), diff --git a/iOSClient/Activity/NCActivityTableViewCell.swift b/iOSClient/Activity/NCActivityTableViewCell.swift index 67df203544..35bd4932f0 100644 --- a/iOSClient/Activity/NCActivityTableViewCell.swift +++ b/iOSClient/Activity/NCActivityTableViewCell.swift @@ -14,15 +14,15 @@ class NCActivityCollectionViewCell: UICollectionViewCell { var indexPath = IndexPath() } -class NCActivityTableViewCell: UITableViewCell, NCCellProtocol { +class NCActivityTableViewCell: UITableViewCell { @IBOutlet weak var icon: UIImageView! @IBOutlet weak var avatar: UIImageView! @IBOutlet weak var subject: UILabel! @IBOutlet weak var subjectLeadingConstraint: NSLayoutConstraint! - private var user: String = "" - private var index = IndexPath() - private var avatarButton: UIButton! + var user: String = "" + var index = IndexPath() + var avatarButton: UIButton! var idActivity: Int = 0 var activityPreviews: [tableActivityPreview] = [] @@ -32,18 +32,6 @@ class NCActivityTableViewCell: UITableViewCell, NCCellProtocol { var account: String! let utility = NCUtility() - var indexPath: IndexPath { - get { return index } - set { index = newValue } - } - var avatarImageView: UIImageView? { - return avatar - } - var fileUser: String? { - get { return user } - set { user = newValue ?? "" } - } - override func awakeFromNib() { super.awakeFromNib() @@ -61,13 +49,9 @@ class NCActivityTableViewCell: UITableViewCell, NCCellProtocol { } func configureAvatarMenu() { - guard let fileUser = fileUser else { - avatarButton.menu = nil - return - } let session = NCSession.shared.getSession(account: account) - avatarButton.menu = NCContextMenuProfile(userId: fileUser, session: session, viewController: viewController).viewMenu() + avatarButton.menu = NCContextMenuProfile(userId: user, session: session, viewController: viewController).viewMenu() } } diff --git a/iOSClient/Assistant/Models/NCAssistantModel.swift b/iOSClient/Assistant/Models/NCAssistantModel.swift index a4f34f0a34..dd99f16704 100644 --- a/iOSClient/Assistant/Models/NCAssistantModel.swift +++ b/iOSClient/Assistant/Models/NCAssistantModel.swift @@ -60,6 +60,7 @@ class NCAssistantModel: ObservableObject { selectedTask = task isLoading = true + /* if useV2 { NextcloudKit.shared.textProcessingGetTasksV2(taskType: task.type ?? "", account: session.account, completion: { _, _, _, error in handle(task: task, error: error) @@ -71,6 +72,7 @@ class NCAssistantModel: ObservableObject { handle(task: taskV2, error: error) } } + */ func handle(task: AssistantTask?, error: NKError?) { self.isLoading = false @@ -87,6 +89,7 @@ class NCAssistantModel: ObservableObject { func scheduleTask(input: String) { isLoading = true + /* if useV2 { guard let selectedType else { return } NextcloudKit.shared.textProcessingScheduleV2(input: input, taskType: selectedType, account: session.account) { _, task, _, error in @@ -98,6 +101,7 @@ class NCAssistantModel: ObservableObject { handle(task: taskV2, error: error) } } + */ func handle(task: AssistantTask?, error: NKError?) { self.isLoading = false @@ -117,6 +121,7 @@ class NCAssistantModel: ObservableObject { func deleteTask(_ task: AssistantTask) { isLoading = true + /* if useV2 { NextcloudKit.shared.textProcessingDeleteTaskV2(taskId: task.id, account: session.account) { _, _, error in handle(task: task, error: error) @@ -126,6 +131,7 @@ class NCAssistantModel: ObservableObject { handle(task: task, error: error) } } + */ func handle(task: AssistantTask, error: NKError?) { self.isLoading = false @@ -148,6 +154,7 @@ class NCAssistantModel: ObservableObject { private func loadAllTypes() { isLoading = true + /* if useV2 { NextcloudKit.shared.textProcessingGetTypesV2(account: session.account) { _, types, _, error in handle(types: types, error: error) @@ -160,6 +167,7 @@ class NCAssistantModel: ObservableObject { handle(types: typesV2, error: error) } } + */ func handle(types: [TaskTypeData]?, error: NKError) { self.isLoading = false @@ -184,6 +192,7 @@ class NCAssistantModel: ObservableObject { private func loadAllTasks(appId: String = "assistant", type: TaskTypeData?) { isLoading = true + /* if useV2 { NextcloudKit.shared.textProcessingGetTasksV2(taskType: type?.id ?? "", account: session.account) { _, tasks, _, error in guard let tasks = tasks?.tasks.filter({ $0.appId == "assistant" }) else { return } @@ -195,6 +204,7 @@ class NCAssistantModel: ObservableObject { handle(tasks: NKTextProcessingTask.toV2(tasks: tasks).tasks, error: error) } } + */ func handle(tasks: [AssistantTask], error: NKError?) { isLoading = false diff --git a/iOSClient/GUI/Lucid Banner/BannerView.swift b/iOSClient/GUI/Lucid Banner/BannerView.swift index a6815a88ed..90ad6db9c8 100644 --- a/iOSClient/GUI/Lucid Banner/BannerView.swift +++ b/iOSClient/GUI/Lucid Banner/BannerView.swift @@ -393,4 +393,3 @@ struct MessageBannerView: View { .padding() } } - diff --git a/iOSClient/Main/Collection Common/Cell/NCCellMain.swift b/iOSClient/Main/Collection Common/Cell/NCCellMain.swift new file mode 100644 index 0000000000..82d5d1b68b --- /dev/null +++ b/iOSClient/Main/Collection Common/Cell/NCCellMain.swift @@ -0,0 +1,206 @@ +// SPDX-FileCopyrightText: Nextcloud GmbH +// SPDX-FileCopyrightText: 2020 Marino Faggiana +// SPDX-License-Identifier: GPL-3.0-or-later + +import Foundation +import UIKit +import NextcloudKit +import RealmSwift + +protocol NCCellMainProtocol { + var metadata: tableMetadata? {get set } + var avatarImg: UIImageView? { get } + var previewImg: UIImageView? { get set } + var localImg: UIImageView? { get set } + var statusImg: UIImageView? { get set } + var infoLbl: UILabel? { get set } + +} + +extension NCCellMainProtocol { + var metadata: tableMetadata? { + get { return nil } + set {} + } + var avatarImg: UIImageView? { + get { return nil } + set {} + } + var previewImg: UIImageView? { + get { return nil } + set {} + } + var localImg: UIImageView? { + get { return nil } + set {} + } + var statusImg: UIImageView? { + get { return nil } + set {} + } + var infoLbl: UILabel? { + get { return nil } + set {} + } +} + +#if !EXTENSION +extension NCCollectionViewCommon { + func cellMainStatus(cell: NCCellMainProtocol, + metadata: tableMetadata, + a11yValues: inout [String]) { + if metadata.isLivePhoto { + cell.statusImg?.image = utility.loadImage(named: "livephoto", colors: [NCBrandColor.shared.iconImageColor]) + a11yValues.append(NSLocalizedString("_upload_mov_livephoto_", comment: "")) + } else if metadata.isVideo { + cell.statusImg?.image = utility.loadImage(named: "play.circle.fill", colors: [.systemBackgroundInverted, .systemGray5]) + } + + switch metadata.status { + case global.metadataStatusWaitCreateFolder: + cell.statusImg?.image = utility.loadImage(named: "arrow.triangle.2.circlepath", colors: NCBrandColor.shared.iconImageMultiColors) + cell.infoLbl?.text = NSLocalizedString("_status_wait_create_folder_", comment: "") + case global.metadataStatusWaitFavorite: + cell.statusImg?.image = utility.loadImage(named: "star.circle", colors: NCBrandColor.shared.iconImageMultiColors) + cell.infoLbl?.text = NSLocalizedString("_status_wait_favorite_", comment: "") + case global.metadataStatusWaitCopy: + cell.statusImg?.image = utility.loadImage(named: "c.circle", colors: NCBrandColor.shared.iconImageMultiColors) + cell.infoLbl?.text = NSLocalizedString("_status_wait_copy_", comment: "") + case global.metadataStatusWaitMove: + cell.statusImg?.image = utility.loadImage(named: "m.circle", colors: NCBrandColor.shared.iconImageMultiColors) + cell.infoLbl?.text = NSLocalizedString("_status_wait_move_", comment: "") + case global.metadataStatusWaitRename: + cell.statusImg?.image = utility.loadImage(named: "a.circle", colors: NCBrandColor.shared.iconImageMultiColors) + cell.infoLbl?.text = NSLocalizedString("_status_wait_rename_", comment: "") + case global.metadataStatusWaitDownload: + cell.statusImg?.image = utility.loadImage(named: "arrow.triangle.2.circlepath", colors: NCBrandColor.shared.iconImageMultiColors) + case global.metadataStatusDownloading: + cell.statusImg?.image = utility.loadImage(named: "arrowshape.down.circle", colors: NCBrandColor.shared.iconImageMultiColors) + case global.metadataStatusDownloadError, global.metadataStatusUploadError: + cell.statusImg?.image = utility.loadImage(named: "exclamationmark.circle", colors: NCBrandColor.shared.iconImageMultiColors) + default: + break + } + + } + func cellMainDirectory(cell: NCCellMainProtocol, + metadata: tableMetadata, + isShare: Bool, + isMounted: Bool) { + let tblDirectory = database.getTableDirectory(ocId: metadata.ocId) + + if metadata.e2eEncrypted { + cell.previewImg?.image = imageCache.getFolderEncrypted(account: metadata.account) + } else if isShare { + cell.previewImg?.image = imageCache.getFolderSharedWithMe(account: metadata.account) + } else if !metadata.shareType.isEmpty { + metadata.shareType.contains(NKShare.ShareType.publicLink.rawValue) ? + (cell.previewImg?.image = imageCache.getFolderPublic(account: metadata.account)) : + (cell.previewImg?.image = imageCache.getFolderSharedWithMe(account: metadata.account)) + } else if !metadata.shareType.isEmpty && metadata.shareType.contains(NKShare.ShareType.publicLink.rawValue) { + cell.previewImg?.image = imageCache.getFolderPublic(account: metadata.account) + } else if metadata.mountType == "group" { + cell.previewImg?.image = imageCache.getFolderGroup(account: metadata.account) + } else if isMounted { + cell.previewImg?.image = imageCache.getFolderExternal(account: metadata.account) + } else if metadata.fileName == autoUploadFileName && metadata.serverUrl == autoUploadDirectory { + cell.previewImg?.image = imageCache.getFolderAutomaticUpload(account: metadata.account) + } else { + cell.previewImg?.image = imageCache.getFolder(account: metadata.account) + } + + // Local image: offline + metadata.isOffline = tblDirectory?.offline ?? false + + if metadata.isOffline { + cell.localImg?.image = imageCache.getImageOfflineFlag(colors: [.systemBackground, .systemGreen]) + } + + // color folder + cell.previewImg?.image = cell.previewImg?.image?.colorizeFolder(metadata: metadata, tblDirectory: tblDirectory) + } + + func cellMainFile(cell: NCCellMainProtocol, + metadata: tableMetadata, + a11yValues: inout [String]) { + let tableLocalFile = database.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId)) + + if metadata.hasPreviewBorder { + cell.previewImg?.layer.borderWidth = 0.2 + cell.previewImg?.layer.borderColor = UIColor.lightGray.cgColor + } + + if metadata.name == global.appName { + let ext = global.getSizeExtension(column: self.numberOfColumns) + if let image = NCImageCache.shared.getImageCache(ocId: metadata.ocId, etag: metadata.etag, ext: ext) { + cell.previewImg?.image = image + } else if let image = utility.getImage(ocId: metadata.ocId, etag: metadata.etag, ext: ext, userId: metadata.userId, urlBase: metadata.urlBase) { + cell.previewImg?.image = image + } + + if cell.previewImg?.image == nil { + if metadata.iconName.isEmpty { + cell.previewImg?.image = NCImageCache.shared.getImageFile() + } else { + cell.previewImg?.image = utility.loadImage(named: metadata.iconName, useTypeIconFile: true, account: metadata.account) + } + } + } else { + // APP NAME - UNIFIED SEARCH + switch metadata.iconName { + case let str where str.contains("contacts"): + cell.previewImg?.image = utility.loadImage(named: "person.crop.rectangle.stack", colors: [NCBrandColor.shared.iconImageColor]) + case let str where str.contains("conversation"): + cell.previewImg?.image = UIImage(named: "talk-template")!.image(color: NCBrandColor.shared.getElement(account: metadata.account)) + case let str where str.contains("calendar"): + cell.previewImg?.image = utility.loadImage(named: "calendar", colors: [NCBrandColor.shared.iconImageColor]) + case let str where str.contains("deck"): + cell.previewImg?.image = utility.loadImage(named: "square.stack.fill", colors: [NCBrandColor.shared.iconImageColor]) + case let str where str.contains("mail"): + cell.previewImg?.image = utility.loadImage(named: "mail", colors: [NCBrandColor.shared.iconImageColor]) + case let str where str.contains("talk"): + cell.previewImg?.image = UIImage(named: "talk-template")!.image(color: NCBrandColor.shared.getElement(account: metadata.account)) + case let str where str.contains("confirm"): + cell.previewImg?.image = utility.loadImage(named: "arrow.right", colors: [NCBrandColor.shared.iconImageColor]) + case let str where str.contains("pages"): + cell.previewImg?.image = utility.loadImage(named: "doc.richtext", colors: [NCBrandColor.shared.iconImageColor]) + default: + cell.previewImg?.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) + if let image = NCImageCache.shared.getImageCache(key: fileName) { + cell.previewImg?.image = image + } else { + self.database.getImageAvatarLoaded(fileName: fileName) { image, tblAvatar in + if let image { + cell.previewImg?.image = image + NCImageCache.shared.addImageCache(image: image, key: fileName) + } else { + cell.previewImg?.image = self.utility.loadUserImage(for: ownerId, displayName: nil, urlBase: metadata.urlBase) + } + + if !(tblAvatar?.loaded ?? false), + self.networking.downloadAvatarQueue.operations.filter({ ($0 as? NCOperationDownloadAvatar)?.fileName == fileName }).isEmpty { + self.networking.downloadAvatarQueue.addOperation(NCOperationDownloadAvatar(user: ownerId, fileName: fileName, account: metadata.account, view: self.collectionView, isPreviewImage: true)) + } + } + } + } + } + } + + // Local image: offline + metadata.isOffline = tableLocalFile?.offline ?? false + + if metadata.isOffline { + a11yValues.append(NSLocalizedString("_offline_", comment: "")) + cell.localImg?.image = imageCache.getImageOfflineFlag(colors: [.systemBackground, .systemGreen]) + } else if utilityFileSystem.fileProviderStorageExists(metadata) { + cell.localImg?.image = imageCache.getImageLocal(colors: [.systemBackground, .systemGreen]) + } + } + +} +#endif diff --git a/iOSClient/Main/Collection Common/Cell/NCCellProtocol.swift b/iOSClient/Main/Collection Common/Cell/NCCellProtocol.swift deleted file mode 100644 index e788a6b1e2..0000000000 --- a/iOSClient/Main/Collection Common/Cell/NCCellProtocol.swift +++ /dev/null @@ -1,105 +0,0 @@ -// SPDX-FileCopyrightText: Nextcloud GmbH -// SPDX-FileCopyrightText: 2020 Marino Faggiana -// SPDX-License-Identifier: GPL-3.0-or-later - -import UIKit - -protocol NCCellProtocol { - var metadata: tableMetadata? {get set } - - var avatarImageView: UIImageView? { get } - var previewImageView: UIImageView? { get set } - var title: UILabel? { get set } - var info: UILabel? { get set } - var subInfo: UILabel? { get set } - var statusImageView: UIImageView? { get set } - var localImageView: UIImageView? { get set } - var favoriteImageView: UIImageView? { get set } - var shareImageView: UIImageView? { get set } - var separatorView: UIView? { get set } - var tagSeparator: UILabel? { get set } - - func titleInfoTrailingFull() - func writeInfoDateSize(date: NSDate, size: Int64) - func setButtonMore(image: UIImage) - func hideImageItem(_ status: Bool) - func hideImageFavorite(_ status: Bool) - func hideImageStatus(_ status: Bool) - func hideImageLocal(_ status: Bool) - func hideLabelInfo(_ status: Bool) - func hideLabelSubinfo(_ status: Bool) - func hideButtonShare(_ status: Bool) - func hideButtonMore(_ status: Bool) - func selected(_ status: Bool, isEditMode: Bool) - func setAccessibility(label: String, value: String) - func setTags(tags: [String]) - func setIconOutlines() -} - -extension NCCellProtocol { - var avatarImageView: UIImageView? { - return nil - } - var metadata: tableMetadata? { - get { return nil } - set {} - } - var previewImageView: UIImageView? { - get { return nil } - set {} - } - var title: UILabel? { - get { return nil } - set {} - } - var info: UILabel? { - get { return nil } - set { } - } - var subInfo: UILabel? { - get { return nil } - set { } - } - var statusImageView: UIImageView? { - get { return nil } - set {} - } - var localImageView: UIImageView? { - get { return nil } - set {} - } - var favoriteImageView: UIImageView? { - get { return nil } - set {} - } - var shareImageView: UIImageView? { - get { return nil } - set {} - } - - var separatorView: UIView? { - get { return nil } - set {} - } - - var tagSeparator: UILabel? { - get { return nil } - set {} - } - - func titleInfoTrailingFull() {} - func writeInfoDateSize(date: NSDate, size: Int64) {} - func setButtonMore(image: UIImage) {} - func hideImageItem(_ status: Bool) {} - func hideImageFavorite(_ status: Bool) {} - func hideImageStatus(_ status: Bool) {} - func hideImageLocal(_ status: Bool) {} - func hideLabelInfo(_ status: Bool) {} - func hideLabelSubinfo(_ status: Bool) {} - func hideButtonShare(_ status: Bool) {} - func hideButtonMore(_ status: Bool) {} - func selected(_ status: Bool, isEditMode: Bool) {} - func setAccessibility(label: String, value: String) {} - func setTags(tags: [String]) {} - func setIconOutlines() {} -} diff --git a/iOSClient/Main/Collection Common/Cell/NCGridCell.swift b/iOSClient/Main/Collection Common/Cell/NCGridCell.swift index 040aa451c3..50f4b187f3 100644 --- a/iOSClient/Main/Collection Common/Cell/NCGridCell.swift +++ b/iOSClient/Main/Collection Common/Cell/NCGridCell.swift @@ -2,61 +2,55 @@ // SPDX-FileCopyrightText: 2018 Marino Faggiana // SPDX-License-Identifier: GPL-3.0-or-later +import Foundation import UIKit +import NextcloudKit +import RealmSwift protocol NCGridCellDelegate: AnyObject { func onMenuIntent(with metadata: tableMetadata?) func openContextMenu(with metadata: tableMetadata?, button: UIButton, sender: Any) } -class NCGridCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProtocol { +class NCGridCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellMainProtocol { @IBOutlet weak var imageItem: UIImageView! @IBOutlet weak var imageSelect: UIImageView! @IBOutlet weak var imageStatus: UIImageView! @IBOutlet weak var imageFavorite: UIImageView! @IBOutlet weak var imageLocal: UIImageView! + @IBOutlet weak var labelTitle: UILabel! @IBOutlet weak var labelInfo: UILabel! @IBOutlet weak var labelSubinfo: UILabel! + @IBOutlet weak var buttonMore: UIButton! + @IBOutlet weak var imageVisualEffect: UIVisualEffectView! @IBOutlet weak var iconsStackView: UIStackView! weak var delegate: NCGridCellDelegate? + // Cell Protocol var metadata: tableMetadata? { didSet { delegate?.openContextMenu(with: metadata, button: buttonMore, sender: self) /* preconfigure UIMenu with each metadata */ } } - - var previewImageView: UIImageView? { + var previewImg: UIImageView? { get { return imageItem } set { imageItem = newValue } } - var title: UILabel? { - get { return labelTitle } - set { labelTitle = newValue } - } - var info: UILabel? { - get { return labelInfo } - set { labelInfo = newValue } - } - var subInfo: UILabel? { - get { return labelSubinfo } - set { labelSubinfo = newValue } + var localImg: UIImageView? { + get { return imageLocal } + set { imageLocal = newValue } } - var statusImageView: UIImageView? { + var statusImg: UIImageView? { get { return imageStatus } set { imageStatus = newValue } } - var localImageView: UIImageView? { - get { return imageLocal } - set { imageLocal = newValue } - } - var favoriteImageView: UIImageView? { - get { return imageFavorite } - set { imageFavorite = newValue } + var infoLbl: UILabel? { + get { return labelInfo } + set { labelInfo = newValue } } override func awakeFromNib() { @@ -72,6 +66,7 @@ class NCGridCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProto override func prepareForReuse() { super.prepareForReuse() + initCell() } @@ -89,9 +84,11 @@ class NCGridCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProto imageStatus.image = nil imageFavorite.image = nil imageLocal.image = nil + labelTitle.text = "" labelInfo.text = "" labelSubinfo.text = "" + imageVisualEffect.layer.cornerRadius = 6 imageVisualEffect.clipsToBounds = true imageVisualEffect.alpha = 0.5 @@ -122,31 +119,7 @@ class NCGridCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProto buttonMore.setImage(image, for: .normal) } - func hideImageItem(_ status: Bool) { - imageItem.isHidden = status - } - - func hideImageFavorite(_ status: Bool) { - imageFavorite.isHidden = status - } - - func hideImageStatus(_ status: Bool) { - imageStatus.isHidden = status - } - - func hideImageLocal(_ status: Bool) { - imageLocal.isHidden = status - } - - func hideLabelInfo(_ status: Bool) { - labelInfo.isHidden = status - } - - func hideLabelSubinfo(_ status: Bool) { - labelSubinfo.isHidden = status - } - - func hideButtonMore(_ status: Bool) { + func setButtonMore(_ status: Bool) { buttonMore.isHidden = status } @@ -181,8 +154,6 @@ class NCGridCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProto accessibilityLabel = label accessibilityValue = value } - - func setIconOutlines() {} } // MARK: - Grid Layout @@ -232,3 +203,93 @@ class NCGridLayout: UICollectionViewFlowLayout { return proposedContentOffset } } + +extension NCCollectionViewCommon { + func gridCell(cell: NCGridCell, indexPath: IndexPath, metadata: tableMetadata) -> NCGridCell { + var isShare = false + var isMounted = false + var a11yValues: [String] = [] + let existsImagePreview = utilityFileSystem.fileProviderStorageImageExists(metadata.ocId, etag: metadata.etag, userId: metadata.userId, urlBase: metadata.urlBase) + + // CONTENT MODE + cell.previewImg?.layer.borderWidth = 0 + + if existsImagePreview && layoutForView?.layout != global.layoutPhotoRatio { + cell.previewImg?.contentMode = .scaleAspectFill + } else { + cell.previewImg?.contentMode = .scaleAspectFit + } + + guard let metadata = self.dataSource.getMetadata(indexPath: indexPath) else { + return cell + } + + if metadataFolder != nil { + isShare = metadata.permissions.contains(NCMetadataPermissions.permissionShared) && !metadataFolder!.permissions.contains(NCMetadataPermissions.permissionShared) + isMounted = metadata.permissions.contains(NCMetadataPermissions.permissionMounted) && !metadataFolder!.permissions.contains(NCMetadataPermissions.permissionMounted) + } + + if !metadata.sessionError.isEmpty, metadata.status != global.metadataStatusNormal { + cell.labelSubinfo.isHidden = false + cell.labelInfo.text = metadata.sessionError + } else { + cell.labelSubinfo.isHidden = false + cell.writeInfoDateSize(date: metadata.date, size: metadata.size) + } + + cell.labelTitle.text = metadata.fileNameView + + // Accessibility [shared] if metadata.ownerId != appDelegate.userId, appDelegate.account == metadata.account { + if metadata.ownerId != metadata.userId { + a11yValues.append(NSLocalizedString("_shared_with_you_by_", comment: "") + " " + metadata.ownerDisplayName) + } + + if metadata.directory { + cellMainDirectory(cell: cell, metadata: metadata, isShare: isShare, isMounted: isMounted) + } else { + cellMainFile(cell: cell, metadata: metadata, a11yValues: &a11yValues) + } + + // image Favorite + if metadata.favorite { + cell.imageFavorite.image = imageCache.getImageFavorite() + a11yValues.append(NSLocalizedString("_favorite_short_", comment: "")) + } + + // Button More + if metadata.lock == true { + cell.setButtonMore(image: imageCache.getImageButtonMoreLock()) + a11yValues.append(String(format: NSLocalizedString("_locked_by_", comment: ""), metadata.lockOwnerDisplayName)) + } else { + cell.setButtonMore(image: imageCache.getImageButtonMore()) + } + + // Status + cellMainStatus(cell: cell, metadata: metadata, a11yValues: &a11yValues) + + // URL + if metadata.classFile == NKTypeClassFile.url.rawValue { + cell.imageLocal.image = nil + } + + // Edit mode + if fileSelect.contains(metadata.ocId) { + cell.selected(true, isEditMode: isEditMode) + a11yValues.append(NSLocalizedString("_selected_", comment: "")) + } else { + cell.selected(false, isEditMode: isEditMode) + } + + // Accessibility + cell.setAccessibility(label: metadata.fileNameView + ", " + (cell.labelInfo.text ?? "") + (cell.labelSubinfo.text ?? ""), value: a11yValues.joined(separator: ", ")) + + // Color string find in search + cell.labelTitle.textColor = NCBrandColor.shared.textColor + cell.labelTitle.font = .systemFont(ofSize: 15) + + // Obligatory here, at the end !! + cell.metadata = metadata + + return cell + } +} diff --git a/iOSClient/Main/Collection Common/Cell/NCListCell.swift b/iOSClient/Main/Collection Common/Cell/NCListCell.swift index 2f4df564b6..df8de370c8 100755 --- a/iOSClient/Main/Collection Common/Cell/NCListCell.swift +++ b/iOSClient/Main/Collection Common/Cell/NCListCell.swift @@ -2,7 +2,10 @@ // SPDX-FileCopyrightText: 2018 Marino Faggiana // SPDX-License-Identifier: GPL-3.0-or-later +import Foundation import UIKit +import NextcloudKit +import RealmSwift protocol NCListCellDelegate: AnyObject { func onMenuIntent(with metadata: tableMetadata?) @@ -10,23 +13,25 @@ protocol NCListCellDelegate: AnyObject { func tapShareListItem(with metadata: tableMetadata?, button: UIButton, sender: Any) } -class NCListCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProtocol { +class NCListCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellMainProtocol { @IBOutlet weak var imageItem: UIImageView! @IBOutlet weak var imageSelect: UIImageView! @IBOutlet weak var imageStatus: UIImageView! @IBOutlet weak var imageFavorite: UIImageView! @IBOutlet weak var imageLocal: UIImageView! + @IBOutlet weak var imageShared: UIImageView! + @IBOutlet weak var imageMore: UIImageView! + @IBOutlet weak var labelTitle: UILabel! @IBOutlet weak var labelInfo: UILabel! - @IBOutlet weak var labelInfoSeparator: UILabel! @IBOutlet weak var labelSubinfo: UILabel! - @IBOutlet weak var imageShared: UIImageView! + @IBOutlet weak var labelInfoSeparator: UILabel! + @IBOutlet weak var tag0: UILabel! + @IBOutlet weak var tag1: UILabel! + @IBOutlet weak var buttonShared: UIButton! - @IBOutlet weak var imageMore: UIImageView! @IBOutlet weak var buttonMore: UIButton! @IBOutlet weak var separator: UIView! - @IBOutlet weak var tag0: UILabel! - @IBOutlet weak var tag1: UILabel! @IBOutlet weak var imageItemLeftConstraint: NSLayoutConstraint! @IBOutlet weak var separatorHeightConstraint: NSLayoutConstraint! @@ -34,54 +39,31 @@ class NCListCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProto weak var delegate: NCListCellDelegate? + // Cell Protocol var metadata: tableMetadata? { didSet { delegate?.openContextMenu(with: metadata, button: buttonMore, sender: self) /* preconfigure UIMenu with each metadata */ } } - - var avatarImageView: UIImageView? { - return imageShared + var avatarImg: UIImageView? { + get { return imageShared } + set { imageShared = newValue } } - var previewImageView: UIImageView? { + var previewImg: UIImageView? { get { return imageItem } set { imageItem = newValue } } - var title: UILabel? { - get { return labelTitle } - set { labelTitle = newValue } - } - var info: UILabel? { - get { return labelInfo } - set { labelInfo = newValue } - } - var subInfo: UILabel? { - get { return labelSubinfo } - set { labelSubinfo = newValue } - } - var statusImageView: UIImageView? { - get { return imageStatus } - set { imageStatus = newValue } - } - var localImageView: UIImageView? { + var localImg: UIImageView? { get { return imageLocal } set { imageLocal = newValue } } - var favoriteImageView: UIImageView? { - get { return imageFavorite } - set { imageFavorite = newValue } - } - var shareImageView: UIImageView? { - get { return imageShared } - set { imageShared = newValue } - } - var separatorView: UIView? { - get { return separator } - set { separator = newValue } + var statusImg: UIImageView? { + get { return imageStatus } + set { imageStatus = newValue } } - var tagSeparator: UILabel? { - get { return labelInfoSeparator } - set { labelInfoSeparator = newValue } + var infoLbl: UILabel? { + get { return labelInfo } + set { labelInfo = newValue } } override var accessibilityIdentifier: String? { @@ -110,6 +92,7 @@ class NCListCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProto override func prepareForReuse() { super.prepareForReuse() + initCell() } @@ -125,19 +108,25 @@ class NCListCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProto imageStatus.image = nil imageFavorite.image = nil imageLocal.image = nil + imageShared.image = nil + imageMore.image = nil + imageSelect.image = nil + labelTitle.text = "" labelInfo.text = "" labelSubinfo.text = "" - imageShared.image = nil - imageMore.image = nil - separatorHeightConstraint.constant = 0.5 + labelInfoSeparator.text = "" tag0.text = "" tag1.text = "" - titleTrailingConstraint.constant = 90 - contentView.bringSubviewToFront(buttonMore) + separatorHeightConstraint.constant = 0.5 + buttonMore.menu = nil buttonMore.showsMenuAsPrimaryAction = true + + titleTrailingConstraint.constant = 90 + + contentView.bringSubviewToFront(buttonMore) } override func snapshotView(afterScreenUpdates afterUpdates: Bool) -> UIView? { @@ -156,7 +145,6 @@ class NCListCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProto } } - // Allow the button to receive taps even with the long press gesture func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool { let location = touch.location(in: contentView) return buttonMore.frame.contains(location) @@ -274,7 +262,6 @@ class NCListCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProto view.removeFromSuperview() } } - } override func layoutSubviews() { @@ -400,3 +387,180 @@ class BidiFilenameLabel: UILabel { return result } } + +#if !EXTENSION +extension NCCollectionViewCommon { + func listCell(cell: NCListCell, indexPath: IndexPath, metadata: tableMetadata) -> NCListCell { + defer { + let capabilities = NCNetworking.shared.capabilities[session.account] ?? NKCapabilities.Capabilities() + if !metadata.isSharable() || (!capabilities.fileSharingApiEnabled && !capabilities.filesComments && capabilities.activity.isEmpty) { + cell.hideButtonShare(true) + } + } + var isShare = false + var isMounted = false + var a11yValues: [String] = [] + let existsImagePreview = utilityFileSystem.fileProviderStorageImageExists(metadata.ocId, etag: metadata.etag, userId: metadata.userId, urlBase: metadata.urlBase) + + // CONTENT MODE + cell.avatarImg?.contentMode = .center + cell.previewImg?.layer.borderWidth = 0 + + if existsImagePreview && layoutForView?.layout != global.layoutPhotoRatio { + cell.previewImg?.contentMode = .scaleAspectFill + } else { + cell.previewImg?.contentMode = .scaleAspectFit + } + + guard let metadata = self.dataSource.getMetadata(indexPath: indexPath) else { + return cell + } + + if let metadataFolder { + isShare = metadata.permissions.contains(NCMetadataPermissions.permissionShared) && !metadataFolder.permissions.contains(NCMetadataPermissions.permissionShared) + isMounted = metadata.permissions.contains(NCMetadataPermissions.permissionMounted) && !metadataFolder.permissions.contains(NCMetadataPermissions.permissionMounted) + } + + if isSearchingMode { + if metadata.name == global.appName { + cell.labelInfo?.text = NSLocalizedString("_in_", comment: "") + " " + utilityFileSystem.getPath(path: metadata.path, user: metadata.user) + } else { + cell.labelInfo?.text = metadata.subline + } + cell.labelSubinfo?.isHidden = true + } else if !metadata.sessionError.isEmpty, metadata.status != global.metadataStatusNormal { + cell.labelSubinfo?.isHidden = false + cell.labelInfo?.text = metadata.sessionError + } else { + cell.labelSubinfo?.isHidden = false + cell.writeInfoDateSize(date: metadata.date, size: metadata.size) + } + + cell.labelTitle?.text = metadata.fileNameView + + // Accessibility [shared] if metadata.ownerId != appDelegate.userId, appDelegate.account == metadata.account { + if metadata.ownerId != metadata.userId { + a11yValues.append(NSLocalizedString("_shared_with_you_by_", comment: "") + " " + metadata.ownerDisplayName) + } + + if metadata.directory { + cellMainDirectory(cell: cell, metadata: metadata, isShare: isShare, isMounted: isMounted) + } else { + cellMainFile(cell: cell, metadata: metadata, a11yValues: &a11yValues) + } + + // image Favorite + if metadata.favorite { + cell.imageFavorite?.image = imageCache.getImageFavorite() + a11yValues.append(NSLocalizedString("_favorite_short_", comment: "")) + } + + // Share image + if isShare { + cell.imageShared?.image = imageCache.getImageShared() + } else if !metadata.shareType.isEmpty { + metadata.shareType.contains(NKShare.ShareType.publicLink.rawValue) ? + (cell.imageShared?.image = imageCache.getImageShareByLink()) : + (cell.imageShared?.image = imageCache.getImageShared()) + } else { + cell.imageShared?.image = imageCache.getImageCanShare() + } + + // Button More + if metadata.lock == true { + cell.setButtonMore(image: imageCache.getImageButtonMoreLock()) + a11yValues.append(String(format: NSLocalizedString("_locked_by_", comment: ""), metadata.lockOwnerDisplayName)) + } else { + cell.setButtonMore(image: imageCache.getImageButtonMore()) + } + + // Status + cellMainStatus(cell: cell, metadata: metadata, a11yValues: &a11yValues) + + // AVATAR + if !metadata.ownerId.isEmpty, metadata.ownerId != metadata.userId { + let fileName = NCSession.shared.getFileName(urlBase: metadata.urlBase, user: metadata.ownerId) + if let image = NCImageCache.shared.getImageCache(key: fileName) { + cell.avatarImg?.contentMode = .scaleAspectFill + cell.avatarImg?.image = image + } else { + self.database.getImageAvatarLoaded(fileName: fileName) { image, tblAvatar in + if let image { + cell.avatarImg?.contentMode = .scaleAspectFill + cell.avatarImg?.image = image + NCImageCache.shared.addImageCache(image: image, key: fileName) + } else { + cell.avatarImg?.contentMode = .scaleAspectFill + cell.avatarImg?.image = self.utility.loadUserImage(for: metadata.ownerId, displayName: metadata.ownerDisplayName, urlBase: metadata.urlBase) + } + + if !(tblAvatar?.loaded ?? false), + self.networking.downloadAvatarQueue.operations.filter({ ($0 as? NCOperationDownloadAvatar)?.fileName == fileName }).isEmpty { + self.networking.downloadAvatarQueue.addOperation(NCOperationDownloadAvatar(user: metadata.ownerId, fileName: fileName, account: metadata.account, view: self.collectionView)) + } + } + } + } + + // URL + if metadata.classFile == NKTypeClassFile.url.rawValue { + cell.imageLocal.image = nil + cell.hideButtonShare(true) + cell.hideButtonMore(true) + } + + // Separator + if collectionView.numberOfItems(inSection: indexPath.section) == indexPath.row + 1 || isSearchingMode { + cell.separator?.isHidden = true + } else { + cell.separator?.isHidden = false + } + + // Edit mode + if fileSelect.contains(metadata.ocId) { + cell.selected(true, isEditMode: isEditMode) + a11yValues.append(NSLocalizedString("_selected_", comment: "")) + } else { + cell.selected(false, isEditMode: isEditMode) + } + + // Accessibility + cell.setAccessibility(label: metadata.fileNameView + ", " + (cell.labelInfo?.text ?? "") + (cell.labelSubinfo?.text ?? ""), value: a11yValues.joined(separator: ", ")) + + // Color string find in search + cell.labelTitle?.textColor = NCBrandColor.shared.textColor + cell.labelTitle?.font = .systemFont(ofSize: 15) + + if isSearchingMode, + let searchResultStore, + let title = cell.labelTitle?.text { + let longestWordRange = (title.lowercased() as NSString).range(of: searchResultStore) + let attributedString = NSMutableAttributedString(string: title, attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 15)]) + attributedString.setAttributes([NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 15), NSAttributedString.Key.foregroundColor: UIColor.systemBlue], range: longestWordRange) + cell.labelTitle?.attributedText = attributedString + } + + // TAGS + cell.setTags(tags: Array(metadata.tags)) + + // SearchingMode - TAG Separator Hidden + if isSearchingMode { + cell.labelInfoSeparator.isHidden = true + } + + // Hide buttons + if metadata.name != global.appName { + cell.titleInfoTrailingFull() + cell.hideButtonShare(true) + cell.hideButtonMore(true) + } + + cell.setIconOutlines() + + // Obligatory here, at the end !! + cell.metadata = metadata + + return cell + } +} +#endif diff --git a/iOSClient/Main/Collection Common/Cell/NCPhotoCell.swift b/iOSClient/Main/Collection Common/Cell/NCPhotoCell.swift index cedf0815a9..5c67a1dddc 100644 --- a/iOSClient/Main/Collection Common/Cell/NCPhotoCell.swift +++ b/iOSClient/Main/Collection Common/Cell/NCPhotoCell.swift @@ -4,48 +4,20 @@ import UIKit -protocol NCPhotoCellDelegate: AnyObject { - func onMenuIntent(with metadata: tableMetadata?) - func openContextMenu(with metadata: tableMetadata?, button: UIButton, sender: Any) -} - -class NCPhotoCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProtocol { +class NCPhotoCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellMainProtocol { @IBOutlet weak var imageItem: UIImageView! @IBOutlet weak var imageSelect: UIImageView! - @IBOutlet weak var imageStatus: UIImageView! - @IBOutlet weak var buttonMore: UIButton! @IBOutlet weak var imageVisualEffect: UIVisualEffectView! - weak var delegate: NCPhotoCellDelegate? - - var metadata: tableMetadata? { - didSet { - delegate?.openContextMenu(with: metadata, button: buttonMore, sender: self) /* preconfigure UIMenu with each metadata */ - } - } - - var previewImageView: UIImageView? { + var metadata: tableMetadata? + var previewImg: UIImageView? { get { return imageItem } set { imageItem = newValue } } - var statusImageView: UIImageView? { - get { return imageStatus } - set { imageStatus = newValue } - } - - override func awakeFromNib() { - super.awakeFromNib() - - let tapObserver = UITapGestureRecognizer(target: self, action: #selector(handleTapObserver(_:))) - tapObserver.cancelsTouchesInView = false - tapObserver.delegate = self - contentView.addGestureRecognizer(tapObserver) - - initCell() - } override func prepareForReuse() { super.prepareForReuse() + initCell() } @@ -57,40 +29,14 @@ class NCPhotoCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProt imageItem.image = nil imageSelect.isHidden = true imageSelect.image = NCImageCache.shared.getImageCheckedYes() - imageStatus.image = nil imageVisualEffect.clipsToBounds = true imageVisualEffect.alpha = 0.5 - - buttonMore.isHidden = true - buttonMore.menu = nil - buttonMore.showsMenuAsPrimaryAction = true - contentView.bringSubviewToFront(buttonMore) } override func snapshotView(afterScreenUpdates afterUpdates: Bool) -> UIView? { return nil } - @objc private func handleTapObserver(_ g: UITapGestureRecognizer) { - let location = g.location(in: contentView) - - if buttonMore.frame.contains(location) { - delegate?.onMenuIntent(with: metadata) - } - } - - func setButtonMore(image: UIImage) { - buttonMore.setImage(image, for: .normal) - } - - func hideButtonMore(_ status: Bool) { - // buttonMore.isHidden = status NO MORE USED - } - - func hideImageStatus(_ status: Bool) { - imageStatus.isHidden = status - } - func selected(_ status: Bool, isEditMode: Bool) { if status { imageSelect.isHidden = false @@ -107,3 +53,54 @@ class NCPhotoCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProt accessibilityValue = value } } + +extension NCCollectionViewCommon { + // MARK: - LAYOUT PHOTO + // + func photoCell(cell: NCPhotoCell, indexPath: IndexPath, metadata: tableMetadata) -> NCPhotoCell { + let ext = global.getSizeExtension(column: self.numberOfColumns) + + cell.metadata = metadata + + // Image + // + if let image = NCImageCache.shared.getImageCache(ocId: metadata.ocId, etag: metadata.etag, ext: ext) { + cell.previewImg?.image = image + cell.previewImg?.contentMode = .scaleAspectFill + } else { + if isPinchGestureActive || ext == global.previewExt512 || ext == global.previewExt1024 { + cell.previewImg?.image = self.utility.getImage(ocId: metadata.ocId, etag: metadata.etag, ext: ext, userId: metadata.userId, urlBase: metadata.urlBase) + } + + DispatchQueue.global(qos: .userInteractive).async { + let image = self.utility.getImage(ocId: metadata.ocId, etag: metadata.etag, ext: ext, userId: metadata.userId, urlBase: metadata.urlBase) + if let image { + self.imageCache.addImageCache(ocId: metadata.ocId, etag: metadata.etag, image: image, ext: ext, cost: indexPath.row) + DispatchQueue.main.async { + cell.previewImg?.image = image + cell.previewImg?.contentMode = .scaleAspectFill + } + } else { + DispatchQueue.main.async { + cell.previewImg?.contentMode = .scaleAspectFit + if metadata.iconName.isEmpty { + cell.previewImg?.image = NCImageCache.shared.getImageFile() + } else { + cell.previewImg?.image = self.utility.loadImage(named: metadata.iconName, useTypeIconFile: true, account: metadata.account) + } + } + } + } + } + + // Edit mode + // + if fileSelect.contains(metadata.ocId) { + cell.selected(true, isEditMode: isEditMode) + } else { + cell.selected(false, isEditMode: isEditMode) + } + + return cell + } +} diff --git a/iOSClient/Main/Collection Common/Cell/NCPhotoCell.xib b/iOSClient/Main/Collection Common/Cell/NCPhotoCell.xib index 1e47d12444..40878baeef 100644 --- a/iOSClient/Main/Collection Common/Cell/NCPhotoCell.xib +++ b/iOSClient/Main/Collection Common/Cell/NCPhotoCell.xib @@ -1,8 +1,8 @@ - + - + @@ -28,13 +28,6 @@ - - - - - - - @@ -42,23 +35,11 @@ - - - @@ -66,29 +47,21 @@ - - - - - - - - diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon+CellDelegate.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon+CellDelegate.swift index 7b799e9ef4..d991fb9ec6 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon+CellDelegate.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon+CellDelegate.swift @@ -1,4 +1,4 @@ -extension NCCollectionViewCommon: NCListCellDelegate, NCGridCellDelegate, NCPhotoCellDelegate { +extension NCCollectionViewCommon: NCListCellDelegate, NCGridCellDelegate { func openContextMenu(with metadata: tableMetadata?, button: UIButton, sender: Any) { Task { guard let metadata else { return } diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift index 0464e787d9..da6923e610 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDataSource.swift @@ -51,81 +51,10 @@ extension NCCollectionViewCommon: UICollectionViewDataSource { self.networking.downloadThumbnailQueue.operations.filter({ ($0 as? NCMediaDownloadThumbnail)?.metadata.ocId == metadata.ocId }).isEmpty { self.networking.downloadThumbnailQueue.addOperation(NCCollectionViewDownloadThumbnail(metadata: metadata, collectionView: collectionView, ext: ext)) } - - } - - private func photoCell(cell: NCPhotoCell, indexPath: IndexPath, metadata: tableMetadata, ext: String) -> NCPhotoCell { - let width = UIScreen.main.bounds.width / CGFloat(self.numberOfColumns) - - cell.metadata = metadata - // cell.hideButtonMore(true) NO MORE USED - cell.hideImageStatus(true) - - // Image - // - if let image = NCImageCache.shared.getImageCache(ocId: metadata.ocId, etag: metadata.etag, ext: ext) { - - cell.previewImageView?.image = image - cell.previewImageView?.contentMode = .scaleAspectFill - - } else { - - if isPinchGestureActive || ext == global.previewExt512 || ext == global.previewExt1024 { - cell.previewImageView?.image = self.utility.getImage(ocId: metadata.ocId, etag: metadata.etag, ext: ext, userId: metadata.userId, urlBase: metadata.urlBase) - } - - DispatchQueue.global(qos: .userInteractive).async { - let image = self.utility.getImage(ocId: metadata.ocId, etag: metadata.etag, ext: ext, userId: metadata.userId, urlBase: metadata.urlBase) - if let image { - self.imageCache.addImageCache(ocId: metadata.ocId, etag: metadata.etag, image: image, ext: ext, cost: indexPath.row) - DispatchQueue.main.async { - cell.previewImageView?.image = image - cell.previewImageView?.contentMode = .scaleAspectFill - } - } else { - DispatchQueue.main.async { - cell.previewImageView?.contentMode = .scaleAspectFit - if metadata.iconName.isEmpty { - cell.previewImageView?.image = NCImageCache.shared.getImageFile() - } else { - cell.previewImageView?.image = self.utility.loadImage(named: metadata.iconName, useTypeIconFile: true, account: metadata.account) - } - } - } - } - } - - // Edit mode - // - if fileSelect.contains(metadata.ocId) { - cell.selected(true, isEditMode: isEditMode) - } else { - cell.selected(false, isEditMode: isEditMode) - } - - if width > 100 { - // cell.hideButtonMore(false) NO MORE USED - cell.hideImageStatus(false) - } - - return cell } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - var cell: NCCellProtocol & UICollectionViewCell - var isShare = false - var isMounted = false - var a11yValues: [String] = [] let metadata = self.dataSource.getMetadata(indexPath: indexPath) ?? tableMetadata() - let existsImagePreview = utilityFileSystem.fileProviderStorageImageExists(metadata.ocId, etag: metadata.etag, userId: metadata.userId, urlBase: metadata.urlBase) - let ext = global.getSizeExtension(column: self.numberOfColumns) - - defer { - let capabilities = NCNetworking.shared.capabilities[session.account] ?? NKCapabilities.Capabilities() - if !metadata.isSharable() || (!capabilities.fileSharingApiEnabled && !capabilities.filesComments && capabilities.activity.isEmpty) { - cell.hideButtonShare(true) - } - } // E2EE create preview if self.isDirectoryE2EE, @@ -138,349 +67,23 @@ extension NCCollectionViewCommon: UICollectionViewDataSource { if isLayoutPhoto { if metadata.isImageOrVideo { let photoCell = (collectionView.dequeueReusableCell(withReuseIdentifier: "photoCell", for: indexPath) as? NCPhotoCell)! - photoCell.delegate = self - cell = photoCell - return self.photoCell(cell: photoCell, indexPath: indexPath, metadata: metadata, ext: ext) + return self.photoCell(cell: photoCell, indexPath: indexPath, metadata: metadata) } else { let gridCell = (collectionView.dequeueReusableCell(withReuseIdentifier: "gridCell", for: indexPath) as? NCGridCell)! gridCell.delegate = self - cell = gridCell + return self.gridCell(cell: gridCell, indexPath: indexPath, metadata: metadata) } } else if isLayoutGrid { // LAYOUT GRID let gridCell = (collectionView.dequeueReusableCell(withReuseIdentifier: "gridCell", for: indexPath) as? NCGridCell)! gridCell.delegate = self - cell = gridCell + return self.gridCell(cell: gridCell, indexPath: indexPath, metadata: metadata) } else { // LAYOUT LIST let listCell = (collectionView.dequeueReusableCell(withReuseIdentifier: "listCell", for: indexPath) as? NCListCell)! listCell.delegate = self - cell = listCell + return self.listCell(cell: listCell, indexPath: indexPath, metadata: metadata) } - - // CONTENT MODE - cell.avatarImageView?.contentMode = .center - cell.previewImageView?.layer.borderWidth = 0 - - if existsImagePreview && layoutForView?.layout != global.layoutPhotoRatio { - cell.previewImageView?.contentMode = .scaleAspectFill - } else { - cell.previewImageView?.contentMode = .scaleAspectFit - } - - guard let metadata = self.dataSource.getMetadata(indexPath: indexPath) else { - return cell - } - - if metadataFolder != nil { - isShare = metadata.permissions.contains(NCMetadataPermissions.permissionShared) && !metadataFolder!.permissions.contains(NCMetadataPermissions.permissionShared) - isMounted = metadata.permissions.contains(NCMetadataPermissions.permissionMounted) && !metadataFolder!.permissions.contains(NCMetadataPermissions.permissionMounted) - } - - if isSearchingMode { - if metadata.name == global.appName { - cell.info?.text = NSLocalizedString("_in_", comment: "") + " " + utilityFileSystem.getPath(path: metadata.path, user: metadata.user) - } else { - cell.info?.text = metadata.subline - } - cell.subInfo?.isHidden = true - } else if !metadata.sessionError.isEmpty, metadata.status != global.metadataStatusNormal { - cell.subInfo?.isHidden = false - cell.info?.text = metadata.sessionError - } else { - cell.subInfo?.isHidden = false - cell.writeInfoDateSize(date: metadata.date, size: metadata.size) - } - - cell.title?.text = metadata.fileNameView - - // Accessibility [shared] if metadata.ownerId != appDelegate.userId, appDelegate.account == metadata.account { - if metadata.ownerId != metadata.userId { - a11yValues.append(NSLocalizedString("_shared_with_you_by_", comment: "") + " " + metadata.ownerDisplayName) - } - - if metadata.directory { - let tblDirectory = database.getTableDirectory(ocId: metadata.ocId) - - if metadata.e2eEncrypted { - cell.previewImageView?.image = imageCache.getFolderEncrypted(account: metadata.account) - } else if isShare { - cell.previewImageView?.image = imageCache.getFolderSharedWithMe(account: metadata.account) - } else if !metadata.shareType.isEmpty { - metadata.shareType.contains(NKShare.ShareType.publicLink.rawValue) ? - (cell.previewImageView?.image = imageCache.getFolderPublic(account: metadata.account)) : - (cell.previewImageView?.image = imageCache.getFolderSharedWithMe(account: metadata.account)) - } else if !metadata.shareType.isEmpty && metadata.shareType.contains(NKShare.ShareType.publicLink.rawValue) { - cell.previewImageView?.image = imageCache.getFolderPublic(account: metadata.account) - } else if metadata.mountType == "group" { - cell.previewImageView?.image = imageCache.getFolderGroup(account: metadata.account) - } else if isMounted { - cell.previewImageView?.image = imageCache.getFolderExternal(account: metadata.account) - } else if metadata.fileName == autoUploadFileName && metadata.serverUrl == autoUploadDirectory { - cell.previewImageView?.image = imageCache.getFolderAutomaticUpload(account: metadata.account) - } else { - cell.previewImageView?.image = imageCache.getFolder(account: metadata.account) - } - - // Local image: offline - metadata.isOffline = tblDirectory?.offline ?? false - - if metadata.isOffline { - cell.localImageView?.image = imageCache.getImageOfflineFlag(colors: [.systemBackground, .systemGreen]) - } - - // color folder - cell.previewImageView?.image = cell.previewImageView?.image?.colorizeFolder(metadata: metadata, tblDirectory: tblDirectory) - - } else { - let tableLocalFile = database.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId)) - - if metadata.hasPreviewBorder { - cell.previewImageView?.layer.borderWidth = 0.2 - cell.previewImageView?.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.previewImageView?.image = image - } else if let image = utility.getImage(ocId: metadata.ocId, etag: metadata.etag, ext: ext, userId: metadata.userId, urlBase: metadata.urlBase) { - cell.previewImageView?.image = image - } - - if cell.previewImageView?.image == nil { - if metadata.iconName.isEmpty { - cell.previewImageView?.image = NCImageCache.shared.getImageFile() - } else { - cell.previewImageView?.image = utility.loadImage(named: metadata.iconName, useTypeIconFile: true, account: metadata.account) - } - } - } else { - // APP NAME - UNIFIED SEARCH - switch metadata.iconName { - case let str where str.contains("contacts"): - cell.previewImageView?.image = utility.loadImage(named: "person.crop.rectangle.stack", colors: [NCBrandColor.shared.iconImageColor]) - case let str where str.contains("conversation"): - cell.previewImageView?.image = UIImage(named: "talk-template")!.image(color: NCBrandColor.shared.getElement(account: metadata.account)) - case let str where str.contains("calendar"): - cell.previewImageView?.image = utility.loadImage(named: "calendar", colors: [NCBrandColor.shared.iconImageColor]) - case let str where str.contains("deck"): - cell.previewImageView?.image = utility.loadImage(named: "square.stack.fill", colors: [NCBrandColor.shared.iconImageColor]) - case let str where str.contains("mail"): - cell.previewImageView?.image = utility.loadImage(named: "mail", colors: [NCBrandColor.shared.iconImageColor]) - case let str where str.contains("talk"): - cell.previewImageView?.image = UIImage(named: "talk-template")!.image(color: NCBrandColor.shared.getElement(account: metadata.account)) - case let str where str.contains("confirm"): - cell.previewImageView?.image = utility.loadImage(named: "arrow.right", colors: [NCBrandColor.shared.iconImageColor]) - case let str where str.contains("pages"): - cell.previewImageView?.image = utility.loadImage(named: "doc.richtext", colors: [NCBrandColor.shared.iconImageColor]) - default: - cell.previewImageView?.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) - if let image = NCImageCache.shared.getImageCache(key: fileName) { - cell.previewImageView?.image = image - } else { - self.database.getImageAvatarLoaded(fileName: fileName) { image, tblAvatar in - if let image { - cell.previewImageView?.image = image - NCImageCache.shared.addImageCache(image: image, key: fileName) - } else { - cell.previewImageView?.image = self.utility.loadUserImage(for: ownerId, displayName: nil, urlBase: metadata.urlBase) - } - - if !(tblAvatar?.loaded ?? false), - self.networking.downloadAvatarQueue.operations.filter({ ($0 as? NCOperationDownloadAvatar)?.fileName == fileName }).isEmpty { - self.networking.downloadAvatarQueue.addOperation(NCOperationDownloadAvatar(user: ownerId, fileName: fileName, account: metadata.account, view: collectionView, isPreviewImageView: true)) - } - } - } - } - } - } - - // Local image: offline - metadata.isOffline = tableLocalFile?.offline ?? false - - if metadata.isOffline { - a11yValues.append(NSLocalizedString("_offline_", comment: "")) - cell.localImageView?.image = imageCache.getImageOfflineFlag(colors: [.systemBackground, .systemGreen]) - } else if utilityFileSystem.fileProviderStorageExists(metadata) { - cell.localImageView?.image = imageCache.getImageLocal(colors: [.systemBackground, .systemGreen]) - } - } - - // image Favorite - if metadata.favorite { - cell.favoriteImageView?.image = imageCache.getImageFavorite() - a11yValues.append(NSLocalizedString("_favorite_short_", comment: "")) - } - - // Share image - if isShare { - cell.shareImageView?.image = imageCache.getImageShared() - } else if !metadata.shareType.isEmpty { - metadata.shareType.contains(NKShare.ShareType.publicLink.rawValue) ? - (cell.shareImageView?.image = imageCache.getImageShareByLink()) : - (cell.shareImageView?.image = imageCache.getImageShared()) - } else { - cell.shareImageView?.image = imageCache.getImageCanShare() - } - - // Button More - if metadata.lock == true { - cell.setButtonMore(image: imageCache.getImageButtonMoreLock()) - a11yValues.append(String(format: NSLocalizedString("_locked_by_", comment: ""), metadata.lockOwnerDisplayName)) - } else { - cell.setButtonMore(image: imageCache.getImageButtonMore()) - } - - // Status - if metadata.isLivePhoto { - cell.statusImageView?.image = utility.loadImage(named: "livephoto", colors: [NCBrandColor.shared.iconImageColor]) - a11yValues.append(NSLocalizedString("_upload_mov_livephoto_", comment: "")) - } else if metadata.isVideo { - cell.statusImageView?.image = utility.loadImage(named: "play.circle.fill", colors: [.systemBackgroundInverted, .systemGray5]) - } - - switch metadata.status { - case global.metadataStatusWaitCreateFolder: - cell.statusImageView?.image = utility.loadImage(named: "arrow.triangle.2.circlepath", colors: NCBrandColor.shared.iconImageMultiColors) - cell.info?.text = NSLocalizedString("_status_wait_create_folder_", comment: "") - case global.metadataStatusWaitFavorite: - cell.statusImageView?.image = utility.loadImage(named: "star.circle", colors: NCBrandColor.shared.iconImageMultiColors) - cell.info?.text = NSLocalizedString("_status_wait_favorite_", comment: "") - case global.metadataStatusWaitCopy: - cell.statusImageView?.image = utility.loadImage(named: "c.circle", colors: NCBrandColor.shared.iconImageMultiColors) - cell.info?.text = NSLocalizedString("_status_wait_copy_", comment: "") - case global.metadataStatusWaitMove: - cell.statusImageView?.image = utility.loadImage(named: "m.circle", colors: NCBrandColor.shared.iconImageMultiColors) - cell.info?.text = NSLocalizedString("_status_wait_move_", comment: "") - case global.metadataStatusWaitRename: - cell.statusImageView?.image = utility.loadImage(named: "a.circle", colors: NCBrandColor.shared.iconImageMultiColors) - cell.info?.text = NSLocalizedString("_status_wait_rename_", comment: "") - case global.metadataStatusWaitDownload: - cell.statusImageView?.image = utility.loadImage(named: "arrow.triangle.2.circlepath", colors: NCBrandColor.shared.iconImageMultiColors) - case global.metadataStatusDownloading: - cell.statusImageView?.image = utility.loadImage(named: "arrowshape.down.circle", colors: NCBrandColor.shared.iconImageMultiColors) - case global.metadataStatusDownloadError, global.metadataStatusUploadError: - cell.statusImageView?.image = utility.loadImage(named: "exclamationmark.circle", colors: NCBrandColor.shared.iconImageMultiColors) - default: - break - } - - // AVATAR - if !metadata.ownerId.isEmpty, metadata.ownerId != metadata.userId { - let fileName = NCSession.shared.getFileName(urlBase: metadata.urlBase, user: metadata.ownerId) - if let image = NCImageCache.shared.getImageCache(key: fileName) { - cell.avatarImageView?.contentMode = .scaleAspectFill - cell.avatarImageView?.image = image - } else { - self.database.getImageAvatarLoaded(fileName: fileName) { image, tblAvatar in - if let image { - cell.avatarImageView?.contentMode = .scaleAspectFill - cell.avatarImageView?.image = image - NCImageCache.shared.addImageCache(image: image, key: fileName) - } else { - cell.avatarImageView?.contentMode = .scaleAspectFill - cell.avatarImageView?.image = self.utility.loadUserImage(for: metadata.ownerId, displayName: metadata.ownerDisplayName, urlBase: metadata.urlBase) - } - - if !(tblAvatar?.loaded ?? false), - self.networking.downloadAvatarQueue.operations.filter({ ($0 as? NCOperationDownloadAvatar)?.fileName == fileName }).isEmpty { - self.networking.downloadAvatarQueue.addOperation(NCOperationDownloadAvatar(user: metadata.ownerId, fileName: fileName, account: metadata.account, view: collectionView)) - } - } - } - } - - // URL - if metadata.classFile == NKTypeClassFile.url.rawValue { - cell.localImageView?.image = nil - cell.hideButtonShare(true) - cell.hideButtonMore(true) - } - - // Separator - if collectionView.numberOfItems(inSection: indexPath.section) == indexPath.row + 1 || isSearchingMode { - cell.separatorView?.isHidden = true - } else { - cell.separatorView?.isHidden = false - } - - // Edit mode - if fileSelect.contains(metadata.ocId) { - cell.selected(true, isEditMode: isEditMode) - a11yValues.append(NSLocalizedString("_selected_", comment: "")) - } else { - cell.selected(false, isEditMode: isEditMode) - } - - // Accessibility - cell.setAccessibility(label: metadata.fileNameView + ", " + (cell.info?.text ?? "") + (cell.subInfo?.text ?? ""), value: a11yValues.joined(separator: ", ")) - - // Color string find in search - cell.title?.textColor = NCBrandColor.shared.textColor - cell.title?.font = .systemFont(ofSize: 15) - - if isSearchingMode, - let searchResultStore, - let title = cell.title?.text { - let longestWordRange = (title.lowercased() as NSString).range(of: searchResultStore) - let attributedString = NSMutableAttributedString(string: title, attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 15)]) - attributedString.setAttributes([NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 15), NSAttributedString.Key.foregroundColor: UIColor.systemBlue], range: longestWordRange) - cell.title?.attributedText = attributedString - } - - // TAGS - cell.setTags(tags: Array(metadata.tags)) - - // SearchingMode - TAG Separator Hidden - if isSearchingMode { - cell.tagSeparator?.isHidden = true - } - - // Layout photo - if isLayoutPhoto { - let width = UIScreen.main.bounds.width / CGFloat(self.numberOfColumns) - - cell.hideImageFavorite(false) - cell.hideImageLocal(false) - cell.hideImageItem(false) - cell.hideButtonMore(false) - cell.hideLabelInfo(false) - cell.hideLabelSubinfo(false) - cell.hideImageStatus(false) - cell.title?.font = UIFont.systemFont(ofSize: 15) - - if width < 120 { - cell.hideImageFavorite(true) - cell.hideImageLocal(true) - cell.title?.font = UIFont.systemFont(ofSize: 10) - if width < 100 { - cell.hideImageItem(true) - cell.hideButtonMore(true) - cell.hideLabelInfo(true) - cell.hideLabelSubinfo(true) - cell.hideImageStatus(true) - } - } - } - - // Hide buttons - if metadata.name != global.appName { - cell.titleInfoTrailingFull() - cell.hideButtonShare(true) - cell.hideButtonMore(true) - } - - cell.setIconOutlines() - - // Obligatory here, at the end !! - cell.metadata = metadata - - return cell } func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView { diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon+Search.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon+Search.swift index 10a8c63438..799e0e6b77 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon+Search.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon+Search.swift @@ -327,4 +327,3 @@ extension NCCollectionViewCommon { return metadata } } - diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift index 51fdabae6f..e1a560361c 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift @@ -13,124 +13,131 @@ class NCCollectionViewCommon: UIViewController, NCAccountSettingsModelDelegate, @IBOutlet weak var collectionView: UICollectionView! - let database = NCManageDatabase.shared - let global = NCGlobal.shared - let utility = NCUtility() - let utilityFileSystem = NCUtilityFileSystem() - let imageCache = NCImageCache.shared - var dataSource = NCCollectionViewDataSource() - let networking = NCNetworking.shared - let appDelegate = (UIApplication.shared.delegate as? AppDelegate)! - var pinchGesture: UIPinchGestureRecognizer = UIPinchGestureRecognizer() - - var autoUploadFileName = "" - var autoUploadDirectory = "" - let refreshControl = UIRefreshControl() - var searchController: UISearchController? - var backgroundImageView = UIImageView() - var serverUrl: String = "" - var isEditMode = false - var isDirectoryE2EE = false - var fileSelect: [String] = [] - var metadataFolder: tableMetadata? - var richWorkspaceText: String? - var sectionFirstHeader: NCSectionFirstHeader? - var sectionFirstHeaderEmptyData: NCSectionFirstHeaderEmptyData? + internal let database = NCManageDatabase.shared + internal let global = NCGlobal.shared + internal let utility = NCUtility() + internal let utilityFileSystem = NCUtilityFileSystem() + internal let imageCache = NCImageCache.shared + internal var dataSource = NCCollectionViewDataSource() + internal let networking = NCNetworking.shared + internal let appDelegate = (UIApplication.shared.delegate as? AppDelegate)! + internal var pinchGesture: UIPinchGestureRecognizer = UIPinchGestureRecognizer() + + internal var autoUploadFileName = "" + internal var autoUploadDirectory = "" + internal let refreshControl = UIRefreshControl() + internal var searchController: UISearchController? + internal var backgroundImageView = UIImageView() + internal var serverUrl: String = "" + internal var isEditMode = false + internal var isDirectoryE2EE = false + internal var fileSelect: [String] = [] + internal var metadataFolder: tableMetadata? + internal var richWorkspaceText: String? + internal var sectionFirstHeader: NCSectionFirstHeader? + internal var sectionFirstHeaderEmptyData: NCSectionFirstHeaderEmptyData? + // Layout - var layoutForView: NCDBLayoutForView? - var layoutForViewLayoutStore: String? - var listLayout = NCListLayout() - var gridLayout = NCGridLayout() - var mediaLayout = NCMediaLayout() - var layoutType = NCGlobal.shared.layoutList - - var tabBarSelect: NCCollectionViewCommonSelectTabBar? - var attributesZoomIn: UIMenuElement.Attributes = [] - var attributesZoomOut: UIMenuElement.Attributes = [] - var tipViewAccounts: EasyTipView? - var syncMetadatasTask: Task? + // + internal var layoutForView: NCDBLayoutForView? + internal var layoutForViewLayoutStore: String? + internal var listLayout = NCListLayout() + internal var gridLayout = NCGridLayout() + internal var mediaLayout = NCMediaLayout() + internal var layoutType = NCGlobal.shared.layoutList + + internal var tabBarSelect: NCCollectionViewCommonSelectTabBar? + + internal var attributesZoomIn: UIMenuElement.Attributes = [] + internal var attributesZoomOut: UIMenuElement.Attributes = [] + + internal var tipViewAccounts: EasyTipView? + internal var syncMetadatasTask: Task? + // Search - var isSearchingMode: Bool = false - var networkSearchInProgress: Bool = false - var searchOperationHandle = NKOperationHandle() - var searchTask: URLSessionTask? - var searchResultText: String? - var searchResultStore: String? + // + internal var isSearchingMode: Bool = false + internal var networkSearchInProgress: Bool = false + internal var searchOperationHandle = NKOperationHandle() + internal var searchTask: URLSessionTask? + internal var searchResultText: String? + internal var searchResultStore: String? // DECLARE - var layoutKey = "" - var titleCurrentFolder = "" - var titlePreviusFolder: String? - var enableSearchBar: Bool = false - var headerRichWorkspaceDisable: Bool = false - - var emptyImageName: String? - var emptyImageColors: [UIColor]? - var emptyTitle: String = "" - - var emptyDescription: String = "" - var emptyDataPortaitOffset: CGFloat = 0 - var emptyDataLandscapeOffset: CGFloat = -20 - - var lastScale: CGFloat = 1.0 - var currentScale: CGFloat = 1.0 - var maxColumns: Int { + // + internal var layoutKey = "" + internal var titleCurrentFolder = "" + internal var titlePreviusFolder: String? + internal var enableSearchBar: Bool = false + internal var headerRichWorkspaceDisable: Bool = false + + internal var emptyImageName: String? + internal var emptyImageColors: [UIColor]? + internal var emptyTitle: String = "" + + internal var emptyDescription: String = "" + internal var emptyDataPortaitOffset: CGFloat = 0 + internal var emptyDataLandscapeOffset: CGFloat = -20 + + internal var lastScale: CGFloat = 1.0 + internal var currentScale: CGFloat = 1.0 + internal var maxColumns: Int { let screenWidth = min(UIScreen.main.bounds.width, UIScreen.main.bounds.height) let column = Int(screenWidth / 44) return column } - var transitionColumns = false - var numberOfColumns: Int = 0 - var lastNumberOfColumns: Int = 0 + internal var transitionColumns = false + internal var numberOfColumns: Int = 0 + internal var lastNumberOfColumns: Int = 0 - let heightHeaderRecommendations: CGFloat = 160 - let heightHeaderSection: CGFloat = 30 + internal let heightHeaderRecommendations: CGFloat = 160 + internal let heightHeaderSection: CGFloat = 30 @MainActor - var session: NCSession.Session { + internal var session: NCSession.Session { NCSession.shared.getSession(controller: tabBarController) } - var isLayoutPhoto: Bool { + internal var isLayoutPhoto: Bool { layoutForView?.layout == global.layoutPhotoRatio || layoutForView?.layout == global.layoutPhotoSquare } - var isLayoutGrid: Bool { + internal var isLayoutGrid: Bool { layoutForView?.layout == global.layoutGrid } - var isLayoutList: Bool { + internal var isLayoutList: Bool { layoutForView?.layout == global.layoutList } - var showDescription: Bool { + internal var showDescription: Bool { !headerRichWorkspaceDisable && NCPreferences().showDescription } - var isRecommendationActived: Bool { + internal var isRecommendationActived: Bool { let capabilities = NCNetworking.shared.capabilities[session.account] ?? NKCapabilities.Capabilities() return self.serverUrl == self.utilityFileSystem.getHomeServer(session: self.session) && capabilities.recommendations } - var infoLabelsSeparator: String { + internal var infoLabelsSeparator: String { layoutForView?.layout == global.layoutList ? " - " : "" } @MainActor - var controller: NCMainTabBarController? { + internal var controller: NCMainTabBarController? { self.tabBarController as? NCMainTabBarController } - var mainNavigationController: NCMainNavigationController? { + internal var mainNavigationController: NCMainNavigationController? { self.navigationController as? NCMainNavigationController } - var sceneIdentifier: String { + internal var sceneIdentifier: String { (self.tabBarController as? NCMainTabBarController)?.sceneIdentifier ?? "" } - var isNumberOfItemsInAllSectionsNull: Bool { + internal var isNumberOfItemsInAllSectionsNull: Bool { var totalItems = 0 for section in 0.. 100 { - cell.hideButtonMore(false) - cell.hideImageStatus(false) + previewImage.layer.borderWidth = 0.2 + previewImage.layer.borderColor = UIColor.systemGray3.cgColor } UIView.transition( - with: previewImageView, + with: previewImage, duration: 0.75, options: .transitionCrossDissolve, animations: { - previewImageView.image = image + previewImage.image = image }, completion: nil ) diff --git a/iOSClient/Main/NCMainNavigationController.swift b/iOSClient/Main/NCMainNavigationController.swift index edf171945f..3b7a5d7a1d 100644 --- a/iOSClient/Main/NCMainNavigationController.swift +++ b/iOSClient/Main/NCMainNavigationController.swift @@ -40,44 +40,26 @@ class NCMainNavigationController: UINavigationController, UINavigationController let notificationsButtonTag = 102 let transfersButtonTag = 103 - lazy var menuButton: UIButton = { - let button = UIButton(type: .system) - return button - }() - var menuBarButtonItem: UIBarButtonItem { - let item = UIBarButtonItem(customView: menuButton) + lazy var menuBarButtonItem: UIBarButtonItem = { + let item = UIBarButtonItem() item.tag = menuButtonTag return item - } - lazy var assistantButton: UIButton = { - let button = UIButton(type: .system) - return button }() - var assistantButtonItem: UIBarButtonItem { - let item = UIBarButtonItem(customView: assistantButton) + lazy var assistantButtonItem: UIBarButtonItem = { + let item = UIBarButtonItem() item.tag = assistantButtonTag return item - } - - lazy var notificationsButton: UIButton = { - let button = UIButton(type: .system) - return button }() - var notificationsButtonItem: UIBarButtonItem { - let item = UIBarButtonItem(customView: notificationsButton) + lazy var notificationsButtonItem: UIBarButtonItem = { + let item = UIBarButtonItem() item.tag = notificationsButtonTag return item - } - - lazy var transfersButton: UIButton = { - let button = UIButton(type: .system) - return button }() - var transfersButtonItem: UIBarButtonItem { - let item = UIBarButtonItem(customView: transfersButton) + lazy var transfersButtonItem: UIBarButtonItem = { + let item = UIBarButtonItem() item.tag = transfersButtonTag return item - } + }() // MARK: - View Life Cycle @@ -89,35 +71,37 @@ class NCMainNavigationController: UINavigationController, UINavigationController setNavigationBarHidden(false, animated: true) Task { - menuButton.setImage(UIImage(systemName: "ellipsis"), for: .normal) - menuButton.tintColor = NCBrandColor.shared.iconImageColor - menuButton.menu = await createRightMenu() - menuButton.showsMenuAsPrimaryAction = true + menuBarButtonItem.image = UIImage(systemName: "ellipsis") + menuBarButtonItem.tintColor = NCBrandColor.shared.iconImageColor + menuBarButtonItem.menu = await createRightMenu() } - assistantButton.setImage(UIImage(systemName: "sparkles"), for: .normal) - assistantButton.tintColor = NCBrandColor.shared.iconImageColor - assistantButton.addAction(UIAction(handler: { _ in + assistantButtonItem.image = UIImage(systemName: "sparkles") + assistantButtonItem.title = NSLocalizedString("_assistant_", comment: "") + assistantButtonItem.tintColor = NCBrandColor.shared.iconImageColor + assistantButtonItem.primaryAction = UIAction(handler: { _ in let assistant = NCAssistant() .environmentObject(NCAssistantModel(controller: self.controller)) let hostingController = UIHostingController(rootView: assistant) self.present(hostingController, animated: true, completion: nil) - }), for: .touchUpInside) + }) - notificationsButton.setImage(UIImage(systemName: "bell.fill"), for: .normal) - notificationsButton.tintColor = NCBrandColor.shared.iconImageColor - notificationsButton.addAction(UIAction(handler: { _ in + notificationsButtonItem.image = UIImage(systemName: "bell.fill") + notificationsButtonItem.title = NSLocalizedString("_notifications_", comment: "") + notificationsButtonItem.tintColor = NCBrandColor.shared.iconImageColor + notificationsButtonItem.primaryAction = UIAction(handler: { _ in if let navigationController = UIStoryboard(name: "NCNotification", bundle: nil).instantiateInitialViewController() as? UINavigationController, let viewController = navigationController.topViewController as? NCNotification { viewController.modalPresentationStyle = .pageSheet viewController.session = self.session self.present(navigationController, animated: true, completion: nil) } - }), for: .touchUpInside) + }) - transfersButton.setImage(UIImage(systemName: "arrow.left.arrow.right.circle.fill"), for: .normal) - transfersButton.tintColor = NCBrandColor.shared.iconImageColor - transfersButton.addAction(UIAction(handler: { _ in + transfersButtonItem.image = UIImage(systemName: "arrow.left.arrow.right.circle.fill") + transfersButtonItem.title = NSLocalizedString("_transfers_", comment: "") + transfersButtonItem.tintColor = NCBrandColor.shared.iconImageColor + transfersButtonItem.primaryAction = UIAction(handler: { _ in let rootView = TransfersView(session: self.session, onClose: { [weak self] in self?.dismiss(animated: true) }) @@ -125,7 +109,7 @@ class NCMainNavigationController: UINavigationController, UINavigationController hosting.modalPresentationStyle = .pageSheet self.present(hosting, animated: true) - }), for: .touchUpInside) + }) // PLUS BUTTON ONLY IN FILES let widthAnchor: CGFloat @@ -186,8 +170,10 @@ class NCMainNavigationController: UINavigationController, UINavigationController } else { _ = await NextcloudKit.shared.getNotificationsAsync(account: account) { task in Task { - let identifier = await NCNetworking.shared.networkingTasks.createIdentifier(account: account, - name: "getNotifications") + let identifier = await NCNetworking.shared.networkingTasks.createIdentifier( + account: account, + name: "getNotifications" + ) await NCNetworking.shared.networkingTasks.track(identifier: identifier, task: task) } } @@ -612,10 +598,8 @@ class NCMainNavigationController: UINavigationController, UINavigationController func createRightMenu() async -> UIMenu? { return nil } func updateRightMenu() async { - if let rightBarButtonItems = topViewController?.navigationItem.rightBarButtonItems, - let menuBarButtonItem = rightBarButtonItems.first(where: { $0.tag == menuButtonTag }), - let menuButton = menuBarButtonItem.customView as? UIButton { - menuButton.menu = await createRightMenu() + if topViewController?.navigationItem.rightBarButtonItems?.first(where: { $0.tag == menuButtonTag }) != nil { + menuBarButtonItem.menu = await createRightMenu() } } @@ -869,11 +853,10 @@ class NCMainNavigationController: UINavigationController, UINavigationController func setRightItemColor(tag: Int, to color: UIColor) { guard let items = topViewController?.navigationItem.rightBarButtonItems, - let item = items.first(where: { $0.tag == tag }), - let button = item.customView as? UIButton + let item = items.first(where: { $0.tag == tag }) else { return } - applyTint(button, color: color) + applyTint(item, color: color) } /// Changes the tint color of all right bar button items currently visible @@ -884,9 +867,7 @@ class NCMainNavigationController: UINavigationController, UINavigationController guard let items = topViewController?.navigationItem.rightBarButtonItems else { return } for item in items { - if let button = item.customView as? UIButton { - applyTint(button, color: color) - } + applyTint(item, color: color) } } @@ -902,11 +883,10 @@ class NCMainNavigationController: UINavigationController, UINavigationController func setLeftItemColor(tag: Int, to color: UIColor) { guard let items = topViewController?.navigationItem.leftBarButtonItems, - let item = items.first(where: { $0.tag == tag }), - let button = item.customView as? UIButton + let item = items.first(where: { $0.tag == tag }) else { return } - applyTint(button, color: color) + applyTint(item, color: color) } /// Changes the tint color of all left bar button items currently visible @@ -917,9 +897,7 @@ class NCMainNavigationController: UINavigationController, UINavigationController guard let items = topViewController?.navigationItem.leftBarButtonItems else { return } for item in items { - if let button = item.customView as? UIButton { - applyTint(button, color: color) - } + applyTint(item, color: color) } } @@ -943,35 +921,33 @@ class NCMainNavigationController: UINavigationController, UINavigationController } } + @MainActor + private func applyTint(_ item: UIBarButtonItem, color: UIColor) { + if let button = item.customView as? UIButton { + applyTint(button, color: color) + } else { + item.tintColor = color + } + } + /// Updates the tint color of all preloaded and currently visible right bar buttons. /// - Parameter color: The UIColor to be applied to all right bar button items. @MainActor func updateRightBarButtonsTint(to color: UIColor) { - let rightButtons: [UIButton] = [ - menuButton, - assistantButton, - notificationsButton, - transfersButton + let rightItems: [UIBarButtonItem] = [ + menuBarButtonItem, + assistantButtonItem, + notificationsButtonItem, + transfersButtonItem ] - // Apply color to preloaded button instances - for button in rightButtons { - if var cfg = button.configuration { - cfg.baseForegroundColor = color - button.configuration = cfg - } else { - button.tintColor = color - button.setTitleColor(color, for: .normal) - } + for item in rightItems { + applyTint(item, color: color) } - // Update also those already visible in the navigation bar - if let rightItems = topViewController?.navigationItem.rightBarButtonItems { - for item in rightItems { - if let button = item.customView as? UIButton { - button.tintColor = color - button.setTitleColor(color, for: .normal) - } + if let visibleItems = topViewController?.navigationItem.rightBarButtonItems { + for item in visibleItems { + applyTint(item, color: color) } } } diff --git a/iOSClient/Networking/NCNetworking+WebDAV.swift b/iOSClient/Networking/NCNetworking+WebDAV.swift index 376b3819ba..9e761710d7 100644 --- a/iOSClient/Networking/NCNetworking+WebDAV.swift +++ b/iOSClient/Networking/NCNetworking+WebDAV.swift @@ -841,14 +841,14 @@ class NCOperationDownloadAvatar: ConcurrentOperation, @unchecked Sendable { var etag: String? var view: UIView? var account: String - var isPreviewImageView: Bool + var isPreviewImage: Bool - init(user: String, fileName: String, account: String, view: UIView?, isPreviewImageView: Bool = false) { + init(user: String, fileName: String, account: String, view: UIView?, isPreviewImage: Bool = false) { self.user = user self.fileName = fileName self.account = account self.view = view - self.isPreviewImageView = isPreviewImageView + self.isPreviewImage = isPreviewImage self.etag = NCManageDatabase.shared.getTableAvatar(fileName: fileName)?.etag } @@ -880,12 +880,12 @@ class NCOperationDownloadAvatar: ConcurrentOperation, @unchecked Sendable { DispatchQueue.main.async { let visibleCells: [UIView] = (self.view as? UICollectionView)?.visibleCells ?? (self.view as? UITableView)?.visibleCells ?? [] - for case let cell as NCCellProtocol in visibleCells { + for case let cell as NCCellMainProtocol in visibleCells { if self.user == cell.metadata?.ownerId { - if self.isPreviewImageView, let previewImageView = cell.previewImageView { - UIView.transition(with: previewImageView, duration: 0.75, options: .transitionCrossDissolve, animations: { previewImageView.image = image}, completion: nil) - } else if let avatarImageView = cell.avatarImageView { - UIView.transition(with: avatarImageView, duration: 0.75, options: .transitionCrossDissolve, animations: { avatarImageView.image = image}, completion: nil) + if self.isPreviewImage, let previewImage = cell.previewImg { + UIView.transition(with: previewImage, duration: 0.75, options: .transitionCrossDissolve, animations: { previewImage.image = image}, completion: nil) + } else if let avatarImage = cell.avatarImg { + UIView.transition(with: avatarImage, duration: 0.75, options: .transitionCrossDissolve, animations: { avatarImage.image = image}, completion: nil) } break } diff --git a/iOSClient/Notification/NCNotification.swift b/iOSClient/Notification/NCNotification.swift index 84fc727b1e..1f6f70084e 100644 --- a/iOSClient/Notification/NCNotification.swift +++ b/iOSClient/Notification/NCNotification.swift @@ -114,7 +114,7 @@ class NCNotification: UITableViewController, NCNotificationCellDelegate { guard let cell = self.tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as? NCNotificationCell else { return UITableViewCell() } cell.delegate = self cell.selectionStyle = .none - cell.indexPath = indexPath + cell.index = indexPath let notification = notifications[indexPath.row] let urlIcon = URL(string: notification.icon) @@ -142,9 +142,9 @@ class NCNotification: UITableViewController, NCNotificationCellDelegate { let results = NCManageDatabase.shared.getImageAvatarLoaded(fileName: fileName) if results.image == nil { - cell.avatarImageView?.image = utility.loadUserImage(for: user, displayName: json["user"]?["name"].string, urlBase: session.urlBase) + cell.avatar?.image = utility.loadUserImage(for: user, displayName: json["user"]?["name"].string, urlBase: session.urlBase) } else { - cell.avatarImageView?.image = results.image + cell.avatar?.image = results.image } if !(results.tblAvatar?.loaded ?? false), @@ -353,7 +353,7 @@ class NCNotification: UITableViewController, NCNotificationCellDelegate { // MARK: - -class NCNotificationCell: UITableViewCell, NCCellProtocol { +class NCNotificationCell: UITableViewCell { @IBOutlet weak var icon: UIImageView! @IBOutlet weak var avatar: UIImageView! @@ -368,24 +368,12 @@ class NCNotificationCell: UITableViewCell, NCCellProtocol { @IBOutlet weak var primaryWidth: NSLayoutConstraint! @IBOutlet weak var secondaryWidth: NSLayoutConstraint! - private var user = "" - private var index = IndexPath() + var user = "" + var index = IndexPath() weak var delegate: NCNotificationCellDelegate? var notification: NKNotifications? - var indexPath: IndexPath { - get { return index } - set { index = newValue } - } - var avatarImageView: UIImageView? { - return avatar - } - var fileUser: String? { - get { return user } - set { user = newValue ?? "" } - } - @IBAction func touchUpInsideRemove(_ sender: Any) { guard let notification = notification else { return } delegate?.tapRemove(with: notification, sender: sender) diff --git a/iOSClient/Recent/NCRecent.swift b/iOSClient/Recent/NCRecent.swift index 2379b3ab4e..1d0bb45377 100644 --- a/iOSClient/Recent/NCRecent.swift +++ b/iOSClient/Recent/NCRecent.swift @@ -141,7 +141,7 @@ class NCRecent: NCCollectionViewCommon { - /Users/marinofaggiana/Developer/ios/iOSClient/Assistant + diff --git a/iOSClient/Select/NCSelect.swift b/iOSClient/Select/NCSelect.swift index ff9bfbb213..730664e2cb 100644 --- a/iOSClient/Select/NCSelect.swift +++ b/iOSClient/Select/NCSelect.swift @@ -337,12 +337,12 @@ extension NCSelect: UICollectionViewDataSource { // Thumbnail if !metadata.directory { if let image = self.utility.getImage(ocId: metadata.ocId, etag: metadata.etag, ext: NCGlobal.shared.previewExt512, userId: metadata.userId, urlBase: metadata.urlBase) { - (cell as? NCCellProtocol)?.previewImageView?.image = image + (cell as? NCListCell)?.previewImg?.image = image } else { if metadata.iconName.isEmpty { - (cell as? NCCellProtocol)?.previewImageView?.image = NCImageCache.shared.getImageFile() + (cell as? NCListCell)?.previewImg?.image = NCImageCache.shared.getImageFile() } else { - (cell as? NCCellProtocol)?.previewImageView?.image = self.utility.loadImage(named: metadata.iconName, useTypeIconFile: true, account: metadata.account) + (cell as? NCListCell)?.previewImg?.image = self.utility.loadImage(named: metadata.iconName, useTypeIconFile: true, account: metadata.account) } if metadata.hasPreview, metadata.status == NCGlobal.shared.metadataStatusNormal { @@ -384,7 +384,7 @@ extension NCSelect: UICollectionViewDataSource { cell.imageSelect.image = nil cell.imageStatus.image = nil - cell.imageLocal.image = nil + cell.imageLocal?.image = nil cell.imageFavorite.image = nil cell.imageShared.image = nil cell.imageMore.image = nil @@ -419,9 +419,9 @@ extension NCSelect: UICollectionViewDataSource { self.database.getTableLocal(predicate: NSPredicate(format: "ocId == %@", metadata.ocId)) { tblLocalFile in if let tblLocalFile, tblLocalFile.offline { - cell.imageLocal.image = NCImageCache.shared.getImageOfflineFlag() + cell.imageLocal?.image = NCImageCache.shared.getImageOfflineFlag() } else if self.utilityFileSystem.fileProviderStorageExists(metadata) { - cell.imageLocal.image = NCImageCache.shared.getImageLocal() + cell.imageLocal?.image = NCImageCache.shared.getImageLocal() } } } diff --git a/iOSClient/Share/NCShare.swift b/iOSClient/Share/NCShare.swift index 02b4ee6fe4..fbe1b89155 100644 --- a/iOSClient/Share/NCShare.swift +++ b/iOSClient/Share/NCShare.swift @@ -484,7 +484,7 @@ extension NCShare: UITableViewDataSource { } else { // USER / GROUP etc. if let cell = tableView.dequeueReusableCell(withIdentifier: "cellUser", for: indexPath) as? NCShareUserCell { - cell.indexPath = indexPath + cell.index = indexPath cell.tableShare = tableShare cell.isDirectory = metadata.directory cell.delegate = self diff --git a/iOSClient/Share/NCShareCommentsCell.swift b/iOSClient/Share/NCShareCommentsCell.swift index 80952a7684..9bbf034968 100644 --- a/iOSClient/Share/NCShareCommentsCell.swift +++ b/iOSClient/Share/NCShareCommentsCell.swift @@ -26,7 +26,7 @@ import NextcloudKit // MARK: - NCShareCommentsCell -class NCShareCommentsCell: UITableViewCell, NCCellProtocol { +class NCShareCommentsCell: UITableViewCell { @IBOutlet weak var imageItem: UIImageView! @IBOutlet weak var labelUser: UILabel! @@ -44,7 +44,7 @@ class NCShareCommentsCell: UITableViewCell, NCCellProtocol { get { return index } set { index = newValue } } - var avatarImageView: UIImageView? { + var avatarImage: UIImageView? { return imageItem } var fileUser: String? { diff --git a/iOSClient/Share/NCShareUserCell.swift b/iOSClient/Share/NCShareUserCell.swift index ee953deea5..87e692ce31 100644 --- a/iOSClient/Share/NCShareUserCell.swift +++ b/iOSClient/Share/NCShareUserCell.swift @@ -24,7 +24,7 @@ import UIKit import DropDown import NextcloudKit -class NCShareUserCell: UITableViewCell, NCCellProtocol { +class NCShareUserCell: UITableViewCell { @IBOutlet weak var imageItem: UIImageView! @IBOutlet weak var labelTitle: UILabel! @IBOutlet weak var buttonMenu: UIButton! @@ -34,26 +34,14 @@ class NCShareUserCell: UITableViewCell, NCCellProtocol { @IBOutlet weak var labelQuickStatus: UILabel! @IBOutlet weak var imageDownArrow: UIImageView! - private var index = IndexPath() - private var avatarButton: UIButton! + var index = IndexPath() + var avatarButton: UIButton! var tableShare: tableShare? var isDirectory = false let utility = NCUtility() weak var delegate: NCShareUserCellDelegate? - var indexPath: IndexPath { - get { return index } - set { index = newValue } - } - var avatarImageView: UIImageView? { - return imageItem - } - var fileUser: String? { - get { return tableShare?.shareWith } - set {} - } - func setupCellUI(userId: String, session: NCSession.Session, metadata: tableMetadata) { guard let tableShare = tableShare else { return @@ -171,7 +159,7 @@ protocol NCShareUserCellDelegate: AnyObject { // MARK: - NCSearchUserDropDownCell -class NCSearchUserDropDownCell: DropDownCell, NCCellProtocol { +class NCSearchUserDropDownCell: DropDownCell { @IBOutlet weak var imageItem: UIImageView! @IBOutlet weak var imageStatus: UIImageView! @@ -179,22 +167,10 @@ class NCSearchUserDropDownCell: DropDownCell, NCCellProtocol { @IBOutlet weak var imageShareeType: UIImageView! @IBOutlet weak var centerTitle: NSLayoutConstraint! - private var user: String = "" - private var index = IndexPath() + var user: String = "" + var index = IndexPath() private let utilityFileSystem = NCUtilityFileSystem() - var indexPath: IndexPath { - get { return index } - set { index = newValue } - } - var avatarImageView: UIImageView? { - return imageItem - } - var fileUser: String? { - get { return user } - set { user = newValue ?? "" } - } - func setupCell(sharee: NKSharee, session: NCSession.Session) { let utility = NCUtility() imageItem.image = NCShareCommon.getImageShareType(shareType: sharee.shareType) diff --git a/iOSClient/Trash/Cell/NCTrashGridCell.swift b/iOSClient/Trash/Cell/NCTrashGridCell.swift index 0fae0620f7..5c03bbb5b4 100644 --- a/iOSClient/Trash/Cell/NCTrashGridCell.swift +++ b/iOSClient/Trash/Cell/NCTrashGridCell.swift @@ -28,7 +28,6 @@ protocol NCTrashGridCellDelegate: AnyObject { } class NCTrashGridCell: UICollectionViewCell, NCTrashCellProtocol { - @IBOutlet weak var imageItem: UIImageView! @IBOutlet weak var imageSelect: UIImageView! @IBOutlet weak var labelTitle: UILabel! @@ -93,10 +92,6 @@ class NCTrashGridCell: UICollectionViewCell, NCTrashCellProtocol { setA11yActions() } - func hideButtonMore(_ status: Bool) { - buttonMore.isHidden = status - } - func selected(_ status: Bool, isEditMode: Bool, account: String) { if isEditMode { buttonMore.isHidden = true