Cut 4 gateway checkmarks down to 2 toogles

This commit is contained in:
Davide De Rosa 2019-04-30 13:10:22 +02:00
parent c6fbdca342
commit 5f0d4960a5
2 changed files with 73 additions and 59 deletions

View File

@ -418,7 +418,7 @@
</subviews>
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="FieldTableViewCell" textLabel="chG-HK-4WY" style="IBUITableViewCellStyleDefault" id="JNm-q5-qBn" customClass="FieldTableViewCell" customModule="Passepartout" customModuleProvider="target">
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="ToggleTableViewCell" textLabel="chG-HK-4WY" style="IBUITableViewCellStyleDefault" id="JNm-q5-qBn" customClass="ToggleTableViewCell" customModule="Passepartout" customModuleProvider="target">
<rect key="frame" x="0.0" y="99.5" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="JNm-q5-qBn" id="NG6-Jk-qkq">
@ -435,6 +435,23 @@
</subviews>
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="FieldTableViewCell" textLabel="dXB-Id-HH0" style="IBUITableViewCellStyleDefault" id="3Zq-6c-3Yc" customClass="FieldTableViewCell" customModule="Passepartout" customModuleProvider="target">
<rect key="frame" x="0.0" y="143.5" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="3Zq-6c-3Yc" id="h7B-7Q-NQr">
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="dXB-Id-HH0">
<rect key="frame" x="16" y="0.0" width="343" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
</tableViewCell>
</prototypes>
<connections>
<outlet property="dataSource" destination="BCT-c7-ovS" id="b8X-oR-HW4"/>

View File

@ -110,7 +110,7 @@ class NetworkSettingsViewController: UITableViewController {
// rows
model.set([.gateway, .dns, .proxy], in: .choices)
model.set([.gatewayAll, .gatewayIPv4, .gatewayIPv6, .gatewayNone], in: .manualGateway)
model.set([.gatewayIPv4, .gatewayIPv6], in: .manualGateway)
var dnsRows: [RowType] = Array(repeating: .dnsAddress, count: networkSettings.dnsServers?.count ?? 0)
dnsRows.insert(.dnsDomain, at: 0)
@ -265,13 +265,9 @@ extension NetworkSettingsViewController {
case proxy
case gatewayAll
case gatewayIPv4
case gatewayIPv6
case gatewayNone
case dnsDomain
@ -330,33 +326,20 @@ extension NetworkSettingsViewController {
cell.rightText = networkChoices.proxy.description
return cell
case .gatewayAll, .gatewayIPv4, .gatewayIPv6, .gatewayNone:
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
var policies: [SessionProxy.RoutingPolicy]?
switch row {
case .gatewayAll:
cell.leftText = L10n.Global.Cells.enabled
policies = [.IPv4, .IPv6]
case .gatewayIPv4:
cell.leftText = "IPv4"
policies = [.IPv4]
case .gatewayIPv6:
cell.leftText = "IPv6"
policies = [.IPv6]
case .gatewayNone:
cell.leftText = L10n.Global.Cells.disabled
default:
break
}
cell.applyChecked(networkSettings.gatewayPolicies == policies, Theme.current)
cell.isTappable = (networkChoices.gateway == .manual)
case .gatewayIPv4:
let cell = Cells.toggle.dequeue(from: tableView, for: indexPath, tag: row.rawValue, delegate: self)
cell.caption = "IPv4"
cell.toggle.isEnabled = (networkChoices.gateway == .manual)
cell.isOn = networkSettings.gatewayPolicies?.contains(.IPv4) ?? false
return cell
case .gatewayIPv6:
let cell = Cells.toggle.dequeue(from: tableView, for: indexPath, tag: row.rawValue, delegate: self)
cell.caption = "IPv6"
cell.toggle.isEnabled = (networkChoices.gateway == .manual)
cell.isOn = networkSettings.gatewayPolicies?.contains(.IPv6) ?? false
return cell
case .dnsDomain:
let cell = Cells.field.dequeue(from: tableView, for: indexPath)
cell.caption = L10n.Configuration.Cells.DnsDomain.caption
@ -508,34 +491,6 @@ extension NetworkSettingsViewController {
}
navigationController?.pushViewController(vc, animated: true)
case .gatewayAll:
guard networkChoices.gateway == .manual else {
return
}
networkSettings.gatewayPolicies = [.IPv4, .IPv6]
tableView.reloadData()
case .gatewayIPv4:
guard networkChoices.gateway == .manual else {
return
}
networkSettings.gatewayPolicies = [.IPv4]
tableView.reloadData()
case .gatewayIPv6:
guard networkChoices.gateway == .manual else {
return
}
networkSettings.gatewayPolicies = [.IPv6]
tableView.reloadData()
case .gatewayNone:
guard networkChoices.gateway == .manual else {
return
}
networkSettings.gatewayPolicies = nil
tableView.reloadData()
case .dnsAddAddress:
tableView.deselectRow(at: indexPath, animated: true)
@ -559,6 +514,39 @@ extension NetworkSettingsViewController {
}
}
private func handle(row: RowType, cell: ToggleTableViewCell) {
switch row {
case .gatewayIPv4:
guard networkChoices.gateway == .manual else {
return
}
var policies = networkSettings.gatewayPolicies ?? []
if cell.toggle.isOn {
policies.append(.IPv4)
} else {
policies.removeAll { $0 == .IPv4 }
}
policies.sort { $0.rawValue < $1.rawValue }
networkSettings.gatewayPolicies = policies
case .gatewayIPv6:
guard networkChoices.gateway == .manual else {
return
}
var policies = networkSettings.gatewayPolicies ?? []
if cell.toggle.isOn {
policies.append(.IPv6)
} else {
policies.removeAll { $0 == .IPv6 }
}
policies.sort { $0.rawValue < $1.rawValue }
networkSettings.gatewayPolicies = policies
default:
break
}
}
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
switch model.row(at: indexPath) {
case .dnsAddress, .proxyBypass:
@ -588,6 +576,15 @@ extension NetworkSettingsViewController {
}
}
extension NetworkSettingsViewController: ToggleTableViewCellDelegate {
func toggleCell(_ cell: ToggleTableViewCell, didToggleToValue value: Bool) {
guard let item = RowType(rawValue: cell.tag) else {
return
}
handle(row: item, cell: cell)
}
}
extension NetworkSettingsViewController: FieldTableViewCellDelegate {
func fieldCellDidEdit(_ cell: FieldTableViewCell) {
commitTextField(cell.field)