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.

245 lines
7.8 KiB

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