Base profile selection on ConnectionProfile

Rather than cells, which relies on cell visibility. Drop ugly
selection segue.

Fixes #63
This commit is contained in:
Davide De Rosa 2019-04-11 15:49:15 +02:00
parent 867f5370c5
commit 60259a2fb9
3 changed files with 17 additions and 30 deletions

View File

@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- VPN status cell doesn't always enter active profile. [#63](https://github.com/passepartoutvpn/passepartout-ios/issues/63)
- Masking preference not retained. [#64](https://github.com/passepartoutvpn/passepartout-ios/issues/64)
## 1.4.0 (2019-04-11)

View File

@ -370,9 +370,6 @@
</label>
</subviews>
</tableViewCellContentView>
<connections>
<segue destination="pel-Q7-aOe" kind="showDetail" identifier="SelectProfileSegueIdentifier" id="wW2-CO-Y42"/>
</connections>
</tableViewCell>
</prototypes>
<connections>
@ -387,6 +384,7 @@
<segue destination="BIO-UT-cpg" kind="presentation" identifier="SiriShortcutsSegueIdentifier" modalPresentationStyle="formSheet" id="I9b-aK-jPT"/>
<segue destination="POR-9u-PsE" kind="presentation" identifier="AboutSegueIdentifier" modalPresentationStyle="formSheet" id="78g-ra-Yhp"/>
<segue destination="5ku-HX-5yk" kind="presentation" identifier="DonateSegueIdentifier" modalPresentationStyle="formSheet" id="H4q-BS-PmK"/>
<segue destination="pel-Q7-aOe" kind="showDetail" identifier="SelectProfileSegueIdentifier" id="bkI-h9-mGF"/>
</connections>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="bGp-H5-24W" userLabel="First Responder" sceneMemberID="firstResponder"/>

View File

@ -155,7 +155,10 @@ class OrganizerViewController: UITableViewController, TableModelHost {
if selectedProfile == nil, let cell = sender as? UITableViewCell, let indexPath = tableView.indexPath(for: cell) {
selectedProfile = profile(at: indexPath)
}
assert(selectedProfile != nil, "No selected profile")
guard selectedProfile != nil else {
assertionFailure("No selected profile")
return
}
vc.setProfile(selectedProfile)
} else if let providerVC = destination as? WizardProviderViewController {
@ -164,12 +167,16 @@ class OrganizerViewController: UITableViewController, TableModelHost {
}
// MARK: Actions
private func selectActiveProfile() {
guard let activeIndexPath = activeIndexPath, let cell = tableView.cellForRow(at: activeIndexPath) else {
private func enterProfile(_ profile: ConnectionProfile) {
perform(segue: StoryboardSegue.Organizer.selectProfileSegueIdentifier, sender: profile)
}
private func enterActiveProfile() {
guard let activeProfile = service.activeProfile else {
return
}
perform(segue: StoryboardSegue.Organizer.selectProfileSegueIdentifier, sender: cell)
enterProfile(activeProfile)
}
private func addNewProvider() {
@ -377,24 +384,6 @@ extension OrganizerViewController {
case testTermination
}
private var activeIndexPath: IndexPath? {
guard let active = service.activeProfileKey else {
return nil
}
switch active.context {
case .provider:
if let row = providers.index(where: { $0 == active.id }) {
return IndexPath(row: row, section: model.index(ofSection: .providers))
}
case .host:
if let row = hosts.index(where: { $0 == active.id }) {
return IndexPath(row: row, section: model.index(ofSection: .hosts))
}
}
return nil
}
override func numberOfSections(in tableView: UITableView) -> Int {
return model.count
}
@ -490,12 +479,11 @@ extension OrganizerViewController {
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
switch model.row(at: indexPath) {
case .connectionStatus:
selectActiveProfile()
enterActiveProfile()
case .profile:
// selectedProfileId = profile(at: indexPath).id
break
enterProfile(profile(at: indexPath))
case .addProvider:
addNewProvider()