Prechádzať zdrojové kódy

tap on passwordfield will start oAuth if needed

Bastian van de Wetering 6 rokov pred
rodič
commit
bbade3e436

+ 17 - 7
deltachat-ios/AccountSetupController.swift

@@ -114,18 +114,25 @@ class AccountSetupController: UITableViewController {
 
     override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
         // handle tap on password 
-        print(indexPath)
+        if indexPath.section == 0 && indexPath.row == 1 {
+            if let emailAdress = emailCell.getText() {
+               let _ = showOAuthAlertIfNeeded(emailAddress: emailAdress)
+            } else {
+                return 
+            }
+        }
     }
 
     @objc func loginButtonPressed() {
-/*
+
         guard let emailAddress = emailCell.getText() else {
             return // handle case when either email or pw fields are empty
         }
 
-        let oAuthStared = showOAuthAlertIfNeeded(emailAddress: emailAddress)
+        let oAuthStarted = showOAuthAlertIfNeeded(emailAddress: emailAddress)
 
-        if oAuthStared {
+        if oAuthStarted {
+            // the loginFlow will be handled by oAuth2
             return
         }
 
@@ -135,8 +142,10 @@ class AccountSetupController: UITableViewController {
         MRConfig.mailPw = passWord
         dc_configure(mailboxPointer)
         hudHandler.showBackupHud("Configuring account")
-        */
- }
+    }
+
+
+
 
     // returns true if needed
     private func showOAuthAlertIfNeeded(emailAddress: String) -> Bool {
@@ -194,6 +203,7 @@ class AccountSetupController: UITableViewController {
     }
 }
 
+/*
 class InputTableViewCell: UITableViewCell {
     lazy var inputField: UITextField = {
         let textField = UITextField()
@@ -261,4 +271,4 @@ class PasswordInputCell: UITableViewCell {
     }
 }
 
-
+*/

+ 58 - 52
deltachat-ios/TextFieldCell.swift

@@ -21,19 +21,23 @@ class TextFieldCell: UITableViewCell {
         return textField
     }()
 
-  init(description: String, placeholder: String) {
-    self.placeholder = placeholder
+    init(description: String, placeholder: String) {
+        self.placeholder = placeholder
 
-    super.init(style: .value1, reuseIdentifier: nil)
+        super.init(style: .value1, reuseIdentifier: nil)
 
-    textLabel?.text = "\(description):"
+        textLabel?.text = "\(description):"
 
-    // see: https://stackoverflow.com/a/35903650
-    // this makes the textField respect the trailing margin of
-    // the table view cell
-    selectionStyle = .none
-    setupViews()
-  }
+        // see: https://stackoverflow.com/a/35903650
+        // this makes the textField respect the trailing margin of
+        // the table view cell
+        selectionStyle = .none
+        setupViews()
+    }
+
+    required init?(coder _: NSCoder) {
+        fatalError("init(coder:) has not been implemented")
+    }
 
     private func setupViews() {
         contentView.addSubview(textField)
@@ -43,65 +47,67 @@ class TextFieldCell: UITableViewCell {
         textField.trailingAnchor.constraint(equalTo: trailing).isActive = true
         textField.centerYAnchor.constraint(equalTo: contentView.centerYAnchor).isActive = true
         if let label = self.textLabel {
-            textField.leadingAnchor.constraint(equalTo: label.trailingAnchor, constant: 20).isActive = true
+            textField.leadingAnchor.constraint(equalTo: label.trailingAnchor, constant: 20).isActive = true // this will prevent the textfield from growing over the textLabel while typing
         } else {
             textField.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 20).isActive = true
         }
     }
 
-  override func setSelected(_ selected: Bool, animated _: Bool) {
-    if selected {
-      textField.becomeFirstResponder()
+    override func setSelected(_ selected: Bool, animated _: Bool) {
+        if selected {
+            textField.becomeFirstResponder()
+        }
     }
-  }
 
-  required init?(coder _: NSCoder) {
-    fatalError("init(coder:) has not been implemented")
-  }
+    func getText() -> String? {
+        return self.textField.text 
+    }
 
-  static func makeEmailCell() -> TextFieldCell {
-    let emailCell = TextFieldCell(description: "Email", placeholder: "you@example.com")
 
-    emailCell.textField.keyboardType = .emailAddress
-    // switch off quicktype
-    emailCell.textField.autocorrectionType = .no
-    emailCell.textField.autocapitalizationType = .none
 
-    return emailCell
-  }
+    static func makeEmailCell() -> TextFieldCell {
+        let emailCell = TextFieldCell(description: "Email", placeholder: "you@example.com")
 
-  static func makePasswordCell() -> TextFieldCell {
-    let passwordCell = TextFieldCell(description: "Password", placeholder: "your IMAP password")
+        emailCell.textField.keyboardType = .emailAddress
+        // switch off quicktype
+        emailCell.textField.autocorrectionType = .no
+        emailCell.textField.autocapitalizationType = .none
 
-    passwordCell.textField.textContentType = UITextContentType.password
-    passwordCell.textField.isSecureTextEntry = true
+        return emailCell
+    }
 
-    return passwordCell
-  }
+    static func makePasswordCell() -> TextFieldCell {
+        let passwordCell = TextFieldCell(description: "Password", placeholder: "your IMAP password")
 
-  static func makeNameCell() -> TextFieldCell {
-    let nameCell = TextFieldCell(description: "Name", placeholder: "new contacts nickname")
+        passwordCell.textField.textContentType = UITextContentType.password
+        passwordCell.textField.isSecureTextEntry = true
 
-    nameCell.textField.autocapitalizationType = .words
-    nameCell.textField.autocorrectionType = .no
-    // .namePhonePad doesn't support autocapitalization
-    // see: https://stackoverflow.com/a/36365399
-    // therefore we use .default to capitalize the first character of the name
-    nameCell.textField.keyboardType = .default
+        return passwordCell
+    }
+
+    static func makeNameCell() -> TextFieldCell {
+        let nameCell = TextFieldCell(description: "Name", placeholder: "new contacts nickname")
 
-    return nameCell
-  }
+        nameCell.textField.autocapitalizationType = .words
+        nameCell.textField.autocorrectionType = .no
+        // .namePhonePad doesn't support autocapitalization
+        // see: https://stackoverflow.com/a/36365399
+        // therefore we use .default to capitalize the first character of the name
+        nameCell.textField.keyboardType = .default
 
-  static func makeConfigCell(label: String, placeholder: String) -> TextFieldCell {
-    let nameCell = TextFieldCell(description: label, placeholder: placeholder)
+        return nameCell
+    }
 
-    nameCell.textField.autocapitalizationType = .words
-    nameCell.textField.autocorrectionType = .no
-    // .namePhonePad doesn't support autocapitalization
-    // see: https://stackoverflow.com/a/36365399
-    // therefore we use .default to capitalize the first character of the name
-    nameCell.textField.keyboardType = .default
+    static func makeConfigCell(label: String, placeholder: String) -> TextFieldCell {
+        let nameCell = TextFieldCell(description: label, placeholder: placeholder)
 
-    return nameCell
-  }
+        nameCell.textField.autocapitalizationType = .words
+        nameCell.textField.autocorrectionType = .no
+        // .namePhonePad doesn't support autocapitalization
+        // see: https://stackoverflow.com/a/36365399
+        // therefore we use .default to capitalize the first character of the name
+        nameCell.textField.keyboardType = .default
+
+        return nameCell
+    }
 }