ContactListController.swift 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // ContactListController.swift
  3. // deltachat-ios
  4. //
  5. // Created by Friedel Ziegelmayer on 26.12.18.
  6. // Copyright © 2018 Jonas Reinsch. All rights reserved.
  7. //
  8. import UIKit
  9. class ContactListController: UITableViewController {
  10. weak var coordinator: ContactListCoordinator?
  11. let contactCellReuseIdentifier = "xyz"
  12. var contactIds: [Int] = Utils.getContactIds()
  13. var contactIdsForGroup: Set<Int> = []
  14. override func viewDidLoad() {
  15. super.viewDidLoad()
  16. title = "Contacts"
  17. navigationController?.navigationBar.prefersLargeTitles = true
  18. tableView.rowHeight = 80
  19. tableView.register(ContactCell.self, forCellReuseIdentifier: contactCellReuseIdentifier)
  20. }
  21. private func getContactIds() {
  22. contactIds = Utils.getContactIds()
  23. tableView.reloadData()
  24. }
  25. override func viewWillAppear(_ animated: Bool) {
  26. super.viewWillAppear(animated)
  27. if #available(iOS 11.0, *) {
  28. navigationController?.navigationBar.prefersLargeTitles = true
  29. }
  30. getContactIds()
  31. }
  32. override func viewWillDisappear(_ animated: Bool) {
  33. super.viewWillDisappear(animated)
  34. if #available(iOS 11.0, *) {
  35. navigationController?.navigationBar.prefersLargeTitles = false
  36. }
  37. }
  38. override func didReceiveMemoryWarning() {
  39. super.didReceiveMemoryWarning()
  40. }
  41. override func numberOfSections(in _: UITableView) -> Int {
  42. return 1
  43. }
  44. override func tableView(_: UITableView, numberOfRowsInSection _: Int) -> Int {
  45. return contactIds.count
  46. }
  47. override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  48. let cell: ContactCell
  49. if let c = tableView.dequeueReusableCell(withIdentifier: "ChatCell") as? ContactCell {
  50. cell = c
  51. } else {
  52. cell = ContactCell(style: .subtitle, reuseIdentifier: "ChatCell")
  53. }
  54. let row = indexPath.row
  55. let contactRow = row
  56. if contactRow < contactIds.count {
  57. let contact = MRContact(id: contactIds[contactRow])
  58. cell.nameLabel.text = contact.name
  59. cell.emailLabel.text = contact.email
  60. // TODO: provider a nice selection
  61. cell.selectionStyle = .none
  62. if let img = contact.profileImage {
  63. cell.setImage(img)
  64. } else {
  65. cell.setBackupImage(name: contact.name, color: contact.color)
  66. }
  67. cell.setVerified(isVerified: contact.isVerified)
  68. }
  69. return cell
  70. }
  71. override func tableView(_: UITableView, didSelectRowAt indexPath: IndexPath) {
  72. let contactId = contactIds[indexPath.row]
  73. let contactProfileController = ContactProfileViewController(contactId: contactId)
  74. navigationController?.pushViewController(contactProfileController, animated: true)
  75. }
  76. }