From 36a941ea828bfcae55b10572730bd613c3029d7f Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Wed, 24 Jul 2024 12:43:57 +0200 Subject: [PATCH 1/9] add 'Cancel' instead of 'Back arrow' to the server settings --- .../AccountSetup/AccountSetupController.swift | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/deltachat-ios/Controller/AccountSetup/AccountSetupController.swift b/deltachat-ios/Controller/AccountSetup/AccountSetupController.swift index 5e3b21161..3715357ad 100644 --- a/deltachat-ios/Controller/AccountSetup/AccountSetupController.swift +++ b/deltachat-ios/Controller/AccountSetup/AccountSetupController.swift @@ -247,12 +247,13 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler { return cell }() + private var cancelButton: UIBarButtonItem { + let button = UIBarButtonItem(title: String.localized("cancel"), style: .plain, target: self, action: #selector(cancelButtonPressed)) + return button + } + private lazy var loginButton: UIBarButtonItem = { - let button = UIBarButtonItem( - title: String.localized("login_title"), - style: .done, - target: self, - action: #selector(loginButtonPressed)) + let button = UIBarButtonItem(title: String.localized("login_title"), style: .done, target: self, action: #selector(loginButtonPressed)) button.isEnabled = !dcContext.isConfigured() return button }() @@ -282,6 +283,7 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler { } else { title = String.localized("login_header") } + navigationItem.leftBarButtonItem = cancelButton navigationItem.rightBarButtonItem = loginButton emailCell.setText(text: dcContext.addr ?? nil) passwordCell.setText(text: dcContext.mailPw ?? nil) @@ -414,6 +416,10 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler { tableView.reloadData() // needed to force a redraw } + @objc private func cancelButtonPressed() { + navigationController?.popViewController(animated: true) + } + @objc private func loginButtonPressed() { guard let emailAddress = emailCell.getText() else { return // handle case when either email or pw fields are empty From 29f27aa9aa23c610b3ec417353d587fdf638b4e0 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Wed, 24 Jul 2024 13:25:52 +0200 Subject: [PATCH 2/9] remove dead code --- .../Controller/AccountSetup/AccountSetupController.swift | 4 ---- 1 file changed, 4 deletions(-) diff --git a/deltachat-ios/Controller/AccountSetup/AccountSetupController.swift b/deltachat-ios/Controller/AccountSetup/AccountSetupController.swift index 3715357ad..94f2557c6 100644 --- a/deltachat-ios/Controller/AccountSetup/AccountSetupController.swift +++ b/deltachat-ios/Controller/AccountSetup/AccountSetupController.swift @@ -507,10 +507,6 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler { showProgressAlert(title: String.localized("login_header"), dcContext: dcContext) } - @objc func closeButtonPressed() { - dismiss(animated: true, completion: nil) - } - // returns true if needed private func showOAuthAlertIfNeeded(emailAddress: String, handleCancel: (() -> Void)?) -> Bool { return false From c4367480a2fc1cbfd2f5e5cf4e1c0b370028748e Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Wed, 24 Jul 2024 13:46:26 +0200 Subject: [PATCH 3/9] work --- .../AccountSetup/CertificateCheckController.swift | 3 ++- .../AccountSetup/SecuritySettingsController.swift | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/deltachat-ios/Controller/AccountSetup/CertificateCheckController.swift b/deltachat-ios/Controller/AccountSetup/CertificateCheckController.swift index f1066d900..0abf80625 100644 --- a/deltachat-ios/Controller/AccountSetup/CertificateCheckController.swift +++ b/deltachat-ios/Controller/AccountSetup/CertificateCheckController.swift @@ -76,6 +76,7 @@ class CertificateCheckController: UITableViewController { } private func selectItem(at index: Int? ) { + // TODO: callback to AccountSetupController here if let oldIndex = selectedIndex { let cell = tableView.cellForRow(at: IndexPath.init(row: oldIndex, section: 0)) cell?.accessoryType = .none @@ -89,7 +90,7 @@ class CertificateCheckController: UITableViewController { } @objc private func okButtonPressed() { - dcContext.certificateChecks = currentValue + dcContext.certificateChecks = currentValue // TODO: setting here is too soon navigationController?.popViewController(animated: true) } diff --git a/deltachat-ios/Controller/AccountSetup/SecuritySettingsController.swift b/deltachat-ios/Controller/AccountSetup/SecuritySettingsController.swift index 4eb1c9c03..7076e8b34 100644 --- a/deltachat-ios/Controller/AccountSetup/SecuritySettingsController.swift +++ b/deltachat-ios/Controller/AccountSetup/SecuritySettingsController.swift @@ -75,15 +75,15 @@ class SecuritySettingsController: UITableViewController { if let cell = tableView.cellForRow(at: indexPath) { cell.accessoryType = .checkmark } - selectedIndex = indexPath.row + selectedIndex = indexPath.row // TODO: callback to AccountSetupController here } @objc func okButtonPressed() { switch securityType { case .IMAPSecurity: - dcContext.setConfigInt("mail_security", Int(options[selectedIndex])) + dcContext.setConfigInt("mail_security", Int(options[selectedIndex])) // TODO: setting here is too soon case .SMTPSecurity: - dcContext.setConfigInt("send_security", Int(options[selectedIndex])) + dcContext.setConfigInt("send_security", Int(options[selectedIndex])) // TODO: setting here is too soon } navigationController?.popViewController(animated: true) } From 9035fcb18bf40a72257ff13b980703dd376a2ad9 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Thu, 25 Jul 2024 23:53:46 +0200 Subject: [PATCH 4/9] fix certificate-checks cancel-behaviour (set value only on log in) --- .../AccountSetup/AccountSetupController.swift | 16 +++++++++++++--- .../CertificateCheckController.swift | 14 ++++++++------ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/deltachat-ios/Controller/AccountSetup/AccountSetupController.swift b/deltachat-ios/Controller/AccountSetup/AccountSetupController.swift index 94f2557c6..261af8a9e 100644 --- a/deltachat-ios/Controller/AccountSetup/AccountSetupController.swift +++ b/deltachat-ios/Controller/AccountSetup/AccountSetupController.swift @@ -230,7 +230,7 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler { }() lazy var certCheckCell: UITableViewCell = { - let certCheckType = CertificateCheckController.ValueConverter.convertHexToString(value: dcContext.certificateChecks) + let certCheckType = CertificateCheckController.ValueConverter.convertHexToString(value: certValue) let cell = UITableViewCell(style: .value1, reuseIdentifier: nil) cell.textLabel?.text = String.localized("login_certificate_checks") cell.detailTextLabel?.text = certCheckType @@ -239,6 +239,8 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler { return cell }() + lazy var certValue: Int = dcContext.certificateChecks + lazy var viewLogCell: UITableViewCell = { let cell = UITableViewCell(style: .value1, reuseIdentifier: nil) cell.textLabel?.text = String.localized("pref_view_log") @@ -589,6 +591,7 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler { } } } + dcContext.certificateChecks = certValue } private func handleLoginSuccess() { @@ -607,7 +610,7 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler { private func initSelectionCells() { imapSecurityCell.detailTextLabel?.text = SecurityConverter.getSocketName(value: Int32(dcContext.getConfigInt("mail_security"))) smtpSecurityCell.detailTextLabel?.text = SecurityConverter.getSocketName(value: Int32(dcContext.getConfigInt("send_security"))) - certCheckCell.detailTextLabel?.text = CertificateCheckController.ValueConverter.convertHexToString(value: dcContext.certificateChecks) + certCheckCell.detailTextLabel?.text = CertificateCheckController.ValueConverter.convertHexToString(value: certValue) } private func resignFirstResponderOnAllCells() { @@ -677,7 +680,8 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler { } private func showCertCheckOptions() { - let certificateCheckController = CertificateCheckController(dcContext: dcContext, sectionTitle: String.localized("login_certificate_checks")) + let certificateCheckController = CertificateCheckController(initValue: certValue, sectionTitle: String.localized("login_certificate_checks")) + certificateCheckController.delegate = self navigationController?.pushViewController(certificateCheckController, animated: true) } @@ -731,3 +735,9 @@ extension AccountSetupController: UITextFieldDelegate { } } } + +extension AccountSetupController: CertificateCheckDelegate { + func onCertificateCheckChanged(newValue: Int) { + certValue = newValue + } +} diff --git a/deltachat-ios/Controller/AccountSetup/CertificateCheckController.swift b/deltachat-ios/Controller/AccountSetup/CertificateCheckController.swift index 0abf80625..3b04293bc 100644 --- a/deltachat-ios/Controller/AccountSetup/CertificateCheckController.swift +++ b/deltachat-ios/Controller/AccountSetup/CertificateCheckController.swift @@ -1,6 +1,10 @@ import UIKit import DcCore +protocol CertificateCheckDelegate: AnyObject { + func onCertificateCheckChanged(newValue: Int) +} + class CertificateCheckController: UITableViewController { var options = [Int(DC_CERTCK_AUTO), @@ -9,7 +13,7 @@ class CertificateCheckController: UITableViewController { var currentValue: Int var selectedIndex: Int? - let dcContext: DcContext + weak var delegate: CertificateCheckDelegate? var okButton: UIBarButtonItem { let button = UIBarButtonItem(title: String.localized("ok"), style: .done, target: self, action: #selector(okButtonPressed)) @@ -29,9 +33,8 @@ class CertificateCheckController: UITableViewController { }) } - init(dcContext: DcContext, sectionTitle: String?) { - self.dcContext = dcContext - self.currentValue = dcContext.certificateChecks + init(initValue: Int, sectionTitle: String?) { + self.currentValue = initValue for (index, value) in options.enumerated() where currentValue == value { selectedIndex = index } @@ -76,7 +79,6 @@ class CertificateCheckController: UITableViewController { } private func selectItem(at index: Int? ) { - // TODO: callback to AccountSetupController here if let oldIndex = selectedIndex { let cell = tableView.cellForRow(at: IndexPath.init(row: oldIndex, section: 0)) cell?.accessoryType = .none @@ -90,7 +92,7 @@ class CertificateCheckController: UITableViewController { } @objc private func okButtonPressed() { - dcContext.certificateChecks = currentValue // TODO: setting here is too soon + delegate?.onCertificateCheckChanged(newValue: currentValue) navigationController?.popViewController(animated: true) } From 88cb7515df1e17a3739ef623d11a655c5fb1a218 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Fri, 26 Jul 2024 00:12:21 +0200 Subject: [PATCH 5/9] fix security-type cancel-behaviour (set value only on log in) --- .../AccountSetup/AccountSetupController.swift | 28 ++++++++++++++----- .../SecuritySettingsController.swift | 24 ++++++---------- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/deltachat-ios/Controller/AccountSetup/AccountSetupController.swift b/deltachat-ios/Controller/AccountSetup/AccountSetupController.swift index 261af8a9e..e01834324 100644 --- a/deltachat-ios/Controller/AccountSetup/AccountSetupController.swift +++ b/deltachat-ios/Controller/AccountSetup/AccountSetupController.swift @@ -165,6 +165,8 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler { return cell }() + lazy var imapSecurityValue: Int = dcContext.getConfigInt("mail_security") + lazy var smtpServerCell: TextFieldCell = { let cell = TextFieldCell( descriptionID: "login_smtp_server", @@ -229,6 +231,8 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler { return cell }() + lazy var smtpSecurityValue: Int = dcContext.getConfigInt("send_security") + lazy var certCheckCell: UITableViewCell = { let certCheckType = CertificateCheckController.ValueConverter.convertHexToString(value: certValue) let cell = UITableViewCell(style: .value1, reuseIdentifier: nil) @@ -591,6 +595,8 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler { } } } + dcContext.setConfigInt("mail_security", imapSecurityValue) + dcContext.setConfigInt("send_security", smtpSecurityValue) dcContext.certificateChecks = certValue } @@ -608,8 +614,8 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler { } private func initSelectionCells() { - imapSecurityCell.detailTextLabel?.text = SecurityConverter.getSocketName(value: Int32(dcContext.getConfigInt("mail_security"))) - smtpSecurityCell.detailTextLabel?.text = SecurityConverter.getSocketName(value: Int32(dcContext.getConfigInt("send_security"))) + imapSecurityCell.detailTextLabel?.text = SecurityConverter.getSocketName(value: Int32(imapSecurityValue)) + smtpSecurityCell.detailTextLabel?.text = SecurityConverter.getSocketName(value: Int32(smtpSecurityValue)) certCheckCell.detailTextLabel?.text = CertificateCheckController.ValueConverter.convertHexToString(value: certValue) } @@ -686,15 +692,14 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler { } private func showImapSecurityOptions() { - let securitySettingsController = SecuritySettingsController(dcContext: dcContext, title: String.localized("login_imap_security"), - type: SecurityType.IMAPSecurity) + let securitySettingsController = SecuritySettingsController(initValue: imapSecurityValue, title: String.localized("login_imap_security"), type: SecurityType.IMAPSecurity) + securitySettingsController.delegate = self navigationController?.pushViewController(securitySettingsController, animated: true) } private func showSmtpSecurityOptions() { - let securitySettingsController = SecuritySettingsController(dcContext: dcContext, - title: String.localized("login_smtp_security"), - type: SecurityType.SMTPSecurity) + let securitySettingsController = SecuritySettingsController(initValue: smtpSecurityValue, title: String.localized("login_smtp_security"), type: SecurityType.SMTPSecurity) + securitySettingsController.delegate = self navigationController?.pushViewController(securitySettingsController, animated: true) } @@ -741,3 +746,12 @@ extension AccountSetupController: CertificateCheckDelegate { certValue = newValue } } + +extension AccountSetupController: SecuritySettingsDelegate { + func onSecuritySettingsChanged(type: SecurityType, newValue: Int) { + switch type { + case .IMAPSecurity: imapSecurityValue = newValue + case .SMTPSecurity: smtpSecurityValue = newValue + } + } +} diff --git a/deltachat-ios/Controller/AccountSetup/SecuritySettingsController.swift b/deltachat-ios/Controller/AccountSetup/SecuritySettingsController.swift index 7076e8b34..21f3f6503 100644 --- a/deltachat-ios/Controller/AccountSetup/SecuritySettingsController.swift +++ b/deltachat-ios/Controller/AccountSetup/SecuritySettingsController.swift @@ -1,14 +1,17 @@ import UIKit import DcCore +protocol SecuritySettingsDelegate: AnyObject { + func onSecuritySettingsChanged(type: SecurityType, newValue: Int) +} + class SecuritySettingsController: UITableViewController { private var options: [Int32] = [DC_SOCKET_AUTO, DC_SOCKET_SSL, DC_SOCKET_STARTTLS, DC_SOCKET_PLAIN] private var selectedIndex: Int - private var securityType: SecurityType - private let dcContext: DcContext + weak var delegate: SecuritySettingsDelegate? private var okButton: UIBarButtonItem { let button = UIBarButtonItem(title: String.localized("ok"), style: .done, target: self, action: #selector(okButtonPressed)) @@ -28,15 +31,9 @@ class SecuritySettingsController: UITableViewController { } } - init(dcContext: DcContext, title: String, type: SecurityType) { + init(initValue: Int, title: String, type: SecurityType) { self.securityType = type - self.dcContext = dcContext - switch securityType { - case .IMAPSecurity: - selectedIndex = options.firstIndex(of: Int32(dcContext.getConfigInt("mail_security"))) ?? 0 - case .SMTPSecurity: - selectedIndex = options.firstIndex(of: Int32(dcContext.getConfigInt("send_security"))) ?? 0 - } + selectedIndex = options.firstIndex(of: Int32(initValue)) ?? 0 super.init(style: .grouped) self.title = title } @@ -79,12 +76,7 @@ class SecuritySettingsController: UITableViewController { } @objc func okButtonPressed() { - switch securityType { - case .IMAPSecurity: - dcContext.setConfigInt("mail_security", Int(options[selectedIndex])) // TODO: setting here is too soon - case .SMTPSecurity: - dcContext.setConfigInt("send_security", Int(options[selectedIndex])) // TODO: setting here is too soon - } + delegate?.onSecuritySettingsChanged(type: securityType, newValue: Int(options[selectedIndex])) navigationController?.popViewController(animated: true) } From 9856c5297ff9cc5873f2975f7cd132a4ded15efc Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Fri, 26 Jul 2024 00:19:20 +0200 Subject: [PATCH 6/9] remove summary of questionable use; we never had that on android/desktop and 'log' shows the same information --- .../AccountSetup/AccountSetupController.swift | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/deltachat-ios/Controller/AccountSetup/AccountSetupController.swift b/deltachat-ios/Controller/AccountSetup/AccountSetupController.swift index e01834324..e459ef95c 100644 --- a/deltachat-ios/Controller/AccountSetup/AccountSetupController.swift +++ b/deltachat-ios/Controller/AccountSetup/AccountSetupController.swift @@ -341,23 +341,7 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler { if sections[section] == basicSection { return String.localized("login_no_servers_hint") } else if sections[section] == advancedSection { - if advancedSectionShowing && dcContext.isConfigured() { - var info = String.localized("used_settings") + "\n" - info += "IMAP " - info += SecurityConverter.getSocketName(value: Int32(dcContext.getConfigInt("mail_security"))) + " " - info += (dcContext.getConfig("configured_mail_user") ?? "unset") + ":***@" - info += (dcContext.getConfig("configured_mail_server") ?? "unset") + ":" - info += (dcContext.getConfig("configured_mail_port") ?? "unset") + "\n" - info += "SMTP " - info += SecurityConverter.getSocketName(value: Int32(dcContext.getConfigInt("send_security"))) + " " - info += (dcContext.getConfig("configured_send_user") ?? "unset") + ":***@" - info += (dcContext.getConfig("configured_send_server") ?? "unset") + ":" - info += (dcContext.getConfig("configured_send_port") ?? "unset") + "\n\n" - info += String.localized("login_subheader") - return info - } else { - return String.localized("login_subheader") - } + return String.localized("login_subheader") } else { return nil } From eeecb9f380e1d37ce8734e515565caad28d50b32 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Fri, 26 Jul 2024 10:52:19 +0200 Subject: [PATCH 7/9] make SecuritySettingsController dumber and leave details to the delegate --- .../AccountSetup/AccountSetupController.swift | 38 +++++++++++-------- .../SecuritySettingsController.swift | 15 ++------ 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/deltachat-ios/Controller/AccountSetup/AccountSetupController.swift b/deltachat-ios/Controller/AccountSetup/AccountSetupController.swift index e459ef95c..df2e14eb8 100644 --- a/deltachat-ios/Controller/AccountSetup/AccountSetupController.swift +++ b/deltachat-ios/Controller/AccountSetup/AccountSetupController.swift @@ -165,7 +165,7 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler { return cell }() - lazy var imapSecurityValue: Int = dcContext.getConfigInt("mail_security") + let imapSecurityValue: AccountSetupSecurityValue lazy var smtpServerCell: TextFieldCell = { let cell = TextFieldCell( @@ -231,7 +231,7 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler { return cell }() - lazy var smtpSecurityValue: Int = dcContext.getConfigInt("send_security") + let smtpSecurityValue: AccountSetupSecurityValue lazy var certCheckCell: UITableViewCell = { let certCheckType = CertificateCheckController.ValueConverter.convertHexToString(value: certValue) @@ -273,6 +273,9 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler { self.sections.append(basicSection) self.sections.append(advancedSection) + self.imapSecurityValue = AccountSetupSecurityValue(initValue: dcContext.getConfigInt("mail_security")) + self.smtpSecurityValue = AccountSetupSecurityValue(initValue: dcContext.getConfigInt("send_security")) + super.init(style: .grouped) hidesBottomBarWhenPushed = true } @@ -579,8 +582,8 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler { } } } - dcContext.setConfigInt("mail_security", imapSecurityValue) - dcContext.setConfigInt("send_security", smtpSecurityValue) + dcContext.setConfigInt("mail_security", imapSecurityValue.value) + dcContext.setConfigInt("send_security", smtpSecurityValue.value) dcContext.certificateChecks = certValue } @@ -598,8 +601,8 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler { } private func initSelectionCells() { - imapSecurityCell.detailTextLabel?.text = SecurityConverter.getSocketName(value: Int32(imapSecurityValue)) - smtpSecurityCell.detailTextLabel?.text = SecurityConverter.getSocketName(value: Int32(smtpSecurityValue)) + imapSecurityCell.detailTextLabel?.text = SecurityConverter.getSocketName(value: Int32(imapSecurityValue.value)) + smtpSecurityCell.detailTextLabel?.text = SecurityConverter.getSocketName(value: Int32(smtpSecurityValue.value)) certCheckCell.detailTextLabel?.text = CertificateCheckController.ValueConverter.convertHexToString(value: certValue) } @@ -676,14 +679,14 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler { } private func showImapSecurityOptions() { - let securitySettingsController = SecuritySettingsController(initValue: imapSecurityValue, title: String.localized("login_imap_security"), type: SecurityType.IMAPSecurity) - securitySettingsController.delegate = self + let securitySettingsController = SecuritySettingsController(initValue: imapSecurityValue.value, title: String.localized("login_imap_security")) + securitySettingsController.delegate = imapSecurityValue navigationController?.pushViewController(securitySettingsController, animated: true) } private func showSmtpSecurityOptions() { - let securitySettingsController = SecuritySettingsController(initValue: smtpSecurityValue, title: String.localized("login_smtp_security"), type: SecurityType.SMTPSecurity) - securitySettingsController.delegate = self + let securitySettingsController = SecuritySettingsController(initValue: smtpSecurityValue.value, title: String.localized("login_smtp_security")) + securitySettingsController.delegate = smtpSecurityValue navigationController?.pushViewController(securitySettingsController, animated: true) } @@ -731,11 +734,14 @@ extension AccountSetupController: CertificateCheckDelegate { } } -extension AccountSetupController: SecuritySettingsDelegate { - func onSecuritySettingsChanged(type: SecurityType, newValue: Int) { - switch type { - case .IMAPSecurity: imapSecurityValue = newValue - case .SMTPSecurity: smtpSecurityValue = newValue - } +class AccountSetupSecurityValue: SecuritySettingsDelegate { + var value: Int + + init(initValue: Int) { + value = initValue + } + + func onSecuritySettingsChanged(newValue: Int) { + value = newValue } } diff --git a/deltachat-ios/Controller/AccountSetup/SecuritySettingsController.swift b/deltachat-ios/Controller/AccountSetup/SecuritySettingsController.swift index 21f3f6503..c1b1ad0d5 100644 --- a/deltachat-ios/Controller/AccountSetup/SecuritySettingsController.swift +++ b/deltachat-ios/Controller/AccountSetup/SecuritySettingsController.swift @@ -2,7 +2,7 @@ import UIKit import DcCore protocol SecuritySettingsDelegate: AnyObject { - func onSecuritySettingsChanged(type: SecurityType, newValue: Int) + func onSecuritySettingsChanged(newValue: Int) } class SecuritySettingsController: UITableViewController { @@ -10,7 +10,6 @@ class SecuritySettingsController: UITableViewController { private var options: [Int32] = [DC_SOCKET_AUTO, DC_SOCKET_SSL, DC_SOCKET_STARTTLS, DC_SOCKET_PLAIN] private var selectedIndex: Int - private var securityType: SecurityType weak var delegate: SecuritySettingsDelegate? private var okButton: UIBarButtonItem { @@ -31,8 +30,7 @@ class SecuritySettingsController: UITableViewController { } } - init(initValue: Int, title: String, type: SecurityType) { - self.securityType = type + init(initValue: Int, title: String) { selectedIndex = options.firstIndex(of: Int32(initValue)) ?? 0 super.init(style: .grouped) self.title = title @@ -72,11 +70,11 @@ class SecuritySettingsController: UITableViewController { if let cell = tableView.cellForRow(at: indexPath) { cell.accessoryType = .checkmark } - selectedIndex = indexPath.row // TODO: callback to AccountSetupController here + selectedIndex = indexPath.row } @objc func okButtonPressed() { - delegate?.onSecuritySettingsChanged(type: securityType, newValue: Int(options[selectedIndex])) + delegate?.onSecuritySettingsChanged(newValue: Int(options[selectedIndex])) navigationController?.popViewController(animated: true) } @@ -85,11 +83,6 @@ class SecuritySettingsController: UITableViewController { } } -enum SecurityType { - case IMAPSecurity - case SMTPSecurity -} - class SecurityConverter { static func getSocketName(value: Int32) -> String { switch value { From 4ca9eaa13cd005d7967554d9be598d0fc3e9b4db Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Fri, 26 Jul 2024 11:07:56 +0200 Subject: [PATCH 8/9] make subsequent dialogs contain a simple 'back' --- .../CertificateCheckController.swift | 27 +------------------ .../SecuritySettingsController.swift | 24 ----------------- 2 files changed, 1 insertion(+), 50 deletions(-) diff --git a/deltachat-ios/Controller/AccountSetup/CertificateCheckController.swift b/deltachat-ios/Controller/AccountSetup/CertificateCheckController.swift index 3b04293bc..f3e9969aa 100644 --- a/deltachat-ios/Controller/AccountSetup/CertificateCheckController.swift +++ b/deltachat-ios/Controller/AccountSetup/CertificateCheckController.swift @@ -15,16 +15,6 @@ class CertificateCheckController: UITableViewController { var selectedIndex: Int? weak var delegate: CertificateCheckDelegate? - 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 staticCells: [UITableViewCell] { return options.map({ let cell = UITableViewCell(style: .default, reuseIdentifier: nil) @@ -46,13 +36,6 @@ class CertificateCheckController: UITableViewController { 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 tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { @@ -89,18 +72,10 @@ class CertificateCheckController: UITableViewController { currentValue = options[newIndex] } selectedIndex = index - } - - @objc private func okButtonPressed() { delegate?.onCertificateCheckChanged(newValue: currentValue) - navigationController?.popViewController(animated: true) - } - - @objc private func cancelButtonPressed() { - navigationController?.popViewController(animated: true) } - class ValueConverter { + class ValueConverter { static func convertHexToString(value: Int) -> String { switch value { case Int(DC_CERTCK_AUTO): diff --git a/deltachat-ios/Controller/AccountSetup/SecuritySettingsController.swift b/deltachat-ios/Controller/AccountSetup/SecuritySettingsController.swift index c1b1ad0d5..45968497e 100644 --- a/deltachat-ios/Controller/AccountSetup/SecuritySettingsController.swift +++ b/deltachat-ios/Controller/AccountSetup/SecuritySettingsController.swift @@ -12,16 +12,6 @@ class SecuritySettingsController: UITableViewController { private var selectedIndex: Int weak var delegate: SecuritySettingsDelegate? - private var okButton: UIBarButtonItem { - let button = UIBarButtonItem(title: String.localized("ok"), style: .done, target: self, action: #selector(okButtonPressed)) - return button - } - - private var cancelButton: UIBarButtonItem { - let button = UIBarButtonItem(title: String.localized("cancel"), style: .plain, target: self, action: #selector(cancelButtonPressed)) - return button - } - private var staticCells: [UITableViewCell] { return options.map { let cell = UITableViewCell(style: .default, reuseIdentifier: nil) @@ -40,12 +30,6 @@ class SecuritySettingsController: UITableViewController { 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 tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { @@ -71,15 +55,7 @@ class SecuritySettingsController: UITableViewController { cell.accessoryType = .checkmark } selectedIndex = indexPath.row - } - - @objc func okButtonPressed() { delegate?.onSecuritySettingsChanged(newValue: Int(options[selectedIndex])) - navigationController?.popViewController(animated: true) - } - - @objc func cancelButtonPressed() { - navigationController?.popViewController(animated: true) } } From fbf64de3d85e0dc4a4323ddcc6d08376e38eff8f Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Wed, 31 Jul 2024 21:43:21 +0200 Subject: [PATCH 9/9] cleanup member visibility --- .../AccountSetup/CertificateCheckController.swift | 9 +++------ .../AccountSetup/SecuritySettingsController.swift | 3 +-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/deltachat-ios/Controller/AccountSetup/CertificateCheckController.swift b/deltachat-ios/Controller/AccountSetup/CertificateCheckController.swift index f3e9969aa..31160a609 100644 --- a/deltachat-ios/Controller/AccountSetup/CertificateCheckController.swift +++ b/deltachat-ios/Controller/AccountSetup/CertificateCheckController.swift @@ -7,12 +7,9 @@ protocol CertificateCheckDelegate: AnyObject { class CertificateCheckController: UITableViewController { - var options = [Int(DC_CERTCK_AUTO), - Int(DC_CERTCK_STRICT), - Int(DC_CERTCK_ACCEPT_INVALID_CERTIFICATES)] - - var currentValue: Int - var selectedIndex: Int? + private let options = [Int(DC_CERTCK_AUTO), Int(DC_CERTCK_STRICT), Int(DC_CERTCK_ACCEPT_INVALID_CERTIFICATES)] + private var currentValue: Int + private var selectedIndex: Int? weak var delegate: CertificateCheckDelegate? var staticCells: [UITableViewCell] { diff --git a/deltachat-ios/Controller/AccountSetup/SecuritySettingsController.swift b/deltachat-ios/Controller/AccountSetup/SecuritySettingsController.swift index 45968497e..48bfddf9a 100644 --- a/deltachat-ios/Controller/AccountSetup/SecuritySettingsController.swift +++ b/deltachat-ios/Controller/AccountSetup/SecuritySettingsController.swift @@ -7,8 +7,7 @@ protocol SecuritySettingsDelegate: AnyObject { class SecuritySettingsController: UITableViewController { - private var options: [Int32] = [DC_SOCKET_AUTO, DC_SOCKET_SSL, DC_SOCKET_STARTTLS, DC_SOCKET_PLAIN] - + private let options: [Int32] = [DC_SOCKET_AUTO, DC_SOCKET_SSL, DC_SOCKET_STARTTLS, DC_SOCKET_PLAIN] private var selectedIndex: Int weak var delegate: SecuritySettingsDelegate?