From 853f9d2655762bc5a6a9bbef58adf6fba3fda553 Mon Sep 17 00:00:00 2001 From: cpilaszewicz <khutbvdw> Date: Mon, 9 Mar 2020 15:32:45 +0100 Subject: [PATCH] Extract method to simplify reading --- enzevalos_iphone/AuthenticationScreen.swift | 6 +++++- enzevalos_iphone/AuthenticationViewModel.swift | 6 ++---- enzevalos_iphone/Onboarding.swift | 2 +- enzevalos_iphone/de.lproj/Localizable.strings | 2 ++ enzevalos_iphone/en.lproj/Localizable.strings | 1 + 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/enzevalos_iphone/AuthenticationScreen.swift b/enzevalos_iphone/AuthenticationScreen.swift index 6232bc3d..17d6fcfe 100644 --- a/enzevalos_iphone/AuthenticationScreen.swift +++ b/enzevalos_iphone/AuthenticationScreen.swift @@ -86,7 +86,7 @@ struct AuthenticationScreen: View { }.padding() //TODO: once SWIFTUI supports optionals improve this if statement - if self.viewModel.errorMessage != nil && !self.viewModel.errorMessage!.isEmpty { + if shouldDisplayErrorMessage() { VStack { Text(self.viewModel.errorMessage!) .foregroundColor(Color.white) @@ -96,5 +96,9 @@ struct AuthenticationScreen: View { } } } + + func shouldDisplayErrorMessage() -> Bool { + return (self.viewModel.errorMessage != nil) && (!self.viewModel.errorMessage!.isEmpty) + } } diff --git a/enzevalos_iphone/AuthenticationViewModel.swift b/enzevalos_iphone/AuthenticationViewModel.swift index ae275610..ce0edb1b 100644 --- a/enzevalos_iphone/AuthenticationViewModel.swift +++ b/enzevalos_iphone/AuthenticationViewModel.swift @@ -56,7 +56,7 @@ class AuthenticationViewModel : ObservableObject { let timeoutDelay: DispatchTimeInterval = DispatchTimeInterval.seconds(10) let result = self.dispatchGroup.wait(timeout: DispatchTime.now() + timeoutDelay) DispatchQueue.main.async { - self.timeoutOccured(timeoutResult: result) + self.onTimeout(timeoutResult: result) } } } @@ -156,7 +156,7 @@ class AuthenticationViewModel : ObservableObject { errorMessage = NSLocalizedString(MailServerConnectionError.TimeoutError.localizedUIBodyString, comment: "") } - func timeoutOccured(timeoutResult: DispatchTimeoutResult) { + func onTimeout(timeoutResult: DispatchTimeoutResult) { imapCallback?.callback = nil smtpCallback?.callback = nil if timeoutResult == .success { @@ -176,7 +176,6 @@ class AuthenticationViewModel : ObservableObject { imapConfigurationSuccessful = true } else { imapConfigurationSuccessful = false - authenticationFailed() } dispatchGroup.leave() } @@ -187,7 +186,6 @@ class AuthenticationViewModel : ObservableObject { smtpConfigurationSuccessful = true } else { smtpConfigurationSuccessful = false - authenticationFailed() } dispatchGroup.leave() return diff --git a/enzevalos_iphone/Onboarding.swift b/enzevalos_iphone/Onboarding.swift index 379dea0a..09ae1c25 100644 --- a/enzevalos_iphone/Onboarding.swift +++ b/enzevalos_iphone/Onboarding.swift @@ -186,7 +186,7 @@ class Onboarding: NSObject { keyboardToolbar.sizeToFit() keyboardToolbar.barTintColor = defaultColor keyboardToolbar.backgroundColor = defaultColor - let googleBarButton = UIBarButtonItem(title: "Login with Google", style: .plain, target: self, action: #selector(startGoogleOauth)) + let googleBarButton = UIBarButtonItem(title: "Login with Google", style: .plain, target: self, action: #selector(oauth)) googleBarButton.tintColor = .orange googleButton = googleBarButton let flexBarButton = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil) diff --git a/enzevalos_iphone/de.lproj/Localizable.strings b/enzevalos_iphone/de.lproj/Localizable.strings index 0eda774b..fd7241bb 100644 --- a/enzevalos_iphone/de.lproj/Localizable.strings +++ b/enzevalos_iphone/de.lproj/Localizable.strings @@ -286,6 +286,8 @@ "MailServerError.Default.Body" = "Es konnte keine Verbindung zum Server hergestellt werden.\n Bitte überprüfe das Password, den Accountname und die Serverkonfiguration (IMAP/SMTP). Die Serverkonfiguration kann mit der Serverkonfiguration auf der Provider-Webseite verglichen werden. In manchen Fällen muss der Zugriff mittels IMAP/SMTP in den Accounteinstellungen erst freigeschaltet werden."; "MailServerError.IMAP.Body" = "Es konnte keine Verbindung zum Server hergestellt werden.\n Bitte überprüfe die IMAP Serverkonfiguration."; "MailServerError.SMTP.Body" = "Es konnte keine Verbindung zum Server hergestellt werden.\n Bitte überprüfe die SMTP Serverkonfiguration."; +"MailServerError.Timeout.Body" = "Der Server hat nicht rechtzeitig geantwortet"; + "Read.Import.Secret.Title" = "Neuer geheimer Schlüssel"; "Read.Import.Secret.Body.PW" = "gib zum Importieren das Passwort für den geheimen Schlüssel mit der ID %@ ein."; diff --git a/enzevalos_iphone/en.lproj/Localizable.strings b/enzevalos_iphone/en.lproj/Localizable.strings index e31af588..17e74684 100644 --- a/enzevalos_iphone/en.lproj/Localizable.strings +++ b/enzevalos_iphone/en.lproj/Localizable.strings @@ -256,6 +256,7 @@ "MailServerError.Default.Body" = "Couldn't connect to server.\n Please, check your account name, password and server configuration. You can also compare the server configuration with the configuration listed on the website of your provider. In some cases, you have to activate the IMAP/SMTP connection in your account settings."; "MailServerError.IMAP.Body" = "Couldn't connect to server.\n Please check your IMAP server configuration."; "MailServerError.SMTP.Body" = "Couldn't connect to server.\n Please check your SMTP server configuration."; +"MailServerError.Timeout.Body" = "Server didn't answer in time"; "Read.Import.Secret.Title" = "New secret"; "Read.Import.Secret.Body.PW" = "Please, enter the password to import the new secret key with the id: %@."; -- GitLab