VerificationViewController.swift 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. class VerificationViewController: ThemedViewController {
  21. @IBOutlet weak var scrollView: UIScrollView!
  22. @IBOutlet weak var descriptionText: SSLabel!
  23. @IBOutlet weak var workTitle: SSLabel!
  24. @IBOutlet weak var otherTitle: SSLabel!
  25. @IBOutlet weak var labelLevel0: SSLabel!
  26. @IBOutlet weak var labelLevel1: SSLabel!
  27. @IBOutlet weak var labelLevel2: SSLabel!
  28. @IBOutlet weak var labelLevel3: SSLabel!
  29. @IBOutlet weak var labelLevel4: SSLabel!
  30. @IBOutlet weak var imageLevel0: UIImageView!
  31. @IBOutlet weak var imageLevel1: UIImageView!
  32. @IBOutlet weak var imageLevel2: UIImageView!
  33. @IBOutlet weak var imageLevel3: UIImageView!
  34. @IBOutlet weak var imageLevel4: UIImageView!
  35. @IBOutlet weak var workConstraint: NSLayoutConstraint!
  36. @IBOutlet weak var threemaConstraint: NSLayoutConstraint!
  37. private var wasTabBarHidden = false
  38. override func viewDidLoad() {
  39. super.viewDidLoad()
  40. labelLevel0.verticalTextAlignment = SSLabelVerticalTextAlignmentTop
  41. labelLevel1.verticalTextAlignment = SSLabelVerticalTextAlignmentTop
  42. labelLevel2.verticalTextAlignment = SSLabelVerticalTextAlignmentTop
  43. labelLevel3.verticalTextAlignment = SSLabelVerticalTextAlignmentTop
  44. labelLevel4.verticalTextAlignment = SSLabelVerticalTextAlignmentTop
  45. labelLevel0.accessibilityLabel = accessibilityLabelForLevel(level: 0)
  46. labelLevel1.accessibilityLabel = accessibilityLabelForLevel(level: 1)
  47. labelLevel2.accessibilityLabel = accessibilityLabelForLevel(level: 2)
  48. labelLevel3.accessibilityLabel = accessibilityLabelForLevel(level: 3)
  49. labelLevel4.accessibilityLabel = accessibilityLabelForLevel(level: 4)
  50. imageLevel0.image = StyleKit.verificationSmall0
  51. imageLevel1.image = StyleKit.verificationSmall1
  52. imageLevel2.image = StyleKit.verificationSmall2
  53. imageLevel3.image = StyleKit.verificationSmall3
  54. imageLevel4.image = StyleKit.verificationSmall4
  55. if !LicenseStore.requiresLicenseKey() {
  56. imageLevel3.isHidden = true
  57. imageLevel4.isHidden = true
  58. labelLevel3.isHidden = true
  59. labelLevel4.isHidden = true
  60. workTitle.isHidden = true
  61. otherTitle.isHidden = true
  62. if workConstraint.priority != .defaultLow {
  63. workConstraint.priority = .defaultLow
  64. }
  65. if threemaConstraint.priority != .required {
  66. threemaConstraint.priority = .required
  67. }
  68. } else {
  69. if workConstraint.priority != .required {
  70. workConstraint.priority = .required
  71. }
  72. if threemaConstraint.priority != .defaultLow {
  73. threemaConstraint.priority = .defaultLow
  74. }
  75. }
  76. setupColors()
  77. }
  78. override func viewWillAppear(_ animated: Bool) {
  79. super.viewWillAppear(animated)
  80. updateView()
  81. }
  82. override func viewWillDisappear(_ animated: Bool) {
  83. super.viewWillDisappear(animated)
  84. if let tabBarController = tabBarController {
  85. tabBarController.tabBar.isHidden = wasTabBarHidden
  86. }
  87. }
  88. func setupColors() {
  89. view.backgroundColor = Colors.background()
  90. descriptionText.textColor = Colors.fontNormal()
  91. labelLevel0.textColor = Colors.fontNormal()
  92. labelLevel1.textColor = Colors.fontNormal()
  93. labelLevel2.textColor = Colors.fontNormal()
  94. labelLevel3.textColor = Colors.fontNormal()
  95. labelLevel4.textColor = Colors.fontNormal()
  96. }
  97. func updateView() {
  98. if let tabBarController = tabBarController {
  99. wasTabBarHidden = tabBarController.tabBar.isHidden
  100. tabBarController.tabBar.isHidden = true
  101. }
  102. descriptionText.text = BundleUtil.localizedString(forKey: "verification_level_text")
  103. workTitle.text = BundleUtil.localizedString(forKey: "verification_level_section_work")
  104. otherTitle.text = BundleUtil.localizedString(forKey: "verification_level_section_other")
  105. labelLevel0.text = BundleUtil.localizedString(forKey: "level0_explanation")
  106. labelLevel1.text = BundleUtil.localizedString(forKey: "level1_explanation")
  107. labelLevel2.text = BundleUtil.localizedString(forKey: "level2_explanation")
  108. labelLevel3.text = BundleUtil.localizedString(forKey: "level3_explanation")
  109. labelLevel4.text = BundleUtil.localizedString(forKey: "level4_explanation")
  110. }
  111. // MARK: - Private functions
  112. private func accessibilityLabelForLevel(level: Int) -> String {
  113. let title = BundleUtil.localizedString(forKey: String(format: "level%d_title", level))
  114. let description = BundleUtil.localizedString(forKey: String(format: "level%d_explanation", level))
  115. return "\(title!), \(description!)"
  116. }
  117. }