Browse Source

added SecuritySettingsController

Bastian van de Wetering 6 years ago
parent
commit
c15dced65c

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

@@ -88,6 +88,7 @@
 		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 */; };
 		AE18F292228C17BC0007B1BE /* PortSettingsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE18F291228C17BC0007B1BE /* PortSettingsController.swift */; };
+		AE18F294228C602A0007B1BE /* SecuritySettingsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE18F293228C602A0007B1BE /* SecuritySettingsController.swift */; };
 		AE25F09022807AD800CDEA66 /* GroupNameCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE25F08F22807AD800CDEA66 /* GroupNameCell.swift */; };
 		AE38B31822672DFC00EC37A1 /* ActionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE38B31722672DFC00EC37A1 /* ActionCell.swift */; };
 		AE38B31A2267328200EC37A1 /* Colors.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE38B3192267328200EC37A1 /* Colors.swift */; };
@@ -283,6 +284,7 @@
 		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; lastKnownFileType = sourcecode.swift; path = ChatListController.swift; sourceTree = "<group>"; };
 		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>"; };
 		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>"; };
 		AE38B3192267328200EC37A1 /* Colors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Colors.swift; sourceTree = "<group>"; };
@@ -573,6 +575,7 @@
 			isa = PBXGroup;
 			children = (
 				AE18F291228C17BC0007B1BE /* PortSettingsController.swift */,
+				AE18F293228C602A0007B1BE /* SecuritySettingsController.swift */,
 			);
 			path = AccountSetup;
 			sourceTree = "<group>";
@@ -974,6 +977,7 @@
 				7070FB6A20FF345F000DC258 /* dc_saxparser.c in Sources */,
 				7070FB8A20FF4118000DC258 /* dc_log.c in Sources */,
 				7070FB9020FF4118000DC258 /* dc_stock.c in Sources */,
+				AE18F294228C602A0007B1BE /* SecuritySettingsController.swift in Sources */,
 				78ED838D21D577D000243125 /* events.swift in Sources */,
 				7070FB8F20FF4118000DC258 /* dc_loginparam.c in Sources */,
 				AE851AC7227C776400ED86F0 /* Location.swift in Sources */,

+ 91 - 0
deltachat-ios/Controller/AccountSetup/SecuritySettingsController.swift

@@ -0,0 +1,91 @@
+//
+//  SecuritySettingsController.swift
+//  deltachat-ios
+//
+//  Created by Bastian van de Wetering on 15.05.19.
+//  Copyright © 2019 Jonas Reinsch. All rights reserved.
+//
+
+import UIKit
+
+class SecuritySettingsController: UITableViewController {
+
+	private var options: [String]
+	private var selectedIndex: Int
+	private var backupIndex: Int
+
+	var onDismiss: ((String) -> Void)?
+
+	private var resetButton: UIBarButtonItem!
+
+	private var staticCells: [UITableViewCell] {
+		return options.map {
+			let cell = UITableViewCell(style: .default, reuseIdentifier: nil)
+			cell.textLabel?.text = $0
+			cell.selectionStyle = .none
+			return cell
+		}
+	}
+
+	init(options: [String], selectedOption: String) {
+		self.options = options
+		selectedIndex = options.index(of: selectedOption)!
+		backupIndex = selectedIndex
+		super.init(style: .grouped)
+	}
+
+	required init?(coder aDecoder: NSCoder) {
+		fatalError("init(coder:) has not been implemented")
+	}
+
+	override func viewDidLoad() {
+		super.viewDidLoad()
+		resetButton = UIBarButtonItem(title: "Reset", style: .done, target: self, action: #selector(resetButtonPressed))
+		resetButton.isEnabled = false
+		navigationItem.rightBarButtonItem = resetButton
+	}
+
+	override func viewWillDisappear(_ animated: Bool) {
+		let selectedOption = options[selectedIndex]
+		onDismiss?(selectedOption)
+	}
+
+	// MARK: - Table view data source
+
+	override func numberOfSections(in tableView: UITableView) -> Int {
+		return 1
+	}
+
+	override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
+		return options.count
+	}
+
+	override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
+		let cell = staticCells[indexPath.row]
+		if selectedIndex == indexPath.row {
+			cell.accessoryType = .checkmark
+		} else {
+			cell.accessoryType = .none
+		}
+		return cell
+	}
+
+	override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
+		// uselect old
+		if let cell = tableView.cellForRow(at: IndexPath(item: selectedIndex, section: 0)) {
+			cell.accessoryType = .none
+		}
+		// select new
+		if let cell = tableView.cellForRow(at: indexPath) {
+			cell.accessoryType = .checkmark
+		}
+		selectedIndex = indexPath.row
+		resetButton.isEnabled = true
+	}
+
+	@objc func resetButtonPressed() {
+		selectedIndex = backupIndex
+		tableView.reloadData()
+	}
+
+}

+ 22 - 19
deltachat-ios/Controller/AccountSetupController.swift

@@ -65,16 +65,20 @@ class AccountSetupController: UITableViewController {
 		cell.accessoryType = .disclosureIndicator
 		cell.detailTextLabel?.text = MRConfig.mailPort ?? MRConfig.configuredMailPort
     cell.accessibilityIdentifier = "IMAPPortCell"
+		cell.selectionStyle = .none 
     return cell
   }()
 
-  lazy var imapSecurityCell: TextFieldCell = {
+  lazy var imapSecurityCell: UITableViewCell = {
     let text = "\(MRConfig.getImapSecurity())"
-    let cell = TextFieldCell(description: "IMAP Security", placeholder: text, delegate: self)
+		let cell = UITableViewCell(style: .value1, reuseIdentifier: nil)
+		cell.textLabel?.text = "IMAP Security"
+		// let cell = TextFieldCell(description: "IMAP Security", placeholder: text, delegate: self)
     cell.accessibilityIdentifier = "IMAPSecurityCell"
-    cell.textField.tag = 5
-    cell.textField.keyboardType = UIKeyboardType.numberPad
-    return cell
+		cell.accessoryType = .disclosureIndicator
+		cell.detailTextLabel?.text = "\(MRConfig.getImapSecurity())"
+		cell.selectionStyle = .none
+		return cell
   }()
 
   lazy var smtpServerCell: TextFieldCell = {
@@ -93,10 +97,11 @@ class AccountSetupController: UITableViewController {
 
   lazy var smtpPortCell: UITableViewCell = {
 		let cell = UITableViewCell(style: .value1, reuseIdentifier: nil)
-		cell.textLabel?.text = "IMAP Port"
+		cell.textLabel?.text = "SMTP Port"
 		cell.accessoryType = .disclosureIndicator
 		cell.detailTextLabel?.text = MRConfig.sendPort ?? MRConfig.configuredSendPort
 		cell.accessibilityIdentifier = "SMTPPortCell"
+		cell.selectionStyle = .none
     return cell
   }()
 
@@ -107,12 +112,14 @@ class AccountSetupController: UITableViewController {
     return cell
   }()
 
-  lazy var smtpSecurityCell: TextFieldCell = {
-    let text = "\(MRConfig.getSmtpSecurity())"
-    let cell = TextFieldCell(description: "SMTP Security", placeholder: text, delegate: self)
-    cell.accessibilityIdentifier = "SMTPSecurityCell"
-    cell.textField.tag = 10
-    cell.textField.keyboardType = UIKeyboardType.numberPad
+  lazy var smtpSecurityCell: UITableViewCell = {
+    let security = "\(MRConfig.getSmtpSecurity())"
+		let cell = UITableViewCell(style: .value1, reuseIdentifier: nil)
+		cell.textLabel?.text = "SMTP Security"
+		cell.detailTextLabel?.text = security
+	  cell.accessibilityIdentifier = "SMTPSecurityCell"
+		cell.accessoryType = .disclosureIndicator
+		cell.selectionStyle = .none
     return cell
   }()
 
@@ -130,7 +137,7 @@ class AccountSetupController: UITableViewController {
     smtpUserCell,
     smtpPortCell,
     smtpPasswordCell,
-    smtpSecurityCell,
+    smtpSecurityCell
   ]
 
   private var advancedSectionShowing: Bool = false
@@ -262,15 +269,11 @@ class AccountSetupController: UITableViewController {
 			coordinator?.showImapPortOptions()
 		} else if tappedCell.accessibilityIdentifier == "SMTPPortCell" {
 			coordinator?.showSmtpPortsOptions()
-		} else if tappedCell.accessibilityIdentifier == "IMAPSecurity" {
+		} else if tappedCell.accessibilityIdentifier == "IMAPSecurityCell" {
 			coordinator?.showImapSecurityOptions()
-		} else if tappedCell.accessibilityIdentifier == "SMTPSecurity" {
+		} else if tappedCell.accessibilityIdentifier == "SMTPSecurityCell" {
 			coordinator?.showSmptpSecurityOptions()
 		}
-
-
-
-
   }
 
   private func toggleAdvancedSection(button: UILabel) {

+ 16 - 1
deltachat-ios/Coordinator/AppCoordinator.swift

@@ -221,7 +221,14 @@ class AccountSetupCoordinator: Coordinator {
 	}
 
 	func showImapSecurityOptions() {
-
+		let currentSecurityOption = MRConfig.getImapSecurity()
+		print(currentSecurityOption)
+		let securitySettingsController = SecuritySettingsController(options: ["Automatic", "SSL / TLS", "STARTTLS", "OFF"], selectedOption: "OFF")
+		securitySettingsController.onDismiss = {
+			option in
+			MRConfig.setSmtpSecurity(smptpFlags: 0) // TODO: needs mapping from option to flag
+		}
+		navigationController.pushViewController(securitySettingsController, animated: true)
 	}
 
 	func showSmtpPortsOptions() {
@@ -237,6 +244,14 @@ class AccountSetupCoordinator: Coordinator {
 	}
 
 	func showSmptpSecurityOptions() {
+		let currentSecurityOption = MRConfig.getSmtpSecurity()
+		print(currentSecurityOption)
+		let securitySettingsController = SecuritySettingsController(options: ["Automatic", "SSL / TLS", "STARTTLS", "OFF"], selectedOption: "OFF")
+		securitySettingsController.onDismiss = {
+			option in
+			MRConfig.setSmtpSecurity(smptpFlags: 0) // TODO: needs mapping from option to flag
+		}
+		navigationController.pushViewController(securitySettingsController, animated: true)
 
 	}