On-Demand: Move detail text to TunnelViewModel

Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
Roopesh Chander 2018-12-08 01:54:18 +05:30
parent b7e5638681
commit 465c22f769
2 changed files with 13 additions and 20 deletions

View File

@ -464,6 +464,18 @@ extension TunnelViewModel {
} }
} }
static func activateOnDemandDetailText(for activateOnDemandSetting: ActivateOnDemandSetting?) -> String {
if let activateOnDemandSetting = activateOnDemandSetting {
if (activateOnDemandSetting.isActivateOnDemandEnabled) {
return TunnelViewModel.activateOnDemandOptionText(for: activateOnDemandSetting.activateOnDemandOption)
} else {
return TunnelViewModel.activateOnDemandOptionText(for: .none)
}
} else {
return TunnelViewModel.activateOnDemandOptionText(for: .none)
}
}
func defaultActivateOnDemandOption() -> ActivateOnDemandOption { func defaultActivateOnDemandOption() -> ActivateOnDemandOption {
return .useOnDemandOverWiFiOrCellular return .useOnDemandOverWiFiOrCellular
} }

View File

@ -426,26 +426,7 @@ class TunnelDetailTableViewActivateOnDemandCell: UITableViewCell {
} }
func update(from activateOnDemandSetting: ActivateOnDemandSetting?) { func update(from activateOnDemandSetting: ActivateOnDemandSetting?) {
let detailText: String detailTextLabel?.text = TunnelViewModel.activateOnDemandDetailText(for: activateOnDemandSetting)
if let activateOnDemandSetting = activateOnDemandSetting {
if (activateOnDemandSetting.isActivateOnDemandEnabled) {
switch (activateOnDemandSetting.activateOnDemandOption) {
case .none:
detailText = "Off"
case .useOnDemandOverWiFiOrCellular:
detailText = "Wi-Fi or cellular"
case .useOnDemandOverWiFiOnly:
detailText = "Wi-Fi only"
case .useOnDemandOverCellularOnly:
detailText = "Cellular only"
}
} else {
detailText = "Off"
}
} else {
detailText = "Off"
}
detailTextLabel?.text = detailText
} }
override func prepareForReuse() { override func prepareForReuse() {