ThreemaQLPreviewController.swift 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 Foundation
  21. import QuickLook
  22. class ThreemaQLPreviewController : QLPreviewController {
  23. var toolbars: [UIView] = []
  24. var observations : [NSKeyValueObservation] = []
  25. var mdmSetup: MDMSetup = MDMSetup.init(setup: false)
  26. override func viewDidLoad() {
  27. super.viewDidLoad()
  28. if (mdmSetup.disableShareMedia() == true) {
  29. navigationItem.setRightBarButton(UIBarButtonItem(), animated: false)
  30. }
  31. }
  32. override func viewWillAppear(_ animated: Bool) {
  33. super.viewWillAppear(animated)
  34. if (mdmSetup.disableShareMedia() == true) {
  35. navigationController?.toolbar.isHidden = true
  36. if let navigationToobar = navigationController?.toolbar {
  37. let observation = navigationToobar.observe(\.isHidden) {[weak self] (changedToolBar, change) in
  38. if self?.navigationController?.toolbar.isHidden == false {
  39. self?.navigationController?.toolbar.isHidden = true
  40. }
  41. }
  42. observations.append(observation)
  43. }
  44. toolbars = toolbarsInSubviews(forView: view)
  45. for toolbar in toolbars {
  46. toolbar.isHidden = true
  47. let observation = toolbar.observe(\.isHidden) { (changedToolBar, change) in
  48. if let isHidden = change.newValue,
  49. isHidden == false {
  50. changedToolBar.isHidden = true
  51. }
  52. }
  53. observations.append(observation)
  54. }
  55. }
  56. }
  57. private func toolbarsInSubviews(forView view: UIView) -> [UIView] {
  58. var toolbars: [UIView] = []
  59. for subview in view.subviews {
  60. if subview is UIToolbar {
  61. toolbars.append(subview)
  62. }
  63. toolbars.append(contentsOf: toolbarsInSubviews(forView: subview))
  64. }
  65. return toolbars
  66. }
  67. }