ThreemaCallsSettingsViewController.swift 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2020 Threema GmbH
  8. //
  9. // This program is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU Affero General Public License, version 3,
  11. // as published by the Free Software Foundation.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU Affero General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Affero General Public License
  19. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. import UIKit
  21. class ThreemaCallsSettingsViewController: ThemedTableViewController {
  22. @IBOutlet weak var enableThreemaCallsCell: UITableViewCell!
  23. @IBOutlet weak var alwaysRelayThreemaCallsCell: UITableViewCell!
  24. @IBOutlet weak var enableCallKitCell: UITableViewCell!
  25. @IBOutlet weak var enableVideoCell: UITableViewCell!
  26. @IBOutlet weak var enableThreemaCallSwitch: UISwitch!
  27. @IBOutlet weak var alwaysRelayThreemaCallsSwitch: UISwitch!
  28. @IBOutlet weak var enableCallKitSwitch: UISwitch!
  29. @IBOutlet weak var enableVideoSwitch: UISwitch!
  30. @IBOutlet weak var videoQualityCellTitleLabel: UILabel!
  31. @IBOutlet weak var videoQualityCellDetailLabel: UILabel!
  32. let mdmSetup: MDMSetup
  33. required init?(coder aDecoder: NSCoder) {
  34. self.mdmSetup = MDMSetup(setup: false)
  35. super.init(coder: aDecoder)
  36. }
  37. override func viewDidLoad() {
  38. super.viewDidLoad()
  39. }
  40. override func viewWillAppear(_ animated: Bool) {
  41. super.viewWillAppear(animated)
  42. self.title = BundleUtil.localizedString(forKey: "settings_threema_calls")
  43. self.setupCells()
  44. self.tableView.reloadData()
  45. }
  46. // MARK: - Table view data source
  47. override func numberOfSections(in tableView: UITableView) -> Int {
  48. if is64Bit == 1 {
  49. if enableThreemaCallSwitch.isOn {
  50. return 4
  51. }
  52. }
  53. return 1
  54. }
  55. override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  56. if section == 3 {
  57. if enableVideoSwitch.isOn {
  58. return 2
  59. }
  60. return 1
  61. }
  62. return super.tableView(tableView, numberOfRowsInSection: section)
  63. }
  64. override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
  65. switch section {
  66. case 3:
  67. return BundleUtil.localizedString(forKey: "settings_threema_calls_video_section")
  68. default:
  69. return nil
  70. }
  71. }
  72. override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
  73. if enableThreemaCallSwitch.isOn {
  74. switch section {
  75. case 1:
  76. return alwaysRelayThreemaCallsSwitch.isOn ? BundleUtil.localizedString(forKey: "hide_voip_call_ip_on") : BundleUtil.localizedString(forKey: "hide_voip_call_ip_off")
  77. case 2:
  78. return enableCallKitSwitch.isOn ? BundleUtil.localizedString(forKey: "voip_callkit_on") : BundleUtil.localizedString(forKey: "voip_callkit_off")
  79. case 3:
  80. return enableVideoSwitch.isOn ? BundleUtil.localizedString(forKey: "settings_threema_calls_video_quality_profile_footer") : nil
  81. default:
  82. return nil
  83. }
  84. }
  85. return nil
  86. }
  87. }
  88. private extension ThreemaCallsSettingsViewController {
  89. // MARK: Private functions
  90. private func setupCells() {
  91. if is64Bit == 1 {
  92. enableDisableCallCellForMDM(!mdmSetup.existsMdmKey(MDM_KEY_DISABLE_CALLS))
  93. enableDisableVideoCellForMDM(!mdmSetup.existsMdmKey(MDM_KEY_DISABLE_VIDEO_CALLS))
  94. } else {
  95. UserSettings.shared().enableThreemaCall = false
  96. enableThreemaCallSwitch.isOn = false
  97. enableThreemaCallsCell.isUserInteractionEnabled = false
  98. enableThreemaCallsCell.textLabel?.isEnabled = false
  99. enableThreemaCallSwitch.isEnabled = false
  100. }
  101. setupLabels()
  102. setupSwitches()
  103. }
  104. private func enableDisableCallCellForMDM(_ enable: Bool) {
  105. enableThreemaCallsCell.isUserInteractionEnabled = enable
  106. enableThreemaCallsCell.textLabel?.isEnabled = enable
  107. enableThreemaCallSwitch.isEnabled = enable
  108. }
  109. private func enableDisableVideoCellForMDM(_ enable: Bool) {
  110. enableVideoCell.isUserInteractionEnabled = enable
  111. enableVideoCell.textLabel?.isEnabled = enable
  112. enableVideoSwitch.isEnabled = enable
  113. }
  114. private func disableCallKitForCN() {
  115. enableCallKitCell.isUserInteractionEnabled = false
  116. enableCallKitCell.textLabel?.isEnabled = false
  117. enableCallKitSwitch.isEnabled = false
  118. enableCallKitSwitch.isOn = false
  119. UserSettings.shared().enableCallKit = false
  120. }
  121. private func setupSwitches() {
  122. self.enableThreemaCallSwitch.isOn = UserSettings.shared().enableThreemaCall
  123. self.alwaysRelayThreemaCallsSwitch.isOn = UserSettings.shared().alwaysRelayCalls
  124. self.enableCallKitSwitch.isOn = UserSettings.shared().enableCallKit
  125. self.enableVideoSwitch.isOn = UserSettings.shared().enableVideoCall
  126. if is64Bit == 1 {
  127. if !mdmSetup.disableCalls() {
  128. if (Locale.current as NSLocale).object(forKey: .countryCode) as? String == "CN" {
  129. disableCallKitForCN()
  130. }
  131. }
  132. }
  133. }
  134. private func setupLabels() {
  135. enableThreemaCallsCell.textLabel?.text = BundleUtil.localizedString(forKey: "settings_threema_calls_enable_calls")
  136. alwaysRelayThreemaCallsCell.textLabel?.text = BundleUtil.localizedString(forKey: "settings_threema_calls_always_relay_calls")
  137. enableCallKitCell.textLabel?.text = BundleUtil.localizedString(forKey: "settings_threema_calls_callkit")
  138. enableVideoCell.textLabel?.text = BundleUtil.localizedString(forKey: "settings_threema_calls_allow_video_calls")
  139. videoQualityCellTitleLabel?.text = BundleUtil.localizedString(forKey: "settings_threema_calls_video_quality_profile")
  140. videoQualityCellDetailLabel?.text = CallsignalingProtocol.currentThreemaVideoCallQualitySettingTitle()
  141. }
  142. // MARK IBActions
  143. @IBAction func enableThreemaCallSwitchChanged(sender: UISwitch) {
  144. UserSettings.shared().enableThreemaCall = sender.isOn
  145. setupSwitches()
  146. tableView.reloadData()
  147. }
  148. @IBAction func alwaysRelayCallsSwitchChanged(sender: UISwitch) {
  149. UserSettings.shared().alwaysRelayCalls = sender.isOn
  150. setupSwitches()
  151. tableView.reloadData()
  152. }
  153. @IBAction func enableCallKitSwitchChanged(sender: UISwitch) {
  154. UserSettings.shared().enableCallKit = sender.isOn
  155. setupSwitches()
  156. tableView.reloadData()
  157. }
  158. @IBAction func enableVideoCallSwitchChanged(sender: UISwitch) {
  159. UserSettings.shared().enableVideoCall = sender.isOn
  160. setupSwitches()
  161. tableView.reloadData()
  162. }
  163. }