MeContactDetailsViewController.swift 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2018-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. import ThreemaFramework
  22. import QuartzCore
  23. class MeContactDetailsViewController: ThemedTableViewController {
  24. @IBOutlet weak var headerView: UIView!
  25. @IBOutlet weak var imageView: UIImageView!
  26. @IBOutlet weak var nameLabel: UILabel!
  27. @IBOutlet weak var threemaTypeIcon: UIImageView!
  28. override func viewDidLoad() {
  29. super.viewDidLoad()
  30. navigationController?.interactivePopGestureRecognizer?.isEnabled = true
  31. navigationController?.interactivePopGestureRecognizer?.delegate = nil
  32. NotificationCenter.default.addObserver(self, selector: #selector(colorThemeChanged(notification:)), name: NSNotification.Name(rawValue: kNotificationColorThemeChanged), object: nil)
  33. let tapRecognizer = UITapGestureRecognizer.init(target: self, action: #selector(tappedImage))
  34. imageView.addGestureRecognizer(tapRecognizer)
  35. threemaTypeIcon.image = Utils.threemaTypeIcon()
  36. setupColors()
  37. }
  38. override func viewWillAppear(_ animated: Bool) {
  39. super.viewWillAppear(animated)
  40. view.alpha = 1.0
  41. updateView()
  42. }
  43. override func viewDidAppear(_ animated: Bool) {
  44. super.viewDidAppear(animated)
  45. if (navigationController?.isNavigationBarHidden)! {
  46. navigationController?.isNavigationBarHidden = false
  47. }
  48. }
  49. override func viewWillLayoutSubviews() {
  50. super.viewWillLayoutSubviews()
  51. let fontDescriptor:UIFontDescriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: .title3)
  52. let size = fontDescriptor.pointSize
  53. nameLabel.font = UIFont.boldSystemFont(ofSize: size)
  54. }
  55. func setupColors() {
  56. nameLabel.textColor = Colors.fontNormal()
  57. nameLabel.shadowColor = nil
  58. }
  59. func updateView() {
  60. var name = MyIdentityStore.shared().pushFromName
  61. if name == nil {
  62. name = MyIdentityStore.shared().identity
  63. }
  64. title = String.init(format:"@%@", BundleUtil.localizedString(forKey: "me"))
  65. nameLabel.text = name
  66. headerView.accessibilityLabel = name
  67. if let profilePicture = MyIdentityStore.shared().profilePicture,
  68. profilePicture["ProfilePicture"] != nil {
  69. imageView.image = UIImage.init(data: profilePicture["ProfilePicture"] as! Data)
  70. imageView.contentMode = .scaleAspectFill
  71. imageView.layer.masksToBounds = true
  72. imageView.layer.cornerRadius = imageView.bounds.size.width / 2
  73. } else {
  74. imageView.image = AvatarMaker.shared()?.unknownPersonImage()
  75. }
  76. imageView.accessibilityLabel = NSLocalizedString("my_profilepicture", comment: "")
  77. threemaTypeIcon.isHidden = !LicenseStore.requiresLicenseKey()
  78. tableView.reloadData()
  79. }
  80. // MARK: - Table view data source
  81. override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  82. return 3
  83. }
  84. override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  85. if indexPath.row == 0 {
  86. let cell = tableView.dequeueReusableCell(withIdentifier: "IdentityCell", for: indexPath)
  87. let label = cell.viewWithTag(100) as! UILabel
  88. label.text = MyIdentityStore.shared().identity
  89. return cell
  90. }
  91. else if indexPath.row == 1 {
  92. let cell = tableView.dequeueReusableCell(withIdentifier: "PublicNicknameCell", for: indexPath)
  93. let label = cell.viewWithTag(101) as! UILabel
  94. var name = MyIdentityStore.shared().pushFromName
  95. if name == nil {
  96. name = MyIdentityStore.shared().identity
  97. }
  98. label.text = name
  99. return cell
  100. }
  101. else {
  102. let cell:KeyFingerprintCell = tableView.dequeueReusableCell(withIdentifier: "KeyFingerprintCell", for: indexPath) as! KeyFingerprintCell
  103. cell.fingerprintValueLabel.text = CryptoUtils.fingerprint(forPublicKey: MyIdentityStore.shared().publicKey)
  104. return cell
  105. }
  106. }
  107. // MARK: - GestureRecognizer
  108. @objc func tappedImage() {
  109. if let profilePicture = MyIdentityStore.shared().profilePicture,
  110. profilePicture["ProfilePicture"] != nil {
  111. let image = UIImage.init(data: profilePicture["ProfilePicture"] as! Data)
  112. if image != nil {
  113. let imageController: FullscreenImageViewController = FullscreenImageViewController.init(for: image)
  114. if UIDevice.current.userInterfaceIdiom == .pad {
  115. let nav: ModalNavigationController = ModalNavigationController.init(rootViewController: imageController)
  116. nav.showDoneButton = true
  117. nav.showFullScreenOnIPad = true
  118. self.present(nav, animated: true, completion: nil)
  119. } else {
  120. navigationController!.pushViewController(imageController, animated: true)
  121. }
  122. }
  123. }
  124. }
  125. // MARK: - Notifications
  126. @objc func colorThemeChanged(notification:NSNotification) {
  127. setupColors()
  128. }
  129. func showProfilePictureChanged(notification:NSNotification) {
  130. updateView()
  131. }
  132. }