AccountSwitchViewController.swift 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import UIKit
  2. import DcCore
  3. class AccountSwitchViewController: UITableViewController {
  4. override func viewDidLoad() {
  5. super.viewDidLoad()
  6. setupSubviews()
  7. }
  8. private func setupSubviews() {
  9. title = String.localized("switch_account")
  10. tableView.register(AccountCell.self, forCellReuseIdentifier: AccountCell.reuseIdentifier)
  11. tableView.rowHeight = AccountCell.cellHeight
  12. tableView.separatorStyle = .none
  13. }
  14. }
  15. class AccountCell: UITableViewCell {
  16. static let reuseIdentifier = "accountCell_reuse_identifier"
  17. static var cellHeight: CGFloat {
  18. let textHeight = UIFont.preferredFont(forTextStyle: .headline).pointSize + UIFont.preferredFont(forTextStyle: .subheadline).pointSize + 24
  19. if textHeight > 74.5 {
  20. return textHeight
  21. }
  22. return 74.5
  23. }
  24. var isLargeText: Bool {
  25. return UIFont.preferredFont(forTextStyle: .body).pointSize > 36
  26. }
  27. lazy var accountAvatar: InitialsBadge = {
  28. let avatar = InitialsBadge(size: 52, accessibilityLabel: "")
  29. return avatar
  30. }()
  31. lazy var accountName: UILabel = {
  32. let label = UILabel()
  33. label.translatesAutoresizingMaskIntoConstraints = false
  34. return label
  35. }
  36. func setupSubviews() {
  37. addSubview(accountAvatar)
  38. addSubview(label)
  39. //addSubview(
  40. }
  41. public func updateCell(dcContext: DcContext) {
  42. let accountId = dcContext.id
  43. let title = dcContext.displayname ?? dcContext.addr ?? ""
  44. let contact = dcContext.getContact(id: Int(DC_CONTACT_ID_SELF))
  45. accountAvatar.setColor(contact.color)
  46. accountAvatar.setName(title)
  47. if let image = contact.profileImage {
  48. accountAvatar.setImage(image)
  49. }
  50. }
  51. }