Skip to content

Commit

Permalink
make SecuritySettingsController dumber and leave details to the delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
r10s committed Jul 26, 2024
1 parent 9856c52 commit c79725f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
38 changes: 22 additions & 16 deletions deltachat-ios/Controller/AccountSetup/AccountSetupController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

Expand All @@ -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)
}

Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ import UIKit
import DcCore

protocol SecuritySettingsDelegate: AnyObject {
func onSecuritySettingsChanged(type: SecurityType, newValue: Int)
func onSecuritySettingsChanged(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
weak var delegate: SecuritySettingsDelegate?

private var okButton: UIBarButtonItem {
Expand All @@ -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
Expand Down Expand Up @@ -76,7 +74,7 @@ class SecuritySettingsController: UITableViewController {
}

@objc func okButtonPressed() {
delegate?.onSecuritySettingsChanged(type: securityType, newValue: Int(options[selectedIndex]))
delegate?.onSecuritySettingsChanged(newValue: Int(options[selectedIndex]))
navigationController?.popViewController(animated: true)
}

Expand All @@ -85,11 +83,6 @@ class SecuritySettingsController: UITableViewController {
}
}

enum SecurityType {
case IMAPSecurity
case SMTPSecurity
}

class SecurityConverter {
static func getSocketName(value: Int32) -> String {
switch value {
Expand Down

0 comments on commit c79725f

Please sign in to comment.