Skip to content

Commit

Permalink
[WIP] Sketch ProxySettings-screen (#2382)
Browse files Browse the repository at this point in the history
  • Loading branch information
zeitschlag committed Nov 5, 2024
1 parent a4946b4 commit 7459f02
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 4 deletions.
10 changes: 9 additions & 1 deletion deltachat-ios.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 54;
objectVersion = 70;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -615,6 +615,10 @@
E23C80FA36453692862D4A90 /* Pods_deltachat_iosTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_deltachat_iosTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */

/* Begin PBXFileSystemSynchronizedRootGroup section */
D8F809C52CD93EA1002CAAC2 /* Proxy */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = Proxy; sourceTree = "<group>"; };
/* End PBXFileSystemSynchronizedRootGroup section */

/* Begin PBXFrameworksBuildPhase section */
30E8F20D2447285600CE2C90 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
Expand Down Expand Up @@ -1097,6 +1101,7 @@
B28D25882913CE8600B9067F /* Settings */ = {
isa = PBXGroup;
children = (
D8F809C52CD93EA1002CAAC2 /* Proxy */,
78E45E3921D3CFBC00D4B15E /* SettingsViewController.swift */,
B2D4B63A29C38D1900B47DA8 /* ChatsAndMediaViewController.swift */,
B2172F3B29C125F2002C289E /* AdvancedViewController.swift */,
Expand Down Expand Up @@ -1215,6 +1220,9 @@
30E8F2192447285600CE2C90 /* PBXTargetDependency */,
B2D0E4982B93A4B200791949 /* PBXTargetDependency */,
);
fileSystemSynchronizedGroups = (
D8F809C52CD93EA1002CAAC2 /* Proxy */,
);
name = "deltachat-ios";
productName = "deltachat-ios";
productReference = 7A9FB1401FB061E2001FEA36 /* deltachat-ios.app */;
Expand Down
11 changes: 8 additions & 3 deletions deltachat-ios/Controller/Settings/AdvancedViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,9 @@ internal final class AdvancedViewController: UITableViewController {
self?.showAccountSettingsController()
}
case .proxySettings:
//TODO: Show ProxySettingsViewController
break

Utils.authenticateDeviceOwner(reason: String.localized("proxy_settings")) { [weak self] in
self?.showProxySettings()
}
case .defaultTagValue: break
}
}
Expand Down Expand Up @@ -397,6 +397,11 @@ internal final class AdvancedViewController: UITableViewController {
navigationController?.pushViewController(controller, animated: true)
}

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

private func showManageKeysDialog() {
let alert = UIAlertController(title: String.localized("pref_manage_keys"), message: nil, preferredStyle: .safeActionSheet)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import UIKit
import DcCore

enum ProxySettingsSection: Int {
case enableProxies = 1
case proxies
case add

var title: String? {
switch self {
case .enableProxies:
return nil
case .proxies:
return "Proxies"
case .add:
return nil
}
}
}

enum ProxySettingsItem {
case enable
case entry(DcLot) // dcContext.checkQr(proxyUrl); DcLot? URL?
case add
}

class ProxySettingsViewController: UIViewController {

let dcContext: DcContext
let tableView: UITableView
let proxies: [String]

init(dcContext: DcContext) {

self.dcContext = dcContext
self.proxies = dcContext.getProxies()
tableView = UITableView(frame: .zero, style: .grouped)
tableView.translatesAutoresizingMaskIntoConstraints = false

tableView.register(SwitchCell.self, forCellReuseIdentifier: SwitchCell.reuseIdentifier)
tableView.register(ActionCell.self, forCellReuseIdentifier: ActionCell.reuseIdentifier)
tableView.register(ProxyTableViewCell.self, forCellReuseIdentifier: ProxyTableViewCell.reuseIdentifier)

super.init(nibName: nil, bundle: nil)

tableView.delegate = self
tableView.dataSource = self

view.addSubview(tableView)
setupConstraints()
}

required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }

private func setupConstraints() {
let constraints = [
tableView.topAnchor.constraint(equalTo: view.topAnchor),
tableView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor),
view.safeAreaLayoutGuide.trailingAnchor.constraint(equalTo: tableView.trailingAnchor),
view.bottomAnchor.constraint(equalTo: tableView.bottomAnchor),
]

NSLayoutConstraint.activate(constraints)
}

private func selectProxy(at indexPath: IndexPath) {
// TODO: set selected proxy
}

private func addProxy() {
// TODO: Show alert with Textfield (alternative: Dedicated Controller?) to add a new proxy-URL, reloadList afterwards
}

private func deleteProxy(at indexPath: IndexPath) {
// TODO: Delete Proxy, if proxy was selected: Deselect proxy
}

private func enableProxies() {
// TODO: Enable Proxies in general
}

private func disableProxies() {
// TODO: Enable Proxies in general
}
}

extension ProxySettingsViewController: UITableViewDataSource {
func numberOfSections(in tableView: UITableView) -> Int {
if proxies.isEmpty == false {
return 3
} else {
return 2
}
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if proxies.isEmpty == false {
if section == ProxySettingsSection.enableProxies.rawValue {
return 1
} else /* if section == ProxySettingsSection.add.rawValue */ {
return 1
}
} else {
if section == ProxySettingsSection.enableProxies.rawValue {
return 1
} else if section == ProxySettingsSection.proxies.rawValue {
return proxies.count
} else /*if section == ProxySettingsSection.add.rawValue*/ {
return 1
}
}
}


func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if proxies.isEmpty == false {
if indexPath.section == ProxySettingsSection.enableProxies.rawValue {
// SwitchCell with enable/disable
} else /* if indexPath.section == ProxySettingsSection.add.rawValue */ {
// ActionCell with add
}
} else {
if indexPath.section == ProxySettingsSection.enableProxies.rawValue {
// SwitchCell with enable/disable
} else if indexPath.section == ProxySettingsSection.proxies.rawValue {
// ProxyCell with proxies[indexPath.row]
} else /*if indexPath.section == ProxySettingsSection.add.rawValue*/ {
// ActionCell with add
}
}
return UITableViewCell()
}
}

extension ProxySettingsViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if proxies.isEmpty == false {
if indexPath.section == ProxySettingsSection.enableProxies.rawValue {
// enable/disable proxy and toggle switch
} else /* if indexPath.section == ProxySettingsSection.add.rawValue */ {
// open dialog to add a new proxy
}
} else {
if indexPath.section == ProxySettingsSection.enableProxies.rawValue {
// enable/disable proxy and toggle switch
} else if indexPath.section == ProxySettingsSection.proxies.rawValue {
// select proxy
} else /*if indexPath.section == ProxySettingsSection.add.rawValue*/ {
// open dialog to add a new proxy
}
}

tableView.deselectRow(at: indexPath, animated: true)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import UIKit

class ProxyTableViewCell: UITableViewCell {
static let reuseIdentifier = "ProxyTableViewCell"

// make it look like the Android-version


}
5 changes: 5 additions & 0 deletions deltachat-ios/Helper/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ struct Utils {
}

public static func authenticateDeviceOwner(reason: String, callback: @escaping () -> Void) {

#if DEBUG
return callback()
#endif

let localAuthenticationContext = LAContext()
var error: NSError?
if localAuthenticationContext.canEvaluatePolicy(.deviceOwnerAuthentication, error: &error) {
Expand Down
1 change: 1 addition & 0 deletions deltachat-ios/View/SwitchCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class SwitchCell: UITableViewCell {

var uiSwitch: UISwitch
var action: ((SwitchCell) -> Void)?
static let reuseIdentifier = "SwitchCell"

var isOn: Bool {
return uiSwitch.isOn
Expand Down

0 comments on commit 7459f02

Please sign in to comment.