Reconnect with a specific action cell

This commit is contained in:
Davide De Rosa 2018-10-21 09:45:59 +02:00
parent be6abdcf2a
commit 6ed70feb77
2 changed files with 19 additions and 10 deletions

View File

@ -397,12 +397,14 @@ extension ServiceViewController: UITableViewDataSource, UITableViewDelegate, Tog
} }
enum RowType: Int { enum RowType: Int {
case useProfile
case vpnService case vpnService
case connectionStatus case connectionStatus
case useProfile case reconnect
case account case account
case endpoint case endpoint
@ -503,6 +505,12 @@ extension ServiceViewController: UITableViewDataSource, UITableViewDelegate, Tog
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let row = model.row(at: indexPath) let row = model.row(at: indexPath)
switch row { switch row {
case .useProfile:
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
cell.applyAction(Theme.current)
cell.leftText = L10n.Service.Cells.UseProfile.caption
return cell
case .vpnService: case .vpnService:
guard service.isActiveProfile(uncheckedProfile) else { guard service.isActiveProfile(uncheckedProfile) else {
fatalError("Do not show vpnService in non-active profile") fatalError("Do not show vpnService in non-active profile")
@ -522,13 +530,14 @@ extension ServiceViewController: UITableViewDataSource, UITableViewDelegate, Tog
cell.applyVPN(Theme.current, with: vpn.isEnabled ? vpn.status : nil) cell.applyVPN(Theme.current, with: vpn.isEnabled ? vpn.status : nil)
cell.leftText = L10n.Service.Cells.ConnectionStatus.caption cell.leftText = L10n.Service.Cells.ConnectionStatus.caption
cell.accessoryType = .none cell.accessoryType = .none
cell.isTappable = !service.needsCredentials(for: uncheckedProfile) && vpn.isEnabled
return cell return cell
case .useProfile: case .reconnect:
let cell = Cells.setting.dequeue(from: tableView, for: indexPath) let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
cell.applyAction(Theme.current) cell.applyAction(Theme.current)
cell.leftText = L10n.Service.Cells.UseProfile.caption cell.leftText = L10n.Service.Cells.Reconnect.caption
cell.accessoryType = .none
cell.isTappable = !service.needsCredentials(for: uncheckedProfile) && vpn.isEnabled
return cell return cell
// shared cells // shared cells
@ -695,12 +704,12 @@ extension ServiceViewController: UITableViewDataSource, UITableViewDelegate, Tog
// true if enters subscreen // true if enters subscreen
private func handle(row: RowType, cell: UITableViewCell) -> Bool { private func handle(row: RowType, cell: UITableViewCell) -> Bool {
switch row { switch row {
case .connectionStatus:
confirmVpnReconnection()
case .useProfile: case .useProfile:
activate() activate()
case .reconnect:
confirmVpnReconnection()
case .account: case .account:
perform(segue: StoryboardSegue.Main.accountSegueIdentifier, sender: cell) perform(segue: StoryboardSegue.Main.accountSegueIdentifier, sender: cell)
return true return true
@ -852,7 +861,7 @@ extension ServiceViewController: UITableViewDataSource, UITableViewDelegate, Tog
// rows // rows
if isActiveProfile { if isActiveProfile {
model.set([.vpnService, .connectionStatus], in: .vpn) model.set([.vpnService, .connectionStatus, .reconnect], in: .vpn)
} else { } else {
model.set([.useProfile], in: .vpn) model.set([.useProfile], in: .vpn)
} }

View File

@ -72,9 +72,9 @@
"service.sections.diagnostics.header" = "Diagnostics"; "service.sections.diagnostics.header" = "Diagnostics";
//"service.sections.destruction.footer" = "Delete configuration from device settings."; //"service.sections.destruction.footer" = "Delete configuration from device settings.";
"service.cells.use_profile.caption" = "Use this profile";
"service.cells.vpn_service.caption" = "Enabled"; "service.cells.vpn_service.caption" = "Enabled";
"service.cells.connection_status.caption" = "Status"; "service.cells.connection_status.caption" = "Status";
"service.cells.use_profile.caption" = "Use this profile";
"service.cells.reconnect.caption" = "Reconnect"; "service.cells.reconnect.caption" = "Reconnect";
"service.cells.account.caption" = "Account"; "service.cells.account.caption" = "Account";
"service.cells.account.none" = "None configured"; "service.cells.account.none" = "None configured";