Selaa lähdekoodia

streamline port selection

the old "featured" view controller brough more problems than it solved,
eg. ports were shown as "0" instead of empty.
also it lacked an "automatic" option.
also it was a bit unclear when the controller
was left if the port was saved or not
(it was not)

instead of fixing all that, just get rid of the controller at all.
a simple input field for the port selection is just fine,
also in-line with android and desktop.
B. Petersen 5 vuotta sitten
vanhempi
commit
3d6d7136e6

+ 0 - 4
deltachat-ios.xcodeproj/project.pbxproj

@@ -112,7 +112,6 @@
 		7AE0A5491FC42F65005ECB4B /* NewChatViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AE0A5481FC42F65005ECB4B /* NewChatViewController.swift */; };
 		7AE0A5491FC42F65005ECB4B /* NewChatViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AE0A5481FC42F65005ECB4B /* NewChatViewController.swift */; };
 		8B6D425BC604F7C43B65D436 /* Pods_deltachat_ios.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6241BE1534A653E79AD5D01D /* Pods_deltachat_ios.framework */; };
 		8B6D425BC604F7C43B65D436 /* Pods_deltachat_ios.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6241BE1534A653E79AD5D01D /* Pods_deltachat_ios.framework */; };
 		AE0D26FD1FB1FE88002FAFCE /* ChatListController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE0D26FC1FB1FE88002FAFCE /* ChatListController.swift */; };
 		AE0D26FD1FB1FE88002FAFCE /* ChatListController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE0D26FC1FB1FE88002FAFCE /* ChatListController.swift */; };
-		AE18F292228C17BC0007B1BE /* PortSettingsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE18F291228C17BC0007B1BE /* PortSettingsController.swift */; };
 		AE18F294228C602A0007B1BE /* SecuritySettingsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE18F293228C602A0007B1BE /* SecuritySettingsController.swift */; };
 		AE18F294228C602A0007B1BE /* SecuritySettingsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE18F293228C602A0007B1BE /* SecuritySettingsController.swift */; };
 		AE25F09022807AD800CDEA66 /* GroupNameCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE25F08F22807AD800CDEA66 /* GroupNameCell.swift */; };
 		AE25F09022807AD800CDEA66 /* GroupNameCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE25F08F22807AD800CDEA66 /* GroupNameCell.swift */; };
 		AE38B31822672DFC00EC37A1 /* ActionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE38B31722672DFC00EC37A1 /* ActionCell.swift */; };
 		AE38B31822672DFC00EC37A1 /* ActionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE38B31722672DFC00EC37A1 /* ActionCell.swift */; };
@@ -327,7 +326,6 @@
 		8DE110C607A0E4485C43B5FA /* Pods-deltachat-ios.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-deltachat-ios.debug.xcconfig"; path = "Pods/Target Support Files/Pods-deltachat-ios/Pods-deltachat-ios.debug.xcconfig"; sourceTree = "<group>"; };
 		8DE110C607A0E4485C43B5FA /* Pods-deltachat-ios.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-deltachat-ios.debug.xcconfig"; path = "Pods/Target Support Files/Pods-deltachat-ios/Pods-deltachat-ios.debug.xcconfig"; sourceTree = "<group>"; };
 		A8615D4600859851E53CAA9C /* Pods-deltachat-ios.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-deltachat-ios.release.xcconfig"; path = "Pods/Target Support Files/Pods-deltachat-ios/Pods-deltachat-ios.release.xcconfig"; sourceTree = "<group>"; };
 		A8615D4600859851E53CAA9C /* Pods-deltachat-ios.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-deltachat-ios.release.xcconfig"; path = "Pods/Target Support Files/Pods-deltachat-ios/Pods-deltachat-ios.release.xcconfig"; sourceTree = "<group>"; };
 		AE0D26FC1FB1FE88002FAFCE /* ChatListController.swift */ = {isa = PBXFileReference; indentWidth = 4; lastKnownFileType = sourcecode.swift; path = ChatListController.swift; sourceTree = "<group>"; tabWidth = 4; };
 		AE0D26FC1FB1FE88002FAFCE /* ChatListController.swift */ = {isa = PBXFileReference; indentWidth = 4; lastKnownFileType = sourcecode.swift; path = ChatListController.swift; sourceTree = "<group>"; tabWidth = 4; };
-		AE18F291228C17BC0007B1BE /* PortSettingsController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PortSettingsController.swift; sourceTree = "<group>"; };
 		AE18F293228C602A0007B1BE /* SecuritySettingsController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecuritySettingsController.swift; sourceTree = "<group>"; };
 		AE18F293228C602A0007B1BE /* SecuritySettingsController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecuritySettingsController.swift; sourceTree = "<group>"; };
 		AE25F08F22807AD800CDEA66 /* GroupNameCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupNameCell.swift; sourceTree = "<group>"; };
 		AE25F08F22807AD800CDEA66 /* GroupNameCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupNameCell.swift; sourceTree = "<group>"; };
 		AE38B31722672DFC00EC37A1 /* ActionCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionCell.swift; sourceTree = "<group>"; };
 		AE38B31722672DFC00EC37A1 /* ActionCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionCell.swift; sourceTree = "<group>"; };
@@ -622,7 +620,6 @@
 		AE18F28B228C17630007B1BE /* AccountSetup */ = {
 		AE18F28B228C17630007B1BE /* AccountSetup */ = {
 			isa = PBXGroup;
 			isa = PBXGroup;
 			children = (
 			children = (
-				AE18F291228C17BC0007B1BE /* PortSettingsController.swift */,
 				30C0D49C237C4908008E2A0E /* CertificateCheckController.swift */,
 				30C0D49C237C4908008E2A0E /* CertificateCheckController.swift */,
 				AE18F293228C602A0007B1BE /* SecuritySettingsController.swift */,
 				AE18F293228C602A0007B1BE /* SecuritySettingsController.swift */,
 			);
 			);
@@ -1123,7 +1120,6 @@
 				305961FB2346125100C80F33 /* TypingIndicator.swift in Sources */,
 				305961FB2346125100C80F33 /* TypingIndicator.swift in Sources */,
 				7092474120B3869500AF8799 /* ContactDetailViewController.swift in Sources */,
 				7092474120B3869500AF8799 /* ContactDetailViewController.swift in Sources */,
 				300C50A1234BDAB800F8AE22 /* TextMediaMessageSizeCalculator.swift in Sources */,
 				300C50A1234BDAB800F8AE22 /* TextMediaMessageSizeCalculator.swift in Sources */,
-				AE18F292228C17BC0007B1BE /* PortSettingsController.swift in Sources */,
 				30F9B9EC235F2116006E7ACF /* MessageCounter.swift in Sources */,
 				30F9B9EC235F2116006E7ACF /* MessageCounter.swift in Sources */,
 				305961F12346125100C80F33 /* ContactMessageCell.swift in Sources */,
 				305961F12346125100C80F33 /* ContactMessageCell.swift in Sources */,
 				AE851AD0227DF50900ED86F0 /* GroupChatDetailViewController.swift in Sources */,
 				AE851AD0227DF50900ED86F0 /* GroupChatDetailViewController.swift in Sources */,

+ 0 - 148
deltachat-ios/Controller/AccountSetup/PortSettingsController.swift

@@ -1,148 +0,0 @@
-import UIKit
-
-class PortSettingsController: UITableViewController {
-
-    var ports: [Int]
-
-    private var sectionTitle: String?
-
-    var onSave: ((String) -> Void)?
-
-    var okButton: UIBarButtonItem {
-        let button =  UIBarButtonItem(title: String.localized("ok"), style: .done, target: self, action: #selector(okButtonPressed))
-        return button
-    }
-
-    var cancelButton: UIBarButtonItem {
-        let button =  UIBarButtonItem(title: String.localized("cancel"), style: .plain, target: self, action: #selector(cancelButtonPressed))
-        return button
-    }
-
-    var currentPort: Int
-    var selectedIndex: Int?
-
-    var staticCells: [UITableViewCell] {
-        return ports.map({
-            let cell = UITableViewCell(style: .default, reuseIdentifier: nil)
-            cell.textLabel?.text = "\($0)"
-            cell.selectionStyle = .none
-            return cell
-        })
-    }
-
-    lazy var customCell: TextFieldCell = {
-        let cell = TextFieldCell(description: "", placeholder: "\(self.currentPort)")
-        cell.selectionStyle = .none
-        cell.textLabel?.text = nil
-        cell.textField.keyboardType = .numberPad
-        cell.onTextFieldChange = textFieldDidChange
-        return cell
-    }()
-
-    init(sectionTitle: String?, ports: [Int], currentPort: Int?) {
-        self.ports = ports
-        self.sectionTitle = sectionTitle
-        self.currentPort = currentPort ?? 0
-        for (index, port) in ports.enumerated() where currentPort == port {
-            selectedIndex = index
-        }
-        super.init(style: .grouped)
-        self.title = sectionTitle
-    }
-
-    required init?(coder aDecoder: NSCoder) {
-        fatalError("init(coder:) has not been implemented")
-    }
-
-    override func viewDidLoad() {
-        super.viewDidLoad()
-
-        navigationItem.rightBarButtonItem = okButton
-        navigationItem.leftBarButtonItem = cancelButton
-    }
-
-    // MARK: - Table view data source
-
-    override func numberOfSections(in tableView: UITableView) -> Int {
-        return 2
-    }
-
-    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
-        if section == 0 {
-            return ports.count
-        } else {
-            return 1
-        }
-    }
-
-    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
-        if indexPath.section == 0 {
-            let row = indexPath.row
-            selectItem(at: row)
-        }
-    }
-
-    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
-
-        let section = indexPath.section
-        let row = indexPath.row
-        if section == 0 {
-            let cell = staticCells[row]
-            if row == selectedIndex || cell.textLabel?.text == "\(currentPort)" {
-                cell.accessoryType = .checkmark
-            } else {
-                cell.accessoryType = .none
-            }
-            return cell
-        } else {
-            // section == 1
-            return customCell
-        }
-    }
-
-    override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
-        if section == 0 {
-            return sectionTitle
-        } else {
-            return String.localized("custom_port")
-        }
-    }
-
-    private func textFieldDidChange(_ textField: UITextField) {
-        selectItem(at: nil)
-        if let text = textField.text, let port = Int(text) {
-            self.currentPort = port
-        }
-    }
-
-    private func selectItem(at index: Int? ) {
-        // unselect old cell
-        // select new cell
-        // update port
-        if let oldIndex = selectedIndex {
-            let cell = tableView.cellForRow(at: IndexPath.init(row: oldIndex, section: 0))
-            cell?.accessoryType = .none
-        }
-        if let newIndex = index {
-            // activate accesoryType on selected cell
-            let cell = tableView.cellForRow(at: IndexPath.init(row: newIndex, section: 0))
-            cell?.accessoryType = .checkmark
-            currentPort = ports[newIndex]
-            // update customCell
-            customCell.textField.placeholder = "\(currentPort)"
-            customCell.textField.resignFirstResponder()
-            customCell.textField.text = nil // will display currentValue as placeholder
-        }
-        selectedIndex = index
-    }
-
-    @objc private func okButtonPressed() {
-           onSave?("\(currentPort)")
-           navigationController?.popViewController(animated: true)
-       }
-
-    @objc private func cancelButtonPressed() {
-        navigationController?.popViewController(animated: true)
-    }
-
-}

+ 29 - 18
deltachat-ios/Controller/AccountSetupController.swift

@@ -206,13 +206,25 @@ class AccountSetupController: UITableViewController {
         return cell
         return cell
     }()
     }()
 
 
-    lazy var imapPortCell: UITableViewCell = {
-        let cell = UITableViewCell(style: .value1, reuseIdentifier: nil)
-        cell.textLabel?.text = String.localized("login_imap_port")
-        cell.accessoryType = .disclosureIndicator
-        cell.detailTextLabel?.text = DcConfig.mailPort ?? DcConfig.configuredMailPort
+    func editablePort(port: String?) -> String {
+        if let port = port {
+            if Int(port) == 0 {
+                return ""
+            }
+            return port
+        } else {
+            return ""
+        }
+    }
+
+    lazy var imapPortCell: TextFieldCell = {
+        let cell = TextFieldCell(descriptionID: "login_imap_port",
+                                 placeholder: String.localized("automatic"),
+                                 delegate: self)
         cell.tag = tagImapPortCell
         cell.tag = tagImapPortCell
-        cell.selectionStyle = .none
+        cell.setText(text: editablePort(port: DcConfig.mailPort))
+        cell.textField.tag = tagImapPortCell
+        cell.textField.keyboardType = .numberPad
         return cell
         return cell
     }()
     }()
 
 
@@ -246,13 +258,14 @@ class AccountSetupController: UITableViewController {
         return cell
         return cell
     }()
     }()
 
 
-    lazy var smtpPortCell: UITableViewCell = {
-        let cell = UITableViewCell(style: .value1, reuseIdentifier: nil)
-        cell.textLabel?.text = String.localized("login_smtp_port")
-        cell.accessoryType = .disclosureIndicator
-        cell.detailTextLabel?.text = DcConfig.sendPort ?? DcConfig.configuredSendPort
-        cell.selectionStyle = .none
+    lazy var smtpPortCell: TextFieldCell = {
+        let cell = TextFieldCell(descriptionID: "login_smtp_port",
+                                 placeholder: String.localized("automatic"),
+                                 delegate: self)
         cell.tag = tagSmtpPortCell
         cell.tag = tagSmtpPortCell
+        cell.setText(text: editablePort(port: DcConfig.sendPort))
+        cell.textField.tag = tagSmtpPortCell
+        cell.textField.keyboardType = .numberPad
         return cell
         return cell
     }()
     }()
 
 
@@ -473,10 +486,6 @@ class AccountSetupController: UITableViewController {
             deleteAccount()
             deleteAccount()
         case tagAdvancedCell:
         case tagAdvancedCell:
             toggleAdvancedSection()
             toggleAdvancedSection()
-        case tagImapPortCell:
-            coordinator?.showImapPortOptions()
-        case tagSmtpPortCell:
-            coordinator?.showSmtpPortsOptions()
         case tagImapSecurityCell:
         case tagImapSecurityCell:
             coordinator?.showImapSecurityOptions()
             coordinator?.showImapSecurityOptions()
         case tagSmtpSecurityCell:
         case tagSmtpSecurityCell:
@@ -644,10 +653,14 @@ class AccountSetupController: UITableViewController {
                 switch  textFieldCell.tag {
                 switch  textFieldCell.tag {
                 case tagImapServerCell:
                 case tagImapServerCell:
                     DcConfig.mailServer = textFieldCell.getText() ?? nil
                     DcConfig.mailServer = textFieldCell.getText() ?? nil
+                case tagImapPortCell:
+                    DcConfig.mailPort = textFieldCell.getText() ?? nil
                 case tagImapUserCell:
                 case tagImapUserCell:
                     DcConfig.mailUser = textFieldCell.getText() ?? nil
                     DcConfig.mailUser = textFieldCell.getText() ?? nil
                 case tagSmtpServerCell:
                 case tagSmtpServerCell:
                     DcConfig.sendServer = textFieldCell.getText() ?? nil
                     DcConfig.sendServer = textFieldCell.getText() ?? nil
+                case tagSmtpPortCell:
+                    DcConfig.sendPort = textFieldCell.getText() ?? nil
                 case tagSmtpUserCell:
                 case tagSmtpUserCell:
                     DcConfig.sendUser = textFieldCell.getText() ?? nil
                     DcConfig.sendUser = textFieldCell.getText() ?? nil
                 case tagSmtpPasswordCell:
                 case tagSmtpPasswordCell:
@@ -765,8 +778,6 @@ class AccountSetupController: UITableViewController {
     }
     }
 
 
     private func initSelectionCells() {
     private func initSelectionCells() {
-        smtpPortCell.detailTextLabel?.text = DcConfig.sendPort ?? DcConfig.configuredSendPort
-        imapPortCell.detailTextLabel?.text = DcConfig.mailPort ?? DcConfig.configuredMailPort
         smtpSecurityCell.detailTextLabel?.text = SecurityConverter.convertHexToString(type: .SMTPSecurity, hex: DcConfig.getSmtpSecurity())
         smtpSecurityCell.detailTextLabel?.text = SecurityConverter.convertHexToString(type: .SMTPSecurity, hex: DcConfig.getSmtpSecurity())
         imapSecurityCell.detailTextLabel?.text = SecurityConverter.convertHexToString(type: .IMAPSecurity, hex: DcConfig.getImapSecurity())
         imapSecurityCell.detailTextLabel?.text = SecurityConverter.convertHexToString(type: .IMAPSecurity, hex: DcConfig.getImapSecurity())
         certCheckCell.detailTextLabel?.text = CertificateCheckController.ValueConverter.convertHexToString(value: DcConfig.certificateChecks)
         certCheckCell.detailTextLabel?.text = CertificateCheckController.ValueConverter.convertHexToString(value: DcConfig.certificateChecks)

+ 0 - 26
deltachat-ios/Coordinator/AppCoordinator.swift

@@ -203,38 +203,12 @@ class AccountSetupCoordinator: Coordinator {
         navigationController.pushViewController(certificateCheckController, animated: true)
         navigationController.pushViewController(certificateCheckController, animated: true)
     }
     }
 
 
-    func showImapPortOptions() {
-        let currentMailPort = DcConfig.mailPort ?? DcConfig.configuredMailPort
-        let currentPort = Int(currentMailPort)
-        let portSettingsController = PortSettingsController(sectionTitle: String.localized("login_imap_port"),
-                                                            ports: [143, 993],
-                                                            currentPort: currentPort)
-        portSettingsController.onSave = {
-            port in
-            DcConfig.mailPort = port
-        }
-        navigationController.pushViewController(portSettingsController, animated: true)
-    }
-
     func showImapSecurityOptions() {
     func showImapSecurityOptions() {
         let securitySettingsController = SecuritySettingsController(title: String.localized("login_imap_security"),
         let securitySettingsController = SecuritySettingsController(title: String.localized("login_imap_security"),
                                                                     type: SecurityType.IMAPSecurity)
                                                                     type: SecurityType.IMAPSecurity)
         navigationController.pushViewController(securitySettingsController, animated: true)
         navigationController.pushViewController(securitySettingsController, animated: true)
     }
     }
 
 
-    func showSmtpPortsOptions() {
-        let currentMailPort = DcConfig.sendPort ?? DcConfig.configuredSendPort
-        let currentPort = Int(currentMailPort)
-        let portSettingsController = PortSettingsController(sectionTitle: String.localized("login_smtp_port"),
-                                                            ports: [25, 465, 587],
-                                                            currentPort: currentPort)
-        portSettingsController.onSave = {
-            port in
-            DcConfig.sendPort = port
-        }
-        navigationController.pushViewController(portSettingsController, animated: true)
-    }
-
     func showSmptpSecurityOptions() {
     func showSmptpSecurityOptions() {
         let securitySettingsController = SecuritySettingsController(title: String.localized("login_imap_security"), type: SecurityType.SMTPSecurity)
         let securitySettingsController = SecuritySettingsController(title: String.localized("login_imap_security"), type: SecurityType.SMTPSecurity)
         navigationController.pushViewController(securitySettingsController, animated: true)
         navigationController.pushViewController(securitySettingsController, animated: true)