RestoreSafePasswordViewController.swift 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2018-2020 Threema GmbH
  8. //
  9. // This program is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU Affero General Public License, version 3,
  11. // as published by the Free Software Foundation.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU Affero General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Affero General Public License
  19. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. import UIKit
  21. class RestoreSafePasswordViewController: IDCreationPageViewController {
  22. @IBOutlet weak var descriptionLabel: UILabel!
  23. @IBOutlet weak var passwordField: SetupTextField!
  24. @IBOutlet weak var cancelButton: SetupButton!
  25. @IBOutlet weak var okButton: SetupButton!
  26. var keyboardResize: KeyboardResizeCenterY?
  27. override func viewDidLoad() {
  28. super.viewDidLoad()
  29. self.hideKeyboardWhenTappedAround()
  30. self.keyboardResize = KeyboardResizeCenterY(parent: self.view, resize: self.mainContentView)
  31. self.descriptionLabel.text = NSLocalizedString("safe_enter_password", comment: "")
  32. self.passwordField.delegate = self
  33. self.passwordField.placeholder = NSLocalizedString("Password", comment: "")
  34. self.passwordField.becomeFirstResponder()
  35. self.cancelButton.setTitle(NSLocalizedString("cancel", comment: ""), for: .normal)
  36. self.okButton.setTitle(NSLocalizedString("ok", comment: ""), for: .normal)
  37. refreshView()
  38. }
  39. private func refreshView() {
  40. if let password = self.passwordField.text,
  41. password.count >= 8 {
  42. self.okButton.deactivated = false
  43. } else {
  44. self.okButton.deactivated = true
  45. }
  46. }
  47. }
  48. extension RestoreSafePasswordViewController: SetupTextFieldDelegate {
  49. func editingChangedTextField(_ sender: SetupTextField, forEvent event: UIEvent) {
  50. refreshView()
  51. }
  52. func primaryActionTriggered(_ sender: SetupTextField, forEvent event: UIEvent) {
  53. self.performSegue(withIdentifier: "okSafePassword", sender: sender)
  54. }
  55. }