diff --git a/ownCloud/Bookmarks/BookmarkViewController.swift b/ownCloud/Bookmarks/BookmarkViewController.swift index fdf9bf2ee..ca85214b1 100644 --- a/ownCloud/Bookmarks/BookmarkViewController.swift +++ b/ownCloud/Bookmarks/BookmarkViewController.swift @@ -34,9 +34,24 @@ class BookmarkViewController: StaticTableViewController { var passwordRow : StaticTableViewRow? var tokenInfoRow : StaticTableViewRow? var deleteAuthDataButtonRow : StaticTableViewRow? + var activeTextField: UITextField? lazy var continueBarButtonItem: UIBarButtonItem = UIBarButtonItem(title: "Continue".localized, style: .done, target: self, action: #selector(handleContinue)) lazy var saveBarButtonItem: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .save, target: self, action: #selector(BookmarkViewController.userActionSave)) + lazy var nextBarButtonItem = UIBarButtonItem(image: UIImage(named: "arrow-down"), style: .plain, target: self, action: #selector(toogleTextField)) + lazy var previousBarButtonItem = UIBarButtonItem(image: UIImage(named: "arrow-up"), style: .plain, target: self, action: #selector(toogleTextField)) + lazy var inputToolbar: UIToolbar = { + var toolbar = UIToolbar() + toolbar.barStyle = .default + toolbar.isTranslucent = true + toolbar.sizeToFit() + let doneBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(resignTextField)) + let flexibleSpaceBarButtonItem = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil) + let fixedSpaceBarButtonItem = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil) + toolbar.setItems([fixedSpaceBarButtonItem, previousBarButtonItem, fixedSpaceBarButtonItem, fixedSpaceBarButtonItem, nextBarButtonItem, flexibleSpaceBarButtonItem, doneBarButtonItem], animated: false) + toolbar.isUserInteractionEnabled = true + return toolbar + }() // MARK: - Internal storage var bookmark : OCBookmark? @@ -727,6 +742,21 @@ class BookmarkViewController: StaticTableViewController { func isAuthenticationMethodTokenBased(_ authenticationMethodIdentifier: OCAuthenticationMethodIdentifier) -> Bool { return authenticationMethodTypeForIdentifier(authenticationMethodIdentifier) == OCAuthenticationMethodType.token } + + // MARK: - Keyboard AccessoryView + @objc func toogleTextField (_ sender: UIBarButtonItem) { + if passwordRow?.textField?.isFirstResponder ?? false { + // Found next responder, so set it + usernameRow?.textField?.becomeFirstResponder() + } else { + // Not found, so remove keyboard + passwordRow?.textField?.becomeFirstResponder() + } + } + + @objc func resignTextField (_ sender: UIBarButtonItem) { + activeTextField?.resignFirstResponder() + } } // MARK: - OCClassSettings support @@ -759,6 +789,7 @@ extension BookmarkViewController : OCClassSettingsSupport { // MARK: - Keyboard / return key tracking extension BookmarkViewController : UITextFieldDelegate { + func textFieldShouldReturn(_ textField: UITextField) -> Bool { if self.navigationItem.rightBarButtonItem == continueBarButtonItem { if !updateInputFocus() { @@ -770,6 +801,23 @@ extension BookmarkViewController : UITextFieldDelegate { return true } + + func textFieldDidBeginEditing(_ textField: UITextField) { + activeTextField = textField + if textField.isEqual(urlRow?.textField) { + textField.returnKeyType = .continue + } else if textField.isEqual(usernameRow?.textField) && passwordRow?.textField?.isEnabled ?? false { + previousBarButtonItem.isEnabled = false + nextBarButtonItem.isEnabled = true + textField.inputAccessoryView = inputToolbar + textField.returnKeyType = .next + } else if textField.isEqual(passwordRow?.textField) && usernameRow?.textField?.isEnabled ?? false { + previousBarButtonItem.isEnabled = true + nextBarButtonItem.isEnabled = false + textField.inputAccessoryView = inputToolbar + textField.returnKeyType = .continue + } + } } // MARK: - Password manager support diff --git a/ownCloud/Resources/Assets.xcassets/arrow-down.imageset/Contents.json b/ownCloud/Resources/Assets.xcassets/arrow-down.imageset/Contents.json new file mode 100644 index 000000000..d08f44547 --- /dev/null +++ b/ownCloud/Resources/Assets.xcassets/arrow-down.imageset/Contents.json @@ -0,0 +1,15 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "down 2.pdf" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + }, + "properties" : { + "template-rendering-intent" : "template" + } +} \ No newline at end of file diff --git a/ownCloud/Resources/Assets.xcassets/arrow-down.imageset/down 2.pdf b/ownCloud/Resources/Assets.xcassets/arrow-down.imageset/down 2.pdf new file mode 100644 index 000000000..b7f3fba60 Binary files /dev/null and b/ownCloud/Resources/Assets.xcassets/arrow-down.imageset/down 2.pdf differ diff --git a/ownCloud/Resources/Assets.xcassets/check-mark.imageset/Contents.json b/ownCloud/Resources/Assets.xcassets/arrow-up.imageset/Contents.json similarity index 71% rename from ownCloud/Resources/Assets.xcassets/check-mark.imageset/Contents.json rename to ownCloud/Resources/Assets.xcassets/arrow-up.imageset/Contents.json index d202e7543..e034b8920 100644 --- a/ownCloud/Resources/Assets.xcassets/check-mark.imageset/Contents.json +++ b/ownCloud/Resources/Assets.xcassets/arrow-up.imageset/Contents.json @@ -2,7 +2,7 @@ "images" : [ { "idiom" : "universal", - "filename" : "checkmark.pdf" + "filename" : "up 2.pdf" } ], "info" : { @@ -10,6 +10,7 @@ "author" : "xcode" }, "properties" : { + "template-rendering-intent" : "template", "preserves-vector-representation" : true } } \ No newline at end of file diff --git a/ownCloud/Resources/Assets.xcassets/arrow-up.imageset/up 2.pdf b/ownCloud/Resources/Assets.xcassets/arrow-up.imageset/up 2.pdf new file mode 100644 index 000000000..9c7ea83c0 Binary files /dev/null and b/ownCloud/Resources/Assets.xcassets/arrow-up.imageset/up 2.pdf differ diff --git a/ownCloud/Resources/Assets.xcassets/check-mark.imageset/checkmark.pdf b/ownCloud/Resources/Assets.xcassets/check-mark.imageset/checkmark.pdf deleted file mode 100644 index 3f261286a..000000000 Binary files a/ownCloud/Resources/Assets.xcassets/check-mark.imageset/checkmark.pdf and /dev/null differ