From 386efd632bf20d7a7a4175f724d1caac9853a7a2 Mon Sep 17 00:00:00 2001 From: Flowinho Date: Mon, 9 Mar 2020 20:15:04 +0100 Subject: [PATCH 1/3] Changing UIContentType from username to email adress Add responder switch to streamline login flow This change achieves two things: - When the user presses Return and the email field is selected, the cursor now switches to the password field (as expected by the user). - It enables iOS to pick up login and password field and enables password autofill. --- iOS/Account/Account.storyboard | 4 ++-- iOS/Account/FeedWranglerAccountViewController.swift | 6 +++++- iOS/Account/FeedbinAccountViewController.swift | 6 +++++- iOS/Settings/Settings.storyboard | 4 ++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/iOS/Account/Account.storyboard b/iOS/Account/Account.storyboard index 9c4011f8f..52982af01 100644 --- a/iOS/Account/Account.storyboard +++ b/iOS/Account/Account.storyboard @@ -1,8 +1,8 @@ - + - + diff --git a/iOS/Account/FeedWranglerAccountViewController.swift b/iOS/Account/FeedWranglerAccountViewController.swift index a5356d09a..eeb2e8551 100644 --- a/iOS/Account/FeedWranglerAccountViewController.swift +++ b/iOS/Account/FeedWranglerAccountViewController.swift @@ -166,7 +166,11 @@ class FeedWranglerAccountViewController: UITableViewController { extension FeedWranglerAccountViewController: UITextFieldDelegate { func textFieldShouldReturn(_ textField: UITextField) -> Bool { - textField.resignFirstResponder() + if textField == emailTextField { + passwordTextField.becomeFirstResponder() + } else { + textField.resignFirstResponder() + } return true } diff --git a/iOS/Account/FeedbinAccountViewController.swift b/iOS/Account/FeedbinAccountViewController.swift index 695ee2a1c..a0d4ea759 100644 --- a/iOS/Account/FeedbinAccountViewController.swift +++ b/iOS/Account/FeedbinAccountViewController.swift @@ -166,7 +166,11 @@ class FeedbinAccountViewController: UITableViewController { extension FeedbinAccountViewController: UITextFieldDelegate { func textFieldShouldReturn(_ textField: UITextField) -> Bool { - textField.resignFirstResponder() + if textField == emailTextField { + passwordTextField.becomeFirstResponder() + } else { + textField.resignFirstResponder() + } return true } diff --git a/iOS/Settings/Settings.storyboard b/iOS/Settings/Settings.storyboard index 97235c536..b3f38b2a5 100644 --- a/iOS/Settings/Settings.storyboard +++ b/iOS/Settings/Settings.storyboard @@ -1,8 +1,8 @@ - + - + From 66fae15f645d7dfef90a3a5c427139aebb55d5e6 Mon Sep 17 00:00:00 2001 From: Flowinho Date: Wed, 11 Mar 2020 13:42:25 +0100 Subject: [PATCH 2/3] Remove redundant code to lessen LOC - Less code - less bugs. - Also resign the first responder when the user presses the action button --- .../FeedWranglerAccountViewController.swift | 38 ++++++++---------- .../FeedbinAccountViewController.swift | 39 ++++++++----------- 2 files changed, 32 insertions(+), 45 deletions(-) diff --git a/iOS/Account/FeedWranglerAccountViewController.swift b/iOS/Account/FeedWranglerAccountViewController.swift index eeb2e8551..a879a5aba 100644 --- a/iOS/Account/FeedWranglerAccountViewController.swift +++ b/iOS/Account/FeedWranglerAccountViewController.swift @@ -78,17 +78,17 @@ class FeedWranglerAccountViewController: UITableViewController { showError(NSLocalizedString("Username & password required.", comment: "Credentials Error")) return } - - startAnimatingActivityIndicator() - disableNavigation() + resignFirstResponder() + toggleActivityIndicatorAnimation(visible: true) + setNavigationEnabled(to: false) // When you fill in the email address via auto-complete it adds extra whitespace let trimmedEmail = email.trimmingCharacters(in: .whitespaces) let credentials = Credentials(type: .feedWranglerBasic, username: trimmedEmail, secret: password) Account.validateCredentials(type: .feedWrangler, credentials: credentials) { result in - self.stopAnimtatingActivityIndicator() - self.enableNavigation() + self.toggleActivityIndicatorAnimation(visible: false) + self.setNavigationEnabled(to: true) switch result { case .success(let validatedCredentials): @@ -138,27 +138,21 @@ class FeedWranglerAccountViewController: UITableViewController { } private func showError(_ message: String) { - presentError(title: "Error", message: message) + presentError(title: NSLocalizedString("Error", comment: "Credentials Error"), message: message) } - private func enableNavigation() { - self.cancelBarButtonItem.isEnabled = true - self.actionButton.isEnabled = true + private func setNavigationEnabled(to value:Bool){ + cancelBarButtonItem.isEnabled = value + actionButton.isEnabled = value } - private func disableNavigation() { - cancelBarButtonItem.isEnabled = false - actionButton.isEnabled = false - } - - private func startAnimatingActivityIndicator() { - activityIndicator.isHidden = false - activityIndicator.startAnimating() - } - - private func stopAnimtatingActivityIndicator() { - self.activityIndicator.isHidden = true - self.activityIndicator.stopAnimating() + private func toggleActivityIndicatorAnimation(visible value: Bool){ + activityIndicator.isHidden = !value + if value { + activityIndicator.startAnimating() + } else { + activityIndicator.stopAnimating() + } } } diff --git a/iOS/Account/FeedbinAccountViewController.swift b/iOS/Account/FeedbinAccountViewController.swift index a0d4ea759..e47d9aaef 100644 --- a/iOS/Account/FeedbinAccountViewController.swift +++ b/iOS/Account/FeedbinAccountViewController.swift @@ -79,17 +79,16 @@ class FeedbinAccountViewController: UITableViewController { showError(NSLocalizedString("Username & password required.", comment: "Credentials Error")) return } - - startAnimatingActivityIndicator() - disableNavigation() + resignFirstResponder() + toggleActivityIndicatorAnimation(visible: true) + setNavigationEnabled(to: false) // When you fill in the email address via auto-complete it adds extra whitespace let trimmedEmail = email.trimmingCharacters(in: .whitespaces) let credentials = Credentials(type: .basic, username: trimmedEmail, secret: password) Account.validateCredentials(type: .feedbin, credentials: credentials) { result in - - self.stopAnimtatingActivityIndicator() - self.enableNavigation() + self.toggleActivityIndicatorAnimation(visible: false) + self.setNavigationEnabled(to: true) switch result { case .success(let credentials): @@ -138,27 +137,21 @@ class FeedbinAccountViewController: UITableViewController { } private func showError(_ message: String) { - presentError(title: "Error", message: message) + presentError(title: NSLocalizedString("Error", comment: "Credentials Error"), message: message) } - private func enableNavigation() { - self.cancelBarButtonItem.isEnabled = true - self.actionButton.isEnabled = true + private func setNavigationEnabled(to value:Bool){ + cancelBarButtonItem.isEnabled = value + actionButton.isEnabled = value } - private func disableNavigation() { - cancelBarButtonItem.isEnabled = false - actionButton.isEnabled = false - } - - private func startAnimatingActivityIndicator() { - activityIndicator.isHidden = false - activityIndicator.startAnimating() - } - - private func stopAnimtatingActivityIndicator() { - self.activityIndicator.isHidden = true - self.activityIndicator.stopAnimating() + private func toggleActivityIndicatorAnimation(visible value: Bool){ + activityIndicator.isHidden = !value + if value { + activityIndicator.startAnimating() + } else { + activityIndicator.stopAnimating() + } } } From b178fe93afd199f018b8e8eaea20ce7ab851bc94 Mon Sep 17 00:00:00 2001 From: Flowinho Date: Wed, 11 Mar 2020 14:02:06 +0100 Subject: [PATCH 3/3] Call action on return if password was added This is an obvious change. --- iOS/Account/FeedWranglerAccountViewController.swift | 1 + iOS/Account/FeedbinAccountViewController.swift | 1 + 2 files changed, 2 insertions(+) diff --git a/iOS/Account/FeedWranglerAccountViewController.swift b/iOS/Account/FeedWranglerAccountViewController.swift index a879a5aba..b6c297df8 100644 --- a/iOS/Account/FeedWranglerAccountViewController.swift +++ b/iOS/Account/FeedWranglerAccountViewController.swift @@ -164,6 +164,7 @@ extension FeedWranglerAccountViewController: UITextFieldDelegate { passwordTextField.becomeFirstResponder() } else { textField.resignFirstResponder() + action(self) } return true } diff --git a/iOS/Account/FeedbinAccountViewController.swift b/iOS/Account/FeedbinAccountViewController.swift index e47d9aaef..df6110b64 100644 --- a/iOS/Account/FeedbinAccountViewController.swift +++ b/iOS/Account/FeedbinAccountViewController.swift @@ -163,6 +163,7 @@ extension FeedbinAccountViewController: UITextFieldDelegate { passwordTextField.becomeFirstResponder() } else { textField.resignFirstResponder() + action(self) } return true }