From b3257965779ebaecae7122b2386e8972367c0766 Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Thu, 6 Jun 2024 09:41:34 +0200 Subject: [PATCH] Cleaning old code (#2941) * coding Signed-off-by: Marino Faggiana * cleaning Signed-off-by: Marino Faggiana * cleaning Signed-off-by: Marino Faggiana * update Signed-off-by: Marino Faggiana * cleaning Signed-off-by: Marino Faggiana * fix Signed-off-by: Marino Faggiana * coding Signed-off-by: Marino Faggiana * cleaning Signed-off-by: Marino Faggiana * cleaning Signed-off-by: Marino Faggiana * cleaning Signed-off-by: Marino Faggiana * coding Signed-off-by: Marino Faggiana * cleaning Signed-off-by: Marino Faggiana --------- Signed-off-by: Marino Faggiana --- .swiftlint.yml | 2 +- .../FileProviderExtension.swift | 3 +- Nextcloud.xcodeproj/project.pbxproj | 22 +++- Share/NCShareExtension+DataSource.swift | 5 +- Share/NCShareExtension+Files.swift | 2 +- .../Data/NCManageDatabase+Directory.swift | 4 +- .../Data/NCManageDatabase+Metadata.swift | 11 +- iOSClient/Extensions/UIDevice+Extension.swift | 52 --------- iOSClient/Login/NCLogin.swift | 10 +- iOSClient/Login/NCLoginWeb.swift | 10 +- ...ctionViewCommon+SelectTabBarDelegate.swift | 4 +- .../NCCollectionViewCommon.swift | 8 +- .../NCCollectionViewCommonSelectTabBar.swift | 20 ++-- .../NCCollectionViewDownloadThumbnail.swift | 2 + .../NCCreateFormUploadDocuments.swift | 6 +- iOSClient/Main/NCActionCenter.swift | 80 ++++++-------- iOSClient/Main/NCMainTabBar.swift | 6 +- iOSClient/Main/NCPickerViewController.swift | 18 +-- iOSClient/Media/NCMedia+Command.swift | 4 +- iOSClient/Menu/AppDelegate+Menu.swift | 60 +++++----- iOSClient/Menu/NCMenu+FloatingPanel.swift | 8 +- iOSClient/Menu/NCMenuAction.swift | 13 ++- iOSClient/Menu/NCShare+Menu.swift | 21 ++-- iOSClient/More/CCManageAccount.m | 2 +- iOSClient/More/NCMore.swift | 6 +- iOSClient/NCGlobal.swift | 48 ++------ .../Networking/NCNetworking+Upload.swift | 7 +- .../Networking/NCNetworking+WebDAV.swift | 8 +- iOSClient/Networking/NCNetworking.swift | 12 +- .../Networking/NCNetworkingProcess.swift | 2 +- .../Scan document/NCDocumentCamera.swift | 4 +- iOSClient/SceneDelegate.swift | 72 ++++++------ iOSClient/Select/NCSelect.swift | 6 +- .../Advanced/NCShareAdvancePermission.swift | 2 +- iOSClient/Share/Advanced/NCShareCells.swift | 69 ++++++------ iOSClient/Share/NCPermissions.swift | 103 ++++++++++++++++++ iOSClient/Share/NCShare+Helper.swift | 2 +- iOSClient/Share/NCShare+NCCellDelegate.swift | 2 +- iOSClient/Share/NCShare.swift | 2 +- iOSClient/Share/NCShareUserCell.swift | 6 +- iOSClient/Utility/CCUtility.h | 15 --- iOSClient/Utility/CCUtility.m | 92 ---------------- iOSClient/Utility/NCLivePhoto.swift | 12 +- iOSClient/Utility/NCStoreReview.swift | 15 +-- iOSClient/Viewer/NCViewer.swift | 4 +- 45 files changed, 376 insertions(+), 486 deletions(-) delete mode 100644 iOSClient/Extensions/UIDevice+Extension.swift create mode 100644 iOSClient/Share/NCPermissions.swift diff --git a/.swiftlint.yml b/.swiftlint.yml index ed2b80dbdb..fc762e7656 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -36,7 +36,7 @@ disabled_rules: - shorthand_operator - type_name - void_function_in_ternary - + - switch_case_alignment excluded: - Carthage - Pods diff --git a/File Provider Extension/FileProviderExtension.swift b/File Provider Extension/FileProviderExtension.swift index 983542320a..3e3c9bf23f 100644 --- a/File Provider Extension/FileProviderExtension.swift +++ b/File Provider Extension/FileProviderExtension.swift @@ -96,8 +96,7 @@ class FileProviderExtension: NSFileProviderExtension { // - for a directory, instantiate an enumerator of its subitems // - for a file, instantiate an enumerator that observes changes to the file let item = try self.item(for: containerItemIdentifier) - - if item.typeIdentifier == kUTTypeFolder as String { + if item.contentType == UTType.folder { maybeEnumerator = FileProviderEnumerator(enumeratedItemIdentifier: containerItemIdentifier) } else { maybeEnumerator = FileProviderEnumerator(enumeratedItemIdentifier: containerItemIdentifier) diff --git a/Nextcloud.xcodeproj/project.pbxproj b/Nextcloud.xcodeproj/project.pbxproj index d3ba0de38b..69b9fed843 100644 --- a/Nextcloud.xcodeproj/project.pbxproj +++ b/Nextcloud.xcodeproj/project.pbxproj @@ -250,6 +250,13 @@ F72429362AFE39860040AEF3 /* NCLivePhoto.swift in Sources */ = {isa = PBXBuildFile; fileRef = F70968A324212C4E00ED60E5 /* NCLivePhoto.swift */; }; F72429372AFE39980040AEF3 /* NCLivePhoto.swift in Sources */ = {isa = PBXBuildFile; fileRef = F70968A324212C4E00ED60E5 /* NCLivePhoto.swift */; }; F72429382AFE39A80040AEF3 /* NCLivePhoto.swift in Sources */ = {isa = PBXBuildFile; fileRef = F70968A324212C4E00ED60E5 /* NCLivePhoto.swift */; }; + F724377B2C10B83E00C7C68D /* NCPermissions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F724377A2C10B83E00C7C68D /* NCPermissions.swift */; }; + F724377C2C10B92200C7C68D /* NCPermissions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F724377A2C10B83E00C7C68D /* NCPermissions.swift */; }; + F724377D2C10B92300C7C68D /* NCPermissions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F724377A2C10B83E00C7C68D /* NCPermissions.swift */; }; + F724377E2C10B92300C7C68D /* NCPermissions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F724377A2C10B83E00C7C68D /* NCPermissions.swift */; }; + F724377F2C10B92400C7C68D /* NCPermissions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F724377A2C10B83E00C7C68D /* NCPermissions.swift */; }; + F72437802C10B92400C7C68D /* NCPermissions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F724377A2C10B83E00C7C68D /* NCPermissions.swift */; }; + F72437812C10B92500C7C68D /* NCPermissions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F724377A2C10B83E00C7C68D /* NCPermissions.swift */; }; F7245924289BB50C00474787 /* ThreadSafeDictionary.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7245923289BB50B00474787 /* ThreadSafeDictionary.swift */; }; F7245925289BB59100474787 /* ThreadSafeDictionary.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7245923289BB50B00474787 /* ThreadSafeDictionary.swift */; }; F7245926289BB59300474787 /* ThreadSafeDictionary.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7245923289BB50B00474787 /* ThreadSafeDictionary.swift */; }; @@ -856,7 +863,6 @@ F7F4F10A27ECDBDB008676F9 /* Inconsolata-ExtraBold.ttf in Resources */ = {isa = PBXBuildFile; fileRef = F7F4F10227ECDBDB008676F9 /* Inconsolata-ExtraBold.ttf */; }; F7F4F10B27ECDBDB008676F9 /* Inconsolata-Light.ttf in Resources */ = {isa = PBXBuildFile; fileRef = F7F4F10327ECDBDB008676F9 /* Inconsolata-Light.ttf */; }; F7F4F10C27ECDBDB008676F9 /* Inconsolata-Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = F7F4F10427ECDBDB008676F9 /* Inconsolata-Regular.ttf */; }; - F7F4F11027ECDC4A008676F9 /* UIDevice+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7F4F10F27ECDC4A008676F9 /* UIDevice+Extension.swift */; }; F7F4F11227ECDC52008676F9 /* UIFont+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7F4F11127ECDC52008676F9 /* UIFont+Extension.swift */; }; F7F623B52A5EF4D30022D3D4 /* Gzip in Frameworks */ = {isa = PBXBuildFile; productRef = F7F623B42A5EF4D30022D3D4 /* Gzip */; }; F7F623B72A5EFA0C0022D3D4 /* Gzip in Frameworks */ = {isa = PBXBuildFile; productRef = F7F623B62A5EFA0C0022D3D4 /* Gzip */; }; @@ -1248,6 +1254,7 @@ F723985B253C95CE00257F49 /* NCViewerRichdocument.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = NCViewerRichdocument.storyboard; sourceTree = ""; }; F723B3DC22FC6D1C00301EFE /* NCShareCommentsCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NCShareCommentsCell.xib; sourceTree = ""; }; F72408322B8A27C900F128E2 /* NCMedia+Command.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCMedia+Command.swift"; sourceTree = ""; }; + F724377A2C10B83E00C7C68D /* NCPermissions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCPermissions.swift; sourceTree = ""; }; F7245923289BB50B00474787 /* ThreadSafeDictionary.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ThreadSafeDictionary.swift; sourceTree = ""; }; F7267A81225DFCE100D6DB7D /* AFNetworking.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AFNetworking.framework; path = Carthage/Build/iOS/AFNetworking.framework; sourceTree = ""; }; F72685E827C78E490019EF5E /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; @@ -1676,7 +1683,6 @@ F7F4F10227ECDBDB008676F9 /* Inconsolata-ExtraBold.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Inconsolata-ExtraBold.ttf"; sourceTree = ""; }; F7F4F10327ECDBDB008676F9 /* Inconsolata-Light.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Inconsolata-Light.ttf"; sourceTree = ""; }; F7F4F10427ECDBDB008676F9 /* Inconsolata-Regular.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Inconsolata-Regular.ttf"; sourceTree = ""; }; - F7F4F10F27ECDC4A008676F9 /* UIDevice+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIDevice+Extension.swift"; sourceTree = ""; }; F7F4F11127ECDC52008676F9 /* UIFont+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIFont+Extension.swift"; sourceTree = ""; }; F7F67BB81A24D27800EE80DA /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; F7F878AD1FB9E3B900599E4F /* NCEndToEndMetadata.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCEndToEndMetadata.swift; sourceTree = ""; }; @@ -2130,6 +2136,7 @@ isa = PBXGroup; children = ( AF93471327E235EB002537EE /* Advanced */, + F724377A2C10B83E00C7C68D /* NCPermissions.swift */, F700510022DF63AC003A3356 /* NCShare.storyboard */, F700510422DF6A89003A3356 /* NCShare.swift */, AFCE353827E5DE0400FEA6C2 /* NCShare+Helper.swift */, @@ -2587,7 +2594,6 @@ AF7E504D27A2D8FF00B5E4AF /* UIBarButton+Extension.swift */, F70CEF5523E9C7E50007035B /* UIColor+Extension.swift */, F79B645F26CA661600838ACA /* UIControl+Extension.swift */, - F7F4F10F27ECDC4A008676F9 /* UIDevice+Extension.swift */, F7F4F11127ECDC52008676F9 /* UIFont+Extension.swift */, F713FEFE2472764000214AF6 /* UIImage+animatedGIF.h */, F713FEFF2472764100214AF6 /* UIImage+animatedGIF.m */, @@ -2684,6 +2690,7 @@ F7BFFA991A24D7BB0044ED85 /* Utility */ = { isa = PBXGroup; children = ( + F702F2FC25EE5D2C008F8E80 /* NYMnemonic */, F7053E3C1C639DF500741EA5 /* CCUtility.h */, F7053E3D1C639DF500741EA5 /* CCUtility.m */, F76D364528A4F8BF00214537 /* NCActivityIndicator.swift */, @@ -2699,7 +2706,6 @@ F359D8662A7D03420023F405 /* NCUtility+Exif.swift */, AF93474B27E34120002537EE /* NCUtility+Image.swift */, F74AF3A3247FB6AE00AC767B /* NCUtilityFileSystem.swift */, - F702F2FC25EE5D2C008F8E80 /* NYMnemonic */, AF36077027BFA4E8001A243D /* ParallelWorker.swift */, F71F6D062B6A6A5E00F1EB15 /* ThreadSafeArray.swift */, F7245923289BB50B00474787 /* ThreadSafeDictionary.swift */, @@ -3798,6 +3804,7 @@ 2C1D5D7623E2DE3300334ABB /* NCManageDatabase.swift in Sources */, F7864AD22A78FE73004870E0 /* NCManageDatabase+LocalFile.swift in Sources */, F314F1142A30E2DE00BC7FAB /* View+Extension.swift in Sources */, + F724377D2C10B92300C7C68D /* NCPermissions.swift in Sources */, F7D68FD028CB9051009139F3 /* NCManageDatabase+DashboardWidget.swift in Sources */, F343A4C12A1E734600DDA874 /* Optional+Extension.swift in Sources */, F7245927289BB59300474787 /* ThreadSafeDictionary.swift in Sources */, @@ -3913,6 +3920,7 @@ F757CC8729E7F88B00F31428 /* NCManageDatabase+Groupfolders.swift in Sources */, F7B769AD2B7A0B2000C1AAEB /* NCManageDatabase+Metadata+Session.swift in Sources */, F73EF7BC2B0224AB0087E6E9 /* NCManageDatabase+ExternalSites.swift in Sources */, + F724377E2C10B92300C7C68D /* NCPermissions.swift in Sources */, F73EF7B42B0224350087E6E9 /* NCManageDatabase+DirectEditing.swift in Sources */, F7490E8229882C80009DCE94 /* NCManageDatabase+E2EE.swift in Sources */, F7490E7829882C28009DCE94 /* NCUtility.swift in Sources */, @@ -3974,6 +3982,7 @@ AF22B218277D196700DAB0CC /* NCShareExtension+Files.swift in Sources */, F702F2D025EE5B5C008F8E80 /* NCGlobal.swift in Sources */, F343A4BE2A1E734600DDA874 /* Optional+Extension.swift in Sources */, + F72437802C10B92400C7C68D /* NCPermissions.swift in Sources */, F7EDE4DB262D7BA200414FE6 /* NCCellProtocol.swift in Sources */, F72944F62A8424F800246839 /* NCEndToEndMetadataV1.swift in Sources */, F7EDE4D1262D7B8400414FE6 /* NCDataSource.swift in Sources */, @@ -4070,6 +4079,7 @@ F783030628B4C51E00B84583 /* String+Extension.swift in Sources */, F763D29E2A249C4500A3C901 /* NCManageDatabase+Capabilities.swift in Sources */, F711A4DD2AF92CAE00095DD8 /* NCUtility+Date.swift in Sources */, + F724377C2C10B92200C7C68D /* NCPermissions.swift in Sources */, F36E64FB2B9733F10085ABB5 /* UIView+Extension.swift in Sources */, F77ED59328C9CEA000E24ED0 /* ToolbarWidgetProvider.swift in Sources */, F72A17D828B221E300F3F159 /* DashboardWidgetView.swift in Sources */, @@ -4119,6 +4129,7 @@ F7817D0229802D7700FFBC65 /* NCViewCertificateDetails.swift in Sources */, F7434B3820E2400600417916 /* NCBrand.swift in Sources */, F7327E332B73A86700A462C7 /* NCNetworking+WebDAV.swift in Sources */, + F724377F2C10B92400C7C68D /* NCPermissions.swift in Sources */, F785EE9E2461A09900B3F945 /* NCNetworking.swift in Sources */, F749B655297B0F2400087535 /* NCManageDatabase+Avatar.swift in Sources */, F7327E382B73AEDE00A462C7 /* NCNetworking+LivePhoto.swift in Sources */, @@ -4262,6 +4273,7 @@ F72D1007210B6882009C96B7 /* NCPushNotificationEncryption.m in Sources */, F76882362C0DD1E7001CF441 /* NCAcknowledgementsView.swift in Sources */, F785EE9D246196DF00B3F945 /* NCNetworkingE2EE.swift in Sources */, + F724377B2C10B83E00C7C68D /* NCPermissions.swift in Sources */, F76673ED22C901F6007ED366 /* FileProviderDomain.swift in Sources */, F794E13D2BBBFF2E003693D7 /* NCMainTabBarController.swift in Sources */, F7CBC1252BAC8B0000EC1D55 /* NCSectionHeaderEmptyData.swift in Sources */, @@ -4411,7 +4423,6 @@ F7581D1A25EFDA61004DC699 /* NCLoginWeb+Menu.swift in Sources */, F76882272C0DD1E7001CF441 /* NCManageE2EEView.swift in Sources */, F7864ACC2A78FE73004870E0 /* NCManageDatabase+LocalFile.swift in Sources */, - F7F4F11027ECDC4A008676F9 /* UIDevice+Extension.swift in Sources */, F7327E302B73A86700A462C7 /* NCNetworking+WebDAV.swift in Sources */, F79FFB262A97C24A0055EEA4 /* NCNetworkingE2EEMarkFolder.swift in Sources */, F70D8D8124A4A9BF000A5756 /* NCNetworkingProcess.swift in Sources */, @@ -4445,6 +4456,7 @@ F7C9B91F2B582F550064EA91 /* NCManageDatabase+SecurityGuard.swift in Sources */, F7A8D74528F1828E008BBE1C /* CCUtility.m in Sources */, F75DD767290ABB25002EB562 /* Intent.intentdefinition in Sources */, + F72437812C10B92500C7C68D /* NCPermissions.swift in Sources */, F749B64C297B0CBB00087535 /* NCManageDatabase+Share.swift in Sources */, F7A8D73F28F181EF008BBE1C /* NCGlobal.swift in Sources */, F74B6D972A7E239A00F03C5F /* NCManageDatabase+Chunk.swift in Sources */, diff --git a/Share/NCShareExtension+DataSource.swift b/Share/NCShareExtension+DataSource.swift index ee26ccd6d8..883a8b6e9e 100644 --- a/Share/NCShareExtension+DataSource.swift +++ b/Share/NCShareExtension+DataSource.swift @@ -136,9 +136,10 @@ extension NCShareExtension: UICollectionViewDataSource { func setupDirectoryCell(_ cell: NCListCell, indexPath: IndexPath, with metadata: tableMetadata) { var isShare = false var isMounted = false + let permissions = NCPermissions() if let metadataFolder = metadataFolder { - isShare = metadata.permissions.contains(NCGlobal.shared.permissionShared) && !metadataFolder.permissions.contains(NCGlobal.shared.permissionShared) - isMounted = metadata.permissions.contains(NCGlobal.shared.permissionMounted) && !metadataFolder.permissions.contains(NCGlobal.shared.permissionMounted) + isShare = metadata.permissions.contains(permissions.permissionShared) && !metadataFolder.permissions.contains(permissions.permissionShared) + isMounted = metadata.permissions.contains(permissions.permissionMounted) && !metadataFolder.permissions.contains(permissions.permissionMounted) } if metadata.e2eEncrypted { diff --git a/Share/NCShareExtension+Files.swift b/Share/NCShareExtension+Files.swift index f6405ec1fe..6b66df2a22 100644 --- a/Share/NCShareExtension+Files.swift +++ b/Share/NCShareExtension+Files.swift @@ -217,6 +217,6 @@ class NCFilesExtensionHandler { extension NSItemProvider { var typeIdentifier: String { if hasItemConformingToTypeIdentifier("public.url") { return "public.url" } else - if hasItemConformingToTypeIdentifier(kUTTypeItem as String) { return kUTTypeItem as String } else { return "" } + if hasItemConformingToTypeIdentifier(UTType.item.identifier as String) { return UTType.item.identifier as String } else { return "" } } } diff --git a/iOSClient/Data/NCManageDatabase+Directory.swift b/iOSClient/Data/NCManageDatabase+Directory.swift index 5084e3a58f..8b6698d6ba 100644 --- a/iOSClient/Data/NCManageDatabase+Directory.swift +++ b/iOSClient/Data/NCManageDatabase+Directory.swift @@ -83,8 +83,8 @@ extension NCManageDatabase { DispatchQueue.main.async { let windowScenes = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene } for windowScene in windowScenes { - if let mainTabBarController = windowScene.keyWindow?.rootViewController as? NCMainTabBarController { - mainTabBarController.filesServerUrl.removeValue(forKey: serverUrl) + if let controller = windowScene.keyWindow?.rootViewController as? NCMainTabBarController { + controller.filesServerUrl.removeValue(forKey: serverUrl) } } } diff --git a/iOSClient/Data/NCManageDatabase+Metadata.swift b/iOSClient/Data/NCManageDatabase+Metadata.swift index 606eb29819..16c5716bd6 100644 --- a/iOSClient/Data/NCManageDatabase+Metadata.swift +++ b/iOSClient/Data/NCManageDatabase+Metadata.swift @@ -166,7 +166,7 @@ extension tableMetadata { } var isDocumentViewableOnly: Bool { - sharePermissionsCollaborationServices == NCGlobal.shared.permissionReadShare && classFile == NKCommon.TypeClassFile.document.rawValue + sharePermissionsCollaborationServices == NCPermissions().permissionReadShare && classFile == NKCommon.TypeClassFile.document.rawValue } var isAudioOrVideo: Bool { @@ -991,18 +991,19 @@ extension NCManageDatabase { } func isMetadataShareOrMounted(metadata: tableMetadata, metadataFolder: tableMetadata?) -> Bool { + let permissions = NCPermissions() var isShare = false var isMounted = false if metadataFolder != nil { - isShare = metadata.permissions.contains(NCGlobal.shared.permissionShared) && !metadataFolder!.permissions.contains(NCGlobal.shared.permissionShared) - isMounted = metadata.permissions.contains(NCGlobal.shared.permissionMounted) && !metadataFolder!.permissions.contains(NCGlobal.shared.permissionMounted) + isShare = metadata.permissions.contains(permissions.permissionShared) && !metadataFolder!.permissions.contains(permissions.permissionShared) + isMounted = metadata.permissions.contains(permissions.permissionMounted) && !metadataFolder!.permissions.contains(permissions.permissionMounted) } else if let directory = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", metadata.account, metadata.serverUrl)) { - isShare = metadata.permissions.contains(NCGlobal.shared.permissionShared) && !directory.permissions.contains(NCGlobal.shared.permissionShared) - isMounted = metadata.permissions.contains(NCGlobal.shared.permissionMounted) && !directory.permissions.contains(NCGlobal.shared.permissionMounted) + isShare = metadata.permissions.contains(permissions.permissionShared) && !directory.permissions.contains(permissions.permissionShared) + isMounted = metadata.permissions.contains(permissions.permissionMounted) && !directory.permissions.contains(permissions.permissionMounted) } if isShare || isMounted { diff --git a/iOSClient/Extensions/UIDevice+Extension.swift b/iOSClient/Extensions/UIDevice+Extension.swift deleted file mode 100644 index 5763365ee3..0000000000 --- a/iOSClient/Extensions/UIDevice+Extension.swift +++ /dev/null @@ -1,52 +0,0 @@ -// -// UIDevice+Extension.swift -// Nextcloud -// -// Created by Federico Malagoni on 23/02/22. -// Copyright © 2022 Federico Malagoni. All rights reserved. -// -// Author Federico Malagoni -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// - -import Foundation -import UIKit - -extension UIDevice { - - var hasNotch: Bool { - if #available(iOS 11.0, *) { - if UIApplication.shared.windows.isEmpty { return false } - let top = UIApplication.shared.windows[0].safeAreaInsets.top - return top > 20 - } else { - // Fallback on earlier versions - return false - } - } -} - -extension UIDeviceOrientation { - /// According to Apple... if the device is laid flat the UI is neither portrait nor landscape, so this flag ignores that and checks if the UI is REALLY in landscape. Thanks Apple. - /// - /// Unless you really need to use this, you can instead try `traitCollection.verticalSizeClass` and `traitCollection.horizontalSizeClass`. - var isLandscapeHardCheck: Bool { - if UIDevice.current.orientation.isValidInterfaceOrientation { - return UIDevice.current.orientation.isLandscape - } else { - return UIApplication.shared.windows.first?.windowScene?.interfaceOrientation.isLandscape ?? false - } - } -} diff --git a/iOSClient/Login/NCLogin.swift b/iOSClient/Login/NCLogin.swift index e4cc34d06c..7a3a9cd329 100644 --- a/iOSClient/Login/NCLogin.swift +++ b/iOSClient/Login/NCLogin.swift @@ -402,13 +402,13 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate { if window?.rootViewController is NCMainTabBarController { self.dismiss(animated: true) } else { - if let mainTabBarController = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController() as? NCMainTabBarController { - mainTabBarController.modalPresentationStyle = .fullScreen - mainTabBarController.view.alpha = 0 - window?.rootViewController = mainTabBarController + if let controller = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController() as? NCMainTabBarController { + controller.modalPresentationStyle = .fullScreen + controller.view.alpha = 0 + window?.rootViewController = controller window?.makeKeyAndVisible() UIView.animate(withDuration: 0.5) { - mainTabBarController.view.alpha = 1 + controller.view.alpha = 1 } } } diff --git a/iOSClient/Login/NCLoginWeb.swift b/iOSClient/Login/NCLoginWeb.swift index 176c468c44..90849819d0 100644 --- a/iOSClient/Login/NCLoginWeb.swift +++ b/iOSClient/Login/NCLoginWeb.swift @@ -305,13 +305,13 @@ extension NCLoginWeb: WKNavigationDelegate { if window?.rootViewController is NCMainTabBarController { self.dismiss(animated: true) } else { - if let mainTabBarController = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController() as? NCMainTabBarController { - mainTabBarController.modalPresentationStyle = .fullScreen - mainTabBarController.view.alpha = 0 - window?.rootViewController = mainTabBarController + if let controller = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController() as? NCMainTabBarController { + controller.modalPresentationStyle = .fullScreen + controller.view.alpha = 0 + window?.rootViewController = controller window?.makeKeyAndVisible() UIView.animate(withDuration: 0.5) { - mainTabBarController.view.alpha = 1 + controller.view.alpha = 1 } } } diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon+SelectTabBarDelegate.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon+SelectTabBarDelegate.swift index 97b2fb8976..f948f61602 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon+SelectTabBarDelegate.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon+SelectTabBarDelegate.swift @@ -122,13 +122,13 @@ extension NCCollectionViewCommon: NCCollectionViewCommonSelectTabBarDelegate { func move() { let metadatas = getSelectedMetadatas() - NCActionCenter.shared.openSelectView(items: metadatas, mainTabBarController: self.tabBarController as? NCMainTabBarController) + NCActionCenter.shared.openSelectView(items: metadatas, controller: self.tabBarController as? NCMainTabBarController) setEditMode(false) } func share() { let metadatas = getSelectedMetadatas() - NCActionCenter.shared.openActivityViewController(selectedMetadata: metadatas, mainTabBarController: self.tabBarController as? NCMainTabBarController) + NCActionCenter.shared.openActivityViewController(selectedMetadata: metadatas, controller: self.tabBarController as? NCMainTabBarController) setEditMode(false) } diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift index 21bb5eab4e..7dbb415db7 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift @@ -89,7 +89,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS override func viewDidLoad() { super.viewDidLoad() - tabBarSelect = NCCollectionViewCommonSelectTabBar(tabBarController: tabBarController as? NCMainTabBarController, delegate: self) + tabBarSelect = NCCollectionViewCommonSelectTabBar(controller: tabBarController as? NCMainTabBarController, delegate: self) self.navigationController?.presentationController?.delegate = self // CollectionView & layout @@ -1289,8 +1289,8 @@ extension NCCollectionViewCommon: UICollectionViewDataSource { } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - var cell: NCCellProtocol & UICollectionViewCell + let permissions = NCPermissions() // LAYOUT LIST if layoutForView?.layout == NCGlobal.shared.layoutList { @@ -1317,8 +1317,8 @@ extension NCCollectionViewCommon: UICollectionViewDataSource { var a11yValues: [String] = [] if metadataFolder != nil { - isShare = metadata.permissions.contains(NCGlobal.shared.permissionShared) && !metadataFolder!.permissions.contains(NCGlobal.shared.permissionShared) - isMounted = metadata.permissions.contains(NCGlobal.shared.permissionMounted) && !metadataFolder!.permissions.contains(NCGlobal.shared.permissionMounted) + isShare = metadata.permissions.contains(permissions.permissionShared) && !metadataFolder!.permissions.contains(permissions.permissionShared) + isMounted = metadata.permissions.contains(permissions.permissionMounted) && !metadataFolder!.permissions.contains(permissions.permissionMounted) } cell.fileSelectImage?.image = nil diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommonSelectTabBar.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommonSelectTabBar.swift index 8bbbab95f4..02a2759c89 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommonSelectTabBar.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommonSelectTabBar.swift @@ -34,7 +34,7 @@ protocol NCCollectionViewCommonSelectTabBarDelegate: AnyObject { } class NCCollectionViewCommonSelectTabBar: ObservableObject { - var tabBarController: NCMainTabBarController? + var controller: NCMainTabBarController? var hostingController: UIViewController? open weak var delegate: NCCollectionViewCommonSelectTabBarDelegate? @@ -47,27 +47,27 @@ class NCCollectionViewCommonSelectTabBar: ObservableObject { @Published var enableLock = false @Published var isSelectedEmpty = true - init(tabBarController: NCMainTabBarController? = nil, delegate: NCCollectionViewCommonSelectTabBarDelegate? = nil) { + init(controller: NCMainTabBarController? = nil, delegate: NCCollectionViewCommonSelectTabBarDelegate? = nil) { let rootView = NCCollectionViewCommonSelectTabBarView(tabBarSelect: self) hostingController = UIHostingController(rootView: rootView) - self.tabBarController = tabBarController + self.controller = controller self.delegate = delegate - guard let tabBarController, let hostingController else { return } + guard let controller, let hostingController else { return } - tabBarController.view.addSubview(hostingController.view) + controller.view.addSubview(hostingController.view) - hostingController.view.frame = tabBarController.tabBar.frame + hostingController.view.frame = controller.tabBar.frame hostingController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight] hostingController.view.backgroundColor = .clear hostingController.view.isHidden = true } func show() { - guard let tabBarController, let hostingController else { return } + guard let controller, let hostingController else { return } - tabBarController.tabBar.isHidden = true + controller.tabBar.isHidden = true if hostingController.view.isHidden { hostingController.view.isHidden = false hostingController.view.transform = .init(translationX: 0, y: hostingController.view.frame.height) @@ -78,10 +78,10 @@ class NCCollectionViewCommonSelectTabBar: ObservableObject { } func hide() { - guard let tabBarController, let hostingController else { return } + guard let controller, let hostingController else { return } hostingController.view.isHidden = true - tabBarController.tabBar.isHidden = false + controller.tabBar.isHidden = false } func isHidden() -> Bool { diff --git a/iOSClient/Main/Collection Common/NCCollectionViewDownloadThumbnail.swift b/iOSClient/Main/Collection Common/NCCollectionViewDownloadThumbnail.swift index c3be24bb0b..7f10df306d 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewDownloadThumbnail.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewDownloadThumbnail.swift @@ -22,6 +22,7 @@ // import Foundation +import UIKit import Queuer import NextcloudKit import Realm @@ -68,6 +69,7 @@ class NCCollectionViewDownloadThumbnail: ConcurrentOperation { NCManageDatabase.shared.setMetadataEtagResource(ocId: self.metadata.ocId, etagResource: etag) DispatchQueue.main.async { if self.metadata.ocId == self.cell?.fileObjectId, let filePreviewImageView = self.cell?.filePreviewImageView { + self.cell?.filePreviewImageView?.contentMode = .scaleAspectFill if self.metadata.hasPreviewBorder { self.cell?.filePreviewImageView?.layer.borderWidth = 0.2 self.cell?.filePreviewImageView?.layer.borderColor = UIColor.systemGray3.cgColor diff --git a/iOSClient/Main/Create cloud/NCCreateFormUploadDocuments.swift b/iOSClient/Main/Create cloud/NCCreateFormUploadDocuments.swift index e1bb82ca16..7790db9111 100644 --- a/iOSClient/Main/Create cloud/NCCreateFormUploadDocuments.swift +++ b/iOSClient/Main/Create cloud/NCCreateFormUploadDocuments.swift @@ -43,7 +43,7 @@ import XLForm var fileName = "" var fileNameExtension = "" var titleForm = "" - var mainTabBarController: NCMainTabBarController? + var controller: NCMainTabBarController? var listOfTemplate: [NKEditorTemplates] = [] var selectTemplate: NKEditorTemplates? let utilityFileSystem = NCUtilityFileSystem() @@ -323,7 +323,7 @@ import XLForm self.dismiss(animated: true, completion: { let metadata = NCManageDatabase.shared.createMetadata(account: self.appDelegate.account, user: self.appDelegate.user, userId: self.appDelegate.userId, fileName: fileName, fileNameView: fileName, ocId: UUID, serverUrl: self.serverUrl, urlBase: self.appDelegate.urlBase, url: url, contentType: results.mimeType) - if let viewController = self.mainTabBarController?.currentViewController() { + if let viewController = self.controller?.currentViewController() { NCViewer().view(viewController: viewController, metadata: metadata, metadatas: [metadata], imageIcon: nil) } }) @@ -342,7 +342,7 @@ import XLForm self.dismiss(animated: true, completion: { let createFileName = (fileName as NSString).deletingPathExtension + "." + self.fileNameExtension let metadata = NCManageDatabase.shared.createMetadata(account: self.appDelegate.account, user: self.appDelegate.user, userId: self.appDelegate.userId, fileName: createFileName, fileNameView: createFileName, ocId: UUID, serverUrl: self.serverUrl, urlBase: self.appDelegate.urlBase, url: url, contentType: "") - if let viewController = self.mainTabBarController?.currentViewController() { + if let viewController = self.controller?.currentViewController() { NCViewer().view(viewController: viewController, metadata: metadata, metadatas: [metadata], imageIcon: nil) } }) diff --git a/iOSClient/Main/NCActionCenter.swift b/iOSClient/Main/NCActionCenter.swift index a1921ab398..ad549cc6b4 100644 --- a/iOSClient/Main/NCActionCenter.swift +++ b/iOSClient/Main/NCActionCenter.swift @@ -73,23 +73,23 @@ class NCActionCenter: NSObject, UIDocumentInteractionControllerDelegate, NCSelec DispatchQueue.main.async { // Select UIWindowScene active in serverUrl - var mainTabBarController: NCMainTabBarController? + var controller: NCMainTabBarController? let windowScenes = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene } if windowScenes.count == 1 { - mainTabBarController = UIApplication.shared.firstWindow?.rootViewController as? NCMainTabBarController + controller = UIApplication.shared.firstWindow?.rootViewController as? NCMainTabBarController } else if let sceneIdentifier = metadata.sceneIdentifier, - let tabBarController = SceneManager.shared.getMainTabBarController(sceneIdentifier: sceneIdentifier) { - mainTabBarController = tabBarController + let tabBarController = SceneManager.shared.getController(sceneIdentifier: sceneIdentifier) { + controller = tabBarController } else { for windowScene in windowScenes { if let rootViewController = windowScene.keyWindow?.rootViewController as? NCMainTabBarController, rootViewController.currentServerUrl() == metadata.serverUrl { - mainTabBarController = rootViewController + controller = rootViewController break } } } - guard let mainTabBarController else { return } + guard let controller else { return } switch selector { case NCGlobal.shared.selectorLoadFileQuickLook: @@ -107,21 +107,21 @@ class NCActionCenter: NSObject, UIDocumentInteractionControllerDelegate, NCSelec } let navigationController = UINavigationController(rootViewController: viewerQuickLook) navigationController.modalPresentationStyle = .fullScreen - mainTabBarController.present(navigationController, animated: true) + controller.present(navigationController, animated: true) } else { self.utilityFileSystem.copyFile(atPath: fileNamePath, toPath: fileNameTemp) - mainTabBarController.present(viewerQuickLook, animated: true) + controller.present(viewerQuickLook, animated: true) } case NCGlobal.shared.selectorLoadFileView: guard UIApplication.shared.applicationState == .active else { return } if metadata.contentType.contains("opendocument") && !self.utility.isRichDocument(metadata) { - self.openDocumentController(metadata: metadata, mainTabBarController: mainTabBarController) + self.openDocumentController(metadata: metadata, controller: controller) } else if metadata.classFile == NKCommon.TypeClassFile.compress.rawValue || metadata.classFile == NKCommon.TypeClassFile.unknow.rawValue { - self.openDocumentController(metadata: metadata, mainTabBarController: mainTabBarController) + self.openDocumentController(metadata: metadata, controller: controller) } else { - if let viewController = mainTabBarController.currentViewController() { + if let viewController = controller.currentViewController() { let imageIcon = UIImage(contentsOfFile: self.utilityFileSystem.getDirectoryProviderStorageIconOcId(metadata.ocId, etag: metadata.etag)) NCViewer().view(viewController: viewController, metadata: metadata, metadatas: [metadata], imageIcon: imageIcon) } @@ -130,16 +130,16 @@ class NCActionCenter: NSObject, UIDocumentInteractionControllerDelegate, NCSelec case NCGlobal.shared.selectorOpenIn: if UIApplication.shared.applicationState == .active { - self.openDocumentController(metadata: metadata, mainTabBarController: mainTabBarController) + self.openDocumentController(metadata: metadata, controller: controller) } case NCGlobal.shared.selectorSaveAlbum: - self.saveAlbum(metadata: metadata, mainTabBarController: mainTabBarController) + self.saveAlbum(metadata: metadata, controller: controller) case NCGlobal.shared.selectorSaveAsScan: - self.saveAsScan(metadata: metadata, mainTabBarController: mainTabBarController) + self.saveAsScan(metadata: metadata, controller: controller) case NCGlobal.shared.selectorOpenDetail: NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterOpenMediaDetail, userInfo: ["ocId": metadata.ocId]) @@ -317,9 +317,9 @@ class NCActionCenter: NSObject, UIDocumentInteractionControllerDelegate, NCSelec // MARK: - Open in ... - func openDocumentController(metadata: tableMetadata, mainTabBarController: NCMainTabBarController?) { + func openDocumentController(metadata: tableMetadata, controller: NCMainTabBarController?) { - guard let mainTabBarController, + guard let mainTabBarController = controller, let mainTabBar = mainTabBarController.tabBar as? NCMainTabBar else { return } let fileURL = URL(fileURLWithPath: utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)) @@ -327,9 +327,9 @@ class NCActionCenter: NSObject, UIDocumentInteractionControllerDelegate, NCSelec documentController?.presentOptionsMenu(from: mainTabBar.menuRect, in: mainTabBar, animated: true) } - func openActivityViewController(selectedMetadata: [tableMetadata], mainTabBarController: NCMainTabBarController?) { - guard let mainTabBarController, - let mainTabBar = mainTabBarController.tabBar as? NCMainTabBar else { return } + func openActivityViewController(selectedMetadata: [tableMetadata], controller: NCMainTabBarController?) { + guard let controller, + let mainTabBar = controller.tabBar as? NCMainTabBar else { return } let metadatas = selectedMetadata.filter({ !$0.directory }) var items: [URL] = [] var downloadMetadata: [(tableMetadata, URL)] = [] @@ -343,13 +343,13 @@ class NCActionCenter: NSObject, UIDocumentInteractionControllerDelegate, NCSelec } } - let processor = ParallelWorker(n: 5, titleKey: "_downloading_", totalTasks: downloadMetadata.count, hudView: mainTabBarController.view) + let processor = ParallelWorker(n: 5, titleKey: "_downloading_", totalTasks: downloadMetadata.count, hudView: controller.view) for (metadata, url) in downloadMetadata { processor.execute { completion in guard let metadata = NCManageDatabase.shared.setMetadatasSessionInWaitDownload(metadatas: [metadata], session: NextcloudKit.shared.nkCommonInstance.sessionIdentifierDownload, selector: "", - sceneIdentifier: mainTabBarController.sceneIdentifier) else { return completion() } + sceneIdentifier: controller.sceneIdentifier) else { return completion() } NCNetworking.shared.download(metadata: metadata, withNotificationProgressTask: false) { } progressHandler: { progress in processor.hud?.progress = Float(progress.fractionCompleted) @@ -366,13 +366,13 @@ class NCActionCenter: NSObject, UIDocumentInteractionControllerDelegate, NCSelec activityViewController.popoverPresentationController?.permittedArrowDirections = .any activityViewController.popoverPresentationController?.sourceView = mainTabBar activityViewController.popoverPresentationController?.sourceRect = mainTabBar.menuRect - mainTabBarController.present(activityViewController, animated: true) + controller.present(activityViewController, animated: true) } } // MARK: - Save as scan - func saveAsScan(metadata: tableMetadata, mainTabBarController: NCMainTabBarController?) { + func saveAsScan(metadata: tableMetadata, controller: NCMainTabBarController?) { let fileNamePath = utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView) let fileNameDestination = CCUtility.createFileName("scan.png", fileDate: Date(), fileType: PHAssetMediaType.image, keyFileName: NCGlobal.shared.keyFileNameMask, keyFileNameType: NCGlobal.shared.keyFileNameType, keyFileNameOriginal: NCGlobal.shared.keyFileNameOriginal, forcedNewFileName: true)! let fileNamePathDestination = utilityFileSystem.directoryScan + "/" + fileNameDestination @@ -382,17 +382,17 @@ class NCActionCenter: NSObject, UIDocumentInteractionControllerDelegate, NCSelec if let navigationController = UIStoryboard(name: "NCScan", bundle: nil).instantiateInitialViewController() { navigationController.modalPresentationStyle = UIModalPresentationStyle.pageSheet let viewController = navigationController.presentedViewController as? NCScan - viewController?.serverUrl = mainTabBarController?.currentServerUrl() - mainTabBarController?.present(navigationController, animated: true, completion: nil) + viewController?.serverUrl = controller?.currentServerUrl() + controller?.present(navigationController, animated: true, completion: nil) } } // MARK: - Save photo - func saveAlbum(metadata: tableMetadata, mainTabBarController: NCMainTabBarController?) { + func saveAlbum(metadata: tableMetadata, controller: NCMainTabBarController?) { let fileNamePath = utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView) - NCAskAuthorization().askAuthorizationPhotoLibrary(viewController: mainTabBarController) { hasPermission in + NCAskAuthorization().askAuthorizationPhotoLibrary(viewController: controller) { hasPermission in guard hasPermission else { let error = NKError(errorCode: NCGlobal.shared.errorFileNotSaved, errorDescription: "_access_photo_not_enabled_msg_") return NCContentPresenter().messageNotification("_access_photo_not_enabled_", error: error, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error) @@ -483,15 +483,15 @@ class NCActionCenter: NSObject, UIDocumentInteractionControllerDelegate, NCSelec func openFileViewInFolder(serverUrl: String, fileNameBlink: String?, fileNameOpen: String?, sceneIdentifier: String) { guard let appDelegate = UIApplication.shared.delegate as? AppDelegate, - let mainTabBarController = SceneManager.shared.getMainTabBarController(sceneIdentifier: sceneIdentifier), - let navigationController = mainTabBarController.viewControllers?.first as? UINavigationController + let controller = SceneManager.shared.getController(sceneIdentifier: sceneIdentifier), + let navigationController = controller.viewControllers?.first as? UINavigationController else { return } var serverUrlPush = self.utilityFileSystem.getHomeServer(urlBase: appDelegate.urlBase, userId: appDelegate.userId) - let filesServerUrl = mainTabBarController.filesServerUrl + let filesServerUrl = controller.filesServerUrl DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { navigationController.popToRootViewController(animated: false) - mainTabBarController.selectedIndex = 0 + controller.selectedIndex = 0 if serverUrlPush == serverUrl, let viewController = navigationController.topViewController as? NCFiles { viewController.blinkCell(fileName: fileNameBlink) @@ -568,7 +568,7 @@ class NCActionCenter: NSObject, UIDocumentInteractionControllerDelegate, NCSelec } } - func openSelectView(items: [tableMetadata], mainTabBarController: NCMainTabBarController?) { + func openSelectView(items: [tableMetadata], controller: NCMainTabBarController?) { guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return } let navigationController = UIStoryboard(name: "NCSelect", bundle: nil).instantiateInitialViewController() as? UINavigationController @@ -620,21 +620,7 @@ class NCActionCenter: NSObject, UIDocumentInteractionControllerDelegate, NCSelec navigationController?.modalPresentationStyle = .formSheet if let navigationController = navigationController { - mainTabBarController?.present(navigationController, animated: true, completion: nil) + controller?.present(navigationController, animated: true, completion: nil) } } } - -fileprivate extension tableMetadata { - func toPasteBoardItem() -> [String: Any]? { - // Get Data - let fileUrl = URL(fileURLWithPath: NCUtilityFileSystem().getDirectoryProviderStorageOcId(ocId, fileNameView: fileNameView)) - guard NCUtilityFileSystem().fileProviderStorageExists(self), - let data = try? Data(contentsOf: fileUrl), - let unmanagedFileUTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, fileExtension as CFString, nil) - else { return nil } - // Pasteboard item - let fileUTI = unmanagedFileUTI.takeRetainedValue() as String - return [fileUTI: data] - } -} diff --git a/iOSClient/Main/NCMainTabBar.swift b/iOSClient/Main/NCMainTabBar.swift index 24b79bf5c6..5aa20d18d6 100644 --- a/iOSClient/Main/NCMainTabBar.swift +++ b/iOSClient/Main/NCMainTabBar.swift @@ -182,8 +182,8 @@ class NCMainTabBar: UITabBar { centerButton.layer.shadowOpacity = 0.5 centerButton.action(for: .touchUpInside) { _ in - if let mainTabBarController = self.window?.rootViewController as? NCMainTabBarController { - let serverUrl = mainTabBarController.currentServerUrl() + if let controller = self.window?.rootViewController as? NCMainTabBarController { + let serverUrl = controller.currentServerUrl() if let directory = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", self.appDelegate.account, serverUrl)) { if !directory.permissions.contains("CK") { let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_no_permission_add_file_") @@ -191,7 +191,7 @@ class NCMainTabBar: UITabBar { return } } - self.appDelegate.toggleMenu(mainTabBarController: mainTabBarController) + self.appDelegate.toggleMenu(controller: controller) } } diff --git a/iOSClient/Main/NCPickerViewController.swift b/iOSClient/Main/NCPickerViewController.swift index 30666c3c3e..70c06e8616 100644 --- a/iOSClient/Main/NCPickerViewController.swift +++ b/iOSClient/Main/NCPickerViewController.swift @@ -32,13 +32,13 @@ import SwiftUI class NCPhotosPickerViewController: NSObject { let appDelegate = (UIApplication.shared.delegate as? AppDelegate)! - var mainTabBarController: NCMainTabBarController + var controller: NCMainTabBarController var maxSelectedAssets = 1 var singleSelectedMode = false @discardableResult - init(mainTabBarController: NCMainTabBarController, maxSelectedAssets: Int, singleSelectedMode: Bool) { - self.mainTabBarController = mainTabBarController + init(controller: NCMainTabBarController, maxSelectedAssets: Int, singleSelectedMode: Bool) { + self.controller = controller super.init() self.maxSelectedAssets = maxSelectedAssets @@ -46,11 +46,11 @@ class NCPhotosPickerViewController: NSObject { self.openPhotosPickerViewController { assets in if !assets.isEmpty { - let serverUrl = mainTabBarController.currentServerUrl() - let view = NCUploadAssetsView(model: NCUploadAssetsModel(assets: assets, serverUrl: serverUrl, userBaseUrl: self.appDelegate, controller: mainTabBarController)) + let serverUrl = controller.currentServerUrl() + let view = NCUploadAssetsView(model: NCUploadAssetsModel(assets: assets, serverUrl: serverUrl, userBaseUrl: self.appDelegate, controller: controller)) let controller = UIHostingController(rootView: view) DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) { - mainTabBarController.present(controller, animated: true, completion: nil) + controller.present(controller, animated: true, completion: nil) } } } @@ -95,7 +95,7 @@ class NCPhotosPickerViewController: NSObject { viewController.configure = configure - mainTabBarController.present(viewController, animated: true, completion: nil) + controller.present(viewController, animated: true, completion: nil) } } @@ -124,8 +124,8 @@ class NCDocumentPickerViewController: NSObject, UIDocumentPickerDelegate { var mainTabBarController: NCMainTabBarController @discardableResult - init (mainTabBarController: NCMainTabBarController, isViewerMedia: Bool, allowsMultipleSelection: Bool, viewController: UIViewController? = nil) { - self.mainTabBarController = mainTabBarController + init (controller: NCMainTabBarController, isViewerMedia: Bool, allowsMultipleSelection: Bool, viewController: UIViewController? = nil) { + self.mainTabBarController = controller self.isViewerMedia = isViewerMedia self.viewController = viewController super.init() diff --git a/iOSClient/Media/NCMedia+Command.swift b/iOSClient/Media/NCMedia+Command.swift index 7b28be9991..c5f8b90596 100644 --- a/iOSClient/Media/NCMedia+Command.swift +++ b/iOSClient/Media/NCMedia+Command.swift @@ -161,8 +161,8 @@ extension NCMedia { ]) let playFile = UIAction(title: NSLocalizedString("_play_from_files_", comment: ""), image: utility.loadImage(named: "play.circle")) { _ in - guard let mainTabBarController = self.tabBarController as? NCMainTabBarController else { return } - self.documentPickerViewController = NCDocumentPickerViewController(mainTabBarController: mainTabBarController, isViewerMedia: true, allowsMultipleSelection: false, viewController: self) + guard let controller = self.tabBarController as? NCMainTabBarController else { return } + self.documentPickerViewController = NCDocumentPickerViewController(controller: controller, isViewerMedia: true, allowsMultipleSelection: false, viewController: self) } let playURL = UIAction(title: NSLocalizedString("_play_from_url_", comment: ""), image: utility.loadImage(named: "link")) { _ in diff --git a/iOSClient/Menu/AppDelegate+Menu.swift b/iOSClient/Menu/AppDelegate+Menu.swift index c60f0ead49..2c26177c4d 100644 --- a/iOSClient/Menu/AppDelegate+Menu.swift +++ b/iOSClient/Menu/AppDelegate+Menu.swift @@ -29,11 +29,11 @@ import NextcloudKit extension AppDelegate { - func toggleMenu(mainTabBarController: NCMainTabBarController) { + func toggleMenu(controller: NCMainTabBarController) { var actions: [NCMenuAction] = [] let appDelegate = (UIApplication.shared.delegate as? AppDelegate)! let directEditingCreators = NCManageDatabase.shared.getDirectEditingCreators(account: appDelegate.account) - let serverUrl = mainTabBarController.currentServerUrl() + let serverUrl = controller.currentServerUrl() let isDirectoryE2EE = NCUtilityFileSystem().isDirectoryE2EE(serverUrl: serverUrl, userBase: appDelegate) let directory = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.account, serverUrl)) let utility = NCUtility() @@ -41,8 +41,8 @@ extension AppDelegate { actions.append( NCMenuAction( title: NSLocalizedString("_upload_photos_videos_", comment: ""), icon: utility.loadImage(named: "photo", colors: [NCBrandColor.shared.iconImageColor]), action: { _ in - NCAskAuthorization().askAuthorizationPhotoLibrary(viewController: mainTabBarController) { hasPermission in - if hasPermission {NCPhotosPickerViewController(mainTabBarController: mainTabBarController, maxSelectedAssets: 0, singleSelectedMode: false) + NCAskAuthorization().askAuthorizationPhotoLibrary(viewController: controller) { hasPermission in + if hasPermission {NCPhotosPickerViewController(controller: controller, maxSelectedAssets: 0, singleSelectedMode: false) } } } @@ -52,7 +52,7 @@ extension AppDelegate { actions.append( NCMenuAction( title: NSLocalizedString("_upload_file_", comment: ""), icon: utility.loadImage(named: "doc", colors: [NCBrandColor.shared.iconImageColor]), action: { _ in - mainTabBarController.documentPickerViewController = NCDocumentPickerViewController(mainTabBarController: mainTabBarController, isViewerMedia: false, allowsMultipleSelection: true) + controller.documentPickerViewController = NCDocumentPickerViewController(controller: controller, isViewerMedia: false, allowsMultipleSelection: true) } ) ) @@ -65,7 +65,7 @@ extension AppDelegate { Task { let fileName = await NCNetworking.shared.createFileName(fileNameBase: NSLocalizedString("_untitled_", comment: "") + ".md", account: appDelegate.account, serverUrl: serverUrl) let fileNamePath = NCUtilityFileSystem().getFileNamePath(String(describing: fileName), serverUrl: serverUrl, urlBase: appDelegate.urlBase, userId: appDelegate.userId) - self.createTextDocument(mainTabBarController: mainTabBarController, fileNamePath: fileNamePath, fileName: String(describing: fileName), creatorId: directEditingCreator.identifier) + self.createTextDocument(controller: controller, fileNamePath: fileNamePath, fileName: String(describing: fileName), creatorId: directEditingCreator.identifier) } }) ) @@ -74,7 +74,7 @@ extension AppDelegate { actions.append( NCMenuAction( title: NSLocalizedString("_scans_document_", comment: ""), icon: utility.loadImage(named: "doc.text.viewfinder", colors: [NCBrandColor.shared.iconImageColor]), action: { _ in - NCDocumentCamera.shared.openScannerDocument(viewController: mainTabBarController) + NCDocumentCamera.shared.openScannerDocument(viewController: controller) } ) ) @@ -82,13 +82,13 @@ extension AppDelegate { actions.append( NCMenuAction( title: NSLocalizedString("_create_voice_memo_", comment: ""), icon: utility.loadImage(named: "mic", colors: [NCBrandColor.shared.iconImageColor]), action: { _ in - NCAskAuthorization().askAuthorizationAudioRecord(viewController: mainTabBarController) { hasPermission in + NCAskAuthorization().askAuthorizationAudioRecord(viewController: controller) { hasPermission in if hasPermission { if let viewController = UIStoryboard(name: "NCAudioRecorderViewController", bundle: nil).instantiateInitialViewController() as? NCAudioRecorderViewController { viewController.serverUrl = serverUrl viewController.modalTransitionStyle = .crossDissolve viewController.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext - mainTabBarController.present(viewController, animated: true, completion: nil) + controller.present(viewController, animated: true, completion: nil) } } } @@ -105,8 +105,8 @@ extension AppDelegate { actions.append( NCMenuAction(title: titleCreateFolder, icon: imageCreateFolder, action: { _ in - let alertController = UIAlertController.createFolder(serverUrl: serverUrl, urlBase: appDelegate, sceneIdentifier: mainTabBarController.sceneIdentifier) - mainTabBarController.present(alertController, animated: true, completion: nil) + let alertController = UIAlertController.createFolder(serverUrl: serverUrl, urlBase: appDelegate, sceneIdentifier: controller.sceneIdentifier) + controller.present(alertController, animated: true, completion: nil) } ) ) @@ -117,8 +117,8 @@ extension AppDelegate { NCMenuAction(title: NSLocalizedString("_create_folder_e2ee_", comment: ""), icon: NCImageCache.images.folderEncrypted, action: { _ in - let alertController = UIAlertController.createFolder(serverUrl: serverUrl, urlBase: appDelegate, markE2ee: true, sceneIdentifier: mainTabBarController.sceneIdentifier) - mainTabBarController.present(alertController, animated: true, completion: nil) + let alertController = UIAlertController.createFolder(serverUrl: serverUrl, urlBase: appDelegate, markE2ee: true, sceneIdentifier: controller.sceneIdentifier) + controller.present(alertController, animated: true, completion: nil) }) ) } @@ -132,7 +132,7 @@ extension AppDelegate { NCMenuAction( title: NSLocalizedString("_add_folder_info_", comment: ""), icon: NCUtility().loadImage(named: "list.dash.header.rectangle", colors: [NCBrandColor.shared.iconImageColor]), action: { _ in let richWorkspaceCommon = NCRichWorkspaceCommon() - if let viewController = mainTabBarController.currentViewController() { + if let viewController = controller.currentViewController() { if NCManageDatabase.shared.getMetadata(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileNameView LIKE[c] %@", appDelegate.account, serverUrl, NCGlobal.shared.fileNameRichWorkspace.lowercased())) == nil { richWorkspaceCommon.createViewerNextcloudText(serverUrl: serverUrl, viewController: viewController) } else { @@ -155,14 +155,14 @@ extension AppDelegate { navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet if let viewController = (navigationController as? UINavigationController)?.topViewController as? NCCreateFormUploadDocuments { - viewController.mainTabBarController = mainTabBarController + viewController.controller = controller viewController.editorId = NCGlobal.shared.editorOnlyoffice viewController.creatorId = directEditingCreator.identifier viewController.typeTemplate = NCGlobal.shared.templateDocument viewController.serverUrl = serverUrl viewController.titleForm = NSLocalizedString("_create_new_document_", comment: "") - mainTabBarController.present(navigationController, animated: true, completion: nil) + controller.present(navigationController, animated: true, completion: nil) } } ) @@ -180,14 +180,14 @@ extension AppDelegate { navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet if let viewController = (navigationController as? UINavigationController)?.topViewController as? NCCreateFormUploadDocuments { - viewController.mainTabBarController = mainTabBarController + viewController.controller = controller viewController.editorId = NCGlobal.shared.editorOnlyoffice viewController.creatorId = directEditingCreator.identifier viewController.typeTemplate = NCGlobal.shared.templateSpreadsheet viewController.serverUrl = serverUrl viewController.titleForm = NSLocalizedString("_create_new_spreadsheet_", comment: "") - mainTabBarController.present(navigationController, animated: true, completion: nil) + controller.present(navigationController, animated: true, completion: nil) } } ) @@ -205,14 +205,14 @@ extension AppDelegate { navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet if let viewController = (navigationController as? UINavigationController)?.topViewController as? NCCreateFormUploadDocuments { - viewController.mainTabBarController = mainTabBarController + viewController.controller = controller viewController.editorId = NCGlobal.shared.editorOnlyoffice viewController.creatorId = directEditingCreator.identifier viewController.typeTemplate = NCGlobal.shared.templatePresentation viewController.serverUrl = serverUrl viewController.titleForm = NSLocalizedString("_create_new_presentation_", comment: "") - mainTabBarController.present(navigationController, animated: true, completion: nil) + controller.present(navigationController, animated: true, completion: nil) } } ) @@ -230,13 +230,13 @@ extension AppDelegate { navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet if let viewController = (navigationController as? UINavigationController)?.topViewController as? NCCreateFormUploadDocuments { - viewController.mainTabBarController = mainTabBarController + viewController.controller = controller viewController.editorId = NCGlobal.shared.editorCollabora viewController.typeTemplate = NCGlobal.shared.templateDocument viewController.serverUrl = serverUrl viewController.titleForm = NSLocalizedString("_create_nextcloudtext_document_", comment: "") - mainTabBarController.present(navigationController, animated: true, completion: nil) + controller.present(navigationController, animated: true, completion: nil) } } ) @@ -251,13 +251,13 @@ extension AppDelegate { navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet if let viewController = (navigationController as? UINavigationController)?.topViewController as? NCCreateFormUploadDocuments { - viewController.mainTabBarController = mainTabBarController + viewController.controller = controller viewController.editorId = NCGlobal.shared.editorCollabora viewController.typeTemplate = NCGlobal.shared.templateSpreadsheet viewController.serverUrl = serverUrl viewController.titleForm = NSLocalizedString("_create_new_spreadsheet_", comment: "") - mainTabBarController.present(navigationController, animated: true, completion: nil) + controller.present(navigationController, animated: true, completion: nil) } } ) @@ -272,13 +272,13 @@ extension AppDelegate { navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet if let viewController = (navigationController as? UINavigationController)?.topViewController as? NCCreateFormUploadDocuments { - viewController.mainTabBarController = mainTabBarController + viewController.controller = controller viewController.editorId = NCGlobal.shared.editorCollabora viewController.typeTemplate = NCGlobal.shared.templatePresentation viewController.serverUrl = serverUrl viewController.titleForm = NSLocalizedString("_create_new_presentation_", comment: "") - mainTabBarController.present(navigationController, animated: true, completion: nil) + controller.present(navigationController, animated: true, completion: nil) } } ) @@ -286,14 +286,14 @@ extension AppDelegate { } } - mainTabBarController.presentMenu(with: actions) + controller.presentMenu(with: actions) } - func createTextDocument(mainTabBarController: NCMainTabBarController, fileNamePath: String, fileName: String, creatorId: String) { - guard let viewController = mainTabBarController.currentViewController() else { return } + func createTextDocument(controller: NCMainTabBarController, fileNamePath: String, fileName: String, creatorId: String) { + guard let viewController = controller.currentViewController() else { return } var UUID = NSUUID().uuidString UUID = "TEMP" + UUID.replacingOccurrences(of: "-", with: "") - let serverUrl = mainTabBarController.currentServerUrl() + let serverUrl = controller.currentServerUrl() let options = NKRequestOptions(customUserAgent: NCUtility().getCustomUserAgentNCText()) NextcloudKit.shared.NCTextCreateFile(fileNamePath: fileNamePath, editorId: NCGlobal.shared.editorText, creatorId: creatorId, templateId: NCGlobal.shared.templateDocument, options: options) { account, url, _, error in diff --git a/iOSClient/Menu/NCMenu+FloatingPanel.swift b/iOSClient/Menu/NCMenu+FloatingPanel.swift index 51e38bc019..b592c44b3a 100644 --- a/iOSClient/Menu/NCMenu+FloatingPanel.swift +++ b/iOSClient/Menu/NCMenu+FloatingPanel.swift @@ -27,22 +27,16 @@ import UIKit class NCMenuFloatingPanelLayout: FloatingPanelLayout { var position: FloatingPanelPosition = .bottom - var initialState: FloatingPanelState = .full - var anchors: [FloatingPanelState: FloatingPanelLayoutAnchoring] { [ .full: FloatingPanelLayoutAnchor(absoluteInset: topInset, edge: .top, referenceGuide: .superview) ] } - let topInset: CGFloat init(actionsHeight: CGFloat) { - // sometimes UIScreen.main.bounds.size.height is not updated correctly - // this ensures we use the correct height value - // can't use `layoutFor size` since menu is dieplayed on top of the whole screen not just the VC - let screenHeight = UIDevice.current.orientation.isLandscapeHardCheck + let screenHeight = UIDevice.current.orientation.isLandscape ? min(UIScreen.main.bounds.size.width, UIScreen.main.bounds.size.height) : max(UIScreen.main.bounds.size.width, UIScreen.main.bounds.size.height) let window = UIApplication.shared.connectedScenes.flatMap { ($0 as? UIWindowScene)?.windows ?? [] }.first { $0.isKeyWindow } diff --git a/iOSClient/Menu/NCMenuAction.swift b/iOSClient/Menu/NCMenuAction.swift index 2b791842ff..6e082b5dab 100644 --- a/iOSClient/Menu/NCMenuAction.swift +++ b/iOSClient/Menu/NCMenuAction.swift @@ -105,6 +105,7 @@ extension NCMenuAction { var icon = "trash" var destructive = false var color = NCBrandColor.shared.iconImageColor + let permissions = NCPermissions() if selectedMetadatas.count > 1 { titleDelete = NSLocalizedString("_delete_selected_files_", comment: "") @@ -123,8 +124,8 @@ extension NCMenuAction { } if let metadataFolder = metadataFolder { - let isShare = metadata.permissions.contains(NCGlobal.shared.permissionShared) && !metadataFolder.permissions.contains(NCGlobal.shared.permissionShared) - let isMounted = metadata.permissions.contains(NCGlobal.shared.permissionMounted) && !metadataFolder.permissions.contains(NCGlobal.shared.permissionMounted) + let isShare = metadata.permissions.contains(permissions.permissionShared) && !metadataFolder.permissions.contains(permissions.permissionShared) + let isMounted = metadata.permissions.contains(permissions.permissionMounted) && !metadataFolder.permissions.contains(permissions.permissionMounted) if isShare || isMounted { titleDelete = NSLocalizedString("_leave_share_", comment: "") icon = "person.2.slash" @@ -161,8 +162,8 @@ extension NCMenuAction { icon: NCUtility().loadImage(named: "square.and.arrow.up", colors: [NCBrandColor.shared.iconImageColor]), order: order, action: { _ in - let mainTabBarController = viewController.tabBarController as? NCMainTabBarController - NCActionCenter.shared.openActivityViewController(selectedMetadata: selectedMetadatas, mainTabBarController: mainTabBarController) + let controller = viewController.tabBarController as? NCMainTabBarController + NCActionCenter.shared.openActivityViewController(selectedMetadata: selectedMetadatas, controller: controller) completion?() } ) @@ -200,8 +201,8 @@ extension NCMenuAction { icon: NCUtility().loadImage(named: "rectangle.portrait.and.arrow.right", colors: [NCBrandColor.shared.iconImageColor]), order: order, action: { _ in - let mainTabBarController = viewController.tabBarController as? NCMainTabBarController - NCActionCenter.shared.openSelectView(items: selectedMetadatas, mainTabBarController: mainTabBarController) + let controller = viewController.tabBarController as? NCMainTabBarController + NCActionCenter.shared.openSelectView(items: selectedMetadatas, controller: controller) completion?() } ) diff --git a/iOSClient/Menu/NCShare+Menu.swift b/iOSClient/Menu/NCShare+Menu.swift index 50b51085c7..d497981031 100644 --- a/iOSClient/Menu/NCShare+Menu.swift +++ b/iOSClient/Menu/NCShare+Menu.swift @@ -22,6 +22,7 @@ // import Foundation +import UIKit import NextcloudKit extension NCShare { @@ -87,16 +88,17 @@ extension NCShare { func toggleUserPermissionMenu(isDirectory: Bool, tableShare: tableShare) { var actions = [NCMenuAction]() + let permissions = NCPermissions() actions.append( NCMenuAction( title: NSLocalizedString("_share_read_only_", comment: ""), icon: utility.loadImage(named: "eye", colors: [NCBrandColor.shared.iconImageColor]), - selected: tableShare.permissions == (NCGlobal.shared.permissionReadShare + NCGlobal.shared.permissionShareShare) || tableShare.permissions == NCGlobal.shared.permissionReadShare, + selected: tableShare.permissions == (permissions.permissionReadShare + permissions.permissionShareShare) || tableShare.permissions == permissions.permissionReadShare, on: false, action: { _ in - let canShare = CCUtility.isPermission(toCanShare: tableShare.permissions) - let permissions = CCUtility.getPermissionsValue(byCanEdit: false, andCanCreate: false, andCanChange: false, andCanDelete: false, andCanShare: canShare, andIsFolder: isDirectory) + let canShare = permissions.isPermissionToCanShare(tableShare.permissions) + let permissions = permissions.getPermission(canEdit: false, canCreate: false, canChange: false, canDelete: false, canShare: canShare, isDirectory: isDirectory) self.updateSharePermissions(share: tableShare, permissions: permissions) } ) @@ -109,8 +111,8 @@ extension NCShare { selected: hasUploadPermission(tableShare: tableShare), on: false, action: { _ in - let canShare = CCUtility.isPermission(toCanShare: tableShare.permissions) - let permissions = CCUtility.getPermissionsValue(byCanEdit: true, andCanCreate: true, andCanChange: true, andCanDelete: true, andCanShare: canShare, andIsFolder: isDirectory) + let canShare = permissions.isPermissionToCanShare(tableShare.permissions) + let permissions = permissions.getPermission(canEdit: true, canCreate: true, canChange: true, canDelete: true, canShare: canShare, isDirectory: isDirectory) self.updateSharePermissions(share: tableShare, permissions: permissions) } ) @@ -120,11 +122,12 @@ extension NCShare { } fileprivate func hasUploadPermission(tableShare: tableShare) -> Bool { + let permissions = NCPermissions() let uploadPermissions = [ - NCGlobal.shared.permissionMaxFileShare, - NCGlobal.shared.permissionMaxFolderShare, - NCGlobal.shared.permissionDefaultFileRemoteShareNoSupportShareOption, - NCGlobal.shared.permissionDefaultFolderRemoteShareNoSupportShareOption] + permissions.permissionMaxFileShare, + permissions.permissionMaxFolderShare, + permissions.permissionDefaultFileRemoteShareNoSupportShareOption, + permissions.permissionDefaultFolderRemoteShareNoSupportShareOption] return uploadPermissions.contains(tableShare.permissions) } diff --git a/iOSClient/More/CCManageAccount.m b/iOSClient/More/CCManageAccount.m index e366ecfb68..229f99216e 100644 --- a/iOSClient/More/CCManageAccount.m +++ b/iOSClient/More/CCManageAccount.m @@ -380,7 +380,7 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa if (indexPath.section == 0) { return 60; } else { - return NCGlobal.shared.heightCellSettings; + return 50; } } diff --git a/iOSClient/More/NCMore.swift b/iOSClient/More/NCMore.swift index bf2c179f57..78309280b3 100644 --- a/iOSClient/More/NCMore.swift +++ b/iOSClient/More/NCMore.swift @@ -289,9 +289,7 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource { } @objc func tapImageLogoManageAccount() { - let controller = CCManageAccount() - self.navigationController?.pushViewController(controller, animated: true) } @@ -300,10 +298,8 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource { func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { if sections[indexPath.section].type == .account { return 75 - } else if sections[indexPath.section].type == .moreApps { - return 50 } else { - return NCGlobal.shared.heightCellSettings + return 50 } } diff --git a/iOSClient/NCGlobal.swift b/iOSClient/NCGlobal.swift index 5c7d2a705a..8cdfc582a7 100644 --- a/iOSClient/NCGlobal.swift +++ b/iOSClient/NCGlobal.swift @@ -134,10 +134,6 @@ class NCGlobal: NSObject { @objc let introLogin: Int = 0 let introSignup: Int = 1 - // Varie size GUI - // - @objc let heightCellSettings: CGFloat = 50 - // Avatar & Preview size // let avatarSize: Int = 128 * Int(UIScreen.main.scale) @@ -148,7 +144,7 @@ class NCGlobal: NSObject { // E2EE // let e2eePassphraseTest = "more over television factory tendency independence international intellectual impress interest sentence pony" - @objc let e2eeVersions = ["1.1", "1.2", "2.0"] + let e2eeVersions = ["1.1", "1.2", "2.0"] let e2eeVersionV11 = "1.1" let e2eeVersionV12 = "1.2" let e2eeVersionV20 = "2.0" @@ -270,36 +266,6 @@ class NCGlobal: NSObject { @objc let errorE2EENoUserFound: Int = -98015 @objc let errorE2EEUploadInProgress: Int = -98016 - // Constants to identify the different permissions of a file - // - @objc let permissionShared = "S" - @objc let permissionCanShare = "R" - @objc let permissionMounted = "M" - @objc let permissionFileCanWrite = "W" - @objc let permissionCanCreateFile = "C" - @objc let permissionCanCreateFolder = "K" - @objc let permissionCanDelete = "D" - @objc let permissionCanRename = "N" - @objc let permissionCanMove = "V" - - // Share permission - // permissions - (int) 1 = read; 2 = update; 4 = create; 8 = delete; 16 = share; 31 = all - // - @objc let permissionReadShare: Int = 1 - @objc let permissionUpdateShare: Int = 2 - @objc let permissionCreateShare: Int = 4 - @objc let permissionDeleteShare: Int = 8 - @objc let permissionShareShare: Int = 16 - - @objc let permissionMinFileShare: Int = 1 - @objc let permissionMaxFileShare: Int = 19 - @objc let permissionMinFolderShare: Int = 1 - @objc let permissionMaxFolderShare: Int = 31 - @objc let permissionDefaultFileRemoteShareNoSupportShareOption: Int = 3 - @objc let permissionDefaultFolderRemoteShareNoSupportShareOption: Int = 15 - // ATTRIBUTES - @objc let permissionDownloadShare: Int = 0 - // Filename Mask and Type // let keyFileNameMask = "fileNameMask" @@ -350,21 +316,21 @@ class NCGlobal: NSObject { // Auto upload subfolder granularity // - @objc let subfolderGranularityDaily = 2 - @objc let subfolderGranularityMonthly = 1 - @objc let subfolderGranularityYearly = 0 + let subfolderGranularityDaily = 2 + let subfolderGranularityMonthly = 1 + let subfolderGranularityYearly = 0 // Notification Center // @objc let notificationCenterChangeUser = "changeUser" - @objc let notificationCenterChangeTheming = "changeTheming" + let notificationCenterChangeTheming = "changeTheming" let notificationCenterRichdocumentGrabFocus = "richdocumentGrabFocus" let notificationCenterReloadDataNCShare = "reloadDataNCShare" let notificationCenterCloseRichWorkspaceWebView = "closeRichWorkspaceWebView" let notificationCenterReloadAvatar = "reloadAvatar" let notificationCenterCreateMediaCacheEnded = "createMediaCacheEnded" - @objc let notificationCenterReloadDataSource = "reloadDataSource" + let notificationCenterReloadDataSource = "reloadDataSource" let notificationCenterReloadDataSourceNetwork = "reloadDataSourceNetwork" // userInfo: withQueryDB let notificationCenterChangeStatusFolderE2EE = "changeStatusFolderE2EE" // userInfo: serverUrl @@ -374,7 +340,7 @@ class NCGlobal: NSObject { let notificationCenterDownloadCancelFile = "downloadCancelFile" // userInfo: ocId, serverUrl, account let notificationCenterUploadStartFile = "uploadStartFile" // userInfo: ocId, serverUrl, account, fileName, sessionSelector - @objc let notificationCenterUploadedFile = "uploadedFile" // userInfo: ocId, serverUrl, account, fileName, ocIdTemp, error + let notificationCenterUploadedFile = "uploadedFile" // userInfo: ocId, serverUrl, account, fileName, ocIdTemp, error let notificationCenterUploadedLivePhoto = "uploadedLivePhoto" // userInfo: ocId, serverUrl, account, fileName, ocIdTemp, error let notificationCenterUploadCancelFile = "uploadCancelFile" // userInfo: ocId, serverUrl, account diff --git a/iOSClient/Networking/NCNetworking+Upload.swift b/iOSClient/Networking/NCNetworking+Upload.swift index a645e8d1b0..56061a31a7 100644 --- a/iOSClient/Networking/NCNetworking+Upload.swift +++ b/iOSClient/Networking/NCNetworking+Upload.swift @@ -432,17 +432,16 @@ extension NCNetworking { })) // Select UIWindowScene active in serverUrl - var mainTabBarController = UIApplication.shared.firstWindow?.rootViewController + var controller = UIApplication.shared.firstWindow?.rootViewController let windowScenes = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene } for windowScene in windowScenes { if let rootViewController = windowScene.keyWindow?.rootViewController as? NCMainTabBarController, rootViewController.currentServerUrl() == metadata.serverUrl { - mainTabBarController = rootViewController + controller = rootViewController break } } - - mainTabBarController?.present(alertController, animated: true) + controller?.present(alertController, animated: true) // Client Diagnostic NCManageDatabase.shared.addDiagnostic(account: metadata.account, issue: NCGlobal.shared.diagnosticIssueProblems, error: NCGlobal.shared.diagnosticProblemsForbidden) diff --git a/iOSClient/Networking/NCNetworking+WebDAV.swift b/iOSClient/Networking/NCNetworking+WebDAV.swift index 09e0f76cf5..56733b41c8 100644 --- a/iOSClient/Networking/NCNetworking+WebDAV.swift +++ b/iOSClient/Networking/NCNetworking+WebDAV.swift @@ -395,7 +395,7 @@ extension NCNetworking { func deleteMetadataPlain(_ metadata: tableMetadata, customHeader: [String: String]? = nil) async -> NKError { // verify permission - let permission = utility.permissionsContainsString(metadata.permissions, permissions: NCGlobal.shared.permissionCanDelete) + let permission = utility.permissionsContainsString(metadata.permissions, permissions: NCPermissions().permissionCanDelete) if !metadata.permissions.isEmpty && permission == false { return NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_no_permission_delete_file_") } @@ -479,7 +479,7 @@ extension NCNetworking { indexPath: IndexPath, completion: @escaping (_ error: NKError) -> Void) { - let permission = utility.permissionsContainsString(metadata.permissions, permissions: NCGlobal.shared.permissionCanRename) + let permission = utility.permissionsContainsString(metadata.permissions, permissions: NCPermissions().permissionCanRename) if !metadata.permissions.isEmpty && !permission { return completion(NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_no_permission_modify_file_")) } @@ -539,7 +539,7 @@ extension NCNetworking { private func moveMetadataPlain(_ metadata: tableMetadata, serverUrlTo: String, overwrite: Bool) async -> NKError { - let permission = utility.permissionsContainsString(metadata.permissions, permissions: NCGlobal.shared.permissionCanRename) + let permission = utility.permissionsContainsString(metadata.permissions, permissions: NCPermissions().permissionCanRename) if !metadata.permissions.isEmpty && !permission { return NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_no_permission_modify_file_") } @@ -588,7 +588,7 @@ extension NCNetworking { private func copyMetadataPlain(_ metadata: tableMetadata, serverUrlTo: String, overwrite: Bool) async -> NKError { - let permission = utility.permissionsContainsString(metadata.permissions, permissions: NCGlobal.shared.permissionCanRename) + let permission = utility.permissionsContainsString(metadata.permissions, permissions: NCPermissions().permissionCanRename) if !metadata.permissions.isEmpty && !permission { return NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_no_permission_modify_file_") } diff --git a/iOSClient/Networking/NCNetworking.swift b/iOSClient/Networking/NCNetworking.swift index 037bc93c86..79dacea174 100644 --- a/iOSClient/Networking/NCNetworking.swift +++ b/iOSClient/Networking/NCNetworking.swift @@ -167,7 +167,6 @@ class NCNetworking: NSObject, NKCommonDelegate { // MARK: - Communication Delegate func networkReachabilityObserver(_ typeReachability: NKCommon.TypeReachability) { - if typeReachability == NKCommon.TypeReachability.reachableCellular || typeReachability == NKCommon.TypeReachability.reachableEthernetOrWiFi { if !lastReachability { #if !EXTENSION @@ -194,7 +193,6 @@ class NCNetworking: NSObject, NKCommonDelegate { } func urlSessionDidFinishEvents(forBackgroundURLSession session: URLSession) { - #if !EXTENSION if let appDelegate = UIApplication.shared.delegate as? AppDelegate, let completionHandler = appDelegate.backgroundSessionCompletionHandler { NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] Called urlSessionDidFinishEvents for Background URLSession") @@ -231,19 +229,20 @@ class NCNetworking: NSObject, NKCommonDelegate { public func checkTrustedChallenge(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) { - let protectionSpace: URLProtectionSpace = challenge.protectionSpace let directoryCertificate = utilityFileSystem.directoryCertificates let host = challenge.protectionSpace.host let certificateSavedPath = directoryCertificate + "/" + host + ".der" var isTrusted: Bool - if let serverTrust: SecTrust = protectionSpace.serverTrust, let certificate = SecTrustGetCertificateAtIndex(serverTrust, 0) { + if let trust: SecTrust = protectionSpace.serverTrust, + let certificates = (SecTrustCopyCertificateChain(trust) as? [SecCertificate]), + let certificate = certificates.first { // extarct certificate txt saveX509Certificate(certificate, host: host, directoryCertificate: directoryCertificate) - let isServerTrusted = SecTrustEvaluateWithError(serverTrust, nil) + let isServerTrusted = SecTrustEvaluateWithError(trust, nil) let certificateCopyData = SecCertificateCopyData(certificate) let data = CFDataGetBytePtr(certificateCopyData) let size = CFDataGetLength(certificateCopyData) @@ -273,7 +272,6 @@ class NCNetworking: NSObject, NKCommonDelegate { } func writeCertificate(host: String) { - let directoryCertificate = utilityFileSystem.directoryCertificates let certificateAtPath = directoryCertificate + "/" + host + ".tmp" let certificateToPath = directoryCertificate + "/" + host + ".der" @@ -284,7 +282,6 @@ class NCNetworking: NSObject, NKCommonDelegate { } func saveX509Certificate(_ certificate: SecCertificate, host: String, directoryCertificate: String) { - let certNamePathTXT = directoryCertificate + "/" + host + ".txt" let data: CFData = SecCertificateCopyData(certificate) let mem = BIO_new_mem_buf(CFDataGetBytePtr(data), Int32(CFDataGetLength(data))) @@ -314,7 +311,6 @@ class NCNetworking: NSObject, NKCommonDelegate { func checkPushNotificationServerProxyCertificateUntrusted(viewController: UIViewController?, completion: @escaping (_ error: NKError) -> Void) { - guard let host = URL(string: NCBrandOptions.shared.pushNotificationServerProxy)?.host else { return } NextcloudKit.shared.checkServer(serverUrl: NCBrandOptions.shared.pushNotificationServerProxy) { error in diff --git a/iOSClient/Networking/NCNetworkingProcess.swift b/iOSClient/Networking/NCNetworkingProcess.swift index 2972dba536..75211e27ad 100644 --- a/iOSClient/Networking/NCNetworkingProcess.swift +++ b/iOSClient/Networking/NCNetworkingProcess.swift @@ -93,7 +93,7 @@ class NCNetworkingProcess: NSObject { @discardableResult func start(scene: UIScene?) async -> (counterDownloading: Int, counterUploading: Int) { self.pauseProcess = true - let hudView = await SceneManager.shared.getMainTabBarController(scene: scene)?.view + let hudView = await SceneManager.shared.getController(scene: scene)?.view let applicationState = await UIApplication.shared.applicationState let maxConcurrentOperationDownload = NCBrandOptions.shared.maxConcurrentOperationDownload var maxConcurrentOperationUpload = NCBrandOptions.shared.maxConcurrentOperationUpload diff --git a/iOSClient/Scan document/NCDocumentCamera.swift b/iOSClient/Scan document/NCDocumentCamera.swift index 05aa051ff5..4d1432ff1a 100644 --- a/iOSClient/Scan document/NCDocumentCamera.swift +++ b/iOSClient/Scan document/NCDocumentCamera.swift @@ -63,11 +63,11 @@ class NCDocumentCamera: NSObject, VNDocumentCameraViewControllerDelegate { controller.dismiss(animated: true) { if let viewController = self.viewController as? NCScan { viewController.loadImage() - } else if let mainTabBarController = self.viewController as? NCMainTabBarController { + } else if let controller = self.viewController as? NCMainTabBarController { if let navigationController = UIStoryboard(name: "NCScan", bundle: nil).instantiateInitialViewController() { navigationController.modalPresentationStyle = UIModalPresentationStyle.pageSheet if let viewController = navigationController.topMostViewController() as? NCScan { - viewController.serverUrl = mainTabBarController.currentServerUrl() + viewController.serverUrl = controller.currentServerUrl() } self.viewController?.present(navigationController, animated: true, completion: nil) } diff --git a/iOSClient/SceneDelegate.swift b/iOSClient/SceneDelegate.swift index 913333da76..276f2a24d7 100644 --- a/iOSClient/SceneDelegate.swift +++ b/iOSClient/SceneDelegate.swift @@ -42,9 +42,9 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { #endif if NCManageDatabase.shared.getActiveAccount() != nil { - if let mainTabBarController = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController() as? NCMainTabBarController { - SceneManager.shared.register(scene: scene, withRootViewController: mainTabBarController) - window?.rootViewController = mainTabBarController + if let controller = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController() as? NCMainTabBarController { + SceneManager.shared.register(scene: scene, withRootViewController: controller) + window?.rootViewController = controller window?.makeKeyAndVisible() } } else { @@ -79,14 +79,14 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { guard !appDelegate.account.isEmpty else { return } hidePrivacyProtectionWindow() - if let window = SceneManager.shared.getWindow(scene: scene), let mainTabBarController = SceneManager.shared.getMainTabBarController(scene: scene) { - window.rootViewController = mainTabBarController + if let window = SceneManager.shared.getWindow(scene: scene), let controller = SceneManager.shared.getController(scene: scene) { + window.rootViewController = controller if NCKeychain().presentPasscode { - NCPasscode.shared.presentPasscode(viewController: mainTabBarController, delegate: self) { + NCPasscode.shared.presentPasscode(viewController: controller, delegate: self) { NCPasscode.shared.enableTouchFaceID() } } else if NCKeychain().accountRequest { - requestedAccount(viewController: mainTabBarController) + requestedAccount(viewController: controller) } } @@ -173,10 +173,10 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { } func scene(_ scene: UIScene, openURLContexts URLContexts: Set) { - guard let mainTabBarController = SceneManager.shared.getMainTabBarController(scene: scene) as? NCMainTabBarController, + guard let controller = SceneManager.shared.getController(scene: scene) as? NCMainTabBarController, let url = URLContexts.first?.url, let appDelegate else { return } - let sceneIdentifier = mainTabBarController.sceneIdentifier + let sceneIdentifier = controller.sceneIdentifier let account = appDelegate.account let scheme = url.scheme let action = url.host @@ -217,44 +217,44 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { let alertController = UIAlertController(title: NSLocalizedString("_info_", comment: ""), message: message, preferredStyle: .alert) alertController.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { _ in })) - mainTabBarController.present(alertController, animated: true, completion: { }) + controller.present(alertController, animated: true, completion: { }) return } switch actionScheme { case NCGlobal.shared.actionUploadAsset: - NCAskAuthorization().askAuthorizationPhotoLibrary(viewController: mainTabBarController) { hasPermission in + NCAskAuthorization().askAuthorizationPhotoLibrary(viewController: controller) { hasPermission in if hasPermission { - NCPhotosPickerViewController(mainTabBarController: mainTabBarController, maxSelectedAssets: 0, singleSelectedMode: false) + NCPhotosPickerViewController(controller: controller, maxSelectedAssets: 0, singleSelectedMode: false) } } case NCGlobal.shared.actionScanDocument: - NCDocumentCamera.shared.openScannerDocument(viewController: mainTabBarController) + NCDocumentCamera.shared.openScannerDocument(viewController: controller) case NCGlobal.shared.actionTextDocument: let directEditingCreators = NCManageDatabase.shared.getDirectEditingCreators(account: appDelegate.account) let directEditingCreator = directEditingCreators!.first(where: { $0.editor == NCGlobal.shared.editorText})! - let serverUrl = mainTabBarController.currentServerUrl() + let serverUrl = controller.currentServerUrl() Task { let fileName = await NCNetworking.shared.createFileName(fileNameBase: NSLocalizedString("_untitled_", comment: "") + ".md", account: appDelegate.account, serverUrl: serverUrl) let fileNamePath = NCUtilityFileSystem().getFileNamePath(String(describing: fileName), serverUrl: serverUrl, urlBase: appDelegate.urlBase, userId: appDelegate.userId) - self.appDelegate?.createTextDocument(mainTabBarController: mainTabBarController, fileNamePath: fileNamePath, fileName: String(describing: fileName), creatorId: directEditingCreator.identifier) + self.appDelegate?.createTextDocument(controller: controller, fileNamePath: fileNamePath, fileName: String(describing: fileName), creatorId: directEditingCreator.identifier) } case NCGlobal.shared.actionVoiceMemo: - NCAskAuthorization().askAuthorizationAudioRecord(viewController: mainTabBarController) { hasPermission in + NCAskAuthorization().askAuthorizationAudioRecord(viewController: controller) { hasPermission in if hasPermission { if let viewController = UIStoryboard(name: "NCAudioRecorderViewController", bundle: nil).instantiateInitialViewController() as? NCAudioRecorderViewController { - viewController.serverUrl = mainTabBarController.currentServerUrl() + viewController.serverUrl = controller.currentServerUrl() viewController.modalTransitionStyle = .crossDissolve viewController.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext - mainTabBarController.present(viewController, animated: true, completion: nil) + controller.present(viewController, animated: true, completion: nil) } } } @@ -288,7 +288,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { let alertController = UIAlertController(title: NSLocalizedString("_info_", comment: ""), message: message, preferredStyle: .alert) alertController.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { _ in })) - mainTabBarController.present(alertController, animated: true, completion: { }) + controller.present(alertController, animated: true, completion: { }) return } @@ -393,49 +393,49 @@ extension SceneDelegate: NCAccountRequestDelegate { class SceneManager { static let shared = SceneManager() - private var sceneMainTabBarController: [NCMainTabBarController: UIScene] = [:] + private var sceneController: [NCMainTabBarController: UIScene] = [:] func register(scene: UIScene, withRootViewController rootViewController: NCMainTabBarController) { - sceneMainTabBarController[rootViewController] = scene + sceneController[rootViewController] = scene } - func getMainTabBarController(scene: UIScene?) -> UIViewController? { - for mainTabBarController in sceneMainTabBarController.keys { - if sceneMainTabBarController[mainTabBarController] == scene { - return mainTabBarController + func getController(scene: UIScene?) -> UIViewController? { + for controller in sceneController.keys { + if sceneController[controller] == scene { + return controller } } return nil } - func getMainTabBarController(sceneIdentifier: String) -> NCMainTabBarController? { - for mainTabBarController in sceneMainTabBarController.keys { - if sceneIdentifier == mainTabBarController.sceneIdentifier { - return mainTabBarController + func getController(sceneIdentifier: String) -> NCMainTabBarController? { + for controller in sceneController.keys { + if sceneIdentifier == controller.sceneIdentifier { + return controller } } return nil } + func getControllers() -> [NCMainTabBarController] { + return Array(sceneController.keys) + } + func getWindow(scene: UIScene?) -> UIWindow? { return (scene as? UIWindowScene)?.keyWindow } func getWindow(controller: NCMainTabBarController?) -> UIWindow? { guard let controller, - let scene = sceneMainTabBarController[controller] else { return nil } + let scene = sceneController[controller] else { return nil } return getWindow(scene: scene) } func getSceneIdentifier() -> [String] { var results: [String] = [] - for mainTabBarController in sceneMainTabBarController.keys { - results.append(mainTabBarController.sceneIdentifier) + for controller in sceneController.keys { + results.append(controller.sceneIdentifier) } return results } - - func getAllMainTabBarController() -> [NCMainTabBarController] { - return Array(sceneMainTabBarController.keys) - } } diff --git a/iOSClient/Select/NCSelect.swift b/iOSClient/Select/NCSelect.swift index bcb5dd89e8..fdb8af35b2 100644 --- a/iOSClient/Select/NCSelect.swift +++ b/iOSClient/Select/NCSelect.swift @@ -297,14 +297,14 @@ extension NCSelect: UICollectionViewDataSource { } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "listCell", for: indexPath) as? NCListCell, let metadata = dataSource.cellForItemAt(indexPath: indexPath) else { return UICollectionViewCell() } var isShare = false var isMounted = false + let permissions = NCPermissions() - isShare = metadata.permissions.contains(NCGlobal.shared.permissionShared) && !metadataFolder.permissions.contains(NCGlobal.shared.permissionShared) - isMounted = metadata.permissions.contains(NCGlobal.shared.permissionMounted) && !metadataFolder.permissions.contains(NCGlobal.shared.permissionMounted) + isShare = metadata.permissions.contains(permissions.permissionShared) && !metadataFolder.permissions.contains(permissions.permissionShared) + isMounted = metadata.permissions.contains(permissions.permissionMounted) && !metadataFolder.permissions.contains(permissions.permissionMounted) cell.listCellDelegate = self diff --git a/iOSClient/Share/Advanced/NCShareAdvancePermission.swift b/iOSClient/Share/Advanced/NCShareAdvancePermission.swift index 1406d7096f..56430fa914 100644 --- a/iOSClient/Share/Advanced/NCShareAdvancePermission.swift +++ b/iOSClient/Share/Advanced/NCShareAdvancePermission.swift @@ -136,7 +136,7 @@ class NCShareAdvancePermission: UITableViewController, NCShareAdvanceFotterDeleg override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { if section == 0 { // check reshare permission, if restricted add note - let maxPermission = metadata.directory ? NCGlobal.shared.permissionMaxFolderShare : NCGlobal.shared.permissionMaxFileShare + let maxPermission = metadata.directory ? NCPermissions().permissionMaxFolderShare : NCPermissions().permissionMaxFileShare return shareConfig.resharePermission != maxPermission ? shareConfig.permissions.count + 1 : shareConfig.permissions.count } else if section == 1 { return shareConfig.advanced.count diff --git a/iOSClient/Share/Advanced/NCShareCells.swift b/iOSClient/Share/Advanced/NCShareCells.swift index e45c75da4c..d1f5d23aba 100644 --- a/iOSClient/Share/Advanced/NCShareCells.swift +++ b/iOSClient/Share/Advanced/NCShareCells.swift @@ -64,11 +64,11 @@ enum NCUserPermission: CaseIterable, NCPermission { var permissionBitFlag: Int { switch self { - case .reshare: return NCGlobal.shared.permissionShareShare - case .edit: return NCGlobal.shared.permissionUpdateShare - case .create: return NCGlobal.shared.permissionCreateShare - case .delete: return NCGlobal.shared.permissionDeleteShare - case .download: return NCGlobal.shared.permissionDownloadShare + case .reshare: return NCPermissions().permissionShareShare + case .edit: return NCPermissions().permissionUpdateShare + case .create: return NCPermissions().permissionCreateShare + case .delete: return NCPermissions().permissionDeleteShare + case .download: return NCPermissions().permissionDownloadShare } } @@ -108,7 +108,7 @@ enum NCLinkPermission: NCPermission { func didChange(_ share: NCTableShareable, to newValue: Bool) { guard self != .allowEdit || newValue else { - share.permissions = NCGlobal.shared.permissionReadShare + share.permissions = NCPermissions().permissionReadShare return } share.permissions = permissionValue @@ -125,45 +125,46 @@ enum NCLinkPermission: NCPermission { var permissionValue: Int { switch self { case .allowEdit: - return CCUtility.getPermissionsValue( - byCanEdit: true, - andCanCreate: true, - andCanChange: true, - andCanDelete: true, - andCanShare: false, - andIsFolder: false) + return NCPermissions().getPermission( + canEdit: true, + canCreate: true, + canChange: true, + canDelete: true, + canShare: false, + isDirectory: false) case .viewOnly: - return CCUtility.getPermissionsValue( - byCanEdit: false, - andCanCreate: false, - andCanChange: false, - andCanDelete: false, + return NCPermissions().getPermission( + canEdit: false, + canCreate: false, + canChange: false, + canDelete: false, // not possible to create "read-only" shares without reshare option // https://github.com/nextcloud/server/blame/f99876997a9119518fe5f7ad3a3a51d33459d4cc/apps/files_sharing/lib/Controller/ShareAPIController.php#L1104-L1107 - andCanShare: true, - andIsFolder: true) + canShare: true, + isDirectory: true) case .uploadEdit: - return CCUtility.getPermissionsValue( - byCanEdit: true, - andCanCreate: true, - andCanChange: true, - andCanDelete: true, - andCanShare: false, - andIsFolder: true) + return NCPermissions().getPermission( + canEdit: true, + canCreate: true, + canChange: true, + canDelete: true, + canShare: false, + isDirectory: true) case .fileDrop: - return NCGlobal.shared.permissionCreateShare + return NCPermissions().permissionCreateShare case .secureFileDrop: - return NCGlobal.shared.permissionCreateShare + return NCPermissions().permissionCreateShare } } func isOn(for share: NCTableShareable) -> Bool { + let permissions = NCPermissions() switch self { - case .allowEdit: return CCUtility.isAnyPermission(toEdit: share.permissions) - case .viewOnly: return !CCUtility.isAnyPermission(toEdit: share.permissions) && share.permissions != NCGlobal.shared.permissionCreateShare - case .uploadEdit: return CCUtility.isAnyPermission(toEdit: share.permissions) && share.permissions != NCGlobal.shared.permissionCreateShare - case .fileDrop: return share.permissions == NCGlobal.shared.permissionCreateShare - case .secureFileDrop: return share.permissions == NCGlobal.shared.permissionCreateShare + case .allowEdit: return permissions.isAnyPermissionToEdit(share.permissions) + case .viewOnly: return !permissions.isAnyPermissionToEdit(share.permissions) && share.permissions != permissions.permissionCreateShare + case .uploadEdit: return permissions.isAnyPermissionToEdit(share.permissions) && share.permissions != permissions.permissionCreateShare + case .fileDrop: return share.permissions == permissions.permissionCreateShare + case .secureFileDrop: return share.permissions == permissions.permissionCreateShare } } diff --git a/iOSClient/Share/NCPermissions.swift b/iOSClient/Share/NCPermissions.swift new file mode 100644 index 0000000000..1e7d348f49 --- /dev/null +++ b/iOSClient/Share/NCPermissions.swift @@ -0,0 +1,103 @@ +// +// NCPermissions.swift +// Nextcloud +// +// Created by Marino Faggiana on 05/06/24. +// Copyright © 2024 Marino Faggiana. All rights reserved. +// +// Author Marino Faggiana +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +import UIKit +import Foundation + +class NCPermissions: NSObject { + let permissionShared = "S" + let permissionCanShare = "R" + let permissionMounted = "M" + let permissionFileCanWrite = "W" + let permissionCanCreateFile = "C" + let permissionCanCreateFolder = "K" + let permissionCanDelete = "D" + let permissionCanRename = "N" + let permissionCanMove = "V" + + // Share permission + // permissions - (int) 1 = read; 2 = update; 4 = create; 8 = delete; 16 = share; 31 = all + // + let permissionReadShare: Int = 1 + let permissionUpdateShare: Int = 2 + let permissionCreateShare: Int = 4 + let permissionDeleteShare: Int = 8 + let permissionShareShare: Int = 16 + // + let permissionMinFileShare: Int = 1 + let permissionMaxFileShare: Int = 19 + let permissionMinFolderShare: Int = 1 + let permissionMaxFolderShare: Int = 31 + let permissionDefaultFileRemoteShareNoSupportShareOption: Int = 3 + let permissionDefaultFolderRemoteShareNoSupportShareOption: Int = 15 + // ATTRIBUTES + let permissionDownloadShare: Int = 0 + + func isPermissionToRead(_ permission: Int) -> Bool { + return ((permission & permissionReadShare) > 0) + } + func isPermissionToCanDelete(_ permission: Int) -> Bool { + return ((permission & permissionDeleteShare) > 0) + } + func isPermissionToCanCreate(_ permission: Int) -> Bool { + return ((permission & permissionCreateShare) > 0) + } + func isPermissionToCanChange(_ permission: Int) -> Bool { + return ((permission & permissionUpdateShare) > 0) + } + func isPermissionToCanShare(_ permission: Int) -> Bool { + return ((permission & permissionShareShare) > 0) + } + func isAnyPermissionToEdit(_ permission: Int) -> Bool { + let canCreate = isPermissionToCanCreate(permission) + let canChange = isPermissionToCanChange(permission) + let canDelete = isPermissionToCanDelete(permission) + return canCreate || canChange || canDelete + } + func isPermissionToReadCreateUpdate(_ permission: Int) -> Bool { + let canRead = isPermissionToRead(permission) + let canCreate = isPermissionToCanCreate(permission) + let canChange = isPermissionToCanChange(permission) + return canCreate && canChange && canRead + } + func getPermission(canEdit: Bool, canCreate: Bool, canChange: Bool, canDelete: Bool, canShare: Bool, isDirectory: Bool) -> Int { + var permission = permissionReadShare + + if canEdit && !isDirectory { + permission = permission + permissionUpdateShare + } + if canCreate && isDirectory { + permission = permission + permissionCreateShare + } + if canChange && isDirectory { + permission = permission + permissionUpdateShare + } + if canDelete && isDirectory { + permission = permission + permissionDeleteShare + } + if canShare { + permission = permission + permissionShareShare + } + return permission + } +} diff --git a/iOSClient/Share/NCShare+Helper.swift b/iOSClient/Share/NCShare+Helper.swift index 4011895a34..ac5c6ff7b1 100644 --- a/iOSClient/Share/NCShare+Helper.swift +++ b/iOSClient/Share/NCShare+Helper.swift @@ -82,7 +82,7 @@ class NCTableShareOptions: NCTableShareable { private init(shareType: Int, metadata: tableMetadata, password: String?) { if metadata.e2eEncrypted && NCGlobal.shared.capabilityE2EEApiVersion == NCGlobal.shared.e2eeVersionV12 { - self.permissions = NCGlobal.shared.permissionCreateShare + self.permissions = NCPermissions().permissionCreateShare } else { self.permissions = NCGlobal.shared.capabilityFileSharingDefaultPermission & metadata.sharePermissionsCollaborationServices } diff --git a/iOSClient/Share/NCShare+NCCellDelegate.swift b/iOSClient/Share/NCShare+NCCellDelegate.swift index b32d710623..011fd17291 100644 --- a/iOSClient/Share/NCShare+NCCellDelegate.swift +++ b/iOSClient/Share/NCShare+NCCellDelegate.swift @@ -63,7 +63,7 @@ extension NCShare: NCShareLinkCellDelegate, NCShareUserCellDelegate { func quickStatus(with tableShare: tableShare?, sender: Any) { guard let tableShare = tableShare, let metadata = metadata, - tableShare.shareType != NCGlobal.shared.permissionDefaultFileRemoteShareNoSupportShareOption else { return } + tableShare.shareType != NCPermissions().permissionDefaultFileRemoteShareNoSupportShareOption else { return } self.toggleUserPermissionMenu(isDirectory: metadata.directory, tableShare: tableShare) } } diff --git a/iOSClient/Share/NCShare.swift b/iOSClient/Share/NCShare.swift index 978dda0b5e..477a1ced20 100644 --- a/iOSClient/Share/NCShare.swift +++ b/iOSClient/Share/NCShare.swift @@ -56,7 +56,7 @@ class NCShare: UIViewController, NCShareNetworkingDelegate, NCSharePagingContent var canReshare: Bool { guard let metadata = metadata else { return true } - return ((metadata.sharePermissionsCollaborationServices & NCGlobal.shared.permissionShareShare) != 0) + return ((metadata.sharePermissionsCollaborationServices & NCPermissions().permissionShareShare) != 0) } var shares: (firstShareLink: tableShare?, share: [tableShare]?) = (nil, nil) diff --git a/iOSClient/Share/NCShareUserCell.swift b/iOSClient/Share/NCShareUserCell.swift index a022e01b44..842707301f 100644 --- a/iOSClient/Share/NCShareUserCell.swift +++ b/iOSClient/Share/NCShareUserCell.swift @@ -61,7 +61,7 @@ class NCShareUserCell: UITableViewCell, NCCellProtocol { name: NSLocalizedString("_show_profile_", comment: ""), target: self, selector: #selector(tapAvatarImage))] - + let permissions = NCPermissions() labelTitle.text = tableShare.shareWithDisplayname labelTitle.textColor = NCBrandColor.shared.textColor isUserInteractionEnabled = true @@ -87,11 +87,11 @@ class NCShareUserCell: UITableViewCell, NCCellProtocol { btnQuickStatus.setTitle("", for: .normal) btnQuickStatus.contentHorizontalAlignment = .left - if tableShare.permissions == NCGlobal.shared.permissionCreateShare { + if tableShare.permissions == permissions.permissionCreateShare { labelQuickStatus.text = NSLocalizedString("_share_file_drop_", comment: "") } else { // Read Only - if CCUtility.isAnyPermission(toEdit: tableShare.permissions) { + if permissions.isAnyPermissionToEdit(tableShare.permissions) { labelQuickStatus.text = NSLocalizedString("_share_editing_", comment: "") } else { labelQuickStatus.text = NSLocalizedString("_share_read_only_", comment: "") diff --git a/iOSClient/Utility/CCUtility.h b/iOSClient/Utility/CCUtility.h index 31a65483e4..767cbab1af 100644 --- a/iOSClient/Utility/CCUtility.h +++ b/iOSClient/Utility/CCUtility.h @@ -37,19 +37,4 @@ + (NSString *)createFileName:(NSString *)fileName fileDate:(NSDate *)fileDate fileType:(PHAssetMediaType)fileType keyFileName:(NSString *)keyFileName keyFileNameType:(NSString *)keyFileNameType keyFileNameOriginal:(NSString *)keyFileNameOriginal forcedNewFileName:(BOOL)forcedNewFileName; + (NSString *)getMimeType:(NSString *)fileNameView; -// ===== Share Permissions ===== - -+ (NSInteger)getPermissionsValueByCanEdit:(BOOL)canEdit andCanCreate:(BOOL)canCreate andCanChange:(BOOL)canChange andCanDelete:(BOOL)canDelete andCanShare:(BOOL)canShare andIsFolder:(BOOL) isFolder; -+ (BOOL)isPermissionToCanCreate:(NSInteger) permissionValue; -+ (BOOL)isPermissionToCanChange:(NSInteger) permissionValue; -+ (BOOL)isPermissionToCanDelete:(NSInteger) permissionValue; -+ (BOOL)isPermissionToCanShare:(NSInteger) permissionValue; -+ (BOOL)isAnyPermissionToEdit:(NSInteger) permissionValue; -+ (BOOL)isPermissionToRead:(NSInteger) permissionValue; -+ (BOOL)isPermissionToReadCreateUpdate:(NSInteger) permissionValue; - -// ===== Third parts ===== - -+ (NSDate *)getATime:(const char *)path; - @end diff --git a/iOSClient/Utility/CCUtility.m b/iOSClient/Utility/CCUtility.m index fd09123fa5..13bfc0a68c 100644 --- a/iOSClient/Utility/CCUtility.m +++ b/iOSClient/Utility/CCUtility.m @@ -159,96 +159,4 @@ + (NSString *)getMimeType:(NSString *)fileNameView return returnFileUTI; } - -#pragma -------------------------------------------------------------------------------------------- -#pragma mark ===== Share Permissions ===== -#pragma -------------------------------------------------------------------------------------------- - -+ (NSInteger) getPermissionsValueByCanEdit:(BOOL)canEdit andCanCreate:(BOOL)canCreate andCanChange:(BOOL)canChange andCanDelete:(BOOL)canDelete andCanShare:(BOOL)canShare andIsFolder:(BOOL) isFolder -{ - NSInteger permissionsValue = NCGlobal.shared.permissionReadShare; - - if (canEdit && !isFolder) { - permissionsValue = permissionsValue + NCGlobal.shared.permissionUpdateShare; - } - if (canCreate & isFolder) { - permissionsValue = permissionsValue + NCGlobal.shared.permissionCreateShare; - } - if (canChange && isFolder) { - permissionsValue = permissionsValue + NCGlobal.shared.permissionUpdateShare; - } - if (canDelete & isFolder) { - permissionsValue = permissionsValue + NCGlobal.shared.permissionDeleteShare; - } - if (canShare) { - permissionsValue = permissionsValue + NCGlobal.shared.permissionShareShare; - } - - return permissionsValue; -} - -+ (BOOL) isPermissionToCanCreate:(NSInteger) permissionValue { - BOOL canCreate = ((permissionValue & NCGlobal.shared.permissionCreateShare) > 0); - return canCreate; -} - -+ (BOOL) isPermissionToCanChange:(NSInteger) permissionValue { - BOOL canChange = ((permissionValue & NCGlobal.shared.permissionUpdateShare) > 0); - return canChange; -} - -+ (BOOL) isPermissionToCanDelete:(NSInteger) permissionValue { - BOOL canDelete = ((permissionValue & NCGlobal.shared.permissionDeleteShare) > 0); - return canDelete; -} - -+ (BOOL) isPermissionToCanShare:(NSInteger) permissionValue { - BOOL canShare = ((permissionValue & NCGlobal.shared.permissionShareShare) > 0); - return canShare; -} - -+ (BOOL) isAnyPermissionToEdit:(NSInteger) permissionValue { - - BOOL canCreate = [self isPermissionToCanCreate:permissionValue]; - BOOL canChange = [self isPermissionToCanChange:permissionValue]; - BOOL canDelete = [self isPermissionToCanDelete:permissionValue]; - - - BOOL canEdit = (canCreate || canChange || canDelete); - - return canEdit; - -} - -+ (BOOL) isPermissionToRead:(NSInteger) permissionValue { - BOOL canRead = ((permissionValue & NCGlobal.shared.permissionReadShare) > 0); - return canRead; -} - -+ (BOOL) isPermissionToReadCreateUpdate:(NSInteger) permissionValue { - - BOOL canRead = [self isPermissionToRead:permissionValue]; - BOOL canCreate = [self isPermissionToCanCreate:permissionValue]; - BOOL canChange = [self isPermissionToCanChange:permissionValue]; - - - BOOL canEdit = (canCreate && canChange && canRead); - - return canEdit; - -} - -#pragma -------------------------------------------------------------------------------------------- -#pragma mark ===== Third parts ===== -#pragma -------------------------------------------------------------------------------------------- - - -+ (NSDate *)getATime:(const char *)path -{ - struct stat st; - stat(path, &st); - time_t accessed = st.st_atime; - NSDate *date = [NSDate dateWithTimeIntervalSince1970:accessed]; - return date; -} @end diff --git a/iOSClient/Utility/NCLivePhoto.swift b/iOSClient/Utility/NCLivePhoto.swift index e59812d3e1..9695ff2e86 100644 --- a/iOSClient/Utility/NCLivePhoto.swift +++ b/iOSClient/Utility/NCLivePhoto.swift @@ -11,6 +11,7 @@ import AVFoundation import MobileCoreServices import Photos import NextcloudKit +import UniformTypeIdentifiers class NCLivePhoto { @@ -157,27 +158,20 @@ class NCLivePhoto { } private func saveAssetResource(_ resource: PHAssetResource, to directory: URL, resourceData: Data) -> URL? { - let fileExtension = UTTypeCopyPreferredTagWithClass(resource.uniformTypeIdentifier as CFString, kUTTagClassFilenameExtension)?.takeRetainedValue() - - guard let ext = fileExtension else { - return nil - } - + guard let ext = UTType(tag: resource.uniformTypeIdentifier, tagClass: .filenameExtension, conformingTo: nil)?.identifier else { return nil } var fileUrl = directory.appendingPathComponent(NSUUID().uuidString) fileUrl = fileUrl.appendingPathExtension(ext as String) - do { try resourceData.write(to: fileUrl, options: [Data.WritingOptions.atomic]) } catch { print("Could not save resource \(resource) to filepath \(String(describing: fileUrl))") return nil } - return fileUrl } func addAssetID(_ assetIdentifier: String, toImage imageURL: URL, saveTo destinationURL: URL) -> URL? { - guard let imageDestination = CGImageDestinationCreateWithURL(destinationURL as CFURL, kUTTypeJPEG, 1, nil), + guard let imageDestination = CGImageDestinationCreateWithURL(destinationURL as CFURL, UTType.jpeg.identifier as CFString, 1, nil), let imageSource = CGImageSourceCreateWithURL(imageURL as CFURL, nil), var imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil) as? [AnyHashable: Any] else { return nil } let assetIdentifierKey = "17" diff --git a/iOSClient/Utility/NCStoreReview.swift b/iOSClient/Utility/NCStoreReview.swift index 69d8105d64..d41da1ed5e 100644 --- a/iOSClient/Utility/NCStoreReview.swift +++ b/iOSClient/Utility/NCStoreReview.swift @@ -25,38 +25,33 @@ import UIKit import StoreKit class NCStoreReview: NSObject { - let runIncrementerSetting = "numberOfRuns" let minimumRunCount = 5 func getRunCounts () -> Int { - let uDefaults = UserDefaults() let savedRuns = uDefaults.value(forKey: runIncrementerSetting) - var runs = 0 if savedRuns != nil { runs = savedRuns as? Int ?? 0 } - print("Nextcloud iOS run Counts are \(runs)") return runs } - @objc func incrementAppRuns() { - + func incrementAppRuns() { let uDefaults = UserDefaults() let runs = getRunCounts() + 1 uDefaults.setValuesForKeys([runIncrementerSetting: runs]) uDefaults.synchronize() } - @objc func showStoreReview() { - + func showStoreReview() { let runs = getRunCounts() - if runs > minimumRunCount { - SKStoreReviewController.requestReview() + if runs > minimumRunCount, + let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene { + SKStoreReviewController.requestReview(in: windowScene) } } } diff --git a/iOSClient/Viewer/NCViewer.swift b/iOSClient/Viewer/NCViewer.swift index 87e7eefdcd..957ae370f2 100644 --- a/iOSClient/Viewer/NCViewer.swift +++ b/iOSClient/Viewer/NCViewer.swift @@ -235,8 +235,8 @@ class NCViewer: NSObject { viewController.present(viewerQuickLook, animated: true) } else { // Document Interaction Controller - if let mainTabBarController = viewController.tabBarController as? NCMainTabBarController { - NCActionCenter.shared.openDocumentController(metadata: metadata, mainTabBarController: mainTabBarController) + if let controller = viewController.tabBarController as? NCMainTabBarController { + NCActionCenter.shared.openDocumentController(metadata: metadata, controller: controller) } } }