diff --git a/Nextcloud.xcodeproj/project.pbxproj b/Nextcloud.xcodeproj/project.pbxproj index 05654d1b07..a65e7b1317 100644 --- a/Nextcloud.xcodeproj/project.pbxproj +++ b/Nextcloud.xcodeproj/project.pbxproj @@ -92,6 +92,16 @@ 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 */; }; + B568C2B72DA7B5060072FCB4 /* SettingsTestCases.swift in Sources */ = {isa = PBXBuildFile; fileRef = B568C2B62DA7B5060072FCB4 /* SettingsTestCases.swift */; }; + B568C2B92DA7CCC10072FCB4 /* CCAdvanced.m in Sources */ = {isa = PBXBuildFile; fileRef = B568C2B82DA7CCC10072FCB4 /* CCAdvanced.m */; }; + B568C2BE2DA7CCDB0072FCB4 /* MagentaCloudVersionView.xib in Resources */ = {isa = PBXBuildFile; fileRef = B568C2BD2DA7CCDB0072FCB4 /* MagentaCloudVersionView.xib */; }; + B568C2BF2DA7CCDB0072FCB4 /* MagentaCloudVersionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B568C2BC2DA7CCDB0072FCB4 /* MagentaCloudVersionView.swift */; }; + B568C2C02DA7CCDB0072FCB4 /* ImprintViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B568C2BB2DA7CCDB0072FCB4 /* ImprintViewController.swift */; }; + B568C2C12DA7CCDB0072FCB4 /* HelpViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B568C2BA2DA7CCDB0072FCB4 /* HelpViewController.swift */; }; + B568C2C42DA7CCEA0072FCB4 /* OpenSourceSoftwareViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B568C2C32DA7CCEA0072FCB4 /* OpenSourceSoftwareViewController.swift */; }; + B568C2C52DA7CCEA0072FCB4 /* NCSettings.m in Sources */ = {isa = PBXBuildFile; fileRef = B568C2C22DA7CCEA0072FCB4 /* NCSettings.m */; }; + C04E2F232A17BB4D001BAD85 /* FilesIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C04E2F222A17BB4D001BAD85 /* FilesIntegrationTests.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 */; }; @@ -1330,6 +1340,17 @@ 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 = ""; }; + B568C2B62DA7B5060072FCB4 /* SettingsTestCases.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsTestCases.swift; sourceTree = ""; }; + B568C2B82DA7CCC10072FCB4 /* CCAdvanced.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CCAdvanced.m; sourceTree = ""; }; + B568C2BA2DA7CCDB0072FCB4 /* HelpViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HelpViewController.swift; sourceTree = ""; }; + B568C2BB2DA7CCDB0072FCB4 /* ImprintViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImprintViewController.swift; sourceTree = ""; }; + B568C2BC2DA7CCDB0072FCB4 /* MagentaCloudVersionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MagentaCloudVersionView.swift; sourceTree = ""; }; + B568C2BD2DA7CCDB0072FCB4 /* MagentaCloudVersionView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MagentaCloudVersionView.xib; sourceTree = ""; }; + B568C2C22DA7CCEA0072FCB4 /* NCSettings.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NCSettings.m; sourceTree = ""; }; + B568C2C32DA7CCEA0072FCB4 /* OpenSourceSoftwareViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenSourceSoftwareViewController.swift; sourceTree = ""; }; + B568C2C62DA7CD930072FCB4 /* CCAdvanced.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CCAdvanced.h; sourceTree = ""; }; + B568C2C72DA7CD930072FCB4 /* NCSettings.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NCSettings.h; 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 = ""; }; @@ -2118,6 +2139,8 @@ isa = PBXGroup; children = ( AA52EB452D42AC5A0089C348 /* Placeholder.swift */, + B568C2B62DA7B5060072FCB4 /* SettingsTestCases.swift */, + AF8ED1FB2757821000B8DBC4 /* NextcloudUnitTests.swift */, ); path = NextcloudUnitTests; sourceTree = ""; @@ -2592,6 +2615,15 @@ F76882042C0DD1E7001CF441 /* Settings */ = { isa = PBXGroup; children = ( + B568C2C62DA7CD930072FCB4 /* CCAdvanced.h */, + B568C2C72DA7CD930072FCB4 /* NCSettings.h */, + B568C2C22DA7CCEA0072FCB4 /* NCSettings.m */, + B568C2C32DA7CCEA0072FCB4 /* OpenSourceSoftwareViewController.swift */, + B568C2BA2DA7CCDB0072FCB4 /* HelpViewController.swift */, + B568C2BB2DA7CCDB0072FCB4 /* ImprintViewController.swift */, + B568C2BC2DA7CCDB0072FCB4 /* MagentaCloudVersionView.swift */, + B568C2BD2DA7CCDB0072FCB4 /* MagentaCloudVersionView.xib */, + B568C2B82DA7CCC10072FCB4 /* CCAdvanced.m */, F768820B2C0DD1E7001CF441 /* Settings */, F76882162C0DD1E7001CF441 /* AutoUpload */, F389C9F32CEE381E00049762 /* SelectAlbum */, @@ -3990,6 +4022,7 @@ F7A48415297028FC00BD1B49 /* Nextcloud Hub.png in Resources */, F74C0437253F1CDC009762AB /* NCShares.storyboard in Resources */, F7F4F10C27ECDBDB008676F9 /* Inconsolata-Regular.ttf in Resources */, + B568C2BE2DA7CCDB0072FCB4 /* MagentaCloudVersionView.xib in Resources */, F7B8B83025681C3400967775 /* GoogleService-Info.plist in Resources */, F7381EE5218218C9000B1560 /* NCOffline.storyboard in Resources */, F768822D2C0DD1E7001CF441 /* Acknowledgements.rtf in Resources */, @@ -4567,6 +4600,9 @@ F768822C2C0DD1E7001CF441 /* NCKeychain.swift in Sources */, F7BFFD282C8846020029A201 /* NCHud.swift in Sources */, F71CD6CA2930D7B1006C95C1 /* NCApplicationHandle.swift in Sources */, + B568C2BF2DA7CCDB0072FCB4 /* MagentaCloudVersionView.swift in Sources */, + B568C2C02DA7CCDB0072FCB4 /* ImprintViewController.swift in Sources */, + B568C2C12DA7CCDB0072FCB4 /* HelpViewController.swift in Sources */, F3754A7D2CF87D600009312E /* SetupPasscodeView.swift in Sources */, F73EF7D72B0226080087E6E9 /* NCManageDatabase+Tip.swift in Sources */, F3374A842D64AC31002A38F9 /* AssistantLabelStyle.swift in Sources */, @@ -4598,6 +4634,7 @@ F72CD63A25C19EBF00F46F9A /* NCAutoUpload.swift in Sources */, F768822F2C0DD1E7001CF441 /* NCAutoUploadModel.swift in Sources */, AF93471D27E2361E002537EE /* NCShareAdvancePermissionFooter.swift in Sources */, + B568C2B92DA7CCC10072FCB4 /* CCAdvanced.m in Sources */, AF1A9B6427D0CA1E00F17A9E /* UIAlertController+Extension.swift in Sources */, F73B422C2476764F00A30FD3 /* NCNotification.swift in Sources */, F7FA80012C0F4F3B0072FC60 /* NCUploadAssetsView.swift in Sources */, @@ -4743,6 +4780,8 @@ AFCE353527E4ED5900FEA6C2 /* DateFormatter+Extension.swift in Sources */, F718C24E254D507B00C5C256 /* NCViewerMediaDetailView.swift in Sources */, F33EE6F22BF4C9B200CA1A51 /* PKCS12.swift in Sources */, + B568C2C42DA7CCEA0072FCB4 /* OpenSourceSoftwareViewController.swift in Sources */, + B568C2C52DA7CCEA0072FCB4 /* NCSettings.m in Sources */, F7145610296433C80038D028 /* NCDocumentCamera.swift in Sources */, F76882312C0DD1E7001CF441 /* NCFileNameView.swift in Sources */, F7381EE1218218C9000B1560 /* NCOffline.swift in Sources */, diff --git a/Tests/NextcloudUnitTests/SettingsTestCases.swift b/Tests/NextcloudUnitTests/SettingsTestCases.swift new file mode 100644 index 0000000000..4b16db93f3 --- /dev/null +++ b/Tests/NextcloudUnitTests/SettingsTestCases.swift @@ -0,0 +1,341 @@ +// +// SettingsTestCases.swift +// NextcloudTests +// +// Created by A200073704 on 12/05/23. +// Copyright © 2023 Marino Faggiana. All rights reserved. +// + +@testable import Nextcloud +import XCTest +import NextcloudKit +import XLForm + + class SettingsTestCases: XCTestCase { + + + override func setUpWithError() throws { + // Put setup code here. This method is called before the invocation of each test method in the class. + } + + override func tearDownWithError() throws { + // Put teardown code here. This method is called after the invocation of each test method in the class. + } + + // MARK: - Settings + + func testAutoUploadSectionIsPresent() { + + let form : XLFormDescriptor = XLFormDescriptor() as XLFormDescriptor + form.rowNavigationOptions = XLFormRowNavigationOptions.stopDisableRow + + var section : XLFormSectionDescriptor + var row : XLFormRowDescriptor + + let image = UIImage(named: "autoUpload") + row = XLFormRowDescriptor(tag: "autoUpload", rowType: XLFormRowDescriptorTypeButton, title: NSLocalizedString("_settings_autoupload_", comment: "")); + section = XLFormSectionDescriptor.formSection(withTitle: "") + section.addFormRow(row) + + XCTAssertNotNil(image) + // Verify that section was found + XCTAssertNotNil(row, "Expected 'Auto Upload' section to exist in form.") + + + } + + func testLockSectionIsPresent() { + let form : XLFormDescriptor = XLFormDescriptor() as XLFormDescriptor + form.rowNavigationOptions = XLFormRowNavigationOptions.stopDisableRow + + var section : XLFormSectionDescriptor + var row : XLFormRowDescriptor + + let image = UIImage(named: "lock_open") + row = XLFormRowDescriptor(tag: "bloccopasscode", rowType: XLFormRowDescriptorTypeButton, title: NSLocalizedString("_lock_not_active_", comment: "")); + section = XLFormSectionDescriptor.formSection(withTitle: "") + section.addFormRow(row) + + XCTAssertNotNil(image) + + XCTAssertNotNil(row, "Expected 'Lock Active / Off ' section exists") + + + } + + func testEnableTouchIDSectionIsPresent() { + + let form : XLFormDescriptor = XLFormDescriptor() as XLFormDescriptor + form.rowNavigationOptions = XLFormRowNavigationOptions.stopDisableRow + + var section : XLFormSectionDescriptor + var row : XLFormRowDescriptor + + row = XLFormRowDescriptor(tag: "enableTouchDaceID", rowType: XLFormRowDescriptorTypeBooleanSwitch, title: NSLocalizedString("_enable_touch_face_id_", comment: "")); + section = XLFormSectionDescriptor.formSection(withTitle: "") + section.addFormRow(row) + + XCTAssertNotNil(row, "Expected 'Enable/Disable touch ID' is present") + + } + + func testEndToEndEncryptionSectionIsPresent() { + let form : XLFormDescriptor = XLFormDescriptor() as XLFormDescriptor + form.rowNavigationOptions = XLFormRowNavigationOptions.stopDisableRow + + var section : XLFormSectionDescriptor + var row : XLFormRowDescriptor + + row = XLFormRowDescriptor(tag: "e2eEncryption", rowType: XLFormRowDescriptorTypeButton, title: NSLocalizedString("_e2e_settings_", comment: "")); + section = XLFormSectionDescriptor.formSection(withTitle: "") + section.addFormRow(row) + + XCTAssertNotNil(row, "Expected 'End to End encryption' section exists") + + + } + + func testAdvancedSectionIsPresent() { + let form : XLFormDescriptor = XLFormDescriptor() as XLFormDescriptor + form.rowNavigationOptions = XLFormRowNavigationOptions.stopDisableRow + + var section : XLFormSectionDescriptor + var row : XLFormRowDescriptor + + row = XLFormRowDescriptor(tag: "advanced", rowType: XLFormRowDescriptorTypeButton, title: NSLocalizedString("_e2e_settings_", comment: "")); + section = XLFormSectionDescriptor.formSection(withTitle: "") + section.addFormRow(row) + + XCTAssertNotNil(row, " Expected 'Advanced' Section exists") + } + + + + func testNavigatesToOpenSourceViewController() { + let form : XLFormDescriptor = XLFormDescriptor() as XLFormDescriptor + form.rowNavigationOptions = XLFormRowNavigationOptions.stopDisableRow + let section = XLFormSectionDescriptor.formSection() + form.addFormSection(section) + + let row = XLFormRowDescriptor(tag: "buttonLeftAligned", rowType: XLFormRowDescriptorTypeButton, title: NSLocalizedString("_used_opensource_software_", comment: "")) + section.addFormRow(row) + + // Create a view controller with the form and add it to a navigation controller + let viewController = OpenSourceSoftwareViewController() + let window = UIApplication.shared.windows.first { $0.isKeyWindow } + let navigationController = UINavigationController(rootViewController: viewController) + window?.rootViewController = navigationController + + viewController.loadViewIfNeeded() + let indexPath = IndexPath(row: 0, section: 0) + print("Calling didSelectRowAt for row at \(indexPath)") + + // Verify that the OpenSourceSoftwareViewController class is opened + XCTAssertTrue(navigationController.topViewController is OpenSourceSoftwareViewController) + + } + + func testHelpSectionIsPresent() { + + let form : XLFormDescriptor = XLFormDescriptor() as XLFormDescriptor + form.rowNavigationOptions = XLFormRowNavigationOptions.stopDisableRow + let section = XLFormSectionDescriptor.formSection() + form.addFormSection(section) + + let row = XLFormRowDescriptor(tag: "buttonLeftAligned", rowType: XLFormRowDescriptorTypeButton, title: NSLocalizedString("_help_", comment: "")) + section.addFormRow(row) + + // Create a view controller with the form and add it to a navigation controller + let viewController = HelpViewController() + let window = UIApplication.shared.windows.first { $0.isKeyWindow } + let navigationController = UINavigationController(rootViewController: viewController) + window?.rootViewController = navigationController + + viewController.loadViewIfNeeded() + let indexPath = IndexPath(row: 0, section: 0) + print("Calling didSelectRowAt for row at \(indexPath)") + + // Verify that the HelpViewController class is opened + XCTAssertTrue(navigationController.topViewController is HelpViewController) + + XCTAssertNotNil(row, "Expected 'Help' Section is present") + + } + + func testImprintSectionIsPresent() { + + let form : XLFormDescriptor = XLFormDescriptor() as XLFormDescriptor + form.rowNavigationOptions = XLFormRowNavigationOptions.stopDisableRow + let section = XLFormSectionDescriptor.formSection() + form.addFormSection(section) + + let row = XLFormRowDescriptor(tag: "buttonLeftAligned", rowType: XLFormRowDescriptorTypeButton, title: NSLocalizedString("_imprint_", comment: "")) + section.addFormRow(row) + + // Create a view controller with the form and add it to a navigation controller + let viewController = ImprintViewController() + let window = UIApplication.shared.windows.first { $0.isKeyWindow } + let navigationController = UINavigationController(rootViewController: viewController) + window?.rootViewController = navigationController + + viewController.loadViewIfNeeded() + let indexPath = IndexPath(row: 0, section: 0) + print("Calling didSelectRowAt for row at \(indexPath)") + + // Verify that the ImprintViewController class is opened + XCTAssertTrue(navigationController.topViewController is ImprintViewController) + + XCTAssertNotNil(row, "Expected 'Imprint' Section is present") + } + + func testMagentaCloudVersionSectionIsPresent() { + + let form : XLFormDescriptor = XLFormDescriptor() as XLFormDescriptor + form.rowNavigationOptions = XLFormRowNavigationOptions.stopDisableRow + let section = XLFormSectionDescriptor.formSection() + form.addFormSection(section) + + let row = XLFormRowDescriptor(tag: "disablefilesapp", rowType: "kNMCCustomCellType", title: NSLocalizedString("_magentacloud_version_", comment: "")) + section.addFormRow(row) + + XCTAssertNotNil(row, "Expected 'MagentaCloud Version' is present") + + + } + + // MARK: - Advanced + + func testShowHiddenFilesSectionIsPresent() { + + let form : XLFormDescriptor = XLFormDescriptor() as XLFormDescriptor + form.rowNavigationOptions = XLFormRowNavigationOptions.stopDisableRow + let section = XLFormSectionDescriptor.formSection() + form.addFormSection(section) + + let row = XLFormRowDescriptor(tag: "showHiddenFiles", rowType: XLFormRowDescriptorTypeBooleanSwitch, title: NSLocalizedString("_show_hidden_files_", comment: "")) + section.addFormRow(row) + + XCTAssertNotNil(row, "Expected 'Show hidden files' section is present") + + } + + func testMostCompatibleSectionIsPresent() { + + let form : XLFormDescriptor = XLFormDescriptor() as XLFormDescriptor + form.rowNavigationOptions = XLFormRowNavigationOptions.stopDisableRow + let section = XLFormSectionDescriptor.formSection() + form.addFormSection(section) + + let row = XLFormRowDescriptor(tag: "formatCompatibility", rowType: XLFormRowDescriptorTypeBooleanSwitch, title: NSLocalizedString("_format_compatibility_", comment: "")) + row.value = "1" + section.addFormRow(row) + + XCTAssertNotNil(row, "Expected 'Most Compatible' is present") + } + + func testLivePhotoSectionIsPresent() { + + let form : XLFormDescriptor = XLFormDescriptor() as XLFormDescriptor + form.rowNavigationOptions = XLFormRowNavigationOptions.stopDisableRow + let section = XLFormSectionDescriptor.formSection() + form.addFormSection(section) + + let row = XLFormRowDescriptor(tag: "livePhoto", rowType: XLFormRowDescriptorTypeBooleanSwitch, title: NSLocalizedString("_upload_mov_livephoto_", comment: "")) + if CCUtility.getLivePhoto() { + row.value = "1" + } else { + row.value = "0" + } + section.addFormRow(row) + + XCTAssertNotNil(row, "Expected 'Live Photo' section is present") + + } + + func testImageResolutionSectionIsPresent() { + + let form : XLFormDescriptor = XLFormDescriptor() as XLFormDescriptor + form.rowNavigationOptions = XLFormRowNavigationOptions.stopDisableRow + let section = XLFormSectionDescriptor.formSection() + form.addFormSection(section) + + let row = XLFormRowDescriptor(tag: "automaticDownloadImage", rowType: XLFormRowDescriptorTypeBooleanSwitch, title: NSLocalizedString("_automatic_Download_Image_", comment: "")) + section.addFormRow(row) + + XCTAssertNotNil(row, "Expected 'Use images in full resolution' section is present") + } + + func testAppIntegrationSectionIsPresent() { + + let form : XLFormDescriptor = XLFormDescriptor() as XLFormDescriptor + form.rowNavigationOptions = XLFormRowNavigationOptions.stopDisableRow + let section = XLFormSectionDescriptor.formSection() + form.addFormSection(section) + + let row = XLFormRowDescriptor(tag: "disablefilesapp", rowType: XLFormRowDescriptorTypeBooleanSwitch, title: NSLocalizedString("_disable_files_app_", comment: "")) + section.addFormRow(row) + + XCTAssertNotNil(row, "Expected 'Disable Files App Integration' section is present") + } + + func testDeleteFilesSectionIsPresent() { + + let form : XLFormDescriptor = XLFormDescriptor() as XLFormDescriptor + form.rowNavigationOptions = XLFormRowNavigationOptions.stopDisableRow + let section = XLFormSectionDescriptor.formSection() + form.addFormSection(section) + + let row = XLFormRowDescriptor(tag: "deleteoldfiles", rowType: XLFormRowDescriptorTypeSelectorPush, title: NSLocalizedString("_delete_old_files_", comment: "")) + section.addFormRow(row) + + XCTAssertNotNil(row, "Expected 'Delete all files older than..' section is present") + } + + func testClearCacheSectionIsPresent() { + + let form : XLFormDescriptor = XLFormDescriptor() as XLFormDescriptor + form.rowNavigationOptions = XLFormRowNavigationOptions.stopDisableRow + let section = XLFormSectionDescriptor.formSection() + form.addFormSection(section) + + let image = UIImage(named: "trash") + + let row = XLFormRowDescriptor(tag: "azzeracache", rowType:XLFormRowDescriptorTypeButton, title: NSLocalizedString("_clear_cache_", comment: "")) + section.addFormRow(row) + + XCTAssertNotNil(image) + + XCTAssertNotNil(row, "Expected 'Clear Cache' section is present") + + } + + func testLogoutButtonIsPresent() { + + let form : XLFormDescriptor = XLFormDescriptor() as XLFormDescriptor + form.rowNavigationOptions = XLFormRowNavigationOptions.stopDisableRow + let section = XLFormSectionDescriptor.formSection() + form.addFormSection(section) + + let image = UIImage(named: "xmark") + + let row = XLFormRowDescriptor(tag: "esci", rowType: XLFormRowDescriptorTypeButton, title: NSLocalizedString("_exit_", comment: "")) + section.addFormRow(row) + + XCTAssertNotNil(image) + + XCTAssertNotNil(row, "Expected 'Logout' Button is present") + + + } + + + + + + + + + + + +} diff --git a/iOSClient/Settings/CCAdvanced.h b/iOSClient/Settings/CCAdvanced.h new file mode 100755 index 0000000000..7f9845888f --- /dev/null +++ b/iOSClient/Settings/CCAdvanced.h @@ -0,0 +1,29 @@ +// +// CCAdvanced.h +// Nextcloud +// +// Created by Marino Faggiana on 12/04/17. +// Copyright (c) 2017 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 +#import + +@interface CCAdvanced : XLFormViewController + +@end diff --git a/iOSClient/Settings/CCAdvanced.m b/iOSClient/Settings/CCAdvanced.m new file mode 100755 index 0000000000..7d6fa31ef2 --- /dev/null +++ b/iOSClient/Settings/CCAdvanced.m @@ -0,0 +1,477 @@ +// +// CCManageHelp.m +// Nextcloud +// +// Created by Marino Faggiana on 06/11/15. +// Copyright (c) 2015 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 "CCAdvanced.h" +#import "CCUtility.h" +#import "NCBridgeSwift.h" +#import "AdjustHelper.h" + +@interface CCAdvanced () +{ + AppDelegate *appDelegate; + XLFormSectionDescriptor *sectionSize; + TealiumHelper *tealium; + AdjustHelper *adjust; +} +@end + +@implementation CCAdvanced + +- (void)initializeForm +{ + XLFormDescriptor *form = [XLFormDescriptor formDescriptor]; + XLFormSectionDescriptor *section; + XLFormRowDescriptor *row; + + // Section HIDDEN FILES ------------------------------------------------- + + section = [XLFormSectionDescriptor formSection]; + [form addFormSection:section]; + + row = [XLFormRowDescriptor formRowDescriptorWithTag:@"showHiddenFiles" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_show_hidden_files_", nil)]; + row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor; + if ([[[NCKeychain alloc] init] showHiddenFiles]) row.value = @"1"; + else row.value = @"0"; + [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"]; + [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"]; + row.cellConfig[@"switchControl.onTintColor"] = NCBrandColor.shared.brand; + [section addFormRow:row]; + + // Format Compatibility + Live Photo + Delete asset + + section = [XLFormSectionDescriptor formSection]; + [form addFormSection:section]; + section.footerTitle = [NSString stringWithFormat:@"%@\n%@\n%@", NSLocalizedString(@"_format_compatibility_footer_", nil), NSLocalizedString(@"_upload_mov_livephoto_footer_", nil), NSLocalizedString(@"_remove_photo_CameraRoll_desc_", nil)]; + + row = [XLFormRowDescriptor formRowDescriptorWithTag:@"formatCompatibility" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_format_compatibility_", nil)]; + row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor; + if ([[[NCKeychain alloc] init] formatCompatibility]) row.value = @"1"; + else row.value = @"0"; + [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"]; + [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"]; + row.cellConfig[@"switchControl.onTintColor"] = NCBrandColor.shared.brand; + [section addFormRow:row]; + + row = [XLFormRowDescriptor formRowDescriptorWithTag:@"livePhoto" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_upload_mov_livephoto_", nil)]; + row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor; + if ([[[NCKeychain alloc] init] livePhoto]) row.value = @"1"; + else row.value = @"0"; + [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"]; + [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"]; + row.cellConfig[@"switchControl.onTintColor"] = NCBrandColor.shared.brand; + [section addFormRow:row]; + + row = [XLFormRowDescriptor formRowDescriptorWithTag:@"removePhotoCameraRoll" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_remove_photo_CameraRoll_", nil)]; + row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor; + if ([[[NCKeychain alloc] init] removePhotoCameraRoll]) row.value = @"1"; + else row.value = @0; + [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"]; + [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"]; + [section addFormRow:row]; + + // Section : Files App -------------------------------------------------------------- + + if (![NCBrandOptions shared].disable_openin_file) { + + section = [XLFormSectionDescriptor formSection]; + [form addFormSection:section]; + section.footerTitle = NSLocalizedString(@"_disable_files_app_footer_", nil); + + // Disable Files App + row = [XLFormRowDescriptor formRowDescriptorWithTag:@"disablefilesapp" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_disable_files_app_", nil)]; + row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor; + if ([[NCKeychain alloc] init].disableFilesApp) row.value = @"1"; + else row.value = @"0"; + [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"]; + [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"]; + row.cellConfig[@"switchControl.onTintColor"] = NCBrandColor.shared.brand; + [section addFormRow:row]; + } + + // Section : Privacy -------------------------------------------------------------- + + if (!NCBrandOptions.shared.disable_crash_service) { + + section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_privacy_", nil)]; + [form addFormSection:section]; + section.footerTitle = NSLocalizedString(@"_privacy_footer_", nil); + + row = [XLFormRowDescriptor formRowDescriptorWithTag:@"crashservice" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_crashservice_title_", nil)]; + row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor; + [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"]; + [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"]; + [row.cellConfig setObject:[[UIImage imageNamed:@"crashservice"] imageWithColor:UIColor.systemGrayColor size:25] forKey:@"imageView.image"]; + if ([[[NCKeychain alloc] init] disableCrashservice]) row.value = @"1"; + else row.value = @"0"; + [section addFormRow:row]; + } + +#ifdef DEBUG + // Section DIAGNOSTICS ------------------------------------------------- + + section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_diagnostics_", nil)]; + [form addFormSection:section]; + + if ([[NSFileManager defaultManager] fileExistsAtPath:@""] && NCBrandOptions.shared.disable_log == false) { + + row = [XLFormRowDescriptor formRowDescriptorWithTag:@"log" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_view_log_", nil)]; + row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor; + [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"]; + [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"]; + [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"]; + [row.cellConfig setObject:[[UIImage imageNamed:@"log"] imageWithColor:UIColor.systemGrayColor size:25] forKey:@"imageView.image"]; + row.action.formBlock = ^(XLFormRowDescriptor * sender) { + + [self deselectFormRow:sender]; + NCViewerQuickLook *viewerQuickLook = [[NCViewerQuickLook alloc] initWith:[NSURL fileURLWithPath:@""] fileNameSource:@"" isEditingEnabled:false metadata:nil]; + [self presentViewController:viewerQuickLook animated:YES completion:nil]; + }; + [section addFormRow:row]; + + row = [XLFormRowDescriptor formRowDescriptorWithTag:@"clearlog" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_clear_log_", nil)]; + row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor; + [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"]; + [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"]; + [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"]; + [row.cellConfig setObject:[[UIImage imageNamed:@"clear"] imageWithColor:UIColor.systemGrayColor size:25] forKey:@"imageView.image"]; + row.action.formBlock = ^(XLFormRowDescriptor * sender) { + + [self deselectFormRow:sender]; + + NSInteger logLevel = [[NCKeychain alloc] init].logLevel; + BOOL isSimulatorOrTestFlight = [[[NCUtility alloc] init] isSimulatorOrTestFlight]; + NSString *versionNextcloudiOS = [NSString stringWithFormat:[NCBrandOptions shared].textCopyrightNextcloudiOS, [[[NCUtility alloc] init] getVersionAppWithBuild:true]]; + }; + [section addFormRow:row]; + + row = [XLFormRowDescriptor formRowDescriptorWithTag:@"logLevel" rowType:XLFormRowDescriptorTypeSlider title:NSLocalizedString(@"_level_log_", nil)]; + row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor; + [row.cellConfig setObject:@(NSTextAlignmentCenter) forKey:@"textLabel.textAlignment"]; + [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"]; + [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"]; + NSInteger logLevel = [[NCKeychain alloc] init].logLevel; + row.value = @(logLevel); + [row.cellConfigAtConfigure setObject:@(2) forKey:@"slider.maximumValue"]; + [row.cellConfigAtConfigure setObject:@(0) forKey:@"slider.minimumValue"]; + [row.cellConfigAtConfigure setObject:@(2) forKey:@"steps"]; + [section addFormRow:row]; + } + + row = [XLFormRowDescriptor formRowDescriptorWithTag:@"capabilities" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_capabilities_", nil)]; + row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor; + [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"]; + [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"]; + [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"]; + [row.cellConfig setObject:[[UIImage imageNamed:@"capabilities"] imageWithColor:UIColor.systemGrayColor size:25] forKey:@"imageView.image"]; + row.action.formBlock = ^(XLFormRowDescriptor * sender) { + + [self deselectFormRow:sender]; + + UIViewController *vc = [[NCHostingCapabilitiesView alloc] makeShipDetailsUI]; + [self.navigationController pushViewController:vc animated:YES]; + }; + [section addFormRow:row]; +#endif + + // Section : Delete files / Clear cache -------------------------------------------------------------- + + sectionSize = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_delete_files_desc_", nil)]; + [form addFormSection:sectionSize]; + sectionSize.footerTitle = NSLocalizedString(@"_clear_cache_footer_", nil); + + row = [XLFormRowDescriptor formRowDescriptorWithTag:@"deleteoldfiles" rowType:XLFormRowDescriptorTypeSelectorPush title:NSLocalizedString(@"_delete_old_files_", nil)]; + + switch ([[NCKeychain alloc] init].cleanUpDay) { + case 0: + row.value = [XLFormOptionsObject formOptionsObjectWithValue:@(0) displayText:NSLocalizedString(@"_never_", nil)]; + break; + case 365: + row.value = [XLFormOptionsObject formOptionsObjectWithValue:@(365) displayText:NSLocalizedString(@"_1_year_", nil)]; + break; + case 180: + row.value = [XLFormOptionsObject formOptionsObjectWithValue:@(180) displayText:NSLocalizedString(@"_6_months_", nil)]; + break; + case 90: + row.value = [XLFormOptionsObject formOptionsObjectWithValue:@(90) displayText:NSLocalizedString(@"_3_months_", nil)]; + break; + case 30: + row.value = [XLFormOptionsObject formOptionsObjectWithValue:@(30) displayText:NSLocalizedString(@"_1_month_", nil)]; + break; + case 7: + row.value = [XLFormOptionsObject formOptionsObjectWithValue:@(7) displayText:NSLocalizedString(@"_1_week_", nil)]; + break; + case 1: + row.value = [XLFormOptionsObject formOptionsObjectWithValue:@(1) displayText:NSLocalizedString(@"_1_day_", nil)]; + break; + default: + row.value = [XLFormOptionsObject formOptionsObjectWithValue:@(0) displayText:NSLocalizedString(@"_never_", nil)]; + break; + } + + [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"]; + [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"]; + row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor; + row.cellConfigForSelector[@"tintColor"] = NCBrandColor.shared.customer; + row.selectorTitle = NSLocalizedString(@"_delete_old_files_", nil); + row.selectorOptions = @[[XLFormOptionsObject formOptionsObjectWithValue:@(0) displayText:NSLocalizedString(@"_never_", nil)], + [XLFormOptionsObject formOptionsObjectWithValue:@(365) displayText:NSLocalizedString(@"_1_year_", nil)], + [XLFormOptionsObject formOptionsObjectWithValue:@(180) displayText:NSLocalizedString(@"_6_months_", nil)], + [XLFormOptionsObject formOptionsObjectWithValue:@(90) displayText:NSLocalizedString(@"_3_months_", nil)], + [XLFormOptionsObject formOptionsObjectWithValue:@(30) displayText:NSLocalizedString(@"_1_month_", nil)], + [XLFormOptionsObject formOptionsObjectWithValue:@(7) displayText:NSLocalizedString(@"_1_week_", nil)], + ]; + [sectionSize addFormRow:row]; + + // Clear cache + row = [XLFormRowDescriptor formRowDescriptorWithTag:@"azzeracache" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_clear_cache_", nil)]; + row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor; + [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"]; + [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"]; + [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"]; + [row.cellConfig setObject:[[UIImage imageNamed:@"trash"] imageWithColor:UIColor.systemGrayColor size:25] forKey:@"imageView.image"]; + row.action.formSelector = @selector(clearCacheRequest:); + [sectionSize addFormRow:row]; + + // Section EXIT -------------------------------------------------------- + + section = [XLFormSectionDescriptor formSection]; + [form addFormSection:section]; + section.footerTitle = NSLocalizedString(@"_exit_footer_", nil); + + // Exit + row = [XLFormRowDescriptor formRowDescriptorWithTag:@"esci" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_exit_", nil)]; + row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor; + [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"]; + [row.cellConfig setObject:[UIColor redColor] forKey:@"textLabel.textColor"]; + [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"]; + [row.cellConfig setObject:[[UIImage imageNamed:@"xmark"] imageWithColor:[UIColor redColor] size:25] forKey:@"imageView.image"]; + row.action.formSelector = @selector(exitNextcloud:); + [section addFormRow:row]; + + self.tableView.showsVerticalScrollIndicator = NO; + self.form = form; +} + +// MARK: - View Life Cycle + +- (void)viewDidLoad +{ + [super viewDidLoad]; + + self.title = NSLocalizedString(@"_advanced_", nil); + appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; + self.view.backgroundColor = UIColor.systemGroupedBackgroundColor; + + adjust = [[AdjustHelper alloc] init]; + self.tableView.backgroundColor = UIColor.systemGroupedBackgroundColor; + + [self initializeForm]; + [self calculateSize]; +} + +- (void)viewWillAppear:(BOOL)animated +{ + [super viewWillAppear:animated]; + + appDelegate.activeViewController = self; +} + +#pragma mark - + +- (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue +{ + [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue]; + + if ([rowDescriptor.tag isEqualToString:@"showHiddenFiles"]) { + + [[NCKeychain alloc] init].showHiddenFiles = [[rowDescriptor.value valueData] boolValue]; + } + + if ([rowDescriptor.tag isEqualToString:@"formatCompatibility"]) { + + [[NCKeychain alloc] init].formatCompatibility = [[rowDescriptor.value valueData] boolValue]; + } + + if ([rowDescriptor.tag isEqualToString:@"livePhoto"]) { + + [[NCKeychain alloc] init].livePhoto = [[rowDescriptor.value valueData] boolValue]; + } + + if ([rowDescriptor.tag isEqualToString:@"removePhotoCameraRoll"]) { + + [[NCKeychain alloc] init].removePhotoCameraRoll = [[rowDescriptor.value valueData] boolValue]; + } + + if ([rowDescriptor.tag isEqualToString:@"disablefilesapp"]) { + + [[NCKeychain alloc] init].disableFilesApp = [[rowDescriptor.value valueData] boolValue]; + } + + if ([rowDescriptor.tag isEqualToString:@"crashservice"]) { + + [[NCKeychain alloc] init].disableCrashservice = [[rowDescriptor.value valueData] boolValue]; + + UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_crashservice_title_", nil) message:NSLocalizedString(@"_crashservice_alert_", nil) preferredStyle:UIAlertControllerStyleAlert]; + UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { + exit(0); + }]; + + [alertController addAction:okAction]; + [self presentViewController:alertController animated:YES completion:nil]; + } + + if ([rowDescriptor.tag isEqualToString:@"logLevel"]) { + + NSInteger levelLog = [[rowDescriptor.value valueData] intValue]; + [[NCKeychain alloc] init].logLevel = levelLog; + } + + if ([rowDescriptor.tag isEqualToString:@"deleteoldfiles"]) { + + NSInteger days = [[rowDescriptor.value valueData] intValue]; + [[NCKeychain alloc] init].cleanUpDay = days; + } +} + +#pragma mark - Clear Cache + +- (void)clearCache:(NSString *)account +{ + [[NCNetworking shared] cancelAllTask]; + + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) { + + NCUtilityFileSystem *ufs = [[NCUtilityFileSystem alloc] init]; + + [[NSURLCache sharedURLCache] setMemoryCapacity:0]; + [[NSURLCache sharedURLCache] setDiskCapacity:0]; + + [[NCManageDatabase shared] clearDatabaseWithAccount:account removeAccount:false]; + + [ufs removeGroupDirectoryProviderStorage]; + [ufs removeGroupLibraryDirectory]; + + [ufs removeDocumentsDirectory]; + [ufs removeTemporaryDirectory]; + + [ufs createDirectoryStandard]; + + [[NCAutoUpload shared] alignPhotoLibraryWithController:self account:appDelegate.account]; + + [[NCImageCache shared] createMediaCacheWithAccount:appDelegate.account withCacheSize:true]; + + [[NCActivityIndicator shared] stop]; + tealium = [[TealiumHelper alloc] init]; + [tealium trackEventWithTitle:@"magentacloud-app.settings.reset" data:nil]; + [adjust trackEvent:ResetsApp]; + [self calculateSize]; + }); +} + +- (void)clearCacheRequest:(XLFormRowDescriptor *)sender +{ + [self deselectFormRow:sender]; + + UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:NSLocalizedString(@"_want_delete_cache_", nil) preferredStyle:UIAlertControllerStyleActionSheet]; + + [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_yes_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { + [[NCActivityIndicator shared] startActivityWithBackgroundView:nil style: UIActivityIndicatorViewStyleLarge blurEffect:true]; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) { + [self clearCache:appDelegate.account]; + }); + }]]; + + [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { + }]]; + + alertController.popoverPresentationController.sourceView = self.view; + NSIndexPath *indexPath = [self.form indexPathOfFormRow:sender]; + CGRect cellRect = [self.tableView rectForRowAtIndexPath:indexPath]; + alertController.popoverPresentationController.sourceRect = CGRectOffset(cellRect, -self.tableView.contentOffset.x, -self.tableView.contentOffset.y); + + [self presentViewController:alertController animated:YES completion:nil]; +} + + +- (void)clearAllCacheRequest:(XLFormRowDescriptor *)sender +{ + [self deselectFormRow:sender]; + + [[NCActivityIndicator shared] startActivityWithBackgroundView:nil style: UIActivityIndicatorViewStyleLarge blurEffect:true]; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) { + [self clearCache:nil]; + }); +} + +- (void)calculateSize +{ + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + NCUtilityFileSystem *ufs = [[NCUtilityFileSystem alloc] init]; + NSString *directory = [ufs directoryProviderStorage]; + int64_t totalSize = [ufs getDirectorySizeWithDirectory:directory]; + sectionSize.footerTitle = [NSString stringWithFormat:@"%@. (%@ %@)", NSLocalizedString(@"_clear_cache_footer_", nil), NSLocalizedString(@"_used_space_", nil), [ufs transformedSize:totalSize]]; + + dispatch_async(dispatch_get_main_queue(), ^{ + [self.tableView reloadData]; + }); + }); +} + +#pragma mark - Exit Nextcloud + +- (void)exitNextcloud:(XLFormRowDescriptor *)sender +{ + [self deselectFormRow:sender]; + + UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:NSLocalizedString(@"_want_exit_", nil) preferredStyle:UIAlertControllerStyleActionSheet]; + + [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) { + tealium = [[TealiumHelper alloc] init]; + [tealium trackEventWithTitle:@"magentacloud-app.settings.logout" data:nil]; + [adjust trackEvent:Logout]; + [appDelegate resetApplication]; + }]]; + + [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { + }]]; + + alertController.popoverPresentationController.sourceView = self.view; + NSIndexPath *indexPath = [self.form indexPathOfFormRow:sender]; + CGRect cellRect = [self.tableView rectForRowAtIndexPath:indexPath]; + alertController.popoverPresentationController.sourceRect = CGRectOffset(cellRect, -self.tableView.contentOffset.x, -self.tableView.contentOffset.y); + + [self presentViewController:alertController animated:YES completion:nil]; +} + +#pragma mark - + +- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { + + if (indexPath.section == 4 && indexPath.row == 2) { + return 80; + } else { + return NCGlobal.shared.heightCellSettings; + } +} + +@end diff --git a/iOSClient/Settings/HelpViewController.swift b/iOSClient/Settings/HelpViewController.swift new file mode 100644 index 0000000000..eb91d7b4cf --- /dev/null +++ b/iOSClient/Settings/HelpViewController.swift @@ -0,0 +1,57 @@ +// +// HelpViewController.swift +// Nextcloud +// +// Created by A200073704 on 11/05/23. +// Copyright © 2023 Marino Faggiana. All rights reserved. +// + +import UIKit +import WebKit + +class HelpViewController: UIViewController, WKNavigationDelegate, WKUIDelegate { + + override func viewDidLoad() { + super.viewDidLoad() + // Do any additional setup after loading the view, typically from a nib. + + self.title = NSLocalizedString("_help_", comment: "") + let myWebView:WKWebView = WKWebView(frame: CGRect(x:0, y:0, width: UIScreen.main.bounds.width, height:UIScreen.main.bounds.height)) + myWebView.uiDelegate = self + myWebView.navigationDelegate = self + myWebView.autoresizingMask = [.flexibleWidth, .flexibleHeight] + self.view.addSubview(myWebView) + + + //1. Load web site into my web view + let myURL = URL(string: "https://cloud.telekom-dienste.de/hilfe") + let myURLRequest:URLRequest = URLRequest(url: myURL!) + NCActivityIndicator.shared.start() + myWebView.load(myURLRequest) + + } + + override func didReceiveMemoryWarning() { + super.didReceiveMemoryWarning() + // Dispose of any resources that can be recreated. + } + + func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { + NCActivityIndicator.shared.stop() + } + + func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) { + if navigationAction.navigationType == .linkActivated { + if let url = navigationAction.request.url, + UIApplication.shared.canOpenURL(url) { + UIApplication.shared.open(url) + decisionHandler(.cancel) + } else { + decisionHandler(.allow) + } + } else { + decisionHandler(.allow) + } + } +} + diff --git a/iOSClient/Settings/ImprintViewController.swift b/iOSClient/Settings/ImprintViewController.swift new file mode 100644 index 0000000000..819a86599d --- /dev/null +++ b/iOSClient/Settings/ImprintViewController.swift @@ -0,0 +1,70 @@ +// +// ImprintViewController.swift +// Nextcloud +// +// Created by A200073704 on 11/05/23. +// Copyright © 2023 Marino Faggiana. All rights reserved. +// + +import UIKit +import WebKit + +class ImprintViewController: UIViewController, WKNavigationDelegate, WKUIDelegate { + + override func viewDidLoad() { + super.viewDidLoad() + // Do any additional setup after loading the view, typically from a nib. + self.title = NSLocalizedString("_imprint_", comment: "") + + let myWebView:WKWebView = WKWebView(frame: CGRect(x:0, y:0, width: UIScreen.main.bounds.width, height:UIScreen.main.bounds.height)) + myWebView.uiDelegate = self + myWebView.navigationDelegate = self + myWebView.autoresizingMask = [.flexibleWidth, .flexibleHeight] + self.view.addSubview(myWebView) + + + //1. Load web site into my web view + let myURL = URL(string: "https://www.telekom.de/impressum") + let myURLRequest:URLRequest = URLRequest(url: myURL!) + NCActivityIndicator.shared.start() + myWebView.load(myURLRequest) + + } + + override func didReceiveMemoryWarning() { + super.didReceiveMemoryWarning() + // Dispose of any resources that can be recreated. + } + + func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { + NCActivityIndicator.shared.stop() + } + + override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { + super.viewWillTransition(to: size, with: coordinator) + + if UIDevice.current.orientation.isLandscape { + print("Landscape") + } + if UIDevice.current.orientation.isFlat { + print("Flat") + } else { + print("Portrait") + } + } + + func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) { + if navigationAction.navigationType == .linkActivated { + if let url = navigationAction.request.url, + UIApplication.shared.canOpenURL(url) { + UIApplication.shared.open(url) + decisionHandler(.cancel) + } else { + decisionHandler(.allow) + } + } else { + decisionHandler(.allow) + } + } +} + diff --git a/iOSClient/Settings/MagentaCloudVersionView.swift b/iOSClient/Settings/MagentaCloudVersionView.swift new file mode 100644 index 0000000000..16de2ec088 --- /dev/null +++ b/iOSClient/Settings/MagentaCloudVersionView.swift @@ -0,0 +1,31 @@ +// +// MagentaCloudVersionView.swift +// Nextcloud +// +// Created by A200073704 on 11/05/23. +// Copyright © 2023 Marino Faggiana. All rights reserved. +// + +import Foundation + + +class MagentaCloudVersionView: XLFormBaseCell{ + + + @IBOutlet weak var cellLabel: UILabel! + @IBOutlet weak var versionLabel: UILabel! + + override func awakeFromNib() { + super.awakeFromNib() + // Initialization code + self.selectionStyle = .none + } + + override func configure() { + super.configure() + } + + override func update() { + super.update() + } +} diff --git a/iOSClient/Settings/MagentaCloudVersionView.xib b/iOSClient/Settings/MagentaCloudVersionView.xib new file mode 100644 index 0000000000..9c9d06adfe --- /dev/null +++ b/iOSClient/Settings/MagentaCloudVersionView.xib @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/iOSClient/Settings/NCSettings.h b/iOSClient/Settings/NCSettings.h new file mode 100644 index 0000000000..e06a29f1ac --- /dev/null +++ b/iOSClient/Settings/NCSettings.h @@ -0,0 +1,33 @@ +// +// NCSettings.h +// Nextcloud +// +// Created by Marino Faggiana on 24/11/14. +// Copyright (c) 2014 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 +#import +#import +#import "CCUtility.h" + +@interface NCSettings : XLFormViewController + +- (void)reloadForm; + +@end diff --git a/iOSClient/Settings/NCSettings.m b/iOSClient/Settings/NCSettings.m new file mode 100644 index 0000000000..19ba0e6e63 --- /dev/null +++ b/iOSClient/Settings/NCSettings.m @@ -0,0 +1,435 @@ +// +// NCSettings.m +// Nextcloud +// +// Created by Marino Faggiana on 24/11/14. +// Copyright (c) 2014 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 "NCSettings.h" +#import "CCAdvanced.h" +#import "CCManageAccount.h" +#import "CCManageAutoUpload.h" +#import "NCBridgeSwift.h" +#import +//#import + +#define alertViewEsci 1 +#define alertViewAzzeraCache 2 + +@interface NCSettings () +{ + AppDelegate *appDelegate; + TOPasscodeViewController *passcodeViewController; + TOPasscodeSettingsViewController *passcodeSettingsViewController; + + NSString *versionServer; + NSString *themingName; + NSString *themingSlogan; +} +@end + +@implementation NCSettings + +- (void)initializeForm +{ + XLFormDescriptor *form = [XLFormDescriptor formDescriptor]; + XLFormSectionDescriptor *section; + XLFormRowDescriptor *row; + + form.rowNavigationOptions = XLFormRowNavigationOptionNone; + + // Section AUTO UPLOAD OF CAMERA IMAGES ---------------------------- + + section = [XLFormSectionDescriptor formSection]; + [form addFormSection:section]; + + row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUpload" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_settings_autoupload_", nil)]; + row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor; + [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"]; + [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"]; + [row.cellConfig setObject:[[UIImage imageNamed:@"autoUpload"] imageWithColor:NCBrandColor.shared.iconColor size:25] forKey:@"imageView.image"]; + row.action.viewControllerClass = [CCManageAutoUpload class]; + [section addFormRow:row]; + + // Section : SECURITY -------------------------------------------------------------- + + section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_security_", nil)]; + [form addFormSection:section]; + + // Lock active YES/NO + row = [XLFormRowDescriptor formRowDescriptorWithTag:@"bloccopasscode" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_lock_not_active_", nil)]; + row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor; + [row.cellConfig setObject:[[UIImage imageNamed:@"lock_open"] imageWithColor:NCBrandColor.shared.iconColor size:25] forKey:@"imageView.image"]; + [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"]; + [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"]; + [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"]; + //[row.cellConfig setObject:@(UITableViewCellAccessoryDisclosureIndicator) forKey:@"accessoryType"]; + row.action.formSelector = @selector(passcode:); + [section addFormRow:row]; + // Enable Touch ID + row = [XLFormRowDescriptor formRowDescriptorWithTag:@"enableTouchDaceID" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_enable_touch_face_id_", nil)]; + row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor; + [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"]; + [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"]; + row.cellConfig[@"switchControl.onTintColor"] = NCBrandColor.shared.brand; + if([[NCKeychain alloc] init].passcode){ + row.disabled = @NO; + }else{ + row.disabled = @YES; + } + [section addFormRow:row]; + + // Section : E2EEncryption -------------------------------------------------------------- + + BOOL isE2EEEnabled = [[NCGlobal shared] capabilityE2EEEnabled]; + NSString *versionE2EE = [[NCGlobal shared] capabilityE2EEApiVersion]; + + if (isE2EEEnabled == YES && [NCGlobal.shared.e2eeVersions containsObject:versionE2EE]) { + + // EndToEnd Encryption + NSString *title = [NSString stringWithFormat:@"%@",NSLocalizedString(@"_e2e_settings_", nil)]; + row = [XLFormRowDescriptor formRowDescriptorWithTag:@"e2eEncryption" rowType:XLFormRowDescriptorTypeButton title:title]; + row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor; + [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"]; + [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"]; + [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"]; + [row.cellConfig setObject:[[UIImage imageNamed:@"lock"] imageWithColor:NCBrandColor.shared.iconColor size:25] forKey:@"imageView.image"]; + row.action.formSelector = @selector(manageE2EE:); + [section addFormRow:row]; + } + + // Section Advanced ------------------------------------------------- + + section = [XLFormSectionDescriptor formSection]; + [form addFormSection:section]; + + // Advanced + row = [XLFormRowDescriptor formRowDescriptorWithTag:@"advanced" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_advanced_", nil)]; + row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor; + [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"]; + [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"]; + [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"]; + [row.cellConfig setObject:[[UIImage imageNamed:@"gear"] imageWithColor:NCBrandColor.shared.iconColor size:25] forKey:@"imageView.image"]; + row.action.viewControllerClass = [CCAdvanced class]; + [section addFormRow:row]; + + // Section : DATA PROTECTION ------------------------------------------------ + + section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_data_protection_", nil)]; + [form addFormSection:section]; + + // Privacy Settings + PrivacySettingsViewController *privacySettingsViewController = [[PrivacySettingsViewController alloc] init]; + privacySettingsViewController.isShowSettingsButton = true; + [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"showSettingsButton"]; + [[NSUserDefaults standardUserDefaults] synchronize]; + row = [XLFormRowDescriptor formRowDescriptorWithTag:@"privacySettings" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_privacy_settings_", nil)]; + row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor; + [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"]; + [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"]; + [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"]; + row.action.viewControllerClass = [privacySettingsViewController class]; + [section addFormRow:row]; + + // Privacy Policy + row = [XLFormRowDescriptor formRowDescriptorWithTag:@"advanced" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_privacy_policy_", nil)]; + row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor; + [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"]; + [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"]; + [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"]; + row.action.viewControllerClass = [PrivacyPolicyViewController class]; + [section addFormRow:row]; + + // Used OpenSource Software + row = [XLFormRowDescriptor formRowDescriptorWithTag:@"buttonLeftAligned" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_used_opensource_software_", nil)]; + row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor; + [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"]; + [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"]; + [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"]; + row.action.viewControllerClass = [OpenSourceSoftwareViewController class]; + [section addFormRow:row]; + + + // Section : SERVICE ------------------------------------------------ + + section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_service_", nil)]; + [form addFormSection:section]; + + // HELP + row = [XLFormRowDescriptor formRowDescriptorWithTag:@"buttonLeftAligned" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_help_", nil)]; + row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor; + [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"]; + [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"]; + [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"]; + row.action.viewControllerClass = [HelpViewController class]; + [section addFormRow:row]; + + // Imprint + row = [XLFormRowDescriptor formRowDescriptorWithTag:@"buttonLeftAligned" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_imprint_", nil)]; + row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor; + [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"]; + [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"]; + [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"]; + row.action.viewControllerClass = [ImprintViewController class]; + [section addFormRow:row]; + + // Section : INFO ------------------------------------------------ + + section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_info_", nil)]; + [form addFormSection:section]; + + //MagentaCloud Version + + //custom cell + + [[XLFormViewController cellClassesForRowDescriptorTypes] setObject:[MagentaCloudVersionView class] forKey:@"kNMCCustomCellType"]; + + row = [XLFormRowDescriptor formRowDescriptorWithTag:@"disablefilesapp" rowType:@"kNMCCustomCellType" title:NSLocalizedString(@"_magentacloud_version_", nil)]; + NSString *appVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleInfoDictionaryVersion"]; + row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor; + row.cellConfigAtConfigure[@"cellLabel.text"] = NSLocalizedString(@"_magentacloud_version_", nil); + [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"cellLabel.font"]; + [row.cellConfig setObject:UIColor.labelColor forKey:@"cellLabel.textColor"]; + row.cellConfigAtConfigure[@"versionLabel.text"] = appVersion; + [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"versionLabel.font"]; + [row.cellConfig setObject:UIColor.systemGrayColor forKey:@"versionLabel.textColor"]; + [section addFormRow:row]; + + self.tableView.showsVerticalScrollIndicator = NO; + self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 35, 0); + self.form = form; +} + +// MARK: - View Life Cycle + +- (void)viewDidLoad +{ + [super viewDidLoad]; + + self.title = NSLocalizedString(@"_settings_", nil); + self.view.backgroundColor = UIColor.systemGroupedBackgroundColor; + self.tableView.backgroundColor = UIColor.systemGroupedBackgroundColor; + appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; + + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground) name:NCGlobal.shared.notificationCenterApplicationDidEnterBackground object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeUser) name:NCGlobal.shared.notificationCenterInitialize object:nil]; + + [self initializeForm]; + [self reloadForm]; +} + +- (void)viewWillAppear:(BOOL)animated +{ + [super viewWillAppear:animated]; + + appDelegate.activeViewController = self; + + versionServer = [[NCGlobal shared] capabilityServerVersion]; + themingName = [[NCGlobal shared] capabilityThemingName]; + themingSlogan = [[NCGlobal shared] capabilityThemingSlogan]; +} + +#pragma mark - NotificationCenter + +- (void)changeUser +{ + [self initializeForm]; + [self reloadForm]; +} + +- (void)applicationDidEnterBackground +{ + if (passcodeViewController.view.window != nil) { + [passcodeViewController dismissViewControllerAnimated:true completion:nil]; + } + if (passcodeSettingsViewController.view.window != nil) { + [passcodeSettingsViewController dismissViewControllerAnimated:true completion:nil]; + } + + [[self navigationController] popToRootViewControllerAnimated:false]; +} + +#pragma mark - + +- (void)reloadForm +{ + self.form.delegate = nil; + + // ------------------------------------------------------------------ + + XLFormRowDescriptor *rowBloccoPasscode = [self.form formRowWithTag:@"bloccopasscode"]; + XLFormRowDescriptor *rowNotPasscodeAtStart = [self.form formRowWithTag:@"notPasscodeAtStart"]; + XLFormRowDescriptor *rowEnableTouchDaceID = [self.form formRowWithTag:@"enableTouchDaceID"]; + + // ------------------------------------------------------------------ + + if ([[NCKeychain alloc] init].passcode) { + rowBloccoPasscode.title = NSLocalizedString(@"_lock_active_", nil); + [rowBloccoPasscode.cellConfig setObject:[[UIImage imageNamed:@"lock"] imageWithColor:NCBrandColor.shared.iconColor size:25] forKey:@"imageView.image"]; + rowEnableTouchDaceID.disabled = @NO; + rowNotPasscodeAtStart.disabled = @NO; + } else { + rowBloccoPasscode.title = NSLocalizedString(@"_lock_not_active_", nil); + [rowBloccoPasscode.cellConfig setObject:[[UIImage imageNamed:@"lock_open"] imageWithColor:NCBrandColor.shared.iconColor size:25] forKey:@"imageView.image"]; + rowEnableTouchDaceID.disabled = @YES; + rowNotPasscodeAtStart.disabled = @YES; + } + + if ([[NCKeychain alloc] init].touchFaceID) [rowEnableTouchDaceID setValue:@1]; else [rowEnableTouchDaceID setValue:@0]; + if ([[NCKeychain alloc] init].requestPasscodeAtStart) [rowNotPasscodeAtStart setValue:@0]; else [rowNotPasscodeAtStart setValue:@1]; + + + // ----------------------------------------------------------------- + + [self.tableView reloadData]; + + self.form.delegate = self; +} + +- (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue +{ + [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue]; + + if ([rowDescriptor.tag isEqualToString:@"notPasscodeAtStart"]) { + + if ([[rowDescriptor.value valueData] boolValue] == YES) { + [[NCKeychain alloc] init].requestPasscodeAtStart = false; + } else { + [[NCKeychain alloc] init].requestPasscodeAtStart = true; + } + } + + if ([rowDescriptor.tag isEqualToString:@"enableTouchDaceID"]) { + + if ([[rowDescriptor.value valueData] boolValue] == YES) { + [[NCKeychain alloc] init].touchFaceID = true; + } else { + [[NCKeychain alloc] init].touchFaceID = false; + } + } +} + +#pragma mark - + +- (void)manageE2EE:(XLFormRowDescriptor *)sender +{ + [self deselectFormRow:sender]; + + UIViewController *vc = [[NCManageE2EEInterface alloc] makeShipDetailsUIWithAccount:appDelegate.account]; + [self.navigationController pushViewController:vc animated:YES]; +} + +#pragma mark - Passcode + +- (void)didPerformBiometricValidationRequestInPasscodeViewController:(TOPasscodeViewController *)passcodeViewController +{ + [[LAContext new] evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:[[NCBrandOptions shared] brand] reply:^(BOOL success, NSError * _Nullable error) { + if (success) { + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) { + [[NCKeychain alloc] init].passcode = nil; + [passcodeViewController dismissViewControllerAnimated:YES completion:nil]; + [self reloadForm]; + }); + } + }]; +} + +- (void)passcodeSettingsViewController:(TOPasscodeSettingsViewController *)passcodeSettingsViewController didChangeToNewPasscode:(NSString *)passcode ofType:(TOPasscodeType)type +{ + [[NCKeychain alloc] init].passcode = passcode; + [passcodeSettingsViewController dismissViewControllerAnimated:YES completion:nil]; + + [self reloadForm]; +} + +- (void)didTapCancelInPasscodeViewController:(TOPasscodeViewController *)passcodeViewController +{ + [passcodeViewController dismissViewControllerAnimated:YES completion:nil]; +} + +- (BOOL)passcodeViewController:(TOPasscodeViewController *)passcodeViewController isCorrectCode:(NSString *)code +{ + if ([code isEqualToString:[[NCKeychain alloc] init].passcode]) { + [[NCKeychain alloc] init].passcode = nil; + [self reloadForm]; + + return YES; + } + + return NO; +} + +- (void)passcode:(XLFormRowDescriptor *)sender +{ + LAContext *laContext = [LAContext new]; + NSError *error; + + [self deselectFormRow:sender]; + + if ([[NCKeychain alloc] init].passcode) { + + passcodeViewController = [[TOPasscodeViewController alloc] initPasscodeType:TOPasscodeTypeSixDigits allowCancel:true]; + passcodeViewController.delegate = self; + passcodeViewController.keypadButtonShowLettering = false; + + if ([[NCKeychain alloc] init].touchFaceID && [laContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) { + if (error == NULL) { + if (laContext.biometryType == LABiometryTypeFaceID) { + passcodeViewController.biometryType = TOPasscodeBiometryTypeFaceID; + passcodeViewController.allowBiometricValidation = true; + passcodeViewController.automaticallyPromptForBiometricValidation = true; + } else if (laContext.biometryType == LABiometryTypeTouchID) { + passcodeViewController.biometryType = TOPasscodeBiometryTypeTouchID; + passcodeViewController.allowBiometricValidation = true; + passcodeViewController.automaticallyPromptForBiometricValidation = true; + } else { + NSLog(@"No Biometric support"); + } + } + } + + [self presentViewController:passcodeViewController animated:YES completion:nil]; + + } else { + + passcodeSettingsViewController = [[TOPasscodeSettingsViewController alloc] init]; + passcodeSettingsViewController.hideOptionsButton = YES; + passcodeSettingsViewController.requireCurrentPasscode = NO; + passcodeSettingsViewController.passcodeType = TOPasscodeTypeSixDigits; + passcodeSettingsViewController.delegate = self; + + [self presentViewController:passcodeSettingsViewController animated:YES completion:nil]; + } +} + +#pragma mark - + +- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { + return NCGlobal.shared.heightCellSettings; +} + +- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section +{ + NSString *sectionName; + NSInteger numSections = [tableView numberOfSections] - 1; + + return sectionName; +} + +@end diff --git a/iOSClient/Settings/OpenSourceSoftwareViewController.swift b/iOSClient/Settings/OpenSourceSoftwareViewController.swift new file mode 100644 index 0000000000..e4cd131f83 --- /dev/null +++ b/iOSClient/Settings/OpenSourceSoftwareViewController.swift @@ -0,0 +1,56 @@ +// +// OpenSourceSoftwareViewController.swift +// Nextcloud +// +// Created by A200073704 on 11/05/23. +// Copyright © 2023 Marino Faggiana. All rights reserved. +// + +import UIKit +import WebKit + +class OpenSourceSoftwareViewController: UIViewController, WKNavigationDelegate, WKUIDelegate { + + override func viewDidLoad() { + super.viewDidLoad() + // Do any additional setup after loading the view, typically from a nib. + + self.title = NSLocalizedString("_used_opensource_software_", comment: "") + let myWebView:WKWebView = WKWebView(frame: CGRect(x:0, y:0, width: UIScreen.main.bounds.width, height:UIScreen.main.bounds.height)) + myWebView.uiDelegate = self + myWebView.navigationDelegate = self + myWebView.autoresizingMask = [.flexibleWidth, .flexibleHeight] + self.view.addSubview(myWebView) + + + //1. Load web site into my web view + let myURL = URL(string: "https://static.magentacloud.de/licences/ios.html") + let myURLRequest:URLRequest = URLRequest(url: myURL!) + NCActivityIndicator.shared.start() + myWebView.load(myURLRequest) + + } + + override func didReceiveMemoryWarning() { + super.didReceiveMemoryWarning() + // Dispose of any resources that can be recreated. + } + + func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { + NCActivityIndicator.shared.stop() + } + + func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) { + if navigationAction.navigationType == .linkActivated { + if let url = navigationAction.request.url, + UIApplication.shared.canOpenURL(url) { + UIApplication.shared.open(url) + decisionHandler(.cancel) + } else { + decisionHandler(.allow) + } + } else { + decisionHandler(.allow) + } + } +}