Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add proxy to onboarding (#2390) #2405

Merged
merged 3 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Unreleased

- fix: show forward-icon on iOS 15 and older
- Add an option to use Proxy-servers (#2382)
- Add an option to use Proxy-servers (#2382, #2390)
- Show on Chatlist if there are Proxy-servers (#2383)
- Detect Proxy-servers in Chat-messages (#2389)
- Share Proxy-servers with your friends, family and allies (#2394)
Expand Down
22 changes: 22 additions & 0 deletions deltachat-ios/Controller/AccountSetup/AccountSetupController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class AccountSetupController: UITableViewController {
private let tagSmtpSecurityCell = 11
private let tagCertCheckCell = 12
private let tagViewLogCell = 15
private let tagProxyCell = 16

private let tagTextFieldEmail = 100
private let tagTextFieldPassword = 200
Expand Down Expand Up @@ -53,6 +54,7 @@ class AccountSetupController: UITableViewController {
smtpServerCell,
smtpPortCell,
certCheckCell,
proxyCell,
viewLogCell
]
private let editView: Bool
Expand Down Expand Up @@ -239,6 +241,14 @@ class AccountSetupController: UITableViewController {

lazy var certValue: Int = dcContext.certificateChecks

lazy var proxyCell: UITableViewCell = {
let cell = UITableViewCell(style: .value1, reuseIdentifier: nil)
cell.textLabel?.text = String.localized("proxy_settings")
cell.tag = tagProxyCell
cell.accessoryType = .disclosureIndicator
return cell
}()

lazy var viewLogCell: UITableViewCell = {
let cell = UITableViewCell(style: .value1, reuseIdentifier: nil)
cell.textLabel?.text = String.localized("pref_view_log")
Expand Down Expand Up @@ -296,6 +306,11 @@ class AccountSetupController: UITableViewController {
super.viewWillAppear(animated)
initSelectionCells()
handleLoginButton()
updateCells()
}

private func updateCells() {
proxyCell.detailTextLabel?.text = dcContext.isProxyEnabled ? String.localized("on") : nil
}

override func viewWillDisappear(_ animated: Bool) {
Expand Down Expand Up @@ -365,6 +380,8 @@ class AccountSetupController: UITableViewController {
case tagViewLogCell:
tableView.deselectRow(at: indexPath, animated: false)
showLogViewController()
case tagProxyCell:
showProxySettings()
default:
break
}
Expand Down Expand Up @@ -587,6 +604,11 @@ class AccountSetupController: UITableViewController {

// MARK: - coordinator

private func showProxySettings() {
let proxySettingsController = ProxySettingsViewController(dcContext: dcContext, dcAccounts: dcAccounts)
navigationController?.pushViewController(proxySettingsController, animated: true)
}

private func showLogViewController() {
let controller = LogViewController(dcContext: dcContext)
navigationController?.pushViewController(controller, animated: true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,30 @@ class InstantOnboardingViewController: UIViewController {

private var providerHostURL: URL
private var qrCodeData: String?
private lazy var menuButton: UIBarButtonItem = {
let image: UIImage?
if #available(iOS 13.0, *) {
image = UIImage(systemName: "ellipsis.circle")
} else {
image = UIImage(named: "ic_more")
}

let menuButton = UIBarButtonItem(image: image, style: .plain, target: self, action: #selector(InstantOnboardingViewController.showMenu(_:)))
menuButton.tintColor = DcColors.primary
return menuButton
}()

private lazy var proxyShieldButton: UIBarButtonItem = {
let button: UIBarButtonItem

if #available(iOS 13, *) {
button = UIBarButtonItem(image: UIImage(systemName: "checkmark.shield"), style: .plain, target: self, action: #selector(InstantOnboardingViewController.showProxySettings(_:)))
} else {
button = UIBarButtonItem(title: String.localized("proxy_settings"), style: .plain, target: self, action: #selector(InstantOnboardingViewController.showProxySettings(_:)))
}
button.tintColor = DcColors.primary
return button
}()

var progressAlertHandler: ProgressAlertHandler?

Expand Down Expand Up @@ -61,6 +85,10 @@ class InstantOnboardingViewController: UIViewController {

NotificationCenter.default.addObserver(self, selector: #selector(InstantOnboardingViewController.keyboardWillShow(_:)), name: UIResponder.keyboardWillShowNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(InstantOnboardingViewController.keyboardWillHide(_:)), name: UIResponder.keyboardWillHideNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(InstantOnboardingViewController.connectivityChanged(_:)), name: Event.connectivityChanged, object: nil)

navigationItem.setRightBarButtonItems([menuButton], animated: true)
updateProxyButton()
}

required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") }
Expand Down Expand Up @@ -93,6 +121,12 @@ class InstantOnboardingViewController: UIViewController {
contentView?.nameTextField.becomeFirstResponder()
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

updateMenuButtons()
}

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)

Expand All @@ -108,6 +142,12 @@ class InstantOnboardingViewController: UIViewController {
contentView?.validateTextfield(text: text)
}

@objc func connectivityChanged(_ notification: Notification) {
DispatchQueue.main.async { [weak self] in
self?.updateMenuButtons()
}
}

// MARK: - actions
private func galleryButtonPressed(_ action: UIAlertAction) {
mediaPicker.showPhotoGallery()
Expand Down Expand Up @@ -193,6 +233,46 @@ class InstantOnboardingViewController: UIViewController {
present(alertController, animated: true)
}

@objc private func showMenu(_ sender: Any) {
let sheet = UIAlertController(title: nil, message: nil, preferredStyle: .safeActionSheet)

let showProxySettings = UIAlertAction(title: String.localized("proxy_settings"), style: .default) { [weak self] _ in
self?.showProxySettings(sender)
}

let cancelAction = UIAlertAction(title: String.localized("cancel"), style: .cancel)

sheet.addAction(showProxySettings)
sheet.addAction(cancelAction)

present(sheet, animated: true)
}

@objc private func showProxySettings(_ sender: Any) {
let proxySettingsController = ProxySettingsViewController(dcContext: dcContext, dcAccounts: dcAccounts)
navigationController?.pushViewController(proxySettingsController, animated: true)
}

private func updateMenuButtons() {
if dcContext.getProxies().isEmpty {
navigationItem.setRightBarButtonItems([menuButton], animated: true)
} else {
navigationItem.setRightBarButtonItems([proxyShieldButton], animated: true)
}

updateProxyButton()
}

private func updateProxyButton() {
guard #available(iOS 13, *) else { return }

if dcContext.isProxyEnabled {
proxyShieldButton.image = UIImage(systemName: "checkmark.shield")
} else {
proxyShieldButton.image = UIImage(systemName: "shield")
}
}

// MARK: - Notifications
@objc private func keyboardWillShow(_ notification: Notification) {
guard let userInfo = notification.userInfo,
Expand Down
Loading