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

//
// GmeContactsViewController.swift
// GMERemittance
//
// Created by gme_2 on 25/08/2018.
//Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
//
import UIKit
class GmeContactsViewController: UIViewController {
// MARK: IBOutlets
@IBOutlet weak var tableview: UITableView!
var presenter: GmeContactsModuleInterface?
var contacts: [GmeContacts] = [] {
didSet {
self.tableview.reloadData()
}
}
// MARK: Properties
// MARK: VC's Life cycle
override func viewDidLoad() {
super.viewDidLoad()
self.viperSetup() // since the viewcontroller in the tabbar is in strong bind with storyboard and segue
self.setup()
}
// MARK: IBActions
// MARK: Other Functions
private func setup() {
self.tableview.dataSource = self
self.tableview.delegate = self
// all setup should be done here
self.createTestContacts()
}
private func createTestContacts() {
let headOfficeContacts = GmeContacts()
headOfficeContacts.title = "Head Office"
headOfficeContacts.address = "325, Jong-ro, Jongno-gu, 03104 Seoul"
headOfficeContacts.contactNumber = "15886864"
headOfficeContacts.language = "Korean Language Support"
let dongdaemunBranchContacts = GmeContacts()
dongdaemunBranchContacts.title = "Dongdaemun Branch"
dongdaemunBranchContacts.address = "315, Jong-ro, Jongno-gu, 03105 Seoul (Near Dongdaemun Station Gate 3)"
dongdaemunBranchContacts.contactNumber = "027635559"
let hwaseongBranchContacts = GmeContacts()
hwaseongBranchContacts.title = "Hwaseong Branch"
hwaseongBranchContacts.address = "1102-1, 3.1 Manse-ro, Hyangnam-eup, Hwaseong-si, 18593 Gyeonggi-do"
hwaseongBranchContacts.contactNumber = "0313540450"
let ansanBranchContacts = GmeContacts()
ansanBranchContacts.title = "Ansan Branch"
ansanBranchContacts.address = "Ansan-si, Gyeonggido Dan-Wongu, Wongogdong Jung-Angdaero 445 (798-12 beonji) 2nd floor"
ansanBranchContacts.contactNumber = "0313626740"
let gimhaeBranchContacts = GmeContacts()
gimhaeBranchContacts.title = "Gimhae Branch"
gimhaeBranchContacts.address = "84, Garak-ro, Gimhae-si, Gyeongsangnam-do"
gimhaeBranchContacts.contactNumber = "0553295559"
let songuriBranchContacts = GmeContacts()
songuriBranchContacts.title = "Songu-ri Branch"
songuriBranchContacts.address = "91, Solmoru-ro, Soheul-eup, Pocheon-si, Gyeonggi-do, Korea 11175 (Across from K-Mart)"
songuriBranchContacts.contactNumber = "0315411856"
let gmeContacts = [headOfficeContacts, dongdaemunBranchContacts, hwaseongBranchContacts, ansanBranchContacts, gimhaeBranchContacts, songuriBranchContacts]
self.contacts = gmeContacts
}
}
// MARK: GmeContactsViewInterface
extension GmeContactsViewController: GmeContactsViewInterface {
}
extension GmeContactsViewController {
func viperSetup() {
let service = GmeContactsService()
let interactor = GmeContactsInteractor(service: service)
let presenter = GmeContactsPresenter()
let wireframe = GmeContactsWireframe()
self.presenter = presenter
interactor.output = presenter
presenter.interactor = interactor
presenter.wireframe = wireframe
presenter.view = self
wireframe.view = self
}
}
extension GmeContactsViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
print(indexPath.row)
if indexPath.row == 0 {return 10}
return UITableViewAutomaticDimension
}
}
extension GmeContactsViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return contacts.count + 1
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.row == 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: "EmptyTableViewCell") as! EmptyTableViewCell
return cell
}
let cell = tableView.dequeueReusableCell(withIdentifier: "GmeContactsTableViewCell") as! GmeContactsTableViewCell
cell.contact = self.contacts.elementAt(index: indexPath.row - 1)
cell.setup()
return cell
}
}