Merge branch 'reuse-core-extensions'

This commit is contained in:
Davide De Rosa 2019-06-23 00:18:02 +02:00
commit 7186beb6bd
5 changed files with 49 additions and 38 deletions

View File

@ -73,3 +73,40 @@ extension UIAlertController {
return action
}
}
extension UIView {
static func get<T: UIView>() -> T {
let name = String(describing: T.self)
let nib = UINib(nibName: name, bundle: nil)
let objects = nib.instantiate(withOwner: nil)
for o in objects {
if let view = o as? T {
return view
}
}
fatalError()
}
}
extension UITableView {
func scrollToRowAsync(at indexPath: IndexPath) {
DispatchQueue.main.async { [weak self] in
self?.scrollToRow(at: indexPath, at: .middle, animated: false)
}
}
func selectRowAsync(at indexPath: IndexPath) {
DispatchQueue.main.async { [weak self] in
self?.selectRow(at: indexPath, animated: false, scrollPosition: .middle)
}
}
}
extension UIColor {
convenience init(rgb: UInt32, alpha: CGFloat) {
let r = CGFloat((rgb & 0xff0000) >> 16) / 255.0
let g = CGFloat((rgb & 0xff00) >> 8) / 255.0
let b = CGFloat(rgb & 0xff) / 255.0
self.init(red: r, green: g, blue: b, alpha: alpha)
}
}

View File

@ -28,15 +28,6 @@ import MessageUI
import StoreKit
import PassepartoutCore
extension UIColor {
convenience init(rgb: UInt32, alpha: CGFloat) {
let r = CGFloat((rgb & 0xff0000) >> 16) / 255.0
let g = CGFloat((rgb & 0xff00) >> 8) / 255.0
let b = CGFloat(rgb & 0xff) / 255.0
self.init(red: r, green: g, blue: b, alpha: alpha)
}
}
struct Theme {
struct Palette {
var primaryBackground = UIColor(rgb: 0x515d71, alpha: 1.0)
@ -174,12 +165,3 @@ extension PoolGroup {
return ImageAsset(name: country.lowercased()).image
}
}
extension SKProduct {
var localizedPrice: String? {
let fmt = NumberFormatter()
fmt.numberStyle = .currency
fmt.locale = priceLocale
return fmt.string(from: price)
}
}

View File

@ -315,7 +315,7 @@ extension ConfigurationViewController: UITableViewDataSource, UITableViewDelegat
case .cipher:
let vc = OptionViewController<OpenVPN.Cipher>()
vc.title = settingCell?.leftText
vc.options = [.aes128cbc, .aes192cbc, .aes256cbc, .aes128gcm, .aes192gcm, .aes256gcm]
vc.options = OpenVPN.Cipher.available
vc.selectedOption = configuration.cipher
vc.descriptionBlock = { $0.description }
vc.selectionBlock = { [weak self] in
@ -327,7 +327,7 @@ extension ConfigurationViewController: UITableViewDataSource, UITableViewDelegat
case .digest:
let vc = OptionViewController<OpenVPN.Digest>()
vc.title = settingCell?.leftText
vc.options = [.sha1, .sha224, .sha256, .sha384, .sha512]
vc.options = OpenVPN.Digest.available
vc.selectedOption = configuration.digest
vc.descriptionBlock = { $0.description }
vc.selectionBlock = { [weak self] in
@ -339,7 +339,7 @@ extension ConfigurationViewController: UITableViewDataSource, UITableViewDelegat
case .compressionFraming:
let vc = OptionViewController<OpenVPN.CompressionFraming>()
vc.title = settingCell?.leftText
vc.options = [.disabled, .compLZO, .compress]
vc.options = OpenVPN.CompressionFraming.available
vc.selectedOption = configuration.compressionFraming ?? .disabled
vc.descriptionBlock = { $0.cellDescription }
vc.selectionBlock = { [weak self] in
@ -358,7 +358,7 @@ extension ConfigurationViewController: UITableViewDataSource, UITableViewDelegat
let vc = OptionViewController<OpenVPN.CompressionAlgorithm>()
vc.title = settingCell?.leftText
vc.options = [.disabled, .LZO]
vc.options = OpenVPN.CompressionAlgorithm.available
vc.selectedOption = configuration.compressionAlgorithm ?? .disabled
vc.descriptionBlock = { $0.cellDescription }
vc.selectionBlock = { [weak self] in

View File

@ -66,19 +66,7 @@ class NetworkSettingsViewController: UITableViewController {
private let networkSettings = ProfileNetworkSettings()
private lazy var clientNetworkSettings: ProfileNetworkSettings? = {
guard let hostProfile = profile as? HostConnectionProfile else {
return nil
}
return ProfileNetworkSettings(from: hostProfile.parameters.sessionConfiguration)
}()
private var choices: [NetworkChoice] {
guard let _ = clientNetworkSettings else {
return [.server, .manual]
}
return [.client, .server, .manual]
}
private lazy var clientNetworkSettings = profile?.clientNetworkSettings
// MARK: TableModelHost
@ -430,7 +418,7 @@ extension NetworkSettingsViewController {
case .gateway:
let vc = OptionViewController<NetworkChoice>()
vc.title = (cell as? SettingTableViewCell)?.leftText
vc.options = choices
vc.options = NetworkChoice.choices(for: profile)
vc.descriptionBlock = { $0.description }
vc.selectedOption = networkChoices.gateway
@ -443,7 +431,7 @@ extension NetworkSettingsViewController {
case .dns:
let vc = OptionViewController<NetworkChoice>()
vc.title = (cell as? SettingTableViewCell)?.leftText
vc.options = choices
vc.options = NetworkChoice.choices(for: profile)
vc.descriptionBlock = { $0.description }
vc.selectedOption = networkChoices.dns
@ -456,7 +444,7 @@ extension NetworkSettingsViewController {
case .proxy:
let vc = OptionViewController<NetworkChoice>()
vc.title = (cell as? SettingTableViewCell)?.leftText
vc.options = choices
vc.options = NetworkChoice.choices(for: profile)
vc.descriptionBlock = { $0.description }
vc.selectedOption = networkChoices.proxy

View File

@ -66,6 +66,7 @@
0E45E6E022BD793800F19312 /* App.strings in Resources */ = {isa = PBXBuildFile; fileRef = 0E45E6E222BD793800F19312 /* App.strings */; };
0E45E6E422BD799700F19312 /* SwiftGen+Strings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E45E6E322BD799700F19312 /* SwiftGen+Strings.swift */; };
0E45E6FA22BD8FC500F19312 /* Core.strings in Resources */ = {isa = PBXBuildFile; fileRef = 0E3CAF98229AAE760008E5C8 /* Core.strings */; };
0E45E71022BE108100F19312 /* OpenVPNOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E45E70F22BE108100F19312 /* OpenVPNOptions.swift */; };
0E4C9CBB20DCF0D600A0C59C /* DestructiveTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E4C9CBA20DCF0D600A0C59C /* DestructiveTableViewCell.swift */; };
0E4FD7F120D58618002221FF /* Macros.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E4FD7F020D58618002221FF /* Macros.swift */; };
0E533B162258E03B00EF94FC /* PoolGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E533B152258E03B00EF94FC /* PoolGroup.swift */; };
@ -203,6 +204,7 @@
0E45E6F722BD898800F19312 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/App.strings; sourceTree = "<group>"; };
0E45E6F822BD898A00F19312 /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/App.strings; sourceTree = "<group>"; };
0E45E6F922BD898B00F19312 /* pt */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pt; path = pt.lproj/App.strings; sourceTree = "<group>"; };
0E45E70F22BE108100F19312 /* OpenVPNOptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenVPNOptions.swift; sourceTree = "<group>"; };
0E4C9CB820DB9BC600A0C59C /* TrustedNetworks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrustedNetworks.swift; sourceTree = "<group>"; };
0E4C9CBA20DCF0D600A0C59C /* DestructiveTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DestructiveTableViewCell.swift; sourceTree = "<group>"; };
0E4FD7DD20D3E49A002221FF /* StandardVPNProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StandardVPNProvider.swift; sourceTree = "<group>"; };
@ -502,6 +504,7 @@
0ECEB109224FECEA00E9E551 /* DataUnit.swift */,
0EC7F20420E24308004EA58E /* DebugLog.swift */,
0ED38AE621404F100004D387 /* EndpointDataSource.swift */,
0E45E70F22BE108100F19312 /* OpenVPNOptions.swift */,
0E89DFC4213DF7AE00741BA1 /* Preferences.swift */,
0EFB901722764689006405E4 /* ProfileNetworkSettings.swift */,
0E89DFC7213E8FC500741BA1 /* SessionProxy+Communication.swift */,
@ -942,6 +945,7 @@
0E3152C2223FA04800F61841 /* MockVPNProvider.swift in Sources */,
0E533B162258E03B00EF94FC /* PoolGroup.swift in Sources */,
0E3152D2223FA05400F61841 /* DebugLog.swift in Sources */,
0E45E71022BE108100F19312 /* OpenVPNOptions.swift in Sources */,
0E3152C4223FA04800F61841 /* VPN.swift in Sources */,
0E3152C6223FA04800F61841 /* VPNProvider.swift in Sources */,
0E3152DA223FA05800F61841 /* PlaceholderConnectionProfile.swift in Sources */,