Table edit: Show/hide 'Exclude Private IPs' instead of enable/disable
This commit is contained in:
parent
864394cf81
commit
c643cd1478
|
@ -133,7 +133,10 @@ extension TunnelEditTableViewController {
|
||||||
return interfaceFieldsBySection[section].count
|
return interfaceFieldsBySection[section].count
|
||||||
} else if ((numberOfPeerSections > 0) && (section < (numberOfInterfaceSections + numberOfPeerSections))) {
|
} else if ((numberOfPeerSections > 0) && (section < (numberOfInterfaceSections + numberOfPeerSections))) {
|
||||||
// Peer
|
// Peer
|
||||||
return peerFields.count
|
let peerIndex = (section - numberOfInterfaceSections)
|
||||||
|
let peerData = tunnelViewModel.peersData[peerIndex]
|
||||||
|
let peerFieldsToShow = peerData.shouldAllowExcludePrivateIPsControl ? peerFields : peerFields.filter { $0 != .excludePrivateIPs }
|
||||||
|
return peerFieldsToShow.count
|
||||||
} else {
|
} else {
|
||||||
// Add peer
|
// Add peer
|
||||||
return 1
|
return 1
|
||||||
|
@ -232,7 +235,8 @@ extension TunnelEditTableViewController {
|
||||||
// Peer
|
// Peer
|
||||||
let peerIndex = (section - numberOfInterfaceSections)
|
let peerIndex = (section - numberOfInterfaceSections)
|
||||||
let peerData = tunnelViewModel.peersData[peerIndex]
|
let peerData = tunnelViewModel.peersData[peerIndex]
|
||||||
let field = peerFields[row]
|
let peerFieldsToShow = peerData.shouldAllowExcludePrivateIPsControl ? peerFields : peerFields.filter { $0 != .excludePrivateIPs }
|
||||||
|
let field = peerFieldsToShow[row]
|
||||||
if (field == .deletePeer) {
|
if (field == .deletePeer) {
|
||||||
let cell = tableView.dequeueReusableCell(withIdentifier: TunnelEditTableViewButtonCell.id, for: indexPath) as! TunnelEditTableViewButtonCell
|
let cell = tableView.dequeueReusableCell(withIdentifier: TunnelEditTableViewButtonCell.id, for: indexPath) as! TunnelEditTableViewButtonCell
|
||||||
cell.buttonText = field.rawValue
|
cell.buttonText = field.rawValue
|
||||||
|
@ -245,13 +249,18 @@ extension TunnelEditTableViewController {
|
||||||
onConfirmed: { [weak s] in
|
onConfirmed: { [weak s] in
|
||||||
guard let s = s else { return }
|
guard let s = s else { return }
|
||||||
let removedSectionIndices = s.deletePeer(peer: peerData)
|
let removedSectionIndices = s.deletePeer(peer: peerData)
|
||||||
s.tableView.deleteSections(removedSectionIndices, with: .automatic)
|
let shouldShowExcludePrivateIPs = (s.tunnelViewModel.peersData.count == 1 &&
|
||||||
if let row = s.peerFields.firstIndex(of: .excludePrivateIPs) {
|
s.tunnelViewModel.peersData[0].shouldAllowExcludePrivateIPsControl)
|
||||||
let excludePrivateIPsIndexPaths = (0 ..< s.tunnelViewModel.peersData.count).map {
|
tableView.performBatchUpdates({
|
||||||
IndexPath(row: row, section: numberOfInterfaceSections + $0)
|
s.tableView.deleteSections(removedSectionIndices, with: .automatic)
|
||||||
|
if (shouldShowExcludePrivateIPs) {
|
||||||
|
if let row = s.peerFields.firstIndex(of: .excludePrivateIPs) {
|
||||||
|
let rowIndexPath = IndexPath(row: row, section: numberOfInterfaceSections /* First peer section */)
|
||||||
|
s.tableView.insertRows(at: [rowIndexPath], with: .automatic)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
s.tableView.reloadRows(at: excludePrivateIPsIndexPaths, with: .none)
|
})
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return cell
|
return cell
|
||||||
|
@ -299,9 +308,16 @@ extension TunnelEditTableViewController {
|
||||||
if (field == .allowedIPs) {
|
if (field == .allowedIPs) {
|
||||||
cell.onValueBeingEdited = { [weak self, weak peerData] value in
|
cell.onValueBeingEdited = { [weak self, weak peerData] value in
|
||||||
if let peerData = peerData, let s = self {
|
if let peerData = peerData, let s = self {
|
||||||
|
let oldValue = peerData.shouldAllowExcludePrivateIPsControl
|
||||||
peerData[.allowedIPs] = value
|
peerData[.allowedIPs] = value
|
||||||
if let row = s.peerFields.firstIndex(of: .excludePrivateIPs) {
|
if (oldValue != peerData.shouldAllowExcludePrivateIPsControl) {
|
||||||
s.tableView.reloadRows(at: [IndexPath(row: row, section: section)], with: .none)
|
if let row = s.peerFields.firstIndex(of: .excludePrivateIPs) {
|
||||||
|
if (peerData.shouldAllowExcludePrivateIPsControl) {
|
||||||
|
s.tableView.insertRows(at: [IndexPath(row: row, section: section)], with: .automatic)
|
||||||
|
} else {
|
||||||
|
s.tableView.deleteRows(at: [IndexPath(row: row, section: section)], with: .automatic)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -315,14 +331,18 @@ extension TunnelEditTableViewController {
|
||||||
cell.buttonText = "Add peer"
|
cell.buttonText = "Add peer"
|
||||||
cell.onTapped = { [weak self] in
|
cell.onTapped = { [weak self] in
|
||||||
guard let s = self else { return }
|
guard let s = self else { return }
|
||||||
|
let shouldHideExcludePrivateIPs = (s.tunnelViewModel.peersData.count == 1 &&
|
||||||
|
s.tunnelViewModel.peersData[0].shouldAllowExcludePrivateIPsControl)
|
||||||
let addedSectionIndices = s.appendEmptyPeer()
|
let addedSectionIndices = s.appendEmptyPeer()
|
||||||
tableView.insertSections(addedSectionIndices, with: .automatic)
|
tableView.performBatchUpdates({
|
||||||
if let row = s.peerFields.firstIndex(of: .excludePrivateIPs) {
|
tableView.insertSections(addedSectionIndices, with: .automatic)
|
||||||
let excludePrivateIPsIndexPaths = (0 ..< s.tunnelViewModel.peersData.count).map {
|
if (shouldHideExcludePrivateIPs) {
|
||||||
IndexPath(row: row, section: numberOfInterfaceSections + $0)
|
if let row = s.peerFields.firstIndex(of: .excludePrivateIPs) {
|
||||||
|
let rowIndexPath = IndexPath(row: row, section: numberOfInterfaceSections /* First peer section */)
|
||||||
|
s.tableView.deleteRows(at: [rowIndexPath], with: .automatic)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
s.tableView.reloadRows(at: excludePrivateIPsIndexPaths, with: .none)
|
}, completion: nil)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return cell
|
return cell
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue