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.

214 lines
7.9 KiB

6 years ago
6 years ago
5 years ago
6 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
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. import Localize_Swift
  10. class GmeContactsViewController: UIViewController {
  11. // MARK: IBOutlets
  12. @IBOutlet weak var tableview: UITableView!
  13. var presenter: GmeContactsModuleInterface?
  14. var contacts: [GmeContacts] = [] {
  15. didSet {
  16. self.tableview.reloadData()
  17. }
  18. }
  19. // MARK: Properties
  20. // MARK: VC's Life cycle
  21. override func viewDidLoad() {
  22. super.viewDidLoad()
  23. self.viperSetup() // since the viewcontroller in the tabbar is in strong bind with storyboard and segue
  24. self.setup()
  25. }
  26. override func viewWillAppear(_ animated: Bool) {
  27. super.viewWillAppear(animated)
  28. self.navigationItem.title = "branch_text".localized()
  29. if self.presentingViewController == nil {
  30. self.navigationItem.rightBarButtonItem = nil
  31. }
  32. }
  33. // MARK: IBActions
  34. @IBAction func touchClose(_ sender: UIBarButtonItem) {
  35. self.dismiss(animated: true, completion: nil)
  36. }
  37. // MARK: Other Functions
  38. private func setup() {
  39. self.tableview.dataSource = self
  40. self.tableview.delegate = self
  41. // all setup should be done here
  42. self.createTestContacts()
  43. NotificationCenter.default.addObserver(self, selector: #selector(setupTabItem), name: NSNotification.Name(LCLLanguageChangeNotification), object: nil)
  44. }
  45. struct StringConstants {
  46. }
  47. private func createTestContacts() {
  48. // let headOfficeContacts = GmeContacts()
  49. // headOfficeContacts.title = "Head Office"
  50. // headOfficeContacts.address = "325, Jong-ro, Jongno-gu, 03104 Seoul"
  51. // headOfficeContacts.contactNumber = ["15886864"]
  52. // headOfficeContacts.language = "Korean Language Support"
  53. let dongdaemunBranchContacts = GmeContacts()
  54. dongdaemunBranchContacts.title = "Dongdaemun Branch"
  55. dongdaemunBranchContacts.address = "315, Jong-ro Jongno-gu, Seoul \n(Dongdaemun Station - Exit 3) \n 서울시 종로구 종로 315"
  56. dongdaemunBranchContacts.contactNumber = ["027635559"]
  57. let hwaseongBranchContacts = GmeContacts()
  58. hwaseongBranchContacts.title = "Hwaseong Branch"
  59. hwaseongBranchContacts.address = "1101-1, 3.1 Manse-ro Hyangnam-eup, Hwaseong-si, Gyeonggi-do \n(Baran Market Place) \n 경기도 화성시 향남읍 3.1만세로 1101-1"
  60. hwaseongBranchContacts.contactNumber = ["0313540450"]
  61. let ansanBranchContacts = GmeContacts()
  62. ansanBranchContacts.title = "Ansan Branch"
  63. ansanBranchContacts.address = "2nd floor, 455, Jungang-daero, Danwon-gu, Ansan -si, Gyeonggi-do \n(Entrance of Asian Street) \n 경기도 안산시 단원구 중앙대로 455 2층"
  64. ansanBranchContacts.contactNumber = ["0313626740"]
  65. let gimhaeBranchContacts = GmeContacts()
  66. gimhaeBranchContacts.title = "Gimhae Branch"
  67. gimhaeBranchContacts.address = "84, Garak-ro, Gimhae-si, Gyeongsangnam-do,\n(Opposite to Top Mart) \n 경상남도 김해시 가락로 84 "
  68. gimhaeBranchContacts.contactNumber = ["0553295559"]
  69. let songuriBranchContacts = GmeContacts()
  70. songuriBranchContacts.title = "Songu-ri Branch"
  71. songuriBranchContacts.address = "91, Solmoru-ro, Soheul-eup, Pocheon-si, Gyeonggi-do, Korea\nNext to Nonghyub Bank) \n 경기도 포천시 소흘읍 솔모루로 91"
  72. songuriBranchContacts.contactNumber = ["0315411856"]
  73. let dongdaemunCisBranch = GmeContacts()
  74. dongdaemunCisBranch.title = "Dongdaemun CIS Branch"
  75. dongdaemunCisBranch.address = "2nd floor, 281, Changgyeonggunag-ro Jongno-gu, Seoul\n(Upper floor of Dongdaemun Mart) \n 서울 중구 을지로 42길 5 2층"
  76. dongdaemunCisBranch.contactNumber = ["0221386429", "01030156864"]
  77. let hyehwaBranch = GmeContacts()
  78. hyehwaBranch.title = "Hyehwa Branch"
  79. hyehwaBranch.address = "281, Changgyeonggung-ro, Jongno-gu, Seoul Hyehwa Rotary\n(Right across from Catholic Church) \n 서울특별시 종로구 창경궁로 281"
  80. hyehwaBranch.contactNumber = ["0221386429", "01029706864"]
  81. let gmeContacts = [dongdaemunCisBranch, dongdaemunBranchContacts, hwaseongBranchContacts, ansanBranchContacts, gimhaeBranchContacts, songuriBranchContacts, hyehwaBranch]
  82. self.contacts = gmeContacts
  83. }
  84. private func call(number: String) {
  85. let number = number.removeWhitespacesInBetween()
  86. if let url = URL(string: "tel://\(number)") {
  87. if UIApplication.shared.canOpenURL(url) {
  88. UIApplication.shared.openURL(url)
  89. }
  90. }
  91. }
  92. override func setupTabItem() {
  93. let image = UIImage.init(named: "ic-agent")
  94. self.tabBarItem = UITabBarItem(title: "branch_text".localized(), image: image, selectedImage: nil)
  95. self.tabBarItem.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: UI_USER_INTERFACE_IDIOM() == .pad ? 2 : -6)
  96. }
  97. }
  98. // MARK: GmeContactsViewInterface
  99. extension GmeContactsViewController: GmeContactsViewInterface {
  100. }
  101. extension GmeContactsViewController {
  102. func viperSetup() {
  103. let service = GmeContactsService()
  104. let interactor = GmeContactsInteractor(service: service)
  105. let presenter = GmeContactsPresenter()
  106. let wireframe = GmeContactsWireframe()
  107. self.presenter = presenter
  108. interactor.output = presenter
  109. presenter.interactor = interactor
  110. presenter.wireframe = wireframe
  111. presenter.view = self
  112. wireframe.view = self
  113. }
  114. }
  115. extension GmeContactsViewController: UITableViewDelegate {
  116. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  117. print(indexPath.row)
  118. if indexPath.row == 0 {return 10}
  119. return UITableViewAutomaticDimension
  120. }
  121. }
  122. extension GmeContactsViewController: UITableViewDataSource {
  123. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  124. return contacts.count + 1
  125. }
  126. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  127. if indexPath.row == 0 {
  128. let cell = tableView.dequeueReusableCell(withIdentifier: "EmptyTableViewCell") as! EmptyTableViewCell
  129. return cell
  130. }
  131. let cell = tableView.dequeueReusableCell(withIdentifier: "GmeContactsTableViewCell") as! GmeContactsTableViewCell
  132. cell.contact = self.contacts.elementAt(index: indexPath.row - 1)
  133. cell.delegate = self
  134. cell.index = indexPath.row - 1
  135. cell.setup()
  136. return cell
  137. }
  138. }
  139. extension GmeContactsViewController: GmeContactCallDelegate {
  140. func call(index: Int?) {
  141. guard let index = index else {return}
  142. if let contact = self.contacts.elementAt(index: index) {
  143. let numbers = contact.contactNumber
  144. let alert = UIAlertController(title:nil, message:"help_you_text".localized(), preferredStyle: .actionSheet)
  145. numbers?.forEach({ number in
  146. let action = UIAlertAction.init(title: "\(number)", style: UIAlertActionStyle.default, handler: { action in
  147. self.call(number: number)
  148. })
  149. alert.addAction(action)
  150. })
  151. alert.view.tintColor = UIColor.darkGray
  152. alert.addAction(UIAlertAction(title: "cancel_text".localized(), style: UIAlertActionStyle.cancel, handler: nil))
  153. present(alert, animated: true, completion: nil)
  154. }
  155. }
  156. }