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

//
// GmeContactsViewController.swift
// GMERemittance
//
// Created by gme_2 on 25/08/2018.
//Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
//
import UIKit
import Localize_Swift
class GmeContactsViewController: UIViewController {
// MARK: IBOutlets
@IBOutlet weak var tableview: UITableView!
var presenter: GmeContactsModuleInterface?
var contacts: [GmeContacts] = [] {
didSet {
self.tableview.reloadData()
}
}
var model: [Branch]? {
didSet {
guard let model = model
else {
return
}
contacts = model.map{
let branch = GmeContacts()
branch.title = $0.agentName
branch.address = $0.agentAddress
branch.contactNumber = [$0.agentPhone1] as? [String]
return branch
}
}
}
// MARK: Properties
// MARK: VC's Life cycle
override func viewDidLoad() {
super.viewDidLoad()
self.setup()
presenter?.fetchBranch()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationItem.title = "branch_text".localized()
if self.presentingViewController == nil {
self.navigationItem.leftBarButtonItem = nil
}
}
// MARK: IBActions
@IBAction func touchClose(_ sender: UIBarButtonItem) {
self.dismiss(animated: true, completion: nil)
}
// MARK: Other Functions
private func setup() {
self.tableview.dataSource = self
self.tableview.delegate = self
// all setup should be done here
self.createTestContacts()
NotificationCenter.default.addObserver(self, selector: #selector(setupTabItem), name: NSNotification.Name(LCLLanguageChangeNotification), object: nil)
}
struct StringConstants {
}
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, Seoul \n(Dongdaemun Station - Exit 3) \n 서울시 종로구 종로 315"
dongdaemunBranchContacts.contactNumber = ["027635559"]
let hwaseongBranchContacts = GmeContacts()
hwaseongBranchContacts.title = "Hwaseong Branch"
hwaseongBranchContacts.address = "1101-1, 3.1 Manse-ro Hyangnam-eup, Hwaseong-si, Gyeonggi-do \n(Baran Market Place) \n 경기도 화성시 향남읍 3.1만세로 1101-1"
hwaseongBranchContacts.contactNumber = ["0313540450"]
let ansanBranchContacts = GmeContacts()
ansanBranchContacts.title = "Ansan Branch"
ansanBranchContacts.address = "2nd floor, 455, Jungang-daero, Danwon-gu, Ansan -si, Gyeonggi-do \n(Entrance of Asian Street) \n 경기도 안산시 단원구 중앙대로 455 2층"
ansanBranchContacts.contactNumber = ["0313626740"]
let gimhaeBranchContacts = GmeContacts()
gimhaeBranchContacts.title = "Gimhae Branch"
gimhaeBranchContacts.address = "84, Garak-ro, Gimhae-si, Gyeongsangnam-do,\n(Opposite to Top Mart) \n 경상남도 김해시 가락로 84 "
gimhaeBranchContacts.contactNumber = ["0553295559"]
let songuriBranchContacts = GmeContacts()
songuriBranchContacts.title = "Songu-ri Branch"
songuriBranchContacts.address = "91, Solmoru-ro, Soheul-eup, Pocheon-si, Gyeonggi-do, Korea\nNext to Nonghyub Bank) \n 경기도 포천시 소흘읍 솔모루로 91"
songuriBranchContacts.contactNumber = ["0315411856"]
let dongdaemunCisBranch = GmeContacts()
dongdaemunCisBranch.title = "Dongdaemun CIS Branch"
dongdaemunCisBranch.address = "2nd floor, 281, Changgyeonggunag-ro Jongno-gu, Seoul\n(Upper floor of Dongdaemun Mart) \n 서울 중구 을지로 42길 5 2층"
dongdaemunCisBranch.contactNumber = ["0221386429", "01030156864"]
let hyehwaBranch = GmeContacts()
hyehwaBranch.title = "Hyehwa Branch"
hyehwaBranch.address = "281, Changgyeonggung-ro, Jongno-gu, Seoul Hyehwa Rotary\n(Right across from Catholic Church) \n 서울특별시 종로구 창경궁로 281"
hyehwaBranch.contactNumber = ["0221386429", "01029706864"]
let gmeContacts = [dongdaemunCisBranch, dongdaemunBranchContacts, hwaseongBranchContacts, ansanBranchContacts, gimhaeBranchContacts, songuriBranchContacts, hyehwaBranch]
self.contacts = gmeContacts
}
private func call(number: String) {
let number = number.removeWhitespacesInBetween()
if let url = URL(string: "tel://\(number)") {
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.openURL(url)
}
}
}
override func setupTabItem() {
let image = UIImage.init(named: "ic-agent")
self.tabBarItem = UITabBarItem(title: "branch_text".localized(), image: image, selectedImage: nil)
self.tabBarItem.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: UI_USER_INTERFACE_IDIOM() == .pad ? 2 : -6)
}
}
// MARK: GmeContactsViewInterface
extension GmeContactsViewController: GmeContactsViewInterface {
func setBranchModel(with model: [Branch]?) {
self.model = model
}
func setBranchesError(with error: Error){
// alertWithOk(message: error.localizedDescription)
}
func startLoading(){
showProgressHud()
}
func endLoading(){
hideProgressHud()
}
}
extension GmeContactsViewController {
func viperSetup() {
let service = GmeContactsService()
let interactor = GmeContactsInteractor(service: service, model: nil)
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 UITableView.automaticDimension
}
}
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.delegate = self
cell.index = indexPath.row - 1
cell.setup()
return cell
}
}
extension GmeContactsViewController: GmeContactCallDelegate {
func call(index: Int?) {
guard let index = index else {return}
if let contact = self.contacts.elementAt(index: index) {
let numbers = contact.contactNumber
let alert = UIAlertController(title:nil, message:"help_you_text".localized(), preferredStyle: .actionSheet)
numbers?.forEach({ number in
let action = UIAlertAction.init(title: "\(number)", style: UIAlertAction.Style.default, handler: { action in
self.call(number: number)
})
alert.addAction(action)
})
alert.view.tintColor = UIColor.darkGray
alert.addAction(UIAlertAction(title: "cancel_text".localized(), style: UIAlertAction.Style.cancel, handler: nil))
present(alert, animated: true, completion: nil)
}
}
}