|
@@ -109,6 +109,14 @@ class AccountSetupController: UITableViewController {
|
|
return cell
|
|
return cell
|
|
}()
|
|
}()
|
|
|
|
|
|
|
|
+ lazy var advancedShowCell: UITableViewCell = {
|
|
|
|
+ let cell = UITableViewCell(style: .value1, reuseIdentifier: nil)
|
|
|
|
+ cell.textLabel?.text = String.localized("menu_advanced")
|
|
|
|
+ cell.accessoryType = .disclosureIndicator
|
|
|
|
+ cell.accessibilityIdentifier = "advancedShowCell"
|
|
|
|
+ return cell
|
|
|
|
+ }()
|
|
|
|
+
|
|
lazy var imapServerCell: TextFieldCell = {
|
|
lazy var imapServerCell: TextFieldCell = {
|
|
let cell = TextFieldCell(descriptionID: "login_imap_server",
|
|
let cell = TextFieldCell(descriptionID: "login_imap_server",
|
|
placeholder: DcConfig.mailServer ?? DcConfig.configuredMailServer,
|
|
placeholder: DcConfig.mailServer ?? DcConfig.configuredMailServer,
|
|
@@ -215,6 +223,7 @@ class AccountSetupController: UITableViewController {
|
|
private lazy var basicSectionCells: [UITableViewCell] = [emailCell, passwordCell]
|
|
private lazy var basicSectionCells: [UITableViewCell] = [emailCell, passwordCell]
|
|
private lazy var restoreCells: [UITableViewCell] = [restoreCell]
|
|
private lazy var restoreCells: [UITableViewCell] = [restoreCell]
|
|
private lazy var advancedSectionCells: [UITableViewCell] = [
|
|
private lazy var advancedSectionCells: [UITableViewCell] = [
|
|
|
|
+ advancedShowCell,
|
|
imapServerCell,
|
|
imapServerCell,
|
|
imapUserCell,
|
|
imapUserCell,
|
|
imapPortCell,
|
|
imapPortCell,
|
|
@@ -301,33 +310,18 @@ class AccountSetupController: UITableViewController {
|
|
} else if sections[section] == dangerSection {
|
|
} else if sections[section] == dangerSection {
|
|
return dangerCells.count
|
|
return dangerCells.count
|
|
} else {
|
|
} else {
|
|
- return advancedSectionShowing ? advancedSectionCells.count : 0
|
|
|
|
|
|
+ return advancedSectionShowing ? advancedSectionCells.count : 1
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
override func tableView(_: UITableView, titleForHeaderInSection section: Int) -> String? {
|
|
override func tableView(_: UITableView, titleForHeaderInSection section: Int) -> String? {
|
|
- if sections[section] == advancedSection {
|
|
|
|
- return String.localized("menu_advanced")
|
|
|
|
- } else if sections[section] == dangerSection {
|
|
|
|
|
|
+ if sections[section] == dangerSection {
|
|
return String.localized("danger")
|
|
return String.localized("danger")
|
|
} else {
|
|
} else {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- override func tableView(_: UITableView, viewForHeaderInSection section: Int) -> UIView? {
|
|
|
|
- if sections[section] == advancedSection {
|
|
|
|
- // Advanced Header
|
|
|
|
- let advancedView = AdvancedSectionHeader()
|
|
|
|
- advancedView.handleTap = toggleAdvancedSection
|
|
|
|
- // set tapHandler
|
|
|
|
- return advancedView
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
- return nil
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
override func tableView(_: UITableView, heightForHeaderInSection _: Int) -> CGFloat {
|
|
override func tableView(_: UITableView, heightForHeaderInSection _: Int) -> CGFloat {
|
|
return 36.0
|
|
return 36.0
|
|
}
|
|
}
|
|
@@ -336,11 +330,7 @@ class AccountSetupController: UITableViewController {
|
|
if sections[section] == basicSection {
|
|
if sections[section] == basicSection {
|
|
return String.localized("login_no_servers_hint")
|
|
return String.localized("login_no_servers_hint")
|
|
} else if sections[section] == advancedSection {
|
|
} else if sections[section] == advancedSection {
|
|
- if advancedSectionShowing {
|
|
|
|
- return String.localized("login_subheader")
|
|
|
|
- } else {
|
|
|
|
- return nil
|
|
|
|
- }
|
|
|
|
|
|
+ return String.localized("login_subheader")
|
|
} else {
|
|
} else {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
@@ -376,6 +366,8 @@ class AccountSetupController: UITableViewController {
|
|
restoreBackup()
|
|
restoreBackup()
|
|
} else if tappedCell.accessibilityIdentifier == "deleteAccountCell" {
|
|
} else if tappedCell.accessibilityIdentifier == "deleteAccountCell" {
|
|
deleteAccount()
|
|
deleteAccount()
|
|
|
|
+ } else if tappedCell.accessibilityIdentifier == "advancedShowCell" {
|
|
|
|
+ toggleAdvancedSection()
|
|
} else if tappedCell.accessibilityIdentifier == "IMAPPortCell" {
|
|
} else if tappedCell.accessibilityIdentifier == "IMAPPortCell" {
|
|
coordinator?.showImapPortOptions()
|
|
coordinator?.showImapPortOptions()
|
|
} else if tappedCell.accessibilityIdentifier == "SMTPPortCell" {
|
|
} else if tappedCell.accessibilityIdentifier == "SMTPPortCell" {
|
|
@@ -387,26 +379,21 @@ class AccountSetupController: UITableViewController {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private func toggleAdvancedSection(button: UILabel) {
|
|
|
|
|
|
+ private func toggleAdvancedSection() {
|
|
let willShow = !advancedSectionShowing
|
|
let willShow = !advancedSectionShowing
|
|
|
|
|
|
- // extract indexPaths from advancedCells
|
|
|
|
guard let advancedSectionIndex = sections.firstIndex(of: advancedSection) else { return }
|
|
guard let advancedSectionIndex = sections.firstIndex(of: advancedSection) else { return }
|
|
- let advancedIndexPaths: [IndexPath] = advancedSectionCells.indices.map { IndexPath(row: $0, section: advancedSectionIndex) }
|
|
|
|
|
|
+ var advancedIndexPaths: [IndexPath] = advancedSectionCells.indices.map { IndexPath(row: $0, section: advancedSectionIndex) }
|
|
|
|
+ advancedIndexPaths.removeFirst() // do not touch the first item that is the switch itself
|
|
|
|
|
|
- // advancedSectionCells.indices.map({indexPaths.append(IndexPath(row: $0, section: 1))}
|
|
|
|
-
|
|
|
|
- // set flag before delete/insert operation, because cellForRowAt will be triggered and uses this flag
|
|
|
|
- advancedSectionShowing = willShow
|
|
|
|
-
|
|
|
|
- button.text = String.localized(willShow ? "hide" : "pref_notifications_show")
|
|
|
|
|
|
+ advancedSectionShowing = willShow // set flag before delete/insert, because cellForRowAt will be triggered and uses this flag
|
|
|
|
|
|
if willShow {
|
|
if willShow {
|
|
tableView.insertRows(at: advancedIndexPaths, with: .fade)
|
|
tableView.insertRows(at: advancedIndexPaths, with: .fade)
|
|
} else {
|
|
} else {
|
|
tableView.deleteRows(at: advancedIndexPaths, with: .fade)
|
|
tableView.deleteRows(at: advancedIndexPaths, with: .fade)
|
|
}
|
|
}
|
|
- tableView.reloadData() // to re-organize footer view (without that sometimes advanced section footer is still visible)
|
|
|
|
|
|
+ tableView.reloadData() // needed to force a redraw
|
|
}
|
|
}
|
|
|
|
|
|
@objc private func loginButtonPressed() {
|
|
@objc private func loginButtonPressed() {
|
|
@@ -689,56 +676,3 @@ extension AccountSetupController: UITextFieldDelegate {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
-class AdvancedSectionHeader: UIView {
|
|
|
|
- var handleTap: ((UILabel) -> Void)?
|
|
|
|
-
|
|
|
|
- private var label: UILabel = {
|
|
|
|
- let label = UILabel()
|
|
|
|
- label.text = String.localized("menu_advanced").uppercased()
|
|
|
|
- label.font = UIFont.systemFont(ofSize: 15)
|
|
|
|
- label.textColor = UIColor.darkGray
|
|
|
|
- return label
|
|
|
|
- }()
|
|
|
|
-
|
|
|
|
- /*
|
|
|
|
- why UILabel, why no UIButton? For unknown reasons UIButton's target function was not triggered when one of the textfields in the tableview was active -> used label as workaround
|
|
|
|
- */
|
|
|
|
- private lazy var toggleButton: UILabel = {
|
|
|
|
- let label = UILabel()
|
|
|
|
- label.text = String.localized("pref_notifications_show")
|
|
|
|
- label.font = UIFont.systemFont(ofSize: 15, weight: .medium)
|
|
|
|
- label.textColor = UIColor.systemBlue
|
|
|
|
- return label
|
|
|
|
- }()
|
|
|
|
-
|
|
|
|
- init() {
|
|
|
|
- super.init(frame: .zero) // will be constraint from tableViewDelegate
|
|
|
|
- setupSubviews()
|
|
|
|
- let tap = UITapGestureRecognizer(target: self, action: #selector(viewTapped)) // use this if the whole header is supposed to be clickable
|
|
|
|
- addGestureRecognizer(tap)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- required init?(coder _: NSCoder) {
|
|
|
|
- fatalError("init(coder:) has not been implemented")
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- func setupSubviews() {
|
|
|
|
- addSubview(label)
|
|
|
|
- label.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
- label.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 15).isActive = true
|
|
|
|
- label.centerYAnchor.constraint(equalTo: centerYAnchor, constant: 0).isActive = true
|
|
|
|
- addSubview(toggleButton)
|
|
|
|
- toggleButton.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
- toggleButton.leadingAnchor.constraint(equalTo: trailingAnchor, constant: -60).isActive = true // since button will change title it should be left aligned
|
|
|
|
- toggleButton.centerYAnchor.constraint(equalTo: label.centerYAnchor, constant: 0).isActive = true
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @objc func buttonTapped(_: UIButton) {
|
|
|
|
- // handleTap?(button)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @objc func viewTapped() {
|
|
|
|
- handleTap?(toggleButton)
|
|
|
|
- }
|
|
|
|
-}
|
|
|