MediaSettingsViewController.swift 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2019-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 MediaSettingsViewController: ThemedTableViewController {
  22. @IBOutlet weak var imageSizeLabel: UILabel!
  23. @IBOutlet weak var videoQualityLabel: UILabel!
  24. @IBOutlet weak var autoSaveMediaSwitch: UISwitch!
  25. @IBOutlet weak var autoSaveMediaLabel: UILabel!
  26. @IBOutlet weak var autoSaveMediaCell: UITableViewCell!
  27. let mdmSetup: MDMSetup
  28. required init?(coder aDecoder: NSCoder) {
  29. self.mdmSetup = MDMSetup(setup: false)
  30. super.init(coder: aDecoder)
  31. }
  32. override func viewDidLoad() {
  33. super.viewDidLoad()
  34. }
  35. override func viewWillAppear(_ animated: Bool) {
  36. super.viewWillAppear(animated)
  37. self.imageSizeLabel.text = BundleUtil.localizedString(forKey: UserSettings.shared().imageSize)
  38. self.videoQualityLabel.text = BundleUtil.localizedString(forKey: UserSettings.shared().videoQuality)
  39. self.autoSaveMediaCell.isUserInteractionEnabled = !mdmSetup.existsMdmKey(MDM_KEY_DISABLE_SAVE_TO_GALLERY)
  40. self.autoSaveMediaLabel.isEnabled = !mdmSetup.existsMdmKey(MDM_KEY_DISABLE_SAVE_TO_GALLERY)
  41. self.autoSaveMediaSwitch.isOn = UserSettings.shared().autoSaveMedia
  42. self.updateColors()
  43. self.tableView.reloadData()
  44. }
  45. // MARK: - Table view data source
  46. override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  47. if #available(iOS 11.0, *) {
  48. if section == 0 {
  49. return 38.0
  50. }
  51. }
  52. return UITableView.automaticDimension
  53. }
  54. override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
  55. if section == 0 {
  56. var footerText = ""
  57. if mdmSetup.existsMdmKey(MDM_KEY_DISABLE_SAVE_TO_GALLERY) {
  58. footerText.append(BundleUtil.localizedString(forKey: "disabled_by_device_policy"))
  59. }
  60. if UserSettings.shared()?.imageSize == "original" || UserSettings.shared()?.imageSize == "xlarge" {
  61. if footerText.count > 0 {
  62. footerText.append("\n\n")
  63. }
  64. footerText.append(BundleUtil.localizedString(forKey: "image_resize_share_extension"))
  65. }
  66. if footerText.count > 0 {
  67. return footerText
  68. }
  69. }
  70. return nil
  71. }
  72. override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
  73. Colors.update(cell)
  74. self.updateColors()
  75. }
  76. @IBAction func autoSaveMediaChanged(_ sender: UISwitch) {
  77. UserSettings.shared().autoSaveMedia = self.autoSaveMediaSwitch.isOn
  78. }
  79. func updateColors() {
  80. }
  81. }