You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

139 lines
4.6 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. //
  2. // GmeContactsViewController.swift
  3. // GMERemittance
  4. //
  5. // Created by gme_2 on 25/08/2018.
  6. //Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import UIKit
  9. class GmeContactsViewController: UIViewController {
  10. // MARK: IBOutlets
  11. @IBOutlet weak var tableview: UITableView!
  12. var presenter: GmeContactsModuleInterface?
  13. var contacts: [GmeContacts] = [] {
  14. didSet {
  15. self.tableview.reloadData()
  16. }
  17. }
  18. // MARK: Properties
  19. // MARK: VC's Life cycle
  20. override func viewDidLoad() {
  21. super.viewDidLoad()
  22. self.viperSetup() // since the viewcontroller in the tabbar is in strong bind with storyboard and segue
  23. self.setup()
  24. }
  25. // MARK: IBActions
  26. // MARK: Other Functions
  27. private func setup() {
  28. self.tableview.dataSource = self
  29. self.tableview.delegate = self
  30. // all setup should be done here
  31. self.createTestContacts()
  32. }
  33. private func createTestContacts() {
  34. let headOfficeContacts = GmeContacts()
  35. headOfficeContacts.title = "Head Office"
  36. headOfficeContacts.address = "325, Jong-ro, Jongno-gu, 03104 Seoul"
  37. headOfficeContacts.contactNumber = "15886864"
  38. headOfficeContacts.language = "Korean Language Support"
  39. let dongdaemunBranchContacts = GmeContacts()
  40. dongdaemunBranchContacts.title = "Dongdaemun Branch"
  41. dongdaemunBranchContacts.address = "315, Jong-ro, Jongno-gu, 03105 Seoul (Near Dongdaemun Station Gate 3)"
  42. dongdaemunBranchContacts.contactNumber = "027635559"
  43. let hwaseongBranchContacts = GmeContacts()
  44. hwaseongBranchContacts.title = "Hwaseong Branch"
  45. hwaseongBranchContacts.address = "1102-1, 3.1 Manse-ro, Hyangnam-eup, Hwaseong-si, 18593 Gyeonggi-do"
  46. hwaseongBranchContacts.contactNumber = "0313540450"
  47. let ansanBranchContacts = GmeContacts()
  48. ansanBranchContacts.title = "Ansan Branch"
  49. ansanBranchContacts.address = "Ansan-si, Gyeonggido Dan-Wongu, Wongogdong Jung-Angdaero 445 (798-12 beonji) 2nd floor"
  50. ansanBranchContacts.contactNumber = "0313626740"
  51. let gimhaeBranchContacts = GmeContacts()
  52. gimhaeBranchContacts.title = "Gimhae Branch"
  53. gimhaeBranchContacts.address = "84, Garak-ro, Gimhae-si, Gyeongsangnam-do"
  54. gimhaeBranchContacts.contactNumber = "0553295559"
  55. let songuriBranchContacts = GmeContacts()
  56. songuriBranchContacts.title = "Songu-ri Branch"
  57. songuriBranchContacts.address = "91, Solmoru-ro, Soheul-eup, Pocheon-si, Gyeonggi-do, Korea 11175 (Across from K-Mart)"
  58. songuriBranchContacts.contactNumber = "0315411856"
  59. let gmeContacts = [headOfficeContacts, dongdaemunBranchContacts, hwaseongBranchContacts, ansanBranchContacts, gimhaeBranchContacts, songuriBranchContacts]
  60. self.contacts = gmeContacts
  61. }
  62. }
  63. // MARK: GmeContactsViewInterface
  64. extension GmeContactsViewController: GmeContactsViewInterface {
  65. }
  66. extension GmeContactsViewController {
  67. func viperSetup() {
  68. let service = GmeContactsService()
  69. let interactor = GmeContactsInteractor(service: service)
  70. let presenter = GmeContactsPresenter()
  71. let wireframe = GmeContactsWireframe()
  72. self.presenter = presenter
  73. interactor.output = presenter
  74. presenter.interactor = interactor
  75. presenter.wireframe = wireframe
  76. presenter.view = self
  77. wireframe.view = self
  78. }
  79. }
  80. extension GmeContactsViewController: UITableViewDelegate {
  81. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  82. print(indexPath.row)
  83. if indexPath.row == 0 {return 10}
  84. return UITableViewAutomaticDimension
  85. }
  86. }
  87. extension GmeContactsViewController: UITableViewDataSource {
  88. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  89. return contacts.count + 1
  90. }
  91. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  92. if indexPath.row == 0 {
  93. let cell = tableView.dequeueReusableCell(withIdentifier: "EmptyTableViewCell") as! EmptyTableViewCell
  94. return cell
  95. }
  96. let cell = tableView.dequeueReusableCell(withIdentifier: "GmeContactsTableViewCell") as! GmeContactsTableViewCell
  97. cell.contact = self.contacts.elementAt(index: indexPath.row - 1)
  98. cell.setup()
  99. return cell
  100. }
  101. }