diff --git a/Nextcloud.xcodeproj/project.pbxproj b/Nextcloud.xcodeproj/project.pbxproj index 8dd4c5545f..bc45aa6008 100644 --- a/Nextcloud.xcodeproj/project.pbxproj +++ b/Nextcloud.xcodeproj/project.pbxproj @@ -85,6 +85,32 @@ AFCE353527E4ED5900FEA6C2 /* DateFormatter+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFCE353427E4ED5900FEA6C2 /* DateFormatter+Extension.swift */; }; AFCE353727E4ED7B00FEA6C2 /* NCShareCells.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFCE353627E4ED7B00FEA6C2 /* NCShareCells.swift */; }; AFCE353927E5DE0500FEA6C2 /* Shareable.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFCE353827E5DE0400FEA6C2 /* Shareable.swift */; }; + AFCE353927E5DE0500FEA6C2 /* NCShare+Helper.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFCE353827E5DE0400FEA6C2 /* NCShare+Helper.swift */; }; + B5BEBD192E93A5260002C9E5 /* Shareable.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5BEBD182E93A5260002C9E5 /* Shareable.swift */; }; + B5BEBD1E2E93A74C0002C9E5 /* CreateLinkFooterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5BEBD1A2E93A74C0002C9E5 /* CreateLinkFooterView.swift */; }; + B5BEBD1F2E93A74C0002C9E5 /* NCPermissions.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5BEBD1B2E93A74C0002C9E5 /* NCPermissions.swift */; }; + B5BEBD202E93A74C0002C9E5 /* NCShareEmailLinkHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5BEBD1C2E93A74C0002C9E5 /* NCShareEmailLinkHeaderView.swift */; }; + B5BEBD212E93A74C0002C9E5 /* NoSharesFooterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5BEBD1D2E93A74C0002C9E5 /* NoSharesFooterView.swift */; }; + B5BEBD222E93A74C0002C9E5 /* CreateLinkFooterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5BEBD1A2E93A74C0002C9E5 /* CreateLinkFooterView.swift */; }; + B5BEBD232E93A74C0002C9E5 /* NCPermissions.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5BEBD1B2E93A74C0002C9E5 /* NCPermissions.swift */; }; + B5BEBD242E93A74C0002C9E5 /* NCShareEmailLinkHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5BEBD1C2E93A74C0002C9E5 /* NCShareEmailLinkHeaderView.swift */; }; + B5BEBD252E93A74C0002C9E5 /* NoSharesFooterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5BEBD1D2E93A74C0002C9E5 /* NoSharesFooterView.swift */; }; + B5E2E6D42DAE52B500AB2EDD /* SharingTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E2E6D32DAE52B500AB2EDD /* SharingTest.swift */; }; + B5E2E6D72DAE571200AB2EDD /* PasswordInputField.xib in Resources */ = {isa = PBXBuildFile; fileRef = B5E2E6D62DAE571200AB2EDD /* PasswordInputField.xib */; }; + B5E2E6D82DAE571200AB2EDD /* PasswordInputField.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E2E6D52DAE571200AB2EDD /* PasswordInputField.swift */; }; + B5E2E6DD2DAE573B00AB2EDD /* NCFilePermissionEditCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = B5E2E6DC2DAE573B00AB2EDD /* NCFilePermissionEditCell.xib */; }; + B5E2E6DE2DAE573B00AB2EDD /* NCFilePermissionCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = B5E2E6DA2DAE573B00AB2EDD /* NCFilePermissionCell.xib */; }; + B5E2E6DF2DAE573B00AB2EDD /* NCFilePermissionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E2E6D92DAE573B00AB2EDD /* NCFilePermissionCell.swift */; }; + B5E2E6E02DAE573B00AB2EDD /* NCFilePermissionEditCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E2E6DB2DAE573B00AB2EDD /* NCFilePermissionEditCell.swift */; }; + B5E2E6E22DAE59CD00AB2EDD /* NCShareAdvancePermissionHeader.xib in Resources */ = {isa = PBXBuildFile; fileRef = B5E2E6E12DAE59CD00AB2EDD /* NCShareAdvancePermissionHeader.xib */; }; + B5E2E6E72DAE59F000AB2EDD /* NCShareHeaderCustomCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = B5E2E6E42DAE59F000AB2EDD /* NCShareHeaderCustomCell.xib */; }; + B5E2E6E82DAE59F000AB2EDD /* NCShareTextInputCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = B5E2E6E62DAE59F000AB2EDD /* NCShareTextInputCell.xib */; }; + B5E2E6E92DAE59F000AB2EDD /* NCShareTextInputCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E2E6E52DAE59F000AB2EDD /* NCShareTextInputCell.swift */; }; + B5E2E6EA2DAE59F000AB2EDD /* NCShareHeaderCustomCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E2E6E32DAE59F000AB2EDD /* NCShareHeaderCustomCell.swift */; }; + B5E2E6ED2DAE66AF00AB2EDD /* NCShareEmailFieldCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = B5E2E6EC2DAE66AF00AB2EDD /* NCShareEmailFieldCell.xib */; }; + B5E2E6EE2DAE66AF00AB2EDD /* NCShareEmailFieldCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E2E6EB2DAE66AF00AB2EDD /* NCShareEmailFieldCell.swift */; }; + B5E2E6F02DAE6E3F00AB2EDD /* ShareDownloadLimitNetwork.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E2E6EF2DAE6E3F00AB2EDD /* ShareDownloadLimitNetwork.swift */; }; + D575039F27146F93008DC9DC /* String+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7A0D1342591FBC5008F8A13 /* String+Extension.swift */; }; D5B6AA7827200C7200D49C24 /* NCActivityTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5B6AA7727200C7200D49C24 /* NCActivityTableViewCell.swift */; }; F310B1EF2BA862F1001C42F5 /* NCViewerMedia+VisionKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = F310B1EE2BA862F1001C42F5 /* NCViewerMedia+VisionKit.swift */; }; F321DA8A2B71205A00DDA0E6 /* NCTrashSelectTabBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = F321DA892B71205A00DDA0E6 /* NCTrashSelectTabBar.swift */; }; @@ -1220,7 +1246,27 @@ AFCE353227E4ED1900FEA6C2 /* UIToolbar+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIToolbar+Extension.swift"; sourceTree = ""; }; AFCE353427E4ED5900FEA6C2 /* DateFormatter+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DateFormatter+Extension.swift"; sourceTree = ""; }; AFCE353627E4ED7B00FEA6C2 /* NCShareCells.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCShareCells.swift; sourceTree = ""; }; - AFCE353827E5DE0400FEA6C2 /* Shareable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Shareable.swift; sourceTree = ""; }; + AFCE353827E5DE0400FEA6C2 /* NCShare+Helper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCShare+Helper.swift"; sourceTree = ""; }; + B5BEBD182E93A5260002C9E5 /* Shareable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Shareable.swift; sourceTree = ""; }; + B5BEBD1A2E93A74C0002C9E5 /* CreateLinkFooterView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateLinkFooterView.swift; sourceTree = ""; }; + B5BEBD1B2E93A74C0002C9E5 /* NCPermissions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCPermissions.swift; sourceTree = ""; }; + B5BEBD1C2E93A74C0002C9E5 /* NCShareEmailLinkHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCShareEmailLinkHeaderView.swift; sourceTree = ""; }; + B5BEBD1D2E93A74C0002C9E5 /* NoSharesFooterView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoSharesFooterView.swift; sourceTree = ""; }; + B5E2E6D32DAE52B500AB2EDD /* SharingTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SharingTest.swift; sourceTree = ""; }; + B5E2E6D52DAE571200AB2EDD /* PasswordInputField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PasswordInputField.swift; sourceTree = ""; }; + B5E2E6D62DAE571200AB2EDD /* PasswordInputField.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = PasswordInputField.xib; sourceTree = ""; }; + B5E2E6D92DAE573B00AB2EDD /* NCFilePermissionCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCFilePermissionCell.swift; sourceTree = ""; }; + B5E2E6DA2DAE573B00AB2EDD /* NCFilePermissionCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NCFilePermissionCell.xib; sourceTree = ""; }; + B5E2E6DB2DAE573B00AB2EDD /* NCFilePermissionEditCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCFilePermissionEditCell.swift; sourceTree = ""; }; + B5E2E6DC2DAE573B00AB2EDD /* NCFilePermissionEditCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NCFilePermissionEditCell.xib; sourceTree = ""; }; + B5E2E6E12DAE59CD00AB2EDD /* NCShareAdvancePermissionHeader.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NCShareAdvancePermissionHeader.xib; sourceTree = ""; }; + B5E2E6E32DAE59F000AB2EDD /* NCShareHeaderCustomCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCShareHeaderCustomCell.swift; sourceTree = ""; }; + B5E2E6E42DAE59F000AB2EDD /* NCShareHeaderCustomCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NCShareHeaderCustomCell.xib; sourceTree = ""; }; + B5E2E6E52DAE59F000AB2EDD /* NCShareTextInputCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCShareTextInputCell.swift; sourceTree = ""; }; + B5E2E6E62DAE59F000AB2EDD /* NCShareTextInputCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NCShareTextInputCell.xib; sourceTree = ""; }; + B5E2E6EB2DAE66AF00AB2EDD /* NCShareEmailFieldCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCShareEmailFieldCell.swift; sourceTree = ""; }; + B5E2E6EC2DAE66AF00AB2EDD /* NCShareEmailFieldCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NCShareEmailFieldCell.xib; sourceTree = ""; }; + B5E2E6EF2DAE6E3F00AB2EDD /* ShareDownloadLimitNetwork.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareDownloadLimitNetwork.swift; sourceTree = ""; }; C0046CDA2A17B98400D87C9D /* NextcloudUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = NextcloudUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; C04E2F202A17BB4D001BAD85 /* NextcloudIntegrationTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = NextcloudIntegrationTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; D5B6AA7727200C7200D49C24 /* NCActivityTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCActivityTableViewCell.swift; sourceTree = ""; }; @@ -2024,6 +2070,7 @@ isa = PBXGroup; children = ( AA52EB452D42AC5A0089C348 /* Placeholder.swift */, + B5E2E6D32DAE52B500AB2EDD /* SharingTest.swift */, ); path = NextcloudUnitTests; sourceTree = ""; @@ -2051,6 +2098,15 @@ isa = PBXGroup; children = ( AA8D316D2D4123B200FE2775 /* DownloadLimit */, + B5E2E6E32DAE59F000AB2EDD /* NCShareHeaderCustomCell.swift */, + B5E2E6E42DAE59F000AB2EDD /* NCShareHeaderCustomCell.xib */, + B5E2E6E52DAE59F000AB2EDD /* NCShareTextInputCell.swift */, + B5E2E6E62DAE59F000AB2EDD /* NCShareTextInputCell.xib */, + B5E2E6E12DAE59CD00AB2EDD /* NCShareAdvancePermissionHeader.xib */, + B5E2E6D92DAE573B00AB2EDD /* NCFilePermissionCell.swift */, + B5E2E6DA2DAE573B00AB2EDD /* NCFilePermissionCell.xib */, + B5E2E6DB2DAE573B00AB2EDD /* NCFilePermissionEditCell.swift */, + B5E2E6DC2DAE573B00AB2EDD /* NCFilePermissionEditCell.xib */, AF93471627E2361E002537EE /* NCShareAdvancePermission.swift */, AF93471827E2361E002537EE /* NCShareAdvancePermissionFooter.swift */, AF93471427E2361E002537EE /* NCShareAdvancePermissionFooter.xib */, @@ -2301,6 +2357,14 @@ F728CE741BF6322C00E69702 /* Share */ = { isa = PBXGroup; children = ( + B5BEBD1A2E93A74C0002C9E5 /* CreateLinkFooterView.swift */, + B5BEBD1B2E93A74C0002C9E5 /* NCPermissions.swift */, + B5BEBD1C2E93A74C0002C9E5 /* NCShareEmailLinkHeaderView.swift */, + B5BEBD1D2E93A74C0002C9E5 /* NoSharesFooterView.swift */, + B5BEBD182E93A5260002C9E5 /* Shareable.swift */, + B5E2E6EF2DAE6E3F00AB2EDD /* ShareDownloadLimitNetwork.swift */, + B5E2E6EB2DAE66AF00AB2EDD /* NCShareEmailFieldCell.swift */, + B5E2E6EC2DAE66AF00AB2EDD /* NCShareEmailFieldCell.xib */, AF93471327E235EB002537EE /* Advanced */, F724377A2C10B83E00C7C68D /* NCSharePermissions.swift */, F3F442ED2DDE292600FD701F /* NCMetadataPermissions.swift */, @@ -2322,7 +2386,7 @@ AF2D7C7D2742559100ADF566 /* NCShareUserCell.swift */, AF93471727E2361E002537EE /* NCShareHeader.xib */, AF93471527E2361E002537EE /* NCShareHeader.swift */, - AFCE353827E5DE0400FEA6C2 /* Shareable.swift */, + AFCE353827E5DE0400FEA6C2 /* NCShare+Helper.swift */, AA8E03D92D2ED83300E7E89C /* TransientShare.swift */, ); path = Share; @@ -2426,6 +2490,8 @@ F758B41E212C516300515F55 /* Scan document */ = { isa = PBXGroup; children = ( + B5E2E6D52DAE571200AB2EDD /* PasswordInputField.swift */, + B5E2E6D62DAE571200AB2EDD /* PasswordInputField.xib */, F758B457212C564000515F55 /* NCScan.storyboard */, F758B45D212C569C00515F55 /* NCScanCell.swift */, F758B45F212C56A400515F55 /* NCScan.swift */, @@ -3930,9 +3996,14 @@ F758B45A212C564000515F55 /* NCScan.storyboard in Resources */, F765F73225237E3F00391DBE /* NCRecent.storyboard in Resources */, F78F74342163757000C2ADAD /* NCTrash.storyboard in Resources */, + B5E2E6E72DAE59F000AB2EDD /* NCShareHeaderCustomCell.xib in Resources */, + B5E2E6E82DAE59F000AB2EDD /* NCShareTextInputCell.xib in Resources */, F702F30225EE5D2C008F8E80 /* english.txt in Resources */, F757CC8C29E82D0500F31428 /* NCGroupfolders.storyboard in Resources */, F79A65C32191D90F00FF6DCC /* NCSelect.storyboard in Resources */, + B5E2E6DD2DAE573B00AB2EDD /* NCFilePermissionEditCell.xib in Resources */, + B5E2E6ED2DAE66AF00AB2EDD /* NCShareEmailFieldCell.xib in Resources */, + B5E2E6DE2DAE573B00AB2EDD /* NCFilePermissionCell.xib in Resources */, F7226EDC1EE4089300EBECB1 /* Main.storyboard in Resources */, AF56C1DC2784856200D8BAE2 /* NCActivityCommentView.xib in Resources */, F7F4F10B27ECDBDB008676F9 /* Inconsolata-Light.ttf in Resources */, @@ -3953,9 +4024,11 @@ F723B3DD22FC6D1D00301EFE /* NCShareCommentsCell.xib in Resources */, F78ACD4B21903F850088454D /* NCTrashListCell.xib in Resources */, AF93471927E2361E002537EE /* NCShareAdvancePermissionFooter.xib in Resources */, + B5E2E6E22DAE59CD00AB2EDD /* NCShareAdvancePermissionHeader.xib in Resources */, F7725A61251F33BB00D125E0 /* NCFiles.storyboard in Resources */, F7CBC1232BAC8B0000EC1D55 /* NCSectionFirstHeaderEmptyData.xib in Resources */, F700510122DF63AC003A3356 /* NCShare.storyboard in Resources */, + B5E2E6D72DAE571200AB2EDD /* PasswordInputField.xib in Resources */, F787704F22E7019900F287A9 /* NCShareLinkCell.xib in Resources */, F70753F72542A9C000972D44 /* NCViewerMediaPage.storyboard in Resources */, F7F4F10627ECDBDB008676F9 /* Inconsolata-Medium.ttf in Resources */, @@ -4084,6 +4157,8 @@ AA52EB472D42AC9E0089C348 /* Placeholder.swift in Sources */, F372087D2BAB4C0F006B5430 /* TestConstants.swift in Sources */, F78E2D6C29AF02DB0024D4F3 /* Database.swift in Sources */, + B5E2E6D42DAE52B500AB2EDD /* SharingTest.swift in Sources */, + F7817CFE29801A3500FFBC65 /* Data+Extension.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -4271,6 +4346,10 @@ F76B3CCF1EAE01BD00921AC9 /* NCBrand.swift in Sources */, F72944F32A84246400246839 /* NCEndToEndMetadataV20.swift in Sources */, F7BAADCC1ED5A87C00B7EAD4 /* NCManageDatabase.swift in Sources */, + B5BEBD1E2E93A74C0002C9E5 /* CreateLinkFooterView.swift in Sources */, + B5BEBD1F2E93A74C0002C9E5 /* NCPermissions.swift in Sources */, + B5BEBD202E93A74C0002C9E5 /* NCShareEmailLinkHeaderView.swift in Sources */, + B5BEBD212E93A74C0002C9E5 /* NoSharesFooterView.swift in Sources */, F7327E322B73A86700A462C7 /* NCNetworking+WebDAV.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -4402,12 +4481,17 @@ 370D26AF248A3D7A00121797 /* NCCellProtocol.swift in Sources */, F32FADA92D1176E3007035E2 /* UIButton+Extension.swift in Sources */, F768822C2C0DD1E7001CF441 /* NCPreferences.swift in Sources */, + F768822C2C0DD1E7001CF441 /* NCKeychain.swift in Sources */, + B5E2E6EE2DAE66AF00AB2EDD /* NCShareEmailFieldCell.swift in Sources */, + F7BFFD282C8846020029A201 /* NCHud.swift in Sources */, F71CD6CA2930D7B1006C95C1 /* NCApplicationHandle.swift in Sources */, F3754A7D2CF87D600009312E /* SetupPasscodeView.swift in Sources */, F73EF7D72B0226080087E6E9 /* NCManageDatabase+Tip.swift in Sources */, F3374A842D64AC31002A38F9 /* AssistantLabelStyle.swift in Sources */, F74BAE172C7E2F4E0028D4FA /* FileProviderDomain.swift in Sources */, F76882402C0DD30B001CF441 /* ViewOnAppear.swift in Sources */, + B5E2E6E92DAE59F000AB2EDD /* NCShareTextInputCell.swift in Sources */, + B5E2E6EA2DAE59F000AB2EDD /* NCShareHeaderCustomCell.swift in Sources */, F790110E21415BF600D7B136 /* NCViewerRichDocument.swift in Sources */, F78ACD4021903CC20088454D /* NCGridCell.swift in Sources */, F7D890752BD25C570050B8A6 /* NCCollectionViewCommon+DragDrop.swift in Sources */, @@ -4429,6 +4513,7 @@ F76D3CF12428B40E005DFA87 /* NCViewerPDFSearch.swift in Sources */, F7245924289BB50C00474787 /* ThreadSafeDictionary.swift in Sources */, F73F537F1E929C8500F8678D /* NCMore.swift in Sources */, + B5BEBD192E93A5260002C9E5 /* Shareable.swift in Sources */, F702F2CF25EE5B5C008F8E80 /* NCGlobal.swift in Sources */, F794E13F2BBC0F70003693D7 /* SceneDelegate.swift in Sources */, F714A1472ED84AF90050A43B /* HudBannerView.swift in Sources */, @@ -4486,7 +4571,7 @@ F71916142E2901FB00E13E96 /* NCNetworking+Upload.swift in Sources */, F704B5E92430C0B800632F5F /* NCCreateFormUploadConflictCell.swift in Sources */, F72D404923D2082500A97FD0 /* NCViewerNextcloudText.swift in Sources */, - AFCE353927E5DE0500FEA6C2 /* Shareable.swift in Sources */, + AFCE353927E5DE0500FEA6C2 /* NCShare+Helper.swift in Sources */, F77BB746289984CA0090FC19 /* UIViewController+Extension.swift in Sources */, F700510522DF6A89003A3356 /* NCShare.swift in Sources */, F72D1007210B6882009C96B7 /* NCPushNotificationEncryption.m in Sources */, @@ -4548,6 +4633,7 @@ F73EF7BF2B02250B0087E6E9 /* NCManageDatabase+GPS.swift in Sources */, F39A1EE22D0AF8A400DAD522 /* Albums.swift in Sources */, F71F6D072B6A6A5E00F1EB15 /* ThreadSafeArray.swift in Sources */, + B5E2E6D82DAE571200AB2EDD /* PasswordInputField.swift in Sources */, F761856C29E98543006EB3B0 /* NCIntroCollectionViewCell.swift in Sources */, F75DD765290ABB25002EB562 /* Intent.intentdefinition in Sources */, F7D4BF012CA1831900A5E746 /* NCCollectionViewCommonPinchGesture.swift in Sources */, @@ -4598,6 +4684,10 @@ F76B3CCE1EAE01BD00921AC9 /* NCBrand.swift in Sources */, F7FA7FFC2C0F4EE40072FC60 /* NCViewerQuickLookView.swift in Sources */, F3A0479B2BD2668800658E7B /* NCAssistant.swift in Sources */, + B5BEBD222E93A74C0002C9E5 /* CreateLinkFooterView.swift in Sources */, + B5BEBD232E93A74C0002C9E5 /* NCPermissions.swift in Sources */, + B5BEBD242E93A74C0002C9E5 /* NCShareEmailLinkHeaderView.swift in Sources */, + B5BEBD252E93A74C0002C9E5 /* NoSharesFooterView.swift in Sources */, F359D8672A7D03420023F405 /* NCUtility+Exif.swift in Sources */, F7A03E352D427312007AA677 /* NCMainNavigationController.swift in Sources */, F769CA192966EA3C00039397 /* ComponentView.swift in Sources */, @@ -4607,6 +4697,7 @@ AF93474E27E3F212002537EE /* NCShareNewUserAddComment.swift in Sources */, F7C30DFD291BD0B80017149B /* NCNetworkingE2EEDelete.swift in Sources */, F77E8C232E79717D00EAE68F /* NCManageDatabase+LivePhoto.swift in Sources */, + B5E2E6F02DAE6E3F00AB2EDD /* ShareDownloadLimitNetwork.swift in Sources */, F76882302C0DD1E7001CF441 /* NCFileNameModel.swift in Sources */, F7CF06882E1127460063AD04 /* NCManageDatabase+CreateMetadata.swift in Sources */, F72FD3B5297ED49A00075D28 /* NCManageDatabase+E2EE.swift in Sources */, @@ -4637,6 +4728,8 @@ AF93471B27E2361E002537EE /* NCShareAdvancePermission.swift in Sources */, F77BC3ED293E528A005F2B08 /* NCConfigServer.swift in Sources */, F7A560422AE1593700BE8FD6 /* NCOperationSaveLivePhoto.swift in Sources */, + B5E2E6DF2DAE573B00AB2EDD /* NCFilePermissionCell.swift in Sources */, + B5E2E6E02DAE573B00AB2EDD /* NCFilePermissionEditCell.swift in Sources */, F7D1C4AC2C9484FD00EC6D44 /* NCMedia+CollectionViewDataSourcePrefetching.swift in Sources */, F7D368DF2DAFE19E0037E7C6 /* NCActivityNavigationController.swift in Sources */, F7A03E332D426115007AA677 /* NCMoreNavigationController.swift in Sources */, diff --git a/Tests/NextcloudUnitTests/SharingTest.swift b/Tests/NextcloudUnitTests/SharingTest.swift new file mode 100644 index 0000000000..984a4c0ac3 --- /dev/null +++ b/Tests/NextcloudUnitTests/SharingTest.swift @@ -0,0 +1,232 @@ +// +// SharingTest.swift +// NextcloudTests +// +// Created by A200020526 on 07/06/23. +// Copyright © 2023 Marino Faggiana. All rights reserved. +// + +import XCTest +@testable import Nextcloud +final class SharingTest: XCTestCase { + + var button: UIButton? + var ncShare: NCShare? + + override func setUpWithError() throws { + // Put setup code here. This method is called before the invocation of each test method in the class. + super.setUp() + button = UIButton() + ncShare = NCShare() + } + + override func tearDownWithError() throws { + // Put teardown code here. This method is called after the invocation of each test method in the class. + button = nil + ncShare = nil + super.tearDown() + } + + func testPerformanceExample() throws { + // This is an example of a performance test case. + self.measure { + // Put the code you want to measure the time of here. + } + } + + + //Date exntesion test case + func testTomorrow() { + let tomorrow = Date.tomorrow + let expectedTomorrow = Calendar.current.date(byAdding: .day, value: 1, to: Date())! + XCTAssertEqual(tomorrow.extendedIso8601String, expectedTomorrow.extendedIso8601String, "Tomorrow date should be correct.") + } + func testToday() { + let today = Date.today + let currentDate = Date() + XCTAssertEqual(today.extendedIso8601String, currentDate.extendedIso8601String, "Today date should be correct.") + } + + func testDayAfter() { + let date = Date() + let dayAfter = date.dayAfter + let expectedDayAfter = Calendar.current.date(byAdding: .day, value: 1, to: date)! + XCTAssertEqual(dayAfter.extendedIso8601String, expectedDayAfter.extendedIso8601String, "Day after date should be correct.") + } + + //Date Formatter extension Test Case + func testShareExpDate() { + let dateFormatter = DateFormatter.shareExpDate + + XCTAssertEqual(dateFormatter.formatterBehavior, .behavior10_4, "Formatter behavior should be correct.") + XCTAssertEqual(dateFormatter.dateStyle, .medium, "Date style should be correct.") + XCTAssertEqual(dateFormatter.dateFormat, NCShareAdvancePermission.displayDateFormat, "Date format should be correct.") + } + + //Button Extension test case + func testSetBackgroundColor() { + // Arrange + let color = UIColor.red + let state: UIControl.State = .normal + + // Act + button?.setBackgroundColor(color, for: state) + + // Assert + XCTAssertNotNil(button?.currentBackgroundImage, "Button background image not nil") + } + + func testSetBackgroundColorForDifferentStates() { + // Arrange + + let selectedColor = UIColor.green + + // Act + button?.isSelected = true + button?.setBackgroundColor(selectedColor, for: .selected) + + // Assert + XCTAssertNotNil(button?.currentBackgroundImage, "Button background image not nil") + button?.isSelected = false + XCTAssertNil(button?.currentBackgroundImage,"Button background image will be nil") + button?.isHighlighted = true + XCTAssertNil(button?.currentBackgroundImage, "Button background image will be nil") + } + + //UIView extension shadow test case + func testAddShadowWithLocation() { + // Create a UIView instance + let view = UIView() + + // Set the shadow with bottom location + view.addShadow(location: .bottom, height: 2, color: .red, opacity: 0.4, radius: 2) + + // Verify that the shadow offset is set correctly for the bottom location + let bottomShadowOffset = view.layer.shadowOffset + XCTAssertEqual(bottomShadowOffset, CGSize(width: 0, height: 2), "Shadow offset not set correctly for bottom location") + + // Verify that the shadow color is set correctly + let shadowColor = view.layer.shadowColor + XCTAssertEqual(shadowColor, UIColor.red.cgColor, "Shadow color not set correctly") + + // Verify that the shadow opacity is set correctly + let shadowOpacity = view.layer.shadowOpacity + XCTAssertEqual(shadowOpacity, 0.4, "Shadow opacity not set correctly") + + // Verify that the shadow radius is set correctly + let shadowRadius = view.layer.shadowRadius + XCTAssertEqual(shadowRadius, 2.0, "Shadow radius not set correctly") + } + + func testAddShadowWithOffset() { + // Create a UIView instance + let view = UIView() + + // Set the shadow with a custom offset + view.addShadow(offset: CGSize(width: 0, height: -4), color: .blue, opacity: 0.6, radius: 3) + + // Verify that the shadow offset is set correctly + let shadowOffset = view.layer.shadowOffset + XCTAssertEqual(shadowOffset, CGSize(width: 0, height: -4), "Shadow offset not set correctly") + + // Verify that the shadow color is set correctly + let shadowColor = view.layer.shadowColor + XCTAssertEqual(shadowColor, UIColor.blue.cgColor, "Shadow color not set correctly") + + // Verify that the shadow opacity is set correctly + let shadowOpacity = view.layer.shadowOpacity + XCTAssertEqual(shadowOpacity, 0.6, "Shadow opacity not set correctly") + + // Verify that the shadow radius is set correctly + let shadowRadius = view.layer.shadowRadius + XCTAssertEqual(shadowRadius, 3.0, "Shadow radius not set correctly") + } + + func testAddShadowForLocation() { + // Create a UIView instance + let view = UIView() + + // Add shadow to the bottom + view.addShadow(location: .bottom, color: UIColor.black) + + // Verify that the shadow properties are set correctly for the bottom location + XCTAssertEqual(view.layer.shadowOffset, CGSize(width: 0, height: 2), "Shadow offset not set correctly for bottom location") + XCTAssertEqual(view.layer.shadowColor, UIColor.black.cgColor, "Shadow color not set correctly for bottom location") + XCTAssertEqual(view.layer.shadowOpacity, 0.4, "Shadow opacity not set correctly for bottom location") + XCTAssertEqual(view.layer.shadowRadius, 2.0, "Shadow radius not set correctly for bottom location") + + // Add shadow to the top + view.addShadow(location: .top) + + // Verify that the shadow properties are set correctly for the top location + XCTAssertEqual(view.layer.shadowOffset, CGSize(width: 0, height: -2), "Shadow offset not set correctly for top location") + XCTAssertEqual(view.layer.shadowColor, NCBrandColor.shared.customerDarkGrey.cgColor, "Shadow color not set correctly for top location") + XCTAssertEqual(view.layer.shadowOpacity, 0.4, "Shadow opacity not set correctly for top location") + XCTAssertEqual(view.layer.shadowRadius, 2.0, "Shadow radius not set correctly for top location") + } + + func testAddShadowForOffset() { + // Create a UIView instance + let view = UIView() + + // Add shadow with custom offset + view.addShadow(offset: CGSize(width: 2, height: 2)) + + // Verify that the shadow properties are set correctly for the custom offset + XCTAssertEqual(view.layer.shadowOffset, CGSize(width: 2, height: 2), "Shadow offset not set correctly for custom offset") + XCTAssertEqual(view.layer.shadowColor, UIColor.black.cgColor, "Shadow color not set correctly for custom offset") + XCTAssertEqual(view.layer.shadowOpacity, 0.5, "Shadow opacity not set correctly for custom offset") + XCTAssertEqual(view.layer.shadowRadius, 5.0, "Shadow radius not set correctly for custom offset") + } + + + func testHasUploadPermission() { + // Create an instance of NCShare + let share = NCShare() + + // Define the input parameters + let tableShareWithUploadPermission = tableShare() + tableShareWithUploadPermission.permissions = NCGlobal.shared.permissionMaxFileShare + + let tableShareWithoutUploadPermission = tableShare() + tableShareWithoutUploadPermission.permissions = NCGlobal.shared.permissionReadShare + + // Call the hasUploadPermission function + let hasUploadPermission1 = share.hasUploadPermission(tableShare: tableShareWithUploadPermission) + let hasUploadPermission2 = share.hasUploadPermission(tableShare: tableShareWithoutUploadPermission) + + // Verify the results + XCTAssertTrue(hasUploadPermission1, "hasUploadPermission returned false for a tableShare with upload permission") + XCTAssertFalse(hasUploadPermission2, "hasUploadPermission returned true for a tableShare without upload permission") + } + + func testGetImageShareType() { + let sut = NCShareCommon // Replace with the actual class containing the getImageShareType function + + // Test case 1: SHARE_TYPE_USER + let shareType1 = sut.shareTypeUser + let result1 = sut.getImageShareType(shareType: shareType1) + XCTAssertEqual(result1, UIImage(named: "shareTypeEmail")?.imageColor(NCBrandColor.shared.label)) + + // Test case 2: SHARE_TYPE_GROUP + let shareType2 = sut.shareTypeGroup + let result2 = sut.getImageShareType(shareType: shareType2) + XCTAssertEqual(result2, UIImage(named: "shareTypeGroup")?.imageColor(NCBrandColor.shared.label)) + + // Test case 3: SHARE_TYPE_LINK + let shareType3 = sut.shareTypeLink + let result3 = sut.getImageShareType(shareType: shareType3) + XCTAssertEqual(result3, UIImage(named: "shareTypeLink")?.imageColor(NCBrandColor.shared.label)) + + // Test case 4: SHARE_TYPE_EMAIL (with isDropDown=false) + let shareType4 = sut.shareTypeEmail + let result4 = sut.getImageShareType(shareType: shareType4) + XCTAssertEqual(result4, UIImage(named: "shareTypeUser")?.imageColor(NCBrandColor.shared.label)) + + // Test case 5: SHARE_TYPE_EMAIL (with isDropDown=true) + let shareType5 = sut.shareTypeEmail + let isDropDown5 = true + let result5 = sut.getImageShareType(shareType: shareType5)//, isDropDown: isDropDown5) + XCTAssertEqual(result5, UIImage(named: "email")?.imageColor(NCBrandColor.shared.label)) + } +} diff --git a/iOSClient/Activity/NCActivity.swift b/iOSClient/Activity/NCActivity.swift index 6098a49209..70be71c3f5 100644 --- a/iOSClient/Activity/NCActivity.swift +++ b/iOSClient/Activity/NCActivity.swift @@ -12,7 +12,7 @@ class NCActivity: UIViewController, NCSharePagingContent { @IBOutlet weak var tableView: UITableView! var commentView: NCActivityCommentView? - var textField: UIView? { commentView?.newCommentField } + var textField: UITextField? { commentView?.newCommentField } var height: CGFloat = 0 var metadata: tableMetadata? var showComments: Bool = false @@ -600,7 +600,7 @@ extension NCActivity: NCShareCommentsCellDelegate { NCMenuAction( title: NSLocalizedString("_delete_comment_", comment: ""), destructive: true, - icon: utility.loadImage(named: "trash", colors: [.red]), + icon: utility.loadImage(named: "trashIcon", colors: [.red]), sender: sender, action: { _ in guard let metadata = self.metadata, let tableComments = tableComments else { return } diff --git a/iOSClient/Extensions/DateFormatter+Extension.swift b/iOSClient/Extensions/DateFormatter+Extension.swift index dceb24e7e7..8f14117050 100644 --- a/iOSClient/Extensions/DateFormatter+Extension.swift +++ b/iOSClient/Extensions/DateFormatter+Extension.swift @@ -31,4 +31,66 @@ extension DateFormatter { dateFormatter.dateStyle = .medium return dateFormatter }() + +// static func formattedExpiryDate(_ date: Date) -> String { +// // Get the app language +// let appLanguage = Locale.preferredLanguages.first?.prefix(2) ?? "en" +// let locale = Locale(identifier: "\(appLanguage)_\(appLanguage.uppercased())") +// +// // Extract components +// let calendar = Calendar.current +// let day = calendar.component(.day, from: date) +// +// // Get month name abbreviation in the correct locale +// let monthFormatter = DateFormatter() +// monthFormatter.locale = locale +// monthFormatter.dateFormat = "MMM" // abbreviated month +// var month = monthFormatter.string(from: date) +// +// // Capitalize first letter (German months are lowercase normally) +// month = month.prefix(1).uppercased() + month.dropFirst() +// +// // Remove trailing period if present (common in German abbreviations) +// month = month.replacingOccurrences(of: ".", with: "") +// +// // Get year +// let year = calendar.component(.year, from: date) +// +// return String(format: "%02d.%@.%d", day, month, year) +// } + + /// Formats a given Date object into the specific string format "dd. MMM. yyyy" + /// required for the expiry date display (e.g., "01. Dez. 2026"). + static func formattedExpiryDate(_ date: Date) -> String { + + // 1. Determine the correct locale to use based on the app's preferences + let appLanguageCode = Locale.preferredLanguages.first?.prefix(2) ?? "en" + // Use a standard locale identifier for consistency across devices + let localeIdentifier = (appLanguageCode == "de" || appLanguageCode == "en") ? appLanguageCode : "en" + let locale = Locale(identifier: String(localeIdentifier)) + + let calendar = Calendar.current + let day = calendar.component(.day, from: date) + let year = calendar.component(.year, from: date) + + // 2. Get the month abbreviation using the correct locale + let monthFormatter = DateFormatter() + monthFormatter.locale = locale + monthFormatter.dateFormat = "MMM" // e.g., "Dez." (German locale adds a period) or "Dec" (English locale adds no period) + var month = monthFormatter.string(from: date) + + // 3. CRITICAL FIXES: + // A. Remove any trailing period the locale might have added + month = month.replacingOccurrences(of: ".", with: "") + + // B. Capitalize the first letter (German defaults to lowercase 'dez') + month = month.prefix(1).uppercased() + month.dropFirst() + + // 4. Use the String(format:) with correct spacing to guarantee the output structure + // This line guarantees a SINGLE period after the day and a SINGLE period after the month abbreviation. + let formattedDateString = String(format: "%02d. %@. %d", day, month, year) + + return formattedDateString + } + } diff --git a/iOSClient/Extensions/UIView+Extension.swift b/iOSClient/Extensions/UIView+Extension.swift index 193198ec46..ce28c998b5 100644 --- a/iOSClient/Extensions/UIView+Extension.swift +++ b/iOSClient/Extensions/UIView+Extension.swift @@ -25,9 +25,86 @@ import Foundation import UIKit extension UIView { + + // Source + // https://stackoverflow.com/questions/18680028/prevent-screen-capture-in-an-ios-app/67054892#67054892 + // + // private weak var scrollView: UIScrollView! (it's an outlet) + // self.view.preventScreenshot(for: self.scrollView) + // + func preventScreenshot(for view: UIView) { + let textField = UITextField() + textField.isSecureTextEntry = true + textField.isUserInteractionEnabled = false + guard let hiddenView = textField.layer.sublayers?.first?.delegate as? UIView else { + return + } + hiddenView.subviews.forEach { $0.removeFromSuperview() } + hiddenView.translatesAutoresizingMaskIntoConstraints = false + self.addSubview(hiddenView) + hiddenView.fillSuperview() + hiddenView.addSubview(view) + } + + func addBlur(style: UIBlurEffect.Style) { + let blur = UIBlurEffect(style: style) + let blurredEffectView = UIVisualEffectView(effect: blur) + blurredEffectView.frame = self.bounds + blurredEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight] + blurredEffectView.isUserInteractionEnabled = false + self.addSubview(blurredEffectView) + } + + func insertBlur(style: UIBlurEffect.Style) { + let blur = UIBlurEffect(style: style) + let blurredEffectView = UIVisualEffectView(effect: blur) + blurredEffectView.frame = self.bounds + blurredEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight] + blurredEffectView.isUserInteractionEnabled = false + self.insertSubview(blurredEffectView, at: 0) + } + func makeCircularBackground(withColor backgroundColor: UIColor) { self.backgroundColor = backgroundColor self.layer.cornerRadius = self.frame.size.width / 2 self.layer.masksToBounds = true } + + var parentTabBarController: UITabBarController? { + var responder: UIResponder? = self + while let nextResponder = responder?.next { + if let tabBarController = nextResponder as? UITabBarController { + return tabBarController + } + responder = nextResponder + } + return nil + } + + func addBlur(style: UIBlurEffect.Style, alpha: CGFloat = 1.0) { + let blurEffect = UIBlurEffect(style: style) + let blurView = UIVisualEffectView(effect: blurEffect) + blurView.frame = bounds + blurView.autoresizingMask = [.flexibleWidth, .flexibleHeight] + blurView.alpha = alpha + blurView.layer.masksToBounds = true + insertSubview(blurView, at: 0) + } + + func addBlurBackground(style: UIBlurEffect.Style, alpha: CGFloat = 1) { + let blur = UIBlurEffect(style: style) + let blurView = UIVisualEffectView(effect: blur) + blurView.isUserInteractionEnabled = false + blurView.alpha = alpha + blurView.layer.masksToBounds = true + blurView.translatesAutoresizingMaskIntoConstraints = false + insertSubview(blurView, at: 0) + + NSLayoutConstraint.activate([ + blurView.topAnchor.constraint(equalTo: topAnchor), + blurView.leadingAnchor.constraint(equalTo: leadingAnchor), + blurView.trailingAnchor.constraint(equalTo: trailingAnchor), + blurView.bottomAnchor.constraint(equalTo: bottomAnchor) + ]) + } } diff --git a/iOSClient/Menu/NCShare+Menu.swift b/iOSClient/Menu/NCShare+Menu.swift index f4cc7a23fd..fc3043036d 100644 --- a/iOSClient/Menu/NCShare+Menu.swift +++ b/iOSClient/Menu/NCShare+Menu.swift @@ -33,11 +33,11 @@ extension NCShare { if share.shareType == NKShare.ShareType.publicLink.rawValue, canReshare { actions.append( NCMenuAction( - title: NSLocalizedString("_share_add_sharelink_", comment: ""), - icon: utility.loadImage(named: "plus", colors: [NCBrandColor.shared.iconImageColor]), + title: NSLocalizedString("_open_in_", comment: ""), + icon: utility.loadImage(named: "open_file", colors: [NCBrandColor.shared.brandElement]), sender: sender, action: { _ in - self.makeNewLinkShare() + NCShareCommon.copyLink(link: share.url, viewController: self, sender: sender) } ) ) @@ -45,8 +45,10 @@ extension NCShare { actions.append( NCMenuAction( - title: NSLocalizedString("_details_", comment: ""), - icon: utility.loadImage(named: "pencil", colors: [NCBrandColor.shared.iconImageColor]), +// title: NSLocalizedString("_details_", comment: ""), +// icon: utility.loadImage(named: "pencil", colors: [NCBrandColor.shared.iconImageColor]), + title: NSLocalizedString("_advance_permissions_", comment: ""), + icon: utility.loadImage(named: "rename", colors: [NCBrandColor.shared.brandElement]), accessibilityIdentifier: "shareMenu/details", sender: sender, action: { _ in @@ -67,11 +69,28 @@ extension NCShare { ) ) + if sendMail { + actions.append( + NCMenuAction( + title: NSLocalizedString("_send_new_email_", comment: ""), + icon: utility.loadImage(named: "email", colors: [NCBrandColor.shared.brandElement]), + sender: sender, + action: { menuAction in + let storyboard = UIStoryboard(name: "NCShare", bundle: nil) + guard let viewNewUserComment = storyboard.instantiateViewController(withIdentifier: "NCShareNewUserAddComment") as? NCShareNewUserAddComment else { return } + viewNewUserComment.metadata = self.metadata + viewNewUserComment.share = tableShare(value: share) +// viewNewUserComment.networking = self.networking + self.navigationController?.pushViewController(viewNewUserComment, animated: true) + } + ) + ) + } + actions.append( NCMenuAction( title: NSLocalizedString("_share_unshare_", comment: ""), - destructive: true, - icon: utility.loadImage(named: "person.2.slash"), + icon: utility.loadImage(named: "trashIcon", colors: [NCBrandColor.shared.brandElement]), sender: sender, action: { _ in Task { @@ -120,26 +139,27 @@ extension NCShare { self.updateSharePermissions(share: share, permissions: permissions) } ), - NCMenuAction( - title: NSLocalizedString("_custom_permissions_", comment: ""), - icon: utility.loadImage(named: "ellipsis", colors: [NCBrandColor.shared.iconImageColor]), - sender: sender, - action: { _ in - guard - let advancePermission = UIStoryboard(name: "NCShare", bundle: nil).instantiateViewController(withIdentifier: "NCShareAdvancePermission") as? NCShareAdvancePermission, - let navigationController = self.navigationController, !share.isInvalidated else { return } - advancePermission.networking = self.networking - advancePermission.share = tableShare(value: share) - advancePermission.oldTableShare = tableShare(value: share) - advancePermission.metadata = self.metadata - - if let downloadLimit = try? self.database.getDownloadLimit(byAccount: self.metadata.account, shareToken: share.token) { - advancePermission.downloadLimit = .limited(limit: downloadLimit.limit, count: downloadLimit.count) - } - - navigationController.pushViewController(advancePermission, animated: true) - } - )] +// NCMenuAction( +// title: NSLocalizedString("_custom_permissions_", comment: ""), +// icon: utility.loadImage(named: "ellipsis", colors: [NCBrandColor.shared.iconImageColor]), +// sender: sender, +// action: { _ in +// guard +// let advancePermission = UIStoryboard(name: "NCShare", bundle: nil).instantiateViewController(withIdentifier: "NCShareAdvancePermission") as? NCShareAdvancePermission, +// let navigationController = self.navigationController, !share.isInvalidated else { return } +// advancePermission.networking = self.networking +// advancePermission.share = tableShare(value: share) +// advancePermission.oldTableShare = tableShare(value: share) +// advancePermission.metadata = self.metadata +// +// if let downloadLimit = try? self.database.getDownloadLimit(byAccount: self.metadata.account, shareToken: share.token) { +// advancePermission.downloadLimit = .limited(limit: downloadLimit.limit, count: downloadLimit.count) +// } +// +// navigationController.pushViewController(advancePermission, animated: true) +// } +// ) + ] ) if isDirectory && (share.shareType == NKShare.ShareType.publicLink.rawValue /* public link */ || share.shareType == NKShare.ShareType.email.rawValue) { diff --git a/iOSClient/NCGlobal.swift b/iOSClient/NCGlobal.swift index 51df24b68c..96ea74c54a 100644 --- a/iOSClient/NCGlobal.swift +++ b/iOSClient/NCGlobal.swift @@ -57,16 +57,19 @@ final class NCGlobal: Sendable { // let nextcloud_unsupported_version: Int = 20 +// let nextcloud_unsupported_version: Int = 17 + // Intro selector // let introLogin: Int = 0 + let introSignup: Int = 1 let introSignUpWithProvider: Int = 1 // Avatar // let avatarSize: Int = 128 * Int(UIScreen.main.scale) let avatarSizeRounded: Int = 128 - + // Preview size // let size1024: CGSize = CGSize(width: 1024, height: 1024) @@ -134,7 +137,35 @@ final class NCGlobal: Sendable { // let buttonMoreMore = "more" let buttonMoreLock = "moreLock" - + let buttonMoreStop = "stop" + + // Standard height sections header/footer + // + let heightButtonsView: CGFloat = 50 + let heightHeaderTransfer: CGFloat = 50 + let heightSection: CGFloat = 30 + let heightFooter: CGFloat = 1 + let heightFooterButton: CGFloat = 30 + let endHeightFooter: CGFloat = 85 + + + // Text - OnlyOffice - Collabora - QuickLook + // + let editorText = "text" + let editorOnlyoffice = "onlyoffice" + let editorCollabora = "collabora" + let editorQuickLook = "quicklook" + + let onlyofficeDocx = "onlyoffice_docx" + let onlyofficeXlsx = "onlyoffice_xlsx" + let onlyofficePptx = "onlyoffice_pptx" + + // Template + // + let templateDocument = "document" + let templateSpreadsheet = "spreadsheet" + let templatePresentation = "presentation" + // Rich Workspace // let fileNameRichWorkspace = "Readme.md" @@ -217,6 +248,8 @@ final class NCGlobal: Sendable { let selectorSaveAsScan = "saveAsScan" let selectorOpenDetail = "openDetail" let selectorSynchronizationOffline = "synchronizationOffline" + let selectorPrint = "print" + let selectorDeleteFile = "deleteFile" // Metadata : Status // @@ -241,16 +274,26 @@ final class NCGlobal: Sendable { let metadataStatusWaitFavorite: Int = 13 let metadataStatusWaitCopy: Int = 14 let metadataStatusWaitMove: Int = 15 - + let metadataStatusUploadingAllMode = [1,2,3] - let metadataStatusDownloadingAllMode = [-1, -2, -3] - let metadataStatusForScreenAwake = [-1, -2, 1, 2] + let metadataStatusInTransfer = [-1, -2, 1, 2] + let metadataStatusFileDown = [-1, -2, -3] let metadataStatusHideInView = [1, 2, 3, 11] + let metadataStatusHideInFileExtension = [1, 2, 3, 10, 11] let metadataStatusWaitWebDav = [10, 11, 12, 13, 14, 15] let metadataStatusTransfers = [-2, -3, 2, 3, 10, 11, 12, 13, 14, 15] let metadatasStatusInWaiting = [-1, 1, 10, 11, 12, 13, 14, 15] let metadatasStatusInProgress = [-2, 2] + + let metadataStatusObserveNetworkingProcess = [-1, 1, 10, 11, 12, 13, 14, 15] + let metadataStatusObserveTrasfers = [-2, 2, 10, 11, 12, 13, 14, 15] + + let metadataStatusUploadingAllMode = [1,2,3] + let metadataStatusDownloadingAllMode = [-1, -2, -3] + let metadataStatusForScreenAwake = [-1, -2, 1, 2] + let metadataStatusHideInView = [1, 2, 3, 11] + let metadataStatusWaitWebDav = [10, 11, 12, 13, 14, 15] // Auto upload subfolder granularity // @@ -264,13 +307,44 @@ final class NCGlobal: Sendable { let notificationCenterChangeTheming = "changeTheming" // userInfo: account let notificationCenterRichdocumentGrabFocus = "richdocumentGrabFocus" let notificationCenterReloadDataNCShare = "reloadDataNCShare" + let notificationCenterDidCreateShareLink = "didCreateShareLink" + let notificationCenterCloseRichWorkspaceWebView = "closeRichWorkspaceWebView" let notificationCenterReloadAvatar = "reloadAvatar" let notificationCenterClearCache = "clearCache" let notificationCenterCheckUserDelaultErrorDone = "checkUserDelaultErrorDone" // userInfo: account, controller let notificationCenterServerDidUpdate = "serverDidUpdate" // userInfo: account let notificationCenterNetworkReachability = "networkReachability" - + let notificationCenterCreateMediaCacheEnded = "createMediaCacheEnded" + let notificationCenterUpdateNotification = "updateNotification" + + let notificationCenterReloadDataSource = "reloadDataSource" // userInfo: serverUrl?, clearDataSource + let notificationCenterGetServerData = "getServerData" // userInfo: serverUrl? + + let notificationCenterChangeStatusFolderE2EE = "changeStatusFolderE2EE" // userInfo: serverUrl + + let notificationCenterDownloadStartFile = "downloadStartFile" // userInfo: ocId, ocIdTransfer, session, serverUrl, account + let notificationCenterDownloadedFile = "downloadedFile" // userInfo: ocId, ocIdTransfer, session, session, serverUrl, account, selector, error + let notificationCenterDownloadCancelFile = "downloadCancelFile" // userInfo: ocId, ocIdTransfer, session, serverUrl, account + + let notificationCenterUploadStartFile = "uploadStartFile" // userInfo: ocId, ocIdTransfer, session, serverUrl, account, fileName, sessionSelector + let notificationCenterUploadedFile = "uploadedFile" // userInfo: ocId, ocIdTransfer, session, serverUrl, account, fileName, ocIdTransfer, error + let notificationCenterUploadedLivePhoto = "uploadedLivePhoto" // userInfo: ocId, ocIdTransfer, session, serverUrl, account, fileName, ocIdTransfer, error + let notificationCenterUploadCancelFile = "uploadCancelFile" // userInfo: ocId, ocIdTransfer, session, serverUrl, account + + let notificationCenterProgressTask = "progressTask" // userInfo: account, ocId, ocIdTransfer, session, serverUrl, status, chunk, e2eEncrypted, progress, totalBytes, totalBytesExpected + + let notificationCenterUpdateBadgeNumber = "updateBadgeNumber" // userInfo: counterDownload, counterUpload + + let notificationCenterCreateFolder = "createFolder" // userInfo: ocId, serverUrl, account, withPush, sceneIdentifier + let notificationCenterDeleteFile = "deleteFile" // userInfo: [ocId], error + let notificationCenterCopyMoveFile = "copyMoveFile" // userInfo: [ocId] serverUrl, account, dragdrop, type (copy, move) + let notificationCenterMoveFile = "moveFile" // userInfo: [ocId], [indexPath], error + let notificationCenterCopyFile = "copyFile" // userInfo: [ocId], [indexPath], error + let notificationCenterRenameFile = "renameFile" // userInfo: serverUrl, account, error + let notificationCenterFavoriteFile = "favoriteFile" // userInfo: ocId, serverUrl + let notificationCenterFileExists = "fileExists" // userInfo: ocId, fileExists + let notificationCenterMenuSearchTextPDF = "menuSearchTextPDF" let notificationCenterMenuGotToPageInPDF = "menuGotToPageInPDF" @@ -285,6 +359,8 @@ final class NCGlobal: Sendable { let notificationCenterPlayerIsPlaying = "playerIsPlaying" let notificationCenterPlayerStoppedPlaying = "playerStoppedPlaying" + let notificationCenterFavoriteStatusChanged = "favoriteStatusChanged" + // Networking Status let networkingStatusCreateFolder = "statusCreateFolder" let networkingStatusDelete = "statusDelete" @@ -299,8 +375,9 @@ final class NCGlobal: Sendable { let networkingStatusUploading = "statusUploading" let networkingStatusUploaded = "statusUploaded" - let networkingStatusReloadAvatar = "statusReloadAvatar" + let networkingStatusReloadAvatar = "statusReloadAvatar" + let notificationCenterUpdateIcons = "updateIcons" // TIP // @@ -383,9 +460,8 @@ final class NCGlobal: Sendable { // let taskDescriptionRetrievesProperties = "retrievesProperties" let taskDescriptionSynchronization = "synchronization" - - // LOG TAG - // + let taskDescriptionDeleteFileOrFolder = "deleteFileOrFolder" + let logTagTask = "BGT" let logTagLocation = "LOCATION" let logTagBgSync = "BGSYNC" @@ -398,10 +474,37 @@ final class NCGlobal: Sendable { let logTagNetworkingTasks = "NETWORKING TASKS" let logTagMetadataTransfers = "METADATA TRANSFERS" + // MoEngage App Version + // + let moEngageAppVersion = 854 + + // Filename Mask and Type + // + let keyFileNameMask = "fileNameMask" + let keyFileNameType = "fileNameType" + let keyFileNameAutoUploadMask = "fileNameAutoUploadMask" + let keyFileNameAutoUploadType = "fileNameAutoUploadType" + let keyFileNameOriginal = "fileNameOriginal" + let keyFileNameOriginalAutoUpload = "fileNameOriginalAutoUpload" + + // LOG TAG + // + let logTagTask = "BGT" + let logTagLocation = "LOCATION" + let logTagBgSync = "BGSYNC" + let logTagE2EE = "E2EE" + let logTagPN = "PUSH NOTIFICATION" + let logTagSync = "SYNC" + let logTagServiceProficer = "SERVICE PROVIDER" + let logTagDatabase = "DB" + let logSpeedUpSyncMetadata = "SYNC METADATA" + let logNetworkingTasks = "NETWORKING TASKS" + // USER DEFAULTS // let udMigrationMultiDomains = "migrationMultiDomains" let udLastVersion = "lastVersion" + } /** diff --git a/iOSClient/Networking/NCDownloadAction.swift b/iOSClient/Networking/NCDownloadAction.swift new file mode 100644 index 0000000000..f2acb8aa99 --- /dev/null +++ b/iOSClient/Networking/NCDownloadAction.swift @@ -0,0 +1,741 @@ +// SPDX-FileCopyrightText: Nextcloud GmbH +// SPDX-FileCopyrightText: 2020 Marino Faggiana +// SPDX-License-Identifier: GPL-3.0-or-later + +import UIKit +import NextcloudKit +import Queuer +import SVGKit +import Photos +import Alamofire + +class NCDownloadAction: NSObject, UIDocumentInteractionControllerDelegate, NCSelectDelegate, NCTransferDelegate { + static let shared = NCDownloadAction() + + var viewerQuickLook: NCViewerQuickLook? + var documentController: UIDocumentInteractionController? + let utilityFileSystem = NCUtilityFileSystem() + let utility = NCUtility() + let global = NCGlobal.shared + var sceneIdentifier: String = "" + + override private init() { } + + func setup(sceneIdentifier: String) { + self.sceneIdentifier = sceneIdentifier + + Task { + await NCNetworking.shared.transferDispatcher.addDelegate(self) + } + } + + // MARK: - Download + + func transferChange(status: String, metadata: tableMetadata, error: NKError) { + DispatchQueue.main.async { + switch status { + /// DOWNLOADED + case self.global.networkingStatusDownloaded: + self.downloadedFile(metadata: metadata, error: error) + default: + break + } + } + } + + func downloadedFile(metadata: tableMetadata, error: NKError) { + guard error == .success else { + return + } + /// Select UIWindowScene active in serverUrl + var controller: NCMainTabBarController? + let windowScenes = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene } + if windowScenes.count == 1 { + controller = UIApplication.shared.firstWindow?.rootViewController as? NCMainTabBarController + } else if let sceneIdentifier = metadata.sceneIdentifier, + 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 { + controller = rootViewController + break + } + } + } + guard let controller else { return } + + switch metadata.sessionSelector { + case NCGlobal.shared.selectorLoadFileQuickLook: + + let fileNamePath = self.utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocId, + fileName: metadata.fileNameView, + userId: metadata.userId, + urlBase: metadata.urlBase) + let fileNameTemp = NSTemporaryDirectory() + metadata.fileNameView + let viewerQuickLook = NCViewerQuickLook(with: URL(fileURLWithPath: fileNameTemp), isEditingEnabled: true, metadata: metadata) + if let image = UIImage(contentsOfFile: fileNamePath) { + if let data = image.jpegData(compressionQuality: 1) { + do { + try data.write(to: URL(fileURLWithPath: fileNameTemp)) + } catch { + return + } + } + let navigationController = UINavigationController(rootViewController: viewerQuickLook) + navigationController.modalPresentationStyle = .fullScreen + controller.present(navigationController, animated: true) + } else { + self.utilityFileSystem.copyFile(atPath: fileNamePath, toPath: fileNameTemp) + controller.present(viewerQuickLook, animated: true) + } + + case NCGlobal.shared.selectorLoadFileView: + guard !isAppInBackground + else { + return + } + + if metadata.contentType.contains("opendocument") && !self.utility.isTypeFileRichDocument(metadata) { + self.openActivityViewController(selectedMetadata: [metadata], controller: controller, sender: nil) + } else if metadata.classFile == NKTypeClassFile.compress.rawValue || metadata.classFile == NKTypeClassFile.unknow.rawValue { + self.openActivityViewController(selectedMetadata: [metadata], controller: controller, sender: nil) + } else { + if let viewController = controller.currentViewController() { + let image = self.utility.getImage(ocId: metadata.ocId, etag: metadata.etag, ext: NCGlobal.shared.previewExt1024, userId: metadata.userId, urlBase: metadata.urlBase) + Task { + if let vc = await NCViewer().getViewerController(metadata: metadata, image: image, delegate: viewController) { + await viewController.navigationController?.pushViewController(vc, animated: true) + } + } + } + } + + case NCGlobal.shared.selectorOpenIn: + guard !isAppInBackground + else { + return + } + + self.openActivityViewController(selectedMetadata: [metadata], controller: controller, sender: nil) + + case NCGlobal.shared.selectorPrint: + // waiting close menu + // https://github.com/nextcloud/ios/issues/2278 +// DispatchQueue.main.async { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { + self.printDocument(metadata: metadata) + } + + case NCGlobal.shared.selectorSaveAlbum: + + self.saveAlbum(metadata: metadata, controller: controller) + + case NCGlobal.shared.selectorSaveAsScan: + + self.saveAsScan(metadata: metadata, controller: controller) + + case NCGlobal.shared.selectorOpenDetail: + NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterOpenMediaDetail, userInfo: ["ocId": metadata.ocId]) + + default: + let applicationHandle = NCApplicationHandle() + applicationHandle.downloadedFile(selector: metadata.sessionSelector, metadata: metadata) + } + } + + // MARK: - + + func setMetadataAvalableOffline(_ metadata: tableMetadata, isOffline: Bool) async { + if isOffline { + if metadata.directory { + await NCManageDatabase.shared.setDirectoryAsync(serverUrl: metadata.serverUrlFileName, offline: false, metadata: metadata) + let predicate = NSPredicate(format: "account == %@ AND serverUrl BEGINSWITH %@ AND sessionSelector == %@ AND status == %d", metadata.account, metadata.serverUrlFileName, NCGlobal.shared.selectorSynchronizationOffline, NCGlobal.shared.metadataStatusWaitDownload) + if let metadatas = await NCManageDatabase.shared.getMetadatasAsync(predicate: predicate) { + await NCManageDatabase.shared.clearMetadatasSessionAsync(metadatas: metadatas) + } + } else { + await NCManageDatabase.shared.setOffLocalFileAsync(ocId: metadata.ocId) + } + } else if metadata.directory { + await NCManageDatabase.shared.cleanTablesOcIds(account: metadata.account, userId: metadata.userId, urlBase: metadata.urlBase) + await NCManageDatabase.shared.setDirectoryAsync(serverUrl: metadata.serverUrlFileName, offline: true, metadata: metadata) + await NCNetworking.shared.synchronization(account: metadata.account, serverUrl: metadata.serverUrlFileName, userId: metadata.userId, urlBase: metadata.urlBase, metadatasInDownload: nil) + } else { + var metadatasSynchronizationOffline: [tableMetadata] = [] + metadatasSynchronizationOffline.append(metadata) + if let metadata = await NCManageDatabase.shared.getMetadataLivePhotoAsync(metadata: metadata) { + metadatasSynchronizationOffline.append(metadata) + } + await NCManageDatabase.shared.addLocalFileAsync(metadata: metadata, offline: true) + for metadata in metadatasSynchronizationOffline { + await NCManageDatabase.shared.setMetadataSessionInWaitDownloadAsync(ocId: metadata.ocId, + session: NCNetworking.shared.sessionDownloadBackground, + selector: NCGlobal.shared.selectorSynchronizationOffline) + AnalyticsHelper.shared.trackEventWithMetadata(eventName: .EVENT__OFFLINE_AVAILABLE, metadata: metadata) + } + } + } + + // MARK: - + + @MainActor + func viewerFile(account: String, fileId: String, viewController: UIViewController) async { + var downloadRequest: DownloadRequest? + let hud = NCHud(viewController.tabBarController?.view) + + if let metadata = await NCManageDatabase.shared.getMetadataFromFileIdAsync(fileId) { + do { + let attr = try FileManager.default.attributesOfItem(atPath: utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocId, + fileName: metadata.fileNameView, + userId: metadata.userId, + urlBase: metadata.urlBase)) + let fileSize = attr[FileAttributeKey.size] as? UInt64 ?? 0 + if fileSize > 0 { + if let vc = await NCViewer().getViewerController(metadata: metadata, delegate: viewController) { + viewController.navigationController?.pushViewController(vc, animated: true) + } + return + } + } catch { + print("Error: \(error)") + } + } + + hud.ringProgress(tapToCancelDetailText: true) { + if let request = downloadRequest { + request.cancel() + } + } + + let resultsFile = await NextcloudKit.shared.getFileFromFileIdAsync(fileId: fileId, account: account) { task in + Task { + let identifier = await NCNetworking.shared.networkingTasks.createIdentifier(account: account, + path: fileId, + name: "getFileFromFileId") + await NCNetworking.shared.networkingTasks.track(identifier: identifier, task: task) + } + } + hud.dismiss() + guard resultsFile.error == .success, let file = resultsFile.file else { + NCContentPresenter().showError(error: resultsFile.error) + return + } + + let metadata = await NCManageDatabase.shared.convertFileToMetadataAsync(file) + await NCManageDatabase.shared.addMetadataAsync(metadata) + + let fileNameLocalPath = self.utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocId, + fileName: metadata.fileNameView, + userId: metadata.userId, + urlBase: metadata.urlBase) + + if metadata.isAudioOrVideo { + if let vc = await NCViewer().getViewerController(metadata: metadata, delegate: viewController) { + viewController.navigationController?.pushViewController(vc, animated: true) + } + return + } + + hud.show() + let download = await NextcloudKit.shared.downloadAsync(serverUrlFileName: metadata.serverUrlFileName, fileNameLocalPath: fileNameLocalPath, account: account) { request in + downloadRequest = request + } taskHandler: { task in + Task { + let identifier = await NCNetworking.shared.networkingTasks.createIdentifier(account: metadata.account, + path: metadata.serverUrlFileName, + name: "download") + await NCNetworking.shared.networkingTasks.track(identifier: identifier, task: task) + + let ocId = metadata.ocId + await NCManageDatabase.shared.setMetadataSessionAsync(ocId: ocId, + sessionTaskIdentifier: task.taskIdentifier, + status: self.global.metadataStatusDownloading) + } + } progressHandler: { progress in + hud.progress(progress.fractionCompleted) + } + + hud.dismiss() + await NCManageDatabase.shared.setMetadataSessionAsync(ocId: metadata.ocId, + session: "", + sessionTaskIdentifier: 0, + sessionError: "", + status: self.global.metadataStatusNormal, + etag: download.etag) + + if download.nkError == .success { + await NCManageDatabase.shared.addLocalFileAsync(metadata: metadata) + if let vc = await NCViewer().getViewerController(metadata: metadata, delegate: viewController) { + viewController.navigationController?.pushViewController(vc, animated: true) + } + } + } + + // MARK: - + + func openShare(viewController: UIViewController, metadata: tableMetadata, page: NCBrandOptions.NCInfoPagingTab) { + var page = page + let capabilities = NCNetworking.shared.capabilities[metadata.account] ?? NKCapabilities.Capabilities() + + NCActivityIndicator.shared.start(backgroundView: viewController.view) + NCNetworking.shared.readFile(serverUrlFileName: metadata.serverUrlFileName, account: metadata.account) { _, metadata, file, error in + Task { @MainActor in + NCActivityIndicator.shared.stop() + + if let metadata = metadata, error == .success { + let shareNavigationController = UIStoryboard(name: "NCShare", bundle: nil).instantiateInitialViewController() as? UINavigationController + let shareViewController = shareNavigationController?.topViewController as? NCShare + shareViewController?.metadata = metadata + shareNavigationController?.modalPresentationStyle = .formSheet + if let shareNavigationController = shareNavigationController { + viewController.present(shareNavigationController, animated: true, completion: nil) + } + } + } + } + } + + // MARK: - Open Activity [Share] ... + + func openActivityViewController(selectedMetadata: [tableMetadata], controller: NCMainTabBarController?, sender: Any?) { + guard let controller else { return } + let metadatas = selectedMetadata.filter({ !$0.directory }) + var urls: [URL] = [] + var downloadMetadata: [(tableMetadata, URL)] = [] + + for metadata in metadatas { + let fileURL = URL(fileURLWithPath: utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocId, + fileName: metadata.fileNameView, + userId: metadata.userId, + urlBase: metadata.urlBase)) + if utilityFileSystem.fileProviderStorageExists(metadata) { + urls.append(fileURL) + } else { + downloadMetadata.append((metadata, fileURL)) + } + } + + let processor = ParallelWorker(n: 5, titleKey: "_downloading_", totalTasks: downloadMetadata.count, controller: controller) + for (metadata, url) in downloadMetadata { + processor.execute { completion in + Task { + guard let metadata = await NCManageDatabase.shared.setMetadataSessionInWaitDownloadAsync(ocId: metadata.ocId, + session: NCNetworking.shared.sessionDownload, + selector: "", + sceneIdentifier: controller.sceneIdentifier) else { + return completion() + } + + await NCNetworking.shared.downloadFile(metadata: metadata) { _ in + } progressHandler: { progress in + processor.hud.progress(progress.fractionCompleted) + } + + if self.utilityFileSystem.fileProviderStorageExists(metadata) { + urls.append(url) + } + completion() + } + } + } + + processor.completeWork { + guard !urls.isEmpty else { return } + let activityViewController = UIActivityViewController(activityItems: urls, applicationActivities: nil) + + // iPad + if let popover = activityViewController.popoverPresentationController { + if let view = sender as? UIView { + popover.sourceView = view + popover.sourceRect = view.bounds + } else { + popover.sourceView = controller.view + popover.sourceRect = CGRect(x: controller.view.bounds.midX, + y: controller.view.bounds.midY, + width: 0, + height: 0) + popover.permittedArrowDirections = [] + } + } + + controller.present(activityViewController, animated: true) + } + } + + // MARK: - Save as scan + + func saveAsScan(metadata: tableMetadata, controller: NCMainTabBarController?) { + let fileNamePath = utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocId, + fileName: metadata.fileNameView, + userId: metadata.userId, + urlBase: metadata.urlBase) + let fileNameDestination = utilityFileSystem.createFileName("scan.png", fileDate: Date(), fileType: PHAssetMediaType.image, notUseMask: true) + let fileNamePathDestination = utilityFileSystem.createServerUrl(serverUrl: utilityFileSystem.directoryScan, fileName: fileNameDestination) + + utilityFileSystem.copyFile(atPath: fileNamePath, toPath: fileNamePathDestination) + + if let navigationController = UIStoryboard(name: "NCScan", bundle: nil).instantiateInitialViewController() { + navigationController.modalPresentationStyle = UIModalPresentationStyle.pageSheet + let viewController = navigationController.presentedViewController as? NCScan + viewController?.serverUrl = controller?.currentServerUrl() + viewController?.controller = controller + controller?.present(navigationController, animated: true, completion: nil) + } + } + + // MARK: - Save photo + + func saveAlbum(metadata: tableMetadata, controller: NCMainTabBarController?) { + let fileNamePath = utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocId, + fileName: metadata.fileNameView, + userId: metadata.userId, + urlBase: metadata.urlBase) + + NCAskAuthorization().askAuthorizationPhotoLibrary(controller: 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) + } + + let errorSave = NKError(errorCode: NCGlobal.shared.errorFileNotSaved, errorDescription: "_file_not_saved_cameraroll_") + + do { + if metadata.isImage { + let data = try Data(contentsOf: URL(fileURLWithPath: fileNamePath)) + PHPhotoLibrary.shared().performChanges({ + let assetRequest = PHAssetCreationRequest.forAsset() + assetRequest.addResource(with: .photo, data: data, options: nil) + }) { success, _ in + if !success { + NCContentPresenter().messageNotification("_save_selected_files_", error: errorSave, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error) + } + } + } else if metadata.isVideo { + PHPhotoLibrary.shared().performChanges({ + PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: URL(fileURLWithPath: fileNamePath)) + }) { success, _ in + if !success { + NCContentPresenter().messageNotification("_save_selected_files_", error: errorSave, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error) + } + } + } else { + NCContentPresenter().messageNotification("_save_selected_files_", error: errorSave, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error) + return + } + } catch { + NCContentPresenter().messageNotification("_save_selected_files_", error: errorSave, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error) + } + } + } + + // MARK: - Copy & Paste + + func copyPasteboard(pasteboardOcIds: [String], controller: NCMainTabBarController?) { + var items = [[String: Any]]() + let hudView = controller + + // getting file data can take some time and block the main queue + DispatchQueue.global(qos: .userInitiated).async { + var downloadMetadatas: [tableMetadata] = [] + for ocid in pasteboardOcIds { + guard let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocid) else { continue } + if let pasteboardItem = metadata.toPasteBoardItem() { + items.append(pasteboardItem) + } else { + downloadMetadatas.append(metadata) + } + } + + let processor = ParallelWorker(n: 5, titleKey: "_downloading_", totalTasks: downloadMetadatas.count, controller: controller) + for metadata in downloadMetadatas { + processor.execute { completion in + Task { + guard let metadata = await NCManageDatabase.shared.setMetadataSessionInWaitDownloadAsync(ocId: metadata.ocId, + session: NCNetworking.shared.sessionDownload, + selector: "", + sceneIdentifier: controller?.sceneIdentifier) else { + return completion() + } + + await NCNetworking.shared.downloadFile(metadata: metadata) { _ in + } progressHandler: { progress in + processor.hud.progress(progress.fractionCompleted) + } + + completion() + } + } + } + + processor.completeWork { + items.append(contentsOf: downloadMetadatas.compactMap({ $0.toPasteBoardItem() })) + UIPasteboard.general.setItems(items, options: [:]) + } + } + } + + func pastePasteboard(serverUrl: String, account: String, controller: NCMainTabBarController?) async { + var fractionCompleted: Float = 0 + let processor = ParallelWorker(n: 5, titleKey: "_status_uploading_", totalTasks: nil, controller: controller) + guard let tblAccount = await NCManageDatabase.shared.getTableAccountAsync(account: account) else { + return + } + + func uploadPastePasteboard(fileName: String, serverUrlFileName: String, fileNameLocalPath: String, serverUrl: String, completion: @escaping () -> Void) { + NextcloudKit.shared.upload(serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath, account: account) { _ in + } taskHandler: { task in + Task { + let identifier = await NCNetworking.shared.networkingTasks.createIdentifier(account: account, + path: serverUrlFileName, + name: "upload") + await NCNetworking.shared.networkingTasks.track(identifier: identifier, task: task) + } + } progressHandler: { progress in + if Float(progress.fractionCompleted) > fractionCompleted || fractionCompleted == 0 { + processor.hud.progress(progress.fractionCompleted) + fractionCompleted = Float(progress.fractionCompleted) + } + } completionHandler: { account, ocId, etag, _, _, _, error in + if error == .success && etag != nil && ocId != nil { + let toPath = self.utilityFileSystem.getDirectoryProviderStorageOcId(ocId!, + fileName: fileName, + userId: tblAccount.userId, + urlBase: tblAccount.urlBase) + self.utilityFileSystem.moveFile(atPath: fileNameLocalPath, toPath: toPath) + NCManageDatabase.shared.addLocalFile(account: account, etag: etag!, ocId: ocId!, fileName: fileName) + Task { + await NCNetworking.shared.transferDispatcher.notifyAllDelegates { delegate in + delegate.transferRequestData(serverUrl: serverUrl) + } + } + } else { + NCContentPresenter().showError(error: error) + } + fractionCompleted = 0 + completion() + } + } + + for (index, items) in UIPasteboard.general.items.enumerated() { + for item in items { + let capabilities = await NKCapabilities.shared.getCapabilities(for: account) + let results = NKFilePropertyResolver().resolve(inUTI: item.key, capabilities: capabilities) + guard let data = UIPasteboard.general.data(forPasteboardType: item.key, inItemSet: IndexSet([index]))?.first else { + continue + } + let fileName = results.name + "_" + NCPreferences().incrementalNumber + "." + results.ext + let serverUrlFileName = utilityFileSystem.createServerUrl(serverUrl: serverUrl, fileName: fileName) + let ocIdUpload = UUID().uuidString + let fileNameLocalPath = utilityFileSystem.getDirectoryProviderStorageOcId(ocIdUpload, + fileName: fileName, + userId: tblAccount.userId, + urlBase: tblAccount.urlBase) + do { try data.write(to: URL(fileURLWithPath: fileNameLocalPath)) } catch { continue } + processor.execute { completion in + uploadPastePasteboard(fileName: fileName, serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath, serverUrl: serverUrl, completion: completion) + } + } + } + processor.completeWork() + } + + // MARK: - + + func openFileViewInFolder(serverUrl: String, fileNameBlink: String?, fileNameOpen: String?, sceneIdentifier: String) { + guard let controller = SceneManager.shared.getController(sceneIdentifier: sceneIdentifier), + let navigationController = controller.viewControllers?.first as? UINavigationController + else { return } + let session = NCSession.shared.getSession(controller: controller) + var serverUrlPush = self.utilityFileSystem.getHomeServer(session: session) + + DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { + navigationController.popToRootViewController(animated: false) + controller.selectedIndex = 0 + if serverUrlPush == serverUrl, + let viewController = navigationController.topViewController as? NCFiles { + viewController.blinkCell(fileName: fileNameBlink) + viewController.openFile(fileName: fileNameOpen) + return + } + + let diffDirectory = serverUrl.replacingOccurrences(of: serverUrlPush, with: "") + var subDirs = diffDirectory.split(separator: "/") + + while serverUrlPush != serverUrl, !subDirs.isEmpty { + + guard let dir = subDirs.first else { + return + } + serverUrlPush = self.utilityFileSystem.createServerUrl(serverUrl: serverUrlPush, fileName: String(dir)) + + if let viewController = controller.navigationCollectionViewCommon.first(where: { $0.navigationController == navigationController && $0.serverUrl == serverUrlPush})?.viewController as? NCFiles, viewController.isViewLoaded { + viewController.fileNameBlink = fileNameBlink + viewController.fileNameOpen = fileNameOpen + navigationController.pushViewController(viewController, animated: false) + } else { + if let viewController: NCFiles = UIStoryboard(name: "NCFiles", bundle: nil).instantiateInitialViewController() as? NCFiles { + viewController.serverUrl = serverUrlPush + viewController.titleCurrentFolder = String(dir) + viewController.navigationItem.backButtonTitle = viewController.titleCurrentFolder + + controller.navigationCollectionViewCommon.append(NavigationCollectionViewCommon(serverUrl: serverUrlPush, navigationController: navigationController, viewController: viewController)) + + if serverUrlPush == serverUrl { + viewController.fileNameBlink = fileNameBlink + viewController.fileNameOpen = fileNameOpen + } + navigationController.pushViewController(viewController, animated: false) + } + } + subDirs.remove(at: 0) + } + } + } + + // MARK: - NCSelect + Delegate + + func dismissSelect(serverUrl: String?, metadata: tableMetadata?, type: String, items: [Any], overwrite: Bool, copy: Bool, move: Bool) {//, session: NCSession.Session) { + if let destination = serverUrl, !items.isEmpty { + if copy { + for case let metadata as tableMetadata in items { + if metadata.status != NCGlobal.shared.metadataStatusNormal, metadata.status != NCGlobal.shared.metadataStatusWaitCopy { + continue + } + + NCNetworking.shared.copyMetadata(metadata, destination: destination, overwrite: overwrite) + } + + } else if move { + for case let metadata as tableMetadata in items { + if metadata.status != NCGlobal.shared.metadataStatusNormal, metadata.status != NCGlobal.shared.metadataStatusWaitMove { + continue + } + + NCNetworking.shared.moveMetadata(metadata, destination: destination, overwrite: overwrite) + } + } + } + } + + func openSelectView(items: [tableMetadata], controller: NCMainTabBarController?) { + let session = NCSession.shared.getSession(controller: controller) + let navigationController = UIStoryboard(name: "NCSelect", bundle: nil).instantiateInitialViewController() as? UINavigationController + let topViewController = navigationController?.topViewController as? NCSelect + var listViewController = [NCSelect]() + var copyItems: [tableMetadata] = [] + let capabilities = NCNetworking.shared.capabilities[controller?.account ?? ""] ?? NKCapabilities.Capabilities() + + for item in items { + if let fileNameError = FileNameValidator.checkFileName(item.fileNameView, account: controller?.account, capabilities: capabilities) { + controller?.present(UIAlertController.warning(message: "\(fileNameError.errorDescription) \(NSLocalizedString("_please_rename_file_", comment: ""))"), animated: true) + return + } + copyItems.append(item) + } + + let home = utilityFileSystem.getHomeServer(session: session) + var serverUrl = copyItems[0].serverUrl + + // Setup view controllers such that the current view is of the same directory the items to be copied are in + while true { + // If not in the topmost directory, create a new view controller and set correct title. + // If in the topmost directory, use the default view controller as the base. + var viewController: NCSelect? + if serverUrl != home { + viewController = UIStoryboard(name: "NCSelect", bundle: nil).instantiateViewController(withIdentifier: "NCSelect.storyboard") as? NCSelect + if viewController == nil { + return + } + viewController!.titleCurrentFolder = (serverUrl as NSString).lastPathComponent + } else { + viewController = topViewController + } + guard let vc = viewController else { return } + + vc.delegate = self + vc.typeOfCommandView = .copyMove + vc.items = copyItems + vc.serverUrl = serverUrl + vc.session = session + + vc.navigationItem.backButtonTitle = vc.titleCurrentFolder + listViewController.insert(vc, at: 0) + + if serverUrl != home { + if let serverDirectoryUp = utilityFileSystem.serverDirectoryUp(serverUrl: serverUrl, home: home) { + serverUrl = serverDirectoryUp + } + } else { + break + } + } + + navigationController?.setViewControllers(listViewController, animated: false) + navigationController?.modalPresentationStyle = .formSheet + + if let navigationController = navigationController { + controller?.present(navigationController, animated: true, completion: nil) + } + } + + // MARK: - Print + + func printDocument(metadata: tableMetadata) { + + let fileNameURL = URL(fileURLWithPath: utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocId, + fileName: metadata.fileNameView, + userId: metadata.userId, + urlBase: metadata.urlBase)) + let printController = UIPrintInteractionController.shared + let printInfo = UIPrintInfo(dictionary: nil) + + printInfo.jobName = fileNameURL.lastPathComponent + printInfo.outputType = metadata.isImage ? .photo : .general + printController.printInfo = printInfo + printController.showsNumberOfCopies = true + + guard !UIPrintInteractionController.canPrint(fileNameURL) else { + printController.printingItem = fileNameURL + printController.present(animated: true) + return + } + + // can't print without data + guard let data = try? Data(contentsOf: fileNameURL) else { return } + + if let svg = SVGKImage(data: data) { + printController.printingItem = svg.uiImage + printController.present(animated: true) + return + } + + guard let text = String(data: data, encoding: .utf8) else { return } + let formatter = UISimpleTextPrintFormatter(text: text) + formatter.perPageContentInsets.top = 72 + formatter.perPageContentInsets.bottom = 72 + formatter.perPageContentInsets.left = 72 + formatter.perPageContentInsets.right = 72 + printController.printFormatter = formatter + printController.present(animated: true) + } +} + +fileprivate extension tableMetadata { + func toPasteBoardItem() -> [String: Any]? { + // Get Data + let fileUrl = URL(fileURLWithPath: NCUtilityFileSystem().getDirectoryProviderStorageOcId(ocId, + fileName: fileNameView, + userId: userId, + urlBase: urlBase)) + guard NCUtilityFileSystem().fileProviderStorageExists(self), + let data = try? Data(contentsOf: fileUrl) else { return nil } + + // Determine the UTI for the file + guard let fileUTI = UTType(filenameExtension: fileExtension)?.identifier else { return nil } + + // Pasteboard item + return [fileUTI: data] + } +} diff --git a/iOSClient/Scan document/PasswordInputField.swift b/iOSClient/Scan document/PasswordInputField.swift new file mode 100644 index 0000000000..43117f09f3 --- /dev/null +++ b/iOSClient/Scan document/PasswordInputField.swift @@ -0,0 +1,73 @@ +// +// PasswordInputField.swift +// Nextcloud +// +// Created by Sumit on 10/06/21. +// Copyright © 2021 Marino Faggiana. All rights reserved. +// + +import Foundation +import XLForm + +class PasswordInputField: XLFormBaseCell,UITextFieldDelegate { + + @IBOutlet weak var fileNameInputTextField: UITextField! + @IBOutlet weak var separatorBottom: UIView! + + override func awakeFromNib() { + super.awakeFromNib() + // Initialization code + fileNameInputTextField.isSecureTextEntry = true + fileNameInputTextField.delegate = self + separatorBottom.backgroundColor = NCBrandColor.shared.systemGray4 + self.selectionStyle = .none + } + + override func setSelected(_ selected: Bool, animated: Bool) { + super.setSelected(selected, animated: animated) + + // Configure the view for the selected state + } + + override func configure() { + super.configure() + // fileNameInputTextField.isEnabled = false + + } + + override func update() { + super.update() + } + + func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { + + if fileNameInputTextField == textField { + if let rowDescriptor = rowDescriptor, let text = self.fileNameInputTextField.text { + + if (text + " ").isEmpty == false { + rowDescriptor.value = self.fileNameInputTextField.text! + string + } else { + rowDescriptor.value = nil + } + } + } + + self.formViewController().textField(textField, shouldChangeCharactersIn: range, replacementString: string) + + return true + } + + func textFieldShouldReturn(_ textField: UITextField) -> Bool { + self.formViewController()?.textFieldShouldReturn(fileNameInputTextField) + return true + } + + func textFieldShouldClear(_ textField: UITextField) -> Bool { + self.formViewController()?.textFieldShouldClear(fileNameInputTextField) + return true + } + + override class func formDescriptorCellHeight(for rowDescriptor: XLFormRowDescriptor!) -> CGFloat { + return 45 + } +} diff --git a/iOSClient/Scan document/PasswordInputField.xib b/iOSClient/Scan document/PasswordInputField.xib new file mode 100644 index 0000000000..26914e0760 --- /dev/null +++ b/iOSClient/Scan document/PasswordInputField.xib @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/iOSClient/Share/Advanced/DownloadLimit/DownloadLimitViewModel.swift b/iOSClient/Share/Advanced/DownloadLimit/DownloadLimitViewModel.swift index a949484cae..4d7b7d54f0 100644 --- a/iOSClient/Share/Advanced/DownloadLimit/DownloadLimitViewModel.swift +++ b/iOSClient/Share/Advanced/DownloadLimit/DownloadLimitViewModel.swift @@ -20,3 +20,19 @@ enum DownloadLimitViewModel { /// case limited(limit: Int, count: Int) } + +extension DownloadLimitViewModel { + var limit: Int? { + if case let .limited(limit, _) = self { + return limit + } + return nil + } + + var count: Int? { + if case let .limited(_, count) = self { + return count + } + return nil + } +} diff --git a/iOSClient/Share/Advanced/DownloadLimit/NCShareDownloadLimitViewController.swift b/iOSClient/Share/Advanced/DownloadLimit/NCShareDownloadLimitViewController.swift index f21e12f356..e3d89e6fc5 100644 --- a/iOSClient/Share/Advanced/DownloadLimit/NCShareDownloadLimitViewController.swift +++ b/iOSClient/Share/Advanced/DownloadLimit/NCShareDownloadLimitViewController.swift @@ -16,14 +16,19 @@ class NCShareDownloadLimitViewController: UIViewController, NCShareNavigationTit public var shareDownloadLimitTableViewControllerDelegate: NCShareDownloadLimitTableViewControllerDelegate? @IBOutlet var headerContainerView: UIView! +// private var headerView: NCShareAdvancePermissionHeader? override func viewDidLoad() { super.viewDidLoad() self.setNavigationTitle() +// NotificationCenter.default.addObserver(self, selector: #selector(handleShareCountsUpdate), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterShareCountsUpdated), object: nil) + // Set up header view. +// setupHeaderView() - guard let headerView = (Bundle.main.loadNibNamed("NCShareHeader", owner: self, options: nil)?.first as? NCShareHeader) else { return } + guard let headerView = (Bundle.main.loadNibNamed("NCShareAdvancePermissionHeader", owner: self, options: nil)?.first as? NCShareAdvancePermissionHeader) else { return } +// guard let headerView = (Bundle.main.loadNibNamed("NCShareHeader", owner: self, options: nil)?.first as? NCShareHeader) else { return } headerContainerView.addSubview(headerView) headerView.frame = headerContainerView.frame headerView.translatesAutoresizingMaskIntoConstraints = false @@ -36,7 +41,7 @@ class NCShareDownloadLimitViewController: UIViewController, NCShareNavigationTit // End editing of inputs when the user taps anywhere else. - let tapGesture = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard(_:))) + let tapGesture = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard)) view.addGestureRecognizer(tapGesture) } @@ -51,7 +56,38 @@ class NCShareDownloadLimitViewController: UIViewController, NCShareNavigationTit tableViewController.share = share } - @objc private func dismissKeyboard(_ sender: Any?) { + @objc private func dismissKeyboard() { view.endEditing(true) } + +// // MARK: - Header +// +// private func setupHeaderView() { +// guard headerView == nil else { return } // Prevent multiple creations +// guard let view = Bundle.main.loadNibNamed("NCShareAdvancePermissionHeader", owner: self, options: nil)?.first as? NCShareAdvancePermissionHeader else { return } +// +// headerView = view +// headerContainerView.addSubview(view) +// +// // Auto Layout +// view.translatesAutoresizingMaskIntoConstraints = false +// NSLayoutConstraint.activate([ +// view.topAnchor.constraint(equalTo: headerContainerView.topAnchor), +// view.bottomAnchor.constraint(equalTo: headerContainerView.bottomAnchor), +// view.leadingAnchor.constraint(equalTo: headerContainerView.leadingAnchor), +// view.trailingAnchor.constraint(equalTo: headerContainerView.trailingAnchor) +// ]) +// +// // Initial setup +// headerView?.setupUI(with: metadata) +// } +// +// @objc private func handleShareCountsUpdate(notification: Notification) { +// guard let userInfo = notification.userInfo, +// let links = userInfo["links"] as? Int, +// let emails = userInfo["emails"] as? Int else { return } +// +// // Just update, don’t recreate +// headerView?.setupUI(with: metadata, linkCount: links, emailCount: emails) +// } } diff --git a/iOSClient/Share/Advanced/NCFilePermissionCell.swift b/iOSClient/Share/Advanced/NCFilePermissionCell.swift new file mode 100644 index 0000000000..4e5ec77f72 --- /dev/null +++ b/iOSClient/Share/Advanced/NCFilePermissionCell.swift @@ -0,0 +1,91 @@ +// +// NCFilePermissionCell.swift +// Nextcloud +// +// Created by T-systems on 17/08/21. +// Copyright © 2021 Marino Faggiana. All rights reserved. +// + +import UIKit + +class NCFilePermissionCell: XLFormButtonCell { + + @IBOutlet weak var seperator: UIView! + @IBOutlet weak var titleLabel: UILabel! + @IBOutlet weak var imageCheck: UIImageView! + @IBOutlet weak var seperatorBelow: UIView! + @IBOutlet weak var seperatorBelowFull: UIView! + @IBOutlet weak var titleLabelBottom: UILabel! + + override func awakeFromNib() { + super.awakeFromNib() + self.selectionStyle = .none + self.backgroundColor = NCBrandColor.shared.secondarySystemGroupedBackground + self.titleLabel.textColor = NCBrandColor.shared.label + NotificationCenter.default.addObserver(self, selector: #selector(changeTheming), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterChangeTheming), object: nil) + } + + @objc func changeTheming() { + self.backgroundColor = NCBrandColor.shared.secondarySystemGroupedBackground + self.titleLabel.textColor = NCBrandColor.shared.label + self.titleLabelBottom.textColor = NCBrandColor.shared.iconColor + } + + override func configure() { + super.configure() + } + + + override func update() { + super.update() + self.selectionStyle = .none + if rowDescriptor.tag == "NCFilePermissionCellSharing" || rowDescriptor.tag == "NCFilePermissionCellAdvanceTxt" { + self.seperator.isHidden = true + self.seperatorBelowFull.isHidden = true + self.seperatorBelow.isHidden = true + self.titleLabel.font = UIFont.boldSystemFont(ofSize: 17) + self.titleLabelBottom.font = UIFont.boldSystemFont(ofSize: 17) + } + if rowDescriptor.tag == "kNMCFilePermissionCellEditing" { + self.seperator.isHidden = true +// self.seperatorBelowFull.isHidden = true + } + + if rowDescriptor.tag == "NCFilePermissionCellFileDrop" { + self.seperator.isHidden = true + self.seperatorBelow.isHidden = false + self.seperatorBelowFull.isHidden = true + } + + if rowDescriptor.tag == "kNMCFilePermissionEditCellEditingCanShare" { + self.seperator.isHidden = true + self.seperatorBelowFull.isHidden = false + } + + if rowDescriptor.tag == "kNMCFilePermissionCellEditingMsg" { + self.seperator.isHidden = true + self.seperatorBelow.isHidden = true + self.seperatorBelowFull.isHidden = false + } + + if rowDescriptor.tag == "kNMCFilePermissionCellFiledropMessage" { + self.seperator.isHidden = true + self.seperatorBelow.isHidden = true + self.seperatorBelowFull.isHidden = false + self.imageCheck.isHidden = true + } + } + + @objc func switchChanged(mySwitch: UISwitch) { + self.rowDescriptor.value = mySwitch.isOn + } + + override func formDescriptorCellDidSelected(withForm controller: XLFormViewController!) { + self.selectionStyle = .none + } + + override class func formDescriptorCellHeight(for rowDescriptor: XLFormRowDescriptor!) -> CGFloat { + return 44.0 + } + +} diff --git a/iOSClient/Share/Advanced/NCFilePermissionCell.xib b/iOSClient/Share/Advanced/NCFilePermissionCell.xib new file mode 100644 index 0000000000..e40c22e14d --- /dev/null +++ b/iOSClient/Share/Advanced/NCFilePermissionCell.xib @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/iOSClient/Share/Advanced/NCFilePermissionEditCell.swift b/iOSClient/Share/Advanced/NCFilePermissionEditCell.swift new file mode 100644 index 0000000000..b32d66a74f --- /dev/null +++ b/iOSClient/Share/Advanced/NCFilePermissionEditCell.swift @@ -0,0 +1,176 @@ +// +// NCFilePermissionEditCell.swift +// Nextcloud +// +// Created by T-systems on 10/08/21. +// Copyright © 2021 Marino Faggiana. All rights reserved. +// + +import UIKit + +class NCFilePermissionEditCell: XLFormBaseCell, UITextFieldDelegate { + + @IBOutlet weak var seperator: UIView! + @IBOutlet weak var seperatorMiddle: UIView! + @IBOutlet weak var seperatorBottom: UIView! + @IBOutlet weak var titleLabel: UILabel! + @IBOutlet weak var switchControl: UISwitch! + @IBOutlet weak var cellTextField: UITextField! + @IBOutlet weak var buttonLinkLabel: UIButton! + let datePicker = UIDatePicker() + var expirationDateText: String! + var expirationDate: NSDate! + + override func awakeFromNib() { + super.awakeFromNib() + self.cellTextField.delegate = self + self.cellTextField.isEnabled = false + self.selectionStyle = .none + switchControl.addTarget(self, action: #selector(switchChanged), for: UIControl.Event.valueChanged) + self.backgroundColor = NCBrandColor.shared.secondarySystemGroupedBackground + self.titleLabel.textColor = NCBrandColor.shared.label + self.cellTextField.attributedPlaceholder = NSAttributedString(string: "", + attributes: [NSAttributedString.Key.foregroundColor: NCBrandColor.shared.fileFolderName]) + self.cellTextField.textColor = NCBrandColor.shared.singleTitleColorButton + NotificationCenter.default.addObserver(self, selector: #selector(changeTheming), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterChangeTheming), object: nil) + } + + @objc func changeTheming() { + self.backgroundColor = NCBrandColor.shared.secondarySystemGroupedBackground + self.titleLabel.textColor = NCBrandColor.shared.iconColor + } + + override func configure() { + super.configure() + } + + override func update() { + super.update() + + if rowDescriptor.tag == "kNMCFilePermissionCellEditingCanShare" { + self.seperatorMiddle.isHidden = true + self.seperatorBottom.isHidden = true + self.cellTextField.isHidden = true + } + if rowDescriptor.tag == "kNMCFilePermissionEditCellLinkLabel" { + self.switchControl.isHidden = true + self.cellTextField.isEnabled = true + self.seperatorBottom.isHidden = true + } + if rowDescriptor.tag == "kNMCFilePermissionEditCellLinkLabel" { + self.switchControl.isHidden = true + } + + if rowDescriptor.tag == "kNMCFilePermissionEditCellExpiration" { + self.seperator.isHidden = true + setDatePicker(sender: self.cellTextField) + } + + if rowDescriptor.tag == "kNMCFilePermissionEditPasswordCellWithText" { + self.seperatorMiddle.isHidden = true + self.seperator.isHidden = true + } + + if rowDescriptor.tag == "kNMCFilePermissionEditCellHideDownload" { + self.seperator.isHidden = true + self.seperatorMiddle.isHidden = true + } + + if rowDescriptor.tag == "kNMCFilePermissionEditCellEditingCanShare" { + self.seperator.isHidden = true + self.seperatorBottom.isHidden = true + } + } + + @objc func switchChanged(mySwitch: UISwitch) { + let isOn = mySwitch.isOn + if isOn { + //on + self.rowDescriptor.value = isOn + self.cellTextField.isEnabled = true + cellTextField.delegate = self + } else { + self.rowDescriptor.value = isOn + self.cellTextField.isEnabled = false + if rowDescriptor.tag == "kNMCFilePermissionEditCellExpiration" || rowDescriptor.tag == "kNMCFilePermissionEditCellPassword" { + self.cellTextField.text = "" + } + } + if rowDescriptor.tag == "kNMCFilePermissionEditPasswordCellWithText" { + seperatorBottom.isHidden = isOn + seperatorMiddle.isHidden = !isOn + } + if rowDescriptor.tag == "kNMCFilePermissionEditCellExpiration" { + seperatorBottom.isHidden = isOn + seperatorMiddle.isHidden = !isOn + } + } + + func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { + if self.cellTextField == textField { + if let rowDescriptor = rowDescriptor, let text = self.cellTextField.text { + + if (text + " ").isEmpty == false { + rowDescriptor.value = self.cellTextField.text! + string + } else { + rowDescriptor.value = nil + } + } + } + + self.formViewController().textField(textField, shouldChangeCharactersIn: range, replacementString: string) + return true + } + + func textFieldShouldReturn(_ textField: UITextField) -> Bool { + self.formViewController()?.textFieldShouldReturn(textField) + return true + } + + func textFieldShouldClear(_ textField: UITextField) -> Bool { + self.formViewController()?.textFieldShouldClear(textField) + return true + } + + override class func formDescriptorCellHeight(for rowDescriptor: XLFormRowDescriptor!) -> CGFloat { + return 30 + } + + override func formDescriptorCellDidSelected(withForm controller: XLFormViewController!) { + self.selectionStyle = .none + } + + func setDatePicker(sender: UITextField) { + //Format Date + datePicker.datePickerMode = .date + datePicker.minimumDate = Date() + //ToolBar + let toolbar = UIToolbar(); + toolbar.sizeToFit() + let doneButton = UIBarButtonItem(title: NSLocalizedString("_done_", comment: ""), style: .plain, target: self, action: #selector(doneDatePicker)); + let spaceButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.flexibleSpace, target: nil, action: nil) + let cancelButton = UIBarButtonItem(title: NSLocalizedString("_cancel_", comment: ""), style: .plain, target: self, action: #selector(cancelDatePicker)); + + toolbar.setItems([doneButton,spaceButton,cancelButton], animated: false) + + sender.inputAccessoryView = toolbar + sender.inputView = datePicker + } + + @objc func doneDatePicker() { + let dateFormatter = DateFormatter() + dateFormatter.formatterBehavior = .behavior10_4 + dateFormatter.dateStyle = .medium + self.expirationDateText = dateFormatter.string(from: datePicker.date as Date) + + dateFormatter.dateFormat = "YYYY-MM-dd HH:mm:ss" + self.expirationDate = datePicker.date as NSDate + self.cellTextField.text = self.expirationDateText + self.rowDescriptor.value = self.expirationDate + self.cellTextField.endEditing(true) + } + + @objc func cancelDatePicker() { + self.cellTextField.endEditing(true) + } +} diff --git a/iOSClient/Share/Advanced/NCFilePermissionEditCell.xib b/iOSClient/Share/Advanced/NCFilePermissionEditCell.xib new file mode 100644 index 0000000000..2a7aa3ac63 --- /dev/null +++ b/iOSClient/Share/Advanced/NCFilePermissionEditCell.xib @@ -0,0 +1,108 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/iOSClient/Share/Advanced/NCShareAdvancePermission.swift b/iOSClient/Share/Advanced/NCShareAdvancePermission.swift index f07ae37f0c..74527cef4c 100644 --- a/iOSClient/Share/Advanced/NCShareAdvancePermission.swift +++ b/iOSClient/Share/Advanced/NCShareAdvancePermission.swift @@ -25,8 +25,104 @@ import UIKit import NextcloudKit import SVGKit import CloudKit +import XLForm + +class NCShareAdvancePermission: XLFormViewController, NCShareAdvanceFotterDelegate, NCShareNavigationTitleSetting { + func dismissShareAdvanceView(shouldSave: Bool) { + + guard shouldSave else { + guard oldTableShare?.hasChanges(comparedTo: share) != false else { + navigationController?.popViewController(animated: true) + return + } + + let alert = UIAlertController( + title: NSLocalizedString("_cancel_request_", comment: ""), + message: NSLocalizedString("_discard_changes_info_", comment: ""), + preferredStyle: .alert) + + alert.addAction(UIAlertAction( + title: NSLocalizedString("_discard_changes_", comment: ""), + style: .destructive, + handler: { _ in self.navigationController?.popViewController(animated: true) })) + + alert.addAction(UIAlertAction(title: NSLocalizedString("_continue_editing_", comment: ""), style: .default)) + self.present(alert, animated: true) + + return + } + + if shouldSave { + self.oldTableShare?.permissions = self.permission ?? (self.oldTableShare?.permissions ?? 0) + self.share.permissions = self.permission ?? (self.oldTableShare?.permissions ?? 0) + if isNewShare { + let storyboard = UIStoryboard(name: "NCShare", bundle: nil) + guard let viewNewUserComment = storyboard.instantiateViewController(withIdentifier: "NCShareNewUserAddComment") as? NCShareNewUserAddComment else { return } + viewNewUserComment.metadata = self.metadata + viewNewUserComment.share = self.share + viewNewUserComment.networking = self.networking + self.navigationController?.pushViewController(viewNewUserComment, animated: true) + } else { + if let downloadSwitchCell = getDownloadLimitSwitchCell() { + let isDownloadLimitOn = downloadSwitchCell.switchControl.isOn + if !isDownloadLimitOn { + setDownloadLimit(deleteLimit: true, limit: String(defaultLimit)) + } else { + let downloadLimitInputCell = getDownloadLimitInputCell() +// let enteredDownloadLimit = downloadLimitInputCell?.cellTextField.text ?? "" + let enteredDownloadLimit = downloadLimitInputCell?.cellTextField.text?.trimmingCharacters(in: .whitespacesAndNewlines) ?? "" + +// if enteredDownloadLimit.isEmpty { +// showDownloadLimitError(message: NSLocalizedString("_share_download_limit_alert_empty_", comment: "")) +// return +// } +// if let num = Int(enteredDownloadLimit), num < 1 { +// showDownloadLimitError(message: NSLocalizedString("_share_download_limit_alert_zero_", comment: "")) +// return +// } +// +// self.downloadLimit = .limited(limit: Int(enteredDownloadLimit)!, count: downloadLimit.count ?? 0) + + // Case 1: Empty input + if enteredDownloadLimit.isEmpty { + showDownloadLimitError(message: NSLocalizedString("_share_download_limit_alert_empty_", comment: "")) + return + } + + // Case 2: Non-numeric or too large + guard let num = Int(enteredDownloadLimit) else { + // Input is either not a number or exceeds Int range + showDownloadLimitError(message: NSLocalizedString("_share_download_limit_alert_invalid_", comment: "")) + return + } + + // Case 3: Zero or negative + if num < 1 { + showDownloadLimitError(message: NSLocalizedString("_share_download_limit_alert_zero_", comment: "")) + return + } + + // ✅ Safe assignment + self.downloadLimit = .limited(limit: num, count: downloadLimit.count ?? 0) + setDownloadLimit(deleteLimit: false, limit: enteredDownloadLimit) + updateDownloadLimitUI() + } + } + + if let expiryDateSwitchCell = getExpiryDateSwitchCell() { + let isExpiryDateOn = expiryDateSwitchCell.switchControl.isOn + if !isExpiryDateOn { + share.expirationDate = nil + } + } + networking?.updateShare(share, downloadLimit: self.downloadLimit) + navigationController?.popViewController(animated: true) + } + } else { + navigationController?.popViewController(animated: true) + } + } -class NCShareAdvancePermission: UITableViewController, NCShareAdvanceFotterDelegate, NCShareNavigationTitleSetting { let database = NCManageDatabase.shared var oldTableShare: tableShare? @@ -56,32 +152,60 @@ class NCShareAdvancePermission: UITableViewController, NCShareAdvanceFotterDeleg var shareConfig: NCShareConfig! var networking: NCShareNetworking? - + let tableViewBottomInset: CGFloat = 80.0 + lazy var shareType: Int = { + isNewShare ? share.shareType : oldTableShare?.shareType ?? NCShareCommon().SHARE_TYPE_USER + }() + static let displayDateFormat = "dd. MMM. yyyy" + var permission: Int? + + /// + /// Default value for limits as possibly provided by the server capabilities. + /// + var defaultLimit: Int { + NCCapabilities.shared.getCapabilities(account: metadata.account).capabilityFileSharingDownloadLimitDefaultLimit + } + override func viewDidLoad() { super.viewDidLoad() self.shareConfig = NCShareConfig(parentMetadata: metadata, share: share) - - // Only persisted shares have tokens which are provided by the server. - // A download limit requires a token to exist. - // Hence it can only be looked up if the share is already persisted at this point. - if isNewShare == false { - if let persistedShare = share as? tableShare { - do { - if let limit = try database.getDownloadLimit(byAccount: metadata.account, shareToken: persistedShare.token) { - self.downloadLimit = .limited(limit: limit.limit, count: limit.count) - } - } catch { - nkLog(error: "There was an error while fetching the download limit for share with token \(persistedShare.token)!") - } + self.setNavigationTitle() + // disbale pull to dimiss + isModalInPresentation = true + self.tableView.separatorStyle = UITableViewCell.SeparatorStyle.none + self.permission = oldTableShare?.permissions + if !isNewShare { + Task { + await getDownloadLimit() } } + initializeForm() + changeTheming() +// getDownloadLimit() +// Task { +// await getDownloadLimit() +// } + +// // Only persisted shares have tokens which are provided by the server. +// // A download limit requires a token to exist. +// // Hence it can only be looked up if the share is already persisted at this point. +// if isNewShare == false { +// if let persistedShare = share as? tableShare { +// do { +// if let limit = try database.getDownloadLimit(byAccount: metadata.account, shareToken: persistedShare.token) { +// self.downloadLimit = .limited(limit: limit.limit, count: limit.count) +// self.updateDownloadLimitUI() +// } +// } catch { +// NextcloudKit.shared.nkCommonInstance.writeLog("[ERROR] There was an error while fetching the download limit for share with token \(persistedShare.token)!") +// } +// } +// } - tableView.estimatedRowHeight = tableView.rowHeight - tableView.rowHeight = UITableView.automaticDimension - self.setNavigationTitle() - self.navigationItem.hidesBackButton = true - // disable pull to dimiss - isModalInPresentation = true + NotificationCenter.default.addObserver(self, selector: #selector(changeTheming), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterChangeTheming), object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(_:)), name: UIResponder.keyboardWillShowNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(_:)), name: UIResponder.keyboardWillHideNotification, object: nil) +// NotificationCenter.default.addObserver(self, selector: #selector(handleShareCountsUpdate), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterShareCountsUpdated), object: nil) } override func viewWillLayoutSubviews() { @@ -90,126 +214,818 @@ class NCShareAdvancePermission: UITableViewController, NCShareAdvanceFotterDeleg setupHeaderView() setupFooterView() } + +// override func viewWillLayoutSubviews() { +// super.viewWillLayoutSubviews() +// +// if tableView.tableHeaderView == nil { +// setupHeaderView() +// } +// if tableView.tableFooterView == nil { +// setupFooterView() +// } +// } + + override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { + if (UIDevice.current.userInterfaceIdiom == .phone), UIDevice().hasNotch { + let isLandscape = UIDevice.current.orientation.isLandscape + let tableViewWidth = isLandscape ? view.bounds.width - 80 : view.bounds.width + tableView.frame = CGRect(x: isLandscape ? 40 : 0, y: tableView.frame.minY, width: tableViewWidth, height: tableView.bounds.height) + tableView.layoutIfNeeded() + } + } + @objc func keyboardWillShow(_ notification: Notification) { + guard let userInfo = notification.userInfo else { return } + + // Use the end frame for the keyboard + if let keyboardFrame = (userInfo[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue { + + // Adjust the content inset of the table view + let keyboardHeight = keyboardFrame.height + let extraPadding: CGFloat = 60 + + // Animate the content inset change to match the keyboard's animation + UIView.animate(withDuration: 0.3, animations: { + self.tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: keyboardHeight + extraPadding, right: 0) + self.tableView.scrollIndicatorInsets = self.tableView.contentInset + }) + } + } + + @objc func keyboardWillHide(_ notification: Notification) { + guard let userInfo = notification.userInfo else { return } + + // Reset the content inset when the keyboard is hidden + if let _ = (userInfo[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue) { + UIView.animate(withDuration: 0.3, animations: { + self.tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: self.tableViewBottomInset, right: 0) + self.tableView.scrollIndicatorInsets = self.tableView.contentInset + }) + } + } + + @objc func changeTheming() { + tableView.backgroundColor = NCBrandColor.shared.secondarySystemGroupedBackground + self.view.backgroundColor = NCBrandColor.shared.secondarySystemGroupedBackground + self.navigationController?.navigationBar.tintColor = NCBrandColor.shared.customer + tableView.reloadData() + } + func setupFooterView() { guard let footerView = (Bundle.main.loadNibNamed("NCShareAdvancePermissionFooter", owner: self, options: nil)?.first as? NCShareAdvancePermissionFooter) else { return } footerView.setupUI(delegate: self, account: metadata.account) // tableFooterView can't use auto layout directly - let container = UIView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: 120)) - container.addSubview(footerView) - tableView.tableFooterView = container + footerView.frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: 100) + self.view.addSubview(footerView) footerView.translatesAutoresizingMaskIntoConstraints = false - footerView.bottomAnchor.constraint(equalTo: container.bottomAnchor).isActive = true - footerView.heightAnchor.constraint(equalTo: container.heightAnchor).isActive = true - footerView.widthAnchor.constraint(equalTo: container.widthAnchor).isActive = true + footerView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true + footerView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true + footerView.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true + footerView.heightAnchor.constraint(equalToConstant: 100).isActive = true + tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: tableViewBottomInset, right: 0) + } func setupHeaderView() { - guard let headerView = (Bundle.main.loadNibNamed("NCShareHeader", owner: self, options: nil)?.first as? NCShareHeader) else { return } + guard let headerView = (Bundle.main.loadNibNamed("NCShareAdvancePermissionHeader", owner: self, options: nil)?.first as? NCShareAdvancePermissionHeader) else { return } headerView.setupUI(with: metadata) - - let container = UIView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: 220)) - container.addSubview(headerView) - tableView.tableHeaderView = container + headerView.ocId = metadata.ocId + headerView.frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: 190) + self.tableView.tableHeaderView = headerView headerView.translatesAutoresizingMaskIntoConstraints = false - headerView.topAnchor.constraint(equalTo: container.topAnchor).isActive = true - headerView.heightAnchor.constraint(equalTo: container.heightAnchor).isActive = true - headerView.widthAnchor.constraint(equalTo: container.widthAnchor).isActive = true + headerView.heightAnchor.constraint(equalToConstant: 190).isActive = true + headerView.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true } - override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { - if section == 0 { - return NSLocalizedString("_custom_permissions_", comment: "") - } else if section == 1 { - return NSLocalizedString("_advanced_", comment: "") - } else { return nil } +// @objc private func handleShareCountsUpdate(notification: Notification) { +// guard let userInfo = notification.userInfo, +// let links = userInfo["links"] as? Int, +// let emails = userInfo["emails"] as? Int else { +// return +// } +// +// // Update existing header if possible +// if let header = tableView.tableHeaderView as? NCShareAdvancePermissionHeader { +// header.setupUI(with: metadata, linkCount: links, emailCount: emails) +// } else { +// // Fallback: re-create header if missing +// setupHeaderView(linkCount: links, emailCount: emails) +// } +// } +// +// func setupHeaderView(linkCount: Int = 0, emailCount: Int = 0) { +// guard let headerView = Bundle.main.loadNibNamed("NCShareAdvancePermissionHeader", owner: self, options: nil)?.first as? NCShareAdvancePermissionHeader else { +// return +// } +// +// headerView.setupUI(with: metadata, linkCount: linkCount, emailCount: emailCount) +// headerView.ocId = metadata.ocId +// headerView.frame = CGRect(x: 0, y: 0, width: view.frame.size.width, height: 190) +// +// tableView.tableHeaderView = headerView +// } + + func initializeForm() { + let form : XLFormDescriptor + var section : XLFormSectionDescriptor + var row : XLFormRowDescriptor + let permissions = NCPermissions() + form = XLFormDescriptor(title: "Other Cells") + + //Sharing + section = XLFormSectionDescriptor.formSection(withTitle: "") + XLFormViewController.cellClassesForRowDescriptorTypes()["kNMCFilePermissionCell"] = NCFilePermissionCell.self + row = XLFormRowDescriptor(tag: "NCFilePermissionCellSharing", rowType: "kNMCFilePermissionCell", title: "") + row.cellConfig["titleLabel.text"] = NSLocalizedString("_sharing_", comment: "") + row.height = 44 + section.addFormRow(row) + + //PERMISSION + XLFormViewController.cellClassesForRowDescriptorTypes()["kNMCShareHeaderCustomCell"] = NCShareHeaderCustomCell.self + row = XLFormRowDescriptor(tag: "kNMCShareHeaderCustomCell", rowType: "kNMCShareHeaderCustomCell", title: NSLocalizedString("_PERMISSIONS_", comment: "")) + row.height = 26 + row.cellConfig["titleLabel.text"] = NSLocalizedString("_PERMISSIONS_", comment: "") + section.addFormRow(row) + + //read only + XLFormViewController.cellClassesForRowDescriptorTypes()["kNMCFilePermissionCell"] = NCFilePermissionCell.self + row = XLFormRowDescriptor(tag: "NCFilePermissionCellRead", rowType: "kNMCFilePermissionCell", title: NSLocalizedString("_PERMISSIONS_", comment: "")) + row.cellConfig["titleLabel.text"] = NSLocalizedString("_share_read_only_", comment: "") + row.height = 44 + + if let permission = self.permission, !permissions.isAnyPermissionToEdit(permission), permission != permissions.permissionCreateShare { + row.cellConfig["imageCheck.image"] = UIImage(named: "success")!.image(color: NCBrandColor.shared.customer, size: 25.0) + } + if isNewShare { + row.cellConfig["imageCheck.image"] = UIImage(named: "success")!.image(color: NCBrandColor.shared.customer, size: 25.0) + self.permission = permissions.permissionReadShare + } + section.addFormRow(row) + + //editing + XLFormViewController.cellClassesForRowDescriptorTypes()["kNMCFilePermissionCell"] = NCFilePermissionCell.self + + row = XLFormRowDescriptor(tag: "kNMCFilePermissionCellEditing", rowType: "kNMCFilePermissionCell", title: NSLocalizedString("_PERMISSIONS_", comment: "")) + row.cellConfig["titleLabel.text"] = NSLocalizedString("_share_allow_editing_", comment: "") + row.height = 44 + if let permission = self.permission { + if permissions.isAnyPermissionToEdit(permission), permission != permissions.permissionCreateShare { + row.cellConfig["imageCheck.image"] = UIImage(named: "success")!.image(color: NCBrandColor.shared.customer, size: 25.0) + } + } + let enabled = NCShareCommon().isEditingEnabled(isDirectory: metadata.directory, fileExtension: metadata.fileExtension, shareType: shareType) || checkIsCollaboraFile() + row.cellConfig["titleLabel.textColor"] = NCBrandColor.shared.label + section.addFormRow(row) + + if !enabled { + row = XLFormRowDescriptor(tag: "kNMCFilePermissionCellEditingMsg", rowType: "kNMCFilePermissionCell", title: NSLocalizedString("_PERMISSIONS_", comment: "")) + row.cellConfig["titleLabel.text"] = NSLocalizedString("share_editing_message", comment: "") + row.cellConfig["titleLabel.textColor"] = NCBrandColor.shared.gray60 + row.height = 80 + section.addFormRow(row) + } + + //file drop + if isFileDropOptionVisible() { + XLFormViewController.cellClassesForRowDescriptorTypes()["kNMCFilePermissionCell"] = NCFilePermissionCell.self + row = XLFormRowDescriptor(tag: "NCFilePermissionCellFileDrop", rowType: "kNMCFilePermissionCell", title: NSLocalizedString("_PERMISSIONS_", comment: "")) + row.cellConfig["titleLabel.text"] = NSLocalizedString("_share_file_drop_", comment: "") + if self.permission == permissions.permissionCreateShare { + row.cellConfig["imageCheck.image"] = UIImage(named: "success")!.image(color: NCBrandColor.shared.customer, size: 25.0) + } + row.height = 44 + section.addFormRow(row) + + //sammelbox message + XLFormViewController.cellClassesForRowDescriptorTypes()["kNMCFilePermissionCell"] = NCFilePermissionCell.self + + row = XLFormRowDescriptor(tag: "kNMCFilePermissionCellFiledropMessage", rowType: "kNMCFilePermissionCell", title: NSLocalizedString("_PERMISSIONS_", comment: "")) + row.cellConfig["titleLabel.text"] = NSLocalizedString("_file_drop_message_", comment: "") + row.cellConfig["titleLabel.textColor"] = NCBrandColor.shared.gray60 +// row.cellConfig["titleLabel.textColor"] = NCBrandColor.shared.label + row.cellConfig["imageCheck.image"] = UIImage() + row.height = 84 + section.addFormRow(row) + } + + //empty cell + XLFormViewController.cellClassesForRowDescriptorTypes()["kNMCXLFormBaseCell"] = NCSeparatorCell.self + row = XLFormRowDescriptor(tag: "kNMCXLFormBaseCell", rowType: "kNMCXLFormBaseCell", title: NSLocalizedString("", comment: "")) + row.height = 16 + section.addFormRow(row) + + //ADVANCE PERMISSION + XLFormViewController.cellClassesForRowDescriptorTypes()["kNMCFilePermissionCell"] = NCFilePermissionCell.self + + row = XLFormRowDescriptor(tag: "NCFilePermissionCellAdvanceTxt", rowType: "kNMCFilePermissionCell", title: NSLocalizedString("_PERMISSIONS_", comment: "")) + row.cellConfig["titleLabel.text"] = NSLocalizedString("_advance_permissions_", comment: "") + row.height = 52 + section.addFormRow(row) + + if isLinkShare() { + //link label section header + + // Custom Link label + XLFormViewController.cellClassesForRowDescriptorTypes()["kNCShareTextInputCell"] = NCShareTextInputCell.self + row = XLFormRowDescriptor(tag: "kNCShareTextInputCellCustomLinkField", rowType: "kNCShareTextInputCell", title: "") + row.cellConfig["cellTextField.placeholder"] = NSLocalizedString("_custom_link_label", comment: "") + row.cellConfig["cellTextField.text"] = oldTableShare?.label + row.cellConfig["cellTextField.textAlignment"] = NSTextAlignment.left.rawValue + row.cellConfig["cellTextField.font"] = UIFont.systemFont(ofSize: 15.0) + row.cellConfig["cellTextField.textColor"] = NCBrandColor.shared.label + row.height = 44 + section.addFormRow(row) + } + + //can reshare + if isCanReshareOptionVisible() { + XLFormViewController.cellClassesForRowDescriptorTypes()["kNMCFilePermissionEditCell"] = NCFilePermissionEditCell.self + + row = XLFormRowDescriptor(tag: "kNMCFilePermissionEditCellEditingCanShare", rowType: "kNMCFilePermissionEditCell", title: "") + row.cellConfig["switchControl.onTintColor"] = NCBrandColor.shared.customer + row.cellClass = NCFilePermissionEditCell.self + row.cellConfig["titleLabel.text"] = NSLocalizedString("_share_can_reshare_", comment: "") + row.height = 44 + section.addFormRow(row) + } + + //hide download + if isHideDownloadOptionVisible() { + + XLFormViewController.cellClassesForRowDescriptorTypes()["kNMCFilePermissionEditCell"] = NCFilePermissionEditCell.self + row = XLFormRowDescriptor(tag: "kNMCFilePermissionEditCellHideDownload", rowType: "kNMCFilePermissionEditCell", title: NSLocalizedString("_PERMISSIONS_", comment: "")) + row.cellConfig["titleLabel.text"] = NSLocalizedString("_share_hide_download_", comment: "") + row.cellConfig["switchControl.onTintColor"] = NCBrandColor.shared.customer + row.cellClass = NCFilePermissionEditCell.self + row.height = 44 + section.addFormRow(row) + } + + //password + if isPasswordOptionsVisible() { + + // Set password + XLFormViewController.cellClassesForRowDescriptorTypes()["kNMCFilePermissionEditCell"] = NCFilePermissionEditCell.self + row = XLFormRowDescriptor(tag: "kNMCFilePermissionEditPasswordCellWithText", rowType: "kNMCFilePermissionEditCell", title: NSLocalizedString("_PERMISSIONS_", comment: "")) + row.cellConfig["titleLabel.text"] = NSLocalizedString("_set_password_", comment: "") + row.cellConfig["switchControl.onTintColor"] = NCBrandColor.shared.customer + row.cellClass = NCFilePermissionEditCell.self + row.height = 44 + section.addFormRow(row) + + // enter password input field + XLFormViewController.cellClassesForRowDescriptorTypes()["NMCSetPasswordCustomInputField"] = PasswordInputField.self + row = XLFormRowDescriptor(tag: "SetPasswordInputField", rowType: "NMCSetPasswordCustomInputField", title: NSLocalizedString("_filename_", comment: "")) + row.cellClass = PasswordInputField.self + row.cellConfig["fileNameInputTextField.placeholder"] = NSLocalizedString("_password_", comment: "") + row.cellConfig["fileNameInputTextField.textAlignment"] = NSTextAlignment.left.rawValue + row.cellConfig["fileNameInputTextField.font"] = UIFont.systemFont(ofSize: 15.0) + row.cellConfig["fileNameInputTextField.textColor"] = NCBrandColor.shared.label + row.cellConfig["backgroundColor"] = NCBrandColor.shared.secondarySystemGroupedBackground + row.height = 44 + +// // Add validator for min 6 characters +// guard let minLengthValidator = XLFormRegexValidator(msg: NSLocalizedString("_password_min_6_chars_", comment: "Password must be at least 6 characters"), andRegexString: "^.{6,}$") else { return <#default value#> } +// row.addValidator(minLengthValidator) + + let hasPassword = oldTableShare?.password != nil && !oldTableShare!.password.isEmpty + row.hidden = NSNumber.init(booleanLiteral: !hasPassword) + section.addFormRow(row) + } + + //expiration + + // expiry date switch + XLFormViewController.cellClassesForRowDescriptorTypes()["kNMCFilePermissionEditCell"] = NCFilePermissionEditCell.self + row = XLFormRowDescriptor(tag: "kNMCFilePermissionEditCellExpiration", rowType: "kNMCFilePermissionEditCell", title: NSLocalizedString("_share_expiration_date_", comment: "")) + row.cellConfig["titleLabel.text"] = NSLocalizedString("_share_expiration_date_", comment: "") + row.cellConfig["switchControl.onTintColor"] = NCBrandColor.shared.customer + row.cellClass = NCFilePermissionEditCell.self + row.height = 44 + section.addFormRow(row) + + // set expiry date field + XLFormViewController.cellClassesForRowDescriptorTypes()["kNCShareTextInputCell"] = NCShareTextInputCell.self + row = XLFormRowDescriptor(tag: "NCShareTextInputCellExpiry", rowType: "kNCShareTextInputCell", title: "") + row.cellClass = NCShareTextInputCell.self + row.cellConfig["cellTextField.placeholder"] = NSLocalizedString("_share_expiration_date_placeholder_", comment: "") + if !isNewShare { + if let date = oldTableShare?.expirationDate { + row.cellConfig["cellTextField.text"] = DateFormatter.shareExpDate.string(from: date as Date) + } + } + row.cellConfig["cellTextField.textAlignment"] = NSTextAlignment.left.rawValue + row.cellConfig["cellTextField.font"] = UIFont.systemFont(ofSize: 15.0) + row.cellConfig["cellTextField.textColor"] = NCBrandColor.shared.label + if let date = oldTableShare?.expirationDate { + row.cellConfig["cellTextField.text"] = DateFormatter.shareExpDate.string(from: date as Date) + } +// else { +// let nextYearTomorrow = Date.tomorrowNextYear +// row.cellConfig["cellTextField.text"] = DateFormatter.shareExpDate.string(from: nextYearTomorrow) +// share.expirationDate = nextYearTomorrow as NSDate +// } + + row.height = 44 + let hasExpiry = oldTableShare?.expirationDate != nil + row.hidden = NSNumber.init(booleanLiteral: !hasExpiry) + section.addFormRow(row) + + if isDownloadLimitVisible() { + // DownloadLimit switch + XLFormViewController.cellClassesForRowDescriptorTypes()["kNMCFilePermissionEditCell"] = NCFilePermissionEditCell.self + row = XLFormRowDescriptor(tag: "kNMCFilePermissionEditCellDownloadLimit", rowType: "kNMCFilePermissionEditCell", title: NSLocalizedString("_share_download_limit_", comment: "")) + row.cellConfig["titleLabel.text"] = NSLocalizedString("_share_download_limit_", comment: "") + row.cellConfig["switchControl.onTintColor"] = NCBrandColor.shared.customer + row.cellClass = NCFilePermissionEditCell.self + row.height = 44 + section.addFormRow(row) + + // set Download Limit field + XLFormViewController.cellClassesForRowDescriptorTypes()["kNCShareTextInputCell"] = NCShareTextInputCell.self + row = XLFormRowDescriptor(tag: "NCShareTextInputCellDownloadLimit", rowType: "kNCShareTextInputCell", title: "") + row.cellClass = NCShareTextInputCell.self + row.cellConfig["cellTextField.placeholder"] = NSLocalizedString("_share_download_limit_placeholder_", comment: "") + row.cellConfig["cellTextField.textAlignment"] = NSTextAlignment.left.rawValue + row.cellConfig["cellTextField.font"] = UIFont.systemFont(ofSize: 15.0) + row.cellConfig["cellTextField.textColor"] = NCBrandColor.shared.label + row.height = 44 + if case let .limited(limit, _) = downloadLimit { + row.hidden = NSNumber(booleanLiteral: false) + row.cellConfig["cellTextField.text"] = "\(limit)" + } else { + row.hidden = NSNumber(booleanLiteral: true) + } + section.addFormRow(row) + + XLFormViewController.cellClassesForRowDescriptorTypes()["kNMCFilePermissionCell"] = NCFilePermissionCell.self + row = XLFormRowDescriptor(tag: "kNMCDownloadLimitCell", rowType: "kNMCFilePermissionCell", title: "") + row.cellClass = NCFilePermissionCell.self + row.height = 44 + switch downloadLimit { + case .limited(_, let count): + row.cellConfig["titleLabel.text"] = NSLocalizedString("_share_remaining_download_", comment: "") + " \(count)" + row.hidden = false + default: + row.hidden = true + } + row.cellConfig["titleLabel.textColor"] = NCBrandColor.shared.systemGray + row.disabled = true + section.addFormRow(row) + } + + form.addFormSection(section) + self.form = form + } + + func reloadForm() { + self.form.delegate = nil + self.tableView.reloadData() + self.form.delegate = self + } + + func updateDownloadLimitUI() { + if let value = downloadLimit.limit { + if let downloadLimitSwitchField: XLFormRowDescriptor = self.form.formRow(withTag: "kNMCFilePermissionEditCellDownloadLimit") { + if let indexPath = self.form.indexPath(ofFormRow: downloadLimitSwitchField) { + let cell = tableView.cellForRow(at: indexPath) as? NCFilePermissionEditCell + cell?.switchControl.isOn = true + } + + if let downloadLimitInputField: XLFormRowDescriptor = self.form.formRow(withTag: "NCShareTextInputCellDownloadLimit") { + downloadLimitInputField.hidden = false + if let indexPath = self.form.indexPath(ofFormRow: downloadLimitInputField) { + let cell = tableView.cellForRow(at: indexPath) as? NCShareTextInputCell + cell?.cellTextField.text = "\(value)" + } + } + + if let downloadLimitInputField: XLFormRowDescriptor = self.form.formRow(withTag: "kNMCDownloadLimitCell") { + downloadLimitInputField.hidden = false + if let indexPath = self.form.indexPath(ofFormRow: downloadLimitInputField) { + let cell = tableView.cellForRow(at: indexPath) as? NCFilePermissionCell + cell?.titleLabel.text = NSLocalizedString("_share_remaining_download_", comment: "") + " \(downloadLimit.count ?? 0)" + } + } + } + } + } + + func getDownloadLimitSwitchCell() -> NCFilePermissionEditCell? { + if let downloadLimitSwitchField: XLFormRowDescriptor = self.form.formRow(withTag: "kNMCFilePermissionEditCellDownloadLimit") { + if let indexPath = self.form.indexPath(ofFormRow: downloadLimitSwitchField) { + let cell = tableView.cellForRow(at: indexPath) as? NCFilePermissionEditCell + return cell + } + } + return nil + } + + func getDownloadLimitInputCell() -> NCShareTextInputCell? { + if let downloadLimitInputField: XLFormRowDescriptor = self.form.formRow(withTag: "NCShareTextInputCellDownloadLimit") { + if let indexPath = self.form.indexPath(ofFormRow: downloadLimitInputField) { + let cell = tableView.cellForRow(at: indexPath) as? NCShareTextInputCell + return cell + } + } + return nil } + + func getExpiryDateSwitchCell() -> NCFilePermissionEditCell? { + if let expiryRow : XLFormRowDescriptor = self.form.formRow(withTag: "kNMCFilePermissionEditCellExpiration") { + if let indexPath = self.form.indexPath(ofFormRow: expiryRow) { + let cell = tableView.cellForRow(at: indexPath) as? NCFilePermissionEditCell + return cell + } + } + return nil + } + + // MARK: - Row Descriptor Value Changed + + override func didSelectFormRow(_ formRow: XLFormRowDescriptor!) { + guard let metadata = self.metadata else { return } + let permissions = NCPermissions() + switch formRow.tag { + case "NCFilePermissionCellRead": + + let value = permissions.getPermission(canEdit: false, canCreate: false, canChange: false, canDelete: false, canShare: canReshareTheShare(), isDirectory: metadata.directory) + self.permission = value +// self.permissions = "RDNVCK" + metadata.permissions = "RDNVCK" + if let row : XLFormRowDescriptor = self.form.formRow(withTag: "NCFilePermissionCellRead") { + row.cellConfig["imageCheck.image"] = UIImage(named: "success")!.image(color: NCBrandColor.shared.customer, size: 25.0) + if let row1 : XLFormRowDescriptor = self.form.formRow(withTag: "kNMCFilePermissionCellEditing") { + row1.cellConfig["imageCheck.image"] = UIImage(named: "success")!.image(color: .clear, size: 25.0) + } + if let row2 : XLFormRowDescriptor = self.form.formRow(withTag: "NCFilePermissionCellFileDrop") { + row2.cellConfig["imageCheck.image"] = UIImage(named: "success")!.image(color: .clear, size: 25.0) + } + } - override func numberOfSections(in tableView: UITableView) -> Int { - return 2 + self.reloadForm() + break + case "kNMCFilePermissionCellEditing": + let value = permissions.getPermission(canEdit: true, canCreate: true, canChange: true, canDelete: true, canShare: canReshareTheShare(), isDirectory: metadata.directory) + self.permission = value +// self.permissions = "RGDNV" + metadata.permissions = "RGDNV" + if let row : XLFormRowDescriptor = self.form.formRow(withTag: "NCFilePermissionCellRead") { + row.cellConfig["imageCheck.image"] = UIImage(named: "success")!.image(color: .clear, size: 25.0) + } + if let row1 : XLFormRowDescriptor = self.form.formRow(withTag: "kNMCFilePermissionCellEditing") { + row1.cellConfig["imageCheck.image"] = UIImage(named: "success")!.image(color: NCBrandColor.shared.customer, size: 25.0) + } + if let row2 : XLFormRowDescriptor = self.form.formRow(withTag: "NCFilePermissionCellFileDrop") { + row2.cellConfig["imageCheck.image"] = UIImage(named: "success")!.image(color: .clear, size: 25.0) + } + self.reloadForm() + break + case "NCFilePermissionCellFileDrop": + self.permission = permissions.permissionCreateShare +// self.permissions = "RGDNVCK" + metadata.permissions = "RGDNVCK" + if let row : XLFormRowDescriptor = self.form.formRow(withTag: "NCFilePermissionCellRead") { + row.cellConfig["imageCheck.image"] = UIImage(named: "success")!.image(color: .clear, size: 25.0) + } + if let row1 : XLFormRowDescriptor = self.form.formRow(withTag: "kNMCFilePermissionCellEditing") { + row1.cellConfig["imageCheck.image"] = UIImage(named: "success")!.image(color: .clear, size: 25.0) + } + if let row2 : XLFormRowDescriptor = self.form.formRow(withTag: "NCFilePermissionCellFileDrop") { + row2.cellConfig["imageCheck.image"] = UIImage(named: "success")!.image(color: NCBrandColor.shared.customer, size: 25.0) + } + self.reloadForm() + break + default: + break + } } - override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - if section == 0 { - // check reshare permission, if restricted add note - let maxPermission = metadata.directory ? NCSharePermissions.permissionMaxFolderShare : NCSharePermissions.permissionMaxFileShare - return shareConfig.sharePermission != maxPermission ? shareConfig.permissions.count + 1 : shareConfig.permissions.count - } else if section == 1 { - return shareConfig.advanced.count - } else { return 0 } + func canReshareTheShare() -> Bool { + if let permissionValue = self.permission { + let canReshare = NCPermissions().isPermissionToCanShare(permissionValue) + return canReshare + } else { + return false + } } - override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - guard let cell = shareConfig.cellFor(indexPath: indexPath) else { - let noteCell = UITableViewCell(style: .subtitle, reuseIdentifier: "noteCell") - noteCell.detailTextLabel?.text = NSLocalizedString("_share_reshare_restricted_", comment: "") - noteCell.detailTextLabel?.isEnabled = false - noteCell.isUserInteractionEnabled = false - noteCell.detailTextLabel?.numberOfLines = 0 - return noteCell + override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { + let permissions = NCPermissions() + if let advancePermissionHeaderRow: XLFormRowDescriptor = self.form.formRow(withTag: "NCFilePermissionCellAdvanceTxt") { + if let advancePermissionHeaderRowIndexPath = form.indexPath(ofFormRow: advancePermissionHeaderRow), indexPath == advancePermissionHeaderRowIndexPath { + let cell = cell as? NCFilePermissionCell + cell?.seperatorBelowFull.isHidden = isLinkShare() + } + } + + //can Reshare + if let canReshareRow: XLFormRowDescriptor = self.form.formRow(withTag: "kNMCFilePermissionEditCellEditingCanShare") { + if let canReShareRowIndexPath = form.indexPath(ofFormRow: canReshareRow), indexPath == canReShareRowIndexPath { + let cell = cell as? NCFilePermissionEditCell + // Can reshare (file) + if let permissionValue = self.permission { + let canReshare = permissions.isPermissionToCanShare(permissionValue) + cell?.switchControl.isOn = canReshare + } else { + //new share + cell?.switchControl.isOn = false + } + } + } + //hide download + if let hideDownloadRow: XLFormRowDescriptor = self.form.formRow(withTag: "kNMCFilePermissionEditCellHideDownload"){ + if let hideDownloadRowIndexPath = form.indexPath(ofFormRow: hideDownloadRow), indexPath == hideDownloadRowIndexPath { + let cell = cell as? NCFilePermissionEditCell + cell?.switchControl.isOn = oldTableShare?.hideDownload ?? false + cell?.titleLabel.isEnabled = !(self.permission == permissions.permissionCreateShare) + cell?.switchControl.isEnabled = !(self.permission == permissions.permissionCreateShare) +// cell?.isUserInteractionEnabled = !(self.permission == permissions.permissionCreateShare) + } + + // set password + if let setPassword : XLFormRowDescriptor = self.form.formRow(withTag: "kNMCFilePermissionEditPasswordCellWithText") { + if let setPasswordIndexPath = self.form.indexPath(ofFormRow: setPassword), indexPath == setPasswordIndexPath { + let passwordCell = cell as? NCFilePermissionEditCell + if let password = oldTableShare?.password { + passwordCell?.switchControl.isOn = !password.isEmpty + } else { + passwordCell?.switchControl.isOn = false + } + } + } + } + + //updateExpiryDateSwitch + if let expiryRow : XLFormRowDescriptor = self.form.formRow(withTag: "kNMCFilePermissionEditCellExpiration") { + if let expiryIndexPath = self.form.indexPath(ofFormRow: expiryRow), indexPath == expiryIndexPath { + let cell = cell as? NCFilePermissionEditCell + if oldTableShare?.expirationDate != nil { + cell?.switchControl.isOn = true + } else { + //new share + cell?.switchControl.isOn = false + } + } + } + + //SetDownloadLimitSwitch + if let limitRow : XLFormRowDescriptor = self.form.formRow(withTag: "kNMCFilePermissionEditCellDownloadLimit") { + if let expiryIndexPath = self.form.indexPath(ofFormRow: limitRow), indexPath == expiryIndexPath { + let cell = cell as? NCFilePermissionEditCell + cell?.switchControl.isOn = downloadLimit.limit != nil + } + } + + //SetDownloadLimitSwitch + if let downloadlimitFieldRow : XLFormRowDescriptor = self.form.formRow(withTag: "NCShareTextInputCellDownloadLimit") { + if let downloadlimitIndexPath = self.form.indexPath(ofFormRow: downloadlimitFieldRow), indexPath == downloadlimitIndexPath { + let cell = cell as? NCShareTextInputCell + cell?.cellTextField.text = "\(downloadLimit.limit ?? 0)" + } + } + + //SetDownloadLimitSwitch + if downloadLimit.count != nil { + if let downloadlimitFieldRow : XLFormRowDescriptor = self.form.formRow(withTag: "kNMCDownloadLimitCell") { + if let downloadlimitIndexPath = self.form.indexPath(ofFormRow: downloadlimitFieldRow), indexPath == downloadlimitIndexPath { + let cell = cell as? NCFilePermissionCell + cell?.titleLabel.text = NSLocalizedString("_share_remaining_download_", comment: "") + " \(downloadLimit.count ?? 0)" + cell?.seperatorBelowFull.isHidden = true + cell?.seperatorBelow.isHidden = true + } + } } - if let cell = cell as? NCShareDateCell { cell.onReload = tableView.reloadData } - return cell } - override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { - tableView.deselectRow(at: indexPath, animated: true) - guard let cellConfig = shareConfig.config(for: indexPath) else { return } - guard let cellConfig = cellConfig as? NCAdvancedPermission else { - cellConfig.didSelect(for: share) - tableView.reloadData() + override func formRowDescriptorValueHasChanged(_ formRow: XLFormRowDescriptor!, oldValue: Any!, newValue: Any!) { + super.formRowDescriptorValueHasChanged(formRow, oldValue: oldValue, newValue: newValue) + + switch formRow.tag { + + case "kNMCFilePermissionEditCellEditingCanShare": + if let value = newValue as? Bool { + canReshareValueChanged(isOn: value) + } + + case "kNMCFilePermissionEditCellHideDownload": + if let value = newValue as? Bool { + share.hideDownload = value + } + + case "kNMCFilePermissionEditPasswordCellWithText": + if let value = newValue as? Bool { + if let setPasswordInputField : XLFormRowDescriptor = self.form.formRow(withTag: "SetPasswordInputField") { + if let indexPath = self.form.indexPath(ofFormRow: setPasswordInputField) { + let cell = tableView.cellForRow(at: indexPath) as? PasswordInputField + cell?.fileNameInputTextField.text = "" + } + share.password = "" + setPasswordInputField.hidden = !value + } + } + + case "kNCShareTextInputCellCustomLinkField": + if let label = formRow.value as? String { + self.form.delegate = nil + share.label = label + self.form.delegate = self + } + + case "SetPasswordInputField": + if let pwd = formRow.value as? String { + self.form.delegate = nil + share.password = pwd + self.form.delegate = self + } + +// case "SetPasswordInputField": +// if let pwd = formRow.value as? String { +// self.form.delegate = nil +// +// // Validate password length +// if pwd.count < 6 { +// share.password = "" +// +// // Show alert for invalid password +// let alert = UIAlertController( +// title: NSLocalizedString("_invalid_password_title_", comment: "Invalid Password"), +// message: NSLocalizedString("_password_min_length_", comment: "Password must be at least 6 characters"), +// preferredStyle: .alert +// ) +// alert.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: "OK"), style: .default)) +// self.present(alert, animated: true) +// +// // Clear the text field in the cell +// if let indexPath = self.form.indexPath(ofFormRow: formRow), +// let cell = tableView.cellForRow(at: indexPath) as? PasswordInputField { +// cell.fileNameInputTextField.text = "" +// } +// } else { +// // Password is valid +// share.password = pwd +// } +// +// self.form.delegate = self +// } + + case "kNMCFilePermissionEditCellLinkLabel": + if let label = formRow.value as? String { + self.form.delegate = nil + share.label = label + self.form.delegate = self + } + +// case "kNMCFilePermissionEditCellExpiration": +// if let value = newValue as? Bool { +// if let inputField : XLFormRowDescriptor = self.form.formRow(withTag: "NCShareTextInputCellExpiry") { +// inputField.hidden = !value +// } +// } + + case "kNMCFilePermissionEditCellExpiration": + if let value = newValue as? Bool { + if let inputField: XLFormRowDescriptor = self.form.formRow(withTag: "NCShareTextInputCellExpiry") { + inputField.hidden = !value + + // Only set expiration date if toggle is ON and there's no existing value + if value && share.expirationDate == nil { + let defaultExpiry = Date.dayNextYear + inputField.value = defaultExpiry + share.expirationDate = defaultExpiry as NSDate + + // Reload the cell to update the UI + if let indexPath = self.form.indexPath(ofFormRow: inputField) { + // Reload row to ensure the text field is updated +// self.tableView.reloadRows(at: [indexPath], with: .automatic) + + // Manually update the cell's text field to display the expiration date + if let cell = self.tableView.cellForRow(at: indexPath) as? NCShareTextInputCell { + // Use DateFormatter to format the date + let formattedDate = DateFormatter.shareExpDate.string(from: defaultExpiry) + cell.cellTextField.text = formattedDate + } + } + } + } + } + + case "kNMCFilePermissionEditCellDownloadLimit": + if let value = newValue as? Bool { + + self.downloadLimit = value ? .limited(limit: 0, count: 0) : .unlimited + + if let inputField : XLFormRowDescriptor = self.form.formRow(withTag: "NCShareTextInputCellDownloadLimit") { + inputField.hidden = !value + if let indexPath = self.form.indexPath(ofFormRow: inputField) { + let cell = tableView.cellForRow(at: indexPath) as? NCShareTextInputCell + cell?.cellTextField.text = "\(downloadLimit.limit ?? 0)" + } + } + + if let inputField : XLFormRowDescriptor = self.form.formRow(withTag: "kNMCDownloadLimitCell") { + inputField.hidden = !value + if let indexPath = self.form.indexPath(ofFormRow: inputField) { + let cell = tableView.cellForRow(at: indexPath) as? NCFilePermissionCell + cell?.seperatorBelowFull.isHidden = true + cell?.seperatorBelow.isHidden = true + cell?.titleLabel.text = "" //String(defaultLimit) + } + } + } + + case "NCShareTextInputCellExpiry": + if let exp = formRow.value as? Date { + self.form.delegate = nil + self.share.expirationDate = exp as NSDate + self.form.delegate = self + } else { + // Only clear if the row value was *explicitly* set to nil by the user + if formRow.value == nil { + self.share.expirationDate = nil + } + } + + default: + break + } + } + //Check file type is collabora + func checkIsCollaboraFile() -> Bool { + guard let metadata = metadata else { + return false + } + + // EDITORS + let editors = NCUtility().editorsDirectEditing(account: metadata.account, contentType: metadata.contentType) + let availableRichDocument = NCUtility().isTypeFileRichDocument(metadata) + + // RichDocument: Collabora + return (availableRichDocument && editors.count == 0) + } + + func isFileDropOptionVisible() -> Bool { + return (metadata.directory && (isLinkShare() || isExternalUserShare())) + } + + func isLinkShare() -> Bool { + return NCShareCommon().isLinkShare(shareType: shareType) + } + + func isExternalUserShare() -> Bool { + return NCShareCommon().isExternalUserShare(shareType: shareType) + } + + func isInternalUser() -> Bool { + return NCShareCommon().isInternalUser(shareType: shareType) + } + + func isCanReshareOptionVisible() -> Bool { + return isInternalUser() + } + + func isHideDownloadOptionVisible() -> Bool { + return !isInternalUser() + } + + func isPasswordOptionsVisible() -> Bool { + return !isInternalUser() + } + + func isDownloadLimitVisible() -> Bool { + return isLinkShare() && !(metadata.directory) + } + + func canReshareValueChanged(isOn: Bool) { + let permissions = NCPermissions() + guard let oldTableShare = oldTableShare, let permission = self.permission else { + self.permission = isOn ? (self.permission ?? 0) + permissions.permissionShareShare : ((self.permission ?? 0) - permissions.permissionShareShare) return } - switch cellConfig { - case .limitDownload: - let storyboard = UIStoryboard(name: "NCShare", bundle: nil) - guard let viewController = storyboard.instantiateViewController(withIdentifier: "NCShareDownloadLimit") as? NCShareDownloadLimitViewController else { return } - viewController.downloadLimit = self.downloadLimit - viewController.metadata = self.metadata - viewController.share = self.share - viewController.shareDownloadLimitTableViewControllerDelegate = self - viewController.onDismiss = tableView.reloadData - self.navigationController?.pushViewController(viewController, animated: true) - case .hideDownload: - share.hideDownload.toggle() - tableView.reloadData() - case .expirationDate: - let cell = tableView.cellForRow(at: indexPath) as? NCShareDateCell - cell?.textField.becomeFirstResponder() - cell?.checkMaximumDate(account: metadata.account) - case .password: - guard share.password.isEmpty else { - share.password = "" - tableView.reloadData() - return + let canEdit = permissions.isAnyPermissionToEdit(permission) + let canCreate = permissions.isPermissionToCanCreate(permission) + let canChange = permissions.isPermissionToCanChange(permission) + let canDelete = permissions.isPermissionToCanDelete(permission) + + if metadata.directory { + self.permission = permissions.getPermission(canEdit: canEdit, canCreate: canCreate, canChange: canChange, canDelete: canDelete, canShare: isOn, isDirectory: metadata.directory) + } else { + if isOn { + if canEdit { + self.permission = permissions.getPermission(canEdit: true, canCreate: true, canChange: true, canDelete: true, canShare: isOn, isDirectory: metadata.directory) + } else { + self.permission = permissions.getPermission(canEdit: false, canCreate: false, canChange: false, canDelete: false, canShare: isOn, isDirectory: metadata.directory) + } + } else { + if canEdit { + self.permission = permissions.getPermission(canEdit: true, canCreate: true, canChange: true, canDelete: true, canShare: isOn, isDirectory: metadata.directory) + } else { + self.permission = permissions.getPermission(canEdit: false, canCreate: false, canChange: false, canDelete: false, canShare: isOn, isDirectory: metadata.directory) + } } - let alertController = UIAlertController.password(titleKey: "_share_password_") { password in - self.share.password = password ?? "" - tableView.reloadData() - } - self.present(alertController, animated: true) - case .note: - let storyboard = UIStoryboard(name: "NCShare", bundle: nil) - guard let viewNewUserComment = storyboard.instantiateViewController(withIdentifier: "NCShareNewUserAddComment") as? NCShareNewUserAddComment else { return } - viewNewUserComment.metadata = self.metadata - viewNewUserComment.share = self.share - viewNewUserComment.onDismiss = tableView.reloadData - self.navigationController?.pushViewController(viewNewUserComment, animated: true) - case .label: - let alertController = UIAlertController.withTextField(titleKey: "_share_link_name_") { textField in - textField.placeholder = cellConfig.title - textField.text = self.share.label - } completion: { newValue in - self.share.label = newValue ?? "" - self.setNavigationTitle() - tableView.reloadData() - } - self.present(alertController, animated: true) - case .downloadAndSync: - share.downloadAndSync.toggle() - tableView.reloadData() } } @@ -267,6 +1083,51 @@ class NCShareAdvancePermission: UITableViewController, NCShareAdvanceFotterDeleg navigationController?.popViewController(animated: true) } + + func getDownloadLimit() async { + NCActivityIndicator.shared.start(backgroundView: view) + + do { + // First, try to fetch download limits from the server. + try await networking?.readDownloadLimits(account: metadata.account, tokens: [oldTableShare?.token ?? ""]) + NCActivityIndicator.shared.stop() // Stop the activity indicator + + if !isNewShare, let persistedShare = share as? tableShare { + // If not a new share and share exists, fetch the limit for that persisted share + do { + if let limit = try database.getDownloadLimit(byAccount: metadata.account, shareToken: persistedShare.token) { + DispatchQueue.main.async { + NCActivityIndicator.shared.stop() // Stop the activity indicator + self.downloadLimit = .limited(limit: limit.limit, count: limit.count) + self.updateDownloadLimitUI() + } + } + } catch { + // Handle the error for the persisted share token lookup + DispatchQueue.main.async { + NextcloudKit.shared.nkCommonInstance.writeLog("[ERROR] Error fetching the download limit for share with token \(persistedShare.token).") + NCActivityIndicator.shared.stop() // Stop the activity indicator + } + } + } + } catch { + // Handle error for fetching download limits from the server + DispatchQueue.main.async { + print("Error fetching download limit: \(error)") + NCActivityIndicator.shared.stop() // Stop the activity indicator + } + } + } + + func setDownloadLimit(deleteLimit: Bool, limit: String) { + networking?.setShareDownloadLimit(Int(limit) ?? 0, token: oldTableShare?.token ?? "") + } + + func showDownloadLimitError(message: String) { + let alertController = UIAlertController(title: "", message: message, preferredStyle: .alert) + alertController.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { action in })) + self.present(alertController, animated: true) + } } // MARK: - NCShareDownloadLimitTableViewControllerDelegate @@ -277,3 +1138,15 @@ extension NCShareAdvancePermission: NCShareDownloadLimitTableViewControllerDeleg self.downloadLimitChanged = true } } + +extension Date { + static var dayNextYear: Date { +// let calendar = Calendar.current +// let now = Date() +// var components = DateComponents() +// components.year = 1 +// components.day = 1 +// return calendar.date(byAdding: components, to: now)! + return Calendar.current.date(byAdding: .year, value: 1, to: Date())! + } +} diff --git a/iOSClient/Share/Advanced/NCShareAdvancePermissionFooter.swift b/iOSClient/Share/Advanced/NCShareAdvancePermissionFooter.swift index dfee243827..64d8f6d9eb 100644 --- a/iOSClient/Share/Advanced/NCShareAdvancePermissionFooter.swift +++ b/iOSClient/Share/Advanced/NCShareAdvancePermissionFooter.swift @@ -35,30 +35,31 @@ class NCShareAdvancePermissionFooter: UIView { func setupUI(delegate: NCShareAdvanceFotterDelegate?, account: String) { self.delegate = delegate - backgroundColor = .clear - + buttonCancel.addTarget(self, action: #selector(cancelClicked), for: .touchUpInside) + buttonNext.addTarget(self, action: #selector(nextClicked), for: .touchUpInside) buttonCancel.setTitle(NSLocalizedString("_cancel_", comment: ""), for: .normal) - buttonCancel.layer.cornerRadius = 25 + buttonNext.setTitle(NSLocalizedString(delegate?.isNewShare == true ? "_next_" : "_apply_changes_", comment: ""), for: .normal) + buttonCancel.layer.cornerRadius = 10 buttonCancel.layer.masksToBounds = true buttonCancel.layer.borderWidth = 1 - buttonCancel.layer.borderColor = NCBrandColor.shared.textColor2.cgColor - buttonCancel.backgroundColor = .secondarySystemBackground - buttonCancel.addTarget(self, action: #selector(cancelClicked(_:)), for: .touchUpInside) - buttonCancel.setTitleColor(NCBrandColor.shared.textColor2, for: .normal) - - buttonNext.setTitle(NSLocalizedString(delegate?.isNewShare == true ? "_share_" : "_save_", comment: ""), for: .normal) - buttonNext.layer.cornerRadius = 25 - buttonNext.layer.masksToBounds = true - buttonNext.backgroundColor = NCBrandColor.shared.getElement(account: account) - buttonNext.addTarget(self, action: #selector(nextClicked(_:)), for: .touchUpInside) + addShadow(location: .top) + layer.cornerRadius = 10 + layer.masksToBounds = true + backgroundColor = NCBrandColor.shared.secondarySystemGroupedBackground + buttonCancel.setTitleColor(NCBrandColor.shared.label, for: .normal) + buttonCancel.layer.borderColor = NCBrandColor.shared.label.cgColor + buttonCancel.backgroundColor = NCBrandColor.shared.secondarySystemGroupedBackground + buttonNext.setBackgroundColor(NCBrandColor.shared.customer, for: .normal) buttonNext.setTitleColor(.white, for: .normal) + buttonNext.layer.cornerRadius = 10 + buttonNext.layer.masksToBounds = true } - @objc func cancelClicked(_ sender: Any?) { + @objc func cancelClicked() { delegate?.dismissShareAdvanceView(shouldSave: false) } - @objc func nextClicked(_ sender: Any?) { + @objc func nextClicked() { delegate?.dismissShareAdvanceView(shouldSave: true) } } diff --git a/iOSClient/Share/Advanced/NCShareAdvancePermissionFooter.xib b/iOSClient/Share/Advanced/NCShareAdvancePermissionFooter.xib index b4ec72ed06..36b09589ef 100644 --- a/iOSClient/Share/Advanced/NCShareAdvancePermissionFooter.xib +++ b/iOSClient/Share/Advanced/NCShareAdvancePermissionFooter.xib @@ -1,67 +1,60 @@ - + - + - - - + + - + + - + - - - - - - - + - + - - - - - - - + + + - - + + - + - - - - - - - - diff --git a/iOSClient/Share/Advanced/NCShareAdvancePermissionHeader.xib b/iOSClient/Share/Advanced/NCShareAdvancePermissionHeader.xib new file mode 100644 index 0000000000..20cda3faac --- /dev/null +++ b/iOSClient/Share/Advanced/NCShareAdvancePermissionHeader.xib @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/iOSClient/Share/Advanced/NCShareCells.swift b/iOSClient/Share/Advanced/NCShareCells.swift index 6915dd23c6..5205b361bd 100644 --- a/iOSClient/Share/Advanced/NCShareCells.swift +++ b/iOSClient/Share/Advanced/NCShareCells.swift @@ -22,8 +22,6 @@ // import UIKit -import OSLog -import NextcloudKit protocol NCShareCellConfig { var title: String { get } @@ -50,17 +48,18 @@ protocol NCPermission: NCToggleCellConfig { static var forDirectory: [Self] { get } static var forFile: [Self] { get } static func forDirectoryE2EE(account: String) -> [NCPermission] - func hasPermission(for parentPermission: Int) -> Bool - func hasReadPermission() -> Bool + func hasResharePermission(for parentPermission: Int) -> Bool + func hasDownload() -> Bool } enum NCUserPermission: CaseIterable, NCPermission { - func hasPermission(for parentPermission: Int) -> Bool { + func hasResharePermission(for parentPermission: Int) -> Bool { + if self == .download { return true } return ((permissionBitFlag & parentPermission) != 0) } - func hasReadPermission() -> Bool { - return self == .read + func hasDownload() -> Bool { + return self == .download } var permissionBitFlag: Int { @@ -74,32 +73,39 @@ enum NCUserPermission: CaseIterable, NCPermission { } func didChange(_ share: Shareable, to newValue: Bool) { - share.permissions ^= permissionBitFlag + if self == .download { + share.attributes = NCManageDatabase.shared.setAttibuteDownload(state: newValue) + } else { + share.permissions ^= permissionBitFlag + } } func isOn(for share: Shareable) -> Bool { - return (share.permissions & permissionBitFlag) != 0 + if self == .download { + return NCManageDatabase.shared.isAttributeDownloadEnabled(attributes: share.attributes) + } else { + return (share.permissions & permissionBitFlag) != 0 + } } static func forDirectoryE2EE(account: String) -> [NCPermission] { - let capabilities = NCNetworking.shared.capabilities[account] ?? NKCapabilities.Capabilities() - if capabilities.e2EEApiVersion == NCGlobal.shared.e2eeVersionV20 { + if NCCapabilities.shared.getCapabilities(account: account).capabilityE2EEApiVersion == NCGlobal.shared.e2eeVersionV20 { return NCUserPermission.allCases } return [] } - case read, reshare, edit, create, delete + case reshare, edit, create, delete, download static let forDirectory: [NCUserPermission] = NCUserPermission.allCases - static let forFile: [NCUserPermission] = [.read, .reshare, .edit] + static let forFile: [NCUserPermission] = [.reshare, .edit] var title: String { switch self { - case .read: return NSLocalizedString("_share_can_read_", comment: "") case .reshare: return NSLocalizedString("_share_can_reshare_", comment: "") case .edit: return NSLocalizedString("_share_can_change_", comment: "") case .create: return NSLocalizedString("_share_can_create_", comment: "") case .delete: return NSLocalizedString("_share_can_delete_", comment: "") + case .download: return NSLocalizedString("_share_can_download_", comment: "") } } } @@ -131,31 +137,90 @@ enum NCLinkEmailPermission: CaseIterable, NCPermission { } func didChange(_ share: Shareable, to newValue: Bool) { - share.permissions ^= permissionBitFlag + guard self != .allowEdit || newValue else { + share.permissions = NCPermissions().permissionReadShare + return + } + share.permissions = permissionValue + } + + func hasResharePermission(for parentPermission: Int) -> Bool { + permissionValue & parentPermission == permissionValue + } + + func hasDownload() -> Bool { + return false + } + + var permissionValue: Int { + switch self { + case .allowEdit: + return NCPermissions().getPermission( + canEdit: true, + canCreate: true, + canChange: true, + canDelete: true, + canShare: false, + isDirectory: false) + case .viewOnly: + 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 + canShare: true, + isDirectory: true) + case .uploadEdit: + return NCPermissions().getPermission( + canEdit: true, + canCreate: true, + canChange: true, + canDelete: true, + canShare: false, + isDirectory: true) + case .fileDrop: + return NCPermissions().permissionCreateShare + case .secureFileDrop: + return NCPermissions().permissionCreateShare + } } func isOn(for share: Shareable) -> Bool { - return (share.permissions & permissionBitFlag) != 0 + let permissions = NCPermissions() + switch self { + 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 + } + } + + static func forDirectoryE2EE(account: String) -> [NCPermission] { + return [NCLinkPermission.secureFileDrop] } var title: String { switch self { - case .read: return NSLocalizedString("_share_can_read_", comment: "") - case .edit: return NSLocalizedString("_share_can_change_", comment: "") - case .create: return NSLocalizedString("_share_can_create_", comment: "") - case .delete: return NSLocalizedString("_share_can_delete_", comment: "") + case .allowEdit: return NSLocalizedString("_share_can_change_", comment: "") + case .viewOnly: return NSLocalizedString("_share_read_only_", comment: "") + case .uploadEdit: return NSLocalizedString("_share_allow_upload_", comment: "") + case .fileDrop: return NSLocalizedString("_share_file_drop_", comment: "") + case .secureFileDrop: return NSLocalizedString("_share_secure_file_drop_", comment: "") } } - case edit, read, create, delete - static let forDirectory: [NCLinkEmailPermission] = NCLinkEmailPermission.allCases - static let forFile: [NCLinkEmailPermission] = [.read, .edit] + case allowEdit, viewOnly, uploadEdit, fileDrop, secureFileDrop + static let forDirectory: [NCLinkPermission] = [.viewOnly, .uploadEdit, .fileDrop] + static let forFile: [NCLinkPermission] = [.allowEdit] } /// /// Individual aspects of share. /// -enum NCAdvancedPermission: CaseIterable, NCShareCellConfig { +enum NCShareDetails: CaseIterable, NCShareCellConfig { func didSelect(for share: Shareable) { switch self { case .hideDownload: share.hideDownload.toggle() @@ -164,7 +229,6 @@ enum NCAdvancedPermission: CaseIterable, NCShareCellConfig { case .password: return case .note: return case .label: return - case .downloadAndSync: return } } @@ -189,8 +253,6 @@ enum NCAdvancedPermission: CaseIterable, NCShareCellConfig { let cell = UITableViewCell(style: .value1, reuseIdentifier: "shareLabel") cell.detailTextLabel?.text = share.label return cell - case .downloadAndSync: - return NCShareToggleCell(isOn: share.downloadAndSync) } } @@ -202,23 +264,20 @@ enum NCAdvancedPermission: CaseIterable, NCShareCellConfig { case .password: return NSLocalizedString("_share_password_protect_", comment: "") case .note: return NSLocalizedString("_share_note_recipient_", comment: "") case .label: return NSLocalizedString("_share_link_name_", comment: "") - case .downloadAndSync: return NSLocalizedString("_share_can_download_", comment: "") } } - case label, hideDownload, limitDownload, expirationDate, password, note, downloadAndSync - static let forLink: [NCAdvancedPermission] = [.expirationDate, .hideDownload, .label, .limitDownload, .note, .password] - static let forUser: [NCAdvancedPermission] = [.expirationDate, .note, .downloadAndSync] + case label, hideDownload, limitDownload, expirationDate, password, note + static let forLink: [NCShareDetails] = NCShareDetails.allCases + static let forUser: [NCShareDetails] = [.expirationDate, .note] } struct NCShareConfig { let permissions: [NCPermission] - let advanced: [NCAdvancedPermission] - let shareable: Shareable - let sharePermission: Int - let isDirectory: Bool + let advanced: [NCShareDetails] + let share: Shareable + let resharePermission: Int - /// There are many share types, but we only classify them as a link share (link type, email type) and a user share (every other share type). init(parentMetadata: tableMetadata, share: Shareable) { self.shareable = share self.sharePermission = parentMetadata.sharePermissionsCollaborationServices @@ -231,44 +290,29 @@ struct NCShareConfig { let hasDownloadLimitCapability = capabilities.fileSharingDownloadLimit if parentMetadata.isDirectory || hasDownloadLimitCapability == false { - self.advanced = NCAdvancedPermission.forLink.filter { $0 != .limitDownload } + self.advanced = NCShareDetails.forLink.filter { $0 != .limitDownload } } else { - self.advanced = NCAdvancedPermission.forLink + self.advanced = NCShareDetails.forLink } } else { - self.advanced = NCAdvancedPermission.forUser + self.advanced = NCShareDetails.forUser } } func cellFor(indexPath: IndexPath) -> UITableViewCell? { let cellConfig = config(for: indexPath) - let cell = cellConfig?.getCell(for: shareable) + let cell = cellConfig?.getCell(for: share) cell?.textLabel?.text = cellConfig?.title - Logger().info("\(cellConfig?.title ?? "")") - - if let cellConfig = cellConfig as? NCPermission, !cellConfig.hasPermission(for: sharePermission) { + if let cellConfig = cellConfig as? NCPermission, !cellConfig.hasResharePermission(for: resharePermission), !cellConfig.hasDownload() { cell?.isUserInteractionEnabled = false cell?.textLabel?.isEnabled = false } - - // For user permissions: Read permission is always enabled and we show it as a non-interactable permission for brevity. - if let cellConfig = cellConfig as? NCUserPermission, cellConfig.hasReadPermission() { - cell?.isUserInteractionEnabled = false - cell?.textLabel?.isEnabled = false - } - - // For link permissions: Read permission is always enabled and we show it as a non-interactable permission in files only for brevity. - if let cellConfig = cellConfig as? NCLinkEmailPermission, cellConfig.hasReadPermission(), !isDirectory { - cell?.isUserInteractionEnabled = false - cell?.textLabel?.isEnabled = false - } - return cell } func didSelectRow(at indexPath: IndexPath) { let cellConfig = config(for: indexPath) - cellConfig?.didSelect(for: shareable) + cellConfig?.didSelect(for: share) } func config(for indexPath: IndexPath) -> NCShareCellConfig? { diff --git a/iOSClient/Share/Advanced/NCShareDateCell.swift b/iOSClient/Share/Advanced/NCShareDateCell.swift index df1c4fe4af..a26dcf3918 100644 --- a/iOSClient/Share/Advanced/NCShareDateCell.swift +++ b/iOSClient/Share/Advanced/NCShareDateCell.swift @@ -2,8 +2,6 @@ // SPDX-FileCopyrightText: 2022 Henrik Storch // SPDX-License-Identifier: GPL-3.0-or-later -import NextcloudKit - /// /// Table view cell to manage the expiration date on a share in its details. /// @@ -12,6 +10,7 @@ class NCShareDateCell: UITableViewCell { let textField = UITextField() var shareType: Int var onReload: (() -> Void)? + let shareCommon = NCShareCommon() init(share: Shareable) { self.shareType = share.shareType @@ -59,8 +58,6 @@ class NCShareDateCell: UITableViewCell { } private func isExpireDateEnforced(account: String) -> Bool { - let capabilities = NCNetworking.shared.capabilities[account] ?? NKCapabilities.Capabilities() - switch self.shareType { case NKShare.ShareType.publicLink.rawValue, NKShare.ShareType.email.rawValue, @@ -80,8 +77,6 @@ class NCShareDateCell: UITableViewCell { } private func defaultExpirationDays(account: String) -> Int { - let capabilities = NCNetworking.shared.capabilities[account] ?? NKCapabilities.Capabilities() - switch self.shareType { case NKShare.ShareType.publicLink.rawValue, NKShare.ShareType.email.rawValue, diff --git a/iOSClient/Share/Advanced/NCShareHeaderCustomCell.swift b/iOSClient/Share/Advanced/NCShareHeaderCustomCell.swift new file mode 100644 index 0000000000..cb5dae8c1f --- /dev/null +++ b/iOSClient/Share/Advanced/NCShareHeaderCustomCell.swift @@ -0,0 +1,30 @@ +// +// NCShareHeaderCustomCell.swift +// Nextcloud +// +// Created by T-systems on 11/08/21. +// Copyright © 2021 Marino Faggiana. All rights reserved. +// + +import UIKit + +class NCShareHeaderCustomCell: XLFormBaseCell { + + @IBOutlet weak var titleLabel: UILabel! + + override func awakeFromNib() { + super.awakeFromNib() + self.selectionStyle = .none + self.backgroundColor = .clear + } + + override func configure() { + super.configure() + } + + override func update() { + self.backgroundColor = .clear + self.titleLabel.textColor = NCBrandColor.shared.systemGray + super.update() + } +} diff --git a/iOSClient/Share/Advanced/NCShareHeaderCustomCell.xib b/iOSClient/Share/Advanced/NCShareHeaderCustomCell.xib new file mode 100644 index 0000000000..89ba3781e5 --- /dev/null +++ b/iOSClient/Share/Advanced/NCShareHeaderCustomCell.xib @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/iOSClient/Share/Advanced/NCShareNewUserAddComment.swift b/iOSClient/Share/Advanced/NCShareNewUserAddComment.swift index 0c6bb586ef..c227d21c8a 100644 --- a/iOSClient/Share/Advanced/NCShareNewUserAddComment.swift +++ b/iOSClient/Share/Advanced/NCShareNewUserAddComment.swift @@ -1,9 +1,12 @@ // +// // NCShareNewUserAddComment.swift // Nextcloud // // Created by TSI-mc on 21/06/21. -// Copyright © 2022 All rights reserved. +// Copyright © 2022 Henrik Storch. All rights reserved. +// +// Author Henrik Storch // // 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 @@ -25,39 +28,69 @@ import NextcloudKit class NCShareNewUserAddComment: UIViewController, NCShareNavigationTitleSetting { @IBOutlet weak var headerContainerView: UIView! - @IBOutlet weak var sharingLabel: UILabel! - @IBOutlet weak var noteTextField: UITextView! - + @IBOutlet weak var labelSharing: UILabel! + @IBOutlet weak var labelNote: UILabel! + @IBOutlet weak var commentTextView: UITextView! + @IBOutlet weak var btnCancel: UIButton! + @IBOutlet weak var btnSendShare: UIButton! + @IBOutlet weak var buttonContainerView: UIView! let contentInsets: CGFloat = 16 - var onDismiss: (() -> Void)? - public var share: Shareable! public var metadata: tableMetadata! + var isNewShare: Bool { share is TransientShare } + var networking: NCShareNetworking? + + /// + /// The possible download limit associated with this share. + /// + /// This can only be created after the share has been actually created due to its requirement of the share token provided by the server. + /// + var downloadLimit: DownloadLimitViewModel = .unlimited override func viewDidLoad() { super.viewDidLoad() self.setNavigationTitle() - - NotificationCenter.default.addObserver(self, selector: #selector(adjustForKeyboard), name: UIResponder.keyboardWillHideNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(adjustForKeyboard), name: UIResponder.keyboardWillChangeFrameNotification, object: nil) +// NotificationCenter.default.addObserver(self, selector: #selector(handleShareCountsUpdate), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterShareCountsUpdated), object: nil) - sharingLabel.text = NSLocalizedString("_share_note_recipient_", comment: "") - - noteTextField.textContainerInset = UIEdgeInsets(top: contentInsets, left: contentInsets, bottom: contentInsets, right: contentInsets) - noteTextField.text = share.note - let toolbar = UIToolbar.toolbar { - self.noteTextField.resignFirstResponder() - self.noteTextField.text = "" - self.share.note = "" - } onDone: { - self.noteTextField.resignFirstResponder() - self.share.note = self.noteTextField.text - self.navigationController?.popViewController(animated: true) + changeTheming() + setupHeader() + } + + @objc func changeTheming() { + self.view.backgroundColor = NCBrandColor.shared.secondarySystemGroupedBackground + self.commentTextView.backgroundColor = NCBrandColor.shared.secondarySystemGroupedBackground + commentTextView.textColor = NCBrandColor.shared.label + btnCancel.setTitleColor(NCBrandColor.shared.label, for: .normal) + btnCancel.layer.borderColor = NCBrandColor.shared.label.cgColor + btnCancel.backgroundColor = .clear + buttonContainerView.backgroundColor = NCBrandColor.shared.secondarySystemGroupedBackground + btnSendShare.setBackgroundColor(NCBrandColor.shared.customer, for: .normal) + btnSendShare.setTitleColor(.white, for: .normal) + commentTextView.layer.borderColor = NCBrandColor.shared.label.cgColor + commentTextView.layer.borderWidth = 1 + commentTextView.layer.cornerRadius = 4.0 + commentTextView.showsVerticalScrollIndicator = false + commentTextView.textContainerInset = UIEdgeInsets(top: contentInsets, left: contentInsets, bottom: contentInsets, right: contentInsets) + btnCancel.setTitle(NSLocalizedString("_cancel_", comment: ""), for: .normal) + btnCancel.layer.cornerRadius = 10 + btnCancel.layer.masksToBounds = true + btnCancel.layer.borderWidth = 1 + btnSendShare.setTitle(NSLocalizedString("_send_share_", comment: ""), for: .normal) + btnSendShare.layer.cornerRadius = 10 + btnSendShare.layer.masksToBounds = true + labelSharing.text = NSLocalizedString("_sharing_", comment: "") + labelNote.text = NSLocalizedString("_share_note_recipient_", comment: "") + commentTextView.inputAccessoryView = UIToolbar.doneToolbar { [weak self] in + self?.commentTextView.resignFirstResponder() } - - noteTextField.inputAccessoryView = toolbar.wrappedSafeAreaContainer - - guard let headerView = (Bundle.main.loadNibNamed("NCShareHeader", owner: self, options: nil)?.first as? NCShareHeader) else { return } + } + + func setupHeader(){ + guard let headerView = (Bundle.main.loadNibNamed("NCShareAdvancePermissionHeader", owner: self, options: nil)?.first as? NCShareAdvancePermissionHeader) else { return } + headerView.ocId = metadata.ocId headerContainerView.addSubview(headerView) headerView.frame = headerContainerView.frame headerView.translatesAutoresizingMaskIntoConstraints = false @@ -65,29 +98,92 @@ class NCShareNewUserAddComment: UIViewController, NCShareNavigationTitleSetting headerView.bottomAnchor.constraint(equalTo: headerContainerView.bottomAnchor).isActive = true headerView.leftAnchor.constraint(equalTo: headerContainerView.leftAnchor).isActive = true headerView.rightAnchor.constraint(equalTo: headerContainerView.rightAnchor).isActive = true - headerView.setupUI(with: metadata) } + +// @objc private func handleShareCountsUpdate(notification: Notification) { +// guard let userInfo = notification.userInfo, +// let links = userInfo["links"] as? Int, +// let emails = userInfo["emails"] as? Int else { +// return +// } +// +// updateHeader(linkCount: links, emailCount: emails) +// } +// +// private func updateHeader(linkCount: Int, emailCount: Int) { +// // If header already exists, just update it +// if let header = headerContainerView.subviews.first(where: { $0 is NCShareAdvancePermissionHeader }) as? NCShareAdvancePermissionHeader { +// header.setupUI(with: metadata, linkCount: linkCount, emailCount: emailCount) +// } else { +// // Otherwise create and attach +// setupHeader(linkCount: linkCount, emailCount: emailCount) +// } +// } +// +// private func setupHeader(linkCount: Int = 0, emailCount: Int = 0) { +// // Clear old header if any +// headerContainerView.subviews.forEach { $0.removeFromSuperview() } +// +// guard let headerView = Bundle.main.loadNibNamed("NCShareAdvancePermissionHeader", owner: self, options: nil)? +// .first as? NCShareAdvancePermissionHeader else { +// return +// } +// +// headerView.ocId = metadata.ocId +// headerContainerView.addSubview(headerView) +// +// headerView.translatesAutoresizingMaskIntoConstraints = false +// NSLayoutConstraint.activate([ +// headerView.topAnchor.constraint(equalTo: headerContainerView.topAnchor), +// headerView.bottomAnchor.constraint(equalTo: headerContainerView.bottomAnchor), +// headerView.leadingAnchor.constraint(equalTo: headerContainerView.leadingAnchor), +// headerView.trailingAnchor.constraint(equalTo: headerContainerView.trailingAnchor) +// ]) +// +// // Initial setup +// headerView.setupUI(with: metadata, linkCount: linkCount, emailCount: emailCount) +// } + + @IBAction func cancelClicked(_ sender: Any) { + self.navigationController?.popToRootViewController(animated: true) + } - override func viewWillDisappear(_ animated: Bool) { - super.viewWillDisappear(animated) - share.note = noteTextField.text - onDismiss?() + @IBAction func sendShareClicked(_ sender: Any) { + share.note = commentTextView.text + if isNewShare { + networking?.createShare(share, downloadLimit: downloadLimit) + } else { + networking?.updateShare(share, downloadLimit: downloadLimit) + } + self.navigationController?.popToRootViewController(animated: true) } @objc func adjustForKeyboard(notification: Notification) { guard let keyboardValue = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue, - let globalTextViewFrame = noteTextField.superview?.convert(noteTextField.frame, to: nil) else { return } - + let globalTextViewFrame = commentTextView.superview?.convert(commentTextView.frame, to: nil) else { return } let keyboardScreenEndFrame = keyboardValue.cgRectValue let portionCovoredByLeyboard = globalTextViewFrame.maxY - keyboardScreenEndFrame.minY if notification.name == UIResponder.keyboardWillHideNotification || portionCovoredByLeyboard < 0 { - noteTextField.contentInset = .zero + commentTextView.contentInset = .zero } else { - noteTextField.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: portionCovoredByLeyboard, right: 0) + commentTextView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: portionCovoredByLeyboard, right: 0) } + commentTextView.scrollIndicatorInsets = commentTextView.contentInset + } - noteTextField.scrollIndicatorInsets = noteTextField.contentInset + @objc func keyboardWillShow(notification: Notification) { + if UIScreen.main.bounds.width <= 375 { + if view.frame.origin.y == 0 { + self.view.frame.origin.y -= 200 + } + } + } + + @objc func keyboardWillHide(notification: Notification) { + if view.frame.origin.y != 0 { + self.view.frame.origin.y = 0 + } } } diff --git a/iOSClient/Share/Advanced/NCShareTextInputCell.swift b/iOSClient/Share/Advanced/NCShareTextInputCell.swift new file mode 100644 index 0000000000..a45ce889ce --- /dev/null +++ b/iOSClient/Share/Advanced/NCShareTextInputCell.swift @@ -0,0 +1,166 @@ +// +// NCShareTextInputCell.swift +// Nextcloud +// +// Created by T-systems on 20/09/21. +// Copyright © 2021 Kunal. All rights reserved. +// + +import UIKit + +class NCShareTextInputCell: XLFormBaseCell, UITextFieldDelegate { + + @IBOutlet weak var seperator: UIView! + @IBOutlet weak var seperatorBottom: UIView! + @IBOutlet weak var cellTextField: UITextField! + @IBOutlet weak var calendarImageView: UIImageView! + + let datePicker = UIDatePicker() + var expirationDateText: String! + var expirationDate: NSDate! + + override func awakeFromNib() { + super.awakeFromNib() + self.cellTextField.delegate = self + self.cellTextField.isEnabled = true + calendarImageView.image = UIImage(named: "calender")?.imageColor(NCBrandColor.shared.brandElement) + self.selectionStyle = .none + self.backgroundColor = NCBrandColor.shared.secondarySystemGroupedBackground + self.cellTextField.attributedPlaceholder = NSAttributedString( + string: "", + attributes: [NSAttributedString.Key.foregroundColor: NCBrandColor.shared.fileFolderName] + ) + self.cellTextField.textColor = NCBrandColor.shared.singleTitleColorButton + } + + override func configure() { + super.configure() + } + + override func update() { + super.update() + + calendarImageView.isHidden = rowDescriptor.tag != "NCShareTextInputCellExpiry" + + if rowDescriptor.tag == "NCShareTextInputCellExpiry" { + seperator.isHidden = true + setDatePicker(sender: self.cellTextField) + } else if rowDescriptor.tag == "NCShareTextInputCellDownloadLimit" { + seperator.isHidden = true + cellTextField.keyboardType = .numberPad + setDownloadLimitDoneButton(sender: self.cellTextField) + } + } + + // MARK: - TextField Delegate + + func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { + if self.cellTextField == textField, let text = self.cellTextField.text { + rowDescriptor.value = (text + string).isEmpty ? nil : text + string + } + self.formViewController().textField(textField, shouldChangeCharactersIn: range, replacementString: string) + return true + } + + func textFieldDidEndEditing(_ textField: UITextField) { + rowDescriptor.value = cellTextField.text + } + + func textFieldShouldReturn(_ textField: UITextField) -> Bool { + self.formViewController()?.textFieldShouldReturn(textField) + return true + } + + func textFieldShouldClear(_ textField: UITextField) -> Bool { + self.formViewController()?.textFieldShouldClear(textField) + return true + } + + override class func formDescriptorCellHeight(for rowDescriptor: XLFormRowDescriptor!) -> CGFloat { + return 30 + } + + override func formDescriptorCellDidSelected(withForm controller: XLFormViewController!) { + self.selectionStyle = .none + } + + // MARK: - Date Picker + + func setDatePicker(sender: UITextField) { + datePicker.datePickerMode = .date + datePicker.minimumDate = Date.tomorrow + if #available(iOS 13.4, *) { + datePicker.preferredDatePickerStyle = .wheels + datePicker.sizeToFit() + } + + let toolbar = UIToolbar() + toolbar.sizeToFit() + + let doneButton = UIBarButtonItem(title: NSLocalizedString("_done_", comment: ""), style: .plain, target: self, action: #selector(doneDatePicker)) + let spaceButton = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil) + let clearButton = UIBarButtonItem(title: NSLocalizedString("_clear_", comment: ""), style: .plain, target: self, action: #selector(clearDatePicker)) + + toolbar.setItems([clearButton, spaceButton, doneButton], animated: false) + sender.inputAccessoryView = toolbar + sender.inputView = datePicker + } + + @objc func doneDatePicker() { +// let dateFormatter = DateFormatter() +// dateFormatter.dateFormat = NCShareAdvancePermission.displayDateFormat +// var expiryDate = dateFormatter.string(from: datePicker.date) +// expiryDate = expiryDate.replacingOccurrences(of: "..", with: ".") +// self.expirationDateText = expiryDate +// self.expirationDate = datePicker.date as NSDate + + let expiryDateString = DateFormatter.shareExpDate.string(from: datePicker.date) + self.expirationDateText = expiryDateString + self.expirationDate = datePicker.date as NSDate + + self.cellTextField.text = self.expirationDateText + self.rowDescriptor.value = self.expirationDate + self.cellTextField.endEditing(true) + } + + @objc func clearDatePicker() { + self.expirationDate = nil + self.cellTextField.text = "" + self.rowDescriptor.value = nil + self.cellTextField.endEditing(true) + } + + // MARK: - Download Limit + + func setDownloadLimitDoneButton(sender: UITextField) { + let toolbar = UIToolbar() + toolbar.sizeToFit() + + let doneButton = UIBarButtonItem(title: NSLocalizedString("_done_", comment: ""), style: .plain, target: self, action: #selector(doneDownloadLimit)) + let spaceButton = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil) + toolbar.setItems([spaceButton, doneButton], animated: false) + + sender.inputAccessoryView = toolbar + } + + @objc func doneDownloadLimit() { + if let text = cellTextField.text, let limit = Int(text) { + rowDescriptor.value = limit + } else { + rowDescriptor.value = 0 + } + cellTextField.endEditing(true) + } +} + +class NCSeparatorCell: XLFormBaseCell { + override func awakeFromNib() { + super.awakeFromNib() + selectionStyle = .none + } + + override func update() { + super.update() + selectionStyle = .none + } +} diff --git a/iOSClient/Share/Advanced/NCShareTextInputCell.xib b/iOSClient/Share/Advanced/NCShareTextInputCell.xib new file mode 100644 index 0000000000..eaa2f0cd13 --- /dev/null +++ b/iOSClient/Share/Advanced/NCShareTextInputCell.xib @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/iOSClient/Share/CreateLinkFooterView.swift b/iOSClient/Share/CreateLinkFooterView.swift new file mode 100644 index 0000000000..fb07695cd0 --- /dev/null +++ b/iOSClient/Share/CreateLinkFooterView.swift @@ -0,0 +1,79 @@ +// +// CreateLinkFooterView.swift +// Nextcloud +// +// Created by A106551118 on 12/08/25. +// Copyright © 2025 Marino Faggiana. All rights reserved. +// + + +import UIKit + +class CreateLinkFooterView: UITableViewHeaderFooterView { + + static let reuseIdentifier = "CreateLinkFooterView" + + private let createButton: UIButton = { + let button = UIButton(type: .system) + button.setTitle(NSLocalizedString("_create_new_link_", comment: ""), for: .normal) + button.setTitleColor(UIColor.label, for: .normal) +// button.setTitleColor(NCBrandColor.shared.shareBlackColor, for: .normal) + button.titleLabel?.font = .systemFont(ofSize: 17, weight: .semibold) + button.layer.cornerRadius = 7 + button.layer.borderWidth = 1 + button.layer.borderColor = NCBrandColor.shared.label.cgColor + button.backgroundColor = .clear + button.translatesAutoresizingMaskIntoConstraints = false + return button + }() + + private let separator: UIView = { + let view = UIView() + view.backgroundColor = .lightGray + view.translatesAutoresizingMaskIntoConstraints = false + return view + }() + + var createButtonAction: (() -> Void)? + + override init(reuseIdentifier: String?) { + super.init(reuseIdentifier: reuseIdentifier) + setupUI() + } + + required init?(coder: NSCoder) { + super.init(coder: coder) + setupUI() + } + + override func layoutSubviews() { + super.layoutSubviews() + createButton.layer.borderColor = NCBrandColor.shared.label.cgColor + } + + private func setupUI() { + contentView.backgroundColor = .clear + + contentView.addSubview(createButton) + contentView.addSubview(separator) + + NSLayoutConstraint.activate([ + createButton.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 20), + createButton.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 15), + createButton.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -15), + createButton.heightAnchor.constraint(equalToConstant: 40), + + separator.topAnchor.constraint(equalTo: createButton.bottomAnchor, constant: 20), + separator.leadingAnchor.constraint(equalTo: contentView.leadingAnchor), + separator.trailingAnchor.constraint(equalTo: contentView.trailingAnchor), + separator.heightAnchor.constraint(equalToConstant: 1), + separator.bottomAnchor.constraint(equalTo: contentView.bottomAnchor) // ensures correct height + ]) + + createButton.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside) + } + + @objc private func buttonTapped() { + createButtonAction?() + } +} diff --git a/iOSClient/Share/NCPermissions.swift b/iOSClient/Share/NCPermissions.swift new file mode 100644 index 0000000000..de40c00833 --- /dev/null +++ b/iOSClient/Share/NCPermissions.swift @@ -0,0 +1,108 @@ +// +// 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 + @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 + // + 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/NCSearchUserDropDownCell.xib b/iOSClient/Share/NCSearchUserDropDownCell.xib index 2ba38c8fa6..f476cfafe9 100755 --- a/iOSClient/Share/NCSearchUserDropDownCell.xib +++ b/iOSClient/Share/NCSearchUserDropDownCell.xib @@ -1,9 +1,9 @@ - + - + @@ -29,12 +29,12 @@ - + @@ -58,12 +58,12 @@ + - @@ -73,12 +73,12 @@ - + - + diff --git a/iOSClient/Share/NCShare+Helper.swift b/iOSClient/Share/NCShare+Helper.swift new file mode 100644 index 0000000000..48079eb097 --- /dev/null +++ b/iOSClient/Share/NCShare+Helper.swift @@ -0,0 +1,114 @@ +// +// NCShare+Helper.swift +// Nextcloud +// +// Created by Henrik Storch on 19.03.22. +// Copyright © 2022 Henrik Storch. All rights reserved. +// +// Author Henrik Storch +// +// 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 NextcloudKit + +extension tableShare: NCTableShareable { } +extension NKShare: NCTableShareable { } + +protocol NCTableShareable: AnyObject { + var shareType: Int { get set } + var permissions: Int { get set } + var idShare: Int { get set } + var shareWith: String { get set } + var hideDownload: Bool { get set } + var password: String { get set } + var label: String { get set } + var note: String { get set } + var expirationDate: NSDate? { get set } + var shareWithDisplayname: String { get set } + var attributes: String? { get set } +} + +extension NCTableShareable { + var expDateString: String? { + guard let date = expirationDate else { return nil } + let dateFormatter = DateFormatter() + dateFormatter.dateFormat = "YYYY-MM-dd HH:mm:ss" + return dateFormatter.string(from: date as Date) + } + + func hasChanges(comparedTo other: NCTableShareable) -> Bool { + return other.shareType != shareType + || other.permissions != permissions + || other.hideDownload != hideDownload + || other.password != password + || other.label != label + || other.note != note + || other.expirationDate != expirationDate + } +} + +class NCTableShareOptions: NCTableShareable { + + var shareType: Int + var permissions: Int + + var idShare: Int = 0 + var shareWith: String = "" + + var hideDownload: Bool = false + var password: String = "" + var label: String = "" + var note: String = "" + var expirationDate: NSDate? + var shareWithDisplayname: String = "" + + var attributes: String? + + private init(shareType: Int, metadata: tableMetadata, password: String?) async { + if metadata.e2eEncrypted, await NKCapabilities.shared.getCapabilities(for: metadata.account).e2EEApiVersion == NCGlobal.shared.e2eeVersionV12 { + self.permissions = NCPermissions().permissionCreateShare + } else { + self.permissions = await NKCapabilities.shared.getCapabilities(for: metadata.account).fileSharingDefaultPermission & metadata.sharePermissionsCollaborationServices + } + self.shareType = shareType + if let password = password { + self.password = password + } + } + + convenience init(sharee: NKSharee, metadata: tableMetadata, password: String?) async { + await self.init(shareType: sharee.shareType, metadata: metadata, password: password) + self.shareWith = sharee.shareWith + self.shareWithDisplayname = sharee.label + } + + static func shareLink(metadata: tableMetadata, password: String?) async -> NCTableShareOptions { + return await NCTableShareOptions(shareType: NCShareCommon.shareTypeLink, metadata: metadata, password: password) + } +} + +protocol NCShareDetail { + var share: NCTableShareable! { get } +} + +extension NCShareDetail where Self: UIViewController { + func setNavigationTitle() { + title = NSLocalizedString("_sharing_", comment: "") + if share.shareType != NCShareCommon.shareTypeLink { + title! = share.shareWithDisplayname.isEmpty ? share.shareWith : share.shareWithDisplayname + } + } +} diff --git a/iOSClient/Share/NCShare+NCCellDelegate.swift b/iOSClient/Share/NCShare+NCCellDelegate.swift index 76c3bf9dc8..0995bfc12f 100644 --- a/iOSClient/Share/NCShare+NCCellDelegate.swift +++ b/iOSClient/Share/NCShare+NCCellDelegate.swift @@ -48,7 +48,7 @@ extension NCShare: NCShareLinkCellDelegate, NCShareUserCellDelegate { func tapMenu(with tableShare: tableShare?, sender: Any) { if let tableShare = tableShare { - self.toggleShareMenu(for: tableShare, sender: sender) + self.toggleShareMenu(for: tableShare, sendMail: (tableShare.shareType != NCShareCommon.shareTypeLink), folder: metadata?.directory ?? false, sender: sender) } else { self.makeNewLinkShare() } diff --git a/iOSClient/Share/NCShare.storyboard b/iOSClient/Share/NCShare.storyboard index 5bf01c2fb8..13289d1bd6 100644 --- a/iOSClient/Share/NCShare.storyboard +++ b/iOSClient/Share/NCShare.storyboard @@ -1,185 +1,310 @@ - + - - - + - - - - - - - - - - - - - - - - - + - + - - + + - + - + - - + + + + + + + + + + + + + + + + + - - + + - - + + - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - + + + + - + - - - - - + + + + + - - - - - - - - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - + + - + - + - + - + - + - + - + @@ -191,10 +316,10 @@ - + - - - - - - - - + + + + + + + - - - - - + + + + + - - + + - + - - - - - + + + + + - + - - - + + + - + - + - + - - + + - + - + - + - + - + - + - - - - + + + + - + - + - + - + - - + + - + - - + + - - + + - + - - + + - - + + - + - - + + - - - - + + + + - - - + + + - + - + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - diff --git a/iOSClient/Share/NCShare.swift b/iOSClient/Share/NCShare.swift index 2551fd8558..8ad37628d0 100644 --- a/iOSClient/Share/NCShare.swift +++ b/iOSClient/Share/NCShare.swift @@ -30,17 +30,25 @@ import NextcloudKit import MarqueeLabel import ContactsUI +enum ShareSection: Int, CaseIterable { + case header + case linkByEmail + case links + case emails +} + class NCShare: UIViewController, NCSharePagingContent { - @IBOutlet weak var viewContainerConstraint: NSLayoutConstraint! - @IBOutlet weak var sharedWithYouByView: UIView! - @IBOutlet weak var sharedWithYouByImage: UIImageView! - @IBOutlet weak var sharedWithYouByLabel: UILabel! - @IBOutlet weak var searchFieldTopConstraint: NSLayoutConstraint! - @IBOutlet weak var searchField: UISearchBar! - var textField: UIView? { searchField } +// @IBOutlet weak var viewContainerConstraint: NSLayoutConstraint! +// @IBOutlet weak var sharedWithYouByView: UIView! +// @IBOutlet weak var sharedWithYouByImage: UIImageView! +// @IBOutlet weak var sharedWithYouByLabel: UILabel! +// @IBOutlet weak var searchFieldTopConstraint: NSLayoutConstraint! +// @IBOutlet weak var searchField: UISearchBar! +// var textField: UIView? { searchField } + var textField: UITextField? { self.view.viewWithTag(Tag.searchField) as? UITextField } @IBOutlet weak var tableView: UITableView! - @IBOutlet weak var btnContact: UIButton! +// @IBOutlet weak var btnContact: UIButton! weak var appDelegate = UIApplication.shared.delegate as? AppDelegate @@ -53,7 +61,9 @@ class NCShare: UIViewController, NCSharePagingContent { var shareLinksCount = 0 var canReshare: Bool { - return ((metadata.sharePermissionsCollaborationServices & NKShare.Permission.share.rawValue) != 0) + guard let metadata = metadata else { return true } + return ((metadata.sharePermissionsCollaborationServices & NCPermissions().permissionShareShare) != 0) +// return ((metadata.sharePermissionsCollaborationServices & NCSharePermissions.permissionReshareShare) != 0) } var session: NCSession.Session { @@ -67,18 +77,25 @@ class NCShare: UIViewController, NCSharePagingContent { private var dropDown = DropDown() var networking: NCShareNetworking? + var isCurrentUser: Bool { + if let currentUser = NCManageDatabase.shared.getActiveTableAccount(), currentUser.userId == metadata?.ownerId { + return true + } + return false + } + var shareLinks: [tableShare] = [] + var shareEmails: [tableShare] = [] + var shareOthers: [tableShare] = [] + private var cachedHeader: NCShareAdvancePermissionHeader? + // MARK: - View Life Cycle override func viewDidLoad() { super.viewDidLoad() + navigationController?.setNavigationBarAppearance() view.backgroundColor = .systemBackground - - viewContainerConstraint.constant = height - searchFieldTopConstraint.constant = 0 - - searchField.placeholder = NSLocalizedString("_shareLinksearch_placeholder_", comment: "") - searchField.autocorrectionType = .no + title = NSLocalizedString("_details_", comment: "") tableView.dataSource = self tableView.delegate = self @@ -88,39 +105,57 @@ class NCShare: UIViewController, NCSharePagingContent { tableView.register(UINib(nibName: "NCShareLinkCell", bundle: nil), forCellReuseIdentifier: "cellLink") tableView.register(UINib(nibName: "NCShareUserCell", bundle: nil), forCellReuseIdentifier: "cellUser") + tableView.register(UINib(nibName: "NCShareEmailFieldCell", bundle: nil), forCellReuseIdentifier: "NCShareEmailFieldCell") + tableView.register(NCShareEmailLinkHeaderView.self, + forHeaderFooterViewReuseIdentifier: NCShareEmailLinkHeaderView.reuseIdentifier) + tableView.register(CreateLinkFooterView.self, forHeaderFooterViewReuseIdentifier: CreateLinkFooterView.reuseIdentifier) + tableView.register(NoSharesFooterView.self, forHeaderFooterViewReuseIdentifier: NoSharesFooterView.reuseIdentifier) + tableView.register(UINib(nibName: "NCShareAdvancePermissionHeader", bundle: nil), + forHeaderFooterViewReuseIdentifier: NCShareAdvancePermissionHeader.reuseIdentifier) NotificationCenter.default.addObserver(self, selector: #selector(reloadData), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterReloadDataNCShare), object: nil) - + NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(appWillEnterForeground), name: UIApplication.willEnterForegroundNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(reloadData), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterDidCreateShareLink), object: nil) +// NotificationCenter.default.addObserver(self, selector: #selector(handleFavoriteStatusChanged), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterFavoriteStatusChanged), object: nil) + + guard let metadata = metadata else { return } + + reloadData() + Task { self.capabilities = await NKCapabilities.shared.getCapabilities(for: metadata.account) if metadata.e2eEncrypted { let metadataDirectory = await self.database.getMetadataDirectoryAsync(serverUrl: metadata.serverUrl, account: metadata.account) if capabilities.e2EEApiVersion == NCGlobal.shared.e2eeVersionV12 || (capabilities.e2EEApiVersion == NCGlobal.shared.e2eeVersionV20 && metadataDirectory?.e2eEncrypted ?? false) { - searchFieldTopConstraint.constant = -50 - searchField.alpha = 0 - btnContact.alpha = 0 } } else { - checkSharedWithYou() } - - reloadData() - + networking = NCShareNetworking(metadata: metadata, view: self.view, delegate: self, session: session) let isVisible = (self.navigationController?.topViewController as? NCSharePaging)?.page == .sharing networking?.readShare(showLoadingIndicator: isVisible) - - searchField.searchTextField.font = .systemFont(ofSize: 14) - searchField.delegate = self } + + navigationItem.leftBarButtonItem = UIBarButtonItem(title: NSLocalizedString("_close_", comment: ""), style: .plain, target: self, action: #selector(exitTapped)) } + override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + super.traitCollectionDidChange(previousTraitCollection) + } + + @objc func exitTapped() { + NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterUpdateIcons) + self.dismiss(animated: true, completion: nil) + } + func makeNewLinkShare() { guard let advancePermission = UIStoryboard(name: "NCShare", bundle: nil).instantiateViewController(withIdentifier: "NCShareAdvancePermission") as? NCShareAdvancePermission, let navigationController = self.navigationController else { return } - self.checkEnforcedPassword(shareType: NKShare.ShareType.publicLink.rawValue) { password in + self.checkEnforcedPassword(shareType: NCShareCommon.shareTypeLink) { password in advancePermission.networking = self.networking advancePermission.share = TransientShare.shareLink(metadata: self.metadata, password: password) advancePermission.metadata = self.metadata @@ -128,75 +163,107 @@ class NCShare: UIViewController, NCSharePagingContent { } } - // Shared with you by ... - func checkSharedWithYou() { - guard !metadata.ownerId.isEmpty, metadata.ownerId != session.userId else { return } - - if !canReshare { - searchField.isUserInteractionEnabled = false - searchField.alpha = 0.5 - searchField.placeholder = NSLocalizedString("_share_reshare_disabled_", comment: "") - btnContact.isEnabled = false - } - - searchFieldTopConstraint.constant = 45 - sharedWithYouByView.isHidden = false - sharedWithYouByLabel.text = NSLocalizedString("_shared_with_you_by_", comment: "") + " " + metadata.ownerDisplayName - sharedWithYouByImage.image = utility.loadUserImage(for: metadata.ownerId, displayName: metadata.ownerDisplayName, urlBase: session.urlBase) - sharedWithYouByLabel.accessibilityHint = NSLocalizedString("_show_profile_", comment: "") - - let shareAction = UITapGestureRecognizer(target: self, action: #selector(openShareProfile(_:))) - sharedWithYouByImage.addGestureRecognizer(shareAction) - let shareLabelAction = UITapGestureRecognizer(target: self, action: #selector(openShareProfile(_:))) - sharedWithYouByLabel.addGestureRecognizer(shareLabelAction) - - let fileName = NCSession.shared.getFileName(urlBase: session.urlBase, user: metadata.ownerId) - let results = NCManageDatabase.shared.getImageAvatarLoaded(fileName: fileName) - - if results.image == nil { - let etag = self.database.getTableAvatar(fileName: fileName)?.etag - let fileNameLocalPath = utilityFileSystem.createServerUrl(serverUrl: utilityFileSystem.directoryUserData, fileName: fileName) - - NextcloudKit.shared.downloadAvatar( - user: metadata.ownerId, - fileNameLocalPath: fileNameLocalPath, - sizeImage: NCGlobal.shared.avatarSize, - avatarSizeRounded: NCGlobal.shared.avatarSizeRounded, - etagResource: etag, - account: metadata.account) { task in - Task { - let identifier = await NCNetworking.shared.networkingTasks.createIdentifier(account: self.metadata.account, - path: self.metadata.ownerId, - name: "downloadAvatar") - await NCNetworking.shared.networkingTasks.track(identifier: identifier, task: task) - } - } completion: { _, imageAvatar, _, etag, _, error in - if error == .success, let etag = etag, let imageAvatar = imageAvatar { - self.database.addAvatar(fileName: fileName, etag: etag) - self.sharedWithYouByImage.image = imageAvatar - self.reloadData() - } else if error.errorCode == NCGlobal.shared.errorNotModified, let imageAvatar = self.database.setAvatarLoaded(fileName: fileName) { - self.sharedWithYouByImage.image = imageAvatar + // MARK: - Notification Center + + @objc func openShareProfile(_ sender: UITapGestureRecognizer) { + self.showProfileMenu(userId: metadata.ownerId, session: session, sender: sender.view) + } + + private func scrollToTopIfNeeded() { + if tableView.numberOfSections > 0 && tableView.numberOfRows(inSection: 0) > 0 { + self.tableView.scrollToRow(at: IndexPath(row: 0, section: 0), at: .top, animated: false) + } + } + + @objc func keyboardWillShow(notification: Notification) { + if UIDevice.current.userInterfaceIdiom == .phone { + if UIScreen.main.bounds.width < 374 || UIDevice.current.orientation.isLandscape { + if let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue { + if view.frame.origin.y == 0 { + scrollToTopIfNeeded() + self.view.frame.origin.y -= keyboardSize.height } } + } else if UIScreen.main.bounds.height < 850 { + if view.frame.origin.y == 0 { + scrollToTopIfNeeded() + self.view.frame.origin.y -= 70 + } + } else { + if view.frame.origin.y == 0 { + scrollToTopIfNeeded() + self.view.frame.origin.y -= 40 + } + } } - reloadData() - } + if UIDevice.current.userInterfaceIdiom == .pad, UIDevice.current.orientation.isLandscape { + if view.frame.origin.y == 0 { + if tableView.numberOfSections > 0 && tableView.numberOfRows(inSection: 0) > 0 { + self.tableView.scrollToRow(at: IndexPath(row: 0, section: 0), at: .top, animated: false) + } + self.view.frame.origin.y -= 230 + } + } - // MARK: - Notification Center + textField?.layer.borderColor = NCBrandColor.shared.brand.cgColor + } - @objc func openShareProfile(_ sender: UITapGestureRecognizer) { - self.showProfileMenu(userId: metadata.ownerId, session: session, sender: sender.view) + + @objc func keyboardWillHide(notification: Notification) { + if view.frame.origin.y != 0 { + self.view.frame.origin.y = 0 + } + textField?.layer.borderColor = NCBrandColor.shared.label.cgColor } + @objc func appWillEnterForeground(notification: Notification) { + reloadData() + } + // MARK: - - + @objc func reloadData() { + guard let metadata = metadata else { + return + } shares = self.database.getTableShares(metadata: metadata) - shareLinksCount = 0 + updateShareArrays() tableView.reloadData() } + + func updateShareArrays() { + shareLinks.removeAll() + shareEmails.removeAll() + + guard var allShares = shares.share else { return } + allShares = allShares.sorted(by: { $0.date?.compare($1.date as Date? ?? Date()) == .orderedAscending }) + if let firstLink = shares.firstShareLink { + // Remove if already exists to avoid duplication + allShares.removeAll { $0.idShare == firstLink.idShare } + allShares.insert(firstLink, at: 0) + } + + shares.share = allShares + + for item in allShares { + if item.shareType == NCShareCommon.shareTypeLink { + shareLinks.append(item) + } else { + shareEmails.append(item) + } + } + } + + @objc func handleFavoriteStatusChanged(notification: Notification) { + // Retrieve the updated metadata from the notification object + if let updatedMetadata = notification.object as? tableMetadata { + // Update the table view header with the new metadata + if let headerView = tableView.tableHeaderView as? NCShareAdvancePermissionHeader { + headerView.setupUI(with: updatedMetadata, linkCount: shareLinks.count, emailCount: shareEmails.count) // Update header UI with new metadata + } + } + } // MARK: - IBAction @@ -209,13 +276,24 @@ class NCShare: UIViewController, NCSharePagingContent { return emailPred.evaluate(with: email) } guard let searchString = textField.text, !searchString.isEmpty else { return } - if searchString.contains("@"), !isValidEmail(searchString) { return } +// if searchString.contains("@"), !isValidEmail(searchString) { return } + if searchString.contains("@"), !utility.validateEmail(searchString) { return } networking?.getSharees(searchString: searchString) } - + + @IBAction func searchFieldDidChange(textField: UITextField) { + NSObject.cancelPreviousPerformRequests(withTarget: self, selector: #selector(searchSharees), object: nil) + guard let searchString = textField.text else {return} + if searchString.count == 0 { + dropDown.hide() + } else { + perform(#selector(searchSharees), with: nil, afterDelay: 0.5) + } + } + func checkEnforcedPassword(shareType: Int, completion: @escaping (String?) -> Void) { guard capabilities.fileSharingPubPasswdEnforced, - shareType == NKShare.ShareType.publicLink.rawValue || shareType == NKShare.ShareType.email.rawValue + shareType == NCShareCommon.shareTypeLink || shareType == NCShareCommon.shareTypeEmail else { return completion(nil) } self.present(UIAlertController.password(titleKey: "_enforce_password_protection_", completion: completion), animated: true) @@ -229,6 +307,44 @@ class NCShare: UIViewController, NCSharePagingContent { cnPicker.predicateForSelectionOfProperty = NSPredicate(format: "emailAddresses.@count > 0") self.present(cnPicker, animated: true) } + + @IBAction func createLinkClicked(_ sender: Any?) { + appDelegate?.adjust.trackEvent(TriggerEvent(CreateLink.rawValue)) + TealiumHelper.shared.trackEvent(title: "magentacloud-app.sharing.create", data: ["": ""]) +// self.touchUpInsideButtonMenu(sender) + self.touchUpInsideButtonMenu(sender as Any) + } + + @IBAction func touchUpInsideButtonMenu(_ sender: Any) { + + guard let metadata = metadata else { return } + let capabilities = NCNetworking.shared.capabilities[metadata.account] ?? NKCapabilities.Capabilities() + let isFilesSharingPublicPasswordEnforced = capabilities.fileSharingPubPasswdEnforced + let shares = NCManageDatabase.shared.getTableShares(metadata: metadata) + + if isFilesSharingPublicPasswordEnforced && shares.firstShareLink == nil { + let alertController = UIAlertController(title: NSLocalizedString("_enforce_password_protection_", comment: ""), message: "", preferredStyle: .alert) + alertController.addTextField { (textField) in + textField.isSecureTextEntry = true + } + alertController.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .default) { (action:UIAlertAction) in }) + let okAction = UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default) {[weak self] (action:UIAlertAction) in + let password = alertController.textFields?.first?.text + self?.networking?.createShareLink(password: password ?? "") + } + + alertController.addAction(okAction) + + present(alertController, animated: true, completion:nil) + } else if shares.firstShareLink == nil { + networking?.createShareLink(password: "") + + } else { + networking?.createShareLink(password: "") + } + + } + } // MARK: - NCShareNetworkingDelegate @@ -258,15 +374,15 @@ extension NCShare: NCShareNetworkingDelegate { } // close keyboard - self.view.endEditing(true) +// self.view.endEditing(true) dropDown = DropDown() let appearance = DropDown.appearance() - // Setting up the blur effect - let blurEffect = UIBlurEffect(style: .light) // You can choose .dark, .extraLight, or .light - let blurEffectView = UIVisualEffectView(effect: blurEffect) - blurEffectView.frame = CGRect(x: 0, y: 0, width: 500, height: 20) +// // Setting up the blur effect +// let blurEffect = UIBlurEffect(style: .light) // You can choose .dark, .extraLight, or .light +// let blurEffectView = UIVisualEffectView(effect: blurEffect) +// blurEffectView.frame = CGRect(x: 0, y: 0, width: 500, height: 20) appearance.backgroundColor = .systemBackground appearance.cornerRadius = 10 @@ -275,6 +391,7 @@ extension NCShare: NCShareNetworkingDelegate { appearance.shadowRadius = 30 appearance.animationduration = 0.25 appearance.textColor = .darkGray + appearance.setupMaskedCorners([.layerMaxXMaxYCorner, .layerMinXMaxYCorner]) let account = NCManageDatabase.shared.getTableAccount(account: metadata.account) let existingShares = NCManageDatabase.shared.getTableShares(metadata: metadata) @@ -282,19 +399,28 @@ extension NCShare: NCShareNetworkingDelegate { for sharee in sharees { if sharee.shareWith == account?.user { continue } // do not show your own account if let shares = existingShares.share, shares.contains(where: {$0.shareWith == sharee.shareWith}) { continue } // do not show already existing sharees - if metadata.ownerDisplayName == sharee.shareWith { continue } // do not show owner of the share + if metadata.ownerDisplayName == sharee.shareWith { continue } // do not show owner of the share var label = sharee.label - if sharee.shareType == NKShare.ShareType.team.rawValue { + if sharee.shareType == NCShareCommon.shareTypeTeam { label += " (\(sharee.circleInfo), \(sharee.circleOwner))" } dropDown.dataSource.append(label) } - dropDown.anchorView = searchField - dropDown.bottomOffset = CGPoint(x: 10, y: searchField.bounds.height) - dropDown.width = searchField.bounds.width - 20 + dropDown.anchorView = textField + dropDown.bottomOffset = CGPoint(x: 10, y: textField?.bounds.height ?? 0) + dropDown.width = (textField?.bounds.width ?? 0) - 20 dropDown.direction = .bottom +// dropDown.bottomOffset = CGPoint(x: 0, y: textField?.bounds.height ?? 0) +// dropDown.width = textField?.bounds.width ?? 0 +// if (UIDevice.current.userInterfaceIdiom == .phone || UIDevice.current.orientation.isLandscape), UIScreen.main.bounds.width < 1111 { +// dropDown.topOffset = CGPoint(x: 0, y: -(textField?.bounds.height ?? 0)) +// dropDown.direction = .top +// } else { +// dropDown.bottomOffset = CGPoint(x: 0, y: (textField?.bounds.height ?? 0) - 80) +// dropDown.direction = .any +// } dropDown.cellNib = UINib(nibName: "NCSearchUserDropDownCell", bundle: nil) dropDown.customCellConfiguration = { (index: Index, _, cell: DropDownCell) in @@ -304,6 +430,8 @@ extension NCShare: NCShareNetworkingDelegate { } dropDown.selectionAction = { index, _ in + self.textField?.text = "" + self.textField?.resignFirstResponder() let sharee = sharees[index] guard let advancePermission = UIStoryboard(name: "NCShare", bundle: nil).instantiateViewController(withIdentifier: "NCShareAdvancePermission") as? NCShareAdvancePermission, @@ -334,8 +462,25 @@ extension NCShare: NCShareNetworkingDelegate { extension NCShare: UITableViewDelegate { func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { - return 60 + guard let sectionType = ShareSection(rawValue: indexPath.section) else { return 0 } + + switch sectionType { + case .header: + return 210 + + case .linkByEmail: + let isPad = UIDevice.current.userInterfaceIdiom == .pad + if isCurrentUser { + return 130 + } else { + return isPad ? (canReshare ? 200 : 220) : 220 + } + + case .links, .emails: + return 60 + } } + } // MARK: - UITableViewDataSource @@ -343,74 +488,158 @@ extension NCShare: UITableViewDelegate { extension NCShare: UITableViewDataSource { func numberOfSections(in tableView: UITableView) -> Int { - return 2 + ShareSection.allCases.count } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - var numRows = shares.share?.count ?? 0 - if section == 0 { - if metadata.e2eEncrypted, capabilities.e2EEApiVersion == NCGlobal.shared.e2eeVersionV12 { - numRows = 1 - } else { - // don't allow link creation if reshare is disabled - numRows = shares.firstShareLink != nil || canReshare ? 2 : 1 - } + guard let sectionType = ShareSection(rawValue: section) else { return 0 } + + switch sectionType { + case .header: + return 0 + case .linkByEmail: + return 1 + case .links: + return shareLinks.count + case .emails: + return shareEmails.count } - return numRows } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - // Setup default share cells - guard indexPath.section != 0 else { - guard let cell = tableView.dequeueReusableCell(withIdentifier: "cellLink", for: indexPath) as? NCShareLinkCell - else { return UITableViewCell() } + guard let sectionType = ShareSection(rawValue: indexPath.section) else { return UITableViewCell() } + + switch sectionType { + case .header: + return UITableViewCell() // Empty row + case .linkByEmail: + guard let cell = tableView.dequeueReusableCell(withIdentifier: "NCShareEmailFieldCell", for: indexPath) as? NCShareEmailFieldCell else { + return UITableViewCell() + } + cell.searchField.addTarget(self, action: #selector(searchFieldDidEndOnExit(textField:)), for: .editingDidEndOnExit) + cell.searchField.addTarget(self, action: #selector(searchFieldDidChange(textField:)), for: .editingChanged) + cell.btnContact.addTarget(self, action: #selector(selectContactClicked(_:)), for: .touchUpInside) + cell.setupCell(with: metadata) + return cell + + case .links: + let tableShare = shareLinks[indexPath.row] + guard let cell = tableView.dequeueReusableCell(withIdentifier: "cellLink", for: indexPath) as? NCShareLinkCell else { + return UITableViewCell() + } cell.delegate = self - if metadata.e2eEncrypted, capabilities.e2EEApiVersion == NCGlobal.shared.e2eeVersionV12 { - cell.tableShare = shares.firstShareLink + if indexPath.row == 0 { + cell.configure(with: tableShare, at: indexPath, isDirectory: metadata.directory, title: "") } else { - if indexPath.row == 0 { - cell.isInternalLink = true - } else if shares.firstShareLink?.isInvalidated != true { - cell.tableShare = shares.firstShareLink - } + let linkNumber = " \(indexPath.row + 1)" + cell.configure(with: tableShare, at: indexPath, isDirectory: metadata.directory, title: linkNumber) } - cell.isDirectory = metadata.directory - cell.setupCellUI() - shareLinksCount += 1 + return cell + + case .emails: + let tableShare = shareEmails[indexPath.row] + guard let cell = tableView.dequeueReusableCell(withIdentifier: "cellUser", for: indexPath) as? NCShareUserCell else { + return UITableViewCell() + } + cell.delegate = self + cell.configure(with: tableShare, at: indexPath, isDirectory: metadata.directory, userId: session.userId) return cell } + } - let orderedShares = shares.share?.sorted(by: { $0.date?.compare($1.date as Date? ?? Date()) == .orderedAscending }) - guard let tableShare = orderedShares?[indexPath.row] else { return UITableViewCell() } + func numberOfRows(in section: Int) -> Int { + return tableView(tableView, numberOfRowsInSection: section) + } + + func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { + guard let sectionType = ShareSection(rawValue: section) else { return nil } + + switch sectionType { + case .header: + let headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: NCShareAdvancePermissionHeader.reuseIdentifier) as? NCShareAdvancePermissionHeader + headerView?.ocId = metadata.ocId + headerView?.setupUI(with: metadata, linkCount: shareLinks.count, emailCount: shareEmails.count) + return headerView + + case .linkByEmail: + return nil + + case .links: + if isCurrentUser || canReshare { + let headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "NCShareEmailLinkHeaderView") as? NCShareEmailLinkHeaderView + headerView?.configure(text: NSLocalizedString("_share_copy_link_", comment: "123")) + return headerView + } + return nil - // LINK, EMAIL - if tableShare.shareType == NKShare.ShareType.publicLink.rawValue || tableShare.shareType == NKShare.ShareType.email.rawValue { - if let cell = tableView.dequeueReusableCell(withIdentifier: "cellLink", for: indexPath) as? NCShareLinkCell { - cell.indexPath = indexPath - cell.tableShare = tableShare - cell.isDirectory = metadata.directory - cell.delegate = self - cell.setupCellUI(titleAppendString: String(shareLinksCount)) - if tableShare.shareType == NKShare.ShareType.publicLink.rawValue { shareLinksCount += 1 } - return cell + case .emails: + if (isCurrentUser || canReshare) && numberOfRows(in: section) > 0 { + let headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "NCShareEmailLinkHeaderView") as? NCShareEmailLinkHeaderView + headerView?.configure(text: NSLocalizedString("_share_shared_with_", comment: "")) + return headerView } - } else { - // USER / GROUP etc. - if let cell = tableView.dequeueReusableCell(withIdentifier: "cellUser", for: indexPath) as? NCShareUserCell { - cell.indexPath = indexPath - cell.tableShare = tableShare - cell.isDirectory = metadata.directory - cell.delegate = self - cell.setupCellUI(userId: session.userId, session: session, metadata: metadata) - - return cell + return nil + } + } + + func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { + guard let sectionType = ShareSection(rawValue: section) else { return 0 } + + switch sectionType { + case .header: + return 190 + case .linkByEmail: + return 0 + case .links: + return (isCurrentUser || canReshare) ? 44 : 0 + case .emails: + return ((isCurrentUser || canReshare) && numberOfRows(in: section) > 0) ? 44 : 0 + } + } + + func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? { + guard isCurrentUser || canReshare, + let sectionType = ShareSection(rawValue: section) else { + return nil + } + + switch sectionType { + case .links: + let footer = tableView.dequeueReusableHeaderFooterView(withIdentifier: CreateLinkFooterView.reuseIdentifier) as? CreateLinkFooterView + footer?.createButtonAction = { [weak self] in + self?.createLinkClicked(nil) + } + return footer + + case .emails: + if numberOfRows(in: section) == 0 { + return tableView.dequeueReusableHeaderFooterView(withIdentifier: NoSharesFooterView.reuseIdentifier) } + return nil + case .header, .linkByEmail: + return nil + } + } + + func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { + guard isCurrentUser || canReshare, + let sectionType = ShareSection(rawValue: section) else { + return 0.001 } - return UITableViewCell() + switch sectionType { + case .links: + return 80 + case .emails: + return numberOfRows(in: section) == 0 ? 100 : 80 + case .header, .linkByEmail: + return 0.001 + } } + } + // MARK: - CNContactPickerDelegate extension NCShare: CNContactPickerDelegate { @@ -418,7 +647,7 @@ extension NCShare: CNContactPickerDelegate { if contact.emailAddresses.count > 1 { showEmailList(arrEmail: contact.emailAddresses.map({$0.value as String}), sender: picker) } else if let email = contact.emailAddresses.first?.value as? String { - searchField?.text = email + textField?.text = email networking?.getSharees(searchString: email) } } @@ -434,7 +663,7 @@ extension NCShare: CNContactPickerDelegate { on: false, sender: sender, action: { _ in - self.searchField?.text = email + self.textField?.text = email self.networking?.getSharees(searchString: email) } ) @@ -455,7 +684,7 @@ extension NCShare: UISearchBarDelegate { if searchText.isEmpty { dropDown.hide() } else { - perform(#selector(searchSharees(_:)), with: nil, afterDelay: 1) + perform(#selector(searchSharees(_:)), with: nil, afterDelay: 0.5) } } @@ -467,7 +696,7 @@ extension NCShare: UISearchBarDelegate { let emailPred = NSPredicate(format: "SELF MATCHES %@", emailRegEx) return emailPred.evaluate(with: email) } - guard let searchString = searchField.text, !searchString.isEmpty else { return } + guard let searchString = textField?.text, !searchString.isEmpty else { return } if searchString.contains("@"), !isValidEmail(searchString) { return } networking?.getSharees(searchString: searchString) } diff --git a/iOSClient/Share/NCShareCommon.swift b/iOSClient/Share/NCShareCommon.swift index c79dfa9305..f96b33f55a 100644 --- a/iOSClient/Share/NCShareCommon.swift +++ b/iOSClient/Share/NCShareCommon.swift @@ -22,9 +22,19 @@ import UIKit import DropDown -import NextcloudKit enum NCShareCommon { + static let shareTypeUser = 0 + static let shareTypeGroup = 1 + static let shareTypeLink = 3 + static let shareTypeEmail = 4 + static let shareTypeContact = 5 + static let shareTypeFederated = 6 + static let shareTypeTeam = 7 + static let shareTypeGuest = 8 + static let shareTypeFederatedGroup = 9 + static let shareTypeRoom = 10 + static let itemTypeFile = "file" static let itemTypeFolder = "folder" @@ -58,24 +68,76 @@ enum NCShareCommon { } } - static func getImageShareType(shareType: Int) -> UIImage? { - typealias type = NKShare.ShareType + static func getImageShareType(shareType: Int, isDropDown:Bool = false) -> UIImage? { switch shareType { - case type.group.rawValue: + case NCShareCommon.shareTypeUser: + return UIImage(named: "shareTypeEmail")?.withTintColor(NCBrandColor.shared.textColor, renderingMode: .alwaysOriginal) + case NCShareCommon.shareTypeGroup: return UIImage(named: "shareTypeGroup")?.withTintColor(NCBrandColor.shared.textColor, renderingMode: .alwaysOriginal) - case type.publicLink.rawValue: + case NCShareCommon.shareTypeLink: return UIImage(named: "shareTypeLink")?.withTintColor(NCBrandColor.shared.textColor, renderingMode: .alwaysOriginal) - case type.email.rawValue: - return UIImage(named: "shareTypeEmail")?.withTintColor(NCBrandColor.shared.textColor, renderingMode: .alwaysOriginal) - case type.team.rawValue: - return UIImage(named: "shareTypeTeam")?.withTintColor(NCBrandColor.shared.textColor, renderingMode: .alwaysOriginal) - case type.federatedGroup.rawValue: + case NCShareCommon.shareTypeEmail: + return UIImage(named: isDropDown ? "email" : "shareTypeUser")?.withTintColor(NCBrandColor.shared.textColor, renderingMode: .alwaysOriginal) + case NCShareCommon.shareTypeContact: + return UIImage(named: "shareTypeUser")?.withTintColor(NCBrandColor.shared.textColor, renderingMode: .alwaysOriginal) + case NCShareCommon.shareTypeFederated: +// return UIImage(named: "shareTypeUser")?.withTintColor(NCBrandColor.shared.textColor, renderingMode: .alwaysOriginal) + return UIImage(named: isDropDown ? "shareTypeUser" : "shareTypeEmail")?.withTintColor(NCBrandColor.shared.textColor, renderingMode: .alwaysOriginal) + case NCShareCommon.shareTypeTeam: +// return UIImage(named: "shareTypeTeam")?.withTintColor(NCBrandColor.shared.textColor, renderingMode: .alwaysOriginal) + return UIImage(named: "shareTypeCircles")?.withTintColor(NCBrandColor.shared.textColor, renderingMode: .alwaysOriginal) + case NCShareCommon.shareTypeGuest: + return UIImage(named: "shareTypeUser")?.withTintColor(NCBrandColor.shared.textColor, renderingMode: .alwaysOriginal) + case NCShareCommon.shareTypeFederatedGroup: return UIImage(named: "shareTypeGroup")?.withTintColor(NCBrandColor.shared.textColor, renderingMode: .alwaysOriginal) - case type.talkConversation.rawValue: + case NCShareCommon.shareTypeRoom: return UIImage(named: "shareTypeRoom")?.withTintColor(NCBrandColor.shared.textColor, renderingMode: .alwaysOriginal) default: return UIImage(named: "shareTypeUser")?.withTintColor(NCBrandColor.shared.textColor, renderingMode: .alwaysOriginal) } } + + static func isLinkShare(shareType: Int) -> Bool { + return shareType == NCShareCommon.shareTypeLink + } + + static func isExternalUserShare(shareType: Int) -> Bool { + return shareType == NCShareCommon.shareTypeEmail + } + + static func isInternalUser(shareType: Int) -> Bool { + return shareType == NCShareCommon.shareTypeUser + } + + static func isFileTypeAllowedForEditing(fileExtension: String, shareType: Int) -> Bool { + if fileExtension == "md" || fileExtension == "txt" { + return true + } else { + return isInternalUser(shareType: shareType) + } + } + + static func isEditingEnabled(isDirectory: Bool, fileExtension: String, shareType: Int) -> Bool { + if !isDirectory {//file + return isFileTypeAllowedForEditing(fileExtension: fileExtension, shareType: shareType) + } else { + return true + } + } + + static func isFileDropOptionVisible(isDirectory: Bool, shareType: Int) -> Bool { + return (isDirectory && (isLinkShare(shareType: shareType) || isExternalUserShare(shareType: shareType))) + } + + static func isCurrentUserIsFileOwner(fileOwnerId: String) -> Bool { + if let currentUser = NCManageDatabase.shared.getActiveTableAccount(), currentUser.userId == fileOwnerId { + return true + } + return false + } + + static func canReshare(withPermission permission: String) -> Bool { + return permission.contains(NCPermissions().permissionCanShare) + } } diff --git a/iOSClient/Share/NCShareEmailFieldCell.swift b/iOSClient/Share/NCShareEmailFieldCell.swift new file mode 100644 index 0000000000..48cdcb1774 --- /dev/null +++ b/iOSClient/Share/NCShareEmailFieldCell.swift @@ -0,0 +1,188 @@ +// +// NCShareEmailFieldCell.swift +// Nextcloud +// +// Created by A200020526 on 01/06/23. +// Copyright © 2023 Marino Faggiana. All rights reserved. +// + +import UIKit +import MarqueeLabel +import NextcloudKit + +enum Tag { + static let searchField = 999 +} + +class NCShareEmailFieldCell: UITableViewCell { + + @IBOutlet weak var searchField: UITextField! + @IBOutlet weak var labelOrLink: UILabel! + @IBOutlet weak var btnContact: UIButton! + @IBOutlet weak var labelSeparator1: UILabel! + @IBOutlet weak var labelSeparator2: UILabel! + @IBOutlet weak var labelSendLinkByMail: UILabel! + @IBOutlet weak var labelSharedWithBy: UILabel! + @IBOutlet weak var labelResharingAllowed: UILabel! + @IBOutlet weak var topConstraintResharingView: NSLayoutConstraint! + @IBOutlet weak var viewOrLinkSeparator: UIView! + + var ocId = "" + + override func awakeFromNib() { + super.awakeFromNib() + } + + override func setSelected(_ selected: Bool, animated: Bool) { + super.setSelected(selected, animated: animated) + } + + override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + super.traitCollectionDidChange(previousTraitCollection) + if previousTraitCollection?.userInterfaceStyle != traitCollection.userInterfaceStyle { + setupCellAppearance() + } + } + + func setupCell(with metadata: tableMetadata) { +// contentView.backgroundColor = NCBrandColor.shared.secondarySystemGroupedBackground + ocId = metadata.ocId + + setupCellAppearance() + updateCanReshareUI() + + setNeedsLayout() + layoutIfNeeded() + } + + func setupCellAppearance() { + configureSearchField() + configureContactButton() + configureLabels() + } + + private func configureSearchField() { + searchField.layer.cornerRadius = 5 + searchField.layer.masksToBounds = true + searchField.layer.borderWidth = 1 + searchField.layer.borderColor = NCBrandColor.shared.label.cgColor + searchField.text = "" + searchField.textColor = NCBrandColor.shared.label + searchField.attributedPlaceholder = NSAttributedString( + string: NSLocalizedString("_shareLinksearch_placeholder_", comment: ""), + attributes: [.foregroundColor: NCBrandColor.shared.gray60] + ) + searchField.tag = Tag.searchField + setDoneButton(sender: searchField) + } + + private func configureContactButton() { + btnContact.layer.cornerRadius = 5 + btnContact.layer.masksToBounds = true + btnContact.layer.borderWidth = 1 + btnContact.layer.borderColor = NCBrandColor.shared.label.cgColor + if let image = UIImage(named: "Contacts")?.withRenderingMode(.alwaysTemplate) { + btnContact.setImage(image, for: .normal) + } + btnContact.tintColor = NCBrandColor.shared.label + + } + + private func configureLabels() { + labelOrLink.text = NSLocalizedString("_share_or_", comment: "") + labelSendLinkByMail.text = NSLocalizedString("_share_send_link_by_mail_", comment: "") + labelSharedWithBy.text = NSLocalizedString("_share_received_shares_text_", comment: "") + labelResharingAllowed.text = NSLocalizedString("_share_reshare_allowed_", comment: "") + + labelSendLinkByMail.textColor = NCBrandColor.shared.label + labelSharedWithBy.textColor = NCBrandColor.shared.label + labelResharingAllowed.textColor = NCBrandColor.shared.label + } + + func updateCanReshareUI() { + guard let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) else { return } + + let isCurrentUser = NCShareCommon.isCurrentUserIsFileOwner(fileOwnerId: metadata.ownerId) + let canReshare = (metadata.sharePermissionsCollaborationServices & NCPermissions().permissionShareShare) != 0 + + labelSharedWithBy.isHidden = isCurrentUser + labelResharingAllowed.isHidden = isCurrentUser + + if !canReshare { + searchField.isUserInteractionEnabled = false + searchField.alpha = 0.5 + btnContact.isEnabled = false + btnContact.alpha = 0.5 + } + + if !isCurrentUser { + let ownerName = metadata.ownerDisplayName + let fullText = NSLocalizedString("_share_received_shares_text_", comment: "") + " " + ownerName + let attributed = NSMutableAttributedString(string: fullText) + + if let range = fullText.range(of: ownerName) { + let nsRange = NSRange(range, in: fullText) + attributed.addAttribute(.font, value: UIFont.boldSystemFont(ofSize: 16), range: nsRange) + } + + labelSharedWithBy.attributedText = attributed + labelSharedWithBy.numberOfLines = 0 + + labelResharingAllowed.text = canReshare + ? NSLocalizedString("_share_reshare_allowed_", comment: "") + : NSLocalizedString("_share_reshare_not_allowed_", comment: "") + + topConstraintResharingView.constant = 15 + } else { + topConstraintResharingView.constant = 0 + } + + viewOrLinkSeparator.isHidden = !canReshare + } + + func updateShareUI(ocId: String, count: Int) { + guard let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) else { return } + + let isCurrentUser = NCShareCommon.isCurrentUserIsFileOwner(fileOwnerId: metadata.ownerId) + let canReshare = (metadata.sharePermissionsCollaborationServices & NCPermissions().permissionShareShare) != 0 + + if !isCurrentUser { + if canReshare { + labelOrLink.isHidden = true + labelSeparator1.isHidden = true + labelSeparator2.isHidden = true + } + } + } + + @objc func cancelDatePicker() { + self.searchField.endEditing(true) + } + + private func setDoneButton(sender: UITextField) { + let toolbar = UIToolbar() + toolbar.sizeToFit() + let doneButton = UIBarButtonItem( + title: NSLocalizedString("_done_", comment: ""), + style: .plain, + target: self, + action: #selector(cancelDatePicker) + ) + let space = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil) + toolbar.setItems([space, doneButton], animated: false) + sender.inputAccessoryView = toolbar + } + + @IBAction func touchUpInsideFavorite(_ sender: UIButton) { + // Hook for favorite action if needed + } + + @IBAction func touchUpInsideDetails(_ sender: UIButton) { + // Hook for toggling detail visibility if needed + } + + @objc func longTap(_ sender: UIGestureRecognizer) { + let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_copied_path_") + NCContentPresenter().showInfo(error: error) + } +} diff --git a/iOSClient/Share/NCShareEmailFieldCell.xib b/iOSClient/Share/NCShareEmailFieldCell.xib new file mode 100644 index 0000000000..8384397621 --- /dev/null +++ b/iOSClient/Share/NCShareEmailFieldCell.xib @@ -0,0 +1,186 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/iOSClient/Share/NCShareEmailLinkHeaderView.swift b/iOSClient/Share/NCShareEmailLinkHeaderView.swift new file mode 100644 index 0000000000..9502164891 --- /dev/null +++ b/iOSClient/Share/NCShareEmailLinkHeaderView.swift @@ -0,0 +1,43 @@ +// +// NCShareEmailLinkHeaderView.swift +// Nextcloud +// +// Created by A106551118 on 12/08/25. +// Copyright © 2025 Marino Faggiana. All rights reserved. +// + +import UIKit + +class NCShareEmailLinkHeaderView: UITableViewHeaderFooterView { + private let label = UILabel() + static let reuseIdentifier = "NCShareEmailLinkHeaderView" + + override init(reuseIdentifier: String?) { + super.init(reuseIdentifier: reuseIdentifier) + setup() + } + + required init?(coder: NSCoder) { + super.init(coder: coder) + setup() + } + + private func setup() { + contentView.backgroundColor = .clear + label.translatesAutoresizingMaskIntoConstraints = false + label.font = .systemFont(ofSize: 17, weight: .semibold) + label.textColor = NCBrandColor.shared.textColor + contentView.addSubview(label) + + NSLayoutConstraint.activate([ + label.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 20), + label.heightAnchor.constraint(equalToConstant: 30), + label.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 15), + label.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -15), + ]) + } + + func configure(text: String) { + label.text = text + } +} diff --git a/iOSClient/Share/NCShareHeader.swift b/iOSClient/Share/NCShareHeader.swift index 3d38815179..1dda12d002 100644 --- a/iOSClient/Share/NCShareHeader.swift +++ b/iOSClient/Share/NCShareHeader.swift @@ -71,3 +71,109 @@ class NCShareHeader: UIView { } } } + +class NCShareAdvancePermissionHeader: UITableViewHeaderFooterView { + @IBOutlet weak var imageView: UIImageView! + @IBOutlet weak var fileName: UILabel! + @IBOutlet weak var info: UILabel! + @IBOutlet weak var favorite: UIButton! + @IBOutlet weak var fullWidthImageView: UIImageView! + + static let reuseIdentifier = "NCShareAdvancePermissionHeader" + + var ocId = "" + let utility = NCUtility() + let utilityFileSystem = NCUtilityFileSystem() + + func setupUI(with metadata: tableMetadata) { + fileName.textColor = NCBrandColor.shared.label + info.textColor = NCBrandColor.shared.textInfo + + let isShare = metadata.permissions.contains(NCPermissions().permissionShared) + + if let image = NCUtility().getImage(ocId: metadata.ocId, etag: metadata.etag, ext: NCGlobal.shared.previewExt1024, userId: metadata.userId, urlBase: metadata.urlBase) { + fullWidthImageView.image = image + fullWidthImageView.contentMode = .scaleAspectFill + imageView.isHidden = true + } else { + imageView.isHidden = false + if metadata.e2eEncrypted { + imageView.image = NCImageCache.shared.getFolderEncrypted(account: metadata.account) + } else if isShare || !metadata.shareType.isEmpty { + imageView.image = NCImageCache.shared.getFolderPublic(account: metadata.account) + } else if !metadata.shareType.isEmpty { + imageView.image = metadata.shareType.contains(3) + ? NCImageCache.shared.getFolderPublic(account: metadata.account) + : NCImageCache.shared.getFolderSharedWithMe(account: metadata.account) + } else if metadata.permissions.contains("S"), (metadata.permissions.range(of: "S") != nil) { + imageView.image = NCImageCache.shared.getImageSharedWithMe() + } else if metadata.directory { + imageView.image = NCImageCache.shared.getFolder(account: metadata.account) + } else if !metadata.iconName.isEmpty { + imageView.image = NCUtility().loadImage(named: metadata.iconName, useTypeIconFile: true, account: metadata.account) + } else { + imageView.image = NCImageCache.shared.getImageFile() + } + } + + fileName.text = metadata.fileNameView + fileName.textColor = NCBrandColor.shared.fileFolderName + + updateFavoriteIcon(isFavorite: metadata.favorite) + info.text = utilityFileSystem.transformedSize(metadata.size) + ", " + utility.getRelativeDateTitle(metadata.date as Date) + } + + func setupUI(with metadata: tableMetadata, linkCount: Int, emailCount: Int) { + fileName.textColor = NCBrandColor.shared.label + info.textColor = NCBrandColor.shared.textInfo + + let isShare = metadata.permissions.contains(NCPermissions().permissionShared) + let hasShares = (linkCount > 0 || emailCount > 0) + + if let image = NCUtility().getImage(ocId: metadata.ocId, etag: metadata.etag, ext: NCGlobal.shared.previewExt1024, userId: metadata.userId, urlBase: metadata.urlBase) { + fullWidthImageView.image = image + fullWidthImageView.contentMode = .scaleAspectFill + imageView.isHidden = true + } else { + imageView.isHidden = false + if metadata.e2eEncrypted { + imageView.image = NCImageCache.shared.getFolderEncrypted(account: metadata.account) + } else if metadata.permissions.contains("S"), (metadata.permissions.range(of: "S") != nil) { + imageView.image = NCImageCache.shared.getFolderSharedWithMe(account: metadata.account) + } else if isShare || !metadata.shareType.isEmpty { + imageView.image = NCImageCache.shared.getFolderPublic(account: metadata.account) + } else if metadata.directory { + imageView.image = NCImageCache.shared.getFolder(account: metadata.account) + } else if !metadata.iconName.isEmpty { + imageView.image = NCUtility().loadImage(named: metadata.iconName, useTypeIconFile: true, account: metadata.account) + } else { + imageView.image = NCImageCache.shared.getImageFile() + } + } + + fileName.text = metadata.fileNameView + fileName.textColor = NCBrandColor.shared.fileFolderName + + updateFavoriteIcon(isFavorite: metadata.favorite) + info.text = utilityFileSystem.transformedSize(metadata.size) + ", " + utility.getRelativeDateTitle(metadata.date as Date) + } + + private func updateFavoriteIcon(isFavorite: Bool) { + favorite.setImage(NCUtility().loadImage(named: isFavorite ? "star" : "star.fill", colors: [NCBrandColor.shared.yellowFavorite], size: 24), for: .normal) + } + + @IBAction func touchUpInsideFavorite(_ sender: UIButton) { + guard let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) else { return } + NCNetworking.shared.favoriteMetadata(metadata) { error in + if error == .success { + Task { + guard let metadata = await NCManageDatabase.shared.getMetadataFromOcIdAsync(metadata.ocId) else { return } + self.updateFavoriteIcon(isFavorite: metadata.favorite) +// NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterFavoriteStatusChanged, object: metadata) + } + } else { + NCContentPresenter().showError(error: error) + } + } + } +} diff --git a/iOSClient/Share/NCShareHeader.xib b/iOSClient/Share/NCShareHeader.xib index 55ffce6cab..88f3d5ea08 100644 --- a/iOSClient/Share/NCShareHeader.xib +++ b/iOSClient/Share/NCShareHeader.xib @@ -1,52 +1,52 @@ - - + + - - + + - + - + - + - + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - + + - - + + - - + + - - - - - - + + + + + + diff --git a/iOSClient/Share/NCShareHeaderView.xib b/iOSClient/Share/NCShareHeaderView.xib index 44b83d3fc7..b7384fb2ec 100644 --- a/iOSClient/Share/NCShareHeaderView.xib +++ b/iOSClient/Share/NCShareHeaderView.xib @@ -1,149 +1,176 @@ - + - - + - - + + - - + + - - + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - + + + + + + + + + + + + - + - - - - - - - - - - - - - - - + + diff --git a/iOSClient/Share/NCShareLinkCell.swift b/iOSClient/Share/NCShareLinkCell.swift index 406dc31b0a..134b0afa3c 100644 --- a/iOSClient/Share/NCShareLinkCell.swift +++ b/iOSClient/Share/NCShareLinkCell.swift @@ -24,22 +24,27 @@ import UIKit import NextcloudKit class NCShareLinkCell: UITableViewCell { - @IBOutlet private weak var imageItem: UIImageView! - @IBOutlet private weak var labelTitle: UILabel! - @IBOutlet private weak var descriptionLabel: UILabel! + @IBOutlet weak var labelTitle: UILabel! + @IBOutlet weak var buttonDetail: UIButton! + @IBOutlet weak var buttonCopy: UIButton! + @IBOutlet weak var btnQuickStatus: UIButton! + @IBOutlet weak var imagePermissionType: UIImageView! + @IBOutlet weak var imageExpiredDateSet: UIImageView! + @IBOutlet weak var imagePasswordSet: UIImageView! + @IBOutlet weak var imageAllowedPermission: UIImageView! + @IBOutlet weak var imageRightArrow: UIImageView! @IBOutlet weak var labelQuickStatus: UILabel! - @IBOutlet weak var statusStackView: UIStackView! - @IBOutlet private weak var menuButton: UIButton! - @IBOutlet private weak var copyButton: UIButton! - @IBOutlet weak var imageDownArrow: UIImageView! + @IBOutlet weak var leadingContraintofImageRightArrow: NSLayoutConstraint! + + private let iconShareSize: CGFloat = 200 - var tableShare: tableShare? - var isDirectory = false weak var delegate: NCShareLinkCellDelegate? + + var tableShare: tableShare? var isInternalLink = false + var isDirectory = false var indexPath = IndexPath() - let utility = NCUtility() override func prepareForReuse() { super.prepareForReuse() @@ -49,7 +54,8 @@ class NCShareLinkCell: UITableViewCell { func setupCellUI(titleAppendString: String? = nil) { var menuImageName = "ellipsis" - + let permissions = NCPermissions() + menuButton.isHidden = isInternalLink descriptionLabel.isHidden = !isInternalLink copyButton.isHidden = !isInternalLink && tableShare == nil @@ -57,21 +63,21 @@ class NCShareLinkCell: UITableViewCell { copyButton.setImage(UIImage(systemName: "doc.on.doc")?.withTintColor(.label, renderingMode: .alwaysOriginal), for: .normal) copyButton.accessibilityLabel = NSLocalizedString("_copy_", comment: "") - + menuButton.accessibilityLabel = NSLocalizedString("_more_", comment: "") menuButton.accessibilityIdentifier = "showShareLinkDetails" - + if isInternalLink { labelTitle.text = NSLocalizedString("_share_internal_link_", comment: "") descriptionLabel.text = NSLocalizedString("_share_internal_link_des_", comment: "") imageItem.image = NCUtility().loadImage(named: "square.and.arrow.up.circle.fill", colors: [NCBrandColor.shared.iconImageColor2]) } else { labelTitle.text = NSLocalizedString("_share_link_", comment: "") - + if let titleAppendString { labelTitle.text?.append(" (\(titleAppendString))") } - + if let tableShare = tableShare { if !tableShare.label.isEmpty { labelTitle.text? += " (\(tableShare.label))" @@ -81,15 +87,15 @@ class NCShareLinkCell: UITableViewCell { menuButton.accessibilityLabel = NSLocalizedString("_add_", comment: "") menuButton.accessibilityIdentifier = "addShareLink" } - + imageItem.image = NCUtility().loadImage(named: "link.circle.fill", colors: [NCBrandColor.shared.getElement(account: tableShare?.account)]) menuButton.setImage(NCUtility().loadImage(named: menuImageName, colors: [NCBrandColor.shared.iconImageColor]), for: .normal) } - + labelTitle.textColor = NCBrandColor.shared.textColor - + statusStackView.isHidden = true - + if let tableShare { statusStackView.isHidden = false labelQuickStatus.text = NSLocalizedString("_custom_permissions_", comment: "") @@ -109,21 +115,93 @@ class NCShareLinkCell: UITableViewCell { imageItem.image = NCUtility().loadImage(named: "envelope.circle.fill", colors: [NCBrandColor.shared.getElement(account: tableShare.account)]) } } - + statusStackView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(openQuickStatus))) labelQuickStatus.textColor = NCBrandColor.shared.customer imageDownArrow.image = utility.loadImage(named: "arrowtriangle.down.circle", colors: [NCBrandColor.shared.customer]) } - @IBAction func touchUpCopy(_ sender: Any) { + override func awakeFromNib() { + super.awakeFromNib() + setupCellAppearance() + } + + override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + super.traitCollectionDidChange(previousTraitCollection) + if previousTraitCollection?.userInterfaceStyle != traitCollection.userInterfaceStyle { + setupCellAppearance() + } + } + + func configure(with share: tableShare?, at indexPath: IndexPath, isDirectory: Bool, title: String) { + self.tableShare = share + self.indexPath = indexPath + self.isDirectory = isDirectory + setupCellAppearance(titleAppendString: title) + +// let shareLinksCountString = shareLinksCount > 0 ? String(shareLinksCount) : "" +// setupCellAppearance(titleAppendString: shareLinksCountString) +// setupCellAppearance(titleAppendString: String(shareLinksCount)) + } + + private func setupCellAppearance(titleAppendString: String? = nil) { +// contentView.backgroundColor = NCBrandColor.shared.secondarySystemGroupedBackground + labelTitle.textColor = NCBrandColor.shared.label + labelQuickStatus.textColor = NCBrandColor.shared.shareBlueColor + + buttonDetail.setTitleColor(NCBrandColor.shared.shareBlackColor, for: .normal) + buttonCopy.setImage(UIImage(named: "share")?.image(color: NCBrandColor.shared.brand, size: 24), for: .normal) + + imageRightArrow.image = UIImage(named: "rightArrow")?.image(color: NCBrandColor.shared.shareBlueColor) + imageExpiredDateSet.image = UIImage(named: "calenderNew")?.image(color: NCBrandColor.shared.shareBlueColor) + imagePasswordSet.image = UIImage(named: "lockNew")?.image(color: NCBrandColor.shared.shareBlueColor) + + buttonDetail.setTitle(NSLocalizedString("_share_details_", comment: ""), for: .normal) + labelTitle.text = NSLocalizedString("_share_link_", comment: "") + + if let tableShare = tableShare, let titleAppendString { + if !tableShare.label.isEmpty { + labelTitle.text? += " (\(tableShare.label))" + } else { + labelTitle.text?.append(" \(titleAppendString)") + } + } + updatePermissionUI() + } + + private func updatePermissionUI() { + guard let tableShare = tableShare else { return } + + let permissions = NCPermissions() + + if tableShare.permissions == permissions.permissionCreateShare { + labelQuickStatus.text = NSLocalizedString("_share_quick_permission_everyone_can_just_upload_", comment: "") + imagePermissionType.image = UIImage(named: "upload")?.image(color: NCBrandColor.shared.shareBlueColor) + } else if permissions.isAnyPermissionToEdit(tableShare.permissions) { + labelQuickStatus.text = NSLocalizedString("_share_quick_permission_everyone_can_edit_", comment: "") + imagePermissionType.image = UIImage(named: "editNew")?.image(color: NCBrandColor.shared.shareBlueColor) + } else { + labelQuickStatus.text = NSLocalizedString("_share_quick_permission_everyone_can_only_view_", comment: "") + imagePermissionType.image = UIImage(named: "showPasswordNew")?.image(color: NCBrandColor.shared.shareBlueColor) + } + + imagePasswordSet.isHidden = tableShare.password.isEmpty + imageExpiredDateSet.isHidden = (tableShare.expirationDate == nil) + + leadingContraintofImageRightArrow.constant = (imagePasswordSet.isHidden && imageExpiredDateSet.isHidden) ? 0 : 5 + } + + // MARK: - Actions + + @IBAction func touchUpInsideCopy(_ sender: Any) { delegate?.tapCopy(with: tableShare, sender: sender) } - @IBAction func touchUpMenu(_ sender: Any) { + @IBAction func touchUpInsideDetail(_ sender: Any) { delegate?.tapMenu(with: tableShare, sender: sender) } - @objc func openQuickStatus(_ sender: UITapGestureRecognizer) { + @IBAction func quickStatusClicked(_ sender: UIButton) { delegate?.quickStatus(with: tableShare, sender: sender) } } diff --git a/iOSClient/Share/NCShareLinkCell.xib b/iOSClient/Share/NCShareLinkCell.xib index d5810a5294..0f88db8ca6 100755 --- a/iOSClient/Share/NCShareLinkCell.xib +++ b/iOSClient/Share/NCShareLinkCell.xib @@ -1,149 +1,159 @@ - + - - - - + - - + + - - + + - - + + + + + + + - - - - + + + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - + + + + + + + + + + - + - - - - - - - - - - - - - + + + + diff --git a/iOSClient/Share/NCShareNavigationTitleSetting.swift b/iOSClient/Share/NCShareNavigationTitleSetting.swift index 927f21b97f..9804dea108 100644 --- a/iOSClient/Share/NCShareNavigationTitleSetting.swift +++ b/iOSClient/Share/NCShareNavigationTitleSetting.swift @@ -2,8 +2,6 @@ // SPDX-FileCopyrightText: 2025 Iva Horn // SPDX-License-Identifier: GPL-3.0-or-later -import NextcloudKit - /// /// View controllers conforming to this gain the convenience method ``setNavigationTitle()`` to set the navigation title in a convenient and consistent way. /// @@ -20,7 +18,7 @@ extension NCShareNavigationTitleSetting where Self: UIViewController { func setNavigationTitle() { title = NSLocalizedString("_share_", comment: "") + " – " - if share.shareType == NKShare.ShareType.publicLink.rawValue { + if share.shareType == NCShareCommon.shareTypeLink { title! += share.label.isEmpty ? NSLocalizedString("_share_link_", comment: "") : share.label } else { title! += share.shareWithDisplayname.isEmpty ? share.shareWith : share.shareWithDisplayname diff --git a/iOSClient/Share/NCShareNetworking.swift b/iOSClient/Share/NCShareNetworking.swift index b696bac0e8..7cd04ddc16 100644 --- a/iOSClient/Share/NCShareNetworking.swift +++ b/iOSClient/Share/NCShareNetworking.swift @@ -36,7 +36,6 @@ class NCShareNetworking: NSObject { self.view = view self.delegate = delegate self.session = session - super.init() } @@ -113,6 +112,37 @@ class NCShareNetworking: NSObject { } } } + + // MARK: - Create Share Link + func createShareLink(password: String?) { + NCActivityIndicator.shared.start(backgroundView: view) + let filenamePath = utilityFileSystem.getFileNamePath(metadata.fileName, serverUrl: metadata.serverUrl, session: session) + + NextcloudKit.shared.createShare(path: filenamePath, + shareType: NCShareCommon.shareTypeLink, + shareWith: "", + account: metadata.account) { [weak self] account, share, _, error in + guard let self = self else { return } + NCActivityIndicator.shared.stop() + + if error == .success, let share = share { + let home = self.utilityFileSystem.getHomeServer(session: self.session) + self.database.addShare(account: self.metadata.account, home: home, shares: [share]) + + if !self.metadata.contentType.contains("directory") { + AnalyticsHelper.shared.trackEventWithMetadata(eventName: .EVENT__SHARE_FILE, metadata: self.metadata) + } + + NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDidCreateShareLink) + // 🔄 ensure we sync DB + UI with server + self.readShare(showLoadingIndicator: false) + } else { + NCContentPresenter().showError(error: error) + } + + self.delegate?.shareCompleted() + } + } func createShare(_ shareable: Shareable, downloadLimit: DownloadLimitViewModel) { NCActivityIndicator.shared.start(backgroundView: view) @@ -144,20 +174,24 @@ class NCShareNetworking: NSObject { self.database.addShare(account: self.metadata.account, home: home, shares: [share]) if shareable.hasChanges(comparedTo: share) { - self.updateShare(shareable, downloadLimit: downloadLimit, changeDownloadLimit: true) + self.updateShare(shareable, downloadLimit: downloadLimit) // Download limit update should happen implicitly on share update. } else { if case let .limited(limit, _) = downloadLimit, capabilities.fileSharingDownloadLimit, - shareable.shareType == NKShare.ShareType.publicLink.rawValue, + shareable.shareType == NCShareCommon.shareTypeLink, shareable.itemType == NCShareCommon.itemTypeFile { self.setShareDownloadLimit(limit, token: share.token) } } + + if !self.metadata.contentType.contains("directory") { + AnalyticsHelper.shared.trackEventWithMetadata(eventName: .EVENT__SHARE_FILE, metadata: self.metadata) + } Task { await NCNetworking.shared.transferDispatcher.notifyAllDelegates { delegate in - delegate.transferReloadData(serverUrl: self.metadata.serverUrl, requestData: true, status: nil) + delegate.transferRequestData(serverUrl: self.metadata.serverUrl) } } } else { @@ -186,7 +220,7 @@ class NCShareNetworking: NSObject { Task { await NCNetworking.shared.transferDispatcher.notifyAllDelegates { delegate in - delegate.transferReloadData(serverUrl: self.metadata.serverUrl, requestData: true, status: nil) + delegate.transferRequestData(serverUrl: self.metadata.serverUrl) } } } else { @@ -195,7 +229,7 @@ class NCShareNetworking: NSObject { } } - func updateShare(_ shareable: Shareable, downloadLimit: DownloadLimitViewModel, changeDownloadLimit: Bool = false) { + func updateShare(_ shareable: Shareable, downloadLimit: DownloadLimitViewModel) { NCActivityIndicator.shared.start(backgroundView: view) NextcloudKit.shared.updateShare(idShare: shareable.idShare, password: shareable.password, expireDate: shareable.formattedDateString, permissions: shareable.permissions, note: shareable.note, label: shareable.label, hideDownload: shareable.hideDownload, attributes: shareable.attributes, account: metadata.account) { task in Task { @@ -215,9 +249,8 @@ class NCShareNetworking: NSObject { self.delegate?.readShareCompleted() if capabilities.fileSharingDownloadLimit, - shareable.shareType == NKShare.ShareType.publicLink.rawValue, - shareable.itemType == NCShareCommon.itemTypeFile, - changeDownloadLimit { + shareable.shareType == NCShareCommon.shareTypeLink, + shareable.itemType == NCShareCommon.itemTypeFile { if case let .limited(limit, _) = downloadLimit { self.setShareDownloadLimit(limit, token: share.token) } else { @@ -227,7 +260,7 @@ class NCShareNetworking: NSObject { Task { await NCNetworking.shared.transferDispatcher.notifyAllDelegates { delegate in - delegate.transferReloadData(serverUrl: self.metadata.serverUrl, requestData: true, status: nil) + delegate.transferRequestData(serverUrl: self.metadata.serverUrl) } } } else { diff --git a/iOSClient/Share/NCSharePaging.swift b/iOSClient/Share/NCSharePaging.swift index fe044d7dad..7ab1c37269 100644 --- a/iOSClient/Share/NCSharePaging.swift +++ b/iOSClient/Share/NCSharePaging.swift @@ -29,7 +29,7 @@ import MarqueeLabel import TagListView protocol NCSharePagingContent { - var textField: UIView? { get } + var textField: UITextField? { get } } class NCSharePaging: UIViewController { @@ -126,7 +126,7 @@ class NCSharePaging: UIViewController { super.viewWillDisappear(animated) Task { await NCNetworking.shared.transferDispatcher.notifyAllDelegates { delegate in - delegate.transferReloadData(serverUrl: metadata.serverUrl, requestData: false, status: nil) + delegate.transferReloadData(serverUrl: metadata.serverUrl, status: nil) } } } @@ -319,13 +319,10 @@ class NCShareHeaderView: UIView { @IBAction func touchUpInsideFavorite(_ sender: UIButton) { guard let metadata = NCManageDatabase.shared.getMetadataFromOcId(ocId) else { return } - NCNetworking.shared.setStatusWaitFavorite(metadata) { error in + NCNetworking.shared.favoriteMetadata(metadata) { error in if error == .success { guard let metadata = NCManageDatabase.shared.getMetadataFromOcId(metadata.ocId) else { return } - self.favorite.setImage(NCUtility().loadImage( - named: "star.fill", - colors: metadata.favorite ? [NCBrandColor.shared.yellowFavorite] : [NCBrandColor.shared.iconImageColor2], - size: 20), for: .normal) + self.favorite.setImage(NCUtility().loadImage(named: metadata.favorite ? "star" : "star.fill", colors: [NCBrandColor.shared.yellowFavorite], size: 20), for: .normal) } else { NCContentPresenter().showError(error: error) } diff --git a/iOSClient/Share/NCSharePermissions.swift b/iOSClient/Share/NCSharePermissions.swift index de12f94a59..26f3479412 100644 --- a/iOSClient/Share/NCSharePermissions.swift +++ b/iOSClient/Share/NCSharePermissions.swift @@ -3,15 +3,36 @@ // Nextcloud // // Created by Marino Faggiana on 05/06/24. -// SPDX-FileCopyrightText: Nextcloud GmbH -// SPDX-FileCopyrightText: 2024 Marino Faggiana -// SPDX-License-Identifier: GPL-3.0-or-later +// 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 -import NextcloudKit enum NCSharePermissions { + // Share permission + // permissions - (int) 1 = read; 2 = update; 4 = create; 8 = delete; 16 = Reshare; 31 = all + // + static let permissionReadShare: Int = 1 + static let permissionEditShare: Int = 2 + static let permissionCreateShare: Int = 4 + static let permissionDeleteShare: Int = 8 + static let permissionReshareShare: Int = 16 static let permissionMinFileShare: Int = 1 static let permissionMaxFileShare: Int = 19 @@ -25,30 +46,30 @@ enum NCSharePermissions { static let permissionDownloadShare: Int = 0 static func hasPermissionToRead(_ permission: Int) -> Bool { - return ((permission & NKShare.Permission.read.rawValue) > 0) + return ((permission & permissionReadShare) > 0) } static func hasPermissionToDelete(_ permission: Int) -> Bool { - return ((permission & NKShare.Permission.delete.rawValue) > 0) + return ((permission & permissionDeleteShare) > 0) } static func hasPermissionToCreate(_ permission: Int) -> Bool { - return ((permission & NKShare.Permission.create.rawValue) > 0) + return ((permission & permissionCreateShare) > 0) } static func hasPermissionToEdit(_ permission: Int) -> Bool { - return ((permission & NKShare.Permission.update.rawValue) > 0) + return ((permission & permissionEditShare) > 0) } static func hasPermissionToShare(_ permission: Int) -> Bool { - return ((permission & NKShare.Permission.share.rawValue) > 0) + return ((permission & permissionReshareShare) > 0) } static func isAnyPermissionToEdit(_ permission: Int) -> Bool { let canCreate = hasPermissionToCreate(permission) let canEdit = hasPermissionToEdit(permission) let canDelete = hasPermissionToDelete(permission) - return canCreate || canEdit || canDelete + return canCreate || canEdit //|| canDelete } /// "Can edit" means it has can read, create, edit, and delete. @@ -57,7 +78,7 @@ enum NCSharePermissions { let canCreate = isDirectory ? hasPermissionToCreate(permission) : true let canEdit = hasPermissionToEdit(permission) let canDelete = isDirectory ? hasPermissionToDelete(permission) : true - return canCreate && canEdit && canRead && canDelete + return canCreate && canEdit && canRead //&& canDelete } /// Read permission is always true for a share, hence why it's not here. @@ -65,20 +86,20 @@ enum NCSharePermissions { var permission = 0 if canRead { - permission = permission + NKShare.Permission.read.rawValue + permission = permission + permissionReadShare } if canCreate && isDirectory { - permission = permission + NKShare.Permission.create.rawValue + permission = permission + permissionCreateShare } if canEdit { - permission = permission + NKShare.Permission.update.rawValue - } - if canDelete && isDirectory { - permission = permission + NKShare.Permission.delete.rawValue + permission = permission + permissionEditShare } +// if canDelete && isDirectory { +// permission = permission + permissionDeleteShare +// } if canShare { - permission = permission + NKShare.Permission.share.rawValue + permission = permission + permissionReshareShare } return permission diff --git a/iOSClient/Share/NCShareUserCell.swift b/iOSClient/Share/NCShareUserCell.swift index c749a99b5f..7e31ba5d86 100644 --- a/iOSClient/Share/NCShareUserCell.swift +++ b/iOSClient/Share/NCShareUserCell.swift @@ -26,127 +26,125 @@ import NextcloudKit class NCShareUserCell: UITableViewCell, NCCellProtocol { - @IBOutlet weak var imageItem: UIImageView! + // MARK: - IBOutlets @IBOutlet weak var labelTitle: UILabel! @IBOutlet weak var buttonMenu: UIButton! - @IBOutlet weak var imageStatus: UIImageView! - @IBOutlet weak var status: UILabel! @IBOutlet weak var btnQuickStatus: UIButton! @IBOutlet weak var labelQuickStatus: UILabel! - @IBOutlet weak var imageDownArrow: UIImageView! - - private var index = IndexPath() - + @IBOutlet weak var imagePermissionType: UIImageView! + @IBOutlet weak var imageRightArrow: UIImageView! + @IBOutlet weak var imageExpiredDateSet: UIImageView! + @IBOutlet weak var imagePasswordSet: UIImageView! + @IBOutlet weak var imageAllowedPermission: UIImageView! + @IBOutlet weak var leadingContraintofImageRightArrow: NSLayoutConstraint! + + // MARK: - Properties + private var indexPathInternal = IndexPath() var tableShare: tableShare? - var isDirectory = false - let utility = NCUtility() + var isDirectory: Bool = false weak var delegate: NCShareUserCellDelegate? var indexPath: IndexPath { - get { return index } - set { index = newValue } - } - var fileAvatarImageView: UIImageView? { - return imageItem + get { indexPathInternal } + set { indexPathInternal = newValue } } + var fileUser: String? { get { return tableShare?.shareWith } set {} } - func setupCellUI(userId: String, session: NCSession.Session, metadata: tableMetadata) { - guard let tableShare = tableShare else { - return - } - self.accessibilityCustomActions = [UIAccessibilityCustomAction( - name: NSLocalizedString("_show_profile_", comment: ""), - target: self, - selector: #selector(tapAvatarImage(_:)))] - labelTitle.text = (tableShare.shareWithDisplayname.isEmpty ? tableShare.shareWith : tableShare.shareWithDisplayname) - - let type = getTypeString(tableShare) - if !type.isEmpty { - labelTitle.text?.append(" (\(type))") - } + // MARK: - Lifecycle + override func awakeFromNib() { + super.awakeFromNib() + setupCellUIAppearance() + } - labelTitle.lineBreakMode = .byTruncatingMiddle - labelTitle.textColor = NCBrandColor.shared.textColor - isUserInteractionEnabled = true - labelQuickStatus.isHidden = false - imageDownArrow.isHidden = false - buttonMenu.isHidden = false - buttonMenu.accessibilityLabel = NSLocalizedString("_more_", comment: "") - imageItem.image = NCShareCommon.getImageShareType(shareType: tableShare.shareType) - - let status = utility.getUserStatus(userIcon: tableShare.userIcon, userStatus: tableShare.userStatus, userMessage: tableShare.userMessage) - imageStatus.image = status.statusImage - self.status.text = status.statusMessage - - // If the initiator or the recipient is not the current user, show the list of sharees without any options to edit it. - if tableShare.uidOwner != userId && tableShare.uidFileOwner != userId { - isUserInteractionEnabled = false - labelQuickStatus.isHidden = true - imageDownArrow.isHidden = true - buttonMenu.isHidden = true + override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + super.traitCollectionDidChange(previousTraitCollection) + if previousTraitCollection?.userInterfaceStyle != traitCollection.userInterfaceStyle { + setupCellUIAppearance() } + } - btnQuickStatus.accessibilityHint = NSLocalizedString("_user_sharee_footer_", comment: "") - btnQuickStatus.setTitle("", for: .normal) - btnQuickStatus.contentHorizontalAlignment = .left + // MARK: - Configure + func configure(with share: tableShare?, at indexPath: IndexPath, isDirectory: Bool, userId: String) { + self.indexPath = indexPath + self.tableShare = share + self.isDirectory = isDirectory + setupCellUI(userId: userId) + } - if NCSharePermissions.canEdit(tableShare.permissions, isDirectory: isDirectory) { // Can edit - labelQuickStatus.text = NSLocalizedString("_share_editing_", comment: "") - } else if tableShare.permissions == NKShare.Permission.read.rawValue { // Read only - labelQuickStatus.text = NSLocalizedString("_share_read_only_", comment: "") - } else { // Custom permissions - labelQuickStatus.text = NSLocalizedString("_custom_permissions_", comment: "") - } + // MARK: - UI Setup + private func setupCellUIAppearance() { +// contentView.backgroundColor = NCBrandColor.shared.secondarySystemGroupedBackground + buttonMenu.contentMode = .scaleAspectFill +// buttonMenu.setImage(NCImageCache.images.buttonMore.image(color: NCBrandColor.shared.brand, size: 24), for: .normal) + buttonMenu.setImage(NCImageCache.shared.getImageButtonMore().image(color: NCBrandColor.shared.brand, size: 24), for: .normal) + labelQuickStatus.textColor = NCBrandColor.shared.shareBlueColor + labelTitle.textColor = NCBrandColor.shared.label + imageRightArrow.image = UIImage(named: "rightArrow")?.image(color: NCBrandColor.shared.shareBlueColor) + imageExpiredDateSet.image = UIImage(named: "calenderNew")?.image(color: NCBrandColor.shared.shareBlueColor) + imagePasswordSet.image = UIImage(named: "lockNew")?.image(color: NCBrandColor.shared.shareBlueColor) + + imagePermissionType.image = imagePermissionType.image?.image(color: NCBrandColor.shared.shareBlueColor) + updatePermissionUI() + } - let fileName = NCSession.shared.getFileName(urlBase: session.urlBase, user: tableShare.shareWith) - let results = NCManageDatabase.shared.getImageAvatarLoaded(fileName: fileName) + private func updatePermissionUI() { + guard let tableShare = tableShare else { return } - imageItem.contentMode = .scaleAspectFill + let permissions = NCPermissions() - if tableShare.shareType == NKShare.ShareType.team.rawValue { - imageItem.image = utility.loadImage(named: "custom.person.3.circle.fill", colors: [NCBrandColor.shared.iconImageColor2]) - } else if results.image == nil { - imageItem.image = utility.loadUserImage(for: tableShare.shareWith, displayName: tableShare.shareWithDisplayname, urlBase: metadata.urlBase) + if tableShare.permissions == permissions.permissionCreateShare { + labelQuickStatus.text = NSLocalizedString("_share_quick_permission_everyone_can_just_upload_", comment: "") + imagePermissionType.image = UIImage(named: "upload")?.image(color: NCBrandColor.shared.shareBlueColor) + } else if permissions.isAnyPermissionToEdit(tableShare.permissions) { + labelQuickStatus.text = NSLocalizedString("_share_quick_permission_everyone_can_edit_", comment: "") + imagePermissionType.image = UIImage(named: "editNew")?.image(color: NCBrandColor.shared.shareBlueColor) } else { - imageItem.image = results.image + labelQuickStatus.text = NSLocalizedString("_share_quick_permission_everyone_can_only_view_", comment: "") + imagePermissionType.image = UIImage(named: "showPasswordNew")?.image(color: NCBrandColor.shared.shareBlueColor) } - if !(results.tblAvatar?.loaded ?? false), - NCNetworking.shared.downloadAvatarQueue.operations.filter({ ($0 as? NCOperationDownloadAvatar)?.fileName == fileName }).isEmpty { - NCNetworking.shared.downloadAvatarQueue.addOperation(NCOperationDownloadAvatar(user: tableShare.shareWith, fileName: fileName, account: metadata.account, view: self)) - } + imagePasswordSet.isHidden = tableShare.password.isEmpty + imageExpiredDateSet.isHidden = (tableShare.expirationDate == nil) + + leadingContraintofImageRightArrow.constant = (imagePasswordSet.isHidden && imageExpiredDateSet.isHidden) ? 0 : 5 } - private func getTypeString(_ tableShare: tableShareV2) -> String { - switch tableShare.shareType { - case NKShare.ShareType.federatedCloud.rawValue: - return NSLocalizedString("_remote_", comment: "") - case NKShare.ShareType.federatedGroup.rawValue: - return NSLocalizedString("_remote_group_", comment: "") - case NKShare.ShareType.talkConversation.rawValue: - return NSLocalizedString("_conversation_", comment: "") - default: - return "" - } - } + private func setupCellUI(userId: String) { + guard let tableShare = tableShare else { return } - override func awakeFromNib() { - super.awakeFromNib() - let tapGesture = UITapGestureRecognizer(target: self, action: #selector(tapAvatarImage(_:))) - imageItem?.addGestureRecognizer(tapGesture) + let permissions = NCPermissions() + labelTitle.text = tableShare.shareWithDisplayname - labelQuickStatus.textColor = NCBrandColor.shared.customer - imageDownArrow.image = utility.loadImage(named: "arrowtriangle.down.circle", colors: [NCBrandColor.shared.customer]) - } + let isOwner = tableShare.uidOwner == userId || tableShare.uidFileOwner == userId + isUserInteractionEnabled = isOwner + buttonMenu.isHidden = !isOwner + buttonMenu.accessibilityLabel = NSLocalizedString("_more_", comment: "") - @objc func tapAvatarImage(_ sender: UITapGestureRecognizer) { - delegate?.showProfile(with: tableShare, sender: sender) + btnQuickStatus.setTitle("", for: .normal) + btnQuickStatus.isEnabled = true + btnQuickStatus.accessibilityHint = NSLocalizedString("_user_sharee_footer_", comment: "") + btnQuickStatus.contentHorizontalAlignment = .left + + setupCellUIAppearance() +// let permissionValue = tableShare.permissions +// +// if permissionValue == permissions.permissionCreateShare { +// labelQuickStatus.text = NSLocalizedString("_share_quick_permission_everyone_can_just_upload_", comment: "") +// imagePermissionType.image = UIImage(named: "upload")?.imageColor(NCBrandColor.shared.shareBlueColor) +// } else if permissions.isAnyPermissionToEdit(permissionValue) { +// labelQuickStatus.text = NSLocalizedString("_share_quick_permission_everyone_can_edit_", comment: "") +// imagePermissionType.image = UIImage(named: "editNew")?.imageColor(NCBrandColor.shared.shareBlueColor) +// } else { +// labelQuickStatus.text = NSLocalizedString("_share_quick_permission_everyone_can_only_view_", comment: "") +// imagePermissionType.image = UIImage(named: "showPasswordNew")?.imageColor(NCBrandColor.shared.shareBlueColor) +// } } + // MARK: - Actions @IBAction func touchUpInsideMenu(_ sender: Any) { delegate?.tapMenu(with: tableShare, sender: sender) } @@ -154,6 +152,10 @@ class NCShareUserCell: UITableViewCell, NCCellProtocol { @IBAction func quickStatusClicked(_ sender: Any) { delegate?.quickStatus(with: tableShare, sender: sender) } + + @objc func tapAvatarImage(_ sender: UITapGestureRecognizer) { + delegate?.showProfile(with: tableShare, sender: sender) + } } protocol NCShareUserCellDelegate: AnyObject { @@ -162,80 +164,49 @@ protocol NCShareUserCellDelegate: AnyObject { func quickStatus(with tableShare: tableShare?, sender: Any) } -// MARK: - NCSearchUserDropDownCell - class NCSearchUserDropDownCell: DropDownCell, NCCellProtocol { @IBOutlet weak var imageItem: UIImageView! @IBOutlet weak var imageStatus: UIImageView! - @IBOutlet weak var status: UILabel! + @IBOutlet weak var statusLabel: UILabel! @IBOutlet weak var imageShareeType: UIImageView! - @IBOutlet weak var centerTitle: NSLayoutConstraint! + @IBOutlet weak var centerTitleConstraint: NSLayoutConstraint! - private var user: String = "" - private var index = IndexPath() - private let utilityFileSystem = NCUtilityFileSystem() + private var userIdentifier: String = "" + private var currentIndexPath = IndexPath() + + // MARK: - NCCellProtocol var indexPath: IndexPath { - get { return index } - set { index = newValue } + get { currentIndexPath } + set { currentIndexPath = newValue } } + var fileAvatarImageView: UIImageView? { - return imageItem + imageItem } + var fileUser: String? { - get { return user } - set { user = newValue ?? "" } + get { userIdentifier } + set { userIdentifier = newValue ?? "" } } + // MARK: - Setup + func setupCell(sharee: NKSharee, session: NCSession.Session) { let utility = NCUtility() - imageItem.image = NCShareCommon.getImageShareType(shareType: sharee.shareType) - imageShareeType.image = NCShareCommon.getImageShareType(shareType: sharee.shareType) - let status = utility.getUserStatus(userIcon: sharee.userIcon, userStatus: sharee.userStatus, userMessage: sharee.userMessage) + imageShareeType.image = NCShareCommon.getImageShareType(shareType: sharee.shareType, isDropDown: true) + + let userStatus = utility.getUserStatus(userIcon: sharee.userIcon, + userStatus: sharee.userStatus, + userMessage: sharee.userMessage) - if let statusImage = status.statusImage { + if let statusImage = userStatus.statusImage { imageStatus.image = statusImage imageStatus.makeCircularBackground(withColor: .systemBackground) } - self.status.text = status.statusMessage - if self.status.text?.count ?? 0 > 0 { - centerTitle.constant = -5 - } else { - centerTitle.constant = 0 - } - - imageItem.image = utility.loadUserImage(for: sharee.shareWith, displayName: nil, urlBase: session.urlBase) - - let fileName = NCSession.shared.getFileName(urlBase: session.urlBase, user: sharee.shareWith) - let results = NCManageDatabase.shared.getImageAvatarLoaded(fileName: fileName) - - if results.image == nil { - let etag = NCManageDatabase.shared.getTableAvatar(fileName: fileName)?.etag - let fileNameLocalPath = utilityFileSystem.createServerUrl(serverUrl: utilityFileSystem.directoryUserData, fileName: fileName) - - NextcloudKit.shared.downloadAvatar( - user: sharee.shareWith, - fileNameLocalPath: fileNameLocalPath, - sizeImage: NCGlobal.shared.avatarSize, - avatarSizeRounded: NCGlobal.shared.avatarSizeRounded, - etagResource: etag, - account: session.account) { task in - Task { - let identifier = await NCNetworking.shared.networkingTasks.createIdentifier(account: session.account, - path: sharee.shareWith, - name: "downloadAvatar") - await NCNetworking.shared.networkingTasks.track(identifier: identifier, task: task) - } - } completion: { _, imageAvatar, _, etag, _, error in - if error == .success, let etag = etag, let imageAvatar = imageAvatar { - NCManageDatabase.shared.addAvatar(fileName: fileName, etag: etag) - self.imageItem.image = imageAvatar - } else if error.errorCode == NCGlobal.shared.errorNotModified, let imageAvatar = NCManageDatabase.shared.setAvatarLoaded(fileName: fileName) { - self.imageItem.image = imageAvatar - } - } - } + statusLabel.text = userStatus.statusMessage + centerTitleConstraint.constant = (statusLabel.text?.isEmpty == false) ? -5 : 0 } } diff --git a/iOSClient/Share/NCShareUserCell.xib b/iOSClient/Share/NCShareUserCell.xib index afd9bad812..2a7e57bf77 100755 --- a/iOSClient/Share/NCShareUserCell.xib +++ b/iOSClient/Share/NCShareUserCell.xib @@ -1,157 +1,134 @@ - + - - - + - - + + - - + + - - + - - + + + + + + + + - - + + - + - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + - + - - - - - - - - - - - - + + + diff --git a/iOSClient/Share/NoSharesFooterView.swift b/iOSClient/Share/NoSharesFooterView.swift new file mode 100644 index 0000000000..636b319a83 --- /dev/null +++ b/iOSClient/Share/NoSharesFooterView.swift @@ -0,0 +1,63 @@ +// +// NoSharesFooterView.swift +// Nextcloud +// +// Created by A106551118 on 12/08/25. +// Copyright © 2025 Marino Faggiana. All rights reserved. +// + + +import UIKit + +class NoSharesFooterView: UITableViewHeaderFooterView { + + static let reuseIdentifier = "NoSharesFooterView" + + private let titleLabel: UILabel = { + let label = UILabel() + label.font = .systemFont(ofSize: 17, weight: .semibold) + label.textColor = NCBrandColor.shared.textColor + label.text = NSLocalizedString("_share_shared_with_", comment: "") + label.translatesAutoresizingMaskIntoConstraints = false + return label + }() + + private let infoLabel: UILabel = { + let label = UILabel() + label.font = .systemFont(ofSize: 15, weight: .regular) + label.textColor = NCBrandColor.shared.textColor + label.text = NSLocalizedString("_share_no_shares_text_", comment: "") + label.numberOfLines = 0 + label.lineBreakMode = .byWordWrapping + label.translatesAutoresizingMaskIntoConstraints = false + return label + }() + + override init(reuseIdentifier: String?) { + super.init(reuseIdentifier: reuseIdentifier) + setupUI() + } + + required init?(coder: NSCoder) { + super.init(coder: coder) + setupUI() + } + + private func setupUI() { + contentView.backgroundColor = .clear + contentView.addSubview(titleLabel) + contentView.addSubview(infoLabel) + + NSLayoutConstraint.activate([ + titleLabel.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 20), + titleLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 15), + titleLabel.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -15), + titleLabel.heightAnchor.constraint(equalToConstant: 25), + + infoLabel.topAnchor.constraint(equalTo: titleLabel.bottomAnchor, constant: 15), + infoLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 15), + infoLabel.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -15), + infoLabel.bottomAnchor.constraint(equalTo: contentView.bottomAnchor) + ]) + } +} diff --git a/iOSClient/Share/ShareDownloadLimitNetwork.swift b/iOSClient/Share/ShareDownloadLimitNetwork.swift new file mode 100644 index 0000000000..06858464bf --- /dev/null +++ b/iOSClient/Share/ShareDownloadLimitNetwork.swift @@ -0,0 +1,156 @@ +// +// ShareDownloadLimitNetwork.swift +// Nextcloud +// +// Created by A118830248 on 11/11/21. +// Copyright © 2021 Marino Faggiana. All rights reserved. +// + +import Foundation +import SwiftyJSON +import NextcloudKit +import Alamofire + +class NMCCommunication: NSObject, XMLParserDelegate { + + public static let shared: NMCCommunication = { + let instance = NMCCommunication() + return instance + }() + + var message = "" + var foundCharacters = ""; + var downloadLimit = DownloadLimit() + private lazy var appDelegate = UIApplication.shared.delegate as? AppDelegate + var controller: NCMainTabBarController! + var session: NCSession.Session { + NCSession.shared.getSession(controller: controller) + } + + func getDownloadLimit(token: String, completion: @escaping (_ downloadLimit: DownloadLimit?, _ errorDescription: String) -> Void) { + let baseUrl = session.urlBase // NCBrandOptions.shared.loginBaseUrl + + func getDownloadLimit(token: String, completion: @escaping (_ downloadLimit: DownloadLimit?, _ errorDescription: String) -> Void) { + let baseUrl = session.urlBase // NCBrandOptions.shared.loginBaseUrl + let endPoint = "/ocs/v2.php/apps/files_downloadlimit/\(token)/limit" + let path = baseUrl+endPoint + do { + var urlRequest = try URLRequest(url: URL(string: path)!, method: .get) + urlRequest.addValue("true", forHTTPHeaderField: "OCS-APIREQUEST") + + let sessionConfiguration = URLSessionConfiguration.default + let urlSession = URLSession(configuration: sessionConfiguration) + + let task = urlSession.dataTask(with: urlRequest) { [self] (data, response, error) in + guard error == nil else { + completion(nil, error?.localizedDescription ?? "") + return + } + + if let httpResponse = response as? HTTPURLResponse { + let statusCode = httpResponse.statusCode + print("url: \(String(describing: httpResponse.url))\nStatus Code: \(statusCode)") + if httpResponse.statusCode == 200 { + let parser = XMLParser(data: data!) + parser.delegate = self + parser.parse() + completion(self.downloadLimit, self.message) + } else { + completion(nil, "Invalid Response code: \(statusCode)") + } + } else { + completion(nil, error?.localizedDescription ?? "Invalid Response") + } + } + task.resume() + } catch { + completion(nil, error.localizedDescription) + } + } + + func setDownloadLimit(deleteLimit: Bool, limit: String, token: String, completion: @escaping (_ success: Bool, _ errorDescription: String) -> Void) { + let baseUrl = session.urlBase //NCBrandOptions.shared.loginBaseUrl + let baseUrl = appDelegate?.urlBase ?? "" //NCBrandOptions.shared.loginBaseUrl + let endPoint = "/ocs/v2.php/apps/files_downloadlimit/\(token)/limit" + let path = baseUrl+endPoint + do { + + let method = deleteLimit ? HTTPMethod.delete : .put + var urlRequest = try URLRequest(url: URL(string: path)!, method: method) + + urlRequest.addValue("true", forHTTPHeaderField: "OCS-APIREQUEST") + urlRequest.addValue(authorizationToken(), forHTTPHeaderField: "Authorization") + urlRequest.addValue("application/json", forHTTPHeaderField: "Content-Type") + + let parameters = ["token": token, "limit": limit] + + let encoder = JSONEncoder() + let jsonData = try encoder.encode(parameters) + urlRequest.httpBody = jsonData + + let sessionConfiguration = URLSessionConfiguration.default + let urlSession = URLSession(configuration: sessionConfiguration) + + let task = urlSession.dataTask(with: urlRequest) { (data, response, error) in + guard error == nil else { + completion(false, error?.localizedDescription ?? "") + return + } + + if let httpResponse = response as? HTTPURLResponse { + let statusCode = httpResponse.statusCode + print("url: \(String(describing: httpResponse.url))\nStatus Code: \(statusCode)") + if httpResponse.statusCode == 200 { + completion(true, error?.localizedDescription ?? "") + } else { + completion(false, "Invalid Response code: \(statusCode)") + } + } else { + completion(false, error?.localizedDescription ?? "Invalid Response") + } + } + task.resume() + } catch { + completion(false, error.localizedDescription) + } + } + + public func authorizationToken() -> String { + let accountDetails = NCManageDatabase.shared.getAllTableAccount().first + let accountDetails = NCManageDatabase.shared.getAllAccount().first + let password = NCKeychain().getPassword(account: accountDetails?.account ?? "") + let password = NCKeychain().getPassword(account: accountDetails?.account ?? "") + let username = accountDetails?.user ?? "" + let credential = Data("\(username):\(password)".utf8).base64EncodedString() + return ("Basic \(credential)") + } + + + // MARK:- XML Parser Delegate + public func parser(_ parser: XMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String : String] = [:]) { + + } + public func parser(_ parser: XMLParser, foundCharacters string: String) { + self.foundCharacters += string; + } + + public func parser(_ parser: XMLParser, didEndElement elementName: String, namespaceURI: String?, qualifiedName qName: String?) { + if elementName == "limit" { + let limit = self.foundCharacters.replacingOccurrences(of: "\n", with: "") + self.downloadLimit.limit = Int(limit.trimmingCharacters(in: .whitespaces)) + } + if elementName == "count" { + let count = self.foundCharacters.replacingOccurrences(of: "\n", with: "") + self.downloadLimit.count = Int(count.trimmingCharacters(in: .whitespaces)) + } + if elementName == "message"{ + self.message = self.foundCharacters + } + self.foundCharacters = "" + } +} + +//struct DownloadLimit: Codable { +// var limit: Int? +// var count: Int? +//} diff --git a/iOSClient/Share/TransientShare.swift b/iOSClient/Share/TransientShare.swift index 5276698339..666b91b66c 100644 --- a/iOSClient/Share/TransientShare.swift +++ b/iOSClient/Share/TransientShare.swift @@ -31,7 +31,7 @@ class TransientShare: Shareable { let capabilities = NCNetworking.shared.capabilities[metadata.account] ?? NKCapabilities.Capabilities() if metadata.e2eEncrypted, capabilities.e2EEApiVersion == NCGlobal.shared.e2eeVersionV12 { - self.permissions = NKShare.Permission.create.rawValue + self.permissions = NCSharePermissions.permissionCreateShare } else { self.permissions = capabilities.fileSharingDefaultPermission & metadata.sharePermissionsCollaborationServices } @@ -51,6 +51,6 @@ class TransientShare: Shareable { } static func shareLink(metadata: tableMetadata, password: String?) -> TransientShare { - TransientShare(shareType: NKShare.ShareType.publicLink.rawValue, metadata: metadata, password: password) + TransientShare(shareType: NCShareCommon.shareTypeLink, metadata: metadata, password: password) } } diff --git a/iOSClient/Utility/NCUtility.swift b/iOSClient/Utility/NCUtility.swift index f025eacb9d..eb35e7d03e 100644 --- a/iOSClient/Utility/NCUtility.swift +++ b/iOSClient/Utility/NCUtility.swift @@ -1,8 +1,26 @@ -// SPDX-FileCopyrightText: Nextcloud GmbH -// SPDX-FileCopyrightText: 2018 Marino Faggiana -// SPDX-License-Identifier: GPL-3.0-or-later +// +// NCUtility.swift +// Nextcloud +// +// Created by Marino Faggiana on 25/06/18. +// Copyright © 2018 Marino Faggiana. All rights reserved. +// +// Author Marino Faggiana +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// -import Foundation import UIKit import NextcloudKit import PDFKit @@ -101,27 +119,18 @@ final class NCUtility: NSObject, Sendable { return String(intFileId) } - func splitOcId(_ ocId: String) -> (fileId: String?, instanceId: String?) { - let parts = ocId.components(separatedBy: "oc") - guard parts.count == 2 else { - return (nil, nil) - } - return (parts[0], "oc" + parts[1]) - } - - /// Pads a numeric fileId with leading zeros to reach 8 characters. - func paddedFileId(_ fileId: String) -> String { - if fileId.count >= 8 { return fileId } - let zeros = String(repeating: "0", count: 8 - fileId.count) - return zeros + fileId - } - - func getLivePhotoOcId(metadata: tableMetadata) -> String? { - if let instanceId = splitOcId(metadata.ocId).instanceId { - return paddedFileId(metadata.livePhotoFile) + instanceId - } - return nil - } +// func getVersionApp(withBuild: Bool = true) -> String { +// if let dictionary = Bundle.main.infoDictionary { +// if let version = dictionary["CFBundleShortVersionString"], let build = dictionary["CFBundleVersion"] { +// if withBuild { +// return "\(version).\(build)" +// } else { +// return "\(version)" +// } +// } +// } +// return "" +// } func getVersionBuild() -> String { if let dictionary = Bundle.main.infoDictionary, @@ -223,7 +232,6 @@ final class NCUtility: NSObject, Sendable { return isEqual } - #if !EXTENSION_FILE_PROVIDER_EXTENSION func getLocation(latitude: Double, longitude: Double, completion: @escaping (String?) -> Void) { let geocoder = CLGeocoder() let llocation = CLLocation(latitude: latitude, longitude: longitude) @@ -244,7 +252,6 @@ final class NCUtility: NSObject, Sendable { } } } - #endif // https://stackoverflow.com/questions/5887248/ios-app-maximum-memory-budget/19692719#19692719 // https://stackoverflow.com/questions/27556807/swift-pointer-problems-with-mach-task-basic-info/27559770#27559770 @@ -284,12 +291,78 @@ final class NCUtility: NSObject, Sendable { } return height } + + // E-mail validations + // 1. Basic Email Validator (ASCII only) + func isValidEmail(_ email: String) -> Bool { + let emailRegex = "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}$" + let predicate = NSPredicate(format: "SELF MATCHES[c] %@", emailRegex) + return predicate.evaluate(with: email) + } - func formatBadgeCount(_ count: Int) -> String { - if count <= 9999 { - return "\(count)" + // 2. Manually Convert Unicode Domain to Punycode with German Char Support + func convertToPunycode(email: String) -> String? { + guard let atIndex = email.firstIndex(of: "@") else { return nil } + + let localPart = String(email[.. String? { + // Mapping of common German characters to their corresponding Punycode equivalents + var punycodeDomain = domain.lowercased() + + let germanCharToPunycode: [String: String] = [ + "ü": "xn--u-1fa", // ü → xn--u-1fa + "ä": "xn--a-1fa", // ä → xn--a-1fa + "ö": "xn--o-1fa", // ö → xn--o-1fa + "ß": "xn--ss-1fa", // ß → xn--ss-1fa + "é": "xn--e-1fa", // é → xn--e-1fa + "è": "xn--e-1f", // è → xn--e-1f + "à": "xn--a-1f", // à → xn--a-1f + ] + + // Replace each German character with the corresponding Punycode equivalent + for (char, punycode) in germanCharToPunycode { + punycodeDomain = punycodeDomain.replacingOccurrences(of: char, with: punycode) + } + + // If no change occurred, return the domain as it is (i.e., no Punycode needed) + return punycodeDomain + } + + // 4. IDN Email Validator (handles Unicode domain by converting to Punycode) + func isValidIDNEmail(_ email: String) -> Bool { + // Convert domain part to Punycode and validate using basic email regex + guard let punycodeEmail = convertToPunycode(email: email) else { + return false + } + + return isValidEmail(punycodeEmail) + } + + // 5. Unified Email Validation - Check for both basic and IDN emails + func validateEmail(_ email: String) -> Bool { + if isValidEmail(email) { + print("Valid ASCII email: \(email)") + return true + } else if isValidIDNEmail(email) { + print("Valid IDN email: \(email)") + return true } else { - return count.formatted(.number.notation(.compactName).locale(Locale(identifier: "en_US"))) + print("Invalid email: \(email)") + return false } } }