- New setting in data settings to enable low bandwidth mode for different network interfaces - Call service now informs RingRTC of preferred bandwidth mode on call connect and reachability changes
64 lines
2.4 KiB
Swift
64 lines
2.4 KiB
Swift
//
|
|
// Copyright (c) 2021 Open Whisper Systems. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
class NetworkInterfacePreferenceViewController: OWSTableViewController {
|
|
private var selectedOption: NetworkInterfaceSet?
|
|
private let availableOptions: [NetworkInterfaceSet]
|
|
private let updateHandler: (NetworkInterfaceSet) -> Void
|
|
|
|
public required init(
|
|
selectedOption: NetworkInterfaceSet?,
|
|
availableOptions: [NetworkInterfaceSet],
|
|
updateHandler: @escaping (NetworkInterfaceSet) -> Void) {
|
|
|
|
self.selectedOption = selectedOption
|
|
self.availableOptions = availableOptions
|
|
self.updateHandler = updateHandler
|
|
super.init()
|
|
}
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
self.useThemeBackgroundColors = true
|
|
updateTableContents()
|
|
}
|
|
|
|
func updateTableContents() {
|
|
self.contents = OWSTableContents(sections: [
|
|
OWSTableSection(header: nil, items: availableOptions.compactMap { option in
|
|
guard let name = Self.name(forInterfaceSet: option) else { return nil }
|
|
|
|
return OWSTableItem(
|
|
text: name,
|
|
actionBlock: { [weak self] in
|
|
self?.selectedOption = option
|
|
self?.updateHandler(option)
|
|
self?.navigationController?.popViewController(animated: true)
|
|
},
|
|
accessoryType: option == selectedOption ? .checkmark : .none)
|
|
})
|
|
])
|
|
}
|
|
|
|
static func name(forInterfaceSet interfaceSet: NetworkInterfaceSet) -> String? {
|
|
switch interfaceSet {
|
|
case .none: return NSLocalizedString(
|
|
"NETWORK_INTERFACE_SET_NEVER",
|
|
comment: "String representing the 'never' condition of having no supported network interfaces")
|
|
case .cellular: return NSLocalizedString(
|
|
"NETWORK_INTERFACE_SET_CELLULAR",
|
|
comment: "String representing only the cellular interface")
|
|
case .wifi: return NSLocalizedString(
|
|
"NETWORK_INTERFACE_SET_WIFI",
|
|
comment: "String representing only the wifi interface")
|
|
case .wifiAndCellular: return NSLocalizedString(
|
|
"NETWORK_INTERFACE_SET_WIFI_CELLULAR",
|
|
comment: "String representing both wifi and cellular interfaces")
|
|
default: return nil
|
|
}
|
|
}
|
|
}
|