MediaShareOptionsViewController.swift 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 MediaShareOptionsViewController: UITableViewController {
  22. @IBOutlet weak var sendAsFileSwitch: UISwitch!
  23. struct ImageSendOptions {
  24. var sendAsFile = false
  25. var imageQuality = ""
  26. }
  27. var options: ImageSendOptions?
  28. @IBOutlet weak var imageSizeLabel: UILabel!
  29. weak var delegate: MediaPreviewViewController?
  30. @IBOutlet weak var saveButton: UIBarButtonItem!
  31. @IBOutlet weak var navigationBar: UINavigationItem!
  32. @IBOutlet weak var sendAsFileCell: UITableViewCell!
  33. @IBOutlet weak var imageQualityCell: UITableViewCell!
  34. func setupOptions(options : ImageSendOptions) {
  35. self.options = options
  36. }
  37. override func viewDidLoad() {
  38. super.viewDidLoad()
  39. self.options!.imageQuality = BundleUtil.localizedString(forKey: UserSettings.shared().imageSize)
  40. self.sendAsFileSwitch.isOn = self.options?.sendAsFile ?? false
  41. self.navigationBar.title = BundleUtil.localizedString(forKey: "more_options")
  42. self.sendAsFileCell.textLabel?.text = BundleUtil.localizedString(forKey: "send_as_file")
  43. saveButton.title = BundleUtil.localizedString(forKey: "Done")
  44. }
  45. override func viewWillDisappear(_ animated: Bool) {
  46. saveOptions()
  47. super.viewWillDisappear(animated)
  48. }
  49. override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
  50. return BundleUtil.localizedString(forKey: "send_as_file_description")
  51. }
  52. override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
  53. return BundleUtil.localizedString(forKey: "send_as_file_title")
  54. }
  55. @IBAction func donePressed(_ sender: Any) {
  56. self.dismiss(animated: true, completion: nil)
  57. saveOptions()
  58. }
  59. func saveOptions() {
  60. self.options?.sendAsFile = self.sendAsFileSwitch.isOn
  61. self.delegate?.updateOptions(imageSendOptions: self.options!)
  62. }
  63. }