diff --git a/File Provider Extension/FileProviderEnumerator.swift b/File Provider Extension/FileProviderEnumerator.swift index 1f2058e681..244b69948d 100644 --- a/File Provider Extension/FileProviderEnumerator.swift +++ b/File Provider Extension/FileProviderEnumerator.swift @@ -160,7 +160,7 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator { let predicate = NSPredicate(format: "account == %@ AND serverUrl == %@", fileProviderData.shared.account, serverUrl) if pageNumber == 1 { - NextcloudKit.shared.readFileOrFolder(serverUrlFileName: serverUrl, depth: "1", showHiddenFiles: NCKeychain().showHiddenFiles) { _, files, _, error in + NextcloudKit.shared.readFileOrFolder(serverUrlFileName: serverUrl, depth: "1", showHiddenFiles: NCKeychain().showHiddenFiles, account: fileProviderData.shared.account) { _, files, _, error in if error == .success { NCManageDatabase.shared.convertFilesToMetadatas(files, useFirstAsMetadataFolder: true) { metadataFolder, metadatas in /// FOLDER diff --git a/File Provider Extension/FileProviderExtension+Actions.swift b/File Provider Extension/FileProviderExtension+Actions.swift index b1e7921454..198f5ff29a 100644 --- a/File Provider Extension/FileProviderExtension+Actions.swift +++ b/File Provider Extension/FileProviderExtension+Actions.swift @@ -33,9 +33,9 @@ extension FileProviderExtension { let directoryName = utilityFileSystem.createFileName(directoryName, serverUrl: tableDirectory.serverUrl, account: fileProviderData.shared.account) let serverUrlFileName = tableDirectory.serverUrl + "/" + directoryName - NextcloudKit.shared.createFolder(serverUrlFileName: serverUrlFileName) { _, ocId, _, error in + NextcloudKit.shared.createFolder(serverUrlFileName: serverUrlFileName, account: fileProviderData.shared.account) { _, ocId, _, error in if error == .success { - NextcloudKit.shared.readFileOrFolder(serverUrlFileName: serverUrlFileName, depth: "0", showHiddenFiles: NCKeychain().showHiddenFiles) { _, files, _, error in + NextcloudKit.shared.readFileOrFolder(serverUrlFileName: serverUrlFileName, depth: "0", showHiddenFiles: NCKeychain().showHiddenFiles, account: fileProviderData.shared.account) { _, files, _, error in if error == .success, let file = files.first { let isDirectoryEncrypted = self.utilityFileSystem.isDirectoryE2EE(file: file) let metadata = NCManageDatabase.shared.convertFileToMetadata(file, isDirectoryE2EE: isDirectoryEncrypted) @@ -69,7 +69,7 @@ extension FileProviderExtension { let serverUrl = metadata.serverUrl let fileName = metadata.fileName - NextcloudKit.shared.deleteFileOrFolder(serverUrlFileName: serverUrlFileName) { account, error in + NextcloudKit.shared.deleteFileOrFolder(serverUrlFileName: serverUrlFileName, account: metadata.account) { account, error in if error == .success { // || error == kOCErrorServerPathNotFound { let fileNamePath = self.utilityFileSystem.getDirectoryProviderStorageOcId(itemIdentifier.rawValue) @@ -107,7 +107,7 @@ extension FileProviderExtension { let serverUrlTo = tableDirectoryTo.serverUrl let fileNameTo = serverUrlTo + "/" + itemFrom.filename - NextcloudKit.shared.moveFileOrFolder(serverUrlFileNameSource: fileNameFrom, serverUrlFileNameDestination: fileNameTo, overwrite: false) { account, error in + NextcloudKit.shared.moveFileOrFolder(serverUrlFileNameSource: fileNameFrom, serverUrlFileNameDestination: fileNameTo, overwrite: false, account: metadataFrom.account) { account, error in if error == .success { if metadataFrom.directory { NCManageDatabase.shared.deleteDirectoryAndSubDirectory(serverUrl: serverUrlFrom, account: account) @@ -138,7 +138,7 @@ extension FileProviderExtension { let fileNamePathTo = metadata.serverUrl + "/" + itemName let ocId = metadata.ocId - NextcloudKit.shared.moveFileOrFolder(serverUrlFileNameSource: fileNamePathFrom, serverUrlFileNameDestination: fileNamePathTo, overwrite: false) { account, error in + NextcloudKit.shared.moveFileOrFolder(serverUrlFileNameSource: fileNamePathFrom, serverUrlFileNameDestination: fileNamePathTo, overwrite: false, account: metadata.account) { account, error in if error == .success { // Rename metadata NCManageDatabase.shared.renameMetadata(fileNameTo: itemName, ocId: ocId) @@ -185,7 +185,7 @@ extension FileProviderExtension { if (favorite == true && metadata.favorite == false) || (favorite == false && metadata.favorite == true) { let fileNamePath = utilityFileSystem.getFileNamePath(metadata.fileName, serverUrl: metadata.serverUrl, urlBase: metadata.urlBase, userId: metadata.userId) - NextcloudKit.shared.setFavorite(fileName: fileNamePath, favorite: favorite) { _, error in + NextcloudKit.shared.setFavorite(fileName: fileNamePath, favorite: favorite, account: metadata.account) { _, error in if error == .success { guard let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) else { return completionHandler(nil, NSFileProviderError(.noSuchItem)) diff --git a/File Provider Extension/FileProviderExtension+Thumbnail.swift b/File Provider Extension/FileProviderExtension+Thumbnail.swift index 17a9d9d055..70bfcb550a 100644 --- a/File Provider Extension/FileProviderExtension+Thumbnail.swift +++ b/File Provider Extension/FileProviderExtension+Thumbnail.swift @@ -38,7 +38,7 @@ extension FileProviderExtension { } let fileNameIconLocalPath = utilityFileSystem.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag) - NextcloudKit.shared.downloadPreview(fileId: metadata.fileId, widthPreview: Int(size.width), heightPreview: Int(size.height), etag: metadata.etag) { _ in + NextcloudKit.shared.downloadPreview(fileId: metadata.fileId, widthPreview: Int(size.width), heightPreview: Int(size.height), etag: metadata.etag, account: metadata.account) { _ in } completion: { _, data, error in if error == .success, let data { do { diff --git a/File Provider Extension/FileProviderExtension.swift b/File Provider Extension/FileProviderExtension.swift index 799f42ec22..1666cd625a 100644 --- a/File Provider Extension/FileProviderExtension.swift +++ b/File Provider Extension/FileProviderExtension.swift @@ -195,7 +195,7 @@ class FileProviderExtension: NSFileProviderExtension { /// SIGNAL fileProviderData.shared.signalEnumerator(ocId: metadata.ocId, type: .update) - NextcloudKit.shared.download(serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath, requestHandler: { _ in + NextcloudKit.shared.download(serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath, account: metadata.account, requestHandler: { _ in }, taskHandler: { task in NCManageDatabase.shared.setMetadataSession(ocId: metadata.ocId, taskIdentifier: task.taskIdentifier) @@ -254,7 +254,7 @@ class FileProviderExtension: NSFileProviderExtension { sessionError: "", selector: "", status: NCGlobal.shared.metadataStatusUploading) - if let task = NKBackground(nkCommonInstance: NextcloudKit.shared.nkCommonInstance).upload(serverUrlFileName: serverUrlFileName, fileNameLocalPath: url.path, dateCreationFile: nil, dateModificationFile: nil, session: NCNetworking.shared.sessionManagerUploadBackgroundExtension) { + if let task = NKBackground(nkCommonInstance: NextcloudKit.shared.nkCommonInstance).upload(serverUrlFileName: serverUrlFileName, fileNameLocalPath: url.path, dateCreationFile: nil, dateModificationFile: nil, account: metadata.account, session: NCNetworking.shared.sessionManagerUploadBackgroundExtension) { NCManageDatabase.shared.setMetadataSession(ocId: metadata.ocId, status: NCGlobal.shared.metadataStatusUploading, taskIdentifier: task.taskIdentifier) @@ -318,7 +318,7 @@ class FileProviderExtension: NSFileProviderExtension { let serverUrlFileName = tableDirectory.serverUrl + "/" + fileName let fileNameLocalPath = self.utilityFileSystem.getDirectoryProviderStorageOcId(ocIdTemp, fileNameView: fileName) - if let task = NKBackground(nkCommonInstance: NextcloudKit.shared.nkCommonInstance).upload(serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath, dateCreationFile: nil, dateModificationFile: nil, session: NCNetworking.shared.sessionManagerUploadBackgroundExtension) { + if let task = NKBackground(nkCommonInstance: NextcloudKit.shared.nkCommonInstance).upload(serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath, dateCreationFile: nil, dateModificationFile: nil, account: metadata.account, session: NCNetworking.shared.sessionManagerUploadBackgroundExtension) { NCManageDatabase.shared.setMetadataSession(ocId: metadata.ocId, status: NCGlobal.shared.metadataStatusUploading, taskIdentifier: task.taskIdentifier) diff --git a/Nextcloud.xcodeproj/project.pbxproj b/Nextcloud.xcodeproj/project.pbxproj index 6c2c0ed949..71e5d3b810 100644 --- a/Nextcloud.xcodeproj/project.pbxproj +++ b/Nextcloud.xcodeproj/project.pbxproj @@ -5414,7 +5414,7 @@ CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 13; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = NKUJUXUJ3B; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -5441,7 +5441,7 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 5.5.2; + MARKETING_VERSION = 5.5.3; ONLY_ACTIVE_ARCH = YES; OTHER_CFLAGS = "-v"; OTHER_LDFLAGS = ""; @@ -5480,7 +5480,7 @@ CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 13; DEVELOPMENT_TEAM = NKUJUXUJ3B; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; @@ -5504,7 +5504,7 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 5.5.2; + MARKETING_VERSION = 5.5.3; ONLY_ACTIVE_ARCH = YES; OTHER_CFLAGS = "-v"; OTHER_LDFLAGS = ""; @@ -5779,7 +5779,7 @@ repositoryURL = "https://github.com/nextcloud/NextcloudKit"; requirement = { kind = exactVersion; - version = 4.0.3; + version = 4.0.4; }; }; F788ECC5263AAAF900ADC67F /* XCRemoteSwiftPackageReference "MarkdownKit" */ = { diff --git a/Share/NCShareExtension.swift b/Share/NCShareExtension.swift index f71371c2c1..d7c91c4e8f 100644 --- a/Share/NCShareExtension.swift +++ b/Share/NCShareExtension.swift @@ -278,7 +278,7 @@ class NCShareExtension: UIViewController { } @objc func actionCreateFolder() { - let alertController = UIAlertController.createFolder(serverUrl: serverUrl, urlBase: activeAccount) { error in + let alertController = UIAlertController.createFolder(serverUrl: serverUrl, userBaseUrl: activeAccount) { error in guard error != .success else { return } self.showAlert(title: "_error_createsubfolders_upload_", description: error.errorDescription) } diff --git a/Widget/Dashboard/DashboardData.swift b/Widget/Dashboard/DashboardData.swift index ef8ebf9a09..ce161954d0 100644 --- a/Widget/Dashboard/DashboardData.swift +++ b/Widget/Dashboard/DashboardData.swift @@ -168,7 +168,7 @@ func getDashboardDataEntry(configuration: DashboardIntent?, isPreview: Bool, dis let titleImage = imagetmp let options = NKRequestOptions(timeout: 90, queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue) - NextcloudKit.shared.getDashboardWidgetsApplication(id, options: options) { _, results, data, error in + NextcloudKit.shared.getDashboardWidgetsApplication(id, account: account.account, options: options) { _, results, data, error in Task { var datas = [DashboardData]() var numberItems = 0 @@ -225,7 +225,7 @@ func getDashboardDataEntry(configuration: DashboardIntent?, isPreview: Bool, dis if FileManager().fileExists(atPath: fileNamePath), let image = UIImage(contentsOfFile: fileNamePath) { icon = image } else { - let (_, data, error) = await NCNetworking.shared.downloadPreview(url: url) + let (_, data, error) = await NCNetworking.shared.downloadPreview(url: url, account: account.account) if error == .success, let image = convertDataToImage(data: data, size: CGSize(width: 256, height: 256), fileNameToWrite: fileName) { icon = image diff --git a/Widget/Files/FilesData.swift b/Widget/Files/FilesData.swift index 85fbfa99f4..21922d6682 100644 --- a/Widget/Files/FilesData.swift +++ b/Widget/Files/FilesData.swift @@ -190,7 +190,7 @@ func getFilesDataEntry(configuration: AccountIntent?, isPreview: Bool, displaySi } let options = NKRequestOptions(timeout: 30, queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue) - NextcloudKit.shared.searchBodyRequest(serverUrl: account.urlBase, requestBody: requestBody, showHiddenFiles: NCKeychain().showHiddenFiles, options: options) { _, files, data, error in + NextcloudKit.shared.searchBodyRequest(serverUrl: account.urlBase, requestBody: requestBody, showHiddenFiles: NCKeychain().showHiddenFiles, account: account.account, options: options) { _, files, data, error in Task { var datas: [FilesData] = [] let title = getTitleFilesWidget(account: account) @@ -223,7 +223,7 @@ func getFilesDataEntry(configuration: AccountIntent?, isPreview: Bool, displaySi } if image == nil, file.hasPreview { let sizePreview = NCUtility().getSizePreview(width: Int(file.width), height: Int(file.height)) - let (_, _, imageIcon, _, _, _) = await NCNetworking.shared.downloadPreview(fileId: file.fileId, fileNamePreviewLocalPath: fileNamePreviewLocalPath, fileNameIconLocalPath: fileNameIconLocalPath, widthPreview: Int(sizePreview.width), heightPreview: Int(sizePreview.height), sizeIcon: NCGlobal.shared.sizeIcon, options: options) + let (_, _, imageIcon, _, _, _) = await NCNetworking.shared.downloadPreview(fileId: file.fileId, fileNamePreviewLocalPath: fileNamePreviewLocalPath, fileNameIconLocalPath: fileNameIconLocalPath, widthPreview: Int(sizePreview.width), heightPreview: Int(sizePreview.height), sizeIcon: NCGlobal.shared.sizeIcon, account: account.account, options: options) image = imageIcon } if image == nil { diff --git a/Widget/Lockscreen/LockscreenData.swift b/Widget/Lockscreen/LockscreenData.swift index 48a971d645..0fe7b8476e 100644 --- a/Widget/Lockscreen/LockscreenData.swift +++ b/Widget/Lockscreen/LockscreenData.swift @@ -52,7 +52,7 @@ func getLockscreenDataEntry(configuration: AccountIntent?, isPreview: Bool, fami account = NCManageDatabase.shared.getAccount(predicate: NSPredicate(format: "account == %@", accountIdentifier)) } - guard let account = account else { + guard let account else { return completion(LockscreenData(date: Date(), isPlaceholder: true, activity: "", link: URL(string: "https://")!, quotaRelative: 0, quotaUsed: "", quotaTotal: "", error: false)) } @@ -78,7 +78,7 @@ func getLockscreenDataEntry(configuration: AccountIntent?, isPreview: Bool, fami let options = NKRequestOptions(timeout: 90, queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue) if #available(iOSApplicationExtension 16.0, *) { if family == .accessoryCircular { - NextcloudKit.shared.getUserProfile(options: options) { _, userProfile, _, error in + NextcloudKit.shared.getUserProfile(account: account.account, options: options) { _, userProfile, _, error in if error == .success, let userProfile = userProfile { if userProfile.quotaRelative > 0 { quotaRelative = Float(userProfile.quotaRelative) / 100 @@ -102,7 +102,7 @@ func getLockscreenDataEntry(configuration: AccountIntent?, isPreview: Bool, fami } } } else if family == .accessoryRectangular { - NextcloudKit.shared.getDashboardWidgetsApplication("activity", options: options) { _, results, _, error in + NextcloudKit.shared.getDashboardWidgetsApplication("activity", account: account.account, options: options) { _, results, _, error in var activity: String = NSLocalizedString("_no_data_available_", comment: "") var link = URL(string: "https://")! if error == .success, let result = results?.first { diff --git a/iOSClient/Activity/NCActivity.swift b/iOSClient/Activity/NCActivity.swift index 02efd0c9a9..6769b26af9 100644 --- a/iOSClient/Activity/NCActivity.swift +++ b/iOSClient/Activity/NCActivity.swift @@ -82,7 +82,7 @@ class NCActivity: UIViewController, NCSharePagingContent { commentView = Bundle.main.loadNibNamed("NCActivityCommentView", owner: self, options: nil)?.first as? NCActivityCommentView commentView?.setup(urlBase: appDelegate, account: activeAccount) { newComment in guard let newComment = newComment, !newComment.isEmpty, let metadata = self.metadata else { return } - NextcloudKit.shared.putComments(fileId: metadata.fileId, message: newComment) { _, error in + NextcloudKit.shared.putComments(fileId: metadata.fileId, message: newComment, account: self.appDelegate.account) { _, error in if error == .success { self.commentView?.newCommentField.text?.removeAll() self.loadComments() @@ -264,7 +264,7 @@ extension NCActivity: UITableViewDataSource { cell.icon.image = image.withTintColor(NCBrandColor.shared.textColor, renderingMode: .alwaysOriginal) } } else { - NextcloudKit.shared.downloadContent(serverUrl: activity.icon) { _, data, error in + NextcloudKit.shared.downloadContent(serverUrl: activity.icon, account: appDelegate.account) { _, data, error in if error == .success { do { try data!.write(to: NSURL(fileURLWithPath: fileNameLocalPath) as URL, options: .atomic) @@ -393,7 +393,7 @@ extension NCActivity { guard showComments, let metadata = metadata else { return } disptachGroup?.enter() - NextcloudKit.shared.getComments(fileId: metadata.fileId) { _, comments, _, error in + NextcloudKit.shared.getComments(fileId: metadata.fileId, account: metadata.account) { _, comments, _, error in if error == .success, let comments = comments { NCManageDatabase.shared.addComments(comments, account: metadata.account, objectId: metadata.fileId) } else if error.errorCode != NCGlobal.shared.errorResourceNotFound { @@ -422,7 +422,8 @@ extension NCActivity { limit: 1, objectId: nil, objectType: objectType, - previews: true) { task in + previews: true, + account: appDelegate.account) { task in self.dataSourceTask = task } completion: { account, _, activityFirstKnown, activityLastGiven, _, error in defer { disptachGroup.leave() } @@ -450,7 +451,8 @@ extension NCActivity { limit: min(limit, 200), objectId: metadata?.fileId, objectType: objectType, - previews: true) { task in + previews: true, + account: appDelegate.account) { task in self.dataSourceTask = task } completion: { account, activities, activityFirstKnown, activityLastGiven, _, error in defer { disptachGroup.leave() } @@ -507,7 +509,7 @@ extension NCActivity: NCShareCommentsCellDelegate { alert.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { _ in guard let message = alert.textFields?.first?.text, !message.isEmpty else { return } - NextcloudKit.shared.updateComments(fileId: metadata.fileId, messageId: tableComments.messageId, message: message) { _, error in + NextcloudKit.shared.updateComments(fileId: metadata.fileId, messageId: tableComments.messageId, message: message, account: self.appDelegate.account) { _, error in if error == .success { self.loadComments() } else { @@ -529,7 +531,7 @@ extension NCActivity: NCShareCommentsCellDelegate { action: { _ in guard let metadata = self.metadata, let tableComments = tableComments else { return } - NextcloudKit.shared.deleteComments(fileId: metadata.fileId, messageId: tableComments.messageId) { _, error in + NextcloudKit.shared.deleteComments(fileId: metadata.fileId, messageId: tableComments.messageId, account: metadata.account) { _, error in if error == .success { self.loadComments() } else { diff --git a/iOSClient/Activity/NCActivityCommentView.swift b/iOSClient/Activity/NCActivityCommentView.swift index d308940641..1792676d25 100644 --- a/iOSClient/Activity/NCActivityCommentView.swift +++ b/iOSClient/Activity/NCActivityCommentView.swift @@ -55,6 +55,4 @@ extension NCActivityCommentView: UISearchBarDelegate { searchBar.resignFirstResponder() completionHandler?(searchBar.text) } - - func searchBarTextDidEndEditing(_ searchBar: UISearchBar) { } } diff --git a/iOSClient/Activity/NCActivityTableViewCell.swift b/iOSClient/Activity/NCActivityTableViewCell.swift index 13aa77ace8..14124d355c 100644 --- a/iOSClient/Activity/NCActivityTableViewCell.swift +++ b/iOSClient/Activity/NCActivityTableViewCell.swift @@ -178,7 +178,7 @@ extension NCActivityTableViewCell: UICollectionViewDataSource { cell.fileId = fileId if !FileManager.default.fileExists(atPath: fileNamePath) { if NCNetworking.shared.downloadThumbnailActivityQueue.operations.filter({ ($0 as? NCOperationDownloadThumbnailActivity)?.fileId == fileId }).isEmpty { - NCNetworking.shared.downloadThumbnailActivityQueue.addOperation(NCOperationDownloadThumbnailActivity(fileId: fileId, fileNamePreviewLocalPath: fileNamePath, cell: cell, collectionView: collectionView)) + NCNetworking.shared.downloadThumbnailActivityQueue.addOperation(NCOperationDownloadThumbnailActivity(fileId: fileId, fileNamePreviewLocalPath: fileNamePath, account: appDelegate.account, cell: cell, collectionView: collectionView)) } } } @@ -208,10 +208,12 @@ class NCOperationDownloadThumbnailActivity: ConcurrentOperation { var collectionView: UICollectionView? var fileNamePreviewLocalPath: String var fileId: String + var account: String - init(fileId: String, fileNamePreviewLocalPath: String, cell: NCActivityCollectionViewCell?, collectionView: UICollectionView?) { + init(fileId: String, fileNamePreviewLocalPath: String, account: String, cell: NCActivityCollectionViewCell?, collectionView: UICollectionView?) { self.fileNamePreviewLocalPath = fileNamePreviewLocalPath self.fileId = fileId + self.account = account self.cell = cell self.collectionView = collectionView } @@ -221,6 +223,7 @@ class NCOperationDownloadThumbnailActivity: ConcurrentOperation { NextcloudKit.shared.downloadPreview(fileId: fileId, fileNamePreviewLocalPath: fileNamePreviewLocalPath, + account: account, options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { _, imagePreview, _, _, _, error in if error == .success, let imagePreview = imagePreview { DispatchQueue.main.async { diff --git a/iOSClient/AppDelegate.swift b/iOSClient/AppDelegate.swift index 3b6180bece..ea9c75c777 100644 --- a/iOSClient/AppDelegate.swift +++ b/iOSClient/AppDelegate.swift @@ -458,7 +458,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD let account: String = "\(user) \(urlBase)" NextcloudKit.shared.setup(account: account, user: user, userId: user, password: password, urlBase: urlBase, groupIdentifier: NCBrandOptions.shared.capabilitiesGroup) - NextcloudKit.shared.getUserProfile { account, userProfile, _, error in + NextcloudKit.shared.getUserProfile(account: account) { account, userProfile, _, error in if error == .success, let userProfile { NCManageDatabase.shared.deleteAccount(account) NCManageDatabase.shared.addAccount(account, urlBase: urlBase, user: user, userId: userProfile.userId, password: password) @@ -512,7 +512,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD } NCPushNotification.shared.pushNotification() - NCService().startRequestServicesServer() + NCService().startRequestServicesServer(account: self.account, user: self.user, userId: self.userId) NCAutoUpload.shared.initAutoUpload(viewController: nil) { items in NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Initialize Auto upload with \(items) uploads") diff --git a/iOSClient/Assistant/Models/NCAssistantTask.swift b/iOSClient/Assistant/Models/NCAssistantTask.swift index cc0857e356..c0ce427865 100644 --- a/iOSClient/Assistant/Models/NCAssistantTask.swift +++ b/iOSClient/Assistant/Models/NCAssistantTask.swift @@ -20,6 +20,7 @@ class NCAssistantTask: ObservableObject { private var tasks: [NKTextProcessingTask] = [] private let excludedTypeIds = ["OCA\\ContextChat\\TextProcessing\\ContextChatTaskType"] + private let appDelegate = (UIApplication.shared.delegate as? AppDelegate)! init() { load() @@ -49,7 +50,7 @@ class NCAssistantTask: ObservableObject { guard let id = task.id else { return } isLoading = true - NextcloudKit.shared.textProcessingGetTask(taskId: id) { _, task, _, error in + NextcloudKit.shared.textProcessingGetTask(taskId: id, account: appDelegate.account) { _, task, _, error in self.isLoading = false if error != .success { @@ -64,7 +65,7 @@ class NCAssistantTask: ObservableObject { func scheduleTask(input: String) { isLoading = true - NextcloudKit.shared.textProcessingSchedule(input: input, typeId: selectedType?.id ?? "", identifier: "assistant") { _, task, _, error in + NextcloudKit.shared.textProcessingSchedule(input: input, typeId: selectedType?.id ?? "", identifier: "assistant", account: appDelegate.account) { _, task, _, error in self.isLoading = false if error != .success { @@ -78,7 +79,6 @@ class NCAssistantTask: ObservableObject { self.tasks.insert(task, at: 0) self.filteredTasks.insert(task, at: 0) } - } } @@ -86,7 +86,7 @@ class NCAssistantTask: ObservableObject { guard let id = task.id else { return } isLoading = true - NextcloudKit.shared.textProcessingDeleteTask(taskId: id) { _, task, _, error in + NextcloudKit.shared.textProcessingDeleteTask(taskId: id, account: appDelegate.account) { _, task, _, error in self.isLoading = false if error != .success { @@ -105,7 +105,7 @@ class NCAssistantTask: ObservableObject { private func loadAllTypes() { isLoading = true - NextcloudKit.shared.textProcessingGetTypes { _, types, _, error in + NextcloudKit.shared.textProcessingGetTypes(account: appDelegate.account) { _, types, _, error in self.isLoading = false if error != .success { @@ -130,7 +130,7 @@ class NCAssistantTask: ObservableObject { private func loadAllTasks(appId: String = "assistant") { isLoading = true - NextcloudKit.shared.textProcessingTaskList(appId: appId) { _, tasks, _, error in + NextcloudKit.shared.textProcessingTaskList(appId: appId, account: appDelegate.account) { _, tasks, _, error in self.isLoading = false if error != .success { diff --git a/iOSClient/Data/NCManageDatabase+Directory.swift b/iOSClient/Data/NCManageDatabase+Directory.swift index cdd8ec70ec..d67a0c9877 100644 --- a/iOSClient/Data/NCManageDatabase+Directory.swift +++ b/iOSClient/Data/NCManageDatabase+Directory.swift @@ -91,7 +91,7 @@ extension NCManageDatabase { let windowScenes = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene } for windowScene in windowScenes { if let controller = windowScene.keyWindow?.rootViewController as? NCMainTabBarController { - controller.filesServerUrl.removeValue(forKey: serverUrl) + controller.navigationCollectionViewCommon.remove(where: { $0.serverUrl == serverUrl}) } } } diff --git a/iOSClient/Data/NCManageDatabase+Metadata.swift b/iOSClient/Data/NCManageDatabase+Metadata.swift index c1a1092a09..71ce34f006 100644 --- a/iOSClient/Data/NCManageDatabase+Metadata.swift +++ b/iOSClient/Data/NCManageDatabase+Metadata.swift @@ -206,7 +206,7 @@ extension tableMetadata { if directory || isDocumentViewableOnly || isDirectoryE2EE { return false } - return contentType == "com.adobe.pdf" || contentType == "application/pdf" || classFile == NKCommon.TypeClassFile.image.rawValue + return isPDF || isImage } var isDeletable: Bool { @@ -277,7 +277,9 @@ extension tableMetadata { } var isAvailableEditorView: Bool { - guard (classFile == NKCommon.TypeClassFile.document.rawValue) && NextcloudKit.shared.isNetworkReachable() else { return false } + guard !isPDF, + classFile == NKCommon.TypeClassFile.document.rawValue, + NextcloudKit.shared.isNetworkReachable() else { return false } let utility = NCUtility() let directEditingEditors = utility.editorsDirectEditing(account: account, contentType: contentType) let richDocumentEditor = utility.isTypeFileRichDocument(self) @@ -311,6 +313,10 @@ extension tableMetadata { return false } + var isPDF: Bool { + return (contentType == "application/pdf" || contentType == "com.adobe.pdf") + } + /// Returns false if the user is lokced out of the file. I.e. The file is locked but by somone else func canUnlock(as user: String) -> Bool { return !lock || (lockOwner == user && lockOwnerType == 0) @@ -837,6 +843,18 @@ extension NCManageDatabase { return nil } + func getResultMetadataFromOcId(_ ocId: String?) -> tableMetadata? { + guard let ocId else { return nil } + + do { + let realm = try Realm() + return realm.objects(tableMetadata.self).filter("ocId == %@", ocId).first + } catch let error as NSError { + NextcloudKit.shared.nkCommonInstance.writeLog("[ERROR] Could not access database: \(error)") + } + return nil + } + func getMetadataFromFileName(_ fileName: String, serverUrl: String) -> tableMetadata? { do { let realm = try Realm() diff --git a/iOSClient/Data/NCManageDatabase+Trash.swift b/iOSClient/Data/NCManageDatabase+Trash.swift index 186f031bae..a34b21cf77 100644 --- a/iOSClient/Data/NCManageDatabase+Trash.swift +++ b/iOSClient/Data/NCManageDatabase+Trash.swift @@ -117,7 +117,7 @@ extension NCManageDatabase { do { let realm = try Realm() realm.refresh() - let results = realm.objects(tableTrash.self).filter("account == %@ AND filePath == %@", account, filePath).sorted(byKeyPath: "date", ascending: false) + let results = realm.objects(tableTrash.self).filter("account == %@ AND filePath == %@", account, filePath).sorted(byKeyPath: "trashbinDeletionTime", ascending: false) return Array(results.map { tableTrash.init(value: $0) }) } catch let error as NSError { NextcloudKit.shared.nkCommonInstance.writeLog("[ERROR] Could not access to database: \(error)") diff --git a/iOSClient/Extensions/UIAlertController+Extension.swift b/iOSClient/Extensions/UIAlertController+Extension.swift index 755c8f7ee9..0eab5ef65f 100644 --- a/iOSClient/Extensions/UIAlertController+Extension.swift +++ b/iOSClient/Extensions/UIAlertController+Extension.swift @@ -32,16 +32,16 @@ extension UIAlertController { /// - urlBase: UrlBase object /// - completion: If not` nil` it overrides the default behavior which shows an error using `NCContentPresenter` /// - Returns: The presentable alert controller - static func createFolder(serverUrl: String, urlBase: NCUserBaseUrl, markE2ee: Bool = false, sceneIdentifier: String? = nil, completion: ((_ error: NKError) -> Void)? = nil) -> UIAlertController { + static func createFolder(serverUrl: String, userBaseUrl: NCUserBaseUrl, markE2ee: Bool = false, sceneIdentifier: String? = nil, completion: ((_ error: NKError) -> Void)? = nil) -> UIAlertController { let alertController = UIAlertController(title: NSLocalizedString("_create_folder_", comment: ""), message: nil, preferredStyle: .alert) let okAction = UIAlertAction(title: NSLocalizedString("_save_", comment: ""), style: .default, handler: { _ in guard let fileNameFolder = alertController.textFields?.first?.text else { return } if markE2ee { Task { - let createFolderResults = await NCNetworking.shared.createFolder(serverUrlFileName: serverUrl + "/" + fileNameFolder) + let createFolderResults = await NCNetworking.shared.createFolder(serverUrlFileName: serverUrl + "/" + fileNameFolder, account: userBaseUrl.account) if createFolderResults.error == .success { - let error = await NCNetworkingE2EEMarkFolder().markFolderE2ee(account: urlBase.account, fileName: fileNameFolder, serverUrl: serverUrl, userId: urlBase.userId) + let error = await NCNetworkingE2EEMarkFolder().markFolderE2ee(account: userBaseUrl.account, fileName: fileNameFolder, serverUrl: serverUrl, userId: userBaseUrl.userId) if error != .success { NCContentPresenter().showError(error: error) } @@ -50,7 +50,7 @@ extension UIAlertController { } } } else { - NCNetworking.shared.createFolder(fileName: fileNameFolder, serverUrl: serverUrl, account: urlBase.account, urlBase: urlBase.urlBase, userId: urlBase.userId, overwrite: false, withPush: true, sceneIdentifier: sceneIdentifier) { error in + NCNetworking.shared.createFolder(fileName: fileNameFolder, serverUrl: serverUrl, account: userBaseUrl.account, urlBase: userBaseUrl.urlBase, userId: userBaseUrl.userId, overwrite: false, withPush: true, sceneIdentifier: sceneIdentifier) { error in if let completion = completion { completion(error) } else if error != .success { diff --git a/iOSClient/Favorites/NCFavorite.swift b/iOSClient/Favorites/NCFavorite.swift index f7b79bc8cd..6dbf0324a2 100644 --- a/iOSClient/Favorites/NCFavorite.swift +++ b/iOSClient/Favorites/NCFavorite.swift @@ -68,7 +68,7 @@ class NCFavorite: NCCollectionViewCommon { override func reloadDataSourceNetwork(withQueryDB: Bool = false) { super.reloadDataSourceNetwork() - NextcloudKit.shared.listingFavorites(showHiddenFiles: NCKeychain().showHiddenFiles, options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { task in + NextcloudKit.shared.listingFavorites(showHiddenFiles: NCKeychain().showHiddenFiles, account: self.appDelegate.account, options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { task in self.dataSourceTask = task self.collectionView.reloadData() } completion: { account, files, _, error in diff --git a/iOSClient/Files/NCFiles.swift b/iOSClient/Files/NCFiles.swift index b6c6a181bf..3fd5d3a08e 100644 --- a/iOSClient/Files/NCFiles.swift +++ b/iOSClient/Files/NCFiles.swift @@ -175,7 +175,7 @@ class NCFiles: NCCollectionViewCommon { private func networkReadFolder(completion: @escaping(_ tableDirectory: tableDirectory?, _ metadatas: [tableMetadata]?, _ metadatasDifferentCount: Int, _ metadatasModified: Int, _ error: NKError) -> Void) { var tableDirectory: tableDirectory? - NCNetworking.shared.readFile(serverUrlFileName: serverUrl) { task in + NCNetworking.shared.readFile(serverUrlFileName: serverUrl, account: appDelegate.account) { task in self.dataSourceTask = task self.collectionView.reloadData() } completion: { account, metadata, error in @@ -204,7 +204,7 @@ class NCFiles: NCCollectionViewCommon { NCKeychain().isEndToEndEnabled(account: account), !NCNetworkingE2EE().isInUpload(account: account, serverUrl: self.serverUrl) { let lock = NCManageDatabase.shared.getE2ETokenLock(account: account, serverUrl: self.serverUrl) - NCNetworkingE2EE().getMetadata(fileId: metadataFolder.ocId, e2eToken: lock?.e2eToken) { account, version, e2eMetadata, signature, _, error in + NCNetworkingE2EE().getMetadata(fileId: metadataFolder.ocId, e2eToken: lock?.e2eToken, account: account) { account, version, e2eMetadata, signature, _, error in if account == self.appDelegate.account, error == .success, let e2eMetadata = e2eMetadata { let error = NCEndToEndMetadata().decodeMetadata(e2eMetadata, signature: signature, serverUrl: self.serverUrl, account: account, urlBase: self.appDelegate.urlBase, userId: self.appDelegate.userId) if error == .success { diff --git a/iOSClient/Groupfolders/NCGroupfolders.swift b/iOSClient/Groupfolders/NCGroupfolders.swift index b067e4aac4..f8c0a49b2c 100644 --- a/iOSClient/Groupfolders/NCGroupfolders.swift +++ b/iOSClient/Groupfolders/NCGroupfolders.swift @@ -70,7 +70,7 @@ class NCGroupfolders: NCCollectionViewCommon { let homeServerUrl = utilityFileSystem.getHomeServer(urlBase: self.appDelegate.urlBase, userId: self.appDelegate.userId) - NextcloudKit.shared.getGroupfolders(options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { task in + NextcloudKit.shared.getGroupfolders(account: self.appDelegate.account, options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { task in self.dataSourceTask = task self.collectionView.reloadData() } completion: { account, results, _, error in @@ -81,7 +81,7 @@ class NCGroupfolders: NCCollectionViewCommon { let mountPoint = groupfolder.mountPoint.hasPrefix("/") ? groupfolder.mountPoint : "/" + groupfolder.mountPoint let serverUrlFileName = homeServerUrl + mountPoint if NCManageDatabase.shared.getMetadataFromDirectory(account: self.appDelegate.account, serverUrl: serverUrlFileName) == nil { - let results = await NCNetworking.shared.readFileOrFolder(serverUrlFileName: serverUrlFileName, depth: "0", showHiddenFiles: NCKeychain().showHiddenFiles) + let results = await NCNetworking.shared.readFileOrFolder(serverUrlFileName: serverUrlFileName, depth: "0", showHiddenFiles: NCKeychain().showHiddenFiles, account: account) if results.error == .success, let file = results.files.first { let isDirectoryE2EE = self.utilityFileSystem.isDirectoryE2EE(file: file) let metadata = NCManageDatabase.shared.convertFileToMetadata(file, isDirectoryE2EE: isDirectoryE2EE) diff --git a/iOSClient/Login/NCLoginProvider.swift b/iOSClient/Login/NCLoginProvider.swift index a7deec3ce2..d43cc5dc04 100644 --- a/iOSClient/Login/NCLoginProvider.swift +++ b/iOSClient/Login/NCLoginProvider.swift @@ -167,7 +167,7 @@ extension NCLoginProvider: WKNavigationDelegate { let user = username NextcloudKit.shared.setup(account: account, user: user, userId: user, password: password, urlBase: urlBase) - NextcloudKit.shared.getUserProfile { _, userProfile, _, error in + NextcloudKit.shared.getUserProfile(account: account) { _, userProfile, _, error in if error == .success, let userProfile { NCManageDatabase.shared.deleteAccount(account) NCManageDatabase.shared.addAccount(account, urlBase: urlBase, user: user, userId: userProfile.userId, password: password) diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDelegate.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDelegate.swift index b57e30a253..81539b7c19 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDelegate.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon+CollectionViewDelegate.swift @@ -58,7 +58,6 @@ extension NCCollectionViewCommon: UICollectionViewDelegate { pushMetadata(metadata) } else { let imageIcon = UIImage(contentsOfFile: utilityFileSystem.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag)) - if !metadata.isDirectoryE2EE && (metadata.isImage || metadata.isAudioOrVideo) { var metadatas: [tableMetadata] = [] for metadata in dataSource.getMetadataSourceForAllSections() { @@ -66,8 +65,7 @@ extension NCCollectionViewCommon: UICollectionViewDelegate { metadatas.append(metadata) } } - NCViewer().view(viewController: self, metadata: metadata, metadatas: metadatas, imageIcon: imageIcon) - return + return NCViewer().view(viewController: self, metadata: metadata, metadatas: metadatas, imageIcon: imageIcon) } else if metadata.isAvailableEditorView || utilityFileSystem.fileProviderStorageExists(metadata) { NCViewer().view(viewController: self, metadata: metadata, metadatas: [metadata], imageIcon: imageIcon) } else if NextcloudKit.shared.isNetworkReachable(), diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon+MediaLayout.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon+MediaLayout.swift index 2d8ba439c7..f5c042f1ef 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon+MediaLayout.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon+MediaLayout.swift @@ -35,7 +35,7 @@ extension NCCollectionViewCommon: NCMediaLayoutDelegate { } func getLayout() -> String? { - return NCManageDatabase.shared.getLayoutForView(account: appDelegate.account, key: NCGlobal.shared.layoutViewFiles, serverUrl: serverUrl)?.layout + return self.layoutType } func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, heightForHeaderInSection section: Int) -> Float { diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift index 80cae01f9b..4a386467ad 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift @@ -57,6 +57,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS var listLayout = NCListLayout() var gridLayout = NCGridLayout() var mediaLayout = NCMediaLayout() + var layoutType = NCGlobal.shared.layoutList var literalSearch: String? var tabBarSelect: NCCollectionViewCommonSelectTabBar! var timerNotificationCenter: Timer? @@ -171,10 +172,16 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS layoutForView = NCManageDatabase.shared.getLayoutForView(account: appDelegate.account, key: layoutKey, serverUrl: serverUrl) if layoutForView?.layout == NCGlobal.shared.layoutList { collectionView?.collectionViewLayout = listLayout + self.layoutType = NCGlobal.shared.layoutList } else if layoutForView?.layout == NCGlobal.shared.layoutGrid { collectionView?.collectionViewLayout = gridLayout - } else if layoutForView?.layout == NCGlobal.shared.layoutPhotoRatio || layoutForView?.layout == NCGlobal.shared.layoutPhotoSquare { + self.layoutType = NCGlobal.shared.layoutGrid + } else if layoutForView?.layout == NCGlobal.shared.layoutPhotoRatio { collectionView?.collectionViewLayout = mediaLayout + self.layoutType = NCGlobal.shared.layoutPhotoRatio + } else if layoutForView?.layout == NCGlobal.shared.layoutPhotoSquare { + collectionView?.collectionViewLayout = mediaLayout + self.layoutType = NCGlobal.shared.layoutPhotoSquare } // FIXME: iPAD PDF landscape mode iOS 16 @@ -700,6 +707,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS let list = UIAction(title: NSLocalizedString("_list_", comment: ""), image: utility.loadImage(named: "list.bullet"), state: layoutForView.layout == NCGlobal.shared.layoutList ? .on : .off) { _ in layoutForView.layout = NCGlobal.shared.layoutList self.layoutForView = NCManageDatabase.shared.setLayoutForView(layoutForView: layoutForView) + self.layoutType = NCGlobal.shared.layoutList self.collectionView.reloadData() self.collectionView.collectionViewLayout.invalidateLayout() @@ -711,6 +719,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS let grid = UIAction(title: NSLocalizedString("_icons_", comment: ""), image: utility.loadImage(named: "square.grid.2x2"), state: layoutForView.layout == NCGlobal.shared.layoutGrid ? .on : .off) { _ in layoutForView.layout = NCGlobal.shared.layoutGrid self.layoutForView = NCManageDatabase.shared.setLayoutForView(layoutForView: layoutForView) + self.layoutType = NCGlobal.shared.layoutGrid self.collectionView.reloadData() self.collectionView.collectionViewLayout.invalidateLayout() @@ -723,6 +732,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS UIAction(title: NSLocalizedString("_media_square_", comment: ""), image: utility.loadImage(named: "square.grid.3x3"), state: layoutForView.layout == NCGlobal.shared.layoutPhotoSquare ? .on : .off) { _ in layoutForView.layout = NCGlobal.shared.layoutPhotoSquare self.layoutForView = NCManageDatabase.shared.setLayoutForView(layoutForView: layoutForView) + self.layoutType = NCGlobal.shared.layoutPhotoSquare self.collectionView.reloadData() self.collectionView.collectionViewLayout.invalidateLayout() @@ -734,6 +744,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS UIAction(title: NSLocalizedString("_media_ratio_", comment: ""), image: utility.loadImage(named: "rectangle.grid.3x2"), state: layoutForView.layout == NCGlobal.shared.layoutPhotoRatio ? .on : .off) { _ in layoutForView.layout = NCGlobal.shared.layoutPhotoRatio self.layoutForView = NCManageDatabase.shared.setLayoutForView(layoutForView: layoutForView) + self.layoutType = NCGlobal.shared.layoutPhotoRatio self.collectionView.reloadData() self.collectionView.collectionViewLayout.invalidateLayout() @@ -1126,7 +1137,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS } @objc func pasteFilesMenu() { - NCActionCenter.shared.pastePasteboard(serverUrl: serverUrl, hudView: tabBarController?.view) + NCActionCenter.shared.pastePasteboard(serverUrl: serverUrl, account: appDelegate.account, hudView: tabBarController?.view) } // MARK: - DataSource + NC Endpoint @@ -1182,7 +1193,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS self.collectionView.reloadData() } } else { - NCNetworking.shared.searchFiles(urlBase: appDelegate, literal: literalSearch) { task in + NCNetworking.shared.searchFiles(urlBase: appDelegate, literal: literalSearch, account: appDelegate.account) { task in self.dataSourceTask = task self.collectionView.reloadData() } completion: { metadatas, error in @@ -1223,10 +1234,10 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS // MARK: - Push metadata func pushMetadata(_ metadata: tableMetadata) { - guard let filesServerUrl = (tabBarController as? NCMainTabBarController)?.filesServerUrl else { return } + guard let navigationCollectionViewCommon = (tabBarController as? NCMainTabBarController)?.navigationCollectionViewCommon else { return } let serverUrlPush = utilityFileSystem.stringAppendServerUrl(metadata.serverUrl, addFileName: metadata.fileName) - if let viewController = filesServerUrl[serverUrlPush], viewController.isViewLoaded { + if let viewController = navigationCollectionViewCommon.first(where: { $0.navigationController == self.navigationController && $0.serverUrl == serverUrlPush})?.viewController, viewController.isViewLoaded { navigationController?.pushViewController(viewController, animated: true) } else { if let viewController: NCFiles = UIStoryboard(name: "NCFiles", bundle: nil).instantiateInitialViewController() as? NCFiles { @@ -1234,7 +1245,9 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS viewController.serverUrl = serverUrlPush viewController.titlePreviusFolder = navigationItem.title viewController.titleCurrentFolder = metadata.fileNameView - filesServerUrl[serverUrlPush] = viewController + + navigationCollectionViewCommon.append(NavigationCollectionViewCommon(serverUrl: serverUrlPush, navigationController: self.navigationController, viewController: viewController)) + navigationController?.pushViewController(viewController, animated: true) } } @@ -1243,10 +1256,8 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS // MARK: - Header size func isHeaderMenuTransferViewEnabled() -> Bool { - if headerMenuTransferView, - let metadata = NCManageDatabase.shared.getMetadataFromOcId(NCNetworking.shared.transferInForegorund?.ocId), - metadata.isTransferInForeground { - return true + if headerMenuTransferView { + return NCManageDatabase.shared.getResultMetadataFromOcId(NCNetworking.shared.transferInForegorund?.ocId)?.isTransferInForeground ?? false } return false } diff --git a/iOSClient/Main/Collection Common/NCCollectionViewDownloadThumbnail.swift b/iOSClient/Main/Collection Common/NCCollectionViewDownloadThumbnail.swift index 928bc87523..33d3e0dbe0 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewDownloadThumbnail.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewDownloadThumbnail.swift @@ -59,6 +59,7 @@ class NCCollectionViewDownloadThumbnail: ConcurrentOperation { heightPreview: Int(sizePreview.height), sizeIcon: NCGlobal.shared.sizeIcon, etag: etagResource, + account: self.metadata.account, options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { _, _, imageIcon, _, etag, error in if error == .success, let imageIcon { NCManageDatabase.shared.setMetadataEtagResource(ocId: self.metadata.ocId, etagResource: etag) diff --git a/iOSClient/Main/Create cloud/NCCreateDocument.swift b/iOSClient/Main/Create cloud/NCCreateDocument.swift index 2027029fde..bc681fa1ea 100644 --- a/iOSClient/Main/Create cloud/NCCreateDocument.swift +++ b/iOSClient/Main/Create cloud/NCCreateDocument.swift @@ -43,7 +43,7 @@ class NCCreateDocument: NSObject { options = NKRequestOptions(customUserAgent: NCUtility().getCustomUserAgentNCText()) } - NextcloudKit.shared.NCTextCreateFile(fileNamePath: fileNamePath, editorId: editorId, creatorId: creatorId, templateId: templateId, options: options) { account, url, _, error in + NextcloudKit.shared.NCTextCreateFile(fileNamePath: fileNamePath, editorId: editorId, creatorId: creatorId, templateId: templateId, account: appDelegate.account, options: options) { account, url, _, error in guard error == .success, account == self.appDelegate.account, let url = url else { NCContentPresenter().showError(error: error) return @@ -56,7 +56,7 @@ class NCCreateDocument: NSObject { } else if editorId == NCGlobal.shared.editorCollabora { - NextcloudKit.shared.createRichdocuments(path: fileNamePath, templateId: templateId) { account, url, _, error in + NextcloudKit.shared.createRichdocuments(path: fileNamePath, templateId: templateId, account: appDelegate.account) { account, url, _, error in guard error == .success, account == self.appDelegate.account, let url = url else { NCContentPresenter().showError(error: error) return @@ -82,7 +82,7 @@ class NCCreateDocument: NSObject { options = NKRequestOptions(customUserAgent: NCUtility().getCustomUserAgentNCText()) } - let results = await textGetListOfTemplates(options: options) + let results = await textGetListOfTemplates(account:appDelegate.account, options: options) if results.error == .success { for template in results.templates { let temp = NKEditorTemplates() @@ -120,7 +120,7 @@ class NCCreateDocument: NSObject { } if editorId == NCGlobal.shared.editorCollabora { - let results = await getTemplatesRichdocuments(typeTemplate: templateId) + let results = await getTemplatesRichdocuments(typeTemplate: templateId, account: appDelegate.account) if results.error == .success { for template in results.templates! { let temp = NKEditorTemplates() @@ -145,19 +145,19 @@ class NCCreateDocument: NSObject { // MARK: - NextcloudKit async/await - func textGetListOfTemplates(options: NKRequestOptions = NKRequestOptions()) async -> (account: String, templates: [NKEditorTemplates], data: Data?, error: NKError) { + func textGetListOfTemplates(account: String, options: NKRequestOptions = NKRequestOptions()) async -> (account: String, templates: [NKEditorTemplates], data: Data?, error: NKError) { await withUnsafeContinuation({ continuation in - NextcloudKit.shared.NCTextGetListOfTemplates { account, templates, data, error in + NextcloudKit.shared.NCTextGetListOfTemplates(account: account) { account, templates, data, error in continuation.resume(returning: (account: account, templates: templates, data: data, error: error)) } }) } - func getTemplatesRichdocuments(typeTemplate: String, options: NKRequestOptions = NKRequestOptions()) async -> (account: String, templates: [NKRichdocumentsTemplate]?, data: Data?, error: NKError) { + func getTemplatesRichdocuments(typeTemplate: String, account: String, options: NKRequestOptions = NKRequestOptions()) async -> (account: String, templates: [NKRichdocumentsTemplate]?, data: Data?, error: NKError) { await withUnsafeContinuation({ continuation in - NextcloudKit.shared.getTemplatesRichdocuments(typeTemplate: typeTemplate, options: options) { account, templates, data, error in + NextcloudKit.shared.getTemplatesRichdocuments(typeTemplate: typeTemplate, account: account, options: options) { account, templates, data, error in continuation.resume(returning: (account: account, templates: templates, data: data, error: error)) } }) diff --git a/iOSClient/Main/NCActionCenter.swift b/iOSClient/Main/NCActionCenter.swift index 7c5b68d3d9..f2d8e46cb8 100644 --- a/iOSClient/Main/NCActionCenter.swift +++ b/iOSClient/Main/NCActionCenter.swift @@ -209,7 +209,7 @@ class NCActionCenter: NSObject, UIDocumentInteractionControllerDelegate, NCSelec } hud.show(in: hudView) - NextcloudKit.shared.getFileFromFileId(fileId: fileId) { account, file, _, error in + NextcloudKit.shared.getFileFromFileId(fileId: fileId, account: account) { account, file, _, error in hud.dismiss() if error != .success { @@ -227,7 +227,7 @@ class NCActionCenter: NSObject, UIDocumentInteractionControllerDelegate, NCSelec NCViewer().view(viewController: viewController, metadata: metadata, metadatas: [metadata], imageIcon: nil) } else { hud.show(in: hudView) - NextcloudKit.shared.download(serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath, requestHandler: { request in + NextcloudKit.shared.download(serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath, account: account, requestHandler: { request in downloadRequest = request }, taskHandler: { _ in }, progressHandler: { progress in @@ -269,7 +269,7 @@ class NCActionCenter: NSObject, UIDocumentInteractionControllerDelegate, NCSelec var page = page NCActivityIndicator.shared.start(backgroundView: viewController.view) - NCNetworking.shared.readFile(serverUrlFileName: serverUrlFileName, queue: .main) { _, metadata, error in + NCNetworking.shared.readFile(serverUrlFileName: serverUrlFileName, account: metadata.account, queue: .main) { _, metadata, error in NCActivityIndicator.shared.stop() @@ -428,12 +428,12 @@ class NCActionCenter: NSObject, UIDocumentInteractionControllerDelegate, NCSelec // MARK: - Copy & Paste - func pastePasteboard(serverUrl: String, hudView: UIView?) { + func pastePasteboard(serverUrl: String, account: String, hudView: UIView?) { var fractionCompleted: Float = 0 let processor = ParallelWorker(n: 5, titleKey: "_uploading_", totalTasks: nil, hudView: hudView) func uploadPastePasteboard(fileName: String, serverUrlFileName: String, fileNameLocalPath: String, serverUrl: String, completion: @escaping () -> Void) { - NextcloudKit.shared.upload(serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath) { request in + NextcloudKit.shared.upload(serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath, account: account) { request in NCNetworking.shared.uploadRequest[fileNameLocalPath] = request } progressHandler: { progress in if Float(progress.fractionCompleted) > fractionCompleted || fractionCompleted == 0 { @@ -484,7 +484,6 @@ class NCActionCenter: NSObject, UIDocumentInteractionControllerDelegate, NCSelec let navigationController = controller.viewControllers?.first as? UINavigationController else { return } var serverUrlPush = self.utilityFileSystem.getHomeServer(urlBase: appDelegate.urlBase, userId: appDelegate.userId) - let filesServerUrl = controller.filesServerUrl DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { navigationController.popToRootViewController(animated: false) @@ -504,7 +503,7 @@ class NCActionCenter: NSObject, UIDocumentInteractionControllerDelegate, NCSelec guard let dir = subDirs.first else { return } serverUrlPush = serverUrlPush + "/" + dir - if let viewController = filesServerUrl[serverUrlPush], viewController.isViewLoaded { + if let viewController = controller.navigationCollectionViewCommon.first(where: { $0.navigationController == navigationController && $0.serverUrl == serverUrlPush})?.viewController as? NCFiles, viewController.isViewLoaded { viewController.fileNameBlink = fileNameBlink viewController.fileNameOpen = fileNameOpen navigationController.pushViewController(viewController, animated: false) @@ -514,7 +513,9 @@ class NCActionCenter: NSObject, UIDocumentInteractionControllerDelegate, NCSelec viewController.serverUrl = serverUrlPush viewController.titleCurrentFolder = String(dir) viewController.navigationItem.backButtonTitle = viewController.titleCurrentFolder - filesServerUrl[serverUrlPush] = viewController + + controller.navigationCollectionViewCommon.append(NavigationCollectionViewCommon(serverUrl: serverUrlPush, navigationController: navigationController, viewController: viewController)) + if serverUrlPush == serverUrl { viewController.fileNameBlink = fileNameBlink viewController.fileNameOpen = fileNameOpen diff --git a/iOSClient/Main/NCMainTabBarController.swift b/iOSClient/Main/NCMainTabBarController.swift index 267d0ce149..0e9044199c 100644 --- a/iOSClient/Main/NCMainTabBarController.swift +++ b/iOSClient/Main/NCMainTabBarController.swift @@ -23,11 +23,28 @@ import UIKit +struct NavigationCollectionViewCommon { + var serverUrl: String + var navigationController: UINavigationController? + var viewController: NCCollectionViewCommon +} + class NCMainTabBarController: UITabBarController { var sceneIdentifier: String = UUID().uuidString var documentPickerViewController: NCDocumentPickerViewController? - let filesServerUrl = ThreadSafeDictionary() + let navigationCollectionViewCommon = ThreadSafeArray() let appDelegate = (UIApplication.shared.delegate as? AppDelegate)! + private var previousIndex: Int? + + override func viewDidLoad() { + super.viewDidLoad() + delegate = self + } + + override func viewDidAppear(_ animated: Bool) { + super.viewDidAppear(animated) + previousIndex = selectedIndex + } func currentViewController() -> UIViewController? { return (selectedViewController as? UINavigationController)?.topViewController @@ -48,3 +65,21 @@ class NCMainTabBarController: UITabBarController { return serverUrl } } + +extension NCMainTabBarController: UITabBarControllerDelegate { + func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) { + if previousIndex == tabBarController.selectedIndex { + scrollToTop(viewController: viewController) + } + previousIndex = tabBarController.selectedIndex + } + + private func scrollToTop(viewController: UIViewController) { + guard let navigationController = viewController as? UINavigationController, + let topViewController = navigationController.topViewController else { return } + + if let scrollView = topViewController.view.subviews.compactMap({ $0 as? UIScrollView }).first { + scrollView.setContentOffset(CGPoint(x: 0, y: -scrollView.adjustedContentInset.top), animated: true) + } + } +} diff --git a/iOSClient/Media/NCMedia+CollectionViewDataSource.swift b/iOSClient/Media/NCMedia+CollectionViewDataSource.swift index eb69de3ad5..c790ca55c9 100644 --- a/iOSClient/Media/NCMedia+CollectionViewDataSource.swift +++ b/iOSClient/Media/NCMedia+CollectionViewDataSource.swift @@ -47,7 +47,7 @@ extension NCMedia: UICollectionViewDataSource { if numberOfItemsInSection == 0 { selectOrCancelButton.isHidden = true menuButton.isHidden = false - gradientView.isHidden = true + gradientView.alpha = 0 activityIndicatorTrailing.constant = 50 } else if isEditMode { selectOrCancelButton.isHidden = false diff --git a/iOSClient/Media/NCMedia+Command.swift b/iOSClient/Media/NCMedia+Command.swift index baedb8b00d..cca74dd361 100644 --- a/iOSClient/Media/NCMedia+Command.swift +++ b/iOSClient/Media/NCMedia+Command.swift @@ -22,6 +22,7 @@ // import Foundation +import UIKit import NextcloudKit extension NCMedia { @@ -85,23 +86,27 @@ extension NCMedia { func setColor() { if isTop { - titleDate?.textColor = NCBrandColor.shared.textColor - activityIndicator.color = NCBrandColor.shared.textColor - selectOrCancelButton.setTitleColor(NCBrandColor.shared.textColor, for: .normal) - menuButton.setImage(NCUtility().loadImage(named: "ellipsis", colors: [NCBrandColor.shared.textColor]), for: .normal) - gradientView.isHidden = true + UIView.animate(withDuration: 0.3) { [self] in + gradientView.alpha = 0 + titleDate?.textColor = NCBrandColor.shared.textColor + activityIndicator.color = NCBrandColor.shared.textColor + selectOrCancelButton.setTitleColor(NCBrandColor.shared.textColor, for: .normal) + menuButton.setImage(NCUtility().loadImage(named: "ellipsis", colors: [NCBrandColor.shared.textColor]), for: .normal) + } } else { - titleDate?.textColor = .white - activityIndicator.color = .white - selectOrCancelButton.setTitleColor(.white, for: .normal) - menuButton.setImage(NCUtility().loadImage(named: "ellipsis", colors: [.white]), for: .normal) - gradientView.isHidden = false + UIView.animate(withDuration: 0.3) { [self] in + gradientView.alpha = 1 + titleDate?.textColor = .white + activityIndicator.color = .white + selectOrCancelButton.setTitleColor(.white, for: .normal) + menuButton.setImage(NCUtility().loadImage(named: "ellipsis", colors: [.white]), for: .normal) + } } } func createMenu() { - var layoutForView = NCManageDatabase.shared.getLayoutForView(account: appDelegate.account, key: NCGlobal.shared.layoutViewMedia, serverUrl: "") - var columnPhoto = layoutForView?.columnPhoto ?? 3 + let layoutForView = NCManageDatabase.shared.getLayoutForView(account: appDelegate.account, key: NCGlobal.shared.layoutViewMedia, serverUrl: "") + let columnPhoto = layoutForView?.columnPhoto ?? 3 let layout = layoutForView?.layout ?? NCGlobal.shared.mediaLayoutRatio let layoutTitle = (layout == NCGlobal.shared.mediaLayoutRatio) ? NSLocalizedString("_media_square_", comment: "") : NSLocalizedString("_media_ratio_", comment: "") let layoutImage = (layout == NCGlobal.shared.mediaLayoutRatio) ? utility.loadImage(named: "square.grid.3x3") : utility.loadImage(named: "rectangle.grid.3x2") @@ -137,32 +142,16 @@ extension NCMedia { let viewLayoutMenu = UIAction(title: layoutTitle, image: layoutImage) { _ in if layout == NCGlobal.shared.mediaLayoutRatio { NCManageDatabase.shared.setLayoutForView(account: self.appDelegate.account, key: NCGlobal.shared.layoutViewMedia, serverUrl: "", layout: NCGlobal.shared.mediaLayoutSquare) + self.layoutType = NCGlobal.shared.mediaLayoutSquare } else { NCManageDatabase.shared.setLayoutForView(account: self.appDelegate.account, key: NCGlobal.shared.layoutViewMedia, serverUrl: "", layout: NCGlobal.shared.mediaLayoutRatio) + self.layoutType = NCGlobal.shared.mediaLayoutRatio } self.createMenu() self.collectionViewReloadData() } - let zoomViewMediaFolder = UIMenu(title: "", options: .displayInline, children: [ - UIMenu(title: NSLocalizedString("_zoom_", comment: ""), children: [ - UIAction(title: NSLocalizedString("_zoom_out_", comment: ""), image: utility.loadImage(named: "minus.magnifyingglass"), attributes: self.attributesZoomOut) { _ in - UIView.animate(withDuration: 0.0, animations: { - let column = columnPhoto + 1 - NCManageDatabase.shared.setLayoutForView(account: self.appDelegate.account, key: NCGlobal.shared.layoutViewMedia, serverUrl: "", columnPhoto: column) - self.createMenu() - self.collectionViewReloadData() - }) - }, - UIAction(title: NSLocalizedString("_zoom_in_", comment: ""), image: utility.loadImage(named: "plus.magnifyingglass"), attributes: self.attributesZoomIn) { _ in - UIView.animate(withDuration: 0.0, animations: { - let column = columnPhoto - 1 - NCManageDatabase.shared.setLayoutForView(account: self.appDelegate.account, key: NCGlobal.shared.layoutViewMedia, serverUrl: "", columnPhoto: column) - self.createMenu() - self.collectionViewReloadData() - }) - } - ]), + let viewOptionsMedia = UIMenu(title: "", options: .displayInline, children: [ UIMenu(title: NSLocalizedString("_media_view_options_", comment: ""), children: [viewFilterMenu, viewLayoutMenu]), UIAction(title: NSLocalizedString("_select_media_folder_", comment: ""), image: utility.loadImage(named: "folder"), handler: { _ in guard let navigationController = UIStoryboard(name: "NCSelect", bundle: nil).instantiateInitialViewController() as? UINavigationController, @@ -174,6 +163,24 @@ extension NCMedia { }) ]) + let zoomOut = UIAction(title: NSLocalizedString("_zoom_out_", comment: ""), image: utility.loadImage(named: "minus.magnifyingglass"), attributes: self.attributesZoomOut) { _ in + UIView.animate(withDuration: 0.0, animations: { + let column = columnPhoto + 1 + NCManageDatabase.shared.setLayoutForView(account: self.appDelegate.account, key: NCGlobal.shared.layoutViewMedia, serverUrl: "", columnPhoto: column) + self.createMenu() + self.collectionViewReloadData() + }) + } + + let zoomIn = UIAction(title: NSLocalizedString("_zoom_in_", comment: ""), image: utility.loadImage(named: "plus.magnifyingglass"), attributes: self.attributesZoomIn) { _ in + UIView.animate(withDuration: 0.0, animations: { + let column = columnPhoto - 1 + NCManageDatabase.shared.setLayoutForView(account: self.appDelegate.account, key: NCGlobal.shared.layoutViewMedia, serverUrl: "", columnPhoto: column) + self.createMenu() + self.collectionViewReloadData() + }) + } + let playFile = UIAction(title: NSLocalizedString("_play_from_files_", comment: ""), image: utility.loadImage(named: "play.circle")) { _ in guard let controller = self.tabBarController as? NCMainTabBarController else { return } self.documentPickerViewController = NCDocumentPickerViewController(controller: controller, isViewerMedia: true, allowsMultipleSelection: false, viewController: self) @@ -195,7 +202,7 @@ extension NCMedia { self.present(alert, animated: true) } - menuButton.menu = UIMenu(title: "", children: [zoomViewMediaFolder, playFile, playURL]) + menuButton.menu = UIMenu(title: "", children: [zoomOut, zoomIn, viewOptionsMedia, playFile, playURL]) } } diff --git a/iOSClient/Media/NCMedia+MediaLayout.swift b/iOSClient/Media/NCMedia+MediaLayout.swift index 0823ea7999..890f13af37 100644 --- a/iOSClient/Media/NCMedia+MediaLayout.swift +++ b/iOSClient/Media/NCMedia+MediaLayout.swift @@ -41,8 +41,7 @@ extension NCMedia: NCMediaLayoutDelegate { } func getLayout() -> String? { - let layoutForView = NCManageDatabase.shared.getLayoutForView(account: appDelegate.account, key: NCGlobal.shared.layoutViewMedia, serverUrl: "") - return layoutForView?.layout ?? NCGlobal.shared.mediaLayoutRatio + return self.layoutType } func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, heightForHeaderInSection section: Int) -> Float { diff --git a/iOSClient/Media/NCMedia.storyboard b/iOSClient/Media/NCMedia.storyboard index f1e221f104..3ac0c1cab8 100644 --- a/iOSClient/Media/NCMedia.storyboard +++ b/iOSClient/Media/NCMedia.storyboard @@ -1,9 +1,9 @@ - + - + @@ -31,7 +31,7 @@ - + @@ -52,12 +52,12 @@