diff --git a/Brand/NCBrand.swift b/Brand/NCBrand.swift index b496e61340..3fac622ea9 100755 --- a/Brand/NCBrand.swift +++ b/Brand/NCBrand.swift @@ -39,7 +39,7 @@ let userAgent: String = { var textCopyrightNextcloudiOS: String = "Nextcloud Hydrogen for iOS %@ © 2024" var textCopyrightNextcloudServer: String = "Nextcloud Server %@" var loginBaseUrl: String = "https://cloud.nextcloud.com" - @objc var pushNotificationServerProxy: String = "https://push-notifications.nextcloud.com" + var pushNotificationServerProxy: String = "https://push-notifications.nextcloud.com" var linkLoginHost: String = "https://nextcloud.com/install" var linkloginPreferredProviders: String = "https://nextcloud.com/signup-ios" var webLoginAutenticationProtocol: String = "nc://" // example "abc://" diff --git a/File Provider Extension/FileProviderEnumerator.swift b/File Provider Extension/FileProviderEnumerator.swift index 671091d1ab..f9cdd88cde 100644 --- a/File Provider Extension/FileProviderEnumerator.swift +++ b/File Provider Extension/FileProviderEnumerator.swift @@ -31,8 +31,11 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator { var serverUrl: String? let providerUtility = fileProviderUtility() let database = NCManageDatabase.shared - var recordsPerPage: Int = 20 var anchor: UInt64 = 0 + // X-NC-PAGINATE + var recordsPerPage: Int = 100 + var paginateToken: String? + var paginatedTotal: Int = 0 init(enumeratedItemIdentifier: NSFileProviderItemIdentifier) { self.enumeratedItemIdentifier = enumeratedItemIdentifier @@ -82,13 +85,13 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator { observer.finishEnumerating(upTo: nil) return } - var pageNumber = 1 + var pageNumber = 0 if let stringPage = String(data: page.rawValue, encoding: .utf8), let intPage = Int(stringPage) { pageNumber = intPage } - self.fetchItemsForPage(serverUrl: serverUrl, pageNumber: pageNumber) { metadatas in + self.fetchItemsForPage(serverUrl: serverUrl, pageNumber: pageNumber) { metadatas, isPaginated in if let metadatas { for metadata in metadatas { if metadata.e2eEncrypted || (!metadata.session.isEmpty && metadata.session != NCNetworking.shared.sessionUploadBackgroundExt) { @@ -104,7 +107,8 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator { observer.didEnumerate(items) if let metadatas, - metadatas.count == self.recordsPerPage { + isPaginated, + metadatas.count == self.recordsPerPage { pageNumber += 1 let providerPage = NSFileProviderPage("\(pageNumber)".data(using: .utf8)!) observer.finishEnumerating(upTo: providerPage) @@ -157,27 +161,56 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator { completionHandler(NSFileProviderSyncAnchor(data!)) } - func fetchItemsForPage(serverUrl: String, pageNumber: Int, completionHandler: @escaping (_ metadatas: Results?) -> Void) { - let predicate = NSPredicate(format: "account == %@ AND serverUrl == %@", fileProviderData.shared.session.account, serverUrl) + func fetchItemsForPage(serverUrl: String, pageNumber: Int, completion: @escaping (_ metadatas: [tableMetadata]?, _ isPaginated: Bool) -> Void) { + var useFirstAsMetadataFolder: Bool = false + var isPaginated: Bool = false + var paginateCount = recordsPerPage + if pageNumber == 0 { + paginateCount += 1 + } + var offset = pageNumber * recordsPerPage + if pageNumber > 0 { + offset += 1 + } + let options = NKRequestOptions(paginate: true, + paginateToken: self.paginateToken, + paginateOffset: offset, + paginateCount: paginateCount, + queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue) + + print("PAGINATE OFFSET: \(offset) COUNT: \(paginateCount) TOTAL: \(self.paginatedTotal)") + + NextcloudKit.shared.readFileOrFolder(serverUrlFileName: serverUrl, depth: "1", showHiddenFiles: NCKeychain().showHiddenFiles, account: fileProviderData.shared.session.account, options: options) { _, files, responseData, error in + if let headers = responseData?.response?.allHeaderFields as? [String: String] { + let normalizedHeaders = Dictionary(uniqueKeysWithValues: headers.map { ($0.key.lowercased(), $0.value) }) + isPaginated = Bool(normalizedHeaders["x-nc-paginate"] ?? "false") ?? false + self.paginateToken = normalizedHeaders["x-nc-paginate-token"] + self.paginatedTotal = Int(normalizedHeaders["x-nc-paginate-total"] ?? "0") ?? 0 + } - if pageNumber == 1 { - NextcloudKit.shared.readFileOrFolder(serverUrlFileName: serverUrl, depth: "1", showHiddenFiles: NCKeychain().showHiddenFiles, account: fileProviderData.shared.session.account) { _, files, _, error in - if error == .success, let files { - self.database.convertFilesToMetadatas(files, useFirstAsMetadataFolder: true) { metadataFolder, metadatas in - /// FOLDER + if error == .success, let files { + if pageNumber == 0 { + self.database.deleteMetadata(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", fileProviderData.shared.session.account, serverUrl)) + useFirstAsMetadataFolder = true + } + self.database.convertFilesToMetadatas(files, useFirstAsMetadataFolder: useFirstAsMetadataFolder) { metadataFolder, metadatas in + /// FOLDER + if useFirstAsMetadataFolder { self.database.addMetadata(metadataFolder) self.database.addDirectory(e2eEncrypted: metadataFolder.e2eEncrypted, favorite: metadataFolder.favorite, ocId: metadataFolder.ocId, fileId: metadataFolder.fileId, etag: metadataFolder.etag, permissions: metadataFolder.permissions, richWorkspace: metadataFolder.richWorkspace, serverUrl: serverUrl, account: metadataFolder.account) - /// FILES - self.database.deleteMetadata(predicate: predicate) - self.database.addMetadatas(metadatas) } + /// FILES + self.database.addMetadatas(metadatas) + completion(metadatas, isPaginated) + } + } else { + if isPaginated { + completion(nil, isPaginated) + } else { + let metadatas = self.database.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", fileProviderData.shared.session.account, serverUrl)) + completion(metadatas, isPaginated) } - let resultsMetadata = self.database.fetchPagedResults(ofType: tableMetadata.self, primaryKey: "ocId", recordsPerPage: self.recordsPerPage, pageNumber: pageNumber, filter: predicate, sortedByKeyPath: "fileName") - completionHandler(resultsMetadata) } - } else { - let resultsMetadata = self.database.fetchPagedResults(ofType: tableMetadata.self, primaryKey: "ocId", recordsPerPage: recordsPerPage, pageNumber: pageNumber, filter: predicate, sortedByKeyPath: "fileName") - completionHandler(resultsMetadata) } } } diff --git a/File Provider Extension/FileProviderExtension+Thumbnail.swift b/File Provider Extension/FileProviderExtension+Thumbnail.swift index 0cffbb8515..e3d58c2e8b 100644 --- a/File Provider Extension/FileProviderExtension+Thumbnail.swift +++ b/File Provider Extension/FileProviderExtension+Thumbnail.swift @@ -32,15 +32,19 @@ extension FileProviderExtension { var counterProgress: Int64 = 0 for itemIdentifier in itemIdentifiers { - guard let metadata = providerUtility.getTableMetadataFromItemIdentifier(itemIdentifier), metadata.hasPreview else { + guard let metadata = providerUtility.getTableMetadataFromItemIdentifier(itemIdentifier), + metadata.hasPreview + else { counterProgress += 1 - if counterProgress == progress.totalUnitCount { completionHandler(nil) } + if counterProgress == progress.totalUnitCount { + completionHandler(nil) + } continue } NextcloudKit.shared.downloadPreview(fileId: metadata.fileId, - width: Int(size.width), - height: Int(size.height), + width: Int(NCGlobal.shared.size512.width), + height: Int(NCGlobal.shared.size512.height), etag: metadata.etag, account: metadata.account) { _ in } completion: { _, _, _, _, responseData, error in @@ -55,6 +59,7 @@ extension FileProviderExtension { } } } + return progress } } diff --git a/Nextcloud.xcodeproj/project.pbxproj b/Nextcloud.xcodeproj/project.pbxproj index 21629c71f1..8409f7a395 100644 --- a/Nextcloud.xcodeproj/project.pbxproj +++ b/Nextcloud.xcodeproj/project.pbxproj @@ -234,6 +234,8 @@ F711A4EB2AF9327D00095DD8 /* UIImage+animatedGIF.m in Sources */ = {isa = PBXBuildFile; fileRef = F713FEFF2472764100214AF6 /* UIImage+animatedGIF.m */; }; F711A4EF2AF932B900095DD8 /* SVGKitSwift in Frameworks */ = {isa = PBXBuildFile; productRef = F711A4EE2AF932B900095DD8 /* SVGKitSwift */; }; F711D63128F44801003F43C8 /* IntentHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7C9739428F17131002C43E2 /* IntentHandler.swift */; }; + F7132C722D085AD200B42D6A /* NCTermOfServiceModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7132C6B2D085AD200B42D6A /* NCTermOfServiceModel.swift */; }; + F7132C732D085AD200B42D6A /* NCTermOfServiceView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7132C6C2D085AD200B42D6A /* NCTermOfServiceView.swift */; }; F713FBE52C31645200F10760 /* NCNetworking+AsyncAwait.swift in Sources */ = {isa = PBXBuildFile; fileRef = F713FBE42C31645200F10760 /* NCNetworking+AsyncAwait.swift */; }; F713FBE62C31646400F10760 /* NCNetworking+AsyncAwait.swift in Sources */ = {isa = PBXBuildFile; fileRef = F713FBE42C31645200F10760 /* NCNetworking+AsyncAwait.swift */; }; F713FBE72C31646500F10760 /* NCNetworking+AsyncAwait.swift in Sources */ = {isa = PBXBuildFile; fileRef = F713FBE42C31645200F10760 /* NCNetworking+AsyncAwait.swift */; }; @@ -1258,6 +1260,8 @@ F710D1F42405770F00A6033D /* NCViewerPDF.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCViewerPDF.swift; sourceTree = ""; }; F710D2012405826100A6033D /* NCViewer+Menu.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NCViewer+Menu.swift"; sourceTree = ""; }; F711A4DB2AF92CAD00095DD8 /* NCUtility+Date.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NCUtility+Date.swift"; sourceTree = ""; }; + F7132C6B2D085AD200B42D6A /* NCTermOfServiceModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCTermOfServiceModel.swift; sourceTree = ""; }; + F7132C6C2D085AD200B42D6A /* NCTermOfServiceView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCTermOfServiceView.swift; sourceTree = ""; }; F713FBE42C31645200F10760 /* NCNetworking+AsyncAwait.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCNetworking+AsyncAwait.swift"; sourceTree = ""; }; F713FEFE2472764000214AF6 /* UIImage+animatedGIF.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+animatedGIF.h"; sourceTree = ""; }; F713FEFF2472764100214AF6 /* UIImage+animatedGIF.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+animatedGIF.m"; sourceTree = ""; }; @@ -2095,6 +2099,15 @@ path = Color; sourceTree = ""; }; + F7132C6D2D085AD200B42D6A /* Terms of service */ = { + isa = PBXGroup; + children = ( + F7132C6B2D085AD200B42D6A /* NCTermOfServiceModel.swift */, + F7132C6C2D085AD200B42D6A /* NCTermOfServiceView.swift */, + ); + path = "Terms of service"; + sourceTree = ""; + }; F713418B2597513800768D21 /* PushNotification */ = { isa = PBXGroup; children = ( @@ -3091,6 +3104,7 @@ F79A65C12191D8DC00FF6DCC /* Select */, F728CE741BF6322C00E69702 /* Share */, F7169A161EE590930086BD69 /* Shares */, + F7132C6D2D085AD200B42D6A /* Terms of service */, F7E9C41320F4CA870040CF18 /* Transfers */, F78F74322163753B00C2ADAD /* Trash */, F7EFC0CB256BF89300461AAD /* UserStatus */, @@ -4367,6 +4381,8 @@ F7CBC1252BAC8B0000EC1D55 /* NCSectionFirstHeaderEmptyData.swift in Sources */, F7D4BF3D2CA2E8D800A5E746 /* TOPasscodeKeypadView.m in Sources */, F7D4BF3E2CA2E8D800A5E746 /* TOPasscodeSettingsKeypadView.m in Sources */, + F7132C722D085AD200B42D6A /* NCTermOfServiceModel.swift in Sources */, + F7132C732D085AD200B42D6A /* NCTermOfServiceView.swift in Sources */, F7D4BF3F2CA2E8D800A5E746 /* TOPasscodeFixedInputView.m in Sources */, F7D4BF402CA2E8D800A5E746 /* TOPasscodeButtonLabel.m in Sources */, F7D4BF412CA2E8D800A5E746 /* TOPasscodeViewControllerAnimatedTransitioning.m in Sources */, @@ -5487,7 +5503,7 @@ CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 4; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = NKUJUXUJ3B; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -5514,7 +5530,7 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 6.1.8; + MARKETING_VERSION = 6.1.9; ONLY_ACTIVE_ARCH = YES; OTHER_CFLAGS = "-v"; OTHER_LDFLAGS = ""; @@ -5553,7 +5569,7 @@ CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 4; DEVELOPMENT_TEAM = NKUJUXUJ3B; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; @@ -5577,7 +5593,7 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 6.1.8; + MARKETING_VERSION = 6.1.9; ONLY_ACTIVE_ARCH = YES; OTHER_CFLAGS = "-v"; OTHER_LDFLAGS = ""; @@ -5852,7 +5868,7 @@ repositoryURL = "https://github.com/nextcloud/NextcloudKit"; requirement = { kind = exactVersion; - version = 5.0.1; + version = 5.0.2; }; }; F788ECC5263AAAF900ADC67F /* XCRemoteSwiftPackageReference "MarkdownKit" */ = { diff --git a/iOSClient/Account Settings/NCAccountSettingsModel.swift b/iOSClient/Account Settings/NCAccountSettingsModel.swift index 8eb33b49d8..ba7c01434f 100644 --- a/iOSClient/Account Settings/NCAccountSettingsModel.swift +++ b/iOSClient/Account Settings/NCAccountSettingsModel.swift @@ -160,7 +160,13 @@ class NCAccountSettingsModel: ObservableObject, ViewOnAppearHandling { } /// Function to change account after 1.5 sec of change - func setAccount(account: String) { + func setAccount(account: String?) { + guard let account + else { + self.tblAccount = nil + self.alias = "" + return + } if let tableAccount = database.getTableAccount(predicate: NSPredicate(format: "account == %@", account)) { self.tblAccount = tableAccount self.alias = tableAccount.alias @@ -170,14 +176,10 @@ class NCAccountSettingsModel: ObservableObject, ViewOnAppearHandling { /// Function to delete the current account func deleteAccount() { if let tblAccount { - NCAccount().deleteAccount(tblAccount.account) - if let account = database.getAllTableAccount().first?.account { - NCAccount().changeAccount(account, userProfile: nil, controller: self.controller) { - onViewAppear() - } - } else { + NCAccount().deleteAccount(tblAccount.account) { + let account = database.getAllTableAccount().first?.account + setAccount(account: account) dismissView = true - appDelegate.openLogin(selector: NCGlobal.shared.introLogin) } } } diff --git a/iOSClient/Account Settings/NCAccountSettingsView.swift b/iOSClient/Account Settings/NCAccountSettingsView.swift index 944a1dd7d7..4ba6ff8379 100644 --- a/iOSClient/Account Settings/NCAccountSettingsView.swift +++ b/iOSClient/Account Settings/NCAccountSettingsView.swift @@ -50,7 +50,7 @@ struct NCAccountSettingsView: View { Image(uiImage: avatar) .resizable() .scaledToFit() - .frame(width: UIScreen.main.bounds.width, height: 75) + .frame(width: UIScreen.main.bounds.width, height: 65) if let statusImage = status.statusImage { ZStack { Circle() diff --git a/iOSClient/AppDelegate.swift b/iOSClient/AppDelegate.swift index 9b502da283..8acd5d4f0c 100644 --- a/iOSClient/AppDelegate.swift +++ b/iOSClient/AppDelegate.swift @@ -279,14 +279,17 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD } func nextcloudPushNotificationAction(data: [String: AnyObject]) { - guard let data = NCApplicationHandle().nextcloudPushNotificationAction(data: data), - let account = data["account"] as? String + guard let data = NCApplicationHandle().nextcloudPushNotificationAction(data: data) else { return } + let account = data["account"] as? String ?? "unavailable" + let app = data["app"] as? String func openNotification(controller: NCMainTabBarController) { - if let viewController = UIStoryboard(name: "NCNotification", bundle: nil).instantiateInitialViewController() as? NCNotification { + if app == NCGlobal.shared.termsOfServiceName { + NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterGetServerData, second: 0.5) + } else if let viewController = UIStoryboard(name: "NCNotification", bundle: nil).instantiateInitialViewController() as? NCNotification { viewController.session = NCSession.shared.getSession(account: account) DispatchQueue.main.asyncAfter(deadline: .now() + 1) { let navigationController = UINavigationController(rootViewController: viewController) diff --git a/iOSClient/Files/NCFiles.swift b/iOSClient/Files/NCFiles.swift index f87039a2c1..0bb1dc3f75 100644 --- a/iOSClient/Files/NCFiles.swift +++ b/iOSClient/Files/NCFiles.swift @@ -24,12 +24,14 @@ import UIKit import NextcloudKit import RealmSwift +import SwiftUI class NCFiles: NCCollectionViewCommon { internal var isRoot: Bool = true internal var fileNameBlink: String? internal var fileNameOpen: String? internal var matadatasHash: String = "" + internal var semaphoreReloadDataSource = DispatchSemaphore(value: 1) required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) @@ -123,6 +125,7 @@ class NCFiles: NCCollectionViewCommon { guard !isSearchingMode else { return super.reloadDataSource() } + self.semaphoreReloadDataSource.wait() var predicate = self.defaultPredicate let predicateDirectory = NSPredicate(format: "account == %@ AND serverUrl == %@", session.account, self.serverUrl) @@ -140,10 +143,12 @@ class NCFiles: NCCollectionViewCommon { self.dataSource = NCCollectionViewDataSource(metadatas: metadatas, layoutForView: layoutForView) if metadatas.isEmpty { + self.semaphoreReloadDataSource.signal() return super.reloadDataSource() } self.dataSource.caching(metadatas: metadatas, dataSourceMetadatas: dataSourceMetadatas) { updated in + self.semaphoreReloadDataSource.signal() if updated || self.isNumberOfItemsInAllSectionsNull || self.numberOfItemsInAllSections != metadatas.count { super.reloadDataSource() } @@ -188,6 +193,19 @@ class NCFiles: NCCollectionViewCommon { NCNetworking.shared.downloadQueue.addOperation(NCOperationDownload(metadata: metadata, selector: NCGlobal.shared.selectorDownloadFile)) } } + } else if error.errorCode == self.global.errorForbidden { + DispatchQueue.main.async { + if self.presentedViewController == nil { + NextcloudKit.shared.getTermsOfService(account: self.session.account) { _, tos, _, error in + if error == .success, let tos { + let termOfServiceModel = NCTermOfServiceModel(controller: self.controller, tos: tos) + let termOfServiceView = NCTermOfServiceModelView(model: termOfServiceModel) + let termOfServiceController = UIHostingController(rootView: termOfServiceView) + self.present(termOfServiceController, animated: true, completion: nil) + } + } + } + } } } } @@ -324,6 +342,7 @@ class NCFiles: NCCollectionViewCommon { override func accountSettingsDidDismiss(tableAccount: tableAccount?, controller: NCMainTabBarController?) { let currentAccount = session.account + if database.getAllTableAccount().isEmpty { appDelegate.openLogin(selector: NCGlobal.shared.introLogin) } else if let account = tableAccount?.account, account != currentAccount { @@ -332,5 +351,7 @@ class NCFiles: NCCollectionViewCommon { titleCurrentFolder = getNavigationTitle() navigationItem.title = titleCurrentFolder } + + setNavigationLeftItems() } } diff --git a/iOSClient/GUI/ComponentView.swift b/iOSClient/GUI/ComponentView.swift index 4e2bd766d1..ac330f32fc 100644 --- a/iOSClient/GUI/ComponentView.swift +++ b/iOSClient/GUI/ComponentView.swift @@ -23,25 +23,6 @@ import SwiftUI -struct TextFieldClearButton: ViewModifier { - @Binding var text: String - - func body(content: Content) -> some View { - HStack { - content - if !text.isEmpty { - Button( - action: { self.text = "" }, - label: { - Image(systemName: "xmark.circle.fill") - .foregroundColor(Color(UIColor.placeholderText)) - } - ).buttonStyle(BorderlessButtonStyle()) - } - } - } -} - struct ButtonRounded: ButtonStyle { var disabled = false var account = "" diff --git a/iOSClient/Media/NCMedia.swift b/iOSClient/Media/NCMedia.swift index 8de4ed4684..1592201655 100644 --- a/iOSClient/Media/NCMedia.swift +++ b/iOSClient/Media/NCMedia.swift @@ -53,8 +53,8 @@ class NCMedia: UIViewController { var isTop: Bool = true var isEditMode = false var fileSelect: [String] = [] - var filesExists: [String] = [] - var ocIdDoNotExists: [String] = [] + var filesExists: ThreadSafeArray = ThreadSafeArray() + var ocIdDoNotExists: ThreadSafeArray = ThreadSafeArray() var hasRunSearchMedia: Bool = false var attributesZoomIn: UIMenuElement.Attributes = [] var attributesZoomOut: UIMenuElement.Attributes = [] @@ -292,10 +292,12 @@ class NCMedia: UIViewController { ocIdDoNotExists.append(ocId) } - if NCNetworking.shared.fileExistsQueue.operationCount == 0, !ocIdDoNotExists.isEmpty { + if NCNetworking.shared.fileExistsQueue.operationCount == 0, + !ocIdDoNotExists.isEmpty, + let ocIdDoNotExists = self.ocIdDoNotExists.getArray() { dataSource.removeMetadata(ocIdDoNotExists) database.deleteMetadataOcIds(ocIdDoNotExists) - ocIdDoNotExists.removeAll() + self.ocIdDoNotExists.removeAll() collectionViewReloadData() } } diff --git a/iOSClient/NCAccount.swift b/iOSClient/NCAccount.swift index ebb0de9013..9464120dd0 100644 --- a/iOSClient/NCAccount.swift +++ b/iOSClient/NCAccount.swift @@ -99,7 +99,7 @@ class NCAccount: NSObject { completion() } - func deleteAccount(_ account: String, wipe: Bool = true) { + func deleteAccount(_ account: String, wipe: Bool = true, completion: () -> Void = {}) { UIApplication.shared.allSceneSessionDestructionExceptFirst() /// Unsubscribing Push Notification @@ -129,6 +129,8 @@ class NCAccount: NSObject { NCKeychain().clearAllKeysPushNotification(account: account) /// Remove User Default Data NCNetworking.shared.removeAllKeyUserDefaultsData(account: account) + + completion() } func deleteAllAccounts() { diff --git a/iOSClient/NCGlobal.swift b/iOSClient/NCGlobal.swift index 80594ccaaa..dd577ebc9a 100644 --- a/iOSClient/NCGlobal.swift +++ b/iOSClient/NCGlobal.swift @@ -55,6 +55,7 @@ class NCGlobal: NSObject { let talkName = "talk-message" let spreedName = "spreed" let twoFactorNotificatioName = "twofactor_nextcloud_notification" + let termsOfServiceName = "terms_of_service" // Nextcloud version // diff --git a/iOSClient/Networking/NCNetworking+Download.swift b/iOSClient/Networking/NCNetworking+Download.swift index cb2218896e..fd90228b79 100644 --- a/iOSClient/Networking/NCNetworking+Download.swift +++ b/iOSClient/Networking/NCNetworking+Download.swift @@ -303,7 +303,7 @@ class NCOperationDownload: ConcurrentOperation, @unchecked Sendable { metadata.sessionTaskIdentifier = 0 metadata.status = NCGlobal.shared.metadataStatusWaitDownload - NCManageDatabase.shared.addMetadata(metadata) + let metadata = NCManageDatabase.shared.addMetadata(metadata) NCNetworking.shared.download(metadata: metadata, withNotificationProgressTask: true) { } completion: { _, _ in diff --git a/iOSClient/Networking/NCService.swift b/iOSClient/Networking/NCService.swift index e6ba678492..89f9e687df 100644 --- a/iOSClient/Networking/NCService.swift +++ b/iOSClient/Networking/NCService.swift @@ -149,13 +149,16 @@ class NCService: NSObject { avatarSizeRounded: NCGlobal.shared.avatarSizeRounded, etag: etag, account: account, - options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { _, _, _, etag, _, error in - if let etag = etag, error == .success { - self.database.addAvatar(fileName: fileName, etag: etag) + options: NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)) { _, _, _, newEtag, _, error in + if let newEtag, + etag != newEtag, + error == .success { + self.database.addAvatar(fileName: fileName, etag: newEtag) + + NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterReloadAvatar, userInfo: ["error": error]) } else if error.errorCode == NCGlobal.shared.errorNotModified { self.database.setAvatarLoaded(fileName: fileName) } - NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterReloadAvatar, userInfo: ["error": error]) } } diff --git a/iOSClient/Scan document/NCUploadScanDocument.swift b/iOSClient/Scan document/NCUploadScanDocument.swift index a43b8e1a43..f0e87bd2b6 100644 --- a/iOSClient/Scan document/NCUploadScanDocument.swift +++ b/iOSClient/Scan document/NCUploadScanDocument.swift @@ -373,7 +373,6 @@ struct UploadScanDocumentView: View { HStack { Text(NSLocalizedString("_filename_", comment: "")) TextField(NSLocalizedString("_enter_filename_", comment: ""), text: $fileName) - .modifier(TextFieldClearButton(text: $fileName)) .multilineTextAlignment(.trailing) .onChange(of: fileName) { _ in let controller = (UIApplication.shared.firstWindow?.rootViewController as? NCMainTabBarController) @@ -416,30 +415,32 @@ struct UploadScanDocumentView: View { view.listRowSeparator(.hidden) } - VStack(spacing: 20) { - Toggle(NSLocalizedString("_delete_all_scanned_images_", comment: ""), isOn: $removeAllFiles) - .toggleStyle(SwitchToggleStyle(tint: Color(NCBrandColor.shared.getElement(account: model.session.account)))) - .onChange(of: removeAllFiles) { newValue in - NCKeychain().deleteAllScanImages = newValue - } - Button(NSLocalizedString("_save_", comment: "")) { - let fileName = model.fileName(fileName) - if !fileName.isEmpty { - model.showHUD.toggle() - model.save(fileName: fileName, password: password, isTextRecognition: isTextRecognition, removeAllFiles: removeAllFiles, quality: quality) { openConflictViewController, error in + Section { + VStack(spacing: 20) { + Toggle(NSLocalizedString("_delete_all_scanned_images_", comment: ""), isOn: $removeAllFiles) + .toggleStyle(SwitchToggleStyle(tint: Color(NCBrandColor.shared.getElement(account: model.session.account)))) + .onChange(of: removeAllFiles) { newValue in + NCKeychain().deleteAllScanImages = newValue + } + Button(NSLocalizedString("_save_", comment: "")) { + let fileName = model.fileName(fileName) + if !fileName.isEmpty { model.showHUD.toggle() - if error { - print("error") - } else if openConflictViewController { - isPresentedUploadConflict = true - } else { - NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDismissScanDocument) + model.save(fileName: fileName, password: password, isTextRecognition: isTextRecognition, removeAllFiles: removeAllFiles, quality: quality) { openConflictViewController, error in + model.showHUD.toggle() + if error { + print("error") + } else if openConflictViewController { + isPresentedUploadConflict = true + } else { + NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDismissScanDocument) + } } } } + .buttonStyle(ButtonRounded(disabled: fileName.isEmpty || !footer.isEmpty, account: model.session.account)) + .disabled(fileName.isEmpty || !footer.isEmpty) } - .buttonStyle(ButtonRounded(disabled: fileName.isEmpty || !footer.isEmpty, account: model.session.account)) - .disabled(fileName.isEmpty || !footer.isEmpty) } Section(header: Text(NSLocalizedString("_quality_image_title_", comment: ""))) { @@ -469,8 +470,6 @@ struct UploadScanDocumentView: View { } .sheet(isPresented: $isPresentedUploadConflict) { UploadConflictView(delegate: model, serverUrl: model.serverUrl, metadatasUploadInConflict: [model.metadata], metadatasNOConflict: []) - }.onTapGesture { - UIApplication.shared.connectedScenes.flatMap { ($0 as? UIWindowScene)?.windows ?? [] }.filter { $0.isKeyWindow }.first?.endEditing(true) } } } diff --git a/iOSClient/Supporting Files/af.lproj/Localizable.strings b/iOSClient/Supporting Files/af.lproj/Localizable.strings index 7ff710b4a4..bf7af0d72c 100644 Binary files a/iOSClient/Supporting Files/af.lproj/Localizable.strings and b/iOSClient/Supporting Files/af.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/an.lproj/Localizable.strings b/iOSClient/Supporting Files/an.lproj/Localizable.strings index cdd335c180..24d93ae700 100644 Binary files a/iOSClient/Supporting Files/an.lproj/Localizable.strings and b/iOSClient/Supporting Files/an.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/ar.lproj/Localizable.strings b/iOSClient/Supporting Files/ar.lproj/Localizable.strings index bd8d917f46..371b03de18 100644 Binary files a/iOSClient/Supporting Files/ar.lproj/Localizable.strings and b/iOSClient/Supporting Files/ar.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/ast.lproj/Localizable.strings b/iOSClient/Supporting Files/ast.lproj/Localizable.strings index 99cebbfd0f..4195e2f5c8 100644 Binary files a/iOSClient/Supporting Files/ast.lproj/Localizable.strings and b/iOSClient/Supporting Files/ast.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/az.lproj/Localizable.strings b/iOSClient/Supporting Files/az.lproj/Localizable.strings index 27eddb2c6b..53bdc363ae 100644 Binary files a/iOSClient/Supporting Files/az.lproj/Localizable.strings and b/iOSClient/Supporting Files/az.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/be.lproj/Localizable.strings b/iOSClient/Supporting Files/be.lproj/Localizable.strings index 8ad27ff06c..7e4f12026a 100644 Binary files a/iOSClient/Supporting Files/be.lproj/Localizable.strings and b/iOSClient/Supporting Files/be.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/bg_BG.lproj/Localizable.strings b/iOSClient/Supporting Files/bg_BG.lproj/Localizable.strings index 9ab2503b62..4d7db768b7 100644 Binary files a/iOSClient/Supporting Files/bg_BG.lproj/Localizable.strings and b/iOSClient/Supporting Files/bg_BG.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/bn_BD.lproj/Localizable.strings b/iOSClient/Supporting Files/bn_BD.lproj/Localizable.strings index 43a3679dc8..e5c5666f80 100644 Binary files a/iOSClient/Supporting Files/bn_BD.lproj/Localizable.strings and b/iOSClient/Supporting Files/bn_BD.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/br.lproj/Localizable.strings b/iOSClient/Supporting Files/br.lproj/Localizable.strings index 733311dab2..e4d04f3abf 100644 Binary files a/iOSClient/Supporting Files/br.lproj/Localizable.strings and b/iOSClient/Supporting Files/br.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/bs.lproj/Localizable.strings b/iOSClient/Supporting Files/bs.lproj/Localizable.strings index 78ca21721f..4a7acff6b5 100644 Binary files a/iOSClient/Supporting Files/bs.lproj/Localizable.strings and b/iOSClient/Supporting Files/bs.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/ca.lproj/Localizable.strings b/iOSClient/Supporting Files/ca.lproj/Localizable.strings index 3389e74906..a1bf1a0821 100644 Binary files a/iOSClient/Supporting Files/ca.lproj/Localizable.strings and b/iOSClient/Supporting Files/ca.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/cs-CZ.lproj/Localizable.strings b/iOSClient/Supporting Files/cs-CZ.lproj/Localizable.strings index f5364f47db..6a98162ede 100644 Binary files a/iOSClient/Supporting Files/cs-CZ.lproj/Localizable.strings and b/iOSClient/Supporting Files/cs-CZ.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/cy_GB.lproj/Localizable.strings b/iOSClient/Supporting Files/cy_GB.lproj/Localizable.strings index 1fcb60905e..bcd77f489c 100644 Binary files a/iOSClient/Supporting Files/cy_GB.lproj/Localizable.strings and b/iOSClient/Supporting Files/cy_GB.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/da.lproj/Localizable.strings b/iOSClient/Supporting Files/da.lproj/Localizable.strings index a5d0ed71a6..7d70fc9f68 100644 Binary files a/iOSClient/Supporting Files/da.lproj/Localizable.strings and b/iOSClient/Supporting Files/da.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/de.lproj/Localizable.strings b/iOSClient/Supporting Files/de.lproj/Localizable.strings index ef853129e3..70e2eb935f 100644 Binary files a/iOSClient/Supporting Files/de.lproj/Localizable.strings and b/iOSClient/Supporting Files/de.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/el.lproj/Localizable.strings b/iOSClient/Supporting Files/el.lproj/Localizable.strings index 3af502a802..0349bd0ed6 100644 Binary files a/iOSClient/Supporting Files/el.lproj/Localizable.strings and b/iOSClient/Supporting Files/el.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/en-GB.lproj/Localizable.strings b/iOSClient/Supporting Files/en-GB.lproj/Localizable.strings index de34f3bd92..df22923d5f 100644 Binary files a/iOSClient/Supporting Files/en-GB.lproj/Localizable.strings and b/iOSClient/Supporting Files/en-GB.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/en.lproj/Localizable.strings b/iOSClient/Supporting Files/en.lproj/Localizable.strings index c7aecf1845..d180c2e608 100644 --- a/iOSClient/Supporting Files/en.lproj/Localizable.strings +++ b/iOSClient/Supporting Files/en.lproj/Localizable.strings @@ -1051,6 +1051,9 @@ "_offline_not_allowed_" = "This operation is not allowed in offline mode"; "_Upload_native_format_yes_"= "Upload in native format: yes"; "_Upload_native_format_no_" = "Upload in native format: no"; +"_terms_of_service_" = "Terms of service"; +"_terms_accept_" = "I acknowledge that I have read and agree to the above terms of service"; +"_terms_accepted_" = "Terms accepted"; // Tip "_tip_pdf_thumbnails_" = "Swipe left from the right edge of the screen to show the thumbnails."; diff --git a/iOSClient/Supporting Files/eo.lproj/Localizable.strings b/iOSClient/Supporting Files/eo.lproj/Localizable.strings index fe6aa6efaa..c333b02189 100644 Binary files a/iOSClient/Supporting Files/eo.lproj/Localizable.strings and b/iOSClient/Supporting Files/eo.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/es-419.lproj/Localizable.strings b/iOSClient/Supporting Files/es-419.lproj/Localizable.strings index ba66df6123..6054bcfc73 100644 Binary files a/iOSClient/Supporting Files/es-419.lproj/Localizable.strings and b/iOSClient/Supporting Files/es-419.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/es-AR.lproj/Localizable.strings b/iOSClient/Supporting Files/es-AR.lproj/Localizable.strings index 14f3dbd28d..7b5a211a52 100644 Binary files a/iOSClient/Supporting Files/es-AR.lproj/Localizable.strings and b/iOSClient/Supporting Files/es-AR.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/es-CL.lproj/Localizable.strings b/iOSClient/Supporting Files/es-CL.lproj/Localizable.strings index fb0cd6b23a..3c74efe1a3 100644 Binary files a/iOSClient/Supporting Files/es-CL.lproj/Localizable.strings and b/iOSClient/Supporting Files/es-CL.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/es-CO.lproj/Localizable.strings b/iOSClient/Supporting Files/es-CO.lproj/Localizable.strings index 603be8217f..fe053de533 100644 Binary files a/iOSClient/Supporting Files/es-CO.lproj/Localizable.strings and b/iOSClient/Supporting Files/es-CO.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/es-CR.lproj/Localizable.strings b/iOSClient/Supporting Files/es-CR.lproj/Localizable.strings index 6c3d7a8e11..9c2ca038f9 100644 Binary files a/iOSClient/Supporting Files/es-CR.lproj/Localizable.strings and b/iOSClient/Supporting Files/es-CR.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/es-DO.lproj/Localizable.strings b/iOSClient/Supporting Files/es-DO.lproj/Localizable.strings index b9113994ce..b3e61dc1a4 100644 Binary files a/iOSClient/Supporting Files/es-DO.lproj/Localizable.strings and b/iOSClient/Supporting Files/es-DO.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/es-EC.lproj/Localizable.strings b/iOSClient/Supporting Files/es-EC.lproj/Localizable.strings index c502232f38..48c9185641 100644 Binary files a/iOSClient/Supporting Files/es-EC.lproj/Localizable.strings and b/iOSClient/Supporting Files/es-EC.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/es-GT.lproj/Localizable.strings b/iOSClient/Supporting Files/es-GT.lproj/Localizable.strings index 19dc46a2e1..27cd6a2d08 100644 Binary files a/iOSClient/Supporting Files/es-GT.lproj/Localizable.strings and b/iOSClient/Supporting Files/es-GT.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/es-HN.lproj/Localizable.strings b/iOSClient/Supporting Files/es-HN.lproj/Localizable.strings index c5b9d9c99e..9e05f6651c 100644 Binary files a/iOSClient/Supporting Files/es-HN.lproj/Localizable.strings and b/iOSClient/Supporting Files/es-HN.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/es-MX.lproj/Localizable.strings b/iOSClient/Supporting Files/es-MX.lproj/Localizable.strings index c19ae350d4..4ceefe5ba3 100644 Binary files a/iOSClient/Supporting Files/es-MX.lproj/Localizable.strings and b/iOSClient/Supporting Files/es-MX.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/es-NI.lproj/Localizable.strings b/iOSClient/Supporting Files/es-NI.lproj/Localizable.strings index 4db67327d5..df041a8569 100644 Binary files a/iOSClient/Supporting Files/es-NI.lproj/Localizable.strings and b/iOSClient/Supporting Files/es-NI.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/es-PA.lproj/Localizable.strings b/iOSClient/Supporting Files/es-PA.lproj/Localizable.strings index 5e0d16aa94..dad7cb3da4 100644 Binary files a/iOSClient/Supporting Files/es-PA.lproj/Localizable.strings and b/iOSClient/Supporting Files/es-PA.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/es-PE.lproj/Localizable.strings b/iOSClient/Supporting Files/es-PE.lproj/Localizable.strings index 6d3a8587e7..731dd41209 100644 Binary files a/iOSClient/Supporting Files/es-PE.lproj/Localizable.strings and b/iOSClient/Supporting Files/es-PE.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/es-PR.lproj/Localizable.strings b/iOSClient/Supporting Files/es-PR.lproj/Localizable.strings index 1e56ad500d..278646b173 100644 Binary files a/iOSClient/Supporting Files/es-PR.lproj/Localizable.strings and b/iOSClient/Supporting Files/es-PR.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/es-PY.lproj/Localizable.strings b/iOSClient/Supporting Files/es-PY.lproj/Localizable.strings index 946e6621f7..5615c06361 100644 Binary files a/iOSClient/Supporting Files/es-PY.lproj/Localizable.strings and b/iOSClient/Supporting Files/es-PY.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/es-SV.lproj/Localizable.strings b/iOSClient/Supporting Files/es-SV.lproj/Localizable.strings index 005b91ef65..a055bbe0cb 100644 Binary files a/iOSClient/Supporting Files/es-SV.lproj/Localizable.strings and b/iOSClient/Supporting Files/es-SV.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/es-UY.lproj/Localizable.strings b/iOSClient/Supporting Files/es-UY.lproj/Localizable.strings index ebb0a9a1a6..09c1ac01f4 100644 Binary files a/iOSClient/Supporting Files/es-UY.lproj/Localizable.strings and b/iOSClient/Supporting Files/es-UY.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/es.lproj/Localizable.strings b/iOSClient/Supporting Files/es.lproj/Localizable.strings index f6cea99a97..6158467a41 100644 Binary files a/iOSClient/Supporting Files/es.lproj/Localizable.strings and b/iOSClient/Supporting Files/es.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/et_EE.lproj/Localizable.strings b/iOSClient/Supporting Files/et_EE.lproj/Localizable.strings index 1cb4981069..8c7d0de041 100644 Binary files a/iOSClient/Supporting Files/et_EE.lproj/Localizable.strings and b/iOSClient/Supporting Files/et_EE.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/eu.lproj/Localizable.strings b/iOSClient/Supporting Files/eu.lproj/Localizable.strings index 1ce86dd4b8..d62dd0cf19 100644 Binary files a/iOSClient/Supporting Files/eu.lproj/Localizable.strings and b/iOSClient/Supporting Files/eu.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/fa.lproj/Localizable.strings b/iOSClient/Supporting Files/fa.lproj/Localizable.strings index 09b581b0d2..2c9e589eb2 100644 Binary files a/iOSClient/Supporting Files/fa.lproj/Localizable.strings and b/iOSClient/Supporting Files/fa.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/fi-FI.lproj/Localizable.strings b/iOSClient/Supporting Files/fi-FI.lproj/Localizable.strings index 5e50b5f4ea..2a70dfb0c2 100644 Binary files a/iOSClient/Supporting Files/fi-FI.lproj/Localizable.strings and b/iOSClient/Supporting Files/fi-FI.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/fo.lproj/Localizable.strings b/iOSClient/Supporting Files/fo.lproj/Localizable.strings index e867ec0901..76816fbe0a 100644 Binary files a/iOSClient/Supporting Files/fo.lproj/Localizable.strings and b/iOSClient/Supporting Files/fo.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/fr.lproj/Localizable.strings b/iOSClient/Supporting Files/fr.lproj/Localizable.strings index df4742dd17..644536c635 100644 Binary files a/iOSClient/Supporting Files/fr.lproj/Localizable.strings and b/iOSClient/Supporting Files/fr.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/ga.lproj/Localizable.strings b/iOSClient/Supporting Files/ga.lproj/Localizable.strings index 7ce3a1ba9e..78c2534735 100644 Binary files a/iOSClient/Supporting Files/ga.lproj/Localizable.strings and b/iOSClient/Supporting Files/ga.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/gd.lproj/Localizable.strings b/iOSClient/Supporting Files/gd.lproj/Localizable.strings index d286147e49..f03a31aaed 100644 Binary files a/iOSClient/Supporting Files/gd.lproj/Localizable.strings and b/iOSClient/Supporting Files/gd.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/gl.lproj/Localizable.strings b/iOSClient/Supporting Files/gl.lproj/Localizable.strings index aa363a7cc4..14742ed4ac 100644 Binary files a/iOSClient/Supporting Files/gl.lproj/Localizable.strings and b/iOSClient/Supporting Files/gl.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/he.lproj/Localizable.strings b/iOSClient/Supporting Files/he.lproj/Localizable.strings index 5fd82065b8..106c87aae9 100644 Binary files a/iOSClient/Supporting Files/he.lproj/Localizable.strings and b/iOSClient/Supporting Files/he.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/hi_IN.lproj/Localizable.strings b/iOSClient/Supporting Files/hi_IN.lproj/Localizable.strings index 8d2019fe8a..0145ef24a8 100644 Binary files a/iOSClient/Supporting Files/hi_IN.lproj/Localizable.strings and b/iOSClient/Supporting Files/hi_IN.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/hr.lproj/Localizable.strings b/iOSClient/Supporting Files/hr.lproj/Localizable.strings index 402fe2dc4b..af0a46ece1 100644 Binary files a/iOSClient/Supporting Files/hr.lproj/Localizable.strings and b/iOSClient/Supporting Files/hr.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/hsb.lproj/Localizable.strings b/iOSClient/Supporting Files/hsb.lproj/Localizable.strings index 03069e94ed..4a4bf2133e 100644 Binary files a/iOSClient/Supporting Files/hsb.lproj/Localizable.strings and b/iOSClient/Supporting Files/hsb.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/hu.lproj/Localizable.strings b/iOSClient/Supporting Files/hu.lproj/Localizable.strings index ec6e2f0c19..b836b3b412 100644 Binary files a/iOSClient/Supporting Files/hu.lproj/Localizable.strings and b/iOSClient/Supporting Files/hu.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/hy.lproj/Localizable.strings b/iOSClient/Supporting Files/hy.lproj/Localizable.strings index cbda3ab1f1..0f8e662829 100644 Binary files a/iOSClient/Supporting Files/hy.lproj/Localizable.strings and b/iOSClient/Supporting Files/hy.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/ia.lproj/Localizable.strings b/iOSClient/Supporting Files/ia.lproj/Localizable.strings index d18e850f0f..87f40a13d3 100644 Binary files a/iOSClient/Supporting Files/ia.lproj/Localizable.strings and b/iOSClient/Supporting Files/ia.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/id.lproj/Localizable.strings b/iOSClient/Supporting Files/id.lproj/Localizable.strings index 924aa3f252..0700e8928a 100644 Binary files a/iOSClient/Supporting Files/id.lproj/Localizable.strings and b/iOSClient/Supporting Files/id.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/ig.lproj/Localizable.strings b/iOSClient/Supporting Files/ig.lproj/Localizable.strings index 04a1418333..a76e22b03c 100644 Binary files a/iOSClient/Supporting Files/ig.lproj/Localizable.strings and b/iOSClient/Supporting Files/ig.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/is.lproj/Localizable.strings b/iOSClient/Supporting Files/is.lproj/Localizable.strings index 1895f491d7..56b481bc04 100644 Binary files a/iOSClient/Supporting Files/is.lproj/Localizable.strings and b/iOSClient/Supporting Files/is.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/it.lproj/Localizable.strings b/iOSClient/Supporting Files/it.lproj/Localizable.strings index 73b465f98c..5d1d0e17a6 100644 Binary files a/iOSClient/Supporting Files/it.lproj/Localizable.strings and b/iOSClient/Supporting Files/it.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/ja-JP.lproj/Localizable.strings b/iOSClient/Supporting Files/ja-JP.lproj/Localizable.strings index 8070e396d4..9d663bb5c1 100644 Binary files a/iOSClient/Supporting Files/ja-JP.lproj/Localizable.strings and b/iOSClient/Supporting Files/ja-JP.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/ka-GE.lproj/Localizable.strings b/iOSClient/Supporting Files/ka-GE.lproj/Localizable.strings index e684cdb755..970a16a164 100644 Binary files a/iOSClient/Supporting Files/ka-GE.lproj/Localizable.strings and b/iOSClient/Supporting Files/ka-GE.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/ka.lproj/Localizable.strings b/iOSClient/Supporting Files/ka.lproj/Localizable.strings index 06eba41b20..30b68ceaae 100644 Binary files a/iOSClient/Supporting Files/ka.lproj/Localizable.strings and b/iOSClient/Supporting Files/ka.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/kab.lproj/Localizable.strings b/iOSClient/Supporting Files/kab.lproj/Localizable.strings index 7f56f993f1..c1f5dc6157 100644 Binary files a/iOSClient/Supporting Files/kab.lproj/Localizable.strings and b/iOSClient/Supporting Files/kab.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/km.lproj/Localizable.strings b/iOSClient/Supporting Files/km.lproj/Localizable.strings index e40fb1183e..b025424247 100644 Binary files a/iOSClient/Supporting Files/km.lproj/Localizable.strings and b/iOSClient/Supporting Files/km.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/kn.lproj/Localizable.strings b/iOSClient/Supporting Files/kn.lproj/Localizable.strings index d4241e0bdf..d7b39b18b7 100644 Binary files a/iOSClient/Supporting Files/kn.lproj/Localizable.strings and b/iOSClient/Supporting Files/kn.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/ko.lproj/Localizable.strings b/iOSClient/Supporting Files/ko.lproj/Localizable.strings index f15d3967e7..c6efb99dcd 100644 Binary files a/iOSClient/Supporting Files/ko.lproj/Localizable.strings and b/iOSClient/Supporting Files/ko.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/la.lproj/Localizable.strings b/iOSClient/Supporting Files/la.lproj/Localizable.strings index cb28d0f7c1..f3972d4f03 100644 Binary files a/iOSClient/Supporting Files/la.lproj/Localizable.strings and b/iOSClient/Supporting Files/la.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/lb.lproj/Localizable.strings b/iOSClient/Supporting Files/lb.lproj/Localizable.strings index fc8179a96d..f6750cf105 100644 Binary files a/iOSClient/Supporting Files/lb.lproj/Localizable.strings and b/iOSClient/Supporting Files/lb.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/lo.lproj/Localizable.strings b/iOSClient/Supporting Files/lo.lproj/Localizable.strings index ee7cfb8e7d..5be68fdb25 100644 Binary files a/iOSClient/Supporting Files/lo.lproj/Localizable.strings and b/iOSClient/Supporting Files/lo.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/lt_LT.lproj/Localizable.strings b/iOSClient/Supporting Files/lt_LT.lproj/Localizable.strings index e99648cbc7..cb327227e8 100644 Binary files a/iOSClient/Supporting Files/lt_LT.lproj/Localizable.strings and b/iOSClient/Supporting Files/lt_LT.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/lv.lproj/Localizable.strings b/iOSClient/Supporting Files/lv.lproj/Localizable.strings index 05ab70a3eb..973b3768a8 100644 Binary files a/iOSClient/Supporting Files/lv.lproj/Localizable.strings and b/iOSClient/Supporting Files/lv.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/mk.lproj/Localizable.strings b/iOSClient/Supporting Files/mk.lproj/Localizable.strings index fbb883ae61..fc159eeeed 100644 Binary files a/iOSClient/Supporting Files/mk.lproj/Localizable.strings and b/iOSClient/Supporting Files/mk.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/mn.lproj/Localizable.strings b/iOSClient/Supporting Files/mn.lproj/Localizable.strings index 7df2f179d5..2ee3a4d8ac 100644 Binary files a/iOSClient/Supporting Files/mn.lproj/Localizable.strings and b/iOSClient/Supporting Files/mn.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/mr.lproj/Localizable.strings b/iOSClient/Supporting Files/mr.lproj/Localizable.strings index aa872d86be..77e9f771b9 100644 Binary files a/iOSClient/Supporting Files/mr.lproj/Localizable.strings and b/iOSClient/Supporting Files/mr.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/ms_MY.lproj/Localizable.strings b/iOSClient/Supporting Files/ms_MY.lproj/Localizable.strings index 14d7cf185e..26fd9207f6 100644 Binary files a/iOSClient/Supporting Files/ms_MY.lproj/Localizable.strings and b/iOSClient/Supporting Files/ms_MY.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/my.lproj/Localizable.strings b/iOSClient/Supporting Files/my.lproj/Localizable.strings index a228a9d603..eb01f5cea2 100644 Binary files a/iOSClient/Supporting Files/my.lproj/Localizable.strings and b/iOSClient/Supporting Files/my.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/nb-NO.lproj/Localizable.strings b/iOSClient/Supporting Files/nb-NO.lproj/Localizable.strings index 07858b84b9..a8498df64f 100644 Binary files a/iOSClient/Supporting Files/nb-NO.lproj/Localizable.strings and b/iOSClient/Supporting Files/nb-NO.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/ne.lproj/Localizable.strings b/iOSClient/Supporting Files/ne.lproj/Localizable.strings index 73d6719126..36e104e211 100644 Binary files a/iOSClient/Supporting Files/ne.lproj/Localizable.strings and b/iOSClient/Supporting Files/ne.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/nl.lproj/Localizable.strings b/iOSClient/Supporting Files/nl.lproj/Localizable.strings index a5a9333a01..c9046dc3cf 100644 Binary files a/iOSClient/Supporting Files/nl.lproj/Localizable.strings and b/iOSClient/Supporting Files/nl.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/nn_NO.lproj/Localizable.strings b/iOSClient/Supporting Files/nn_NO.lproj/Localizable.strings index 53086c348c..9e4eed9d6e 100644 Binary files a/iOSClient/Supporting Files/nn_NO.lproj/Localizable.strings and b/iOSClient/Supporting Files/nn_NO.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/oc.lproj/Localizable.strings b/iOSClient/Supporting Files/oc.lproj/Localizable.strings index 412977e2b2..da36ddf30c 100644 Binary files a/iOSClient/Supporting Files/oc.lproj/Localizable.strings and b/iOSClient/Supporting Files/oc.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/pl.lproj/Localizable.strings b/iOSClient/Supporting Files/pl.lproj/Localizable.strings index 7d71c86b31..5482a22297 100644 Binary files a/iOSClient/Supporting Files/pl.lproj/Localizable.strings and b/iOSClient/Supporting Files/pl.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/ps.lproj/Localizable.strings b/iOSClient/Supporting Files/ps.lproj/Localizable.strings index a498f5c03e..4ef23dff41 100644 Binary files a/iOSClient/Supporting Files/ps.lproj/Localizable.strings and b/iOSClient/Supporting Files/ps.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/pt-BR.lproj/Localizable.strings b/iOSClient/Supporting Files/pt-BR.lproj/Localizable.strings index 6c90f773e8..f9cb6b1bd6 100644 Binary files a/iOSClient/Supporting Files/pt-BR.lproj/Localizable.strings and b/iOSClient/Supporting Files/pt-BR.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/pt-PT.lproj/Localizable.strings b/iOSClient/Supporting Files/pt-PT.lproj/Localizable.strings index 4aa4af87e9..89ae56b689 100644 Binary files a/iOSClient/Supporting Files/pt-PT.lproj/Localizable.strings and b/iOSClient/Supporting Files/pt-PT.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/ro.lproj/Localizable.strings b/iOSClient/Supporting Files/ro.lproj/Localizable.strings index ea0c23a35f..24bf6b7809 100644 Binary files a/iOSClient/Supporting Files/ro.lproj/Localizable.strings and b/iOSClient/Supporting Files/ro.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/ru.lproj/Localizable.strings b/iOSClient/Supporting Files/ru.lproj/Localizable.strings index ba48653cf7..fa3560f72d 100644 Binary files a/iOSClient/Supporting Files/ru.lproj/Localizable.strings and b/iOSClient/Supporting Files/ru.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/sc.lproj/Localizable.strings b/iOSClient/Supporting Files/sc.lproj/Localizable.strings index ce2aae907d..e469390f0f 100644 Binary files a/iOSClient/Supporting Files/sc.lproj/Localizable.strings and b/iOSClient/Supporting Files/sc.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/si.lproj/Localizable.strings b/iOSClient/Supporting Files/si.lproj/Localizable.strings index d499c373f0..d527ee6115 100644 Binary files a/iOSClient/Supporting Files/si.lproj/Localizable.strings and b/iOSClient/Supporting Files/si.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/sk-SK.lproj/Localizable.strings b/iOSClient/Supporting Files/sk-SK.lproj/Localizable.strings index e933f6030a..e31e4b2595 100644 Binary files a/iOSClient/Supporting Files/sk-SK.lproj/Localizable.strings and b/iOSClient/Supporting Files/sk-SK.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/sl.lproj/Localizable.strings b/iOSClient/Supporting Files/sl.lproj/Localizable.strings index 54c231a017..2af5563015 100644 Binary files a/iOSClient/Supporting Files/sl.lproj/Localizable.strings and b/iOSClient/Supporting Files/sl.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/sq.lproj/Localizable.strings b/iOSClient/Supporting Files/sq.lproj/Localizable.strings index f3b12dc2c1..f64cc8bc78 100644 Binary files a/iOSClient/Supporting Files/sq.lproj/Localizable.strings and b/iOSClient/Supporting Files/sq.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/sr.lproj/Localizable.strings b/iOSClient/Supporting Files/sr.lproj/Localizable.strings index 0156da769e..2d40d5843c 100644 Binary files a/iOSClient/Supporting Files/sr.lproj/Localizable.strings and b/iOSClient/Supporting Files/sr.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/sr@latin.lproj/Localizable.strings b/iOSClient/Supporting Files/sr@latin.lproj/Localizable.strings index 6f1fdba567..0f743833e4 100644 Binary files a/iOSClient/Supporting Files/sr@latin.lproj/Localizable.strings and b/iOSClient/Supporting Files/sr@latin.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/sv.lproj/Localizable.strings b/iOSClient/Supporting Files/sv.lproj/Localizable.strings index b389b70722..275b1173af 100644 Binary files a/iOSClient/Supporting Files/sv.lproj/Localizable.strings and b/iOSClient/Supporting Files/sv.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/sw.lproj/Localizable.strings b/iOSClient/Supporting Files/sw.lproj/Localizable.strings index 8d2019fe8a..0145ef24a8 100644 Binary files a/iOSClient/Supporting Files/sw.lproj/Localizable.strings and b/iOSClient/Supporting Files/sw.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/ta.lproj/Localizable.strings b/iOSClient/Supporting Files/ta.lproj/Localizable.strings index cace197399..e29bd7e988 100644 Binary files a/iOSClient/Supporting Files/ta.lproj/Localizable.strings and b/iOSClient/Supporting Files/ta.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/th_TH.lproj/Localizable.strings b/iOSClient/Supporting Files/th_TH.lproj/Localizable.strings index 367a852135..4bb9735390 100644 Binary files a/iOSClient/Supporting Files/th_TH.lproj/Localizable.strings and b/iOSClient/Supporting Files/th_TH.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/tk.lproj/Localizable.strings b/iOSClient/Supporting Files/tk.lproj/Localizable.strings index 267d20c4e9..abd86b353b 100644 Binary files a/iOSClient/Supporting Files/tk.lproj/Localizable.strings and b/iOSClient/Supporting Files/tk.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/tr.lproj/Localizable.strings b/iOSClient/Supporting Files/tr.lproj/Localizable.strings index a983fed6e5..8497573928 100644 Binary files a/iOSClient/Supporting Files/tr.lproj/Localizable.strings and b/iOSClient/Supporting Files/tr.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/ug.lproj/Localizable.strings b/iOSClient/Supporting Files/ug.lproj/Localizable.strings index 241859f1a4..bf887b7211 100644 Binary files a/iOSClient/Supporting Files/ug.lproj/Localizable.strings and b/iOSClient/Supporting Files/ug.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/uk.lproj/Localizable.strings b/iOSClient/Supporting Files/uk.lproj/Localizable.strings index b4cb84480a..44142d39d7 100644 Binary files a/iOSClient/Supporting Files/uk.lproj/Localizable.strings and b/iOSClient/Supporting Files/uk.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/ur_PK.lproj/Localizable.strings b/iOSClient/Supporting Files/ur_PK.lproj/Localizable.strings index 90fd8e3b4a..45d936b9ab 100644 Binary files a/iOSClient/Supporting Files/ur_PK.lproj/Localizable.strings and b/iOSClient/Supporting Files/ur_PK.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/uz.lproj/Localizable.strings b/iOSClient/Supporting Files/uz.lproj/Localizable.strings index 8d2019fe8a..0145ef24a8 100644 Binary files a/iOSClient/Supporting Files/uz.lproj/Localizable.strings and b/iOSClient/Supporting Files/uz.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/vi.lproj/Localizable.strings b/iOSClient/Supporting Files/vi.lproj/Localizable.strings index df41d2b09f..3e36245b40 100644 Binary files a/iOSClient/Supporting Files/vi.lproj/Localizable.strings and b/iOSClient/Supporting Files/vi.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/zh-Hans.lproj/Localizable.strings b/iOSClient/Supporting Files/zh-Hans.lproj/Localizable.strings index 927d2dddda..1da9cb48ca 100644 Binary files a/iOSClient/Supporting Files/zh-Hans.lproj/Localizable.strings and b/iOSClient/Supporting Files/zh-Hans.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/zh-Hant-TW.lproj/Localizable.strings b/iOSClient/Supporting Files/zh-Hant-TW.lproj/Localizable.strings index 9e521f4032..ad717e5862 100644 Binary files a/iOSClient/Supporting Files/zh-Hant-TW.lproj/Localizable.strings and b/iOSClient/Supporting Files/zh-Hant-TW.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/zh_HK.lproj/Localizable.strings b/iOSClient/Supporting Files/zh_HK.lproj/Localizable.strings index c489915e41..b70e3d3c43 100644 Binary files a/iOSClient/Supporting Files/zh_HK.lproj/Localizable.strings and b/iOSClient/Supporting Files/zh_HK.lproj/Localizable.strings differ diff --git a/iOSClient/Supporting Files/zu_ZA.lproj/Localizable.strings b/iOSClient/Supporting Files/zu_ZA.lproj/Localizable.strings index 8d2019fe8a..0145ef24a8 100644 Binary files a/iOSClient/Supporting Files/zu_ZA.lproj/Localizable.strings and b/iOSClient/Supporting Files/zu_ZA.lproj/Localizable.strings differ diff --git a/iOSClient/Terms of service/NCTermOfServiceModel.swift b/iOSClient/Terms of service/NCTermOfServiceModel.swift new file mode 100644 index 0000000000..f6ed00579f --- /dev/null +++ b/iOSClient/Terms of service/NCTermOfServiceModel.swift @@ -0,0 +1,70 @@ +// SPDX-FileCopyrightText: Nextcloud GmbH +// SPDX-FileCopyrightText: 2024 Marino Faggiana +// SPDX-License-Identifier: GPL-3.0-or-later + +import Foundation +import NextcloudKit + +/// A model that allows the user to configure the account +class NCTermOfServiceModel: ObservableObject { + /// Root View Controller + var controller: NCMainTabBarController? + /// Set true for dismiss the view + @Published var dismissView = false + // Data + @Published var languages: [String: String] = [:] + @Published var terms: [String: String] = [:] + @Published var termsId: [String: Int] = [:] + @Published var hasUserSigned: Bool = false + + /// Initialization code + init(controller: NCMainTabBarController?, tos: NKTermsOfService?) { + self.controller = controller + + if let terms = tos?.getTerms() { + for term in terms { + self.terms[term.languageCode] = term.body + self.termsId[term.languageCode] = term.id + } + } else { + languages = ["en": "English", "de": "Deutsch", "it": "Italiano"] + } + + if let languages = tos?.getLanguages() { + for language in languages { + if self.terms[language.key] != nil { + self.languages[language.key] = language.value + } + } + } else { + terms = [ + "en": "These are the Terms of Service.", + "de": "Dies sind die Allgemeinen Geschäftsbedingungen.", + "it": "Questi sono i Termini di servizio." + ] + } + + if let hasUserSigned = tos?.hasUserSigned() { + self.hasUserSigned = hasUserSigned + } + } + + func signTermsOfService(termId: Int?) { + guard let termId, + let controller + else { + return + } + + NextcloudKit.shared.signTermsOfService(termId: "\(termId)", account: controller.account) { _, _, error in + if error == .success { + NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterGetServerData) + self.dismissView = true + } else { + NCContentPresenter().showError(error: error) + } + } + } + + deinit { } +} diff --git a/iOSClient/Terms of service/NCTermOfServiceView.swift b/iOSClient/Terms of service/NCTermOfServiceView.swift new file mode 100644 index 0000000000..9c3e6dcbb7 --- /dev/null +++ b/iOSClient/Terms of service/NCTermOfServiceView.swift @@ -0,0 +1,79 @@ +// SPDX-FileCopyrightText: Nextcloud GmbH +// SPDX-FileCopyrightText: 2024 Marino Faggiana +// SPDX-License-Identifier: GPL-3.0-or-later + +import SwiftUI + +struct NCTermOfServiceModelView: View { + @State private var selectedLanguage = Locale.preferredLanguages.first?.components(separatedBy: "-").first ?? "en" + @State private var termsText = "Loading terms..." + @ObservedObject var model: NCTermOfServiceModel + + @Environment(\.presentationMode) var presentationMode + + var body: some View { + VStack { + HStack { + Text(NSLocalizedString("_terms_of_service_", comment: "Terms of Service")) + .font(.headline) + .frame(maxWidth: .infinity, alignment: .leading) + + Picker("Select Language", selection: $selectedLanguage) { + ForEach(model.languages.keys.sorted(), id: \.self) { key in + Text(model.languages[key] ?? "").tag(key) + } + } + .pickerStyle(MenuPickerStyle()) + .frame(maxWidth: .infinity, alignment: .trailing) + .onChange(of: selectedLanguage) { newLanguage in + if let terms = model.terms[newLanguage] { + termsText = terms + } else { + selectedLanguage = model.languages.first?.key ?? "en" + termsText = model.terms[selectedLanguage] ?? "Terms not available in selected language." + } + } + } + .padding(.horizontal) + + ScrollView { + Text(termsText) + .font(.body) + .foregroundColor(.primary) + .frame(maxWidth: .infinity) + .padding(.horizontal) + } + .padding(.top) + + Button(action: { + model.signTermsOfService(termId: model.termsId[selectedLanguage]) + }) { + Text(model.hasUserSigned ? NSLocalizedString("_terms_accepted_", comment: "Accepted terms") : NSLocalizedString("_terms_accept_", comment: "Accept terms")) + .foregroundColor(.white) + .padding() + .background(model.hasUserSigned ? Color.green : Color.blue) + .cornerRadius(10) + .padding(.bottom) + } + .disabled(model.hasUserSigned) + } + .padding() + .onAppear { + if let item = model.terms[selectedLanguage] { + termsText = item + } else { + selectedLanguage = model.languages.first?.key ?? "en" + termsText = model.terms[selectedLanguage] ?? "Terms not available in selected language." + } + } + .onReceive(model.$dismissView) { newValue in + if newValue { + presentationMode.wrappedValue.dismiss() + } + } + } +} + +#Preview { + NCTermOfServiceModelView(model: NCTermOfServiceModel(controller: nil, tos: nil)) +}