CompanyDirectoryContactCell.swift 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. class CompanyDirectoryContactCell: UITableViewCell {
  22. @IBOutlet weak var avatar: UIImageView!
  23. @IBOutlet weak var nameLabel: UILabel!
  24. @IBOutlet weak var categoryLabel: UILabel!
  25. @IBOutlet weak var identityLabel: UILabel!
  26. @IBOutlet weak var csiLabel: UILabel!
  27. @IBOutlet weak var verificationLevel: UIImageView!
  28. var addContactActive: Bool = true
  29. var contact: CompanyDirectoryContact! {
  30. didSet {
  31. setupCell()
  32. }
  33. }
  34. func setupCell() {
  35. avatar.image = AvatarMaker.shared().avatar(forFirstName: contact.first, lastName: contact.last, size: avatar.frame.size.width)
  36. nameLabel.text = contact.fullName()
  37. categoryLabel.text = contact.categoryString()
  38. csiLabel.text = contact.csi
  39. identityLabel.text = contact.id
  40. verificationLevel.image = StyleKit.verification3
  41. if ContactStore.shared()?.contact(forIdentity: contact.id) != nil {
  42. self.accessoryView = nil
  43. self.accessoryType = addContactActive == true ? .disclosureIndicator : .none
  44. } else {
  45. if addContactActive == true {
  46. self.accessoryType = .none
  47. let addButton = UIButton.init(type: .contactAdd)
  48. addButton.addTarget(self, action: #selector(addContact), for: .touchUpInside)
  49. addButton.imageEdgeInsets = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: -5)
  50. self.accessoryView = addButton
  51. } else {
  52. self.accessoryView = nil
  53. self.accessoryType = .none
  54. }
  55. }
  56. }
  57. func setupColors() {
  58. nameLabel.textColor = Colors.fontNormal()
  59. categoryLabel.textColor = Colors.fontLight()
  60. csiLabel.textColor = Colors.fontLight()
  61. identityLabel.textColor = Colors.fontLight()
  62. }
  63. @objc private func addContact() {
  64. ContactStore.shared()?.addWorkContact(withIdentity: contact.id, publicKey: contact.pk, firstname: contact.first, lastname: contact.last)
  65. setupCell()
  66. }
  67. }